WordPress.org

Make WordPress Core

Ticket #47526: patch.2.diff

File patch.2.diff, 2.2 KB (added by kevindees, 2 months ago)

revised working implementation

  • src/wp-includes/functions.php

     
    195195}
    196196
    197197/**
     198 * Updates _site_state_changed option in database
     199 *
     200 * Should be called when a theme or plugin has been activated or deactivated.
     201 * Used to facilitate tasks like flushing rewrite rules for the registration
     202 * and deregistration of post types and taxonomies.
     203 *
     204 * @since 5.2.2
     205 *
     206 * @param string|array $arg single function name or list of function names
     207 */
     208function update_site_state_changed( $arg ) {
     209    $value = [];
     210
     211    if( $state = get_option( '_site_state_changed' ) ) {
     212        $value = maybe_unserialize( $state );
     213
     214        if( !is_array( $value ) ) {
     215            $value = [];
     216        }
     217    }
     218
     219    if( is_array( $arg ) ) {
     220        $value = array_merge( $value, $arg );
     221    } else {
     222        $value[] = $arg;
     223    }
     224
     225    update_option( '_site_state_changed', $value );
     226}
     227
     228/**
     229 * Check site state
     230 */
     231function check_site_state_change() {
     232    if ( $site_state = get_option( '_site_state_changed' ) ) {
     233        $site_state = apply_filters( 'site_state_changed', $site_state );
     234
     235        if( is_array( $site_state ) ) {
     236            $site_state = array_unique( $site_state );
     237            foreach ( $site_state as $site_state_func ) {
     238                if( function_exists( $site_state_func ) ) {
     239                    call_user_func( $site_state_func );
     240                }
     241            }
     242        }
     243
     244        do_action( 'site_state_changed', $site_state );
     245        delete_option( '_site_state_changed' );
     246    }
     247}
     248
     249/**
    198250 * Determines if the date should be declined.
    199251 *
    200252 * If the locale specifies that month names require a genitive case in certain
  • src/wp-settings.php

     
    534534        unset( $file );
    535535}
    536536
     537// Check site state change
     538check_site_state_change();
     539
    537540/**
    538541 * This hook is fired once WP, all plugins, and the theme are fully loaded and instantiated.
    539542 *