$user_id vs. is_user_logged_in()

Well it wouldn’t always work unless you global $user_id. is_user_logged_in will however work without that extra line of code. The speed improvement is most likely so small it’s less than the speed improvement between single and double quotes and not even worth thinking about. Also $user_id variable may disappear in a new version and would … Read more

Protect custom php file with login

This is impossible to answer definitively without a better description, but I am assuming that app.php is a completely distinct piece of code. In which case, WordPress can’t really manage access to it. You will need to incorporate it into WordPress. While this is not the only way to do it I would advise: Create … Read more

wp.template() Not a function

Ah, I get it. When you enqueue your admin script, add ‘wp-util’ as a dependancy. wp_enqueue_script( ‘script_handle’, plugin_dir_url( __FILE__ ) . ‘script.js’, array( ‘jquery’, ‘wp-util’ ), ‘1.0’, true );

Disable WP Editor for specific page templates

Yes, try this : function remove_editor() { if (isset($_GET[‘post’])) { $id = $_GET[‘post’]; $template = get_post_meta($id, ‘_wp_page_template’, true); switch ($template) { case ‘template_01.php’: case ‘template_02.php’: case ‘template_03.php’: case ‘template_04.php’: // the below removes ‘editor’ support for ‘pages’ // if you want to remove for posts or custom post types as well // add this line … Read more

Remove Metabox from Menus screen

The box gets added in wp_nav_menu_setup(), so you’ll have to remove it sometime after that and before it’s being output later in nav-menus.php. There don’t seem to be any action hooks you can use there, but admin-header.php has a few. You could try this: add_action( ‘admin_head-nav-menus.php’, ‘roots_remove_nav_menu_metaboxes’ ); I’ve never tried removing metaboxes from the … Read more

Why are my styles being applied to the admin area?

Why are my styles being applied to the admin area? Assuming that is all of the code, it is because you are enqueueing the styles globally. You need to hook that to wp_enqueue_scripts, which will only load on the front end. wp_register_style( ‘main-styles’, get_stylesheet_directory_uri() . ‘/css/styles.css’, false, ‘1.0.0’, ‘all’); function enqueue_script_front_wpse_84975() { wp_enqueue_style(‘main-styles’); } add_action(‘wp_enqueue_scripts’, … Read more

Remove default subpages from Custom Post Menu

You can manipulate the global variable $submenu and remove them. In normal circumstances, the index key values are 5 (All items) and 10 (New item). In this example, the post type is portfolio: add_action( ‘admin_init’, ‘remove_cpt_submenus_wpse_95797’ ); function remove_cpt_submenus_wpse_95797() { global $submenu; unset( $submenu[‘edit.php?post_type=portfolio’][5], $submenu[‘edit.php?post_type=portfolio’][10] ); }