WordPress.org

Make WordPress Core

Changeset 31188


Ignore:
Timestamp:
01/16/2015 01:05:52 AM (5 years ago)
Author:
wonderboymusic
Message:

In PHP 5.0.0, is_a() became deprecated in favour of the instanceof operator. Calling is_a() would result in an E_STRICT warning.

In PHP 5.3.0, is_a() is no longer deprecated, and will therefore no longer throw E_STRICT warnings.

To avoid warnings in PHP < 5.3.0, convert all is_a() calls to $var instanceof WP_Class calls.

instanceof does not throw any error if the variable being tested is not an object, it simply returns false.

Props markoheijnen, wonderboymusic.
Fixes #25672.

Location:
trunk/src
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-users-list-table.php

    r31181 r31188  
    340340        global $wp_roles;
    341341
    342         if ( !( is_object( $user_object ) && is_a( $user_object, 'WP_User' ) ) )
     342        if ( ! ( $user_object instanceof WP_User ) ) {
    343343            $user_object = get_userdata( (int) $user_object );
     344        }
    344345        $user_object->filter = 'display';
    345346        $email = $user_object->user_email;
  • trunk/src/wp-admin/includes/screen.php

    r30979 r31188  
    375375    public static function get( $hook_name = '' ) {
    376376
    377         if ( is_a( $hook_name, 'WP_Screen' ) )
     377        if ( $hook_name instanceof WP_Screen ) {
    378378            return $hook_name;
     379        }
    379380
    380381        $post_type = $taxonomy = null;
  • trunk/src/wp-admin/includes/template.php

    r31181 r31188  
    177177    $r = wp_parse_args( $params, $defaults );
    178178
    179     if ( empty( $r['walker'] ) || ! is_a( $r['walker'], 'Walker' ) ) {
     179    if ( empty( $r['walker'] ) || ! ( $r['walker'] instanceof Walker ) ) {
    180180        $walker = new Walker_Category_Checklist;
    181181    } else {
  • trunk/src/wp-admin/includes/theme.php

    r31090 r31188  
    150150        $themes_update = get_site_transient('update_themes');
    151151
    152     if ( ! is_a( $theme, 'WP_Theme' ) )
     152    if ( ! ( $theme instanceof WP_Theme ) ) {
    153153        return false;
     154    }
    154155
    155156    $stylesheet = $theme->get_stylesheet();
  • trunk/src/wp-includes/capabilities.php

    r31147 r31188  
    521521        }
    522522
    523         if ( is_a( $id, 'WP_User' ) ) {
     523        if ( $id instanceof WP_User ) {
    524524            $this->init( $id->data, $blog_id );
    525525            return;
  • trunk/src/wp-includes/category-template.php

    r31027 r31188  
    883883    $args = func_get_args();
    884884    // the user's options are the third parameter
    885     if ( empty($args[2]['walker']) || !is_a($args[2]['walker'], 'Walker') )
     885    if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) {
    886886        $walker = new Walker_Category;
    887     else
     887    } else {
    888888        $walker = $args[2]['walker'];
    889 
     889    }
    890890    return call_user_func_array(array( &$walker, 'walk' ), $args );
    891891}
  • trunk/src/wp-includes/class-feed.php

    r28505 r31188  
    3838
    3939    public function save($data) {
    40         if ( is_a($data, 'SimplePie') )
     40        if ( $data instanceof SimplePie ) {
    4141            $data = $data->data;
     42        }
    4243
    4344        set_transient($this->name, $data, $this->lifetime);
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r31085 r31188  
    696696     */
    697697    public function add_setting( $id, $args = array() ) {
    698         if ( is_a( $id, 'WP_Customize_Setting' ) )
     698        if ( $id instanceof WP_Customize_Setting ) {
    699699            $setting = $id;
    700         else
     700        } else {
    701701            $setting = new WP_Customize_Setting( $this, $id, $args );
    702 
     702        }
    703703        $this->settings[ $setting->id ] = $setting;
    704704    }
     
    738738     */
    739739    public function add_panel( $id, $args = array() ) {
    740         if ( is_a( $id, 'WP_Customize_Panel' ) ) {
     740        if ( $id instanceof WP_Customize_Panel ) {
    741741            $panel = $id;
    742         }
    743         else {
     742        } else {
    744743            $panel = new WP_Customize_Panel( $this, $id, $args );
    745744        }
     
    784783     */
    785784    public function add_section( $id, $args = array() ) {
    786         if ( is_a( $id, 'WP_Customize_Section' ) )
     785        if ( $id instanceof WP_Customize_Section ) {
    787786            $section = $id;
    788         else
     787        } else {
    789788            $section = new WP_Customize_Section( $this, $id, $args );
    790 
     789        }
    791790        $this->sections[ $section->id ] = $section;
    792791    }
     
    826825     */
    827826    public function add_control( $id, $args = array() ) {
    828         if ( is_a( $id, 'WP_Customize_Control' ) )
     827        if ( $id instanceof WP_Customize_Control ) {
    829828            $control = $id;
    830         else
     829        } else {
    831830            $control = new WP_Customize_Control( $this, $id, $args );
    832 
     831        }
    833832        $this->controls[ $control->id ] = $control;
    834833    }
  • trunk/src/wp-includes/class-wp-error.php

    r31138 r31188  
    215215 * @return bool True, if WP_Error. False, if not WP_Error.
    216216 */
    217 function is_wp_error($thing) {
    218     if ( is_object($thing) && is_a($thing, 'WP_Error') )
    219         return true;
    220     return false;
     217function is_wp_error( $thing ) {
     218    return ( $thing instanceof WP_Error );
    221219}
  • trunk/src/wp-includes/class-wp-theme.php

    r31108 r31188  
    275275        if ( $this->template != $this->stylesheet ) {
    276276            // If we are a parent, then there is a problem. Only two generations allowed! Cancel things out.
    277             if ( is_a( $_child, 'WP_Theme' ) && $_child->template == $this->stylesheet ) {
     277            if ( $_child instanceof WP_Theme && $_child->template == $this->stylesheet ) {
    278278                $_child->parent = null;
    279279                $_child->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), $_child->template ) );
  • trunk/src/wp-includes/class-wp-xmlrpc-server.php

    r31149 r31188  
    11181118
    11191119        // convert the date field back to IXR form
    1120         if ( isset( $content_struct['post_date'] ) && ! is_a( $content_struct['post_date'], 'IXR_Date' ) ) {
     1120        if ( isset( $content_struct['post_date'] ) && ! ( $content_struct['post_date'] instanceof IXR_Date ) ) {
    11211121            $content_struct['post_date'] = $this->_convert_date( $content_struct['post_date'] );
    11221122        }
     
    11241124        // ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct,
    11251125        // since _insert_post will ignore the non-GMT date if the GMT date is set
    1126         if ( isset( $content_struct['post_date_gmt'] ) && ! is_a( $content_struct['post_date_gmt'], 'IXR_Date' ) ) {
     1126        if ( isset( $content_struct['post_date_gmt'] ) && ! ( $content_struct['post_date_gmt'] instanceof IXR_Date ) ) {
    11271127            if ( $content_struct['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) ) {
    11281128                unset( $content_struct['post_date_gmt'] );
  • trunk/src/wp-includes/compat.php

    r30075 r31188  
    6666        global $wp_json;
    6767
    68         if ( !is_a($wp_json, 'Services_JSON') ) {
     68        if ( ! ( $wp_json instanceof Services_JSON ) ) {
    6969            require_once( ABSPATH . WPINC . '/class-json.php' );
    7070            $wp_json = new Services_JSON();
     
    7979        global $wp_json;
    8080
    81         if ( !is_a($wp_json, 'Services_JSON') ) {
     81        if ( ! ($wp_json instanceof Services_JSON ) ) {
    8282            require_once( ABSPATH . WPINC . '/class-json.php' );
    8383            $wp_json = new Services_JSON();
  • trunk/src/wp-includes/deprecated.php

    r31106 r31188  
    26852685        if ( !isset($user->ID) )
    26862686            $user->ID = 0;
    2687         if ( !is_a( $user, 'WP_User' ) ) {
     2687        if ( ! ( $user instanceof WP_User ) ) {
    26882688            $vars = get_object_vars($user);
    26892689            foreach ( array_keys($vars) as $field ) {
  • trunk/src/wp-includes/functions.wp-scripts.php

    r31030 r31188  
    3636
    3737    global $wp_scripts;
    38     if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
     38    if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
    3939        if ( ! did_action( 'init' ) )
    4040            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     
    7373function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
    7474    global $wp_scripts;
    75     if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
     75    if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
    7676        if ( ! did_action( 'init' ) )
    7777            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     
    116116function wp_localize_script( $handle, $object_name, $l10n ) {
    117117    global $wp_scripts;
    118     if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
     118    if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
    119119        if ( ! did_action( 'init' ) )
    120120            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     
    142142function wp_deregister_script( $handle ) {
    143143    global $wp_scripts;
    144     if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
     144    if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
    145145        if ( ! did_action( 'init' ) )
    146146            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     
    198198function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) {
    199199    global $wp_scripts;
    200     if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
     200    if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
    201201        if ( ! did_action( 'init' ) )
    202202            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     
    230230function wp_dequeue_script( $handle ) {
    231231    global $wp_scripts;
    232     if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
     232    if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
    233233        if ( ! did_action( 'init' ) )
    234234            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     
    255255function wp_script_is( $handle, $list = 'enqueued' ) {
    256256    global $wp_scripts;
    257     if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
     257    if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
    258258        if ( ! did_action( 'init' ) )
    259259            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
  • trunk/src/wp-includes/functions.wp-styles.php

    r30674 r31188  
    3535
    3636    global $wp_styles;
    37     if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
     37    if ( ! ( $wp_styles instanceof WP_Styles ) ) {
    3838        if ( ! did_action( 'init' ) )
    3939            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     
    6868function wp_add_inline_style( $handle, $data ) {
    6969    global $wp_styles;
    70     if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
     70    if ( ! ( $wp_styles instanceof WP_Styles ) ) {
    7171        if ( ! did_action( 'init' ) )
    7272            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     
    103103function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
    104104    global $wp_styles;
    105     if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
     105    if ( ! ( $wp_styles instanceof WP_Styles ) ) {
    106106        if ( ! did_action( 'init' ) )
    107107            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     
    125125function wp_deregister_style( $handle ) {
    126126    global $wp_styles;
    127     if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
     127    if ( ! ( $wp_styles instanceof WP_Styles ) ) {
    128128        if ( ! did_action( 'init' ) )
    129129            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     
    158158function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) {
    159159    global $wp_styles;
    160     if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
     160    if ( ! ( $wp_styles instanceof WP_Styles ) ) {
    161161        if ( ! did_action( 'init' ) )
    162162            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     
    184184function wp_dequeue_style( $handle ) {
    185185    global $wp_styles;
    186     if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
     186    if ( ! ( $wp_styles instanceof WP_Styles ) ) {
    187187        if ( ! did_action( 'init' ) )
    188188            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
     
    208208function wp_style_is( $handle, $list = 'enqueued' ) {
    209209    global $wp_styles;
    210     if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
     210    if ( ! ( $wp_styles instanceof WP_Styles ) ) {
    211211        if ( ! did_action( 'init' ) )
    212212            _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
  • trunk/src/wp-includes/general-template.php

    r31170 r31188  
    28502850function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
    28512851    global $wp_styles;
    2852     if ( !is_a($wp_styles, 'WP_Styles') )
     2852    if ( ! ( $wp_styles instanceof WP_Styles ) ) {
    28532853        $wp_styles = new WP_Styles();
     2854    }
    28542855
    28552856    // For backward compatibility
  • trunk/src/wp-includes/ms-functions.php

    r31168 r31188  
    20062006 */
    20072007function is_user_spammy( $user = null ) {
    2008     if ( ! is_a( $user, 'WP_User' ) ) {
    2009         if ( $user )
     2008    if ( ! ( $user instanceof WP_User ) ) {
     2009        if ( $user ) {
    20102010            $user = get_user_by( 'login', $user );
    2011         else
     2011        } else {
    20122012            $user = wp_get_current_user();
     2013        }
    20132014    }
    20142015
  • trunk/src/wp-includes/pluggable.php

    r31152 r31188  
    261261
    262262    // (Re)create it, if it's gone missing
    263     if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) {
     263    if ( ! ( $phpmailer instanceof PHPMailer ) ) {
    264264        require_once ABSPATH . WPINC . '/class-phpmailer.php';
    265265        require_once ABSPATH . WPINC . '/class-smtp.php';
  • trunk/src/wp-includes/post.php

    r31169 r31188  
    423423        $post = $GLOBALS['post'];
    424424
    425     if ( is_a( $post, 'WP_Post' ) ) {
     425    if ( $post instanceof WP_Post ) {
    426426        $_post = $post;
    427427    } elseif ( is_object( $post ) ) {
  • trunk/src/wp-includes/script-loader.php

    r31170 r31188  
    779779    }
    780780
    781     if ( !is_a($wp_scripts, 'WP_Scripts') )
     781    if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
    782782        $wp_scripts = new WP_Scripts();
     783    }
    783784
    784785    script_concat_settings();
     
    809810    global $wp_scripts, $concatenate_scripts;
    810811
    811     if ( !is_a($wp_scripts, 'WP_Scripts') )
     812    if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
    812813        return array(); // No need to run if not instantiated.
    813 
     814    }
    814815    script_concat_settings();
    815816    $wp_scripts->do_concat = $concatenate_scripts;
     
    893894    global $wp_scripts;
    894895
    895     if ( !is_a($wp_scripts, 'WP_Scripts') )
     896    if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
    896897        return array(); // no need to run if nothing is queued
    897 
     898    }
    898899    return print_head_scripts();
    899900}
     
    948949    global $wp_styles, $concatenate_scripts;
    949950
    950     if ( !is_a($wp_styles, 'WP_Styles') )
     951    if ( ! ( $wp_styles instanceof WP_Styles ) ) {
    951952        $wp_styles = new WP_Styles();
     953    }
    952954
    953955    script_concat_settings();
     
    978980    global $wp_styles, $concatenate_scripts;
    979981
    980     if ( !is_a($wp_styles, 'WP_Styles') )
     982    if ( ! ( $wp_styles instanceof WP_Styles ) ) {
    981983        return;
     984    }
    982985
    983986    $wp_styles->do_concat = $concatenate_scripts;
  • trunk/src/wp-includes/template.php

    r31090 r31188  
    136136    $templates = array();
    137137
    138     if ( is_a( $author, 'WP_User' ) ) {
     138    if ( $author instanceof WP_User ) {
    139139        $templates[] = "author-{$author->user_nicename}.php";
    140140        $templates[] = "author-{$author->ID}.php";
  • trunk/src/wp-includes/theme.php

    r31168 r31188  
    20282028    global $wp_customize;
    20292029
    2030     return is_a( $wp_customize, 'WP_Customize_Manager' ) && $wp_customize->is_preview();
    2031 }
     2030    return ( $wp_customize instanceof WP_Customize_Manager ) && $wp_customize->is_preview();
     2031}
  • trunk/src/wp-includes/user.php

    r31144 r31188  
    113113 */
    114114function wp_authenticate_username_password($user, $username, $password) {
    115     if ( is_a( $user, 'WP_User' ) ) {
     115    if ( $user instanceof WP_User ) {
    116116        return $user;
    117117    }
     
    168168 */
    169169function wp_authenticate_cookie($user, $username, $password) {
    170     if ( is_a( $user, 'WP_User' ) ) {
     170    if ( $user instanceof WP_User ) {
    171171        return $user;
    172172    }
     
    203203 */
    204204function wp_authenticate_spam_check( $user ) {
    205     if ( $user && is_a( $user, 'WP_User' ) && is_multisite() ) {
     205    if ( $user instanceof WP_User && is_multisite() ) {
    206206        /**
    207207         * Filter whether the user has been marked as a spammer.
     
    17111711    global $wpdb;
    17121712
    1713     if ( is_a( $userdata, 'stdClass' ) ) {
     1713    if ( $userdata instanceof stdClass ) {
    17141714        $userdata = get_object_vars( $userdata );
    1715     } elseif ( is_a( $userdata, 'WP_User' ) ) {
     1715    } elseif ( $userdata instanceof WP_User ) {
    17161716        $userdata = $userdata->to_array();
    17171717    }
     
    19701970 */
    19711971function wp_update_user($userdata) {
    1972     if ( is_a( $userdata, 'stdClass' ) )
     1972    if ( $userdata instanceof stdClass ) {
    19731973        $userdata = get_object_vars( $userdata );
    1974     elseif ( is_a( $userdata, 'WP_User' ) )
     1974    } elseif ( $userdata instanceof WP_User ) {
    19751975        $userdata = $userdata->to_array();
     1976    }
    19761977
    19771978    $ID = (int) $userdata['ID'];
  • trunk/src/wp-includes/widgets.php

    r31077 r31188  
    15531553
    15541554    $widget_obj = $wp_widget_factory->widgets[$widget];
    1555     if ( !is_a($widget_obj, 'WP_Widget') )
     1555    if ( ! ( $widget_obj instanceof WP_Widget ) ) {
    15561556        return;
     1557    }
    15571558
    15581559    $before_widget = sprintf('<div class="widget %s">', $widget_obj->widget_options['classname'] );
Note: See TracChangeset for help on using the changeset viewer.