updated plugin Simple Local Avatars
version 2.7.3
This commit is contained in:
parent
35a7ea2e06
commit
0bf59ae0ba
@ -68,12 +68,6 @@ class Simple_Local_Avatars {
|
||||
$this->options = (array) get_option( 'simple_local_avatars' );
|
||||
$this->user_key = 'simple_local_avatar';
|
||||
$this->rating_key = 'simple_local_avatar_rating';
|
||||
$this->avatar_ratings = array(
|
||||
'G' => __( 'G — Suitable for all audiences', 'simple-local-avatars' ),
|
||||
'PG' => __( 'PG — Possibly offensive, usually for audiences 13 and above', 'simple-local-avatars' ),
|
||||
'R' => __( 'R — Intended for adult audiences above 17', 'simple-local-avatars' ),
|
||||
'X' => __( 'X — Even more mature than above', 'simple-local-avatars' ),
|
||||
);
|
||||
|
||||
if (
|
||||
! $this->is_avatar_shared() // Are we sharing avatars?
|
||||
@ -108,6 +102,7 @@ class Simple_Local_Avatars {
|
||||
add_filter( 'pre_option_simple_local_avatars', array( $this, 'pre_option_simple_local_avatars' ), 10, 1 );
|
||||
|
||||
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
||||
add_action( 'init', array( $this, 'define_avatar_ratings' ) );
|
||||
|
||||
// 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' ) );
|
||||
@ -508,10 +503,42 @@ class Simple_Local_Avatars {
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the ratings avatar ratings.
|
||||
*
|
||||
* The ratings need to be defined after the languages have been loaded so
|
||||
* they can be translated. This method exists to define the ratings
|
||||
* after that has been done.
|
||||
*
|
||||
* @since 2.7.3
|
||||
*/
|
||||
public function define_avatar_ratings() {
|
||||
/*
|
||||
* Avatar ratings.
|
||||
*
|
||||
* The key should not be translated as it's used by WP Core in it's
|
||||
* english form (G, PG, etc).
|
||||
*
|
||||
* The values should be translated, these include the initial rating
|
||||
* name and the description for display to users.
|
||||
*/
|
||||
$this->avatar_ratings = array(
|
||||
/* translators: Content suitability rating: https://en.wikipedia.org/wiki/Motion_Picture_Association_of_America_film_rating_system */
|
||||
'G' => __( 'G — Suitable for all audiences', ),
|
||||
/* translators: Content suitability rating: https://en.wikipedia.org/wiki/Motion_Picture_Association_of_America_film_rating_system */
|
||||
'PG' => __( 'PG — Possibly offensive, usually for audiences 13 and above', ),
|
||||
/* translators: Content suitability rating: https://en.wikipedia.org/wiki/Motion_Picture_Association_of_America_film_rating_system */
|
||||
'R' => __( 'R — Intended for adult audiences above 17', ),
|
||||
/* translators: Content suitability rating: https://en.wikipedia.org/wiki/Motion_Picture_Association_of_America_film_rating_system */
|
||||
'X' => __( 'X — Even more mature than above', ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register admin settings.
|
||||
*/
|
||||
public function admin_init() {
|
||||
$this->define_avatar_ratings();
|
||||
// upgrade pre 2.0 option
|
||||
$old_ops = get_option( 'simple_local_avatars_caps' );
|
||||
if ( $old_ops ) {
|
||||
@ -857,9 +884,9 @@ class Simple_Local_Avatars {
|
||||
<th scope="row"><label for="simple-local-avatar"><?php esc_html_e( 'Upload Avatar', 'simple-local-avatars' ); ?></label></th>
|
||||
<td style="width: 50px;" id="simple-local-avatar-photo">
|
||||
<?php
|
||||
add_filter( 'pre_option_avatar_rating', '__return_null' ); // ignore ratings here
|
||||
add_filter( 'pre_option_avatar_rating', '__return_empty_string' ); // ignore ratings here
|
||||
echo wp_kses_post( get_simple_local_avatar( $profileuser->ID ) );
|
||||
remove_filter( 'pre_option_avatar_rating', '__return_null' );
|
||||
remove_filter( 'pre_option_avatar_rating', '__return_empty_string' );
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
@ -917,8 +944,6 @@ class Simple_Local_Avatars {
|
||||
<fieldset id="simple-local-avatar-ratings" <?php disabled( empty( $profileuser->simple_local_avatar ) ); ?>>
|
||||
<legend class="screen-reader-text"><span><?php esc_html_e( 'Rating' ); ?></span></legend>
|
||||
<?php
|
||||
$this->update_avatar_ratings();
|
||||
|
||||
if ( empty( $profileuser->simple_local_avatar_rating ) || ! array_key_exists( $profileuser->simple_local_avatar_rating, $this->avatar_ratings ) ) {
|
||||
$profileuser->simple_local_avatar_rating = 'G';
|
||||
}
|
||||
@ -956,7 +981,7 @@ class Simple_Local_Avatars {
|
||||
$meta_value = array();
|
||||
|
||||
// set the new avatar
|
||||
if ( is_int( $url_or_media_id + 0 ) ) {
|
||||
if ( is_numeric( $url_or_media_id ) ) {
|
||||
$meta_value['media_id'] = $url_or_media_id;
|
||||
$url_or_media_id = wp_get_attachment_url( $url_or_media_id );
|
||||
}
|
||||
@ -988,13 +1013,22 @@ class Simple_Local_Avatars {
|
||||
}
|
||||
|
||||
// check for uploaded files
|
||||
if ( ! empty( $_FILES['simple-local-avatar']['name'] ) ) :
|
||||
if ( ! empty( $_FILES['simple-local-avatar']['name'] ) && 0 === $_FILES['simple-local-avatar']['error'] ) :
|
||||
|
||||
// need to be more secure since low privelege users can upload
|
||||
if ( false !== strpos( $_FILES['simple-local-avatar']['name'], '.php' ) ) {
|
||||
$this->avatar_upload_error = __( 'For security reasons, the extension ".php" cannot be in your file name.', 'simple-local-avatars' );
|
||||
add_action( 'user_profile_update_errors', array( $this, 'user_profile_update_errors' ) );
|
||||
$allowed_mime_types = wp_get_mime_types();
|
||||
$file_mime_type = strtolower( $_FILES['simple-local-avatar']['type'] );
|
||||
|
||||
if ( ! ( 0 === strpos( $file_mime_type, 'image/' ) ) || ! in_array( $file_mime_type, $allowed_mime_types, true ) ) {
|
||||
$this->avatar_upload_error = __( 'Only images can be uploaded as an avatar', 'simple-local-avatars' );
|
||||
add_action( 'user_profile_update_errors', array( $this, 'user_profile_update_errors' ) );
|
||||
return;
|
||||
}
|
||||
|
||||
$max_upload_size = $this->upload_size_limit( wp_max_upload_size() );
|
||||
if ( $_FILES['simple-local-avatar']['size'] > $max_upload_size ) {
|
||||
$this->avatar_upload_error = sprintf( __( 'Max allowed avatar size is %s', 'simple-local-avatars' ), size_format( $max_upload_size ) );
|
||||
add_action( 'user_profile_update_errors', array( $this, 'user_profile_update_errors' ) );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1011,9 +1045,6 @@ class Simple_Local_Avatars {
|
||||
include_once ABSPATH . 'wp-admin/includes/image.php';
|
||||
}
|
||||
|
||||
// allow developers to override file size upload limit for avatars
|
||||
add_filter( 'upload_size_limit', array( $this, 'upload_size_limit' ) );
|
||||
|
||||
$this->user_id_being_edited = $user_id; // make user_id known to unique_filename_callback function
|
||||
$avatar_id = media_handle_upload(
|
||||
'simple-local-avatar',
|
||||
@ -1030,8 +1061,6 @@ class Simple_Local_Avatars {
|
||||
)
|
||||
);
|
||||
|
||||
remove_filter( 'upload_size_limit', array( $this, 'upload_size_limit' ) );
|
||||
|
||||
if ( is_wp_error( $avatar_id ) ) { // handle failures.
|
||||
$this->avatar_upload_error = '<strong>' . __( 'There was an error uploading the avatar:', 'simple-local-avatars' ) . '</strong> ' . esc_html( $avatar_id->get_error_message() );
|
||||
add_action( 'user_profile_update_errors', array( $this, 'user_profile_update_errors' ) );
|
||||
@ -1302,20 +1331,6 @@ class Simple_Local_Avatars {
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwriting existing avatar_ratings so this can be called just before the rating strings would be used so that
|
||||
* translations will work correctly.
|
||||
* Default text-domain because the strings have already been translated
|
||||
*/
|
||||
private function update_avatar_ratings() {
|
||||
$this->avatar_ratings = array(
|
||||
'G' => __( 'G — Suitable for all audiences' ),
|
||||
'PG' => __( 'PG — Possibly offensive, usually for audiences 13 and above' ),
|
||||
'R' => __( 'R — Intended for adult audiences above 17' ),
|
||||
'X' => __( 'X — Even more mature than above' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear user cache.
|
||||
*/
|
||||
|
@ -5,7 +5,7 @@ Tags: avatar, gravatar, user photos, users, profile
|
||||
Requires at least: 5.7
|
||||
Tested up to: 6.1
|
||||
Requires PHP: 7.4
|
||||
Stable tag: 2.7.1
|
||||
Stable tag: 2.7.3
|
||||
License: GPLv2 or later
|
||||
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
@ -41,6 +41,19 @@ You can also use `get_simple_local_avatar()` (with the same arguments) to retrei
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 2.7.3 - 2023-01-16 =
|
||||
* **Fixed:** Issue causing fatal errors when avatars used on front end of site (props [@Rottinator](https://github.com/Rottinator), [@peterwilsoncc](https://github.com/peterwilsoncc), [@ravinderk](https://github.com/ravinderk), [@faisal-alvi](https://github.com/faisal-alvi) via [#187](https://github.com/10up/simple-local-avatars/pull/187)).
|
||||
* **Fixed:** Deprecation error in admin on PHP 8.0 and later (props [@Rottinator](https://github.com/Rottinator), [@peterwilsoncc](https://github.com/peterwilsoncc), [@ravinderk](https://github.com/ravinderk), [@faisal-alvi](https://github.com/faisal-alvi) via [#187](https://github.com/10up/simple-local-avatars/pull/187)).
|
||||
|
||||
= 2.7.2 - 2023-01-13 =
|
||||
* **Added:** Filter hook `simple_local_avatars_upload_limit` to restrict image upload size & image file checking enhanced (props [@Shirkit](https://github.com/Shirkit), [@jayedul](https://github.com/jayedul), [@faisal-alvi](https://github.com/faisal-alvi), [@jeffpaul](https://github.com/jeffpaul) via [#171](https://github.com/10up/simple-local-avatars/pull/171)).
|
||||
* **Added:** GitHub Actions summary on Cypress e2e test runs (props [@faisal-alvi](https://github.com/faisal-alvi), [@jeffpaul](https://github.com/jeffpaul), [@iamdharmesh](https://github.com/iamdharmesh) via [#174](https://github.com/10up/simple-local-avatars/pull/174)).
|
||||
* **Changed:** Cypress integration migrated from 9.5.4 to 11.2.0 (props [@iamdharmesh](https://github.com/iamdharmesh), [@jayedul](https://github.com/jayedul), [@faisal-alvi](https://github.com/faisal-alvi) via [#172](https://github.com/10up/simple-local-avatars/pull/172)).
|
||||
* **Fixed:** PHP8 support for `assign_new_user_avatar` (props [@lllopo](https://github.com/lllopo), [@mattwatsoncodes](https://github.com/mattwatsoncodes), [@faisal-alvi](https://github.com/faisal-alvi) via [#183](https://github.com/10up/simple-local-avatars/pull/183)).
|
||||
* **Fixed:** Fixed the user profile language not respected issue (props [@dkotter](https://github.com/dkotter), [@lllopo](https://github.com/lllopo), [@faisal-alvi](https://github.com/faisal-alvi), [@jeffpaul](https://github.com/jeffpaul) via [#175](https://github.com/10up/simple-local-avatars/pull/175)).
|
||||
* **Removed:** textdomain from the core strings and the function `update_avatar_ratings` as it's not required anymore (props [@dkotter](https://github.com/dkotter), [@lllopo](https://github.com/lllopo), [@faisal-alvi](https://github.com/faisal-alvi), [@jeffpaul](https://github.com/jeffpaul) via [#175](https://github.com/10up/simple-local-avatars/pull/175)).
|
||||
* **Security:** Bump `json5` from 1.0.1 to 1.0.2 (props [@dependabot](https://github.com/dependabot), [@faisal-alvi](https://github.com/faisal-alvi) via [#182](https://github.com/10up/simple-local-avatars/pull/182)).
|
||||
|
||||
= 2.7.1 - 2022-12-08 =
|
||||
* **Added:** Added missing files from the last release and changed the readme file to fix the bullet points and added fullstops.
|
||||
|
||||
|
@ -3,10 +3,10 @@
|
||||
* Plugin Name: Simple Local Avatars
|
||||
* 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.
|
||||
* Version: 2.7.1
|
||||
* Version: 2.7.3
|
||||
* Requires at least: 5.7
|
||||
* Requires PHP: 7.4
|
||||
* Author: Jake Goldman, 10up
|
||||
* Author: 10up
|
||||
* Author URI: https://10up.com
|
||||
* License: GPLv2 or later
|
||||
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
@ -20,7 +20,7 @@ define( 'SLA_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
||||
require_once dirname( __FILE__ ) . '/includes/class-simple-local-avatars.php';
|
||||
|
||||
// Global constants.
|
||||
define( 'SLA_VERSION', '2.7.1' );
|
||||
define( 'SLA_VERSION', '2.7.3' );
|
||||
define( 'SLA_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||
|
||||
if ( ! defined( 'SLA_IS_NETWORK' ) ) {
|
||||
|
Loading…
Reference in New Issue
Block a user