Admin menu links just refresh the page

I'm using add_submenu_page() function to add some options to my plugin. On Linux hosting everything works like it should, on Windows hosting those 5 sub-menus have same link somehow and when I click on them page just reloads. What can be issue? Both hosts are using same PHP version. Here is the code $this->page_hooks['link1'] = add_submenu_page(__FILE__, __('link1', 'domain'), __('link1', 'domain'), $acl_table['manage_link1'], 'wp-plugin-link1', array($this, 'on_manage_link1')); $this->page_hooks['link2'] = add_submenu_page(__FILE__, __('link2', 'domain'), __('link2', 'domain'), $acl_table['manage_link2'], 'wp-plugin-link2', array($this, 'on_manage_link2')); $this->page_hooks['link3'] = add_submenu_page(__FILE__, __('link3', 'domain'), …
Category: Web

Show media-frame-menu on custom Media Frame

I have a plugin I built that adds a custom media frame with the following: media_frame = wp.media.frames.media_frame = wp.media({ title: 'Select your images', button: { text: 'Use Image' }, multiple: false }); media_frame.open(); This produces a media frame that looks like this: Thus far, this has been all I needed, but my site uses Wordpress Multisite and I'm trying to add in the Network Shared Media plugin. However, Network Shared Media requires the media-frame-menu sidebar in order to access …
Category: Web

Custom Admin Menu Order for all User Roles

I've reordered the admin menu items through: function custom_menu_order($menu_ord) { if (!$menu_ord) return true; return array( 'index.php', // Dashboard 'edit.php?post_type=page', // Pages 'edit.php?post_type=sp_faq', // FAQs 'gf_edit_forms', // Forms 'woocommerce', // Woocommerce 'edit.php?post_type=product', //Products 'edit.php', // Posts/News 'edit.php?post_type=event', // Events 'upload.php', // Media 'themes.php', // Appearance 'plugins.php', // Plugins 'users.php', // Users 'tools.php', // Tools 'options-general.php', // Settings ); } add_filter('custom_menu_order', 'custom_menu_order'); // Activate custom_menu_order add_filter('menu_order', 'custom_menu_order'); This works great for the Admin user role, however, does not work for other …
Category: Web

Change the destination of the URLs in post.php

The post.php screen lists posts vertically in the admin area [and other post types]. Each item's post_title is a hyperlink, directly above some inline choices. Both the title link, and the "Edit" inline selection, redundantly go to the same destination, namely: http[s]://{yoursite.tld}/wp-admin/post.php?post={postID}&action=edit I want to filter the post_title URL href using PHP. Specifically, I want to set a custom destination to the URL, based on metadata stored in the post. i.e post_ID:123 has post meta data: {'custom_URL' : 'http:somesite.com'} In …
Category: Web

How to access wordpress menu & submenu item through the REST API?

I want to display the menu & submenu items from Wordpress in another web-application, menu and Submenu are get but there is more menu inside Submenu I want that. function return_menus( $data ) { $menuID = $data['id']; //$primaryNav = wp_get_nav_menu_items($menuID); $x = wp_get_nav_menu_items($menuID); // echo '<pre>'; // print_r($x); // echo '</pre>'; $menu = array(); $submenu = array(); foreach($x as $y){ $y-> submenu = array(); if($y->menu_item_parent === '0') array_push($menu, $y); else array_push($submenu, $y); } for($i=0; $i < count($submenu); $i++) { $index …
Category: Web

How do I set up a webhook?

I have a simple script that sends Slack messages, runs reports and does other things. I would like this script to run directly based after users purchase something on my site. I do NOT want to build this functionality using WordPress, my goal is to have loosely coupled systems. ENTER WEBHOOKS. Webhooks sound exactly like what I want. Something happens on WordPress and then it pings my reporting server. WordPress advertises a webhooks feature at https://en.support.wordpress.com/webhooks/ it states this there …
Category: Web

Admin custom option screen not saved unless user manage_options capability

I am running into exactly the problem described by this Trac: https://core.trac.wordpress.org/ticket/14365 I see that one of the devs added a Diff here: https://core.trac.wordpress.org/attachment/ticket/14365/14365.api.diff, which looks like it would add the ability to register the exact capability the user should have, to save the options -- without needing the user to have broad "manage_options" capability which I do not want them to have since it exposes too many other things in Admin. OK, so that Diff looks good to me. …
Category: Web

Pagination in plugin's backend

I am displaying a list of posts in the plugin backend but I can't seem to get the pagination to work. I used the standard approach of getting the "paged" variable and then passing it to get_posts()'s arguments, but whenever I visit my custom backend page or subpage and add the &page=2 variable I get that permissions error about not having enough of them to visit that page. Is there a special way to apply pagination in the backend?
Category: Web

adding existing menu page on new customer user role

I have created new user role 'Host' . now I am trying to show admin menu item ' user' in it . i have googled some code and tried this $result = add_role( 'Host', __(Host), array( 'read' => true // Use false to explicitly deny ) ); function Host_menu_links(){ $user = wp_get_current_user(); if( $user_role == 'Host' ) { remove_menu_page('tools.php'); remove_menu_page('themes.php'); remove_menu_page('options-general.php'); remove_menu_page('plugins.php'); remove_menu_page('edit-comments.php'); remove_menu_page('page.php'); remove_menu_page('upload.php'); remove_menu_page( 'edit.php?post_type=page' ); remove_menu_page( 'edit.php?post_type=videos' ); remove_menu_page( 'edit.php' ); } } add_action('admin_menu', 'Host_menu_links'); I am …
Category: Web

reorder plugin menu position

Looking for a function that I can use to reorder the admin position of a 3rd party plugin, and that will still work once said plugin gets updated. Backstory AIO webmaster and All In One Events plugins are both forcing a menu position of 6. So if you load both plugins, the Events plugin "loses" and disappears. I'd like a function to simply move AIO webmaster from say position 6 to somewhere else — best would be to remove the …
Category: Web

How To Remove or Hide Appearance->Background from Admin Menu

I have a menu Appearance->Background on WP admin, i want to remove or hide from Editor user. i was try to using public function remove_menu() if( !current_user_can( 'administrator' )){ { if( !current_user_can( 'administrator' )) { remove_submenu_page( 'themes.php', 'background.php'); } } add_action('admin_init', [$this,'remove_menu']); But the menu still appear, what solution for this?Thanks
Category: Web

Duplicate "Pages" Item in Admin Menu

I'm registering the following post type: register_post_type( 'post', array( 'hierarchical' => true, 'public' => true ) ); Now I have duplicate "Pages" menu items in WordPress Admin Menu. It should be not "Pages" but rather "Posts". In older versions of WordPress ( < 4.4 ) everything was alright. Any suggestions to do the same? Most important is to make my posts hierarchical.
Category: Web

How to add taxonomy to Users menu in admin?

I want to create a taxonomy that is related to the users, therefore I'd like to show the taxonomy under "Users" menu within wordpress admin. In codex there's a mention that you can attach taxonomy to "nav_menu_item" but I can't find any working example of how this works. If I use: register_taxonomy( 'expertise', array( 'nav_menu_item' ), $args ); or register_taxonomy( 'expertise', array( 'users' ), $args ); it doesn't work. Any help would be much appreciated.
Category: Web

How to redirect one admin URL to another when admin page URL has "/admin.php?page=" in it?

The following code (from here, middle section chopped out) allows me to redirect users who land on a certain page in the WP admin to another admin page... function admin_redirects() { global $pagenow; /* Redirect Customizer to Theme options */ if($pagenow == 'customize.php'){ wp_redirect(admin_url('/admin.php?page=theme_options', 'http'), 301); exit; } } add_action('admin_init', 'admin_redirects'); It works great...for some pages. The problem is I cannot get redirects to work for pages originating with a URL structure such as "admin.php?page=example-options." The example-options string is just …
Category: Web

Is it possible to have dynamic post id # in add_menu_page()?

I use the add_menu_page function in my custom theme builds but when I export my local copy of the site and import it in the production site some of post id numbers change and I have to update this function manually (ie: in the code below: ?post=8, ?post=8, ?post=10). Is there a way to have these numbers be dynamic? function custom_admin_menu_links() { $user = wp_get_current_user(); if ( ! $user->has_cap( 'manage_options' ) ) { add_menu_page( 'Home', 'Home', 'edit_posts', 'post.php?post=6&action=edit', '', 'dashicons-admin-home', …
Category: Web

Remove Theme menu link from Admin Panel

I am trying to remove menu from the admin panel my code works as it removes some pages but i can't remove the following. admin.php?page=ot-theme-options admin.php?page=ot-settings admin.php?page=yith_woocompare_panel add_action('admin_menu', 'remove_admin_menu_links'); function remove_admin_menu_links(){ $user = wp_get_current_user(); if( $user && isset($user->user_email) && '[email protected]' == $user->user_email ) { remove_menu_page('tools.php'); remove_menu_page('options-general.php'); remove_menu_page('plugins.php'); remove_menu_page('users.php'); remove_menu_page( 'themes.php' ); remove_submenu_page( 'themes.php', 'widgets.php' ); remove_menu_page( 'wpcf7' ); remove_menu_page( 'ot-theme-options' ); // Doesn't work remove_menu_page( 'ot-settings' ); // Doesn't work //echo '<pre>' . print_r( $GLOBALS[ 'menu' ], TRUE) . '</pre>'; …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.