PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.5
Pods – Custom Content Types and Fields v2.8.23.5
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / tribe-common / src / Tribe / Error.php
pods / tribe-common / src / Tribe Last commit date
Admin 1 week ago Ajax 1 week ago Asset 1 week ago Context 1 week ago Customizer 1 week ago Debug_Bar 1 week ago Dialog 1 week ago Documentation 1 week ago Duplicate 1 week ago Editor 1 week ago Image 1 week ago JSON_LD 1 week ago Languages 1 week ago Log 1 week ago Meta 1 week ago Models 1 week ago PUE 1 week ago Process 1 week ago Promoter 1 week ago REST 1 week ago Repository 1 week ago Service_Providers 1 week ago Shortcode 1 week ago Support 1 week ago Tabbed_View 1 week ago Tooltip 1 week ago Traits 1 week ago Utils 1 week ago Validator 1 week ago Widget 1 week ago Abstract_Deactivation.php 1 week ago Abstract_Plugin_Register.php 1 week ago App_Shop.php 1 week ago Assets.php 1 week ago Assets_Pipeline.php 1 week ago Autoloader.php 1 week ago Cache.php 1 week ago Cache_Listener.php 1 week ago Changelog_Reader.php 1 week ago Container.php 1 week ago Context.php 1 week ago Cost_Utils.php 1 week ago Credits.php 1 week ago Customizer.php 1 week ago DB_Lock.php 1 week ago Data.php 1 week ago Date_Utils.php 1 week ago Db.php 1 week ago Debug.php 1 week ago Dependency.php 1 week ago Deprecation.php 1 week ago Editor.php 1 week ago Error.php 1 week ago Exception.php 1 week ago Extension.php 1 week ago Extension_Loader.php 1 week ago Feature_Detection.php 1 week ago Field.php 1 week ago Field_Conditional.php 1 week ago Freemius.php 1 week ago Log.php 1 week ago Main.php 1 week ago Notices.php 1 week ago Plugin_Meta_Links.php 1 week ago Plugins.php 1 week ago Plugins_API.php 1 week ago Post_History.php 1 week ago Post_Transient.php 1 week ago Promise.php 1 week ago Repository.php 1 week ago Rewrite.php 1 week ago Settings.php 1 week ago Settings_Manager.php 1 week ago Settings_Tab.php 1 week ago Simple_Table.php 1 week ago Support.php 1 week ago Tabbed_View.php 1 week ago Template.php 1 week ago Template_Factory.php 1 week ago Template_Part_Cache.php 1 week ago Templates.php 1 week ago Terms.php 1 week ago Timezones.php 1 week ago Tracker.php 1 week ago Updater.php 1 week ago Validate.php 1 week ago View_Helpers.php 1 week ago
Error.php
201 lines
1 <?php
2 // Don't load directly
3 defined( 'WPINC' ) or die;
4
5 class Tribe__Error {
6 /**
7 * All the Errors Registered
8 * @var array
9 */
10 private $items = [];
11
12 /**
13 * Static Singleton Holder
14 *
15 * @var self
16 */
17 private static $instance;
18
19 /**
20 * Static Singleton Factory Method
21 *
22 * @return self
23 */
24 public static function instance() {
25 if ( ! self::$instance ) {
26 self::$instance = new self;
27 }
28
29 return self::$instance;
30 }
31
32 /**
33 * Setup all the hooks and filters
34 *
35 * @return void
36 */
37 private function __construct() {
38 $this->register( 'unknown', esc_html__( 'An Unknown error occurred' ) );
39 }
40
41 /**
42 * Make a quickly usable method to transform code/indexes to WP_Errors
43 *
44 * @see tribe_error()
45 *
46 * @param string|array $indexes Which Error we are looking for
47 * @param array $context Gives the Error context
48 * @param array $sprintf Allows variables on the message
49 *
50 * @return WP_Error
51 */
52 public function send( $indexes, $context = [], $sprintf = [] ) {
53 if ( ! $this->exists( $indexes ) ) {
54 $indexes = [ 'unknown' ];
55 }
56
57 // Fetches the Errors
58 $messages = (array) $this->get( $indexes );
59 $error = new WP_Error;
60
61 foreach ( $messages as $key => $message ) {
62 // Allows variables when sending the message
63 if ( ! empty( $sprintf ) ) {
64 $message = vsprintf( $message, $sprintf );
65 }
66 // Add this Message to the WP_Error
67 $error->add( $key, $message, $context );
68 }
69
70 return $error;
71 }
72
73 /**
74 * Register a new error based on a Namespace
75 *
76 * @param string|array $indexes A list of the namespaces and last item should be the error name
77 * @param string $message What is going to be the message associate with this indexes
78 *
79 * @return boolean
80 */
81 public function register( $indexes, $message ) {
82 if ( is_string( $indexes ) ) {
83 // Each namespace should come with `:`
84 $indexes = (array) explode( ':', $indexes );
85 }
86
87 // Couldn't register the error
88 if ( empty( $indexes ) ) {
89 return false;
90 }
91
92 $variable = &$this->items;
93 $count = count( $indexes );
94
95 // Will create the Indexes based on the $slug
96 foreach ( $indexes as $i => $index ) {
97 if ( $count === $i + 1 ) {
98 $variable[ $index ] = $message;
99 } else {
100 $variable = &$variable[ $index ];
101 }
102 }
103
104 // Allows Chain Reactions
105 return true;
106 }
107
108 /**
109 * Removes an error from the items
110 *
111 * @param string|array $indexes A list of the namespaces and last item should be the error name
112 *
113 * @return boolean
114 */
115 public function remove( $indexes ) {
116 if ( ! $this->exists( $indexes ) ) {
117 return false;
118 }
119
120 if ( is_string( $indexes ) ) {
121 // Each namespace should come with `:`
122 $indexes = (array) explode( ':', $indexes );
123 }
124
125 // Ensures that we don't modify the original
126 $variable = &$this->items;
127 $count = count( $indexes );
128
129 foreach ( $indexes as $i => $index ) {
130 if ( $count === $i + 1 ) {
131 unset( $variable[ $index ] );
132 } else {
133 $variable = &$variable[ $index ];
134 }
135 }
136
137 return true;
138 }
139
140 /**
141 * Fetches the error or namespace
142 *
143 * @param string|array $indexes (optional) A list of the namespaces and last item should be the error name
144 *
145 * @return null|array|string
146 */
147 public function get( $indexes = null ) {
148 if ( is_null( $indexes ) ) {
149 return $this->items;
150 }
151
152 if ( is_string( $indexes ) ) {
153 // Each namespace should come with `:`
154 $indexes = (array) explode( ':', $indexes );
155 }
156
157 // Ensures that we don't modify the original
158 $variable = $this->items;
159 $count = count( $indexes );
160
161 foreach ( $indexes as $i => $index ) {
162 if ( ! isset( $variable[ $index ] ) ) {
163 // If we are on the last item and we don't have it set make it Null
164 if ( $count === $i + 1 ) {
165 return null;
166 }
167 continue;
168 }
169
170 $variable = $variable[ $index ];
171 }
172
173 $return = [];
174 $was_namespace = is_array( $variable );
175
176 /**
177 * @todo Allow fetching bigger groups
178 * Right now you can only fetch the first group of messages
179 * Trying to fetch Namespaces that contain other namespaces will bug
180 */
181 foreach ( (array) $variable as $key => $value ) {
182 $key = implode( ':', $indexes ) . ( $was_namespace ? ':' . $key : '' );
183 $return[ $key ] = $value;
184 }
185
186 return $return;
187 }
188
189 /**
190 * Checks if a given error or namespace exists
191 *
192 * @param string|array $indexes A list of the namespaces and last item should be the error name
193 *
194 * @return boolean
195 */
196 public function exists( $indexes ) {
197 $variable = $this->get( $indexes );
198 return ! empty( $variable ) || is_array( $variable ) ? true : false;
199 }
200 }
201