Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address deprecation warning for wpmu_new_blog #156

Merged
merged 4 commits into from
Oct 10, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions includes/class-simple-local-avatars.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function __construct() {
*/
public function add_hooks() {
global $pagenow;
global $wp_version;

add_filter( 'plugin_action_links_' . SLA_PLUGIN_BASENAME, array( $this, 'plugin_filter_action_links' ) );

Expand Down Expand Up @@ -133,7 +134,12 @@ public function add_hooks() {
add_action( 'wp_ajax_sla_clear_user_cache', array( $this, 'sla_clear_user_cache' ) );

add_filter( 'avatar_defaults', array( $this, 'add_avatar_default_field' ) );
add_action( 'wpmu_new_blog', array( $this, 'set_defaults' ) );
if ( version_compare( $wp_version, '5.1', '<' ) {
faisal-alvi marked this conversation as resolved.
Show resolved Hide resolved
add_action( 'wpmu_new_blog', array( $this, 'set_defaults' ) );
} else {
add_action( 'wp_initialize_site', array( $this, 'set_defaults' ) );
}

faisal-alvi marked this conversation as resolved.
Show resolved Hide resolved

if ( 'profile.php' === $pagenow ) {
add_filter( 'media_view_strings', function ( $strings ) {
Expand Down Expand Up @@ -1233,13 +1239,17 @@ public function pre_option_simple_local_avatars( $value ) {
/**
* Set plugin defaults for a new site
*
* @param int $blog_id Blog ID.
* @param int|WP_Site $blog_id Blog ID.
faisal-alvi marked this conversation as resolved.
Show resolved Hide resolved
*/
public function set_defaults( $blog_id ) {
if ( 'enforce' === $this->get_network_mode() ) {
return;
}

if ( $blog_id instanceof WP_Site ) {
$blog_id = (int) $blog_id->blog_id;
}

switch_to_blog( $blog_id );
update_option( 'simple_local_avatars', $this->sanitize_options( $this->options ) );
restore_current_blog();
Expand Down