Make WordPress Core


Ignore:
Timestamp:
09/26/2023 11:49:57 AM (3 years ago)
Author:
hellofromTonya
Message:

General: Use wp_trigger_error() in _doing_it_wrong() and _deprecated_*().

Uses wp_trigger_error() in _doing_it_wrong() and each _deprecated_*() function, i.e. instead of trigger_error().

To avoid redundancy, uses wp_trigger_error() once. How? Saves each message to $message variable and then passes it to wp_trigger_error() at the end of the function.

Functions:

  • _doing_it_wrong()
  • _deprecated_function()
  • _deprecated_constructor()
  • _deprecated_class()
  • _deprecated_file()
  • _deprecated_argument()
  • _deprecated_hook()

Follow-up to [56530].

Props azaozz, costdev, flixos90, hellofromTonya, peterwilsoncc.
See #57686.

File:
1 edited

Legend:

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

    r56687 r56705  
    54695469                if ( function_exists( '__' ) ) {
    54705470                        if ( $replacement ) {
    5471                                 trigger_error(
    5472                                         sprintf(
    5473                                                 /* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */
    5474                                                 __( 'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
    5475                                                 $function_name,
    5476                                                 $version,
    5477                                                 $replacement
    5478                                         ),
    5479                                         E_USER_DEPRECATED
     5471                                $message = sprintf(
     5472                                        /* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */
     5473                                        __( 'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
     5474                                        $function_name,
     5475                                        $version,
     5476                                        $replacement
    54805477                                );
    54815478                        } else {
    5482                                 trigger_error(
    5483                                         sprintf(
    5484                                                 /* translators: 1: PHP function name, 2: Version number. */
    5485                                                 __( 'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
    5486                                                 $function_name,
    5487                                                 $version
    5488                                         ),
    5489                                         E_USER_DEPRECATED
     5479                                $message = sprintf(
     5480                                        /* translators: 1: PHP function name, 2: Version number. */
     5481                                        __( 'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
     5482                                        $function_name,
     5483                                        $version
    54905484                                );
    54915485                        }
    54925486                } else {
    54935487                        if ( $replacement ) {
    5494                                 trigger_error(
    5495                                         sprintf(
    5496                                                 'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
    5497                                                 $function_name,
    5498                                                 $version,
    5499                                                 $replacement
    5500                                         ),
    5501                                         E_USER_DEPRECATED
     5488                                $message = sprintf(
     5489                                        'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
     5490                                        $function_name,
     5491                                        $version,
     5492                                        $replacement
    55025493                                );
    55035494                        } else {
    5504                                 trigger_error(
    5505                                         sprintf(
    5506                                                 'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
    5507                                                 $function_name,
    5508                                                 $version
    5509                                         ),
    5510                                         E_USER_DEPRECATED
     5495                                $message = sprintf(
     5496                                        'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
     5497                                        $function_name,
     5498                                        $version
    55115499                                );
    55125500                        }
    55135501                }
     5502
     5503                wp_trigger_error( '', $message, E_USER_DEPRECATED );
    55145504        }
    55155505}
     
    55615551                if ( function_exists( '__' ) ) {
    55625552                        if ( $parent_class ) {
    5563                                 trigger_error(
    5564                                         sprintf(
    5565                                                 /* translators: 1: PHP class name, 2: PHP parent class name, 3: Version number, 4: __construct() method. */
    5566                                                 __( 'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),
    5567                                                 $class_name,
    5568                                                 $parent_class,
    5569                                                 $version,
    5570                                                 '<code>__construct()</code>'
    5571                                         ),
    5572                                         E_USER_DEPRECATED
     5553                                $message = sprintf(
     5554                                        /* translators: 1: PHP class name, 2: PHP parent class name, 3: Version number, 4: __construct() method. */
     5555                                        __( 'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),
     5556                                        $class_name,
     5557                                        $parent_class,
     5558                                        $version,
     5559                                        '<code>__construct()</code>'
    55735560                                );
    55745561                        } else {
    5575                                 trigger_error(
    5576                                         sprintf(
    5577                                                 /* translators: 1: PHP class name, 2: Version number, 3: __construct() method. */
    5578                                                 __( 'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
    5579                                                 $class_name,
    5580                                                 $version,
    5581                                                 '<code>__construct()</code>'
    5582                                         ),
    5583                                         E_USER_DEPRECATED
     5562                                $message = sprintf(
     5563                                        /* translators: 1: PHP class name, 2: Version number, 3: __construct() method. */
     5564                                        __( 'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
     5565                                        $class_name,
     5566                                        $version,
     5567                                        '<code>__construct()</code>'
    55845568                                );
    55855569                        }
    55865570                } else {
    55875571                        if ( $parent_class ) {
    5588                                 trigger_error(
    5589                                         sprintf(
    5590                                                 'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
    5591                                                 $class_name,
    5592                                                 $parent_class,
    5593                                                 $version,
    5594                                                 '<code>__construct()</code>'
    5595                                         ),
    5596                                         E_USER_DEPRECATED
     5572                                $message = sprintf(
     5573                                        'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
     5574                                        $class_name,
     5575                                        $parent_class,
     5576                                        $version,
     5577                                        '<code>__construct()</code>'
    55975578                                );
    55985579                        } else {
    5599                                 trigger_error(
    5600                                         sprintf(
    5601                                                 'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
    5602                                                 $class_name,
    5603                                                 $version,
    5604                                                 '<code>__construct()</code>'
    5605                                         ),
    5606                                         E_USER_DEPRECATED
     5580                                $message = sprintf(
     5581                                        'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
     5582                                        $class_name,
     5583                                        $version,
     5584                                        '<code>__construct()</code>'
    56075585                                );
    56085586                        }
    56095587                }
     5588
     5589                wp_trigger_error( '', $message, E_USER_DEPRECATED );
    56105590        }
    56115591}
     
    56525632                if ( function_exists( '__' ) ) {
    56535633                        if ( $replacement ) {
    5654                                 trigger_error(
    5655                                         sprintf(
    5656                                                 /* translators: 1: PHP class name, 2: Version number, 3: Alternative class or function name. */
    5657                                                 __( 'Class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
    5658                                                 $class_name,
    5659                                                 $version,
    5660                                                 $replacement
    5661                                         ),
    5662                                         E_USER_DEPRECATED
     5634                                $message = sprintf(
     5635                                        /* translators: 1: PHP class name, 2: Version number, 3: Alternative class or function name. */
     5636                                        __( 'Class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
     5637                                        $class_name,
     5638                                        $version,
     5639                                        $replacement
    56635640                                );
    56645641                        } else {
    5665                                 trigger_error(
    5666                                         sprintf(
    5667                                                 /* translators: 1: PHP class name, 2: Version number. */
    5668                                                 __( 'Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
    5669                                                 $class_name,
    5670                                                 $version
    5671                                         ),
    5672                                         E_USER_DEPRECATED
     5642                                $message = sprintf(
     5643                                        /* translators: 1: PHP class name, 2: Version number. */
     5644                                        __( 'Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
     5645                                        $class_name,
     5646                                        $version
    56735647                                );
    56745648                        }
    56755649                } else {
    56765650                        if ( $replacement ) {
    5677                                 trigger_error(
    5678                                         sprintf(
    5679                                                 'Class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
    5680                                                 $class_name,
    5681                                                 $version,
    5682                                                 $replacement
    5683                                         ),
    5684                                         E_USER_DEPRECATED
     5651                                $message = sprintf(
     5652                                        'Class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
     5653                                        $class_name,
     5654                                        $version,
     5655                                        $replacement
    56855656                                );
    56865657                        } else {
    5687                                 trigger_error(
    5688                                         sprintf(
    5689                                                 'Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
    5690                                                 $class_name,
    5691                                                 $version
    5692                                         ),
    5693                                         E_USER_DEPRECATED
     5658                                $message = sprintf(
     5659                                        'Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
     5660                                        $class_name,
     5661                                        $version
    56945662                                );
    56955663                        }
    56965664                }
     5665
     5666                wp_trigger_error( '', $message, E_USER_DEPRECATED );
    56975667        }
    56985668}
     
    57445714                if ( function_exists( '__' ) ) {
    57455715                        if ( $replacement ) {
    5746                                 trigger_error(
    5747                                         sprintf(
    5748                                                 /* translators: 1: PHP file name, 2: Version number, 3: Alternative file name. */
    5749                                                 __( 'File %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
    5750                                                 $file,
    5751                                                 $version,
    5752                                                 $replacement
    5753                                         ) . $message,
    5754                                         E_USER_DEPRECATED
    5755                                 );
     5716                                $message = sprintf(
     5717                                        /* translators: 1: PHP file name, 2: Version number, 3: Alternative file name. */
     5718                                        __( 'File %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
     5719                                        $file,
     5720                                        $version,
     5721                                        $replacement
     5722                                ) . $message;
    57565723                        } else {
    5757                                 trigger_error(
    5758                                         sprintf(
    5759                                                 /* translators: 1: PHP file name, 2: Version number. */
    5760                                                 __( 'File %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
    5761                                                 $file,
    5762                                                 $version
    5763                                         ) . $message,
    5764                                         E_USER_DEPRECATED
    5765                                 );
     5724                                $message = sprintf(
     5725                                        /* translators: 1: PHP file name, 2: Version number. */
     5726                                        __( 'File %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
     5727                                        $file,
     5728                                        $version
     5729                                ) . $message;
    57665730                        }
    57675731                } else {
    57685732                        if ( $replacement ) {
    5769                                 trigger_error(
    5770                                         sprintf(
    5771                                                 'File %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
    5772                                                 $file,
    5773                                                 $version,
    5774                                                 $replacement
    5775                                         ) . $message,
    5776                                         E_USER_DEPRECATED
     5733                                $message = sprintf(
     5734                                        'File %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
     5735                                        $file,
     5736                                        $version,
     5737                                        $replacement
    57775738                                );
    57785739                        } else {
    5779                                 trigger_error(
    5780                                         sprintf(
    5781                                                 'File %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
    5782                                                 $file,
    5783                                                 $version
    5784                                         ) . $message,
    5785                                         E_USER_DEPRECATED
    5786                                 );
     5740                                $message = sprintf(
     5741                                        'File %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
     5742                                        $file,
     5743                                        $version
     5744                                ) . $message;
    57875745                        }
    57885746                }
     5747
     5748                wp_trigger_error( '', $message, E_USER_DEPRECATED );
    57895749        }
    57905750}
     
    58385798                if ( function_exists( '__' ) ) {
    58395799                        if ( $message ) {
    5840                                 trigger_error(
    5841                                         sprintf(
    5842                                                 /* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */
    5843                                                 __( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s' ),
    5844                                                 $function_name,
    5845                                                 $version,
    5846                                                 $message
    5847                                         ),
    5848                                         E_USER_DEPRECATED
     5800                                $message = sprintf(
     5801                                        /* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */
     5802                                        __( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s' ),
     5803                                        $function_name,
     5804                                        $version,
     5805                                        $message
    58495806                                );
    58505807                        } else {
    5851                                 trigger_error(
    5852                                         sprintf(
    5853                                                 /* translators: 1: PHP function name, 2: Version number. */
    5854                                                 __( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
    5855                                                 $function_name,
    5856                                                 $version
    5857                                         ),
    5858                                         E_USER_DEPRECATED
     5808                                $message = sprintf(
     5809                                        /* translators: 1: PHP function name, 2: Version number. */
     5810                                        __( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
     5811                                        $function_name,
     5812                                        $version
    58595813                                );
    58605814                        }
    58615815                } else {
    58625816                        if ( $message ) {
    5863                                 trigger_error(
    5864                                         sprintf(
    5865                                                 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s',
    5866                                                 $function_name,
    5867                                                 $version,
    5868                                                 $message
    5869                                         ),
    5870                                         E_USER_DEPRECATED
     5817                                $message = sprintf(
     5818                                        'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s',
     5819                                        $function_name,
     5820                                        $version,
     5821                                        $message
    58715822                                );
    58725823                        } else {
    5873                                 trigger_error(
    5874                                         sprintf(
    5875                                                 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.',
    5876                                                 $function_name,
    5877                                                 $version
    5878                                         ),
    5879                                         E_USER_DEPRECATED
     5824                                $message = sprintf(
     5825                                        'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.',
     5826                                        $function_name,
     5827                                        $version
    58805828                                );
    58815829                        }
    58825830                }
     5831
     5832                wp_trigger_error( '', $message, E_USER_DEPRECATED );
    58835833        }
    58845834}
     
    59295879
    59305880                if ( $replacement ) {
    5931                         trigger_error(
    5932                                 sprintf(
    5933                                         /* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */
    5934                                         __( 'Hook %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
    5935                                         $hook,
    5936                                         $version,
    5937                                         $replacement
    5938                                 ) . $message,
    5939                                 E_USER_DEPRECATED
    5940                         );
     5881                        $message = sprintf(
     5882                                /* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */
     5883                                __( 'Hook %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
     5884                                $hook,
     5885                                $version,
     5886                                $replacement
     5887                        ) . $message;
    59415888                } else {
    5942                         trigger_error(
    5943                                 sprintf(
    5944                                         /* translators: 1: WordPress hook name, 2: Version number. */
    5945                                         __( 'Hook %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
    5946                                         $hook,
    5947                                         $version
    5948                                 ) . $message,
    5949                                 E_USER_DEPRECATED
    5950                         );
    5951                 }
     5889                        $message = sprintf(
     5890                                /* translators: 1: WordPress hook name, 2: Version number. */
     5891                                __( 'Hook %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
     5892                                $hook,
     5893                                $version
     5894                        ) . $message;
     5895                }
     5896
     5897                wp_trigger_error( '', $message, E_USER_DEPRECATED );
    59525898        }
    59535899}
     
    60055951                        );
    60065952
    6007                         trigger_error(
    6008                                 sprintf(
    6009                                         /* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: WordPress version number. */
    6010                                         __( 'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s' ),
    6011                                         $function_name,
    6012                                         $message,
    6013                                         $version
    6014                                 ),
    6015                                 E_USER_NOTICE
     5953                        $message = sprintf(
     5954                                /* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: WordPress version number. */
     5955                                __( 'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s' ),
     5956                                $function_name,
     5957                                $message,
     5958                                $version
    60165959                        );
    60175960                } else {
     
    60255968                        );
    60265969
    6027                         trigger_error(
    6028                                 sprintf(
    6029                                         'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s',
    6030                                         $function_name,
    6031                                         $message,
    6032                                         $version
    6033                                 ),
    6034                                 E_USER_NOTICE
     5970                        $message = sprintf(
     5971                                'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s',
     5972                                $function_name,
     5973                                $message,
     5974                                $version
    60355975                        );
    60365976                }
     5977
     5978                wp_trigger_error( '', $message );
    60375979        }
    60385980}
Note: See TracChangeset for help on using the changeset viewer.