!empty( $settings['new_site_defaults'] ), 'source_site_id' => !empty( $settings['source_site_id'] ) ? (int) $settings['source_site_id'] : get_main_site_id(), ]; } /** * Renders the Network Admin page. * * @return void */ public function render_page(): void { if( !current_user_can( 'manage_network_options' ) ) { wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'adminease' ) ); } $settings = self::get_network_settings(); $sites = get_sites( [ 'number' => 200 ] ); if( !in_array( $settings['source_site_id'], array_map( 'intval', wp_list_pluck( $sites, 'blog_id' ) ), true ) ) { $source_site = get_site( $settings['source_site_id'] ); if( $source_site instanceof WP_Site ) { $sites[] = $source_site; } } ?>

!empty( $_POST['adminease_new_site_defaults'] ), 'source_site_id' => $source_site_id, ] ); wp_safe_redirect( add_query_arg( 'updated', 'true', network_admin_url( 'admin.php?page=' . self::PAGE ) ) ); exit; } /** * Gives a new site the source site's settings, when that is switched on. * * Only the option is written here. The flag makes Plugin::maybe_reapply_file_settings() * fire adminease_settings_saved on the new site's first admin visit, when every * feature is loaded for that site and creates its tables and cron events. * * @param WP_Site $new_site The site that was just created. * * @return void */ public function copy_settings_to_new_site( WP_Site $new_site ): void { $network_settings = self::get_network_settings(); if( !$network_settings['new_site_defaults'] ) { return; } $source_site_id = $network_settings['source_site_id']; if( (int) $new_site->blog_id === $source_site_id || !get_site( $source_site_id ) ) { return; } $settings = get_blog_option( $source_site_id, 'adminease_settings', [] ); if( empty( $settings ) || !is_array( $settings ) ) { return; } $settings = self::prepare_new_site_settings( $settings ); switch_to_blog( (int) $new_site->blog_id ); update_option( 'adminease_settings', $settings ); update_option( 'adminease_pending_reapply', 1, false ); restore_current_blog(); } /** * Removes what a new site must not inherit: shared-file settings and the source * site's secrets, with the features that cannot work without them. * * @param array $settings The source site's settings. * * @return array The settings to give the new site. */ public static function prepare_new_site_settings( array $settings ): array { $settings = NetworkLock::remove_shared_settings( $settings ); $secrets = [ 'security' => [ 'password_protect_site_enabled', 'password_protect_site_password' ], 'updates-and-notifications' => [ 'smtp_enabled', 'smtp_password' ], ]; foreach( $secrets as $tab => $keys ) { if( !isset( $settings[ $tab ] ) || !is_array( $settings[ $tab ] ) ) { continue; } foreach( $keys as $key ) { unset( $settings[ $tab ][ $key ] ); } } return $settings; } }