Wordpress Issue Create Menu Option - php

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..

Related

WordPress add_menu_page not showing in backend

I am trying to create a custom plugin using the code below but the tab/link to the page is not appearing in the WordPress Dashboard and I'm not sure what I'm doing wrong. My company-admin.php file is located in my plugins folder inside a folder called company-admin. The file permissions for the php file are 644 incase that is relevant. Can you help?
add_action( 'admin_menu', 'my_admin_menu' );
function my_admin_menu() {
add_menu_page(
'Company Admin',
'Company Admin',
'manage_options',
'company-admin/company-admin.php',
'',
'',
6
);
}
I'm unsure if this is the correct way to navigate to my plugin but I used this link, correct me if its the wrong link;
https://mywebpage.uk/wp-admin/admin.php?page=company-admin%2Fcompany-admin.php
And what I get is the following error;
Sorry, you are not allowed to access this page.
Query Monitor
The message above was triggered by Core.
Call stack:
wp_die()
wp-admin/includes/menu.php:348
the permission file in wordpress must be 755 for work correctly.
For develop a plugin follow the wordpress official guide https://developer.wordpress.org/plugins/intro/
Let me know.
Try to add more code to your path. Instead of 'company-admin/company-admin.php', paste 'your_plagin_folder/company-admin/company-admin.php',
Edited
But more cleanest is using that way:
function wpdocs_register_my_custom_menu_page(){
add_menu_page(
'Custom Menu Title',
'custom menu',
'manage_options',
'custompage',
'my_custom_menu_page',
'',
6
);
}
add_action( 'admin_menu', 'wpdocs_register_my_custom_menu_page' );
/**
* Display a custom menu page
*/
function my_custom_menu_page(){
//print all what you need or include any pages
include_once plugins_url('company-admin/company-admin.php', __FILE__);
}

Wordpress Administration menu pointed to the theme file

I want to add custom menu and sub-menu to Wordpress admin area. I read some info about it in Codex and I added menus using the function below, which I placed in my theme's functions.php
add_action( 'admin_menu', 'restaurant_menu' );
function restaurant_menu() {
add_menu_page( 'Restaurants Admin Page', 'Restaurants', 'manage_options', get_template_directory() . '/inc/restaurants.php', 'restaurants_admin_page', 'dashicons-format-aside', 6 );
The menu is added to the Wordpress admin sidebar, but I when I'm going that page it goes to the next link:
http://site.ge/wp-admin/admin.php?page=home%2Fbmtbow%2Fpublic_html%2Ftesting%2Fwp-content%2Fthemes%2Fmytheme%2Finc%2Frestaurants.php
but there is no any content, like it is not pointed to the right PHP file.
Am I doing something wrong? and could you help me to solve this problem?
The add_menu_page function doesn't seem to accept a php file as an argument for content. But it does take a function name. You can call your php file with the content in a function, then pass that function as an argument to add_menu_page. (As a side point, you might have the order of your arguments mixed up. The slug is supposed to be 4th, not 5th.) More information about add_menu_page() and it's arguments can be found here.
Try this:
add_action( 'admin_menu', 'restaurant_menu' );
function restaurant_menu() {
add_menu_page( 'Restaurants Admin Page', 'Restaurants', 'manage_options', 'restaurants_admin_page', 'restaurant_admin_page_contents', 'dashicons-format-aside', 6 );
}
function restaurant_admin_page_contents(){
include get_template_directory() . '/inc/restaurants.php';
}

Wordpress sub_menu_page on custom post type

I would love to add a sub menu page on my custom post type called "vouchercodes", but everytime I click on this item in the menu I get "Sorry, you are not allowed to access this page."
I found some articels that "should" work:
https://developer.wordpress.org/reference/functions/add_submenu_page/
https://wordpress.stackexchange.com/questions/63202/how-to-add-a-sub-menu-page-to-a-custom-post-type
But none of those worked for me. I'm sure that I use an full administrator account and I haven't recived any error's in my error logs.
The code I use:
function sens_admin_add_submenus(){
add_submenu_page('edit.php?post_type=vouchercodes', 'Custom Settings', 'Settings', 'manage_options', 'vouchercodes_settings', 'My_Custom_Callback');
}
add_action('admin_init', 'sens_admin_add_submenus');
And my simpel callback function:
function My_Custom_Callback(){
echo "<h1>Welcome to my awsome setting's page</h1>";
}
What am I doing wrong?
Answer Fix from ishio:
Change admin_init to admin_menu
Changing the add_action call from admin_init to admin_menu will correct this.

Wordpress plugin pages

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 &.

Wordpress - Plugin. using remove_action for favorite_actions

Learning php, figure as well as following tutorials doing some practical useful stuff is import. So a wordpress plugin....
Trying to remove the favorite actions box that you get in the wordpress admin header.
<?php
/*
Plugin Name: Hide Favorite Actions
Plugin URI: http://www.mysite.com
Description: Allows you to remove the Screen Options and Help tabs from view
Author: Tai Havard
Version: 1.0
Author URI:
*/
add_action('admin_menu','removeHelpAndScreenOptions');
function removeHelpAndScreenOptions()
{
remove_action('favorite_actions');
}
?>
Plugins activated, function runs, I'm just not sure how to get hold of the favorite_actions correctly and wether remove_action is the correct function for use with the favorite_actions hook.
Thanks
Here's how remove action works:
remove_action( 'hook_name', 'function_name' );
That says you want to remove the function function_name from the hook hook_name. I don't know what the hook and function are fore removing help and screen options, though. If I remember correctly, those tabs are hardcoded into the actual admin pages.
I used that code and got an error in a template.php (presumably expecting an array) The box disappears if you return with an empty element, something like this:
add_filter('favorite_actions', 'no_fav');
function no_fav($actions) {
$actions = array(
'' => array(__(''), '')
);
return $actions;
}
I just deleted the strings, somebody could probably write a more elegant empty array.
In your plugin just add
function rb_ax() {
return;
}
add_filter( 'favorite_actions', 'rb_ax' );
And you're done.
this works for me, wp 3.0.5
/**
* Remove "Favorite actions" from Admin
*/
add_filter('favorite_actions', 'no_fav');
function no_fav($actions) {
return array();
}
I put it in functions.php, but it would probably work fine as a plugin.
returning nothing (void?) works, but writes Warning: Invalid argument supplied for foreach()...

Categories