Buddypress: add custom component to members section - php

For each member page you have a selection of components (e.g. profile, settings, activity...)
What I am trying to do is add a new component called jobs to each page. I understand how to add the link to the navigation bar. It is just creating the page that is confusing me.
Do I add a new directory, if so how do I let buddypress know.
Having a url structure like:
example.com/member/username/jobs
is important.
Thanks!

The global variable $bp is where you want to insert the new Jobs component. By dumping the global variable $bp, you can see all of the elements contained in it, including all of the components. To easily dump $bp, add the following to the top of member-header.php:
global $bp;
foreach ( (array)$bp as $key => $value ) {
echo '<pre>';
echo '<strong>' . $key . ': </strong><br />';
print_r( $value );
echo '</pre>';
}
The array within $bp that you want to add the component 'Jobs' to is bp_nav.
In functions.php add the following:
add_action( 'bp_setup_nav', 'add_subnav_items', 100 ); //Priority must be higher than 10
function add_subnav_items() {
global $bp;
//Jobs tab
$tab_array['name'] = 'Jobs';
$tab_array['link'] = $bp->displayed_user->domain.'jobs';
$tab_array['slug'] = 'jobs';
$tab_array['parent_url'] = $bp->displayed_user->domain;
$tab_array['parent_slug'] = bp_core_get_userlink(bp_loggedin_user_id());
$tab_array['css_id'] = 'jobs';
$tab_array['position'] = 100;
$tab_array['user_has_access'] = '1';
$tab_array['screen_function'] = 'bp_jobs_screen_general';
$bp->bp_nav['jobs'] = $tab_array; //Add new array element to the 'bp_nav' array
}
The 'screen_function' is a function that handles the screen that is to be shown when 'Jobs' tab is selected so you must add the function 'bp_jobs_screen_general' in functions.php:
function bp_jobs_screen_general() {
bp_core_load_template( apply_filters( 'bp_jobs_screen_general','members/single/jobs' ) );
}
This function looks for a template file named jobs.php in members/single/ so you must create it. For an example on how the screen_function's work, refer to a function for displaying Groups screens within wp-content/plugins/buddypress/bp-groups/bp-groups-screens.php.

Related

Wordpress: nav_menu_link_attributes won't accept variable as attribute

I am trying to take a custom color that was chosen by the user in the Customizer, and add it as an html attribute to the links that are outputted by a specific menu.
Here is my code so far:
// Gets the footer link color, if assigned by user.
if (get_theme_mod('theme_footer_link_color')) {
$footerLinkColorAttribute = 'color:' . get_theme_mod('theme_footer_link_color', 'default_value') . ';';
}
function add_customizer_link_color_attribute_to_footer_menu_links($atts, $item, $args){
if ($args->theme_location == 'footerNavLocation') {
$atts['style'] = $footerLinkColorAttribute;
}
return $atts;
}
add_filter('nav_menu_link_attributes', 'add_customizer_link_color_attribute_to_footer_menu_links', 10, 3);
My problem is that the style attribute is taking $footerLinkColorAttribute as plain text, instead of a variable that contains the text set by the user.
How can I get it to be taken as a variable?
I figured it out. I was defining the variable outside of the function, but needed to define it inside of the function:
function add_customizer_link_color_attribute_to_footer_menu_links($atts, $item, $args){
if ($args->theme_location == 'footerNavLocation') {
// If there is a footer link color assigned in the Customizer, this gets it ready to be inserted as an attribute into the link menu link text.
if (get_theme_mod('lets_get_started_footer_link_color')) {
$footerLinkColorAttribute = 'color:' . get_theme_mod('lets_get_started_footer_link_color', 'default_value') . ';';
}
$atts['style'] = $footerLinkColorAttribute;
}
return $atts;
}
add_filter('nav_menu_link_attributes', 'add_customizer_link_color_attribute_to_footer_menu_links', 10, 3);

Fetching revolution slider shortcodes

I'm trying something new here. I have a Wordpress custom theme. I have Advanced custom fields all setup. I'm using the advanced custom field's load_field function on a "select" field with "choices". What I want to basically do is to show the revolution slider shortcodes as choices for this field... This is my code in the functions.php file. Any help would be highly appreciated! :)
<?php
function my_acf_load_field( $field ) {
$field['choices'] = array(
<-- WANT REVOLUTION SLIDER SHORTCODES HERE -->
);
return $field;
}
// all
// add_filter('acf/load_field', 'my_acf_load_field');
// type
add_filter('acf/load_field/type=select', 'my_acf_load_field');
// name
// add_filter('acf/load_field/name=my_select', 'my_acf_load_field');
// key
// add_filter('acf/load_field/key=field_508a263b40457', 'my_acf_load_field');
?>
Answer updated April 22, 2020: For Slider Revolution V6, the function getAllSliderAliases() has been replaced with get_sliders() and returns an array of objects instead of an array of strings. Source.
functions.php for Slider Revolution V6
function my_acf_load_field( $field ) {
if ( class_exists( 'RevSlider' ) ) {
$rev_slider = new RevSlider();
$sliders = $rev_slider->get_sliders();
if(count($sliders) > 0) {
foreach($sliders as $slider)
{
$field['choices'][$slider->alias] = $slider->title;
}
} else {
$field['choices'] = array( 'none' => 'No sliders exist. You must create one first.' );
}
} else {
$field['choices'] = array( 'none' => 'Slider Revolution plugin was not found.' );
}
return $field;
}
//Only place these options on a specific select field with the alias "rev_slider"
add_filter('acf/load_field/name=rev_slider', 'my_acf_load_field');
And then on the template or whatever page you're using the custom field on, I placed the actual shortcode there instead.
page.php
$slider_alias = get_field('rev_slider');
if(!empty($slider_alias)) {
echo do_shortcode(sprintf('[rev_slider alias="%s"]', $slider_alias));
}
Old Answer for versions of Slider Revolution before V6
For whatever reason, my $sliders variable from Andrew M's answer wasn't returning anything, so I came up with this solution instead based on Themepunch's documentation for displaying any slider at random and this article for checking if the class exists first to avoid errors.
functions.php for Slider Revolution versions before V6
function my_acf_load_field( $field ) {
if ( class_exists( 'RevSlider' ) ) {
$rev_slider = new RevSlider();
$slider_aliases = $rev_slider->getAllSliderAliases();
if(count($slider_aliases) > 0) {
foreach($slider_aliases as $slider_alias)
{
$field['choices'][$slider_alias] = $slider_alias;
}
} else {
$field['choices'] = array( 'none' => 'No sliders exist. You must create one first.' );
}
} else {
$field['choices'] = array( 'none' => 'Slider Revolution plugin was not found.' );
}
return $field;
}
//Only place these options on a specific select field with the alias "rev_slider"
add_filter('acf/load_field/name=rev_slider', 'my_acf_load_field');
What you could do is the following. Revolution slider slider items are stored in a table called wp_revslider_sliders (the wp_ part may change based on how you set up the database - check the table name first)
You can query this table using the Wordpress $wpdb global and get back the alias field - which is used as the shortcode. So in the body of your load field function you could try something like this
function my_acf_load_field( $field ) {
global $wpdb;
$query = sprintf('select r.id, r.alias from %srevslider_sliders r',$wpdb->prefix);
$sliders = $wpdb->get_results($query,OBJECT);
foreach($sliders as $slider)
{
//This just formats the string with the correct short code
$field['choices'][$slider->alias] = sprintf('[rev_slider alias="%s"]',$slider->alias);
}
return $field;
}
That should populate your dropdown with the right options - or at least get you on the right path
From Slider Revolution V6 the method "getAllSliderAliases" is not available anymore.
New Code is :
functions.php
function my_acf_load_field($field)
{
if (class_exists('RevSlider')) {
$rev_slider = new RevSlider();
$slider_aliases = $rev_slider->get_sliders();
if (count($slider_aliases) > 0) {
foreach ($slider_aliases as $slider_alias) {
$field['choices'][$slider_alias->alias] = $slider_alias->alias;
}
} else {
$field['choices'] = array('none' => 'No sliders exist. You must create one first.');
}
} else {
$field['choices'] = array('none' => 'Slider Revolution plugin was not found.');
}
return $field;
}
//Only place these options on a specific select field with the alias "rev_slider"
add_filter('acf/load_field/name=rev_slider', 'my_acf_load_field');
page.php
$slider_alias = get_field('rev_slider');
if(!empty($slider_alias)) {
echo do_shortcode(sprintf('[rev_slider alias="%s"]', $slider_alias));
}

Moodle - Adding an element to the settings menu

I'm trying to develop a plugin in Moodle. One of the requirements is to add an element to the Settings Menu, in which I was able to achieve with the help of this guide
https://docs.moodle.org/dev/Local_plugins#Adding_an_element_to_the_settings_menu
And this is my code in local/myplugin/lib.php
<?php
function local_myplugin_extends_settings_navigation($settingsnav, $context) {
// question_extend_settings_navigation
global $CFG, $PAGE;
// Only add this settings item on non-site course pages.
if (!$PAGE->course or $PAGE->course->id == 1) {
return;
}
// Only let users with the appropriate capability see this settings item.
/*if (!has_capability('moodle/backup:backupcourse', context_course::instance($PAGE->course->id))) {
return;
}*/
if ($settingnode = $settingsnav->find('courseadmin', navigation_node::TYPE_COURSE)) {
$strfoo = get_string('classrecord', 'local_myplugin');
$url = new moodle_url('/course/classrecord.php', array('id' => $PAGE->course->id));
$foonode = navigation_node::create(
$strfoo,
$url,
navigation_node::NODETYPE_LEAF,
'myplugin',
'myplugin',
new pix_icon('i/grades', $strfoo)
);
if ($PAGE->url->compare($url, URL_MATCH_BASE)) {
$foonode->make_active();
}
$settingnode->add_node($foonode);
}
}
?>
I allowed the students to see the element "Class Record" in the settings menu
My concern is that how can I hide/show Class Record I added?
Any ideas would be great!
If you want only certain users to see the link, then create an appropriate capability in local/myplugin/db/access.php, e.g. 'local/myplugin:viewclassrecord', defaulting to being assigned to the 'student' role. Then check for it in the function you have defined.
e.g.
if (!has_capability('local/myplugin:viewclassrecord', $context)) {
return;
}

show more than one pagination in same template file in drupal7

In my custom template tpl file, i am showing two sections (div content) of data, one from each function of my custom module.
The data also has pagination for it, displayed below.
Initially only one block of data will be displayed. Other block of data will be hidden on the page, unless the user clicks on a tab in the page.
Now my question is, how can i show individual paginations for each of my blocks in the same page ?
If i click on a page link in block 1 and go to its page, the pagination links for another block must not be affected.
How to achieve this in Drupal 7?
// my custom module code below
// function one
func one() {
$page = strtolower($page);
$query = db_select('keyword', 'k');
$query->groupBy('k.res');
$stories = $query->extend('PagerDefault')->limit(10)->execute();
return $stories;
}
// function two
func two() {
$page = strtolower($page);
$query = db_select('videos', 'v');
$query->groupBy('v.res');
$videos= $query->extend('PagerDefault')->limit(10)->execute();
return $videos;
}
// in my custom template page
// below is first section in same page
$block_content = fun one(arg(1));
$args = array( 'parameters' => array('pg' => 'one'));
print (theme ('pager',$args));
foreach($block_content as $content)
{
// doing something to display
}
print (theme ('pager',$args));
// below is second section in same page
$block_content = fun two(arg(1));
$args = array( 'parameters' => array('pg' => 'two'));
print (theme ('pager',$args));
foreach($block_content as $content)
{
// doing something to display
}
print (theme ('pager',$args));
You can use the PagerDefault::element() method to set a unique element ID for the pager:
// First one
$stories = $query->extend('PagerDefault')->element(0)->limit(10)->execute();
// Second one
$videos = $query->extend('PagerDefault')->element(1)->limit(10)->execute();
Then use the respective element ID in the theme call:
// First one
$args = array('element' => 0, ...);
print theme('pager', $args);
// Second one
$args = array('element' => 1, ...);
print theme('pager', $args);

Add custom tab to all pages in MediaWiki

I've got a MediaWiki site and I would like to add a tab with a very simple "read article" functionality (without any edit/comment options). I followed the manual and tried to create a namespace for it, but it still doesn't work.
The snippet from LocalSettings.php looks like this:
define("NS_ARTICLE", 500);
$wgExtraNamespaces[NS_ARTICLE] = "Article";
$wgNamespaceProtection[NS_ARTICLE] = array( '' );
$wgNamespacesWithSubpages[NS_ARTICLE] = true;
$wgContentNamespaces[] = NS_ARTICLE;
I created new methods in Title.php:
public function getReadPage() {
return Title::makeTitle( MWNamespace::getRead( NS_ARTICLE ), $this->getDBkey() );
}
In Namespace.php:
public static function getRead( $index ) {
self::isMethodValidFor( $index, __METHOD__ );
return self::isTalk( $index )
? $index
: $index + 1;
}
And in SkinTemplate.php:
$readPage = $title->getReadPage();
$content_navigation['namespaces']['article']['class'] = 'selected';
$content_navigation['namespaces']['article']['text'] = 'Article';
$content_navigation['namespaces']['article']['href'] = $readPage;
$content_navigation['namespaces']['article']['primary'] = true;
$content_navigation['namespaces']['article']['context'] = 'subject';
The Tab appeared, but it links to ":Title" instead of "Article:Title". If I look for "Article:Title" page, the following message appears:
There is currently no text in this page. You can search for this page title in other pages, search the related logs, or edit this page.
Any ideas?
Don't touch the MediaWiki sources or you'll have to redo the same thing each time you upgrade. Tab manipulation is doable with hooks, e.g. SkinTemplateNavigation.

Categories