PluginProbe ʕ •ᴥ•ʔ
Disable Admin Notices – Hide Dashboard Notifications / trunk
Disable Admin Notices – Hide Dashboard Notifications vtrunk
1.4.5 trunk 1.0.0 1.0.2 1.0.3 1.0.5 1.0.6 1.1.1 1.1.3 1.1.4 1.2.0 1.2.2 1.2.3 1.2.4 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4
disable-admin-notices / libs / factory / core / includes / functions.php
disable-admin-notices / libs / factory / core / includes Last commit date
activation 1 year ago assets-managment 1 year ago components 1 year ago entities 1 year ago updates 5 months ago class-check-compatibility.php 1 year ago class-factory-migrations.php 6 months ago class-factory-notices.php 1 year ago class-factory-options.php 1 year ago class-factory-plugin-abstract.php 5 months ago class-factory-plugin-base.php 1 year ago class-factory-requests.php 1 year ago class-factory-requirements.php 5 months ago functions.php 1 year ago index.php 3 years ago
functions.php
206 lines
1 <?php
2 /**
3 * Factory Function Library
4 *
5 * @author Alex Kovalev <alex.kovalevv@gmail.com>, repo: https://github.com/alexkovalevv
6 * @author Webcraftic <wordpress.webraftic@gmail.com>, site: https://webcraftic.com
7 *
8 * @package factory-core
9 * @since 1.0.0
10 */
11
12 // Exit if accessed directly
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! function_exists( 'get_user_locale' ) ) {
18 function get_user_locale( $user_id = 0 ) {
19 $user = false;
20 if ( 0 === $user_id && function_exists( 'wp_get_current_user' ) ) {
21 $user = wp_get_current_user();
22 } else if ( $user_id instanceof WP_User ) {
23 $user = $user_id;
24 } else if ( $user_id && is_numeric( $user_id ) ) {
25 $user = get_user_by( 'id', $user_id );
26 }
27
28 if ( ! $user ) {
29 return get_locale();
30 }
31
32 $locale = $user->locale;
33
34 return $locale ? $locale : get_locale();
35 }
36 }
37
38 /**
39 * Fires functions attached to a deprecated filter hook.
40 *
41 * When a filter hook is deprecated, the apply_filters() call is replaced with
42 * apply_filters_deprecated(), which triggers a deprecation notice and then fires
43 * the original filter hook.
44 *
45 * This is a copy of `apply_filters_deprecated` introduced in WP 4.6.
46 *
47 * @since 1.0.0
48 *
49 * @param string $tag The name of the filter hook.
50 * @param array $args Array of additional function arguments to be passed to apply_filters().
51 * @param string $version The version of BP Block Users that deprecated the hook.
52 * @param string $replacement Optional. The hook that should have been used.
53 * @param string $message Optional. A message regarding the change.
54 *
55 * @return mixed
56 * @see wbcr_factory_480_deprecated_hook()
57 *
58 */
59 function wbcr_factory_480_apply_filters_deprecated( $tag, $args, $version, $replacement = false, $message = null ) {
60 if ( function_exists( 'apply_filters_deprecated' ) ) {
61 return apply_filters_deprecated( $tag, $args, $version, $replacement, $message );
62 }
63 if ( ! has_filter( $tag ) ) {
64 return $args[0];
65 }
66 wbcr_factory_480_deprecated_hook( $tag, $version, $replacement, $message );
67
68 return apply_filters_ref_array( $tag, $args );
69 }
70
71 /**
72 * Fires functions attached to a deprecated action hook.
73 *
74 * When an action hook is deprecated, the do_action() call is replaced with
75 * do_action_deprecated(), which triggers a deprecation notice and then fires
76 * the original hook.
77 *
78 * This is a copy of `do_action_deprecated` introduced in WP 4.6.
79 *
80 * @since 1.0.0
81 *
82 * @param string $tag The name of the action hook.
83 * @param array $args Array of additional function arguments to be passed to do_action().
84 * @param string $version The version of BP Block Users that deprecated the hook.
85 * @param string $replacement Optional. The hook that should have been used.
86 * @param string $message Optional. A message regarding the change.
87 *
88 * @return void
89 * @see _deprecated_hook()
90 *
91 */
92 function wbcr_factory_480_do_action_deprecated( $tag, $args, $version, $replacement = false, $message = null ) {
93 if ( function_exists( 'do_action_deprecated' ) ) {
94 do_action_deprecated( $tag, $args, $version, $replacement, $message );
95
96 return;
97 }
98 if ( ! has_action( $tag ) ) {
99 return;
100 }
101 wbcr_factory_480_deprecated_hook( $tag, $version, $replacement, $message );
102 do_action_ref_array( $tag, $args );
103 }
104
105 /**
106 * Marks a deprecated action or filter hook as deprecated and throws a notice.
107 *
108 * Use the 'wbcr_factory_480_deprecated_hook_run' action to get the backtrace describing where the
109 * deprecated hook was called.
110 *
111 * Default behavior is to trigger a user error if WP_DEBUG is true.
112 *
113 * This function is called by the do_action_deprecated() and apply_filters_deprecated()
114 * functions, and so generally does not need to be called directly.
115 *
116 * This is a copy of `_deprecated_hook` introduced in WP 4.6.
117 *
118 * @since 1.0.0
119 * @access private
120 *
121 * @param string $hook The hook that was used.
122 * @param string $version The version of WordPress that deprecated the hook.
123 * @param string $replacement Optional. The hook that should have been used.
124 * @param string $message Optional. A message regarding the change.
125 */
126 function wbcr_factory_480_deprecated_hook( $hook, $version, $replacement = null, $message = null ) {
127 /**
128 * Fires when a deprecated hook is called.
129 *
130 * @since 1.0.0
131 *
132 * @param string $hook The hook that was called.
133 * @param string $replacement The hook that should be used as a replacement.
134 * @param string $version The version of BP Block Users that deprecated the argument used.
135 * @param string $message A message regarding the change.
136 */
137 do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message );
138
139 /**
140 * Filter whether to trigger deprecated hook errors.
141 *
142 * @since 1.0.0
143 *
144 * @param bool $trigger Whether to trigger deprecated hook errors. Requires
145 * `WP_DEBUG` to be defined true.
146 */
147 if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) {
148 $message = empty( $message ) ? '' : ' ' . $message;
149 if ( ! is_null( $replacement ) ) {
150 trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message );
151 } else {
152 trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook, $version ) . $message );
153 }
154 }
155 }
156
157 if ( ! function_exists( '_sanitize_text_fields' ) ) {
158 function _sanitize_text_fields( $str, $keep_newlines = false ) {
159 $filtered = wp_check_invalid_utf8( $str );
160
161 if ( strpos( $filtered, '<' ) !== false ) {
162 $filtered = wp_pre_kses_less_than( $filtered );
163 // This will strip extra whitespace for us.
164 $filtered = wp_strip_all_tags( $filtered, false );
165
166 // Use html entities in a special case to make sure no later
167 // newline stripping stage could lead to a functional tag
168 $filtered = str_replace( "<\n", "&lt;\n", $filtered );
169 }
170
171 if ( ! $keep_newlines ) {
172 $filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
173 }
174 $filtered = trim( $filtered );
175
176 $found = false;
177 while( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) {
178 $filtered = str_replace( $match[0], '', $filtered );
179 $found = true;
180 }
181
182 if ( $found ) {
183 // Strip out the whitespace that may now exist after removing the octets.
184 $filtered = trim( preg_replace( '/ +/', ' ', $filtered ) );
185 }
186
187 return $filtered;
188 }
189 }
190
191 if ( ! function_exists( 'sanitize_textarea_field' ) ) {
192 function sanitize_textarea_field( $str ) {
193 $filtered = _sanitize_text_fields( $str, true );
194
195 /**
196 * Filters a sanitized textarea field string.
197 *
198 * @since 4.7.0
199 *
200 * @param string $filtered The sanitized string.
201 * @param string $str The string prior to being sanitized.
202 */
203 return apply_filters( 'sanitize_textarea_field', $filtered, $str );
204 }
205 }
206