Add menu bar above the WordPress administration bar - wordpress

I wish to add our own service menu above the WordPress administration bar in the administration area. I do not wish to hack the WordPress system, but I cannot find a hook.
Is there a method?

You can add extra menu items in your administrator menu bar instead of removing/replacing the menu bar.
Below is an example which will insert one menu item with two sub menu items. Just paste the code in your functions.php and log in to your WordPress as admin. If everything goes right then you can see an extra menu in your administrator bar. To accomplish this, WordPress provided the admin_bar_menu hook:
add_action('admin_bar_menu', 'my_custom_menu', 1000);
function my_custom_menu()
{
global $wp_admin_bar;
if(!is_super_admin() || !is_admin_bar_showing()) return;
// Add Parent Menu
$argsParent=array(
'id' => 'myCustomMenu',
'title' => 'Services',
'href' => false
);
$wp_admin_bar->add_menu($argsParent);
// Add Sub Menus
$argsSub1=array(
'parent' => 'myCustomMenu',
'title' => 'Visit Heera IT',
'href' => 'http://heera.it',
'meta' => array('target' => '_blank')
);
$wp_admin_bar->add_menu($argsSub1);
$argsSub2=array(
'parent' => 'myCustomMenu',
'title' => 'Visit StackOverflow',
'href' => 'http://stackoverflow.com/',
'meta' => array('target' => '_blank')
);
$wp_admin_bar->add_menu($argsSub2);
}
For more details, you can visit Codex.

You can also accomplish this using a plugin that allows you to easily customize the content and appearance of the WordPress Admin Bar. Here are a few plugins to consider:
Plugin #1
Plugin #2
Plugin #3

$wp_admin_bar->add_menu(array
(
"parent" => "bba_booking_bank",
"id" => "bba_booking_bank_location",
"title" => $bba_location_providers_wizard_setup,
"href" => admin_url("admin.php?page=booking_bank"),
));
$wp_admin_bar->add_menu(array
(
"parent" => "bba_booking_bank",
"id" => "bba_booking_bank_calendar",
"title" => $bba_booking_bank_calendar,
"href" => admin_url("admin.php?page=bba_booking_calendar"),
)
);

Related

How Do you Properly Add An Image Control To Wordpress Customizer?

Wordpress admin customizer control is incomplete. How can I fix it?
My Code:
$wp_customize->add_setting('swag_header_media');
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'swag_header_media', array(
'label' => 'Current Image Selection',
'section' => 'swag_header_media_section',
'active_callback' => 'header_show_image_selection_settings_callback',
'settings' => 'swag_header_media'
)));
The results are incomplete. I can select an image from the and the image show up in the frontend of the theme. However, the image selected does not show that it is being used in the control.
In other words(see screenshot), you can see the background image being used(phone), but it doesn't show that it being used in the admin customizer control. Its says "Current Image Selection", but it's empty with no buttons below it to change or remove it.
When you inspect the page, is there any errors?
It is a bit hard to figure out with so little data.
Try this 'settings' => 'themename_theme_options[swag_header_media]',
Try:
$wp_customize->add_setting('themename_theme_mods[swag_header_media]',array(
//'default' => 'image.jpg',
//'capability' => 'edit_theme_options',
//'type' => 'option'
));
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'swag_header_media', array(
'label' => 'Current Image Selection',
'section' => 'swag_header_media_section',
'active_callback' => 'header_show_image_selection_settings_callback',
'settings' => 'themename_theme_mods[swag_header_media]'
)));
if that doesnt work,I suggest to change swag_header_media to other keyname. I suspect that key name might be used by other control/funtion too. So, try to add any 1 letter to that keyname, and see the result. Also, if you have any caching on site, turn it off.
also, the problem could be with callback,

WordPress: Can you programmatically create page templates?

I am currently building a React/Redux theme for WordPress using the WordPress API. I need to add Page Templates to my theme. I can do this by creating almost empty files like:
<?php
/* Template Name: My Template */
?>
But I would like to create these 'Page Templates' programmatically.
The functionality I required is to be able to select a 'Page Template' inside the WordPress CMS and have this come down on the API. This functions as expected if the 'Page Templates' are created as above.
Is this possible?
This can be achieved using the theme_page_templates filter.
CONST CUSTOM_PAGE_TEMPLATES = array(
array('slug' => 'home', 'label' => 'Home'),
array('slug' => 'content-page', 'label' => 'Content Page'),
array('slug' => 'ordering', 'label' => 'Ordering'),
array('slug' => 'reviews', 'label' => 'Reviews')
);
/**
* Add file-less page templates to the page template dropdown
*/
add_filter('theme_page_templates', function($page_templates, $wp_theme, $post) {
foreach(CUSTOM_PAGE_TEMPLATES as $template) {
// Append if it doesn't already exists
if (!isset($page_templates[$template['slug']])) {
$page_templates[$template['slug']] = $template['label'];
}
}
return $page_templates;
}, PHP_INT_MAX, 3);

How to implement styling in page?

I am making custom h1 styling menu for customize panel in wordpress site but I don't know how to include the custom h1 styles in html structure of page.
$wp_customize->add_section( 'h1_styles' , array(
'title' => __('H1 Styles','wptthemecustomizer'),
'panel' => 'design_settings',
'priority' => 100
) );
$wp_customize->add_setting(
'wpt_h1_color',
array(
'default' => '#222222',
'transport' => 'postMessage'
)
);
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize,
'custom_h1_color',
array(
'label' => __( 'Color', 'wptthemecustomizer' ),
'section' => 'h1_styles',
'settings' => 'wpt_h1_color'
)
)
);
I know I have to do something like this :-
if( get_theme_mod( 'wpt_h1_color') != "" ):
/* code */
endif;
But I want to know should I apply styles directly in html in head section with the above code or It can be done through function in functions.php.
Thanks for your help !
You can do it directly in html outputing <style></style> and some css in there (which is faster than loading external files, and Google Speed Insights maybe not recommends, but approves that way). You can also wp_enqueue_style() if you want to.

Adding a tab to the node edit form in Drupal

I have added a tab to the node edit form in Drupal 7 like this (code snippet from hook_menu implementation, irrelevant lines removed):
'node/%/products' => array(
'title' => t('Products'),
'page callback' => 'some_function',
'page arguments' => array(
1
),
'access callback' => TRUE,
'type' => MENU_LOCAL_TASK
)
The tab shows up and works, however, the page is shown in the site's default theme, not in the admin theme. Also the other tabs are missing from the page that is displayed.
I tried fixing this by including this inside an implementation of hook_admin_paths, but it didn't make a difference:
return array(
'node/%/products' => TRUE,
);
How can I enforce my page to show in the admin theme and display the other tabs for the node edit form (such as "Edit", "Revisions" etc.) ?
EDIT: The box Use the administration theme when editing or creating content at admin/appearance is ticked, and system-defined pages such as node/%/edit display in the admin theme, but my new page does not.
I found out what I was doing wrong. In hook_menu % is used to denote an argument; in hook_admin_paths, these have to be replaced by asterisks. The following change to my implementation of hook_admin_paths solved it:
return array(
'node/*/products' => TRUE,
);
On /admin/appearance page, at the bottom of the page where you set the administration menu, check the value of the tickbox "Use the administration theme when editing or creating content".
I had the same problem and I solved with the following hook_menu :
<?php
function <mymodulename>_menu() {
$items = array();
$output['node/%node/mypath'] = array(
'title' => t('Title'),
'type' => MENU_LOCAL_TASK,
'page arguments' => array('node', 1),
'page callback' => 'callback_function',
'theme callback' => 'variable_get',
'theme arguments' => array('admin_theme'),
)
}
function callback_function() {
return 'My New Page.';
}
I think you need to have %node inside the path because that's the right way to "auto load" the node (Drupal take care of this) and pass it as an argument to callback_function where you can use the loaded node.

Drupal 6: how to display node with its local tasks tabs in menu item

In my case each user has a gallery. Gallery is a node. I'd like to hide default "Create content" menu and add custom menu link that links to user gallery.
function custom_menu() {
$items = array();
$items['galleries/editgallery'] = array(
'title' => 'Edit gallery',
'description' => 'edit gallery',
'page callback' => 'custom_edit_gallery',
'access callback' => 'custom_access_editgallery',
);
return $items;
}
function custom_edit_gallery (){
global $user;
$node = node_load ($user->gallerynid);
return node_page_view ($node);
}
But it doesn't show local tasks tabs(like "Edit" tab).
You would need to add them yourself.
With normal theming, you could create a custom template file or overwrite a theme function etc to add the tabs you want.
You could also do this within hook_menu, by using MENU_LOCAL_TASK and MENU_DEFAULT_LOCAL_TASK, see the api.

Resources