buddy press profile link not going to correct place - php

I created a bp-custom.php and regrouped the menu items fine. But now i am trying to add a link to go to /site/members. It list all the members.
When i add it though it goes under the profile I am viewing. I am redirecting to a wordpress page if that helps. Or is there a better way to do this.
Ex :
http://website.com/log-in/members/username/members/
I want it to go just here
http://website.com/log-in/members/
I would love to learn how to just put a url and no slug but whatever works. I do not know why it keeps referencing that signed in /member/username. I have even tried parent url and that did not work. I might have been using parent url syntax wrong.
Here is the function
function mb_bp_profile_menu_posts() {
global $bp;
bp_core_new_nav_item(
array(
'name' => 'Members',
'slug' => 'members',
'position' => 60,
)
);
}
I know that i can create .htaccess for this. But I don't want to do it.
May i know what is the clean way (alternate way) to do this?
I have tried what the user said in comment below and found in bp-members-template this function. I then added the part in bold to add the link but that did not work. I am just adding a google link for testing only.
function bp_get_displayed_user_nav() {
global $bp;
foreach ( (array) $bp->bp_nav as $user_nav_item ) {
if ( empty( $user_nav_item['show_for_displayed_user'] ) && !bp_is_my_profile() )
continue;
$selected = '';
if ( bp_is_current_component( $user_nav_item['slug'] ) ) {
$selected = ' class="current selected"';
}
if ( bp_loggedin_user_domain() ) {
$link = str_replace( bp_loggedin_user_domain(), bp_displayed_user_domain(), $user_nav_item['link'] );
} else {
$link = trailingslashit( bp_displayed_user_domain() . $user_nav_item['link'] );
}
echo apply_filters_ref_array( 'bp_get_displayed_user_nav_' . $user_nav_item['css_id'], array( '<li id="' . $user_nav_item['css_id'] . '-personal-li" ' . $selected . '><a id="user-' . $user_nav_item['css_id'] . '" href="' . $link . '">' . $user_nav_item['name'] . '</a></li>', &$user_nav_item ) );
**echo "<a href='http://www.google.com'>Google</a>"; }**
}

The bp_core_new_nav_item function is used to add a link to the user's navigation which explains why you're seeing URLs like /members/username/members/ when clicking on the tab. I don't think bp_core_new_nav_item is the right approach here.
An alternative approach would be to replace the function in your theme template that outputs the navigation with your own custom menu.
See this article on the BP Template Hierarchy which shows you how you can set up your own templates:
http://codex.buddypress.org/themes/theme-compatibility-1-7/template-hierarchy/

Related

Wordpress Website, add_filter() to change logo depending on language [duplicate]

This question already has answers here:
WordPress Change logo image when I click to a different language
(6 answers)
Closed 4 years ago.
I am working on a website for a friend of mine, which is multilingual. Therefore I use the plugin Polylang. 'The theme I use is called 'spacious'.
I currently face the problem, that I cant add different logos for different languages, aswell as different header texts/background images.
I googled a bit, and found a possible solution, but I didnt get it to work.
function pojo_polylang_get_multilang_logo( $value ) {
if ( function_exists( 'pll_current_language' ) ) {
$logos = array(
'en' => 'logo_en.jpg',
'fr' => 'logo_fr.jpg',
'de' => 'logo_de.jpg',
'es' => 'logo_esp.jpg',
);
$default_logo = $logos['en'];
$current_lang = pll_current_language();
$assets_url = get_stylesheet_directory_uri() . '/images/';
if ( isset( $logos[ $current_lang ] ) )
$value = $assets_url . $logos[ $current_lang ];
else
$value = $assets_url . $default_logo;
}
return $value;
}
add_filter( 'theme_mod_image_logo', 'pojo_polylang_get_multilang_logo' );
In my understanding, this function first stores the preset Logo filenames in an array, then checks for the current language and depending on the current language, the add_filter() function sets the current logo.
I tried copying this into the functions.php file but it didnt work.
My thought is, that it doesnt work, because of the first parameter 'theme_mod_image_logo'. I also googled this php function to get a better understanding of it and to know what parameter to pass to the function. Can someone explain to me who is firm with php, what parameter I need to pass or if you have a better solution for me?
In case this works for the logo, I could also apply this function to a header-image right? Just change the filenames in the array and pass the right parameter?
Thanks already, I would really appreciate your help!!
I need to leave now for about one hour or two, and wont be able to respond back during that time!
Edit: I also had a lokk at 'duplicate' question. It didnt help me since, my understanding is not good enough
I think the best approach is to hook into "get_custom_logo", which is used by your theme:
add_filter( 'get_custom_logo', 'my_polylang_logo' );
function my_polylang_logo() {
if ( function_exists( 'pll_current_language' ) ) {
$logos = array(
'en' => 'logo_en.jpg',
'fr' => 'logo_fr.jpg',
'de' => 'logo_de.jpg',
'es' => 'logo_esp.jpg'
);
$current_lang = pll_current_language();
$img_path = get_stylesheet_directory_uri() . '/images/';
if ( isset( $logos[ $current_lang ] ) ) {
$logo_url = $img_path . $logos[$current_lang];
} else {
$logo_url = $img_path . $logos['en'];
}
$home_url = home_url();
$html = sprintf( '<img src="%2$s">', esc_url( $home_url ), $logo_url);
}
return $html;
}
(untested)

How to handle user_row_actions in WordPress?

First of all, I have not find solution for my problem. I have read few articles and thread to create a user actions , and tried the following code.
function kv_admin_deactivate_link($actions, $user_object) {
$actions['deactivate_user'] = "<a href='" . admin_url( "users.php?action=deactivate&user=$user_object->ID") . "'>" . __( 'Deactivate', 'kvc' ) . "</a>";
return $actions;
}
add_filter('user_row_actions', 'kv_admin_deactivate_link', 10, 2);
After using the above code it gets me the additional action with users list as like in the below screenshot.
Now, my problem is, I don't know how to proceed to write my codes to deactivate a user. So can you help me to write function to handle /wp-admin/users.php?action=deactivate&user=41. Here I am writing these function for my wordpress theme and how can I write function for it.
This will help you to perform your deactivate operation function. just create a admin menu with the following code.
function xxxadmin_submenu_email() {
add_menu_page('Your menu', 'Your menu', 'manage_options', 'deactivate' , 'xxx_deactivate_functions', '', 66);
}
add_action('admin_menu', 'xxxadmin_submenu_email');
Now, it will get you a page and you have to write function inside xxx_deactivate_functions it. Here is sample code.
function xxx_deactivate_functions() {
if(isset($_GET['action']) && $_GET['action']== 'deactivate'){
$user_id = $_GET['user'];
$user_info = get_userdata($user_id);
}
}
And I have modified your function like the below one.
function kv_admin_deactivate_link($actions, $user_object) {
$actions['deactivate_user'] = "<a href='" . admin_url( "users.php?page=deactivate&action=deactivate&user=$user_object->ID") . "'>" . __( 'Deactivate', 'kvc' ) . "</a>";
return $actions;
}
add_filter('user_row_actions', 'kv_admin_deactivate_link', 10, 2);
This is one way to do this. But wait for some other experts solution to code it better way. Hope its helpful for urgent need.

Redirect after front end deleting post

I've created a delete post button on the front end for a Wordpress site. It deletes the post fine but then tries to reload the post again causing a 404. Is there a way I redirect it after deleting to a specific url? This is my code:
function wp_delete_post_link($link = 'Delete This', $before = '', $after = '') {
global $post;
$link = "<a href='" . wp_nonce_url( get_bloginfo('url') . "/wp-admin/post.php?action=delete&post=" . $post->ID, 'delete-post_' . $post->ID) . "'>".$link."</a>";
echo $before . $link . $after;
}
Then on the template:
<?php wp_delete_post_link('Delete This', '<p>', '</p>'); ?>
I think you are looking for the wp_redirect function.
$location = 'http://domainname.com/pagename/';
$status = '301';
wp_redirect( $location, $status );
exit;
Just place after your successful delete code.
How about running this function right after your echo:
header( 'Location: yournewURL.html' ) ;
Replace 'yournewURL.html' with the page you need to redirect to.

How to return a certain html tag in php

Sorry if this is a really stupid question. I am just starting to learn PHP and am probably jumping the gun a bit.
I am writing a very 'simple' wordpress plugin which has a custom post type and takes the content from it and returns it on the homepage with a shortcode. Below is the part of the code that handles the shortcode.
add_shortcode("new-tub", "new_tub_short");
function new_tub_short() {
$post_id = 87;
return '<a class="new-tub" href="' . home_url( '/test' , __FILE__ ) . '">' . get_post_field('post_content', $post_id) . '</a>';
}
So currently it wraps a link around the content of the post. All that is in the post will be an image, however, I would like to make it fool proof so it doesnt include another link and paragraph tag.
My question is, is it possible to search for the img tag within that post and return that only?
Thanks in advance,
Alex
You can do this by using strip_tags. Try this,
add_shortcode("new-tub", "new_tub_short");
function new_tub_short() {
$post_id = 87;
return '<a class="new-tub" href="' . home_url( '/test' , __FILE__ ) . '">' . strip_tags(get_post_field('post_content', $post_id), '<img>') . '</a>';
}
http://php.net/manual/en/function.strip-tags.php

Kunena for Joomla uses nofollow for internal links

For some reason Kunena puts nofollow links for everything internal. This makes sense for all external links but certainly not for internal ones. I want Google to index the paths associated with the forum posts I have.
I'm hoping someone knows how to remove the nofollow links. It looks like this file is the main one: components/com_kunena/lib/kunena.link.class.php
There are a few functions where I remove the nofollow links such as:
static function GetHrefLink($link, $name, $title = '', $rel = 'nofollow', $class = '', $anker = '', $attr = '') {
return '<a ' . ($class ? 'class="' . $class . '" ' : '') . 'href="' . $link . ($anker ? ('#' . $anker) : '') . '" title="' . $title . '"' . ($rel ? ' rel="' . $rel . '"' : '') . ($attr ? ' ' . $attr : '') . '>' . $name . '</a>';
}
//
// Basic universal href link
//
static function GetSefHrefLink($link, $name, $title = '', $rel = 'nofollow', $class = '', $anker = '', $attr = '') {
$uri = $link instanceof JURI ? $link : JURI::getInstance($link);
if ($anker) $uri->setFragment($anker);
return JHTML::_('kunenaforum.link', $uri, $name, $title, $class, $rel, $attr);
}
I've tried removing the parameter everywhere, I tried just leaving it empty and I've tried using follow as a replacement. I've also tried looking for every single place where nofollow is shown in the whole Kunena component and tried removing those. Still no luck. Anyone with any ideas?
Kunena: 2.0.2
Joomla: 2.5.7
You dont need to change nofollow because google will index whole topic and categories. Check url for topic if its indexed. And add RSS and sitemap to google webmaster. You can configure RSS# kunena settings
Resolved this by changing this file: administrator/components/com_kunena/libraries/view.php
Find:
public function getTopicLink
Change this line:
return JHTML::_('kunenaforum.link', $uri, $content, $title, $class, 'nofollow');
to:
return JHTML::_('kunenaforum.link', $uri, $content, $title, $class, 'follow');
This exists in several spots.
If I understand your original concern, you want to remove all the rel="nofollow" references.
I would do this with a free component called ReReplacer. http://www.nonumber.nl/extensions/rereplacer
Create a rereplacer item that searches for rel="nofollow" and replaces it with rel="follow".
I did this for a forum of Joomla users that we want them to have follow links in their signatures.
If you buy the pro version of rereplacer then you can specify the replacement for only Kunena.

Categories