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
Related
I have a lot of CSS scripts in my WordPress plugin which may affect the other WordPress tags, such as form as an example:
.form {
padding:30px;
background-color:#fff;
}
I can change the CSS, but I want to have a script which only allows the stylesheet to show on the plugin page.
So to clear it up, currently the stylesheet <link> is always in the source code of the admin panel, but I want a script which only puts the stylesheet <link> in the source code when the user is on the plugin page.
You can use get_current_screen:
$screen = get_current_screen();
if ( $screen->id == 'your_plugin_page' ) ){
$custom_css = ".form {.....}";
wp_add_inline_style( 'your_main_style_handle', $custom_css );
}
Update 1:
To add a submenu to your admin menu:
add_action( 'admin_menu', 'your_plugin_admin_menu' );
//Add this to register you styles
add_action( 'admin_init', 'your_plugin_admin_init' );
then:
/**
* Register your stylesheet.
*/
function wpdocs_plugin_admin_init() {
wp_register_style('your-style', plugins_url('scripts/jquery-ui.css',__FILE__ ));
wp_register_script( 'jquery-ui', plugins_url('scripts/jquery-ui.js',__FILE__ ));
}
/**
* Register your plugin page and hook stylesheet loading.
*/
function your_plugin_admin_menu() {
$page = add_submenu_page(...., 'your_plugin_manage_menu' );
//Call 'your_plugin_admin_styles' only on the plugin’s options page
add_action( "admin_print_styles-{$page}", 'your_plugin_admin_styles');
}
/**
* Enqueue our stylesheet.
*/
function your_plugin_admin_styles() {
wp_enqueue_style('your-style');
wp_enqueue_script('jquery-ui');
$custom_css = ".form {.....}";
wp_add_inline_style( 'your-style', $custom_css );
}
/**
* Output our admin page.
*/
function your_plugin_manage_menu() {
// ...
}
you can create style-sheet, and create hook for that style-sheet reference. Then you can add WordPress using add_action(), within plugin call, where you like to call that script. So it will be referenced at head of page for on specified page as needed.
Read more on
https://developer.wordpress.org/reference/functions/wp_enqueue_script/
https://developer.wordpress.org/reference/functions/add_action/
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
}
I want to add a text in admin login page, i searched a lot about this but can't find any thing else a plugin (its my last option).
I also use this filter:
function my_login_logo_url_title() {
return 'Your Site Name and Info';
}
add_filter( 'login_headertitle', 'my_login_logo_url_title' );
But nothing happens; is there any other hook or filter?
Try this :
add_filter( 'login_message', 'my_login_logo_url_title' );
function my_login_logo_url_title() {
return 'Your Site Name and Info';
}
Codex of login_message
I have a page called edit profile, i have installed the profile builder plugin,so the users can edit their profile from front end, if the user is logged in i wants to show the edit profile and logout links in the menu else it is login. how can i achieve that? i am using wp-bootstrap responsive theme, i am new in wordpress development any one please help me.Do i need to change any thing in the header.php file?
<?php
if ( is_user_logged_in() ) {
// i want to add Edit profile and logout to the menu
} else {
// i want to add login to the menu
} ?>
You can use the wp_nav_menu_items filter to add the menu
add_filter( 'wp_nav_menu_items', 'your_custom_menu_item', 10, 2 );
function your_custom_menu_item ( $items, $args ) {
if ( is_user_logged_in() ) {
$items .= 'Show whatever';
} else {
$items .= 'Show whatever';
}
return $items; /* This will have the menu items */
}
Reference
So I have created a wordpress template, and when i log in into wordpress there is a admin bar over main menu. This div wraps the other div's of the website.
My question is:
How can i set div margin-top: i.e. 50 pixels only when there is admin bar, ergo there is a user logged in?
EDIT:
So, this is my code of functions.php and it still doesnt work.
<?php
function new_excerpt_more( $more ) {
return '...<br /><br />Pročitaj još';
}
add_filter('excerpt_more', 'new_excerpt_more');
?>
<?php
if(is_admin_bar_showing() && !is_admin()) {
function link_to_stylesheet() {
?>
<style type="text/css">#wrapper{margin-top:150px;}</style>
<?php
}
add_action('wp_head', 'link_to_stylesheet');
}
?>
EDIT2:
I tried this too... It doesn't work.
<?php
if(is_admin_bar_showing() && !is_admin()) {
function link_to_stylesheet() {
?>
<style type="text/css">body{margin-top:150px;}</style>
<?php
}
add_action('wp_head', 'link_to_stylesheet');
}
?>
To apply top:50px in admin bar when on front end, you may try this (put this in functions.php)
if(is_admin_bar_showing() && !is_admin()) {
function link_to_stylesheet() {
?>
<style type="text/css">#wpadminbar {top:50px;}</style>
<?php
}
add_action('wp_head', 'link_to_stylesheet');
}
To remove admin bar completely, you may try this (put this in functions.php)
add_filter('show_admin_bar', '__return_false');
To remove admin bar from front end only for non-admin user (put this in functions.php)
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
You can setup from your back end (only for yourself) from Users -> Your Profile menu by removing check from
Show Toolbar when viewing site check box
I solved this by adding
<?php if ( is_user_logged_in() ) { ?>
<style type="text/css" media="screen">
body{margin-top:28px !important;}
</style>
<?php } ?>
To the functions.php
Whenever anybody is logged in and has a WPadminbar on the front-end
add this to your functions.php:
function adminbar_theme_setup() {
add_theme_support( 'admin-bar', array( 'callback' => 'custom_admin_bar_css') );
}
add_action( 'after_setup_theme', 'adminbar_theme_setup' );
function custom_admin_bar_css() { ?>
<style>body{margin-top:28px !important;}</style>
<?php
}