How to do a query only on a specific admin page?

It’s worthwhile pointing out that using admin_init within the current_screen filter is too late because admin_init has already fired. Instead do: add_action(‘current_screen’, ‘current_screen_callback’); function current_screen_callback($screen) { if( is_object($screen) && $screen->id === ‘top_level_custom-settings-api’ ) { add_filter(‘top_level_screen’, ‘__return_true’); } } Elsewhere in your top_level_page_callback callback responsible for executing the query: function top_level_page_callback() { $active_posts = null; if … Read more

How to limit the pages displayed for choosing parent page on page attribute’s menu?

This meta box is printed with page_attributes_meta_box and the select field for choosing parent is generated with this code: if ( is_post_type_hierarchical( $post->post_type ) ) : $dropdown_args = array( ‘post_type’ => $post->post_type, ‘exclude_tree’ => $post->ID, ‘selected’ => $post->post_parent, ‘name’ => ‘parent_id’, ‘show_option_none’ => __(‘(no parent)’), ‘sort_column’ => ‘menu_order, post_title’, ‘echo’ => 0, ); $dropdown_args = … Read more

Restrict access to admin but allow admin_post hook

All you need to do is to modify your method of restricting users. add_action( ‘admin_init’, function() { if ( (defined(‘DOING_AJAX’) && DOING_AJAX) || ( strpos($_SERVER[‘SCRIPT_NAME’], ‘admin-post.php’) ) ) { return; } if ( !current_user_can(‘manage_options’) ) { wp_redirect( home_url(‘/meu-perfil’) ); exit(); } }

Make sub menu items a main link in the admin menu using fuctions.php

OK, it’s a bit messy, but it works. Take a look function remove_submenus() { global $submenu; unset($submenu[‘themes.php’][10]); // Removes Menu } add_action(‘admin_menu’, ‘remove_submenus’); function new_nav_menu () { global $menu; $menu[99] = array(”, ‘read’, ‘separator’, ”, ‘menu-top menu-nav’); add_menu_page(__(‘Nav Menus’, ‘mav-menus’), __(‘Nav Menus’, ‘nav-menus’), ‘edit_themes’, ‘nav-menus.php’, ”, 99); } add_action(‘admin_menu’, ‘new_nav_menu’); Essentially it is removing the … Read more

Where is default wp_head() implemented?

Is there somewhere I can see this default implementation? wp_head() function simply triggers the wp_head action hook that runs all callback functions that were added to this hook using add_action(‘wp_head’,’callback_function’); So there is no default implementation. Can this default implementation be “turned off”? Like we said before since there is no default implementation you need … Read more