Wordpress php issue with creating custom filter -
i'm new working filters, keen make plugin building extensible.
in main plugin have following class , function:
class skizzar_admin_theme_pages { // return (array) properties of skizzar admin theme admin pages static function get_pages( $page_slug = '' ) { $pages = array(); // default page properties $default_args = array( 'menu-title' => '', 'tab-title' => '', 'parent' => 'admin.php', 'in-menu' => false, 'has-tab' => true, 'tab-side' => false, 'top-level' => false, ); $pages['sat-options-general'] = array_merge( $default_args, array( 'slug' => 'sat-options-general', 'menu-title' => _x( 'admin theme', 'page title in menu', 'skizzar_admin_theme' ), 'tab-title' => _x( 'admin theme options', 'option tab title', 'skizzar_admin_theme' ), 'title' => _x( 'admin theme options', 'option page title', 'skizzar_admin_theme' ), 'callback' => array( __class__, 'display_general_options_page' ), 'in-menu' => true, 'top-level' => true, ) ); $pages['sat-addons'] = array_merge( $default_args, array( 'slug' => 'sat-addons', 'menu-title' => _x( 'addons', 'page title in menu', 'skizzar_admin_theme' ), 'tab-title' => _x( 'addons', 'option tab title', 'skizzar_admin_theme' ), 'title' => _x( 'browse addons', 'option page title', 'skizzar_admin_theme' ), 'callback' => array( __class__, 'display_addons_page' ), 'in-menu' => true, ) ); return apply_filters( 'skizzar_admin_theme_tab', $pages, $default_args, $page_slug ); } // output content of requested options page static function display_general_options_page() { $page_info = self::get_pages( 'sat-options-general' ); include( plugin_dir_path( __file__ ) . 'inc/page-options-general.php' ); } ... }
in nutshell, array used create submenu page , tabs across top of page, amongst other things. see have added filter:
apply_filters( 'skizzar_admin_theme_tab', $pages, $default_args, $page_slug );
to function get_pages()
, can add pages addon plugin.
in addon plugin, have following function:
function add_google_analytics_tab( $pages, $default_args, $page_slug ) { $pages['sat-ga'] = array_merge( $default_args, array( 'slug' => 'sat-ga', 'menu-title' => _x( 'ga', 'page title in menu', 'skizzar_admin_theme' ), 'tab-title' => _x( 'ga', 'option tab title', 'skizzar_admin_theme' ), 'title' => _x( 'ga', 'option page title', 'skizzar_admin_theme' ), 'callback' => array( __class__, 'display_ga_page' ), 'in-menu' => true, ) ); // return if ( $page_slug ) { if ( ! isset( $pages[ $page_slug ] ) ) { return null; } return $pages[ $page_slug ]; } return $pages; } function display_ga_page() { echo 'ga settings go here'; }
this called using following add_filter function:
add_filter( 'skizzar_admin_theme_tab', array(&$this, 'add_google_analytics_tab', 1, 3) );
the hope add array get_pages()
function in main plugin, adding submenu item , tabs etc.
however, met fololwing errors:
call_user_func_array() expects parameter 1 valid callback, array must have 2 members in ...plugin.php on line 235 invalid argument supplied foreach() in ...class-sat-menu.php on line 13
here referenced line in class-sat-menu.php
static function action_add_menu_entries() { // skizzar admin theme pages foreach ( skizzar_admin_theme_pages::get_pages() $page_info ) { if ( ! $page_info['in-menu'] ) { $page_info['parent'] = null; } if ($page_info['top-level']) { add_menu_page( $page_info['title'], // page title ( $page_info['menu-title'] ? $page_info['menu-title'] : $page_info['title'] ), // menu title skizzar_admin_theme_user::get_admin_cap(), // capability $page_info['slug'], // slug $page_info['callback'] // callback ); } else { add_submenu_page( 'sat-options-general', $page_info['title'], ( $page_info['menu-title'] ? $page_info['menu-title'] : $page_info['title'] ), skizzar_admin_theme_user::get_admin_cap(), $page_info['slug'], $page_info['callback'] ); } } }
i can't quite head around error is, advise or appreciated
Comments
Post a Comment