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 );```
Related
I have managed to get all product links on my Woocommerce site to open in a new tab, however, I am using endless scroll with ajax for loading more products and the products that get loaded via endless scroll does not open in a new tab when clicking on them.
Here is my current code for opening products in a new tab;
remove_action( 'woocommerce_before_shop_loop_item','woocommerce_template_loop_product_link_open', 10 );
add_action ( 'woocommerce_before_shop_loop_item', 'chr_function_open_new_tab', 10 );
function chr_function_open_new_tab() {
echo '<a target="_blank" href="' . get_the_permalink() . '" class="woocommerce-LoopProduct-link">';
}
Any help with this is highly appreciated.
Thanks in advance!
I think that your remove_action cannot take an action. That's why it gives a trouble. So try this code:
add_action('init',function(){ remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 ); } ,0);
function chr_function_open_new_tab() {
echo '<a target="_blank" href="' . get_the_permalink() . '" class="woocommerce-LoopProduct-link">';
}
Second Other Solution, you can do it with simple jQuery
add_action('wp_footer',function(){
if ( has_term( 'stone', 'product_cat' ) ) {
echo '<script>
//for existing content
jQuery(".woocommerce-LoopProduct-link").attr("target","_blank");
//for content part which comes from AJAX
jQuery( document ).ajaxComplete(function() {
jQuery(".woocommerce-LoopProduct-link").attr("target","_blank");
});
</script>';
}
});
Instead try to use this dedicated filter hook for add to cart button:
// Change loop add to cart ajax button to a linked button to single product pages
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_loop_add_to_cart', 20, 2 );
function replace_loop_add_to_cart( $html, $product ) {
$link = $product->get_permalink();
$text = __("Read More", "woocommerce");
return '' . $text . '';
}
And here for the product link:
add_filter( 'woocommerce_before_shop_loop_item', 'replace_template_loop_product_link_open', 1 );
function replace_loop_product_link() {
remove_action( 'woocommerce_before_shop_loop_item','woocommerce_template_loop_product_link_open', 10 );
add_action ( 'woocommerce_before_shop_loop_item', 'new_loop_product_link_open', 10 );
}
function new_loop_product_link_open() {
global $product;
echo '<a href="' . esc_url( $product->get_permalink() ) . '" target="_blank" class="woocommerce-LoopProduct-link woocommerce-loop-product__link">';
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
But in your case, it could not work as expected, depending on how your custom ajax functionality is implemented. As the problem remains for products loaded via ajax, the target="_blank" need to be implemented in the corresponding script too.
At this point nobody can help you more as we can't guess how this functionality is built.
Im working with Wordpress.
For the last hour Im trying to find a code in php. files considering the "Quick view" button, but with no results.
Does anyone know where I can find it?
Best regards.
Filip
It depends on the eCommerce plugin you are using and also on the theme. If you are using woocommerce with a theme built for woocommerce then you can find these kind of things in "woocomerce" folder located in theme directory. If there is no such directory in your theme then take a look at woocommerce plugin directory.
If you are using this plugin for the quick view
You can try this code:
add_filter('woocommerce_loop_quick_view_button','custom_quick_view');
function custom_quick_view($output)
{
$output = 'My Cutom Output';
return $output;
}
For OceanWP theme please try this code:
add_filter('ocean_woo_quick_view_button_html','custom_quick_view');
function custom_quick_view($output)
{
global $product;
$output = '<a href="#" id="product_id_' . $product->get_id() . '"
class="owp-quick-view" data-product_id="' . $product->get_id() . '"><i
class="icon-eye"></i>' . esc_html__( 'Quick View', 'oceanwp' ) . '</a>'; //Edit the $output as you want
return $output;
}
Place this code in your functions.php
Ok If anyone looking to change the text this how I did it and it works with any Theme:
Just add this a snippet in WordPress so you don't need to play around with function file or even when you update the theme or the plugin it will not change or break the text.
add_filter('woocommerce_loop_quick_view_button','custom_quick_view');
function custom_quick_view($output)
{
global $product;
$output = '<a href="#" id="product_id_' . $product->get_id() . '"
class="quick-view-button button" data-product_id="' . $product->get_id() . '"><i
class="icon-eye"></i>' . esc_html__( 'Buy Now', 'wc_quick_view' ) . '</a>'; //Edit the $output as you want
return $output;
}
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.
I've changed my wp-content folder to a folder called stuff and am trying to change my image urls in existing posts with a function rather than a SQL query...
I've placed this in my function.php hoping it would work, but the images are still using the 'wp-content' folder?
define('WP_UPLOADSURL', 'http://' . $_SERVER['HTTP_HOST']);
add_filter( 'pre_option_upload_url_path', function( $upload_dir_uri ){
return str_replace( WP_UPLOADSURL . '/wp-content/', WP_UPLOADSURL . '/stuff/', $upload_dir_uri );
});
I just needed to add the filter to the_content not the pre_option_upload_url_path.
define('WP_UPLOADSURL', 'http://' . $_SERVER['HTTP_HOST'] . '/');
add_filter( 'the_content', function( $upload_dir_uri ){
return str_replace( WP_UPLOADSURL . '/wp-content/', WP_UPLOADSURL . '/stuff/', $upload_dir_uri ); /* Again Change stuff */
});
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.