2014-01-29 43 views
2

我有這個和「Strict Standards:call_user_func_array()期望參數1是更新到php 5.5之後的有效回調,非靜態方法」。

我知道了解決方法是有點改變「::」,以「 - >」在某處下面的PHP,但我不能確定如何對其進行格式化..

function widget($args, $instance) { 
      extract($args); 
      $title = apply_filters('widget_title', $instance['title']); 
      echo $before_widget; 
      if ($title) 
      echo $before_title . $title . $after_title; 
      wp_custom_sidebar_plugin::query_custom_sidebar(); 
      echo $after_widget; 
     } 

這是倒數第二行我需要解決...只是不知道如何寫這個PHP。

繼承人的完整代碼

<?php 
/* 
Plugin Name: WordPress Custom Sidebar 
Plugin URI: http://www.typomedia.org/wordpress/plugins/wordpress-custom-sidebar/ 
Description: With this plugin you can handle sidebar contents like posts and assign them from a dropdown menu. 
Author: Typomedia Foundation 
Version: 2.3 
Author URI: http://www.typomedia.org/ 
*/ 

if (!class_exists ('wp_custom_sidebar_plugin')) { 
    class wp_custom_sidebar_plugin { 

    function custom_sidebar_textdomain() { 
     load_plugin_textdomain('wpcsp', false, dirname(plugin_basename(__FILE__)) . '/languages/'); 
    } 

    function custom_sidebar_addcolumn() { 
     global $wpdb; 
     if (false === $wpdb->query("SELECT post_sidebar FROM $wpdb->posts LIMIT 0")) { 
      $wpdb->query("ALTER TABLE $wpdb->posts ADD COLUMN post_sidebar varchar(200)"); 
     } 
    } 

    function custom_sidebar_insert_post($pID) { 
     global $wpdb; 
     extract($_POST); 
     $wpdb->query("UPDATE $wpdb->posts SET post_sidebar = '$post_sidebar' WHERE ID = $pID"); 
    } 

    function custom_sidebar_post_type() { 
     $labels = array(
      'name' => __('Sidebars', 'wpcsp'), 
      'singular_name' => __('Sidebar', 'wpcsp'), 
      'add_new' => __('Add New', 'wpcsp'), 
      'add_new_item' => __('Add New Sidebar', 'wpcsp'), 
      'edit_item' => __('Edit Sidebar', 'wpcsp'), 
      'new_item' => __('New Sidebar', 'wpcsp'), 
      'all_items' => __('All Sidebars', 'wpcsp'), 
      'view_item' => __('View Sidebars', 'wpcsp'), 
      'search_items' => __('Search Sidebars', 'wpcsp'), 
      'not_found' => __('No Sidebars found', 'wpcsp'), 
      'not_found_in_trash' => __('No Sidebars found in Trash', 'wpcsp'), 
      'parent_item_colon' => '', 
      'menu_name' => __('Sidebars', 'wpcsp') 
      ); 

     $args = array(
      'labels' => $labels, 
      'show_ui' => true, 
      'public' => false, 
      'publicly_queryable' => false, 
      'capability_type' => 'post', 
      'hierarchical' => true, 
      'menu_position' => 20, 
      'supports' => array('title', 'editor', 'revisions'), 
     ); 

     register_post_type('sidebar',$args); 
    } 

    function custom_sidebar_dropdown_box($post) { 
     global $post; 
     $post_sidebar = $post->post_sidebar; 
      $sidebars = wp_dropdown_pages(array(
      'post_type' => 'sidebar', 
      'selected' => $post->post_sidebar, 
      'name' => 'post_sidebar', 
      'sort_column' => 'menu_order, post_date', 
      )); 
      ?> 
      <p><a href="<?php echo site_url(); ?>/wp-admin/post-new.php?post_type=sidebar"><?php _e('Create new sidebar', 'wpcsp') ?></a></p> 
      <?php 
    } 

    function custom_sidebar_meta_box() { 
     add_meta_box('custom_sidebar', __('Sidebar', 'wpscp'), array('wp_custom_sidebar_plugin','custom_sidebar_dropdown_box'), 'post', 'side', 'low'); 
     add_meta_box('custom_sidebar', __('Sidebar', 'wpscp'), array('wp_custom_sidebar_plugin','custom_sidebar_dropdown_box'), 'page', 'side', 'low'); 
    } 

    function query_custom_sidebar() { 
      global $post; 
      $parent = get_post($post->post_parent); 

      if (is_single() || is_page() && $post->post_sidebar) { 
       $sidebar_id = $post->post_sidebar; 
       $args = array(
        'post_type' => 'sidebar', 
        'p' => $sidebar_id 
        ); 
      } 

      elseif (is_single() || is_page() && $parent->post_sidebar) {   
       $sidebar_id = $parent->post_sidebar; 
       $args = array(
        'post_type' => 'sidebar', 
        'p' => $sidebar_id 
        ); 
      } 

      else { 
      $args = array(
       'post_type' => 'sidebar', 
       'posts_per_page' => 1, 
       'order' => 'ASC',   
       ); 
      }  

      // The Loop 
      $the_query = new WP_Query($args); 
      while ($the_query->have_posts()) : $the_query->the_post(); 
       the_content(); 
      endwhile; 
      // Reset Post Data 
      wp_reset_postdata(); 
    } 

    function custom_sidebar_register_widget() { 
     register_widget('custom_sidebar_widget'); 
    } 

    function custom_sidebar_default_entry() { 
     global $wpdb; 
     $args = array(
      'post_type' => 'sidebar', 
      'post_title' => 'Default Sidebar', 
      'post_content' => '<h2>WordPress Custom Sidebar 2.1</h2>This plugin is a development of <a title="Designstudio, Philipp Speck" href="http://www.destio.de" target="_blank">Designstudio, Philipp Speck &raquo;</a>', 
      'post_status' => 'publish' 
      ); 

     $columns = get_posts('post_type=sidebar'); 
     // check if not exsist then insert default entry 
     if (empty($columns)) { 
       wp_insert_post($args); 
     } 
    } // end function custom_sidebar_default_entry 

    function plugin_header() { 
     global $post_type; 
     ?> 
    <style> 
    <?php if (($_GET['post_type'] == 'sidebar') || ($post_type == 'sidebar')) : ?> 
     #icon-edit { background:transparent url('<?php echo plugins_url('icon32.png', __FILE__);?>') no-repeat -4px -5px; } 
    <?php endif; ?> 
     #adminmenu #menu-posts-sidebar div.wp-menu-image{background:transparent url('<?php echo plugins_url('icon16.png', __FILE__);?>') no-repeat scroll 1px -33px;} 
     #adminmenu #menu-posts-sidebar:hover div.wp-menu-image,#adminmenu #menu-posts-sidebar.wp-has-current-submenu div.wp-menu-image{background:transparent url('<?php echo plugins_url('icon16.png', __FILE__);?>') no-repeat scroll 1px -1px;} 
    </style> 
    <?php 
    } 

    } // end class wp_custom_sidebar_plugin 
} // end class_exists check 

if (!class_exists ('custom_sidebar_widget')) { 
    class custom_sidebar_widget extends WP_Widget { 

     function custom_sidebar_widget() { 
      $options = array('description' => __('To assign custom sidebars inside post or pages drag the widget to an area of your choice.', 'wpcsp')); 
      parent::WP_Widget(false, __('Custom Sidebar', 'wpcsp'), $options); 
     } 

     function widget($args, $instance) {   
      extract($args); 
      $title = apply_filters('widget_title', $instance['title']); 
      echo $before_widget; 
      if ($title) 
      echo $before_title . $title . $after_title; 
      wp_custom_sidebar_plugin::query_custom_sidebar(); 
      echo $after_widget; 
     } 

    } // close custom_sidebar_widget class 
} // end class_exists check 

add_action('init', array('wp_custom_sidebar_plugin','custom_sidebar_textdomain')); 
add_action('init', array('wp_custom_sidebar_plugin','custom_sidebar_addcolumn')); 
add_action('init', array('wp_custom_sidebar_plugin','custom_sidebar_post_type')); 
add_action('plugins_loaded', array('wp_custom_sidebar_plugin','custom_sidebar_default_entry')); 
add_action('widgets_init', array('wp_custom_sidebar_plugin','custom_sidebar_register_widget')); 
add_action('admin_menu', array('wp_custom_sidebar_plugin','custom_sidebar_meta_box')); 
add_action('wp_insert_post', array('wp_custom_sidebar_plugin','custom_sidebar_insert_post')); 
add_action('admin_head', array('wp_custom_sidebar_plugin', 'plugin_header')); 
?> 

回答

0

嗯,試圖改變

function widget($args, $instance) { 

public static function widget($args, $instance) { 
+0

沒有那個錯誤編輯出來。繼承人完整的代碼 – Ramabyte

0

你在靜態情況下調用query_custom_sidebar當它不是一個靜態方法。嘗試使query_custom_sidebar成爲靜態函數,或者創建wp_custom_sidebar_plugin類的實例,並通過該實例調用方法query_custom_sidebar

相關問題