Viewing 6 replies - 1 through 6 (of 6 total)
  • Which action is the enqueue hooked on to?

    If it’s not hooked onto a specific action how are you specifying when the enqueue is run?

    Thread Starter christian_gnoth

    (@christian_gnoth)

    the function is called. i have checked it – i create a file in the function with file_put_contents – the file is created. so the function is called.

    function bbnuke_plugin_add_option_page()
    {
      $bbnuke_admin_page =
      add_menu_page   (                       'baseballNuke Plugin Options', 'baseballNuke', 8, 'bbnuke-option-page',  'bbnuke_plugin_create_option_page', BBNPURL . 'images/baseballNuke_16x16.gif');
      add_submenu_page( 'bbnuke-option-page', 'Players',                     'Players',      8, 'bbnuke-players',      'bbnuke_plugin_create_players_page');
      add_submenu_page( 'bbnuke-option-page', 'Fields',                      'Fields',       5, 'bbnuke-fields',       'bbnuke_plugin_create_fields_page');
      add_submenu_page( 'bbnuke-option-page', 'Schedule',                    'Schedule',     5, 'bbnuke-schedule',     'bbnuke_plugin_create_schedules_page');
      add_submenu_page( 'bbnuke-option-page', 'Tournaments',                 'Tournaments',  5, 'bbnuke-tournaments',  'bbnuke_plugin_create_tournaments_page');
      add_submenu_page( 'bbnuke-option-page', 'Practices',                   'Practices',    5, 'bbnuke-practice',     'bbnuke_plugin_create_practice_page');
      add_submenu_page( 'bbnuke-option-page', 'Game Results',                'Game Results', 5, 'bbnuke-game-results', 'bbnuke_plugin_create_game_results_page');
      add_submenu_page( 'bbnuke-option-page', 'Uninstsll',                   'Uninstall',    5, 'bbnuke-uninstall',    'bbnuke_plugin_uninstall');
    
      add_action( 'admin_print_scripts-' . $bbnuke_admin_page, 'bbnuke_admin_head' );
    
      return;
    }
    
    function  bbnuke_admin_head()
    {
      wp_enqueue_style( 'bbnuke_admin_styles' );
    }
    function bbnuke_admin_init_method()
    {
    
      wp_register_style('bbnuke_admin_styles', BBNPURL . 'css/bbnuke-admin-plugin.css');
    }
    
    add_action( 'admin_init',   'bbnuke_admin_init_method');
    Thread Starter christian_gnoth

    (@christian_gnoth)

    any idea how to check if the style is registered properly? the enqueue function do not returns any value – so there is no chance to check if the call is successfull or not.

    Are you aware the code you have above will only enqueue the stylesheet when it’s the parent page, ie. your main plugin page, not any of the rest(subpages)… are you checking the top level page when the enqueue fails? (the bbnuke-option-page page).

    You don’t necessarily need to register the style unless you’re likely to re-use it elsewhere… just the enqueue is sufficient if you’re only using it inside the plugin..

    eg.

    wp_enqueue_style( 'bbnuke_admin_styles', BBNPURL . 'css/bbnuke-admin-plugin.css' );

    So you could actually drop the register style code altogether..

    For checking the registered styles, you can print out the $wp_styles var..

    Thread Starter christian_gnoth

    (@christian_gnoth)

    still not working.

    I have putted it in

    add_action( ‘wp_print_styles’, ‘bbnuke_print_styles’);

    function  bbnuke_print_styles()
    {
    
      global $plugin_url;
    
      if ( is_admin() )
      {
    //  wp_register_style('bbnuke_admin_styles', BBNPURL . 'css/bbnuke-admin-plugin.css');
        wp_enqueue_style( 'bbnuke_admin_styles', BBNPURL . 'css/bbnuke-admin-plugin.css');
      }
      else
      {
        wp_register_style('bbnuke_frontend_styles', BBNPURL . 'css/bbnuke-frontend-plugin.php');
        wp_enqueue_style( 'bbnuke_frontend_styles' );
      }
    
      return;
    }

    but it is not printed.

    so i putted it in admin_init and the style is printed.

    wp_print_styles is a front side hook (not the admin area), so it’s not suited..

    Create hooks for each of your pages..

    $bbnuke_admin_page =
    add_menu_page   (                       'baseballNuke Plugin Options', 'baseballNuke', 8, 'bbnuke-option-page',  'bbnuke_plugin_create_option_page', BBNPURL . 'images/baseballNuke_16x16.gif');
    
    $players_page      =
    add_submenu_page( 'bbnuke-option-page', 'Players',                     'Players',      8, 'bbnuke-players',      'bbnuke_plugin_create_players_page');
    
    $fields_page
    add_submenu_page( 'bbnuke-option-page', 'Fields',                      'Fields',       5, 'bbnuke-fields',       'bbnuke_plugin_create_fields_page');

    …etc..

    You can then add actions to each of those pages that should load the stylesheet..

    add_action( 'admin_print_styles-' . $bbnuke_admin_page, 'bbnuke_admin_head' );
    add_action( 'admin_print_styles-' . $players_page, 'bbnuke_admin_head' );
    add_action( 'admin_print_styles-' . $fields_page, 'bbnuke_admin_head' );

    ..and so on…

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘enqueue styles for plugin’ is closed to new replies.