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
}
Related
I am working on a plugin and I am creating a meta box on my page using the below code but it's not displaying anything.
Any idea where is the issue with my code?
class bt_dashboard {
function __construct() {
add_meta_box( 'metaboxes-sidebox-1', 'Sidebox 1 Title', array( $this, 'welcome_bt' ), 'welcomebt', 'advanced', 'default' );
}
function setup() {
// setup class, maybe add hooks
}
function welcome_bt() {
?>
<h2>Wellcome to metabox</h2>
<?php
}
}
Meta box not displaying on the plugin page
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 );
}
I am attempting to create a plugin that uses the setting API to add some options for my user. I currently create a new menu page and then create a setting section. This all works fine but then my callback function isn't being called. Can anyone see why?
function register_my_custom_menu_page() {
add_menu_page( 'custom menu title', 'custom menu', 'manage_options', 'menu-slug', 'sandbox_initialize_theme_options' );
}
add_action( 'admin_menu', 'register_my_custom_menu_page' );
function sandbox_initialize_theme_options() {
// First, we register a section. This is necessary since all future options must belong to one.
add_settings_section(
'general_settings_section', // ID used to identify this section and with which to register options
'Sandbox Options', // Title to be displayed on the administration page
'sandbox_general_options_callback', // Callback used to render the description of the section
'menu-slug' // Page on which to add this section of options
);
} // end sandbox_initialize_theme_options
function sandbox_general_options_callback() {
echo '<p>Select which areas of content you wish to display.</p>';
} // end sandbox_general_options_callback
I am going to make a WordPress plugin to change the Login Logo. But Now I am trying to make a option panel and how user can edit the plugin function admin panel.
//Function For Login Logo Change
function awesome_custom_login_logo() {
echo '<style type="text/css">
h1 a { background-image:url(/images/logo.jpg) !important; }
</style>';
}
add_action('login_head', 'awesome_custom_login_logo');
//Function For Login Logo Url
function awesome_login_logo_url() {
return get_bloginfo( 'url' );
}
add_filter( 'login_headerurl', 'awesome_login_logo_url' );
//Function For Login Logo Title
function awesome_login_logo_url_title() {
return 'Your Site Name and Info';
}
add_filter( 'login_headertitle', 'awesome_login_logo_url_title' );
Any Idea about create a menu, submenu, option page etc ?
You can take refrence from wordpress function admin_menu and add_sub_menu_page
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>";
}