0

I am trying to load scripts on three different screens ONLY. I am getting the styles on the ins-carrier-display pages but they do not print on the ins-carrier-edit page.

Am I missing something?

// Create admin page navigation listings
function bf_carrier_admin_network() {
  global $bfc_admin_page;
  $bfc_admin_page = add_submenu_page('settings.php', 'Carriers', 'BrightFire Carriers', 'edit_posts', 'ins-carrier-edit', 'carrier_admin_network');   
}

function bf_carrier_admin_actions() {
  global $bfc_admin_page;
  if (current_user_can('manage_options')){
    $bfc_admin_page = add_options_page('BrightFire Carriers', 'BrightFire Carriers', 'edit_posts', 'ins-carrier-display', 'carrier_admin');   
  }else{
    $bfc_admin_page = add_menu_page('Carriers', 'Carriers', 'edit_posts', 'ins-carrier-display', 'carrier_admin','dashicons-products',58);
  }
}

add_action('admin_menu', 'bf_carrier_admin_actions');
add_action('network_admin_menu', 'bf_carrier_admin_network');

//registser admin scripts
add_action('admin_enqueue_scripts', 'bfc_styles_scripts');
function bfc_styles_scripts(){
  global $bfc_admin_page;

  $bfc_admin_screen = get_current_screen();

  if ( $bfc_admin_page == $bfc_admin_screen->id ) {
    wp_enqueue_script('jquery');
    wp_enqueue_script('jquery-effects-core');
    wp_enqueue_script('jquery-effects-drop');
    wp_enqueue_script('jquery-effects-highlight');
    wp_enqueue_style( 'bfc_admin_style', plugins_url( 'css/admin.css' , __FILE__ ));
    wp_enqueue_script('bootstrap', plugins_url('js/bootstrap.js', __FILE__), array('jquery'), '2.3.2'); 
  }
}   

1 Answer 1

0

A bit of research on here and it seems I was trying too hard. I have found the following solution. Props to this answer.

// Create admin page navigation listings
function bf_carrier_admin_network() {
  $hook_suffix = add_submenu_page('settings.php', 'Carriers', 'BrightFire Carriers', 'edit_posts', 'ins-carrier-edit', 'carrier_admin_network');    

  add_action( "load-{$hook_suffix}", 'bfc_styles_scripts' );
}
add_action('network_admin_menu', 'bf_carrier_admin_network');

function bf_carrier_admin_display() {
  if (current_user_can('manage_options')){
    $hook_suffix =  add_options_page('BrightFire Carriers', 'BrightFire Carriers', 'edit_posts', 'ins-carrier-display', 'carrier_admin');   
  }else{
    $hook_suffix = add_menu_page('Carriers', 'Carriers', 'edit_posts', 'ins-carrier-display', 'carrier_admin','dashicons-products',58);
  }

  add_action( "load-{$hook_suffix}", 'bfc_styles_scripts' );
}
add_action('admin_menu', 'bf_carrier_admin_display');

//register admin scripts
function bfc_styles_scripts(){
  wp_enqueue_script('jquery');
  wp_enqueue_script('jquery-effects-core');
  wp_enqueue_script('jquery-effects-drop');
  wp_enqueue_script('jquery-effects-highlight');
  wp_enqueue_style( 'bfc_admin_style', plugins_url( 'css/admin.css' , __FILE__ ));
  wp_enqueue_script('bootstrap', plugins_url('js/bootstrap.js', __FILE__), array('jquery'), '2.3.2'); 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.