← All changes
|
includes/deprecated/class-charitable-deprecated.php
+17
-13
1.6.6
→
1.8.13
View file →
| @@ -2,10 +2,10 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * A helper class for logging deprecated arguments, functions and methods. |
| 4 | 4 | * |
| 5 | 5 | * @package Charitable/Classes/Charitable_Deprecated |
| 6 | - * @author Eric Daams | |
| 7 | - * @copyright Copyright (c) 2018, Studio 164a | |
| 6 | + * @author David Bisset | |
| 7 | + * @copyright Copyright (c) 2023, WP Charitable LLC | |
| 8 | 8 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 | 9 | * @version 1.4.0 |
| 10 | 10 | * @version 1.5.9 |
| 11 | 11 | */ |
| @@ -10,9 +10,11 @@ | ||
| 10 | 10 | * @version 1.5.9 |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | // Exit if accessed directly. |
| 14 | -if ( ! defined( 'ABSPATH' ) ) { exit; } | |
| 14 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 15 | + exit; | |
| 16 | +} | |
| 15 | 17 | |
| 16 | 18 | if ( ! class_exists( 'Charitable_Deprecated' ) ) : |
| 17 | 19 | |
| 18 | 20 | /** |
| @@ -46,9 +48,9 @@ | ||
| 46 | 48 | * @since 1.5.9 |
| 47 | 49 | * |
| 48 | 50 | * @var string |
| 49 | 51 | */ |
| 50 | - private $context; | |
| 52 | + protected $context; | |
| 51 | 53 | |
| 52 | 54 | /** |
| 53 | 55 | * Create class object. Private constructor. |
| 54 | 56 | * |
| @@ -65,13 +67,9 @@ | ||
| 65 | 67 | * |
| 66 | 68 | * @return Charitable_Deprecated |
| 67 | 69 | */ |
| 68 | 70 | public static function get_instance() { |
| 69 | - if ( is_null( self::$instance ) ) { | |
| 70 | - self::$instance = new self(); | |
| 71 | - } | |
| 72 | - | |
| 73 | - return self::$instance; | |
| 71 | + return self::$instance ??= new self(); | |
| 74 | 72 | } |
| 75 | 73 | |
| 76 | 74 | /** |
| 77 | 75 | * Log a deprecated argument. |
| @@ -88,14 +86,16 @@ | ||
| 88 | 86 | return false; |
| 89 | 87 | } |
| 90 | 88 | |
| 91 | 89 | if ( ! is_null( $extra_message ) ) { |
| 90 | + // translators: 1: function name, 2: version number, 3: extra message, 4: plugin name. | |
| 92 | 91 | $message = sprintf( __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s of %4$s! %3$s', 'charitable' ), $function, $version, $extra_message, $this->context ); |
| 93 | 92 | } else { |
| 93 | + // translators: 1: function name, 2: version number, 3: plugin name. | |
| 94 | 94 | $message = sprintf( __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s of %3$s with no alternatives available.', 'charitable' ), $function, $version, $this->context ); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - trigger_error( $message ); | |
| 97 | + trigger_error( $message ); // phpcs:ignore | |
| 98 | 98 | |
| 99 | 99 | return true; |
| 100 | 100 | } |
| 101 | 101 | |
| @@ -114,14 +114,16 @@ | ||
| 114 | 114 | return false; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | if ( ! is_null( $replacement ) ) { |
| 118 | + // translators: 1: function name, 2: version number, 3: replacement function name, 4: plugin name. | |
| 118 | 119 | $message = sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s of %4$s! Use %3$s instead.', 'charitable' ), $function, $version, $replacement, $this->context ); |
| 119 | 120 | } else { |
| 121 | + // translators: 1: function name, 2: version number, 3: plugin name. | |
| 120 | 122 | $message = sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s of %3$s with no alternatives available.', 'charitable' ), $function, $version, $this->context ); |
| 121 | 123 | } |
| 122 | 124 | |
| 123 | - trigger_error( $message ); | |
| 125 | + trigger_error( $message ); // phpcs:ignore | |
| 124 | 126 | |
| 125 | 127 | return true; |
| 126 | 128 | } |
| 127 | 129 | |
| @@ -139,13 +141,15 @@ | ||
| 139 | 141 | if ( ! $this->is_logging_enabled() ) { |
| 140 | 142 | return false; |
| 141 | 143 | } |
| 142 | 144 | |
| 143 | - $version = is_null( $version ) ? '' : sprintf( __( '(This message was added in %s version %s.)', 'charitable' ), $this->context, $version ); | |
| 145 | + // translators: 1: function name, 2: error message, 3: version number. | |
| 146 | + $version = is_null( $version ) ? '' : sprintf( __( '(This message was added in %1$s version %2$s.)', 'charitable' ), $this->context, $version ); | |
| 144 | 147 | |
| 148 | + // translators: 1: function name, 2: error message, 3: version number. | |
| 145 | 149 | $message = sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', 'charitable' ), $function, $message, $version ); |
| 146 | 150 | |
| 147 | - trigger_error( $message ); | |
| 151 | + trigger_error( $message ); // phpcs:ignore | |
| 148 | 152 | |
| 149 | 153 | return true; |
| 150 | 154 | } |
| 151 | 155 | |