您好,我的自定义插件有问题:/
警告:call\\u user\\u func\\u array()要求参数1为有效回调,在C:\\xampp\\htdocs\\wordpress\\wp includes\\plugin中找不到函数“wp\\u slider\\u info\\u page”,或函数名无效。php在线496
我找到了很多关于这个警告的话题,但我仍然不知道是什么错了/
if ( !class_exists( \'wp_slider\' ) ) {
class wp_slider{
function __construct() {
add_action( \'admin_menu\', array( $this, \'wp_slider_info\' ) );
add_action( \'slider-style\', array( $this, \'slider_styles\') );
add_action( \'slider-script\', array( $this, \'slider_scripts\') );
add_filter( \'the_content\', array( $this, \'wp_slider_info_page\') );
register_activation_hook( __FILE__, array( $this, \'wp_install\' ) );
register_deactivation_hook(__FILE__, array( $this, \'wp_uninstall\' ) );
}
function wp_slider_info(){
add_menu_page(\'wp Slider\', \'wp Slider\', \'administrator\', \'slider-info\', \'wp_slider_info_page\', \'dashicons-format-video\');
}
function wp_install(){
global $wpdb;
$table_name=$wpdb->prefix.\'wp_slider\';
$sql="CREATE TABLE $table_name (
id int(11) NOT NULL AUTO_INCREMENT,
image varchar(255) NOT NULL,
link varchar(255) NOT NULL,
title varchar(255) NOT NULL,
content text NULL,
UNIQUE KEY id (id)
);";
require_once( ABSPATH . \'wp-admin/includes/upgrade.php\' );
dbDelta( $sql );
}
function wp_uninstall(){
global $wpdb;
$table_name=$wpdb->prefix.\'wp_slider\';
$sql=\'DROP TABLE \'.$table_name;
$wpdb->query($sql);
}
public function slider_scripts() {
if (!is_admin()) {
wp_register_style(\'slider-script\', plugins_url(\'slider-script.js\', __FILE__), array( \'jquery\' ));
wp_enqueue_style(\'slider-script\');
}
}
public function slider_styles( $page ) {
wp_register_style(\'slider-style\', plugins_url(\'slider-style.css\', __FILE__));
wp_enqueue_style(\'slider-style\');
}
function wp_slider_info_page( $content ){
return $content . \'<p>Test</p>\';
}
}
new wp_slider();
}
SO网友:Rene Korss
wp_slider_info_page
是类的方法。
类中的函数必须设置如下:
array( $this, \'wp_slider_info_page\' )
只有这样WP才知道它是当前类的一部分。
代替
add_menu_page(\'wp Slider\', \'wp Slider\', \'administrator\', \'slider-info\', \'wp_slider_info_page\', \'dashicons-format-video\');
使用
add_menu_page(\'wp Slider\', \'wp Slider\', \'administrator\', \'slider-info\', array( $this, \'wp_slider_info_page\' ), \'dashicons-format-video\');