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