WordPress - Fully Customize Admin Bar? - wordpress

Is there a straightforward way to fully customize the backend WP admin (top) bar? I want to replicate the frontend nav with logo/styling and a few links. I've googled this to no end and haven't found any clear cut way to "create your own" admin bar (avoiding plugins).
My customers access all of their paid content on the backend of WP, so I'd like to mimic the branding/logo/style/links of the frontend. Thank you to any helpful answers/resources!

You can use the admin_bar_menu action to customize the default admin bar by removing/modifying existing menus and adding new ones. You can also add sub-menus too.
It would take a bit of work to completely overhaul it, but here is the basic syntax for creating and adding menus to it (place in functions.php or equivalent):
add_action('admin_bar_menu', 'nebula_admin_bar_menus', 800);
function nebula_admin_bar_menus($wp_admin_bar){
$wp_admin_bar->add_node(array(
'id' => 'nebula-github',
'title' => 'Nebula Github',
'href' => 'https://github.com/chrisblakley/Nebula',
'meta' => array('target' => '_blank')
));
$wp_admin_bar->add_node(array(
'parent' => 'nebula-github',
'id' => 'nebula-github-issues',
'title' => 'Issues',
'href' => 'https://github.com/chrisblakley/Nebula/issues',
'meta' => array('onclick' => 'exampleFunction(); return false;') //JavaScript function trigger just as an example.
));
}
This method could be done in a loop to mimic your frontend nav. HTML can be included in this and styles can also be applied to the elements as needed. You can even run JavaScript functions on click events if you wanted to (example in snippet above).
I hope this is in the ballpark of what you're looking to do, or at least gets you headed in the right direction.

Related

How to add/Modify Redux Framework options in Child Theme

I am using a paid theme which is using Redux Framework. I am trying to add a new field in Footer Options. I am able to add this field in options but only in print_r() function it is showing not showing in Themes Options Panel.
function add_another_section_bl($sections){
$sections[12]['fields'][] = array(
'id' => 'rd_footer_message_1',
'type' => 'textarea',
'title' => __('Text 2 to display in footer under bar', 'thefoxwp'),
'subtitle' => __('write your copyright information or anything you\'d like.', 'thefoxwp'),
'validate' => 'html', //see http://codex.wordpress.org/Function_Reference/wp_kses_post
'default' => 'Copyright 2015 Tranmautritam\'s team | All Rights Reserved'
);
return $sections;}
add_filter("redux/options/rd_data/register", 'add_another_section_bl');
In array data it is showing the required data but not in Options Panel in wordpress dashboard.
Kindly get me out of this.
There's a much simpler approach if you use the Redux API:
https://docs.redux.io/configuration/redux-api.html
You can modify, add, update any section or field before it is rendered. Please note, you may have to put your code within hooks. Also please note the Redux 4 method names have changed from setArgs to set_args (camelcase to non).
Otherwise, you will have all you need.

Drupal 7 Creating Full Page Custom Module

I want to create a full page, custom module. By this, I mean a module that is not wrapped into the main Drupal sites them. Here is my code:
myapp.module:
function myapp_menu()
{
$result = array();
$result['myapp/home'] = array(
'title' => 'My App Title', // Title of our page
'description'=> 'My App Web Site', // Description of our page
'page callback' => 'myapp_function',
'access arguments' => array('access content'), // permission to access this page
'type' => MENU_NORMAL_ITEM, // type of menu item
);
return $result;
}
function myapp_function(){
return theme('my_custom_template');
}
function myapp_theme(){
return array(
'my_custom_template' => array(
'template' => 'myapp-page',
),
);
}
myapp-page.tpl.php
Hello World
The problem is that, when the page is displayed, it is still kept within the main Drupal Sites main theme. I would like to make this page its own, full page, site. Can anyone help with doing this?
thanks
You can hack like this :
function myapp_function(){
print theme('my_custom_template');
exit;
}
Also you can use declaration options listed in https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_theme/7.x
Parameters
array $existing: An array of existing implementations that may be used
for override purposes. This is primarily useful for themes that may
wish to examine existing implementations to extract data (such as
arguments) so that it may properly register its own, higher priority
implementations.
$type: Whether a theme, module, etc. is being processed. This is
primarily useful so that themes tell if they are the actual theme
being called or a parent theme. May be one of:
'module': A module is being checked for theme implementations.
'base_theme_engine': A theme engine is being checked for a theme that
is a parent of the actual theme being used. 'theme_engine': A theme
engine is being checked for the actual theme being used. 'base_theme':
A base theme is being checked for theme implementations. 'theme': The
actual theme in use is being checked. $theme: The actual name of
theme, module, etc. that is being being processed.
$path: The directory path of the theme or module, so that it doesn't
need to be looked up.

Change cache settings programmatically in Drupal 7

I have a block which displays list of RSS feed from an external site. I want to keep caching other blocks except the mentioned block. Howto do that?
For example, I have blockA, blockB and blockC. I only want to change the blockB's cache settings permamently to DRUPAL_NO_CACHE and leave other blocks as they are and I want to do that programmatically.
You can change the caching roles in the specific module that creates youre block.
In the block info like beneath:
function pref_block_info() {
return array(
'pref_main' => array(
'info' => t('Display flash game for auth. users'),
'cache' => DRUPAL_NO_CACHE,
),
'pref_winner' => array(
'info' => t('Show the winner of the last week.'),
'cache' => DRUPAL_NO_CACHE,
),
'pref_leader' => array(
'info' => t('Show the leader of the current week.'),
'cache' => DRUPAL_NO_CACHE,
),
'pref_top' => array(
'info' => t('Show the top 10 of the current week.'),
'cache' => DRUPAL_NO_CACHE,
),
);
}
The answer given by Jurgo is perfectly right, if you are defining the block within your own module.
In case if you want to change the caching behavior of a block written by some other module then you can use the function mymodule_block_list_alter
function mymodule_block_list_alter(&$blocks, $theme, $code_blocks) {
// Remove the caching on rss feeds block.
// Here rss-feeds is the unique key for the block
$blocks['rss-feeds']['cache'] = DRUPAL_NO_CACHE;
}
Where do the blocks come from? That's important. As Jurgo said, you can specify it in hook_block_info if it's a custom module. If they are views blocks, there is a caching setting per display within views that handles this. If they are blocks provided by some other module, you'd need to directly query the database to change the block's caching setting.
As a general note, to display RSS feeds, just use Feeds and Views. Then you don't write custom code at all for any of this.
This will reduce the work by going to performance settings page (admin/settings/performance) & clicking "cleared cached data" by scrolling down.
But make sure that this page is only accessed by administrator.
For Drupal 7 is same as Drupal 6:
<?php
drupal_flush_all_caches();
drupal_set_message('cache flushed.');
?>

Menu path with wildcard

You can't use wildcards in menu paths? A quick summary of my problem (which I've made sure makes sense, so you're not wasting your time): I have a menu which i'm showing on node pages of a certain content-type. My path to a node page would be like...
events/instal2010
...where instal2010 would be the name of an event (event is the content-type).
I'm using the Context and Menu Block modules to place a menu in the sidebar on that page...
Event (the default active item)
Programme
Visitor info
Book tickets
... where the path for Programme would be
events/instal2010/programme
So for this to work for many different events, those menu items need a wildcard in their path, e.g.
events/*/programme
Perhaps it's time to ditch menus and just use a block with php to determine what page we're on from the URL.
Any advice from experienced hands would be awsome, thanks.
You cannot create menu items with wildcards from the administrative interface of Drupal, but you can create menu items with wildcards in a module. I would recommend creating a custom module that uses hook_menu() to create the menu items. An example implementation would look something like:
function YOURMODULE_menu() {
$items = array();
$items['events/%/programme'] = array(
'title' => 'Programme',
'description' => 'Loads a program page',
'page callback' => 'YOUR CUSTOM FUNCTION NAME', // Custom function used to perform any actions, display the page, etc
'page arguments' => array(1), // Passes wildcard (%) to your page callback function
'access callback' => TRUE, // Change if you want to control access
'type' => MENU_NORMAL_ITEM, // Creates a link in the menu
'menu_name' => 'primary-links' // Adds the link to your primary links menu, change if needed
);
return $items;
}
In $items['events/%/programme'] = array(, the % is the wildcard and it will be passed to your page callback function. It may be helpful to read more about hook_menu() and the Anatomy of hook_menu may also help as well.

Drupal 6 - force page view to display a different view?

Kind-of a crazy question here...
I have a view display that's set up as a page. It looks great in theme A (desktop), but terrible in theme B (mobile). So I made a different version of the view for theme B. Since the desktop/mobile 'sites' are the same just with different themes, the url for this page will be the same regardless of hte theme selected.
So I would like to be able to point the user to:
mysite/this_crazy_view
and have the returned page select the proper view depending on which theme it's in. I know that if I were using blocks I would just assign the appropriate blocks to the page in question on a theme-by-theme basis, but since the displays are using page display I don't know what the right approach would be.
I would rather not rebuild the views as blocks if I can help it (if it can't be helped, so be it...) so I was hoping there was some way to conditionally load the view via the tpl.php file or something like that...
The code I'm using in my module (per #Clive 's recommendation below) is:
<?php
function bandes_custom_hook_menu() {
$items['charley_test'] = array(
'title' => 'Title',
'access arguments' => array('access content'),
'page callback' => 'bandes_custom_set_page_view',
'type' => MENU_NORMAL_ITEM );
return $items;
}
function bandes_custom_set_page_view() {
global $theme_key;
$view_name = $theme_key == 'mobile_jquery' ? 'course_views_mobile' : 'course_views';
$display_id = 'page_5';
return views_embed_view($view_name, $display_id);
}
?>
I've cleared the cache a number of times and tried a variety of different paths in the $items array. The course_views and course_views_mobile both definitely work on their own.
I was also wondering if I could just create a views-view--course-views--page-5.tpl.php which contains almost nothing aside from the views_embed_view(course_views_mobile, page_5) part? (Only on one of the two themes...)
Actually I think the answer was simpler than all of the above. The redirect thing was giving me fits, so I removed the module, reset the paths to what I had been using, and tried the template/theme approach instead.
This is: views-view--course-views--page-5.tpl.php, only used on the mobile theme, but referring to the non-mobile view (kinda gives me a headache, but it works)
<?php
//get the view
print "IM IN YR VUE, MESSING THNGZ UP!"; //yeah, I'm going to remove this part...
$view_name="course_views_mobile";
$display_id="page_5";
print views_embed_view($view_name, $display_id);
?>
Any reason that shouldn't work? (Or why it is a really bad idea?)
Me again :)
I just thought of an easy-ish way around this actually; if you can change the URL of your views to something other than the path you want to access them at (any path would do) you could implement a hook_menu() function in a custom module for that path, to make the choice depending on your theme:
function MYMODULE_hook_menu() {
$items['this_crazy_view'] = array(
'title' => 'Title',
'access arguments' => array('access content'),
'page callback' => 'MYMODULE_crazy_view_page',
'type' => MENU_CALLBACK // or MENU_NORMAL_ITEM if you want it to appear in menus as usual
);
return $items; // Forgot to add this orginally
}
function MYMODULE_crazy_view_page() {
global $theme_key;
$view_name = $theme_key == 'foo' ? 'theView' : 'theOtherView';
$display_id = 'page_1'; // Or whatever the page display is called
return views_embed_view($view_name, $display_id);
}
That should do the trick

Resources