Wordpress plugin pages - php

I'm not sure how to ask this so I'll explain my problem first. I have a plugin for Wordpress that updates a calendar and some databases that have multiple id's. So I have a hook for a page "editrental.php" which works fine but then when I click on a link for a certain item and goes to something like this
"editrental.php?id=3828" it won't let the page show. I'm guessing it has something to do with the way i set up the hook which is like this
add_submenu_page(null,'Wasatch Front Waste Calander Manage Editrental',
'WFWRD Calendar Manage Editrental', 'manage_options', 'trailer-scheduler-
editrental', 'trailer_admin_editrental');
Any ideas on how to set this up correctly or links to send me in the right direction? Thanks everybody.

Try using this
add_submenu_page(
'edit.php?post_type=POST-TYPE-NAME', //under which post/custom post the submenu should appear
__('Submenu Title','menu-test'),
__('Submenu Title','menu-test'),
'manage_options',
'custom-admin-page',
array($this, 'function-name') //where the functionality works for the submmenu
);

// Add to admin_menu function
$page = add_submenu_page( 'edit.php?post_type=theme', __('Theme Page Options'), __('Theme Menu Options'), 'edit_themes', 'theme_options', theme_options);
function theme_options() {
// Render our theme options page here ...
}

So to fix this all I ended up doing was switching "editrental.php?id=3828" with "editrental.php&id=3828". For some reason it wasn't excepting the ? but it did except the &.

Related

Wordpress Issue Create Menu Option

I have created a Custom Setting API for web developing for a client. I was just creating first menu option on the WP dashboard.
But when I send file I get this error message saying -->
:call_user_func_array() expects parameter 1 to be a valid callback, function ' allb_admin_page' not found or invalid function name in
function allb_admin_page() {
add_menu_page( ' ALLB Theme Options', 'ALLB', 'manage_options', 'a-legacy-left-behind', 'allb_theme_create_page', 110);
}
add_action( 'admin_menu', ' allb_admin_page' );
function allb_theme_create_page() {
// genration of our admin page
}
I was thinking this may be new update or this function that i am using might be removed from WordPress or i am doing something wrong please explain.
Can anyone help with this quick issue having on word press, please?
Thank you,
Happy New Years!!!
You need to remove the space:
add_action('admin_menu', 'allb_admin_page');
Here is the answer..
Please try it once, Just copy and past this code..
function allb_admin_page() {
add_menu_page('ALLB Theme Options', 'ALLB', 'manage_options', 'a-legacy-left-behind', 'allb_theme_create_page', 110);
}
add_action('admin_menu','allb_admin_page');
function allb_theme_create_page() {
// genration of our admin page
}
I hope it'll help to you..

Show admin-only submenu link to editors in WordPress. Results in error

I'm using a plugin which adds a submenu item to an admin menu like so:
add_submenu_page( 'propertyhive', 'Property Hive Settings', 'Settings', 'manage_options', 'ph-settings', 'callback_fn' );
Due to it stating manage_options it only appears for administrators. I need to show it for editors. Here's what I've tried in my theme's functions.php file:
add_action( 'admin_menu', 'custom_settings_menu', 99 );
function custom_settings_menu()
{
// Remove the submenu item first
remove_submenu_page( 'propertyhive', 'ph-settings' );
// Add it again but with different role (manage_propertyhive)
// This role does exist as other submenu items ue it
add_submenu_page( 'propertyhive', 'Property Hive Settings', 'Settings', 'manage_propertyhive', 'ph-settings', 'my_theme_callback_fn' );
}
Although this does show the submenu item correctly, I get the following error:
Sorry, you are not allowed to access this page.
Can anyone see anything obvious or have any inclinations as to what might cause this?
Note: The manage_propertyhive capability definitely does exist
I believe this is happening because 'manage_propertyhive' is not a defined capability, therefore nobody will have access to that menu. You can either use one of the predefined wordpress capabilities which you can find here or you can define your own custom capability such as 'manage_propertyhive', by following the instructions here.
Hope this helps!
1) Are you sure the add_submenu_page() function from the Plugin is copied correctly? add_submenu_page() accepts only 6 parameters - in your question it has 7 paramters with propertyhive being the capability and manage_options being the menu_slug (which is perplexing)
https://developer.wordpress.org/reference/functions/add_submenu_page/
2) I guess that administrators as well as editors got the capability manage_propertyhive ? If not make sure.
3) In your sample code the callback function for the new propertyhive submenu page is my_theme_callback_fn - did you insert the correct callback function here?
4) The fact that you add the submenu page to editors does not necessarily mean they can access that page - did you check the Plugin for further capability checks? Maybe in the code of the callback function or in some other function of the Plugin capabilities are checked again and editors are missing some capability.
This must do the trick
function add_theme_caps() {
$role = get_role( 'editor' );
$caps = (array)$role->capabilities;
if(!array_key_exists('manage_propertyhive', $caps)) {
$role->add_cap( 'manage_propertyhive' );
}
}
add_action( 'admin_init', 'add_theme_caps');
Assuming you've set up the capability right, perhaps the parent page is not allowing access to submenu page, make sure user is able to access parent page...
This is the function that checks if user can access the page... If it returns false the error is displayed...
https://github.com/WordPress/WordPress/blob/4.6.1/wp-admin/includes/plugin.php#L1697-L1763
Besides checking several other things, it also checks if parent page is accessible by the user.
If that doesn't work, I'd suggest you to go to this file on you local install, and var_dump all vars that are checked before returning false, this is how we devs debug the errors... ;)
Make sure to restore the file to original file ( I just update the WordPress again, that restores all core files to their original state )...
Hope that helps.

add_submenu_page to post_type post

I'm trying to add a settings submenu page to the post_type post, but I can not get it to work. The page exists if I go to the url directly, but it does not appear in the sidebar menu. If I change the post type to page, it works perfectly fine, but the settings I'm trying to add apply specifically to the post post_type.
is there a solution for this?
Thanks,
function the_post_settings() {
add_submenu_page(
'edit.php?post_type=post',
'Post Settings',
'Settings',
'edit_posts',
'post-settings',
'post_settings'
);
}
add_action('admin_menu' , 'the_post_settings');
I solved my own problem. I had to change edit.php?post_type=post to just edit.php.
All is well now. Hope I helped someone else in the future

I want to add a new wordpress page

Happy new year to everyone. I added a new link in my wordpress. The url is wp-admin/users.php?page=business&user_id=2 but when I access the page is says You do not have sufficient permissions to access this page. I know that the page is not created yet business How will I create new page so that I can work on page=business?
It is really that easy please add the following code. Let me know if you require more help.
add_action('admin_menu', 'adminMenus');
function adminMenus(){
add_submenu_page( 'users.php', 'Business Page Title', 'My Business Menu', 'manage_options', 'business', 'businessPageFunction');
}
function businessPageFunction(){
echo "Meow...";
}
For more information View Function Reference/add submenu page and Plugin API/Action Reference/admin menu

Using variables in the URL on wordpress menu link

I am using wordpress wp-admin to create the menu. It is under Appearance/menu.
I have a link that points to /members/ but what I really need is a link to /members/$logged_user...
For example /members/user_1 or /members/user_2.
How can I do that?
I dont know if it is important, but I am using buddypress plugin.
I have written a short script for adding dynamic buddypress links in wordpress menu. Hope it helps
I have added custom links in wordpress menu replacing username in link with --username--
example
http://website_name.com/members/--username--/messages/
then add this code in function.php
add_filter( 'nav_menu_link_attributes', 'menu_override', 10, 3 );
function menu_override( $atts, $item, $args ) {
$user = wp_get_current_user();
$newlink = str_replace("--username--", $user->user_login, $atts[href]);
$atts[href] = $newlink;
return $atts;
}
The default menu doesn't really have that option. But you can make your own walker function, searching for the keyword and replacing it with the current user.
See http://codex.wordpress.org/Function_Reference/wp_nav_menu#Using_a_Custom_Walker_Function
But it would probably be faster and more manageable to just place the link outside the menu call with some static html and the needed php.
You can use the BuddyPress Custom Profile Menu plugin to get close to this functionality, otherwise you will have to write custom code that uses actions/filters of wp_nav_menu().

Categories