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.
Related
I want to write a Single Sign On (SSO) plugin for WordPress. I want to use an external image link as user's profile picture after user login.
This image has a link which is located in http://www.example.com/image.png.
How can I do this in WordPress?
Please add this code to your activated theme's functions.php file.
add_filter( 'author_link', 'modify_author_link', 10, 1 );
function modify_author_link( $link ) {
$link = 'http://google.com/';
return $link;
}
You can use your any link, just change https://google.com to your link.
Thanks.
These Hooks ('get_avatar', 'avatar_defaults') are also available by WordPress, as an example:
you can check the documentation here:
https://codex.wordpress.org/Function_Reference/get_avatar
function my_custom_avatar($avatar, $id_or_email, $size, $default, $alt)
{
echo $avatar . ' -> ' . $id_or_email . ' -> ' . $size . ' -> ' . $default . ' -> ' .$alt;
$avatar = 'https://www.example.com/yourImage';
$avatar = "<img alt='{$alt}' src='{$avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
return $avatar;
}
add_filter( 'get_avatar', 'my_custom_avatar', 10, 5 );
add_filter( 'avatar_defaults', 'my_custom_avatar', 10, 1 );```
I am currently trying to do research on how to output a result from a WordPress custom plugin to the frontend of WordPress. I have trying adding filters, do actions, add actions. But nothing seems to work. I know the add_action works for child themes because I'm currently using a script to do so.
The script below works for the child theme but not in a plugins functions.php page.
function displayPages()
{
$pageIDs = "List of page ids";
if(is_page($pageIDs))
{
include_once 'script.js';
}
}
add_action('wp_footer', 'displayPages')
Here is the current code I was trying use to fix the problem with the plugin.
function getPageIDs()
{
include_once($_SERVER['DOCUMENT_ROOT'].'/stage/wp-config.php' );
global $wpdb;
$row = $wpdb->get_row( 'SELECT pages FROM schemalocalbusiness WHERE id = 1');
$pageIDs = $row->pages;
$pageIDsArray = explode(",", $pageIDs);
foreach($pageIDsArray as $perma)
{
echo ' ' . esc_url( get_permalink($perma) ) . '<br>';
}
}
function includeShemaOnPage()
{
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if(getPageID() == $acturla_link)
{
print 'SUCCESS';
}
}
add_action('wp_footer', 'includeShemaOnPage');
Any and all help would be much appreciated! Thank you in advance!
Hi I found this code on online, it is a simple button to reveal the coupon code and open the URL at the same time.
function coupon_add($coup, $uurl)
{
echo "
<script type='text/javascript'>
<!--
function coupon(coup,url)
{alert('COUPON CODE: ' + coup);
window.open(url,'_blank');
}
//-->
</script>";
echo "<center><br /><input style=\"width:250px; height:60px;font-
size:30px;\" type=\"button\" onclick=\"coupon('".$coup."','".$uurl."')\"
value=\"VIEW COUPON\" \/></center><p>";
}
I would like to turn this into a short code so I can insert it into a post. Would love some help with this, thanks in advance!
In your functions.php:
add_shortcode( 'my_coupon_add', 'sc_my_coupon_add' );
function sc_my_coupon_add( $args, $content = null ){
$atts = shortcode_atts( array(
'coup' => '',
'uurl' => ''
), $args, 'my_coupon_add' );
return "<script type='text/javascript'>
function coupon( coup, url ){
alert( 'COUPON CODE: ' + coup );
window.open( url, '_blank' );
}
</script>
<center><br /><input style=\"width:250px; height:60px;font-size:30px;\" type=\"button\" onclick=\"coupon('" . $atts[ 'coup' ] . "','" . $atts[ 'uurl' ] . "')\" value=\"VIEW COUPON\" \/></center><p>";
}
Now you can use the shortcode [my_coupon_add coup="" uurl=""] and pass your parameters. The way the javascript is written, this can only be used once on a page or post or else you'll have issues with the coupon() function, but this should give you enough to scale/rewrite it if needed more than once (like moving the coupon() javascript function to a main js file so it's available once and only when needed).
You might need to double-check the single and double quotes - I whipped this up quickly.
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.
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/