How to check if the current page is a plugin admin panel in wordpress

Please, I want to know how to check if I am currently on the plugin admin page. I created a plugin with a menu item that displays a page containing some statistics for this use of the plugin, for this I use custom jQuery plugins, some CSS that I will never use outside of this page.

Therefore, I am interested to know how I can check this, install or not use the plugin and JS styles.

Here is my queue style code

function bridge_style_enqueuer() {
   wp_register_style( "bridge_display_style", WP_PLUGIN_URL.'/symfony-bridge/chosen.css');
   wp_register_style( "bridge_display_style_tb", WP_PLUGIN_URL.'/symfony-bridge/bootstrap.min.css');
   wp_enqueue_style( 'bridge_display_style' );
   wp_enqueue_style( 'bridge_display_style_tb' );
}
add_action( 'admin_init', 'bridge_style_enqueuer' );

I do the same with Js

function bridge_script_enqueuer() {
   wp_register_script( "bridge_script", WP_PLUGIN_URL.'/symfony-bridge/bridge.js', array('jquery'),FASLE, TRUE);
   wp_register_script( "bridge_chosen_script", WP_PLUGIN_URL.'/symfony-bridge/chosen.js', array('jquery'),FASLE, TRUE);
   wp_register_script( "bridge_chosen_script_tb", WP_PLUGIN_URL.'/symfony-bridge/bootstrap.min.js', array('jquery'),FASLE, TRUE);

    wp_enqueue_script( 'bridge_script' );
    wp_enqueue_script( 'bridge_chosen_script' );
    wp_enqueue_script( 'bridge_chosen_script_tb' );
}
 add_action( 'admin_init', 'bridge_script_enqueuer' );
+4
source share
4 answers

WP Screen API:

$screen = get_current_screen();

if ( in_array( $screen->id, array( 'some_admin_page', 'another_admin_page' ) ) )
{
    wp_enqueue_script( 'bridge_script' );
}

, init admin_enqueue_scripts ( ) " ", .. add_menu_page().

+3

js hook admin_enqueue_scripts - http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts. , , css hook wp_enqueue_scripts.

0

- add_*_page admin_print_scripts-$your_plugin_page:

add_action( 'admin_menu', 'add_page_so_20162413' );

function add_page_so_20162413()
{
    $my_page = add_menu_page( /* etc */ );
    add_action( "admin_print_scripts-$my_page", 'enqueue_so_20162413' );
}

function enqueue_so_20162413()
{
    wp_enqueue_script( /* etc */ );
    wp_enqueue_style( /* etc */ );
}

Diggy , . >

0

you can use is_admin()to check if you are in the admin panel http://codex.wordpress.org/Function_Reference/is_admin

-1
source

All Articles