create new page within my admin page wordpress - php

I'm creating a new plug for my project I have the like in the admin menu and i have created the landing page I would like to know how i can create a new page within my plugin.
So if I was to click on View All Images how could i navigate to a new page within my plugin?
add_action('admin_menu', 'test_plugin_setup_menu');
add_action('admin_enqueue_scripts', 'my_admin_scripts');
function test_plugin_setup_menu(){
add_menu_page( 'Test Plugin Page', 'Test Plugin', 'manage_options', 'test-plugin', 'test_init' );
}
function test_init(){
echo "<a href='#'>View All Images</a>";
}

Use plugins_url() function
function test_init(){
echo "<a href='<?=plugins_url();?>/your_file.php'>View All Images</a>";
}

Related

Add custom link as a sub menu, below WooCommerce in Admin Area

I'm trying to add a custom link as a submenu, below WooCommerce, under "Orders".
I've tried using the following code, but I'm missing something. How do I add a custom link?
add_action('admin_menu', 'register_my_custom_submenu_page');
function register_my_custom_submenu_page() {
add_submenu_page( 'woocommerce', 'My Custom Submenu Page', 'My Custom Submenu Page',
'manage_options', 'my-custom-submenu-page', 'my_custom_submenu_page_callback' );
}
function my_custom_submenu_page_callback() {
echo '<h3>My Custom Submenu Page</h3>';
}
I used the following code to add a custom link, under WooCommerce:
// Adding custom sub menu
add_action('admin_menu', 'add_custom_link_into_appearnace_menu');
function add_custom_link_into_appearnace_menu() {
global $submenu;
$permalink = 'http://www.cusomtlink.com';
$submenu['woocommerce'][] = array( 'POS Orders', 'manage_options', $permalink );
}

How can i add new item to wordpress sidemenu, with icon on it

How can i add new item to wordpress sidemenu, with icon on it?. So far i have done this , but when clicked , it will redirect to another page. i dont want to redirect to new page . but i want to redirect to logout page
i have searched here on stackoverflow . but no answers so far.
here is what i treid, in functions.php file:
/*
* Logout
*/
add_action('admin_menu', 'logout_menu_item');
function logout_menu_item() {
add_menu_page('Logout', 'Logout', 'manage_options', 'logout', "wp_logout", 'dashicons-external', 999);
}
refrence https://core.trac.wordpress.org/browser/tags/3.2.1/wp-admin/menu.php
<?php
add_action('admin_init', 'logout_menu_item_link');
function logout_menu_item_link() {
global $menu;
$menu[9999] = array(__('Logout'), 'read', wp_logout_url(),'','custom-class','custom-id','dashicons-external');
}
Try Like This:
<?php
add_action('admin_init', 'logout_menu_item_link');
function logout_menu_item_link() {
global $menu;
$menu[9999] = array(__('Logout'), 'manage_options', wp_logout_url());
}
?>
example: Add Icons: https://developer.wordpress.org/resource/dashicons/#album

Wordpress Issue Create Sub Menu

I just making sure that I'm creating the submenu on dashboard correctly.
I'm watching a tutorial on how to create a Setting API on Youtube
The problem is when every I hover on ALLB Option Sitting does pop up with the submenu.
Can anyone help with this quick issue having on WordPress, please explain with detail?
<?php
/*
====================
Admin Page
====================
*/
function allb_admin_page() {
//Generate A Legacy Left Behind Admin Page
add_menu_page( ' ALLB Theme Options', 'ALLB Options', 'manage_options', 'a_legacy_left_behind', 'allb_theme_create_page', 'dashicons-admin-customizer', 110);
//Generate A Legacy Left Behind Admin Sub Page
add_submenu_page('allb_theme', 'ALLB Theme Options', 'Setting', 'manage_options', 'a_legacy_left_behind', 'allb_theme_settings_page');
}
add_action('admin_menu', 'allb_admin_page');
function allb_theme_create_page() {
// genration of our admin page
}
function allb_theme_settings_page() {
// genration of our admin page
}
Here is the answer..
Just copy and past this code in your theme's functions.php file..
Would you please try it once ?
add_action('admin_menu', 'my_menu_pages');
function my_menu_pages(){
add_menu_page('My Page Title', 'My Menu Title', 'manage_options', 'my-menu', 'my_menu_output' );
add_submenu_page('my-menu', 'Submenu Page Title', 'Whatever You Want', 'manage_options', 'my-menu' );
add_submenu_page('my-menu', 'Submenu Page Title2', 'Whatever You Want2', 'manage_options', 'my-menu2' );
}
I hope its helpful for you..
Hope this will solve your issue
function allb_admin_page() {
//Generate A Legacy Left Behind Admin Page
add_menu_page( 'ALLB Theme Options', 'ALLB Options', 'manage_options', 'a_legacy_left_behind', 'allb_theme_create_page');
//Generate A Legacy Left Behind Admin Sub Page
add_submenu_page('a_legacy_left_behind', 'ALLB Theme Options', 'Setting', 'manage_options', 'a_legacy_left_behind_sub', 'allb_theme_settings_page');
}

How to create own backend functionality for WordPress admin panel

I'm trying to call a function in the admin panel to fetch and call database records from the backend.
Here is my code:
// Add the admin options page
function cusplugin_menu_page() {
add_options_page(__('cusplugin Custom Plugin Settings', 'cusplugin'), __('cusplugin Custom Plugin Settings', 'cusplugin'), 'manage_options', 'cusplugin', 'cusplugin_options_page');
}
add_action('admin_menu', 'cusplugin_menu_page');
// Add the admin settings and such
function cusplugin_section_callback() {
echo __('On this page you can add Custom Style (CSS) to change the layout of Contact Form.', 'cusplugin');
}
function cusplugin_field_callback() {
$cusplugin_setting = esc_textarea(get_option('cusplugin-setting'));
echo "<textarea name='cusplugin-setting' rows='10' cols='60' maxlength='1000'>$cusplugin_setting</textarea>";
}
// Display the admin options page
function cusplugin_options_page() {
Here I can't understand what I missed in this code?
Here is the solution ☺ :
// Add the admin options page
function cusplugin_menu_page() {
add_options_page(__('cusplugin Custom Plugin Settings', 'cusplugin'), __('cusplugin Custom Plugin Settings', 'cusplugin'), 'manage_options', 'cusplugin', 'cusplugin_options_page');
}
add_action('admin_menu', 'cusplugin_menu_page');
// Add the admin settings and such
function cusplugin_admin_init() {
register_setting('cusplugin-options', 'cusplugin-setting', 'cusplugin_sanitize_text_field');
add_settings_section('cusplugin-section', __('Description', 'cusplugin'), 'cusplugin_section_callback', 'cusplugin');
add_settings_field('cusplugin-field', __('Custom Style', 'cusplugin'), 'cusplugin_field_callback', 'cusplugin', 'cusplugin-section');
}
add_action('admin_init', 'cusplugin_admin_init');
function cusplugin_section_callback() {
echo __('On this page you can add Custom Style (CSS) to change the layout of Contact Form.', 'cusplugin');
}
function cusplugin_field_callback() {
$cusplugin_setting = esc_textarea(get_option('cusplugin-setting'));
echo "<textarea name='cusplugin-setting' rows='10' cols='60' maxlength='1000'>$cusplugin_setting</textarea>";
}
// Display the admin options page
function cusplugin_options_page() {
// Enter user code here to duiplay options in admin section
}

Add menu page is creating submenu with same title name

I am using this function to create menu option in wp dashboard
add_menu_page(
__('Advertisement Pages'),// the page title
__('Advertisement'),//menu title
'edit_themes',//capability
'a-advertise',//menu slug/handle this is what you need!!!
'display_all_ad',//callback function
'',//icon_url,
'15'//position
);
it is creating menu the name of Advertisement but also creating submenu with the same name.
try this
add_action( 'admin_menu', 'advertisement_menus' );
function advertisement_menus() {
add_menu_page( 'Advertisement Pages', 'Advertisement', 'edit_themes', 'advertisement_slug', 'display_all_ad', '', 15 );
}
//and your call back function
function display_all_ad(){
echo "this is call back";
}

Categories