WordPress.org

Make WordPress Core

Changeset 46625


Ignore:
Timestamp:
11/01/2019 12:39:04 AM (2 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Pass an appropriate error level to trigger_error() in _doing_it_wrong() and related functions:

  • _deprecated_function()
  • _deprecated_argument()
  • _deprecated_constructor()
  • _deprecated_file()

The error level passed is E_USER_DEPRECATED for the deprecated function group and E_USER_NOTICE for _doing_it_wrong().

Props jrf.
Fixes #36561.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r46610 r46625  
    45494549 * @since 2.5.0
    45504550 * @since 5.4.0 This function is no longer marked as "private".
     4551 * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
    45514552 *
    45524553 * @param string $function    The function that was called.
     
    45774578        if ( function_exists( '__' ) ) {
    45784579            if ( ! is_null( $replacement ) ) {
    4579                 /* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */
    4580                 trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $function, $version, $replacement ) );
     4580                trigger_error(
     4581                    sprintf(
     4582                        /* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */
     4583                        __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
     4584                        $function,
     4585                        $version,
     4586                        $replacement
     4587                    ),
     4588                    E_USER_DEPRECATED
     4589                );
    45814590            } else {
    4582                 /* translators: 1: PHP function name, 2: Version number. */
    4583                 trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $function, $version ) );
     4591                trigger_error(
     4592                    sprintf(
     4593                        /* translators: 1: PHP function name, 2: Version number. */
     4594                        __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
     4595                        $function,
     4596                        $version
     4597                    ),
     4598                    E_USER_DEPRECATED
     4599                );
    45844600            }
    45854601        } else {
    45864602            if ( ! is_null( $replacement ) ) {
    4587                 trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
     4603                trigger_error(
     4604                    sprintf(
     4605                        '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
     4606                        $function,
     4607                        $version,
     4608                        $replacement
     4609                    ),
     4610                    E_USER_DEPRECATED
     4611                );
    45884612            } else {
    4589                 trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
     4613                trigger_error(
     4614                    sprintf(
     4615                        '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
     4616                        $function,
     4617                        $version
     4618                    ),
     4619                    E_USER_DEPRECATED
     4620                );
    45904621            }
    45914622        }
     
    46064637 * @since 4.5.0 Added the `$parent_class` parameter.
    46074638 * @since 5.4.0 This function is no longer marked as "private".
     4639 * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
    46084640 *
    46094641 * @param string $class        The class containing the deprecated constructor.
     
    46464678                        $version,
    46474679                        '<pre>__construct()</pre>'
    4648                     )
     4680                    ),
     4681                    E_USER_DEPRECATED
    46494682                );
    46504683            } else {
     
    46564689                        $version,
    46574690                        '<pre>__construct()</pre>'
    4658                     )
     4691                    ),
     4692                    E_USER_DEPRECATED
    46594693                );
    46604694            }
     
    46684702                        $version,
    46694703                        '<pre>__construct()</pre>'
    4670                     )
     4704                    ),
     4705                    E_USER_DEPRECATED
    46714706                );
    46724707            } else {
     
    46774712                        $version,
    46784713                        '<pre>__construct()</pre>'
    4679                     )
     4714                    ),
     4715                    E_USER_DEPRECATED
    46804716                );
    46814717            }
     
    46984734 * @since 2.5.0
    46994735 * @since 5.4.0 This function is no longer marked as "private".
     4736 * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
    47004737 *
    47014738 * @param string $file        The file that was included.
     
    47284765    if ( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) {
    47294766        $message = empty( $message ) ? '' : ' ' . $message;
     4767
    47304768        if ( function_exists( '__' ) ) {
    47314769            if ( ! is_null( $replacement ) ) {
    4732                 /* translators: 1: PHP file name, 2: Version number, 3: Alternative file name. */
    4733                 trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $file, $version, $replacement ) . $message );
     4770                trigger_error(
     4771                    sprintf(
     4772                        /* translators: 1: PHP file name, 2: Version number, 3: Alternative file name. */
     4773                        __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
     4774                        $file,
     4775                        $version,
     4776                        $replacement
     4777                    ) . $message,
     4778                    E_USER_DEPRECATED
     4779                );
    47344780            } else {
    4735                 /* translators: 1: PHP file name, 2: Version number. */
    4736                 trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $file, $version ) . $message );
     4781                trigger_error(
     4782                    sprintf(
     4783                        /* translators: 1: PHP file name, 2: Version number. */
     4784                        __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
     4785                        $file,
     4786                        $version
     4787                    ) . $message,
     4788                    E_USER_DEPRECATED
     4789                );
    47374790            }
    47384791        } else {
    47394792            if ( ! is_null( $replacement ) ) {
    4740                 trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $file, $version, $replacement ) . $message );
     4793                trigger_error(
     4794                    sprintf(
     4795                        '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
     4796                        $file,
     4797                        $version,
     4798                        $replacement
     4799                    ) . $message,
     4800                    E_USER_DEPRECATED
     4801                );
    47414802            } else {
    4742                 trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $file, $version ) . $message );
     4803                trigger_error(
     4804                    sprintf(
     4805                        '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
     4806                        $file,
     4807                        $version
     4808                    ) . $message,
     4809                    E_USER_DEPRECATED
     4810                );
    47434811            }
    47444812        }
     
    47654833 * @since 3.0.0
    47664834 * @since 5.4.0 This function is no longer marked as "private".
     4835 * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
    47674836 *
    47684837 * @param string $function The function that was called.
     
    47934862        if ( function_exists( '__' ) ) {
    47944863            if ( ! is_null( $message ) ) {
    4795                 /* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */
    4796                 trigger_error( sprintf( __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s' ), $function, $version, $message ) );
     4864                trigger_error(
     4865                    sprintf(
     4866                        /* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */
     4867                        __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s' ),
     4868                        $function,
     4869                        $version,
     4870                        $message
     4871                    ),
     4872                    E_USER_DEPRECATED
     4873                );
    47974874            } else {
    4798                 /* translators: 1: PHP function name, 2: Version number. */
    4799                 trigger_error( sprintf( __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $function, $version ) );
     4875                trigger_error(
     4876                    sprintf(
     4877                        /* translators: 1: PHP function name, 2: Version number. */
     4878                        __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
     4879                        $function,
     4880                        $version
     4881                    ),
     4882                    E_USER_DEPRECATED
     4883                );
    48004884            }
    48014885        } else {
    48024886            if ( ! is_null( $message ) ) {
    4803                 trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message ) );
     4887                trigger_error(
     4888                    sprintf(
     4889                        '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s',
     4890                        $function,
     4891                        $version,
     4892                        $message
     4893                    ),
     4894                    E_USER_DEPRECATED
     4895                );
    48044896            } else {
    4805                 trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
     4897                trigger_error(
     4898                    sprintf(
     4899                        '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.',
     4900                        $function,
     4901                        $version
     4902                    ),
     4903                    E_USER_DEPRECATED
     4904                );
    48064905            }
    48074906        }
     
    48214920 *
    48224921 * @since 4.6.0
     4922 * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
    48234923 * @access private
    48244924 *
     
    48514951    if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) {
    48524952        $message = empty( $message ) ? '' : ' ' . $message;
     4953
    48534954        if ( ! is_null( $replacement ) ) {
    4854             /* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */
    4855             trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message );
     4955            trigger_error(
     4956                sprintf(
     4957                    /* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */
     4958                    __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
     4959                    $hook,
     4960                    $version,
     4961                    $replacement
     4962                ) . $message,
     4963                E_USER_DEPRECATED
     4964            );
    48564965        } else {
    4857             /* translators: 1: WordPress hook name, 2: Version number. */
    4858             trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook, $version ) . $message );
     4966            trigger_error(
     4967                sprintf(
     4968                    /* translators: 1: WordPress hook name, 2: Version number. */
     4969                    __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
     4970                    $hook,
     4971                    $version
     4972                ) . $message,
     4973                E_USER_DEPRECATED
     4974            );
    48594975        }
    48604976    }
     
    49095025                $version = sprintf( __( '(This message was added in version %s.)' ), $version );
    49105026            }
     5027
    49115028            $message .= ' ' . sprintf(
    49125029                /* translators: %s: Documentation URL. */
     
    49145031                __( 'https://wordpress.org/support/article/debugging-in-wordpress/' )
    49155032            );
    4916             /* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: Version information message. */
    4917             trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) );
     5033
     5034            trigger_error(
     5035                sprintf(
     5036                    /* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: Version information message. */
     5037                    __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ),
     5038                    $function,
     5039                    $message,
     5040                    $version
     5041                ),
     5042                E_USER_NOTICE
     5043            );
    49185044        } else {
    49195045            if ( is_null( $version ) ) {
     
    49225048                $version = sprintf( '(This message was added in version %s.)', $version );
    49235049            }
     5050
    49245051            $message .= sprintf(
    49255052                ' Please see <a href="%s">Debugging in WordPress</a> for more information.',
    49265053                'https://wordpress.org/support/article/debugging-in-wordpress/'
    49275054            );
    4928             trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ) );
     5055
     5056            trigger_error(
     5057                sprintf(
     5058                    '%1$s was called <strong>incorrectly</strong>. %2$s %3$s',
     5059                    $function,
     5060                    $message,
     5061                    $version
     5062                ),
     5063                E_USER_NOTICE
     5064            );
    49295065        }
    49305066    }
  • trunk/tests/phpunit/includes/phpunit6/compat.php

    r46586 r46625  
    66    class_alias( 'PHPUnit\Framework\Exception', 'PHPUnit_Framework_Exception' );
    77    class_alias( 'PHPUnit\Framework\ExpectationFailedException', 'PHPUnit_Framework_ExpectationFailedException' );
     8    class_alias( 'PHPUnit\Framework\Error\Deprecated', 'PHPUnit_Framework_Error_Deprecated' );
    89    class_alias( 'PHPUnit\Framework\Error\Notice', 'PHPUnit_Framework_Error_Notice' );
    910    class_alias( 'PHPUnit\Framework\Error\Warning', 'PHPUnit_Framework_Error_Warning' );
  • trunk/tests/phpunit/tests/compat.php

    r46586 r46625  
    181181
    182182    /**
    183      * @expectedException PHPUnit_Framework_Error_Notice
     183     * @expectedException PHPUnit_Framework_Error_Deprecated
    184184     */
    185185    function test_json_encode_decode() {
Note: See TracChangeset for help on using the changeset viewer.