From ee42a1a9bb8f82481f8d0c5ee165f9327ed12681 Mon Sep 17 00:00:00 2001
From: jrfnl <jrfnl@users.noreply.github.com>
Date: Sun, 18 Jun 2017 15:49:43 +0200
Subject: [PATCH] Deprecated notices should be classified as
E_(USER_)DEPRECATED.
---
src/wp-includes/functions.php | 170 +++++++++++++++++----
tests/phpunit/includes/phpunit6/compat.php | 1 +
tests/phpunit/tests/compat.php | 2 +-
3 files changed, 144 insertions(+), 29 deletions(-)
diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
index d3dded8078..df23c5186d 100644
|
a
|
b
|
function absint( $maybeint ) { |
| 4528 | 4528 | * This function is to be used in every function that is deprecated. |
| 4529 | 4529 | * |
| 4530 | 4530 | * @since 2.5.0 |
| | 4531 | * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE). |
| 4531 | 4532 | * @access private |
| 4532 | 4533 | * |
| 4533 | 4534 | * @param string $function The function that was called. |
| … |
… |
function _deprecated_function( $function, $version, $replacement = null ) { |
| 4557 | 4558 | if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) { |
| 4558 | 4559 | if ( function_exists( '__' ) ) { |
| 4559 | 4560 | if ( ! is_null( $replacement ) ) { |
| 4560 | | /* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */ |
| 4561 | | trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $function, $version, $replacement ) ); |
| | 4561 | trigger_error( |
| | 4562 | sprintf( |
| | 4563 | /* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */ |
| | 4564 | __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), |
| | 4565 | $function, |
| | 4566 | $version, |
| | 4567 | $replacement |
| | 4568 | ), |
| | 4569 | E_USER_DEPRECATED |
| | 4570 | ); |
| 4562 | 4571 | } else { |
| 4563 | | /* translators: 1: PHP function name, 2: Version number. */ |
| 4564 | | trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $function, $version ) ); |
| | 4572 | trigger_error( |
| | 4573 | sprintf( |
| | 4574 | /* translators: 1: PHP function name, 2: Version number. */ |
| | 4575 | __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), |
| | 4576 | $function, |
| | 4577 | $version |
| | 4578 | ), |
| | 4579 | E_USER_DEPRECATED |
| | 4580 | ); |
| 4565 | 4581 | } |
| 4566 | 4582 | } else { |
| 4567 | 4583 | if ( ! is_null( $replacement ) ) { |
| 4568 | | trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ) ); |
| | 4584 | trigger_error( |
| | 4585 | sprintf( |
| | 4586 | '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', |
| | 4587 | $function, |
| | 4588 | $version, |
| | 4589 | $replacement |
| | 4590 | ), |
| | 4591 | E_USER_DEPRECATED |
| | 4592 | ); |
| 4569 | 4593 | } else { |
| 4570 | | trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) ); |
| | 4594 | trigger_error( |
| | 4595 | sprintf( |
| | 4596 | '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', |
| | 4597 | $function, |
| | 4598 | $version |
| | 4599 | ), |
| | 4600 | E_USER_DEPRECATED |
| | 4601 | ); |
| 4571 | 4602 | } |
| 4572 | 4603 | } |
| 4573 | 4604 | } |
| … |
… |
function _deprecated_function( $function, $version, $replacement = null ) { |
| 4585 | 4616 | * |
| 4586 | 4617 | * @since 4.3.0 |
| 4587 | 4618 | * @since 4.5.0 Added the `$parent_class` parameter. |
| | 4619 | * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE). |
| 4588 | 4620 | * |
| 4589 | 4621 | * @access private |
| 4590 | 4622 | * |
| … |
… |
function _deprecated_constructor( $class, $version, $parent_class = '' ) { |
| 4627 | 4659 | $parent_class, |
| 4628 | 4660 | $version, |
| 4629 | 4661 | '<pre>__construct()</pre>' |
| 4630 | | ) |
| | 4662 | ), |
| | 4663 | E_USER_DEPRECATED |
| 4631 | 4664 | ); |
| 4632 | 4665 | } else { |
| 4633 | 4666 | trigger_error( |
| … |
… |
function _deprecated_constructor( $class, $version, $parent_class = '' ) { |
| 4637 | 4670 | $class, |
| 4638 | 4671 | $version, |
| 4639 | 4672 | '<pre>__construct()</pre>' |
| 4640 | | ) |
| | 4673 | ), |
| | 4674 | E_USER_DEPRECATED |
| 4641 | 4675 | ); |
| 4642 | 4676 | } |
| 4643 | 4677 | } else { |
| … |
… |
function _deprecated_constructor( $class, $version, $parent_class = '' ) { |
| 4649 | 4683 | $parent_class, |
| 4650 | 4684 | $version, |
| 4651 | 4685 | '<pre>__construct()</pre>' |
| 4652 | | ) |
| | 4686 | ), |
| | 4687 | E_USER_DEPRECATED |
| 4653 | 4688 | ); |
| 4654 | 4689 | } else { |
| 4655 | 4690 | trigger_error( |
| … |
… |
function _deprecated_constructor( $class, $version, $parent_class = '' ) { |
| 4658 | 4693 | $class, |
| 4659 | 4694 | $version, |
| 4660 | 4695 | '<pre>__construct()</pre>' |
| 4661 | | ) |
| | 4696 | ), |
| | 4697 | E_USER_DEPRECATED |
| 4662 | 4698 | ); |
| 4663 | 4699 | } |
| 4664 | 4700 | } |
| … |
… |
function _deprecated_constructor( $class, $version, $parent_class = '' ) { |
| 4678 | 4714 | * This function is to be used in every file that is deprecated. |
| 4679 | 4715 | * |
| 4680 | 4716 | * @since 2.5.0 |
| | 4717 | * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE). |
| 4681 | 4718 | * @access private |
| 4682 | 4719 | * |
| 4683 | 4720 | * @param string $file The file that was included. |
| … |
… |
function _deprecated_file( $file, $version, $replacement = null, $message = '' ) |
| 4711 | 4748 | $message = empty( $message ) ? '' : ' ' . $message; |
| 4712 | 4749 | if ( function_exists( '__' ) ) { |
| 4713 | 4750 | if ( ! is_null( $replacement ) ) { |
| 4714 | | /* translators: 1: PHP file name, 2: Version number, 3: Alternative file name. */ |
| 4715 | | trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $file, $version, $replacement ) . $message ); |
| | 4751 | trigger_error( |
| | 4752 | sprintf( |
| | 4753 | /* translators: 1: PHP file name, 2: Version number, 3: Alternative file name. */ |
| | 4754 | __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), |
| | 4755 | $file, |
| | 4756 | $version, |
| | 4757 | $replacement |
| | 4758 | ) . $message, |
| | 4759 | E_USER_DEPRECATED |
| | 4760 | ); |
| 4716 | 4761 | } else { |
| 4717 | | /* translators: 1: PHP file name, 2: Version number. */ |
| 4718 | | trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $file, $version ) . $message ); |
| | 4762 | trigger_error( |
| | 4763 | sprintf( |
| | 4764 | /* translators: 1: PHP file name, 2: Version number. */ |
| | 4765 | __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), |
| | 4766 | $file, |
| | 4767 | $version |
| | 4768 | ) . $message, |
| | 4769 | E_USER_DEPRECATED |
| | 4770 | ); |
| 4719 | 4771 | } |
| 4720 | 4772 | } else { |
| 4721 | 4773 | if ( ! is_null( $replacement ) ) { |
| 4722 | | trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $file, $version, $replacement ) . $message ); |
| | 4774 | trigger_error( |
| | 4775 | sprintf( |
| | 4776 | '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', |
| | 4777 | $file, |
| | 4778 | $version, |
| | 4779 | $replacement |
| | 4780 | ) . $message, |
| | 4781 | E_USER_DEPRECATED |
| | 4782 | ); |
| 4723 | 4783 | } else { |
| 4724 | | trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $file, $version ) . $message ); |
| | 4784 | trigger_error( |
| | 4785 | sprintf( |
| | 4786 | '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', |
| | 4787 | $file, |
| | 4788 | $version |
| | 4789 | ) . $message, |
| | 4790 | E_USER_DEPRECATED |
| | 4791 | ); |
| 4725 | 4792 | } |
| 4726 | 4793 | } |
| 4727 | 4794 | } |
| … |
… |
function _deprecated_file( $file, $version, $replacement = null, $message = '' ) |
| 4745 | 4812 | * The current behavior is to trigger a user error if WP_DEBUG is true. |
| 4746 | 4813 | * |
| 4747 | 4814 | * @since 3.0.0 |
| | 4815 | * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE). |
| 4748 | 4816 | * @access private |
| 4749 | 4817 | * |
| 4750 | 4818 | * @param string $function The function that was called. |
| … |
… |
function _deprecated_argument( $function, $version, $message = null ) { |
| 4774 | 4842 | if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) { |
| 4775 | 4843 | if ( function_exists( '__' ) ) { |
| 4776 | 4844 | if ( ! is_null( $message ) ) { |
| 4777 | | /* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */ |
| 4778 | | trigger_error( sprintf( __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s' ), $function, $version, $message ) ); |
| | 4845 | trigger_error( |
| | 4846 | sprintf( |
| | 4847 | /* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */ |
| | 4848 | __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s' ), |
| | 4849 | $function, |
| | 4850 | $version, |
| | 4851 | $message |
| | 4852 | ), |
| | 4853 | E_USER_DEPRECATED |
| | 4854 | ); |
| 4779 | 4855 | } else { |
| 4780 | | /* translators: 1: PHP function name, 2: Version number. */ |
| 4781 | | 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 ) ); |
| | 4856 | trigger_error( |
| | 4857 | sprintf( |
| | 4858 | /* translators: 1: PHP function name, 2: Version number. */ |
| | 4859 | __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.' ), |
| | 4860 | $function, |
| | 4861 | $version |
| | 4862 | ), |
| | 4863 | E_USER_DEPRECATED |
| | 4864 | ); |
| 4782 | 4865 | } |
| 4783 | 4866 | } else { |
| 4784 | 4867 | if ( ! is_null( $message ) ) { |
| 4785 | | trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message ) ); |
| | 4868 | trigger_error( |
| | 4869 | sprintf( |
| | 4870 | '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', |
| | 4871 | $function, |
| | 4872 | $version, |
| | 4873 | $message |
| | 4874 | ), |
| | 4875 | E_USER_DEPRECATED |
| | 4876 | ); |
| 4786 | 4877 | } else { |
| 4787 | | 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 ) ); |
| | 4878 | trigger_error( |
| | 4879 | sprintf( |
| | 4880 | '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.', |
| | 4881 | $function, |
| | 4882 | $version |
| | 4883 | ), |
| | 4884 | E_USER_DEPRECATED |
| | 4885 | ); |
| 4788 | 4886 | } |
| 4789 | 4887 | } |
| 4790 | 4888 | } |
| … |
… |
function _deprecated_argument( $function, $version, $message = null ) { |
| 4802 | 4900 | * functions, and so generally does not need to be called directly. |
| 4803 | 4901 | * |
| 4804 | 4902 | * @since 4.6.0 |
| | 4903 | * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE). |
| 4805 | 4904 | * @access private |
| 4806 | 4905 | * |
| 4807 | 4906 | * @param string $hook The hook that was used. |
| … |
… |
function _deprecated_hook( $hook, $version, $replacement = null, $message = null |
| 4833 | 4932 | if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) { |
| 4834 | 4933 | $message = empty( $message ) ? '' : ' ' . $message; |
| 4835 | 4934 | if ( ! is_null( $replacement ) ) { |
| 4836 | | /* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */ |
| 4837 | | trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message ); |
| | 4935 | trigger_error( |
| | 4936 | sprintf( |
| | 4937 | /* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */ |
| | 4938 | __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), |
| | 4939 | $hook, |
| | 4940 | $version, |
| | 4941 | $replacement |
| | 4942 | ) . $message, |
| | 4943 | E_USER_DEPRECATED |
| | 4944 | ); |
| 4838 | 4945 | } else { |
| 4839 | | /* translators: 1: WordPress hook name, 2: Version number. */ |
| 4840 | | trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook, $version ) . $message ); |
| | 4946 | trigger_error( |
| | 4947 | sprintf( |
| | 4948 | /* translators: 1: WordPress hook name, 2: Version number. */ |
| | 4949 | __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), |
| | 4950 | $hook, |
| | 4951 | $version |
| | 4952 | ) . $message, |
| | 4953 | E_USER_DEPRECATED |
| | 4954 | ); |
| 4841 | 4955 | } |
| 4842 | 4956 | } |
| 4843 | 4957 | } |
| … |
… |
function _doing_it_wrong( $function, $message, $version ) { |
| 4896 | 5010 | __( 'https://wordpress.org/support/article/debugging-in-wordpress/' ) |
| 4897 | 5011 | ); |
| 4898 | 5012 | /* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: Version information message. */ |
| 4899 | | trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) ); |
| | 5013 | trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ), E_USER_NOTICE ); |
| 4900 | 5014 | } else { |
| 4901 | 5015 | if ( is_null( $version ) ) { |
| 4902 | 5016 | $version = ''; |
| … |
… |
function _doing_it_wrong( $function, $message, $version ) { |
| 4907 | 5021 | ' Please see <a href="%s">Debugging in WordPress</a> for more information.', |
| 4908 | 5022 | 'https://wordpress.org/support/article/debugging-in-wordpress/' |
| 4909 | 5023 | ); |
| 4910 | | trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ) ); |
| | 5024 | trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ), E_USER_NOTICE ); |
| 4911 | 5025 | } |
| 4912 | 5026 | } |
| 4913 | 5027 | } |
diff --git a/tests/phpunit/includes/phpunit6/compat.php b/tests/phpunit/includes/phpunit6/compat.php
index de9b0bccac..dcc99e9a76 100644
|
a
|
b
|
if ( class_exists( 'PHPUnit\Runner\Version' ) && version_compare( PHPUnit\Runner |
| 5 | 5 | class_alias( 'PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase' ); |
| 6 | 6 | class_alias( 'PHPUnit\Framework\Exception', 'PHPUnit_Framework_Exception' ); |
| 7 | 7 | class_alias( 'PHPUnit\Framework\ExpectationFailedException', 'PHPUnit_Framework_ExpectationFailedException' ); |
| | 8 | class_alias( 'PHPUnit\Framework\Error\Deprecated', 'PHPUnit_Framework_Error_Deprecated' ); |
| 8 | 9 | class_alias( 'PHPUnit\Framework\Error\Notice', 'PHPUnit_Framework_Error_Notice' ); |
| 9 | 10 | class_alias( 'PHPUnit\Framework\Error\Warning', 'PHPUnit_Framework_Error_Warning' ); |
| 10 | 11 | class_alias( 'PHPUnit\Framework\Test', 'PHPUnit_Framework_Test' ); |
diff --git a/tests/phpunit/tests/compat.php b/tests/phpunit/tests/compat.php
index dd6e06c0af..a8b14ee42c 100644
|
a
|
b
|
EOT; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
| 183 | | * @expectedException PHPUnit_Framework_Error_Notice |
| | 183 | * @expectedException PHPUnit_Framework_Error_Deprecated |
| 184 | 184 | */ |
| 185 | 185 | function test_json_encode_decode() { |
| 186 | 186 | require_once( ABSPATH . WPINC . '/class-json.php' ); |