Renaming the tabs in Buddypress - php

I have a multisite WP with Buddypress and BP Multi Network.
The sites are being created automatically (data is coming from external system).
The problem is I want to show only the Activity tab in the menu and I want to rename it as well. I have created bp-custom.php and this is its content:
<?php
function bp_change_tabname() {
global $bp;
$bp->bp_nav['activity']['name'] = 'Duvar';
$bp->bp_nav['members'] = false;
}
add_action( 'bp_setup_nav', 'bp_change_tabname', 999 );
?>
It is not working though. It seems like the content of bp-custom is irrelevant.
Any ideas?

To remove a nav item from the navigation array you can use bp_core_remove_nav_item(). For example:
function my_remove_tabs() {
bp_core_remove_nav_item( $parent_id );
}
add_action( 'bp_setup_nav', 'my_remove_tabs' );
Where $parent_id is the slug of the parent navigation item.
To customise the tab labels, you could use a language file. See the Customising Labels, Messages and URLs article for more info on how and why.

Related

How to create custom draggable widget in WordPress

i need to make some blocks(widgets) like the same of WordPress dashboard widgets. that means if we dragged a widget to another position it wouldn't change after refreshing the page. is there any way for the same.?? i want some blocks or widgets (functioning like dashboard widgets) in my custom plugin. :)
I believe you need this:
function your_dashboard_widgets() {
global $wp_meta_boxes;
wp_add_dashboard_widget('custom_help_widget', 'Theme Support', 'your_widget_callback');
}
add_action('wp_dashboard_setup', 'your_dashboard_widgets');
function your_widget_callback() {
echo '<p>Welcome!</p>';
}

Is it possible to insert shortcode inside Header menu or top-bar menu in wordpress?

I have made a simple shortcode for my wordpress theme. I'm trying to align it on right-side above the corner of my page. Is it possible to insert shortcode function.php?
I want to place my Short-code in the top-bar (right side above the corner) so that it will work for each pages. Means if i click on any menu then the shortcode should have to work on that menu also.
Actually i'm new in web development. Please suggest me what shall i have to do so it will align where i want and should have work for each module.
You can use wordpress function for that. Please open the file on which you have to place shortcode. Like if you want to place it on header open header.php and add
<?php echo do_shortcode('[your_shortcode]'); ?>
where you want your shortcode content to appear
The best way is to find the top bar menu hook of your theme and then add this code (adapted for your needs) in your function.php child theme :
function my_shotcode_inside_top_bar ( $items, $args ) {
if (is_page() && $args->theme_location == 'secondary') {
$items .= '<li class="my-class">' . do_shortcode( "[my_shortcode]" ) . '</li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'my_shotcode_inside_top_bar', 10, 2 );
is_page displays the shortcode in pages only but you can choose another condition or no condition at all.
secondary is the hook and it depends on your theme. You can normally find it in your theme header.php file.
A menu location selector should be added - that way some themes support multiple menus, and some are called "top" or custom added.
The shortcode could then contain a call to whatever a menu position is:
EG: [myshortcode menu="secondary"]
Didn't have enough points to add this as a comment.

wordpress functions.php - use different page template for each post category

I want to hook into the save_post function, find out what category the post is in, and then assign a different page template for posts in each category. I've tried about 30 different versions of this with no luck. Will someone please help point me in the right direction?
add_action( 'save_post', 'assign_custom_template' );
function assign_custom_template($post_id) {
$category = get_the_category($post_id);
$cat_id = $category->cat_ID;
if( $cat_id == 1 ) {
update_post_meta($post_id, "_wp_page_template", "template1.php");
}
if( $cat_id == 2 ) {
update_post_meta($post_id, "_wp_page_template", "template2.php");
}
}
You just need to create category-1.php which rendered as template1.php and category-2.php which rendered as template2.php in your theme root.
See template hierarchy for more info.
I tried to emulate the official WP hierarchy scheme among my posts & custom post types, but it just wasn't happening. I ended up using Custom Post Types so that I could assign templates to both the "list" pages and the "individual" pages. And then I wrote some javascript that looks for the post-type string in the URL, and if it's detected, it adds the current_page_parent/ancestor classes to the appropriate menu items. Not perfect or totally future-proof, but it gets the job done.
If someone comes up with a better solution, please post it!

Why does wpmu_new_user not fire inside of a plugin but does inside functions.php?

I have a project to complete where sites within a WordPress Multisite blog will automatically add users to the corresponding sites (where the plugin is enabled)
I hope I worded that correctly.
The problem: The wpmu_new_user hook does not fire inside of a plugin but WILL inside of functions.php
This is my code:
add_action( 'wpmu_new_user', 'register_hack_action', 10, 1 );
add_action( 'wpmu_activate_user', 'register_hack_action', 10, 1);
function register_hack_action( $user_id ) {
$this_id = get_current_blog_id();
if ( !defined('ABSPATH') ) {
// do nothing
} else {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
$blog_list = get_blog_list( 0, 'all' );
foreach ($blog_list AS $blog) {
switch_to_blog($blog['blog_id']);
if ( is_plugin_active( 'register-hack/register-hack.php' ) ) {
// add user to blog
add_user_to_blog($blog['blog_id'], $user_id, 'subscriber');
}
}
}
This works perfectly fine when you add the snippet to functions.php. But when you add it to a plugin (which goes into wp-content/plugins) and then is activated on certain sites, just will not work. if you can try it for yourself you'll see what i mean.. I don't understand why it will not work. I need it to be inside of the plugin and work.
Only some extensive debugging could answer this... But this kind of stuff is better placed inside a Must Use plugin.
Must-use plugins (a.k.a. mu-plugins) are plugins installed in a special directory inside the content folder and which are automatically enabled on all sites in the installation. Must-use plugins do not show in the default list of plugins on the Plugins page of wp-admin – although they do appear in a special Must-Use section – and cannot be disabled except by removing the plugin file from the must-use directory, which is found in wp-content/mu-plugins by default.
I don't understand why you're using that include_once, please, test it removing that.
Especulations:
as a normal plugin, it should be Network Activated and try to encapsulate the actions with:
add_action( 'plugins_loaded', function() {
add_action( 'wpmu_new_user', 'register_hack_action', 10, 1 );
add_action( 'wpmu_activate_user', 'register_hack_action', 10, 1);
});
maybe you're putting inside the main site theme?

Using variables in the URL on wordpress menu link

I am using wordpress wp-admin to create the menu. It is under Appearance/menu.
I have a link that points to /members/ but what I really need is a link to /members/$logged_user...
For example /members/user_1 or /members/user_2.
How can I do that?
I dont know if it is important, but I am using buddypress plugin.
I have written a short script for adding dynamic buddypress links in wordpress menu. Hope it helps
I have added custom links in wordpress menu replacing username in link with --username--
example
http://website_name.com/members/--username--/messages/
then add this code in function.php
add_filter( 'nav_menu_link_attributes', 'menu_override', 10, 3 );
function menu_override( $atts, $item, $args ) {
$user = wp_get_current_user();
$newlink = str_replace("--username--", $user->user_login, $atts[href]);
$atts[href] = $newlink;
return $atts;
}
The default menu doesn't really have that option. But you can make your own walker function, searching for the keyword and replacing it with the current user.
See http://codex.wordpress.org/Function_Reference/wp_nav_menu#Using_a_Custom_Walker_Function
But it would probably be faster and more manageable to just place the link outside the menu call with some static html and the needed php.
You can use the BuddyPress Custom Profile Menu plugin to get close to this functionality, otherwise you will have to write custom code that uses actions/filters of wp_nav_menu().

Categories