Make WordPress Core

Changeset 58409

Timestamp:
06/13/2024 08:48:33 PM (8 weeks ago)
Author:
hellofromTonya
Message:

Code Modernization: Use wp_trigger_error() instead of trigger_error().

Replaces trigger_error() with wp_trigger_error().

The usage of wp_trigger_error() avoids generating E_USER family errors unless WP_DEBUG is on. In doing so, users should not see these messages in normal production.

Notes:

  • Removes E_USER_NOTICE when passed as an argumnent, as it's the default error level.
  • An empty string is passed for the function name when its name is already in the error message or does not add value to the error message.
  • Externally maintained libraries are not included.

Follow-up to [55204], [25956], [29630], [38883], [52062], [52049], [54272], [38883], [55245], [51599], [14452], [38883], [24976].

Props prasadkarmalkar, rajinsharwar, thelovekesh, hellofromTonya, swissspidy.
Fixes #59652.

Location:
trunk
Files:
17 edited

Legend:

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

    r58208 r58409  
    27962796                '<code>wp_opcache_invalidate_directory()</code>'
    27972797            );
    2798             trigger_error( $error_message );
     2798            $error_message );
    27992799        }
    28002800        return;
  • trunk/src/wp-admin/includes/plugin-install.php

    r58402 r58409  
    175175        if ( $ssl && is_wp_error( $request ) ) {
    176176            if ( ! wp_is_json_request() ) {
    177                 trigger_error(
     177                wp_trigger_error(
     178                    __FUNCTION__,
    178179                    sprintf(
    179180                        /* translators: %s: Support forums URL. */
  • trunk/src/wp-admin/includes/theme.php

    r57773 r58409  
    569569        if ( $ssl && is_wp_error( $request ) ) {
    570570            if ( ! wp_doing_ajax() ) {
    571                 trigger_error(
     571                wp_trigger_error(
     572                    __FUNCTION__,
    572573                    sprintf(
    573574                        /* translators: %s: Support forums URL. */
  • trunk/src/wp-admin/includes/translation-install.php

    r54891 r58409  
    6060
    6161        if ( $ssl && is_wp_error( $request ) ) {
    62             trigger_error(
     62            wp_trigger_error(
     63                __FUNCTION__,
    6364                sprintf(
    6465                    /* translators: %s: Support forums URL. */
  • trunk/src/wp-admin/includes/update.php

    r58064 r58409  
    146146
    147147    if ( $ssl && is_wp_error( $response ) ) {
    148         trigger_error(
     148        wp_trigger_error(
     149            __FUNCTION__,
    149150            sprintf(
    150151                /* translators: %s: Support forums URL. */
  • trunk/src/wp-admin/link-parse-opml.php

    r55917 r58409  
    7979// Create an XML parser.
    8080if ( ! function_exists( 'xml_parser_create' ) ) {
    81     trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
     81    __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
    8282    wp_die( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
    8383}
  • trunk/src/wp-includes/block-template-utils.php

    r58323 r58409  
    253253        WP_TEMPLATE_PART_AREA_UNCATEGORIZED
    254254    );
    255     trigger_error( $warning_message, E_USER_NOTICE );
     255    );
    256256    return WP_TEMPLATE_PART_AREA_UNCATEGORIZED;
    257257}
  • trunk/src/wp-includes/class-wp-theme-json-resolver.php

    r58354 r58409  
    505505            $json_decoding_error = json_last_error();
    506506            if ( JSON_ERROR_NONE !== $json_decoding_error ) {
    507                 trigger_error( 'Error when decoding a theme.json schema for user data. ' . json_last_error_msg() );
     507                'Error when decoding a theme.json schema for user data. ' . json_last_error_msg() );
    508508                /**
    509509                 * Filters the data provided by the user for global styles & settings.
  • trunk/src/wp-includes/class-wp-theme-json.php

    r58354 r58409  
    37763776            || ( '+' !== $spacing_scale['operator'] && '*' !== $spacing_scale['operator'] ) ) {
    37773777            if ( ! empty( $spacing_scale ) ) {
    3778                 trigger_error(
     3778                wp_trigger_error(
     3779                    __METHOD__,
    37793780                    sprintf(
    37803781                        /* translators: 1: theme.json, 2: settings.spacing.spacingScale */
  • trunk/src/wp-includes/feed.php

    r58200 r58409  
    588588
    589589    if ( ! function_exists( 'xml_parser_create' ) ) {
    590         trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
     590        __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
    591591
    592592        return array( 'html', "<![CDATA[$data]]>" );
  • trunk/src/wp-includes/formatting.php

    r58147 r58409  
    55195519        /*
    55205520         * To maintain consistency with pre-PHP 8 error levels,
    5521          * trigger_error() is used to trigger an E_USER_WARNING,
     5521         * trigger_error() is used to trigger an E_USER_WARNING,
    55225522         * rather than _doing_it_wrong(), which triggers an E_USER_NOTICE.
    55235523         */
    5524         trigger_error(
     5524        wp_trigger_error(
     5525            '',
    55255526            sprintf(
    55265527                /* translators: 1: The function name, 2: The argument number, 3: The argument name, 4: The expected type, 5: The provided type. */
  • trunk/src/wp-includes/functions.php

    r58361 r58409  
    46124612
    46134613    if ( ! $filename ) {
    4614         trigger_error(
     4614        wp_trigger_error(
     4615            __FUNCTION__,
    46154616            sprintf(
    46164617                /* translators: %s: Path to the JSON file. */
     
    46264627
    46274628    if ( JSON_ERROR_NONE !== json_last_error() ) {
    4628         trigger_error(
     4629        wp_trigger_error(
     4630            __FUNCTION__,
    46294631            sprintf(
    46304632                /* translators: 1: Path to the JSON file, 2: Error message. */
     
    87588760function clean_dirsize_cache( $path ) {
    87598761    if ( ! is_string( $path ) || empty( $path ) ) {
    8760         trigger_error(
     8762        wp_trigger_error(
     8763            '',
    87618764            sprintf(
    87628765                /* translators: 1: Function name, 2: A variable type, like "boolean" or "integer". */
  • trunk/src/wp-includes/ms-default-constants.php

    r56192 r58409  
    148148
    149149        if ( $subdomain_error_warn ) {
    150             trigger_error(
     150            wp_trigger_error(
     151                __FUNCTION__,
    151152                sprintf(
    152153                    /* translators: 1: VHOST, 2: SUBDOMAIN_INSTALL */
  • trunk/src/wp-includes/rss.php

    r57370 r58409  
    6464        #
    6565        if ( ! function_exists('xml_parser_create') ) {
    66             return trigger_error( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." );
     66            wp_trigger_error( '', "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." );
     67            return;
    6768        }
    6869
     
    388389    function error( $errormsg, $lvl = E_USER_WARNING ) {
    389390        if ( MAGPIE_DEBUG ) {
    390             trigger_error( $errormsg, $lvl);
     391            $errormsg, $lvl);
    391392        } else {
    392393            error_log( $errormsg, 0);
     
    824825        $this->ERROR = $errormsg;
    825826        if ( MAGPIE_DEBUG ) {
    826             trigger_error( $errormsg, $lvl);
     827            $errormsg, $lvl);
    827828        }
    828829        else {
  • trunk/src/wp-includes/theme.php

    r58366 r58409  
    515515        $dirs = @ scandir( $theme_root );
    516516        if ( ! $dirs ) {
    517             trigger_error( "$theme_root is not readable", E_USER_NOTICE );
     517            );
    518518            continue;
    519519        }
     
    539539                $sub_dirs = @ scandir( $theme_root . '/' . $dir );
    540540                if ( ! $sub_dirs ) {
    541                     trigger_error( "$theme_root/$dir is not readable", E_USER_NOTICE );
     541                    );
    542542                    continue;
    543543                }
  • trunk/src/wp-includes/update.php

    r56559 r58409  
    203203
    204204    if ( $ssl && is_wp_error( $response ) ) {
    205         trigger_error(
     205        wp_trigger_error(
     206            __FUNCTION__,
    206207            sprintf(
    207208                /* translators: %s: Support forums URL. */
     
    441442
    442443    if ( $ssl && is_wp_error( $raw_response ) ) {
    443         trigger_error(
     444        wp_trigger_error(
     445            __FUNCTION__,
    444446            sprintf(
    445447                /* translators: %s: Support forums URL. */
     
    722724
    723725    if ( $ssl && is_wp_error( $raw_response ) ) {
    724         trigger_error(
     726        wp_trigger_error(
     727            __FUNCTION__,
    725728            sprintf(
    726729                /* translators: %s: Support forums URL. */
  • trunk/tests/phpunit/tests/filesystem/wpOpcacheInvalidateDirectory.php

    r56971 r58409  
    3838        $this->expectError();
    3939        $this->expectErrorMessage(
    40             '<code>wp_opcache_invalidate_directory()</code>',
     40            '<code>wp_opcache_invalidate_directory()</code>',
    4141            'The expected error was not triggered.'
    4242        );
Note: See TracChangeset for help on using the changeset viewer.