Created
April 13, 2018 16:12
-
-
Save pcfreak30/12a0023518863ad75c2c05c76e8f53da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function unload_textdomain( $value, $domain ) { | |
if ( isset( $GLOBALS['l10n'][ $domain ] ) ) { | |
unset( $GLOBALS['l10n'][ $domain ] ); | |
} | |
return $value; | |
} | |
public function one_time_false() { | |
remove_filter( 'locale', [ $this, 'one_time_false' ] ); | |
return false; | |
} | |
private function update_rewrites( $network_wide, $insert ) { | |
$blog_ids = (array) get_current_blog_id(); | |
if ( is_multisite() && $network_wide ) { | |
$blog_ids = get_sites( | |
[ | |
'fields' => 'ids', | |
] | |
); | |
} | |
$rewrite_objects = []; | |
foreach ( | |
$blog_ids | |
as $blog_id | |
) { | |
if ( is_multisite() ) { | |
switch_to_blog( $blog_id ); | |
unset( $GLOBALS['locale'] ); | |
$locale = get_locale(); | |
unset( $GLOBALS['locale'] ); | |
restore_current_blog(); | |
add_filter( 'locale', [ $this, 'one_time_false' ] ); | |
add_filter( 'override_unload_textdomain', [ $this, 'unload_textdomain' ], 10, 2 ); | |
switch_to_locale( $locale ); | |
remove_filter( 'locale', [ $this, 'one_time_false' ] ); | |
remove_filter( 'override_unload_textdomain', [ $this, 'unload_textdomain' ] ); | |
switch_to_blog( $blog_id ); | |
$rewrite_objects[ $blog_id ] = $GLOBALS['wp_rewrite']; | |
$GLOBALS['wp_rewrite'] = new \WP_Rewrite(); | |
do_action( "{$this->plugin->safe_slug}_multisite_before_rewrites", $blog_id ); | |
} | |
if ( $insert ) { | |
$this->plugin->request->add_rewrite_rules(); | |
} | |
flush_rewrite_rules(); | |
if ( is_multisite() ) { | |
do_action( "{$this->plugin->safe_slug}_multisite_after_rewrites", $blog_id ); | |
restore_current_blog(); | |
add_filter( 'override_unload_textdomain', [ $this, 'unload_textdomain' ], 10, 2 ); | |
restore_current_locale(); | |
remove_filter( 'override_unload_textdomain', [ $this, 'unload_textdomain' ] ); | |
$GLOBALS['wp_rewrite'] = $rewrite_objects[ $blog_id ]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment