Make WordPress Core

Ticket #21432: 21432.diff

File 21432.diff, 12.1 KB (added by ryan, 13 years ago)

Incomplete and untested

  • class-wp-theme.php

     
    11091109
    11101110                $current = $blog_id == get_current_blog_id();
    11111111
    1112                 if ( $current )
     1112                if ( $current ) {
    11131113                        $allowed_themes[ $blog_id ] = get_option( 'allowedthemes' );
    1114                 else
    1115                         $allowed_themes[ $blog_id ] = get_blog_option( $blog_id, 'allowedthemes' );
     1114                } else {
     1115                        switch_to_blog( $blog_id );
     1116                        $allowed_themes[ $blog_id ] = get_option( 'allowedthemes' );
     1117                        restore_current_blog();
     1118                }
    11161119
    11171120                // This is all super old MU back compat joy.
    11181121                // 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
    11191122                if ( false === $allowed_themes[ $blog_id ] ) {
    1120                         if ( $current )
     1123                        if ( $current ) {
    11211124                                $allowed_themes[ $blog_id ] = get_option( 'allowed_themes' );
    1122                         else
    1123                                 $allowed_themes[ $blog_id ] = get_blog_option( $blog_id, 'allowed_themes' );
     1125                        } else {
     1126                                switch_to_blog( $blog_id );
     1127                                $allowed_themes[ $blog_id ] = get_option( 'allowed_themes' );
     1128                                restore_current_blog();
     1129                        }
    11241130
    11251131                        if ( ! is_array( $allowed_themes[ $blog_id ] ) || empty( $allowed_themes[ $blog_id ] ) ) {
    11261132                                $allowed_themes[ $blog_id ] = array();
     
    11391145                                        update_option( 'allowedthemes', $allowed_themes[ $blog_id ] );
    11401146                                        delete_option( 'allowed_themes' );
    11411147                                } else {
    1142                                         update_blog_option( $blog_id, 'allowedthemes', $allowed_themes[ $blog_id ] );
    1143                                         delete_blog_option( $blog_id, 'allowed_themes' );
     1148                                        switch_to_blog( $blog_id );
     1149                                        update_option( 'allowedthemes', $allowed_themes[ $blog_id ] );
     1150                                        delete_option( 'allowed_themes' );
     1151                                        restore_current_blog();
    11441152                                }
    11451153                        }
    11461154                }
  • ms-blogs.php

     
    222222                return $details;
    223223        }
    224224
    225         $details->blogname              = get_blog_option( $blog_id, 'blogname' );
    226         $details->siteurl               = get_blog_option( $blog_id, 'siteurl' );
    227         $details->post_count    = get_blog_option( $blog_id, 'post_count' );
     225        switch_to_blog( $blog_id );
     226        $details->blogname              = get_option( 'blogname' );
     227        $details->siteurl               = get_option( 'siteurl' );
     228        $details->post_count    = get_option( 'post_count' );
     229        restore_current_blog();
    228230
    229231        $details = apply_filters( 'blog_details', $details );
    230232
     
    307309}
    308310
    309311/**
    310  * Retrieve option value for a given blog id based on name of option.
    311  *
    312  * If the option does not exist or does not have a value, then the return value
    313  * will be false. This is useful to check whether you need to install an option
    314  * and is commonly used during installation of plugin options and to test
    315  * whether upgrading is required.
    316  *
    317  * If the option was serialized then it will be unserialized when it is returned.
    318  *
    319  * @since MU
    320  *
    321  * @param int $id A blog ID. Can be null to refer to the current blog.
    322  * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
    323  * @param mixed $default Optional. Default value to return if the option does not exist.
    324  * @return mixed Value set for the option.
    325  */
    326 function get_blog_option( $id, $option, $default = false ) {
    327         $id = (int) $id;
    328 
    329         if ( empty( $id ) )
    330                 $id = get_current_blog_id();
    331 
    332         if ( $id == get_current_blog_id() )
    333                 return get_option( $option, $default );
    334 
    335         switch_to_blog( $id );
    336         $option = get_option( $option, $default );
    337         restore_current_blog();
    338 
    339         return $option;
    340 }
    341 
    342 /**
    343  * Add a new option for a given blog id.
    344  *
    345  * You do not need to serialize values. If the value needs to be serialized, then
    346  * it will be serialized before it is inserted into the database. Remember,
    347  * resources can not be serialized or added as an option.
    348  *
    349  * You can create options without values and then update the values later.
    350  * Existing options will not be updated and checks are performed to ensure that you
    351  * aren't adding a protected WordPress option. Care should be taken to not name
    352  * options the same as the ones which are protected.
    353  *
    354  * @since MU
    355  *
    356  * @param int $id A blog ID. Can be null to refer to the current blog.
    357  * @param string $option Name of option to add. Expected to not be SQL-escaped.
    358  * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped.
    359  * @return bool False if option was not added and true if option was added.
    360  */
    361 function add_blog_option( $id, $option, $value ) {
    362         $id = (int) $id;
    363 
    364         if ( empty( $id ) )
    365                 $id = get_current_blog_id();
    366 
    367         if ( $id == get_current_blog_id() )
    368                 return add_option( $option, $value );
    369 
    370         switch_to_blog( $id );
    371         $return = add_option( $option, $value );
    372         restore_current_blog();
    373 
    374         return $return;
    375 }
    376 
    377 /**
    378  * Removes option by name for a given blog id. Prevents removal of protected WordPress options.
    379  *
    380  * @since MU
    381  *
    382  * @param int $id A blog ID. Can be null to refer to the current blog.
    383  * @param string $option Name of option to remove. Expected to not be SQL-escaped.
    384  * @return bool True, if option is successfully deleted. False on failure.
    385  */
    386 function delete_blog_option( $id, $option ) {
    387         $id = (int) $id;
    388 
    389         if ( empty( $id ) )
    390                 $id = get_current_blog_id();
    391 
    392         if ( $id == get_current_blog_id() )
    393                 return delete_option( $option );
    394 
    395         switch_to_blog( $id );
    396         $return = delete_option( $option );
    397         restore_current_blog();
    398 
    399         return $return;
    400 }
    401 
    402 /**
    403  * Update an option for a particular blog.
    404  *
    405  * @since MU
    406  *
    407  * @param int $id The blog id
    408  * @param string $option The option key
    409  * @param mixed $value The option value
    410  * @return bool True on success, false on failrue.
    411  */
    412 function update_blog_option( $id, $option, $value, $deprecated = null ) {
    413         $id = (int) $id;
    414 
    415         if ( null !== $deprecated  )
    416                 _deprecated_argument( __FUNCTION__, '3.1' );
    417 
    418         if ( $id == get_current_blog_id() )
    419                 return update_option( $option, $value );
    420 
    421         switch_to_blog( $id );
    422         $return = update_option( $option, $value );
    423         restore_current_blog();
    424 
    425         refresh_blog_details( $id );
    426 
    427         return $return;
    428 }
    429 
    430 /**
    431312 * Switch the current blog.
    432313 *
    433314 * This function is useful if you need to pull posts, or other information,
  • class-wp-xmlrpc-server.php

     
    475475                        $blog_id = $blog->userblog_id;
    476476                        $is_admin = current_user_can_for_blog( $blog_id, 'manage_options' );
    477477
     478                        switch_to_blog( $blog_id );
    478479                        $struct[] = array(
    479480                                'isAdmin'               => $is_admin,
    480                                 'url'                   => get_home_url( $blog_id, '/' ),
     481                                'url'                   => home_url( '/' ),
    481482                                'blogid'                => (string) $blog_id,
    482                                 'blogName'              => get_blog_option( $blog_id, 'blogname' ),
    483                                 'xmlrpc'                => get_site_url( $blog_id, 'xmlrpc.php' )
     483                                'blogName'              => get_option( 'blogname' ),
     484                                'xmlrpc'                => site_url( 'xmlrpc.php' )
    484485                        );
     486                        restore_current_blog();
    485487                }
    486488
    487489                return $struct;
  • link-template.php

     
    18961896        if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) )
    18971897                $scheme = is_ssl() && !is_admin() ? 'https' : 'http';
    18981898
    1899         if ( empty( $blog_id ) || !is_multisite() )
     1899        if ( empty( $blog_id ) || !is_multisite() ) {
    19001900                $url = get_option( 'home' );
    1901         else
    1902                 $url = get_blog_option( $blog_id, 'home' );
     1901        } else {
     1902                switch_to_blog( $blog_id );
     1903                $url = get_option( 'home' );
     1904                restore_current_blog();
     1905        }
    19031906
    19041907        if ( 'relative' == $scheme )
    19051908                $url = preg_replace( '#^.+://[^/]*#', '', $url );
     
    19611964                        $scheme = ( is_ssl() ? 'https' : 'http' );
    19621965        }
    19631966
    1964         if ( empty( $blog_id ) || !is_multisite() )
     1967        if ( empty( $blog_id ) || !is_multisite() ) {
    19651968                $url = get_option( 'siteurl' );
    1966         else
    1967                 $url = get_blog_option( $blog_id, 'siteurl' );
     1969        } else {
     1970                switch_to_blog( $blog_id );
     1971                $url = get_option( 'siteurl' );
     1972                restore_current_blog();
     1973        }
    19681974
    19691975        if ( 'relative' == $scheme )
    19701976                $url = preg_replace( '#^.+://[^/]*#', '', $url );
  • ms-deprecated.php

     
    270270        }
    271271        return $url;
    272272}
     273
     274/**
     275 * Retrieve option value for a given blog id based on name of option.
     276 *
     277 * If the option does not exist or does not have a value, then the return value
     278 * will be false. This is useful to check whether you need to install an option
     279 * and is commonly used during installation of plugin options and to test
     280 * whether upgrading is required.
     281 *
     282 * If the option was serialized then it will be unserialized when it is returned.
     283 *
     284 * @since MU
     285 * @deprecated 3.5.0
     286 *
     287 * @param int $id A blog ID. Can be null to refer to the current blog.
     288 * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
     289 * @param mixed $default Optional. Default value to return if the option does not exist.
     290 * @return mixed Value set for the option.
     291 */
     292function get_blog_option( $id, $option, $default = false ) {
     293        _deprecated_function( __FUNCTION__, '3.5' );
     294
     295        $id = (int) $id;
     296
     297        if ( empty( $id ) )
     298                $id = get_current_blog_id();
     299
     300        if ( $id == get_current_blog_id() )
     301                return get_option( $option, $default );
     302
     303        switch_to_blog( $id );
     304        $option = get_option( $option, $default );
     305        restore_current_blog();
     306
     307        return $option;
     308}
     309
     310/**
     311 * Add a new option for a given blog id.
     312 *
     313 * You do not need to serialize values. If the value needs to be serialized, then
     314 * it will be serialized before it is inserted into the database. Remember,
     315 * resources can not be serialized or added as an option.
     316 *
     317 * You can create options without values and then update the values later.
     318 * Existing options will not be updated and checks are performed to ensure that you
     319 * aren't adding a protected WordPress option. Care should be taken to not name
     320 * options the same as the ones which are protected.
     321 *
     322 * @since MU
     323 * @deprecated 3.5.0
     324 *
     325 * @param int $id A blog ID. Can be null to refer to the current blog.
     326 * @param string $option Name of option to add. Expected to not be SQL-escaped.
     327 * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped.
     328 * @return bool False if option was not added and true if option was added.
     329 */
     330function add_blog_option( $id, $option, $value ) {
     331        _deprecated_function( __FUNCTION__, '3.5' );
     332
     333        $id = (int) $id;
     334
     335        if ( empty( $id ) )
     336                $id = get_current_blog_id();
     337
     338        if ( $id == get_current_blog_id() )
     339                return add_option( $option, $value );
     340
     341        switch_to_blog( $id );
     342        $return = add_option( $option, $value );
     343        restore_current_blog();
     344
     345        return $return;
     346}
     347
     348/**
     349 * Removes option by name for a given blog id. Prevents removal of protected WordPress options.
     350 *
     351 * @since MU
     352 * @deprecated 3.5.0
     353 *
     354 * @param int $id A blog ID. Can be null to refer to the current blog.
     355 * @param string $option Name of option to remove. Expected to not be SQL-escaped.
     356 * @return bool True, if option is successfully deleted. False on failure.
     357 */
     358function delete_blog_option( $id, $option ) {
     359        _deprecated_function( __FUNCTION__, '3.5' );
     360
     361        $id = (int) $id;
     362
     363        if ( empty( $id ) )
     364                $id = get_current_blog_id();
     365
     366        if ( $id == get_current_blog_id() )
     367                return delete_option( $option );
     368
     369        switch_to_blog( $id );
     370        $return = delete_option( $option );
     371        restore_current_blog();
     372
     373        return $return;
     374}
     375
     376/**
     377 * Update an option for a particular blog.
     378 *
     379 * @since MU
     380 * @deprecated 3.5.0
     381 *
     382 * @param int $id The blog id
     383 * @param string $option The option key
     384 * @param mixed $value The option value
     385 * @return bool True on success, false on failrue.
     386 */
     387function update_blog_option( $id, $option, $value, $deprecated = null ) {
     388        _deprecated_function( __FUNCTION__, '3.5' );
     389
     390        $id = (int) $id;
     391
     392        if ( null !== $deprecated  )
     393                _deprecated_argument( __FUNCTION__, '3.1' );
     394
     395        if ( $id == get_current_blog_id() )
     396                return update_option( $option, $value );
     397
     398        switch_to_blog( $id );
     399        $return = update_option( $option, $value );
     400        restore_current_blog();
     401
     402        refresh_blog_details( $id );
     403
     404        return $return;
     405}