updated plugin Simple Local Avatars
version 2.5.0
This commit is contained in:
parent
3ebf964f56
commit
02c261fbfc
@ -1 +1 @@
|
|||||||
<?php return array('dependencies' => array(), 'version' => '743de2221cd3b95dfce2abc7e2a95842');
|
<?php return array('dependencies' => array(), 'version' => 'fdc7a56cb4a6a7999938');
|
||||||
|
File diff suppressed because one or more lines are too long
@ -80,7 +80,7 @@ class Simple_Local_Avatars {
|
|||||||
&& (
|
&& (
|
||||||
( // And either an ajax request not in the network admin.
|
( // And either an ajax request not in the network admin.
|
||||||
defined( 'DOING_AJAX' ) && DOING_AJAX
|
defined( 'DOING_AJAX' ) && DOING_AJAX
|
||||||
&& ! preg_match( '#^' . network_admin_url() . '#i', $_SERVER['HTTP_REFERER'] )
|
&& isset( $_SERVER['HTTP_REFERER'] ) && ! preg_match( '#^' . network_admin_url() . '#i', $_SERVER['HTTP_REFERER'] )
|
||||||
)
|
)
|
||||||
||
|
||
|
||||||
( // Or normal request not in the network admin.
|
( // Or normal request not in the network admin.
|
||||||
@ -99,6 +99,7 @@ class Simple_Local_Avatars {
|
|||||||
* Register actions and filters.
|
* Register actions and filters.
|
||||||
*/
|
*/
|
||||||
public function add_hooks() {
|
public function add_hooks() {
|
||||||
|
global $pagenow;
|
||||||
|
|
||||||
add_filter( 'plugin_action_links_' . SLA_PLUGIN_BASENAME, array( $this, 'plugin_filter_action_links' ) );
|
add_filter( 'plugin_action_links_' . SLA_PLUGIN_BASENAME, array( $this, 'plugin_filter_action_links' ) );
|
||||||
|
|
||||||
@ -107,7 +108,10 @@ class Simple_Local_Avatars {
|
|||||||
|
|
||||||
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
||||||
|
|
||||||
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
// Load the JS on BE & FE both, in order to support third party plugins like bbPress.
|
||||||
|
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||||
|
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||||
|
|
||||||
add_action( 'show_user_profile', array( $this, 'edit_user_profile' ) );
|
add_action( 'show_user_profile', array( $this, 'edit_user_profile' ) );
|
||||||
add_action( 'edit_user_profile', array( $this, 'edit_user_profile' ) );
|
add_action( 'edit_user_profile', array( $this, 'edit_user_profile' ) );
|
||||||
|
|
||||||
@ -130,6 +134,14 @@ class Simple_Local_Avatars {
|
|||||||
|
|
||||||
add_filter( 'avatar_defaults', array( $this, 'add_avatar_default_field' ) );
|
add_filter( 'avatar_defaults', array( $this, 'add_avatar_default_field' ) );
|
||||||
add_action( 'wpmu_new_blog', array( $this, 'set_defaults' ) );
|
add_action( 'wpmu_new_blog', array( $this, 'set_defaults' ) );
|
||||||
|
|
||||||
|
if ( 'profile.php' === $pagenow ) {
|
||||||
|
add_filter( 'media_view_strings', function ( $strings ) {
|
||||||
|
$strings['skipCropping'] = esc_html__( 'Default Crop', 'simple-local-avatars' );
|
||||||
|
|
||||||
|
return $strings;
|
||||||
|
}, 10, 1 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -262,11 +274,42 @@ class Simple_Local_Avatars {
|
|||||||
|
|
||||||
if ( ! empty( $args['url'] ) ) {
|
if ( ! empty( $args['url'] ) ) {
|
||||||
$args['found_avatar'] = true;
|
$args['found_avatar'] = true;
|
||||||
|
|
||||||
|
// If custom alt text isn't passed, pull alt text from the local image.
|
||||||
|
if ( empty( $args['alt'] ) ) {
|
||||||
|
$args['alt'] = $this->get_simple_local_avatar_alt( $id_or_email );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a user ID from certain possible values.
|
||||||
|
*
|
||||||
|
* @since 2.5.0
|
||||||
|
*
|
||||||
|
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
|
||||||
|
* user email, WP_User object, WP_Post object, or WP_Comment object.
|
||||||
|
* @return int|false
|
||||||
|
*/
|
||||||
|
public function get_user_id( $id_or_email ) {
|
||||||
|
$user_id = false;
|
||||||
|
|
||||||
|
if ( is_numeric( $id_or_email ) ) {
|
||||||
|
$user_id = (int) $id_or_email;
|
||||||
|
} elseif ( is_object( $id_or_email ) && ! empty( $id_or_email->user_id ) ) {
|
||||||
|
$user_id = (int) $id_or_email->user_id;
|
||||||
|
} elseif ( $id_or_email instanceof WP_Post && ! empty( $id_or_email->post_author ) ) {
|
||||||
|
$user_id = (int) $id_or_email->post_author;
|
||||||
|
} elseif ( is_string( $id_or_email ) ) {
|
||||||
|
$user = get_user_by( 'email', $id_or_email );
|
||||||
|
$user_id = $user ? $user->ID : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $user_id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get local avatar url.
|
* Get local avatar url.
|
||||||
*
|
*
|
||||||
@ -277,16 +320,7 @@ class Simple_Local_Avatars {
|
|||||||
* @param int $size Requested avatar size.
|
* @param int $size Requested avatar size.
|
||||||
*/
|
*/
|
||||||
public function get_simple_local_avatar_url( $id_or_email, $size ) {
|
public function get_simple_local_avatar_url( $id_or_email, $size ) {
|
||||||
if ( is_numeric( $id_or_email ) ) {
|
$user_id = $this->get_user_id( $id_or_email );
|
||||||
$user_id = (int) $id_or_email;
|
|
||||||
} elseif ( is_object( $id_or_email ) && ! empty( $id_or_email->user_id ) ) {
|
|
||||||
$user_id = (int) $id_or_email->user_id;
|
|
||||||
} elseif ( $id_or_email instanceof WP_Post && ! empty( $id_or_email->post_author ) ) {
|
|
||||||
$user_id = (int) $id_or_email->post_author;
|
|
||||||
} elseif ( is_string( $id_or_email ) ) {
|
|
||||||
$user = get_user_by( 'email', $id_or_email );
|
|
||||||
$user_id = $user ? $user->ID : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( empty( $user_id ) ) {
|
if ( empty( $user_id ) ) {
|
||||||
return '';
|
return '';
|
||||||
@ -354,7 +388,15 @@ class Simple_Local_Avatars {
|
|||||||
$dest_file = $editor->generate_filename();
|
$dest_file = $editor->generate_filename();
|
||||||
$saved = $editor->save( $dest_file );
|
$saved = $editor->save( $dest_file );
|
||||||
if ( ! is_wp_error( $saved ) ) {
|
if ( ! is_wp_error( $saved ) ) {
|
||||||
$local_avatars[ $size ] = str_replace( $upload_path['basedir'], $upload_path['baseurl'], $dest_file );
|
// Transform the destination file path into URL.
|
||||||
|
$dest_file_url = '';
|
||||||
|
if ( false !== strpos( $dest_file, $upload_path['basedir'] ) ) {
|
||||||
|
$dest_file_url = str_replace( $upload_path['basedir'], $upload_path['baseurl'], $dest_file );
|
||||||
|
} else if ( is_multisite() && false !== strpos( $dest_file, ABSPATH . 'wp-content/uploads' ) ) {
|
||||||
|
$dest_file_url = str_replace( ABSPATH . 'wp-content/uploads', network_site_url( '/wp-content/uploads' ), $dest_file );
|
||||||
|
}
|
||||||
|
|
||||||
|
$local_avatars[ $size ] = $dest_file_url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -372,6 +414,31 @@ class Simple_Local_Avatars {
|
|||||||
return esc_url( $local_avatars[ $size ] );
|
return esc_url( $local_avatars[ $size ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get local avatar alt text.
|
||||||
|
*
|
||||||
|
* @since 2.5.0
|
||||||
|
*
|
||||||
|
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
|
||||||
|
* user email, WP_User object, WP_Post object, or WP_Comment object.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_simple_local_avatar_alt( $id_or_email ) {
|
||||||
|
$user_id = $this->get_user_id( $id_or_email );
|
||||||
|
|
||||||
|
if ( empty( $user_id ) ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch local avatar from meta and make sure we have a media ID.
|
||||||
|
$local_avatars = get_user_meta( $user_id, 'simple_local_avatar', true );
|
||||||
|
if ( empty( $local_avatars['media_id'] ) ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return esc_attr( get_post_meta( $local_avatars['media_id'], '_wp_attachment_image_alt', true ) );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get default avatar url
|
* Get default avatar url
|
||||||
*
|
*
|
||||||
@ -620,7 +687,7 @@ class Simple_Local_Avatars {
|
|||||||
*
|
*
|
||||||
* @param string $hook_suffix Page hook
|
* @param string $hook_suffix Page hook
|
||||||
*/
|
*/
|
||||||
public function admin_enqueue_scripts( $hook_suffix ) {
|
public function enqueue_scripts( $hook_suffix ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the admin screens where we enqueue our scripts.
|
* Filter the admin screens where we enqueue our scripts.
|
||||||
@ -631,6 +698,11 @@ class Simple_Local_Avatars {
|
|||||||
*/
|
*/
|
||||||
$screens = apply_filters( 'simple_local_avatars_admin_enqueue_scripts', array( 'profile.php', 'user-edit.php', 'options-discussion.php' ), $hook_suffix );
|
$screens = apply_filters( 'simple_local_avatars_admin_enqueue_scripts', array( 'profile.php', 'user-edit.php', 'options-discussion.php' ), $hook_suffix );
|
||||||
|
|
||||||
|
// Allow SLA actions on a bbPress profile edit page at FE.
|
||||||
|
if ( function_exists( 'bbp_is_user_home_edit' ) && bbp_is_user_home_edit() ) {
|
||||||
|
$hook_suffix = 'profile.php';
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! in_array( $hook_suffix, $screens, true ) ) {
|
if ( ! in_array( $hook_suffix, $screens, true ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -649,6 +721,7 @@ class Simple_Local_Avatars {
|
|||||||
'simple-local-avatars',
|
'simple-local-avatars',
|
||||||
'i10n_SimpleLocalAvatars',
|
'i10n_SimpleLocalAvatars',
|
||||||
array(
|
array(
|
||||||
|
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
||||||
'user_id' => $user_id,
|
'user_id' => $user_id,
|
||||||
'insertIntoPost' => __( 'Set as avatar', 'simple-local-avatars' ),
|
'insertIntoPost' => __( 'Set as avatar', 'simple-local-avatars' ),
|
||||||
'selectCrop' => __( 'Select avatar and Crop', 'simple-local-avatars' ),
|
'selectCrop' => __( 'Select avatar and Crop', 'simple-local-avatars' ),
|
||||||
@ -779,7 +852,8 @@ class Simple_Local_Avatars {
|
|||||||
<?php
|
<?php
|
||||||
// if user is author and above hide the choose file option
|
// if user is author and above hide the choose file option
|
||||||
// force them to use the WP Media Selector
|
// force them to use the WP Media Selector
|
||||||
if ( ! current_user_can( 'upload_files' ) ) {
|
// At FE, show the file input field regardless of the caps.
|
||||||
|
if ( ! is_admin() || ! current_user_can( 'upload_files' ) ) {
|
||||||
?>
|
?>
|
||||||
<p style="display: inline-block; width: 26em;">
|
<p style="display: inline-block; width: 26em;">
|
||||||
<span class="description"><?php esc_html_e( 'Choose an image from your computer:' ); ?></span><br />
|
<span class="description"><?php esc_html_e( 'Choose an image from your computer:' ); ?></span><br />
|
||||||
@ -889,6 +963,14 @@ class Simple_Local_Avatars {
|
|||||||
include_once ABSPATH . 'wp-admin/includes/media.php';
|
include_once ABSPATH . 'wp-admin/includes/media.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// front end (plugin bbPress etc) support
|
||||||
|
if ( ! function_exists( 'wp_handle_upload' ) ) {
|
||||||
|
include_once ABSPATH . 'wp-admin/includes/file.php';
|
||||||
|
}
|
||||||
|
if ( ! function_exists( 'wp_generate_attachment_metadata' ) ) {
|
||||||
|
include_once ABSPATH . 'wp-admin/includes/image.php';
|
||||||
|
}
|
||||||
|
|
||||||
// allow developers to override file size upload limit for avatars
|
// allow developers to override file size upload limit for avatars
|
||||||
add_filter( 'upload_size_limit', array( $this, 'upload_size_limit' ) );
|
add_filter( 'upload_size_limit', array( $this, 'upload_size_limit' ) );
|
||||||
|
|
||||||
@ -1248,7 +1330,13 @@ class Simple_Local_Avatars {
|
|||||||
*/
|
*/
|
||||||
private function clear_user_avatar_cache( $local_avatars, $user_id, $media_id ) {
|
private function clear_user_avatar_cache( $local_avatars, $user_id, $media_id ) {
|
||||||
if ( ! empty( $media_id ) ) {
|
if ( ! empty( $media_id ) ) {
|
||||||
$file_name_data = pathinfo( wp_get_original_image_path( $media_id ) );
|
// In order to support WP 4.9.
|
||||||
|
if ( function_exists( 'wp_get_original_image_path' ) ) {
|
||||||
|
$file_name_data = pathinfo( wp_get_original_image_path( $media_id ) );
|
||||||
|
} else {
|
||||||
|
$file_name_data = pathinfo( get_attached_file( $media_id ) );
|
||||||
|
}
|
||||||
|
|
||||||
$file_dir_name = $file_name_data['dirname'];
|
$file_dir_name = $file_name_data['dirname'];
|
||||||
$file_name = $file_name_data['filename'];
|
$file_name = $file_name_data['filename'];
|
||||||
$file_ext = $file_name_data['extension'];
|
$file_ext = $file_name_data['extension'];
|
||||||
@ -1306,10 +1394,10 @@ class Simple_Local_Avatars {
|
|||||||
update_option( 'simple_local_avatar_default', $file_id );
|
update_option( 'simple_local_avatar_default', $file_id );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Migrate the user's avatar data from WP User Avatar/ProfilePress
|
* Migrate the user's avatar data from WP User Avatar/ProfilePress
|
||||||
*
|
*
|
||||||
* This function creates a new option in the wp_options table to store the processed user IDs
|
* This function creates a new option in the wp_options table to store the processed user IDs
|
||||||
* so that we can run this command multiple times without processing the same user over and over again.
|
* so that we can run this command multiple times without processing the same user over and over again.
|
||||||
*
|
*
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
=== Simple Local Avatars ===
|
=== Simple Local Avatars ===
|
||||||
Contributors: jakemgold, 10up, thinkoomph
|
Contributors: jakemgold, 10up, thinkoomph, jeffpaul, faisal03
|
||||||
Donate link: https://10up.com/plugins/simple-local-avatars-wordpress/
|
Donate link: https://10up.com/plugins/simple-local-avatars-wordpress/
|
||||||
Tags: avatar, gravatar, user photos, users, profile
|
Tags: avatar, gravatar, user photos, users, profile
|
||||||
Requires at least: 4.6
|
Requires at least: 4.6
|
||||||
Tested up to: 6.0
|
Tested up to: 6.0
|
||||||
Requires PHP: 5.6
|
Requires PHP: 5.6
|
||||||
Stable tag: 2.4.0
|
Stable tag: 2.5.0
|
||||||
License: GPLv2 or later
|
License: GPLv2 or later
|
||||||
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
|
||||||
Adds an avatar upload field to user profiles. Generates requested sizes on demand just like Gravatar!
|
Adds an avatar upload field to user profiles. Generates requested sizes on demand just like Gravatar!
|
||||||
|
|
||||||
@ -41,6 +41,15 @@ You can also use `get_simple_local_avatar()` (with the same arguments) to retrei
|
|||||||
|
|
||||||
== Changelog ==
|
== Changelog ==
|
||||||
|
|
||||||
|
= 2.5.0 - 2022-06-24 =
|
||||||
|
* **Added:** Skip cropping button (props [@dkotter](https://github.com/dkotter), [@faisal-alvi](https://github.com/faisal-alvi), [@cadic](https://github.com/cadic), [@jeffpaul](https://github.com/jeffpaul), [@dinhtungdu](https://github.com/dinhtungdu) via [#130](https://github.com/10up/simple-local-avatars/pull/130))!
|
||||||
|
* **Added:** Updated the button name from "Skip Crop" to "Default Crop" only on the edit profile page (props [@faisal-alvi](https://github.com/faisal-alvi), [@peterwilsoncc](https://github.com/peterwilsoncc) via [#136](https://github.com/10up/simple-local-avatars/pull/136)).
|
||||||
|
* **Added:** If an image used for a local avatar has alt text assigned, ensure that alt text is used when rendering the image (props [@dkotter](https://github.com/dkotter), [@pixelloop](https://github.com/pixelloop), [@faisal-alvi](https://github.com/faisal-alvi) via [#127](https://github.com/10up/simple-local-avatars/pull/127)).
|
||||||
|
* **Added:** Support for bbPress by loading the JS at FE on the profile edit page (props [@foliovision](https://github.com/foliovision), [@faisal-alvi](https://github.com/faisal-alvi), [@iamdharmesh](https://github.com/iamdharmesh) via [#134](https://github.com/10up/simple-local-avatars/pull/134)).
|
||||||
|
* **Added:** Cypress E2E tests (props [@faisal-alvi](https://github.com/faisal-alvi), [@vikrampm1](https://github.com/vikrampm1), [@Sidsector9](https://github.com/Sidsector9) via [#115](https://github.com/10up/simple-local-avatars/pull/115)).
|
||||||
|
* **Fixed:** Broken avatar URLs for network-configured shared avatars with non-standard thumbnail sizes (props [@vladolaru](https://github.com/vladolaru), [@faisal-alvi](https://github.com/faisal-alvi) via [#125](https://github.com/10up/simple-local-avatars/pull/125)).
|
||||||
|
* **Fixed:** `HTTP_REFERER` is null and causing PHP warning (props [@alireza-salehi](https://github.com/alireza-salehi), [@faisal-alvi](https://github.com/faisal-alvi), [@peterwilsoncc](https://github.com/peterwilsoncc) via [#129](https://github.com/10up/simple-local-avatars/pull/129)).
|
||||||
|
|
||||||
= 2.4.0 - 2022-05-10 =
|
= 2.4.0 - 2022-05-10 =
|
||||||
* **Added:** Ability to set a default avatar. (props [@mehulkaklotar](https://github.com/mehulkaklotar), [@jeffpaul](https://github.com/jeffpaul), [@dinhtungdu](https://github.com/dinhtungdu), [@faisal-alvi](https://github.com/faisal-alvi) via [#96](https://github.com/10up/simple-local-avatars/pull/96)).
|
* **Added:** Ability to set a default avatar. (props [@mehulkaklotar](https://github.com/mehulkaklotar), [@jeffpaul](https://github.com/jeffpaul), [@dinhtungdu](https://github.com/dinhtungdu), [@faisal-alvi](https://github.com/faisal-alvi) via [#96](https://github.com/10up/simple-local-avatars/pull/96)).
|
||||||
* **Fixed:** Correct plugin name in changelog. (props [@grappler](https://github.com/grappler), [@jeffpaul](https://github.com/jeffpaul) via [#117](https://github.com/10up/simple-local-avatars/pull/117)).
|
* **Fixed:** Correct plugin name in changelog. (props [@grappler](https://github.com/grappler), [@jeffpaul](https://github.com/jeffpaul) via [#117](https://github.com/10up/simple-local-avatars/pull/117)).
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* Plugin Name: Simple Local Avatars
|
* Plugin Name: Simple Local Avatars
|
||||||
* Plugin URI: https://10up.com/plugins/simple-local-avatars-wordpress/
|
* Plugin URI: https://10up.com/plugins/simple-local-avatars-wordpress/
|
||||||
* Description: Adds an avatar upload field to user profiles. Generates requested sizes on demand, just like Gravatar! Simple and lightweight.
|
* Description: Adds an avatar upload field to user profiles. Generates requested sizes on demand, just like Gravatar! Simple and lightweight.
|
||||||
* Version: 2.4.0
|
* Version: 2.5.0
|
||||||
* Requires at least: 4.6
|
* Requires at least: 4.6
|
||||||
* Requires PHP: 5.6
|
* Requires PHP: 5.6
|
||||||
* Author: Jake Goldman, 10up
|
* Author: Jake Goldman, 10up
|
||||||
@ -20,7 +20,7 @@ define( 'SLA_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
|||||||
require_once dirname( __FILE__ ) . '/includes/class-simple-local-avatars.php';
|
require_once dirname( __FILE__ ) . '/includes/class-simple-local-avatars.php';
|
||||||
|
|
||||||
// Global constants.
|
// Global constants.
|
||||||
define( 'SLA_VERSION', '2.2.0' );
|
define( 'SLA_VERSION', '2.5.0' );
|
||||||
define( 'SLA_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
define( 'SLA_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||||
|
|
||||||
if ( ! defined( 'SLA_IS_NETWORK' ) ) {
|
if ( ! defined( 'SLA_IS_NETWORK' ) ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user