updated plugin Simple Local Avatars version 2.7.3

This commit is contained in:
2023-01-18 16:40:01 +00:00
committed by Gitium
parent 35a7ea2e06
commit 0bf59ae0ba
3 changed files with 66 additions and 38 deletions

View File

@ -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 &#8212; Suitable for all audiences' ),
'PG' => __( 'PG &#8212; Possibly offensive, usually for audiences 13 and above' ),
'R' => __( 'R &#8212; Intended for adult audiences above 17' ),
'X' => __( 'X &#8212; Even more mature than above' ),
);
}
/**
* Clear user cache.
*/