January 10, 2018

Replace your WordPress Avatar URL with ACF image field

Replace your WordPress Avatar URL with ACF image field add_filter(‘get_avatar_url’, ‘lb_acf_profile_avatar_url’, 10, 2); function lb_acf_profile_avatar_url($avatar, $id){ $image_id = get_user_meta($id, ‘lb_local_avatar’, true); if ( ! $image_id ) { return $avatar; } $image_url = wp_get_attachment_image_src( $image_id, ‘thumbnail’ ); $avatar = $image_url[0]; return $avatar; }

January 9, 2018

How to allow WooCommerce customers to add capability of image uploading to library?

How to allow WooCommerce customers to add capability of image uploading to library? add_action(‘admin_init’, ‘allow_customer_uploads’); function allow_customer_uploads(){ $customer = get_role(‘customer’); $customer->add_cap(‘upload_files’); }

How to use ACF Image field as WordPress user profile avatar?

How to use ACF Image field as WordPress user profile avatar? add_filter(‘get_avatar’, ‘lb_acf_profile_avatar’, 10, 5); function lb_acf_profile_avatar( $avatar, $id_or_email, $size, $default, $alt ) { $field_name = ‘lb_local_avatar’; $user = ”; // Get user by id or email if ( is_numeric( $id_or_email ) ) { $id = (int) $id_or_email; $user = get_user_by( ‘id’ , $id ); […]

Restrict users to view only their uploads while using ACF

Restrict users to view only their uploads while using ACF add_filter( ‘ajax_query_attachments_args’, ‘lb_show_current_user_attachments’ ); function lb_show_current_user_attachments( $query ) { $user_id = get_current_user_id(); if ( $user_id && !current_user_can(‘activate_plugins’) && !current_user_can(‘edit_others_posts ‘) ) { $query[‘author’] = $user_id; } return $query; }