Is conditionnal `is_admin()` function is already applied to app/admin.php?

Hi, should I check for is_admin() in {my-theme}/app/admin.php or it is already tested?

It is for adding settings of a plugin in menu item for Editor role.

Thank you

What have you tried?

To be sure, I check for it (is_admin()), but I just wanted to keep code dry and don’t want to repeat the function if it is not necessary.

Specifically, I try to add Polylang settings for editor, but I didn’t find what function to call yet, I’m looking for it, they don’t use add_options_page in the plugin, so I am not sure what I should use as function call.

if (is_admin()) {  
  add_action('admin_menu', function () {
    if (!current_user_can('manage_options')){  
        add_menu_page(__('Languages Settings'), 'Languages', 'edit_pages', 'polylang', 'dashicons-translation');  
    }  
  });  
}

Hey @Jimmy_Turgeon_Trovac - I don’t believe that file is already checked with is_admin(), but you also shouldn’t need to do that, because you’re running your code on the ‘admin_menu’ action. That action only fires when the admin area is loaded. See: https://codex.wordpress.org/Plugin_API/Action_Reference#Actions_Run_During_an_Admin_Page_Request

1 Like

Ok I got it, that’s probably why there is no use of it for other actions in the same admin.php file like for the customizer.

Thank you @mmirus

1 Like