Open a thickbox-style Lightbox from WP Admin Bar - php

Folks,
I'm currently setting up a WP install. In order for the client to access a custom help-document, I added an additional dropdown menu in the admin-bar as a WP plugin via the following php-file:
<?php
function pub_admin_bar_init() {
if (!is_super_admin() || !is_admin_bar_showing() )
return;
add_action('admin_bar_menu', 'pub_admin_bar_links', 500);
}
add_action('admin_bar_init', 'pub_admin_bar_init');
function pub_admin_bar_links() {
global $wp_admin_bar;
$links = array(
'Chapter 1' => 'http://manual.domain.com/index1.html',
'Chapter 2' => 'http://manual.domain.com/index2.html',
'Chapter 3' => 'http://manual.domain.com/index3.html',
'Chapter 4' => 'http://manual.domain.com/index4.html',
'Chapter ...' => 'http://manual.domain.com/index5.html',
);
$wp_admin_bar->add_menu( array(
'title' => 'Help-Document',
'href' => false,
'id' => 'pub_links',
'href' => false
));
foreach ($links as $label => $url) {
$wp_admin_bar->add_menu( array(
'title' => $label,
'href' => $url,
'parent' => 'pub_links',
'meta' => array('target' => '_blank')
));
}
}
?>
The dropdown works fine and the referenced html-files located in the subdomain of the same domain get called in a new tab.
However, in order to have everything neatly arranged within the WP admin, I'd like to call the menu items in the new admin-bar dropdown via an iframe Lightbox.
I managed to set this up in the Dashboard intro section using the built-in thickbox with the following syntax:
<a style="text-decoration:none;"
href="http://codex.wordpress.org/First_Steps_With_WordPress?
keepThis=true&TB_iframe=true&height=800&width=1200" class="thickbox"
title="sometitle">First Steps with WordPress</a>
This lets me call the html help-files (or any other url for that matter) as an iframe in a thickbox-style overlay.
Now my actual question:
Could someone point me to how I could make the links in the admin-bar dropdown ('Chapter 1' => 'http://manual.domain.com/index1.html', ...) as thickbox-style overlays instead of target=_blank?
Help very much appreciated. Thanks a lot!

'meta' => array('target' => '_blank'),
You forget of ","

Related

How to access an array variable from another PHP file in Wordpress?

I'm adding some custom code to dynamically display Social Network icons in a Wordpress theme, by using the Customize API.
The only problem that prevents it to work as expected is that I need to find a way to access an array variable from another file, not only from the one where it is declared.
First, I've added some code to functions.php, to create some text fields in the Theme Customizer, as follows:
function my_customizer_options($wp_customize) {
// Section
$wp_customize -> add_section ( 'my_social', array(
'title' => __('Social', 'my-theme'),
'description' => __('Social Network profiles', 'my-theme'),
'priority' => 20,
)
);
// Social Networks list
$socialnetworks = array(
// Social Network => Icon Name
'facebook' => 'fa-facebook-f',
'linkedin' => 'fa-linkedin-in',
'instagram' => 'fa-instagram',
'twitter' => 'fa-twitter',
);
// Settings and controls
foreach ($socialnetworks as $key => $value) {
$wp_customize -> add_setting ( $key, array( 'default' => '' ) );
$wp_customize -> add_control ( $key, array(
'type' => 'url',
'label' => __(ucfirst($key), 'my-theme'),
'section' => 'my_social',
));
}
add_action( 'customize_register', 'my_customizer_options' );
This lets me add items to the $socialnetworks array at will, and automatically generates the code required to add settings and controls, without having to do it manually by writing down the same bits of code again and again. I.e., if I need to add more fields for more social networks, I can simply add entries to the $socialnetworks array without duplicating the whole // Settings and controls code.
Until now, it works perfectly, I now have four text fields in the customizer where I can insert URLs of social network profiles. Now I need to access these values from inside the theme template files.
This is the portion of my header.php file where I want to display the icons that link to the respective Social Network profiles:
/*
// Social Networks list
$socialnetworks = array(
// Social Network => Icon Name
'facebook' => 'fa-facebook-f',
'linkedin' => 'fa-linkedin-in',
'instagram' => 'fa-instagram',
'twitter' => 'fa-twitter',
);
*/
// Social Icon
foreach ($my_socialnetworks as $key => $value) {
if ( get_theme_mod($key, '')) { ?>
<i class="fab <?php echo $value ?>"></i>
<?php };
}
This is supposed to retrieve the values inserted in the Customizer with the get_theme_mod() WP builtin functions, and dinamically add the icons and relative links for each inserted URL.
The problem is that in order to make it work, I need to uncomment the $socialnetworks array, and basically redefine it also from inside header.php, while I want instead to access it from functions.php.
A possible problem could be that $socialnetworks is defined inside the my_customizer_options() function; I tried to move it outside, before the function itself, but in this way it even breaks the code in functions.php without solving anything.
I need the correct place and the correct way to define $socialnetworks once and being able to access it from any file of my theme, how should I modify my code in order to achieve this?
As suggested by an user in the comments, I put the array in a function, now I can access the array from anywhere by calling the function.
Here is the modified code:
functions.php:
// Social Networks list
function my_socialnetworks() {
$socialnetworks = array(
// Social Network => Icon Name
'facebook' => 'fa-facebook-f',
'linkedin' => 'fa-linkedin-in',
'instagram' => 'fa-instagram',
'twitter' => 'fa-twitter',
);
return $my_socialnetworks;
}
function my_customizer_options($wp_customize) {
// Section
$wp_customize -> add_section ( 'my_social', array(
'title' => __('Social', 'my-theme'),
'description' => __('Social Network profiles', 'my-theme'),
'priority' => 20,
)
);
$my_socialnetworks = my_socialnetworks();
// Settings and controls
foreach ($socialnetworks as $key => $value) {
$wp_customize -> add_setting ( $key, array( 'default' => '' ) );
$wp_customize -> add_control ( $key, array(
'type' => 'url',
'label' => __(ucfirst($key), 'my-theme'),
'section' => 'my_social',
));
}
add_action( 'customize_register', 'my_customizer_options' );
and header.php:
$my_socialnetworks = my_socialnetworks();
// Social Icon
foreach ($my_socialnetworks as $key => $value) {
if ( get_theme_mod($key, '')) { ?>
<i class="fab <?php echo $value ?>"></i>
<?php };
}

How can I add a link to the Wordpress Admin Bar that runs my function onclick?

I am wanting to add a link to the Wordpress admin bar that will eventually purge all cache. At the moment I am trying to add the link to the admin bar but seem to be having problems.
I have followed a few methods I had found on Google, but for some reason I couldn't get them to work. (I don't know if this is due to the examples being outdated with the version of Wordpress?)
Here is what I am using so far:
function time_to_purge($wp_admin_bar) {
$args = array(
'id' => 'DaylesPurge',
'title' => 'Purge Cache',
'href' => '#',
'meta' => array(
'class' => 'DaylesPurge'
)
);
$wp_admin_bar->add_node($args);
}
add_action('admin_bar_menu', 'time_to_purge', 50);
function PurgeConfirmation() {
document.getElementById("PurgeConfirmation").innerHTML = "Are you sure you
wish to purge the cash?";
}
[EDIT]
Never-mind, this works perfectly. It was a matter of a simple spelling mistake in my code that was preventing it from displaying.
function time_to_purge($wp_admin_bar) {
$args = array(
'id' => 'DaylesPurge',
'title' => 'Purge Cache',
'href' => '#',
'meta' => array(
'class' => 'DaylesPurge'
)
);
$wp_admin_bar->add_node($args);
}
add_action('admin_bar_menu', 'time_to_purge', 50);
function PurgeConfirmation() {
document.getElementById("PurgeConfirmation").innerHTML = "Are you sure you
wish to purge the cash?";
}

ZF2 Navigation Order

I have following problem and i tested it with data from the original documentation of the zend framework 2. I dont know if i miss something or if it is just a missing functionality.
In the following example i create a navigation with two levels and then print the navigation labels with echo. As you can see i set an order for both first level pages and for two second level pages. If you look at my output you can see that only the first level pages are in right order. The second level pages arent in right order.
For every level you put in a navigation greater than level one, the order isnt changed.
Anybody of you have the same problem or can tell me what iam doing wrong? Or is this a not given functionality of the zend-navigation module?
Thanks
Script
$container = new \Zend\Navigation\Navigation(
array(
array(
'label' => 'ACL page 1 (guest)',
'uri' => '#acl-guest',
'resource' => 'nav-guest',
'order' => 777,
'pages' => array(
array(
'label' => 'ACL page 1.1 (foo)',
'uri' => '#acl-foo',
'resource' => 'nav-foo',
'order' => 666
),
array(
'label' => 'ACL page 1.2 (bar)',
'uri' => '#acl-bar',
'resource' => 'nav-bar',
),
array(
'label' => 'ACL page 1.3 (baz)',
'uri' => '#acl-baz',
'resource' => 'nav-baz',
),
array(
'label' => 'ACL page 1.4 (bat)',
'uri' => '#acl-bat',
'resource' => 'nav-bat',
'order' => 111
),
),
),
array(
'label' => 'ACL page 2 (member)',
'uri' => '#acl-member',
'resource' => 'nav-member',
'order' => 555
)
)
);
foreach ($container as $page) {
echo $page->label."<br>";
if ($page->hasPages()) {
foreach ($page->getPages() as $page2) {
echo $page2->label."<br>";
}
}
}
die("ASD");
Output
ACL page 2 (member)
ACL page 1 (guest)
ACL page 1.1 (foo)
ACL page 1.2 (bar)
ACL page 1.3 (baz)
ACL page 1.4 (bat)
ASD
Method $page->getPages() return Array (docs). Elements are ordered only if list is Navigation object.
Try:
foreach ($container as $page) {
echo $page->label."<br>";
if ($page->hasPages()) {
$subpages = new \Zend\Navigation\Navigation($page->getPages());
foreach ($subpages as $page2) {
echo $page2->label."<br>";
}
}
}

How can I add a Submenu to the WordPress Admin Bar

I need to add a dropdown menu to Wordpress in the admin bar to include multiple links. What is the best solution?
I was looking for the answer to this question for a while and couldn't find the solution on here so I thought this would help! I found a great blog post and the perfect solution to my question:
http://davidwalsh.name/add-submenu-wordpress-admin-bar
Like adding functionality to your theme and other admin area, the directives will go in your theme's functions.php file. The code itself should be self explanatory:
function create_dwb_menu() {
global $wp_admin_bar;
$menu_id = 'dwb';
$wp_admin_bar->add_menu(array('id' => $menu_id, 'title' => __('DWB'), 'href' => '/'));
$wp_admin_bar->add_menu(array('parent' => $menu_id, 'title' => __('Homepage'), 'id' => 'dwb-home', 'href' => '/', 'meta' => array('target' => '_blank')));
$wp_admin_bar->add_menu(array('parent' => $menu_id, 'title' => __('Drafts'), 'id' => 'dwb-drafts', 'href' => 'edit.php?post_status=draft&post_type=post'));
$wp_admin_bar->add_menu(array('parent' => $menu_id, 'title' => __('Pending Comments'), 'id' => 'dwb-pending', 'href' => 'edit-comments.php?comment_status=moderated'));
}
add_action('admin_bar_menu', 'create_dwb_menu', 2000);
Setting an id on the parent menu item allows you to use the parent key for submenu items; the rest of the keys are easy to figure out. With the menu created, you simply need to add the WordPress hook and specificity to add it!

add custom module under a menu stream

I am creating my own module and one of its requirement is to have it located in a certain menu. My problem is that the menu is generated using a plugin PyroStreams.
So first things first, I downloaded a copy of the sample module on the Github, then have it place in addons/default/modules/. I refreshed my PyroCMS Admin -> Add-ons -> Modules and see the sample module in there. As stated on the detail.php of this sample module
public function info()
{
return array(
'name' => array(
'en' => 'Test Modules'
),
'description' => array(
'en' => 'My custom module.'
),
'frontend' => FALSE,
'backend' => TRUE,
'menu' => 'content', // You can also place modules in their top level menu. For example try: 'menu' => 'Sample',
'sections' => array(
'items' => array(
'name' => 'Test', // These are translated from your language file
'uri' => 'admin/sample',
'shortcuts' => array(
'create' => array(
'name' => 'sample:create',
'uri' => 'admin/sample/create',
'class' => 'add'
)
)
)
)
);
}
It should appear on the Content menu which is correct. Now, I can't find anything on docs that states instructions on properly mapping the menu for custom modules, so out of initiative I tried to change the value for menu => "content" to menu => "Test Stream" but that didn't work. As shown in the screenshot below, that is where I wanted to place my custom module, under the menu "Test Stream". What am I missing?
Add this method to your detail.php file:
public function admin_menu(&$menu)
{
// Create main menu item
add_admin_menu_place('lang:module:title', 9); // 9 is the placement order of your menu item, it would be after profile
// Create sub-menu
$menu['lang:module:title']['lang:module:submeu1'] = 'admin/add';
$menu['lang:module:title']['lang:module:submeu2'] = 'admin/edit';
}
also set the 'menu'=> false, at your info() method.

Categories