From 9adda3e4d3e0d37cf426a3d7773623d3c264b085 Mon Sep 17 00:00:00 2001 From: JK Date: Tue, 27 Jun 2023 00:03:48 +0600 Subject: [PATCH 01/12] Host/Domain change support added for local avatar url --- includes/class-simple-local-avatars.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/includes/class-simple-local-avatars.php b/includes/class-simple-local-avatars.php index 0eb8fa84..693963c1 100644 --- a/includes/class-simple-local-avatars.php +++ b/includes/class-simple-local-avatars.php @@ -337,7 +337,7 @@ public function get_simple_local_avatar_url( $id_or_email, $size ) { // Fetch local avatar from meta and make sure it's properly set. $local_avatars = get_user_meta( $user_id, $this->user_key, true ); - if ( empty( $local_avatars['full'] ) ) { + if ( empty( $local_avatars['media_id'] ) ) { return ''; } @@ -371,12 +371,15 @@ public function get_simple_local_avatar_url( $id_or_email, $size ) { if ( ! $avatar_full_path ) { return ''; } + + // Use dynamic full url in favour of host/domain change. + $local_avatars['full'] = wp_get_attachment_image_url( $local_avatars['media_id'], 'full' ); } $size = (int) $size; // Generate a new size. - if ( ! array_key_exists( $size, $local_avatars ) ) { + if ( ! array_key_exists( $size, $local_avatars ) || ! ( strpos( $local_avatars[ $size ], content_url() ) === 0 ) ) { $local_avatars[ $size ] = $local_avatars['full']; // just in case of failure elsewhere // allow automatic rescaling to be turned off From fcb274c6a256a59ace993999af0e5240d270578e Mon Sep 17 00:00:00 2001 From: JK Date: Tue, 27 Jun 2023 00:38:31 +0600 Subject: [PATCH 02/12] PHPUnit Fix --- tests/phpunit/SimpleLocalAvatarsTest.php | 16 ++++++++++++++++ .../multisite/SimpleLocalAvatarsNetworkTest.php | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/tests/phpunit/SimpleLocalAvatarsTest.php b/tests/phpunit/SimpleLocalAvatarsTest.php index 7b7c3ce3..71d87fba 100644 --- a/tests/phpunit/SimpleLocalAvatarsTest.php +++ b/tests/phpunit/SimpleLocalAvatarsTest.php @@ -64,6 +64,13 @@ public function setUp(): void { ->with( 101 ) ->andReturn( '/avatar.png' ); + WP_Mock::userFunction( 'wp_get_attachment_image_url' ) + ->with( 101, 'full' ) + ->andReturn( '/avatar.png' ); + + WP_Mock::userFunction( 'content_url' ) + ->andReturn( 'http://localhost/simple-local-avatar/wp-content' ); + WP_Mock::userFunction( 'admin_url' ) ->with( 'options-discussion.php' ) ->andReturn( 'wp-admin/options-discussion.php' ); @@ -196,9 +203,18 @@ public function test_get_simple_local_avatar_url_media_file_deleted() { WP_Mock::userFunction( 'get_user_meta' ) ->with( 2, 'simple_local_avatar', true ) ->andReturn( [ 'media_id' => 102 ] ); + WP_Mock::userFunction( 'get_attached_file' ) ->with( 102 ) ->andReturn( false ); + + WP_Mock::userFunction( 'wp_get_attachment_image_url' ) + ->with( 102, 'full' ) + ->andReturn( false ); + + WP_Mock::userFunction( 'content_url' ) + ->andReturn( 'http://localhost/simple-local-avatar/wp-content' ); + $this->assertEquals( '', $this->instance->get_simple_local_avatar_url( 2, 96 ) ); } diff --git a/tests/phpunit/multisite/SimpleLocalAvatarsNetworkTest.php b/tests/phpunit/multisite/SimpleLocalAvatarsNetworkTest.php index 1b619bf8..e44dd86a 100644 --- a/tests/phpunit/multisite/SimpleLocalAvatarsNetworkTest.php +++ b/tests/phpunit/multisite/SimpleLocalAvatarsNetworkTest.php @@ -131,6 +131,16 @@ public function test_get_simple_local_avatar_url() { 'return' => '/avatar.png', 'times' => 1, ] ); + WP_Mock::userFunction( 'wp_get_attachment_image_url', [ + 'args' => [ 101, 'full' ], + 'return' => '/avatar.png', + 'times' => 1, + ] ); + WP_Mock::userFunction( 'content_url', [ + 'args' => [], + 'return' => 'http://localhost/simple-local-avatar/wp-content', + 'times' => 1, + ] ); WP_Mock::userFunction( 'get_option' ) ->with( 'avatar_rating' ) ->andReturn( false ); From d18ebf29f515a80d82ff26054834064111471a5e Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 19 Sep 2023 19:13:27 +0530 Subject: [PATCH 03/12] chore: ignore file --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 6c8d7791..6b5cf2df 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,5 @@ tests/cypress/screenshots tests/cypress/videos tests/cypress/downloads tests/cypress/reports + +.phpunit.result.cache From 0d6c6d75ed1d8fd25742796b6d1b94ba23bf27a6 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 19 Sep 2023 19:14:54 +0530 Subject: [PATCH 04/12] format: improve code formatting --- includes/class-simple-local-avatars.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/class-simple-local-avatars.php b/includes/class-simple-local-avatars.php index ba6e70db..0a376333 100644 --- a/includes/class-simple-local-avatars.php +++ b/includes/class-simple-local-avatars.php @@ -335,6 +335,8 @@ public function get_simple_local_avatar_url( $id_or_email, $size ) { return ''; } + + // Fetch local avatar from meta and make sure it's properly set. $local_avatars = get_user_meta( $user_id, $this->user_key, true ); if ( empty( $local_avatars['media_id'] ) ) { @@ -357,7 +359,7 @@ public function get_simple_local_avatar_url( $id_or_email, $size ) { if ( ! empty( $local_avatars['media_id'] ) ) { // If using shared avatars, make sure we validate the URL on the main site. if ( $this->is_avatar_shared() ) { - $origin_blog_id = isset( $local_avatars['blog_id'] ) && ! empty( $local_avatars['blog_id'] ) ? $local_avatars['blog_id'] : get_main_site_id(); + $origin_blog_id = ! empty( $local_avatars['blog_id'] ) ? $local_avatars['blog_id'] : get_main_site_id(); switch_to_blog( $origin_blog_id ); } @@ -419,7 +421,7 @@ public function get_simple_local_avatar_url( $id_or_email, $size ) { endif; } - if ( 'http' !== substr( $local_avatars[ $size ], 0, 4 ) ) { + if ( strpos( $local_avatars[ $size ], 'http' ) !== 0 ) { $local_avatars[ $size ] = home_url( $local_avatars[ $size ] ); } From 08a2fc612a3fce8bf229a670933c0e11094e55d6 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 19 Sep 2023 19:30:59 +0530 Subject: [PATCH 05/12] format: remove extra newline --- includes/class-simple-local-avatars.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/class-simple-local-avatars.php b/includes/class-simple-local-avatars.php index 0a376333..24de73c0 100644 --- a/includes/class-simple-local-avatars.php +++ b/includes/class-simple-local-avatars.php @@ -335,8 +335,6 @@ public function get_simple_local_avatar_url( $id_or_email, $size ) { return ''; } - - // Fetch local avatar from meta and make sure it's properly set. $local_avatars = get_user_meta( $user_id, $this->user_key, true ); if ( empty( $local_avatars['media_id'] ) ) { From 4a05dd77abdaa4ce4bd4258c9c4224b7cb463b3f Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 19 Sep 2023 19:37:14 +0530 Subject: [PATCH 06/12] tests: set content url to example.com --- tests/phpunit/SimpleLocalAvatarsTest.php | 6 +++--- tests/phpunit/multisite/SimpleLocalAvatarsNetworkTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/SimpleLocalAvatarsTest.php b/tests/phpunit/SimpleLocalAvatarsTest.php index 71d87fba..5f031475 100644 --- a/tests/phpunit/SimpleLocalAvatarsTest.php +++ b/tests/phpunit/SimpleLocalAvatarsTest.php @@ -69,7 +69,7 @@ public function setUp(): void { ->andReturn( '/avatar.png' ); WP_Mock::userFunction( 'content_url' ) - ->andReturn( 'http://localhost/simple-local-avatar/wp-content' ); + ->andReturn( 'https://example.com/' ); WP_Mock::userFunction( 'admin_url' ) ->with( 'options-discussion.php' ) @@ -207,13 +207,13 @@ public function test_get_simple_local_avatar_url_media_file_deleted() { WP_Mock::userFunction( 'get_attached_file' ) ->with( 102 ) ->andReturn( false ); - + WP_Mock::userFunction( 'wp_get_attachment_image_url' ) ->with( 102, 'full' ) ->andReturn( false ); WP_Mock::userFunction( 'content_url' ) - ->andReturn( 'http://localhost/simple-local-avatar/wp-content' ); + ->andReturn( 'http://example.com' ); $this->assertEquals( '', $this->instance->get_simple_local_avatar_url( 2, 96 ) ); } diff --git a/tests/phpunit/multisite/SimpleLocalAvatarsNetworkTest.php b/tests/phpunit/multisite/SimpleLocalAvatarsNetworkTest.php index e44dd86a..84dd9d0d 100644 --- a/tests/phpunit/multisite/SimpleLocalAvatarsNetworkTest.php +++ b/tests/phpunit/multisite/SimpleLocalAvatarsNetworkTest.php @@ -138,7 +138,7 @@ public function test_get_simple_local_avatar_url() { ] ); WP_Mock::userFunction( 'content_url', [ 'args' => [], - 'return' => 'http://localhost/simple-local-avatar/wp-content', + 'return' => 'http://example.com', 'times' => 1, ] ); WP_Mock::userFunction( 'get_option' ) From 61df6f8a475c060230066066e62487c773814f93 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 19 Sep 2023 19:41:25 +0530 Subject: [PATCH 07/12] fix: return avatar if exist --- includes/class-simple-local-avatars.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/includes/class-simple-local-avatars.php b/includes/class-simple-local-avatars.php index 24de73c0..e23a26c0 100644 --- a/includes/class-simple-local-avatars.php +++ b/includes/class-simple-local-avatars.php @@ -335,8 +335,14 @@ public function get_simple_local_avatar_url( $id_or_email, $size ) { return ''; } - // Fetch local avatar from meta and make sure it's properly set. $local_avatars = get_user_meta( $user_id, $this->user_key, true ); + + // Return avatar if exists. + if ( array_key_exists( $size, $local_avatars ) && ( strpos( $local_avatars[ $size ], content_url() ) === 0 ) ) { + return esc_url( $local_avatars[ $size ] ); + } + + // Fetch local avatar from meta and make sure it's properly set. if ( empty( $local_avatars['media_id'] ) ) { return ''; } From f0adefe8adb6f7910d517cfdae6d520aa4697126 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 19 Sep 2023 19:46:11 +0530 Subject: [PATCH 08/12] refactor: remove unused if condition --- includes/class-simple-local-avatars.php | 32 ++++++++++++------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/includes/class-simple-local-avatars.php b/includes/class-simple-local-avatars.php index e23a26c0..d7d007d4 100644 --- a/includes/class-simple-local-avatars.php +++ b/includes/class-simple-local-avatars.php @@ -360,28 +360,26 @@ public function get_simple_local_avatar_url( $id_or_email, $size ) { } // handle "real" media - if ( ! empty( $local_avatars['media_id'] ) ) { - // If using shared avatars, make sure we validate the URL on the main site. - if ( $this->is_avatar_shared() ) { - $origin_blog_id = ! empty( $local_avatars['blog_id'] ) ? $local_avatars['blog_id'] : get_main_site_id(); - switch_to_blog( $origin_blog_id ); - } + // If using shared avatars, make sure we validate the URL on the main site. + if ( $this->is_avatar_shared() ) { + $origin_blog_id = ! empty( $local_avatars['blog_id'] ) ? $local_avatars['blog_id'] : get_main_site_id(); + switch_to_blog( $origin_blog_id ); + } - $avatar_full_path = get_attached_file( $local_avatars['media_id'] ); + $avatar_full_path = get_attached_file( $local_avatars['media_id'] ); - if ( $this->is_avatar_shared() ) { - restore_current_blog(); - } - - // has the media been deleted? - if ( ! $avatar_full_path ) { - return ''; - } + if ( $this->is_avatar_shared() ) { + restore_current_blog(); + } - // Use dynamic full url in favour of host/domain change. - $local_avatars['full'] = wp_get_attachment_image_url( $local_avatars['media_id'], 'full' ); + // has the media been deleted? + if ( ! $avatar_full_path ) { + return ''; } + // Use dynamic full url in favour of host/domain change. + $local_avatars['full'] = wp_get_attachment_image_url( $local_avatars['media_id'], 'full' ); + $size = (int) $size; // Generate a new size. From 97c54878cb668b2921b6fcfeeff62d46072d4aea Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 19 Sep 2023 19:50:05 +0530 Subject: [PATCH 09/12] refactor: remove unused if condition --- includes/class-simple-local-avatars.php | 63 ++++++++++++------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/includes/class-simple-local-avatars.php b/includes/class-simple-local-avatars.php index d7d007d4..3ef065dd 100644 --- a/includes/class-simple-local-avatars.php +++ b/includes/class-simple-local-avatars.php @@ -330,6 +330,7 @@ public function get_user_id( $id_or_email ) { */ public function get_simple_local_avatar_url( $id_or_email, $size ) { $user_id = $this->get_user_id( $id_or_email ); + $size = (int) $size; if ( empty( $user_id ) ) { return ''; @@ -380,48 +381,44 @@ public function get_simple_local_avatar_url( $id_or_email, $size ) { // Use dynamic full url in favour of host/domain change. $local_avatars['full'] = wp_get_attachment_image_url( $local_avatars['media_id'], 'full' ); - $size = (int) $size; - // Generate a new size. - if ( ! array_key_exists( $size, $local_avatars ) || ! ( strpos( $local_avatars[ $size ], content_url() ) === 0 ) ) { - $local_avatars[ $size ] = $local_avatars['full']; // just in case of failure elsewhere - - // allow automatic rescaling to be turned off - if ( apply_filters( 'simple_local_avatars_dynamic_resize', true ) ) : + // Just in case of failure elsewhere, set the full size as default. + $local_avatars[ $size ] = $local_avatars['full']; - $upload_path = wp_upload_dir(); + // allow automatic rescaling to be turned off + if ( apply_filters( 'simple_local_avatars_dynamic_resize', true ) ) : - // get path for image by converting URL, unless its already been set, thanks to using media library approach - if ( ! isset( $avatar_full_path ) ) { - $avatar_full_path = str_replace( $upload_path['baseurl'], $upload_path['basedir'], $local_avatars['full'] ); - } + $upload_path = wp_upload_dir(); - // generate the new size - $editor = wp_get_image_editor( $avatar_full_path ); - if ( ! is_wp_error( $editor ) ) { - $resized = $editor->resize( $size, $size, true ); - if ( ! is_wp_error( $resized ) ) { - $dest_file = $editor->generate_filename(); - $saved = $editor->save( $dest_file ); - if ( ! is_wp_error( $saved ) ) { - // 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 ); - } + // get path for image by converting URL, unless its already been set, thanks to using media library approach + if ( ! isset( $avatar_full_path ) ) { + $avatar_full_path = str_replace( $upload_path['baseurl'], $upload_path['basedir'], $local_avatars['full'] ); + } - $local_avatars[ $size ] = $dest_file_url; + // generate the new size + $editor = wp_get_image_editor( $avatar_full_path ); + if ( ! is_wp_error( $editor ) ) { + $resized = $editor->resize( $size, $size, true ); + if ( ! is_wp_error( $resized ) ) { + $dest_file = $editor->generate_filename(); + $saved = $editor->save( $dest_file ); + if ( ! is_wp_error( $saved ) ) { + // 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; } } + } - // save updated avatar sizes - update_user_meta( $user_id, $this->user_key, $local_avatars ); - - endif; - } + // save updated avatar sizes + update_user_meta( $user_id, $this->user_key, $local_avatars ); + endif; if ( strpos( $local_avatars[ $size ], 'http' ) !== 0 ) { $local_avatars[ $size ] = home_url( $local_avatars[ $size ] ); From 24a661ebe9dec6a1192186fbf393ec6791864ba7 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Fri, 22 Sep 2023 18:15:34 +0530 Subject: [PATCH 10/12] update unit test as per new changes --- .../SimpleLocalAvatarsNetworkTest.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/phpunit/multisite/SimpleLocalAvatarsNetworkTest.php b/tests/phpunit/multisite/SimpleLocalAvatarsNetworkTest.php index 84dd9d0d..7a073b4d 100644 --- a/tests/phpunit/multisite/SimpleLocalAvatarsNetworkTest.php +++ b/tests/phpunit/multisite/SimpleLocalAvatarsNetworkTest.php @@ -141,6 +141,30 @@ public function test_get_simple_local_avatar_url() { 'return' => 'http://example.com', 'times' => 1, ] ); + WP_Mock::userFunction( 'wp_upload_dir', [ + 'args' => [], + 'return' => ['baseurl' => '', 'basedir' => ''], + 'times' => 1, + ] ); + WP_Mock::userFunction( 'wp_get_image_editor', [ + 'args' => [ '/avatar.png' ], + 'return' => false, + 'times' => 1, + ] ); + WP_Mock::userFunction( 'is_wp_error', [ + 'return' => true, + 'times' => 1, + ] ); + WP_Mock::userFunction( 'update_user_meta', [ + 'args' => [ 1, 'simple_local_avatar', ['media_id' => 101, 'full' => '/avatar.png', 96 => '/avatar.png'] ], + 'return' => true, + 'times' => 1, + ] ); + WP_Mock::userFunction( 'home_url', [ + 'args' => [ '/avatar.png' ], + 'return' => 'https://example.com/avatar-96x96.png', + 'times' => 1, + ] ); WP_Mock::userFunction( 'get_option' ) ->with( 'avatar_rating' ) ->andReturn( false ); From 7ce4d23e3bdf8add81e1de194f2c3ce25d58a98c Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Fri, 22 Sep 2023 19:15:19 +0530 Subject: [PATCH 11/12] improve condition to fix cypress fatal error Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, string given in /var/www/html/wp-content/plugins/simple-local-avatars/includes/class-simple-local-avatars.php:342 --- includes/class-simple-local-avatars.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-simple-local-avatars.php b/includes/class-simple-local-avatars.php index 3ef065dd..5dbfa297 100644 --- a/includes/class-simple-local-avatars.php +++ b/includes/class-simple-local-avatars.php @@ -339,7 +339,7 @@ public function get_simple_local_avatar_url( $id_or_email, $size ) { $local_avatars = get_user_meta( $user_id, $this->user_key, true ); // Return avatar if exists. - if ( array_key_exists( $size, $local_avatars ) && ( strpos( $local_avatars[ $size ], content_url() ) === 0 ) ) { + if ( is_array( $local_avatars ) && array_key_exists( $size, $local_avatars ) && ( strpos( $local_avatars[ $size ], content_url() ) === 0 ) ) { return esc_url( $local_avatars[ $size ] ); } From a6770c5001a983815c4707ec9cb1b2298366fa78 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Fri, 22 Sep 2023 19:44:12 +0530 Subject: [PATCH 12/12] fixing phpcs issues --- includes/class-simple-local-avatars.php | 42 +++++++++++++++---------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/includes/class-simple-local-avatars.php b/includes/class-simple-local-avatars.php index 5dbfa297..ef33b24e 100644 --- a/includes/class-simple-local-avatars.php +++ b/includes/class-simple-local-avatars.php @@ -65,9 +65,9 @@ class Simple_Local_Avatars { public function __construct() { $this->add_hooks(); - $this->options = (array) get_option( 'simple_local_avatars' ); - $this->user_key = 'simple_local_avatar'; - $this->rating_key = 'simple_local_avatar_rating'; + $this->options = (array) get_option( 'simple_local_avatars' ); + $this->user_key = 'simple_local_avatar'; + $this->rating_key = 'simple_local_avatar_rating'; if ( ! $this->is_avatar_shared() // Are we sharing avatars? @@ -136,18 +136,26 @@ public function add_hooks() { } if ( 'profile.php' === $pagenow ) { - add_filter( 'media_view_strings', function ( $strings ) { - $strings['skipCropping'] = esc_html__( 'Default Crop', 'simple-local-avatars' ); - - return $strings; - }, 10, 1 ); + add_filter( + 'media_view_strings', + function ( $strings ) { + $strings['skipCropping'] = esc_html__( 'Default Crop', 'simple-local-avatars' ); + + return $strings; + }, + 10, + 1 + ); } // Fix: An error occurred cropping the image (https://github.com/10up/simple-local-avatars/issues/141). if ( isset( $_POST['action'] ) && 'crop-image' === $_POST['action'] && is_admin() && wp_doing_ajax() ) { - add_action( 'plugins_loaded', function () { - remove_all_actions( 'setup_theme' ); - } ); + add_action( + 'plugins_loaded', + function () { + remove_all_actions( 'setup_theme' ); + } + ); } } @@ -330,7 +338,7 @@ public function get_user_id( $id_or_email ) { */ public function get_simple_local_avatar_url( $id_or_email, $size ) { $user_id = $this->get_user_id( $id_or_email ); - $size = (int) $size; + $size = (int) $size; if ( empty( $user_id ) ) { return ''; @@ -407,7 +415,7 @@ public function get_simple_local_avatar_url( $id_or_email, $size ) { $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' ) ) { + } elseif ( 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 ); } @@ -1008,7 +1016,7 @@ public function assign_new_user_avatar( $url_or_media_id, $user_id ) { * * @param int $user_id Id of the user who's avatar was updated */ - do_action( 'simple_local_avatar_updated' , $user_id ); + do_action( 'simple_local_avatar_updated', $user_id ); } /** @@ -1415,9 +1423,9 @@ private function clear_user_avatar_cache( $local_avatars, $user_id, $media_id ) $file_name_data = pathinfo( get_attached_file( $media_id ) ); } - $file_dir_name = $file_name_data['dirname']; - $file_name = $file_name_data['filename']; - $file_ext = $file_name_data['extension']; + $file_dir_name = $file_name_data['dirname']; + $file_name = $file_name_data['filename']; + $file_ext = $file_name_data['extension']; foreach ( $local_avatars as $local_avatars_key => $local_avatar_value ) { if ( ! in_array( $local_avatars_key, [ 'media_id', 'full' ], true ) ) { $file_size_path = sprintf( '%1$s/%2$s-%3$sx%3$s.%4$s', $file_dir_name, $file_name, $local_avatars_key, $file_ext );