Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like FrmAppHelper often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FrmAppHelper, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 6 | class FrmAppHelper { |
||
| 7 | public static $db_version = 97; //version of the database we are moving to |
||
| 8 | public static $pro_db_version = 37; //deprecated |
||
| 9 | public static $font_version = 7; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @since 2.0 |
||
| 13 | */ |
||
| 14 | public static $plug_version = '4.06.03'; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @since 1.07.02 |
||
| 18 | * |
||
| 19 | * @param none |
||
| 20 | * |
||
| 21 | * @return string The version of this plugin |
||
| 22 | */ |
||
| 23 | public static function plugin_version() { |
||
| 26 | |||
| 27 | public static function plugin_folder() { |
||
| 30 | |||
| 31 | public static function plugin_path() { |
||
| 34 | |||
| 35 | public static function plugin_url() { |
||
| 39 | |||
| 40 | public static function relative_plugin_url() { |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @return string Site URL |
||
| 46 | */ |
||
| 47 | public static function site_url() { |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Get the name of this site |
||
| 53 | * Used for [sitename] shortcode |
||
| 54 | * |
||
| 55 | * @since 2.0 |
||
| 56 | * @return string |
||
| 57 | */ |
||
| 58 | public static function site_name() { |
||
| 61 | |||
| 62 | public static function make_affiliate_url( $url ) { |
||
| 71 | |||
| 72 | public static function get_affiliate() { |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @since 3.04.02 |
||
| 78 | * @param array|string $args |
||
| 79 | * @param string $page |
||
| 80 | */ |
||
| 81 | public static function admin_upgrade_link( $args, $page = '' ) { |
||
| 82 | if ( empty( $page ) ) { |
||
| 83 | $page = 'https://formidableforms.com/lite-upgrade/'; |
||
| 84 | } else { |
||
| 85 | $page = str_replace( 'https://formidableforms.com/', '', $page ); |
||
| 86 | $page = 'https://formidableforms.com/' . $page; |
||
| 87 | } |
||
| 88 | |||
| 89 | $anchor = ''; |
||
| 90 | if ( is_array( $args ) ) { |
||
| 91 | $medium = $args['medium']; |
||
| 92 | $content = $args['content']; |
||
| 93 | if ( isset( $args['anchor'] ) ) { |
||
| 94 | $anchor = '#' . $args['anchor']; |
||
| 95 | } |
||
| 96 | } else { |
||
| 97 | $medium = $args; |
||
| 98 | } |
||
| 99 | |||
| 100 | $query_args = array( |
||
| 101 | 'utm_source' => 'WordPress', |
||
| 102 | 'utm_medium' => $medium, |
||
| 103 | 'utm_campaign' => 'liteplugin', |
||
| 104 | ); |
||
| 105 | |||
| 106 | if ( isset( $content ) ) { |
||
| 107 | $query_args['utm_content'] = $content; |
||
| 108 | } |
||
| 109 | |||
| 110 | if ( is_array( $args ) && isset( $args['param'] ) ) { |
||
| 111 | $query_args['f'] = $args['param']; |
||
| 112 | } |
||
| 113 | |||
| 114 | $link = add_query_arg( $query_args, $page ) . $anchor; |
||
| 115 | return self::make_affiliate_url( $link ); |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @since 4.07 |
||
| 120 | */ |
||
| 121 | public static function renewal_message() { |
||
| 122 | if ( ! FrmAddonsController::is_license_expired() ) { |
||
| 123 | return; |
||
| 124 | } |
||
| 125 | ?> |
||
| 126 | <div class="frm_error_style" style="text-align:left"> |
||
| 127 | <?php self::icon_by_class( 'frmfont frm_alert_icon' ); ?> |
||
| 128 | |
||
| 129 | <?php esc_attr_e( 'Your account has expired', 'formidable' ); ?> |
||
| 130 | <div style="float:right"> |
||
| 131 | <a href="<?php echo esc_url( self::admin_upgrade_link( 'form-renew', 'account/downloads/' ) ); ?>"> |
||
| 132 | Renew Now |
||
| 133 | </a> |
||
| 134 | </div> |
||
| 135 | </div> |
||
| 136 | <?php |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Get the Formidable settings |
||
| 141 | * |
||
| 142 | * @since 2.0 |
||
| 143 | * |
||
| 144 | * @param array $args - May include the form id when values need translation. |
||
| 145 | * @return FrmSettings $frm_setings |
||
| 146 | */ |
||
| 147 | public static function get_settings( $args = array() ) { |
||
| 148 | global $frm_settings; |
||
| 149 | if ( empty( $frm_settings ) ) { |
||
| 150 | $frm_settings = new FrmSettings( $args ); |
||
| 151 | } elseif ( isset( $args['current_form'] ) ) { |
||
| 152 | // If the global has already been set, allow strings to be filtered. |
||
| 153 | $frm_settings->maybe_filter_for_form( $args ); |
||
| 154 | } |
||
| 155 | |||
| 156 | return $frm_settings; |
||
| 157 | } |
||
| 158 | |||
| 159 | public static function get_menu_name() { |
||
| 160 | $frm_settings = self::get_settings(); |
||
| 161 | |||
| 162 | return $frm_settings->menu; |
||
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @since 3.05 |
||
| 167 | */ |
||
| 168 | public static function svg_logo( $atts = array() ) { |
||
| 169 | $defaults = array( |
||
| 170 | 'height' => 18, |
||
| 171 | 'width' => 18, |
||
| 172 | 'fill' => '#4d4d4d', |
||
| 173 | 'orange' => '#f05a24', |
||
| 174 | ); |
||
| 175 | $atts = array_merge( $defaults, $atts ); |
||
| 176 | |||
| 177 | return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 599.68 601.37" width="' . esc_attr( $atts['width'] ) . '" height="' . esc_attr( $atts['height'] ) . '"> |
||
| 178 | <path fill="' . esc_attr( $atts['orange'] ) . '" d="M289.6 384h140v76h-140z"/> |
||
| 179 | <path fill="' . esc_attr( $atts['fill'] ) . '" d="M400.2 147h-200c-17 0-30.6 12.2-30.6 29.3V218h260v-71zM397.9 264H169.6v196h75V340H398a32.2 32.2 0 0 0 30.1-21.4 24.3 24.3 0 0 0 1.7-8.7V264zM299.8 601.4A300.3 300.3 0 0 1 0 300.7a299.8 299.8 0 1 1 511.9 212.6 297.4 297.4 0 0 1-212 88zm0-563A262 262 0 0 0 38.3 300.7a261.6 261.6 0 1 0 446.5-185.5 259.5 259.5 0 0 0-185-76.8z"/> |
||
| 180 | </svg>'; |
||
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @since 4.0 |
||
| 185 | */ |
||
| 186 | public static function show_logo( $atts = array() ) { |
||
| 187 | echo self::kses( self::svg_logo( $atts ), 'all' ); // WPCS: XSS ok. |
||
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @since 4.03.02 |
||
| 192 | */ |
||
| 193 | public static function show_header_logo() { |
||
| 194 | $icon = self::svg_logo( |
||
| 195 | array( |
||
| 196 | 'height' => 35, |
||
| 197 | 'width' => 35, |
||
| 198 | ) |
||
| 199 | ); |
||
| 200 | |||
| 201 | $new_icon = apply_filters( 'frm_icon', $icon, true ); |
||
| 202 | if ( $new_icon !== $icon ) { |
||
| 203 | if ( strpos( $new_icon, '<svg' ) === 0 ) { |
||
| 204 | $icon = str_replace( 'viewBox="0 0 20', 'width="30" height="35" style="color:#929699" viewBox="0 0 20', $new_icon ); |
||
| 205 | } else { |
||
| 206 | // Show nothing if it isn't an SVG. |
||
| 207 | $icon = '<div style="height:39px"></div>'; |
||
| 208 | } |
||
| 209 | } |
||
| 210 | echo self::kses( $icon, 'all' ); // WPCS: XSS ok. |
||
| 211 | } |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @since 2.02.04 |
||
| 215 | */ |
||
| 216 | public static function ips_saved() { |
||
| 217 | $frm_settings = self::get_settings(); |
||
| 218 | |||
| 219 | return ! $frm_settings->no_ips; |
||
| 220 | } |
||
| 221 | |||
| 222 | public static function pro_is_installed() { |
||
| 223 | return apply_filters( 'frm_pro_installed', false ); |
||
| 224 | } |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @since 4.06.02 |
||
| 228 | */ |
||
| 229 | public static function pro_is_connected() { |
||
| 230 | global $frm_vars; |
||
| 231 | return self::pro_is_installed() && $frm_vars['pro_is_authorized']; |
||
| 232 | } |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @since 4.06 |
||
| 236 | */ |
||
| 237 | public static function is_form_builder_page() { |
||
| 238 | $action = self::simple_get( 'frm_action', 'sanitize_title' ); |
||
| 239 | return self::is_admin_page( 'formidable' ) && ( $action === 'edit' || $action === 'settings' || $action === 'duplicate' ); |
||
| 240 | } |
||
| 241 | |||
| 242 | public static function is_formidable_admin() { |
||
| 243 | $page = self::simple_get( 'page', 'sanitize_title' ); |
||
| 244 | $is_formidable = strpos( $page, 'formidable' ) !== false; |
||
| 245 | if ( empty( $page ) ) { |
||
| 246 | $is_formidable = self::is_view_builder_page(); |
||
| 247 | } |
||
| 248 | |||
| 249 | return $is_formidable; |
||
| 250 | } |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Check for certain page in Formidable settings |
||
| 254 | * |
||
| 255 | * @since 2.0 |
||
| 256 | * |
||
| 257 | * @param string $page The name of the page to check |
||
| 258 | * |
||
| 259 | * @return boolean |
||
| 260 | */ |
||
| 261 | public static function is_admin_page( $page = 'formidable' ) { |
||
| 262 | global $pagenow; |
||
| 263 | $get_page = self::simple_get( 'page', 'sanitize_title' ); |
||
| 264 | if ( $pagenow ) { |
||
| 265 | // allow this to be true during ajax load i.e. ajax form builder loading |
||
| 266 | $is_page = ( $pagenow == 'admin.php' || $pagenow == 'admin-ajax.php' ) && $get_page == $page; |
||
| 267 | if ( $is_page ) { |
||
| 268 | return true; |
||
| 269 | } |
||
| 270 | } |
||
| 271 | |||
| 272 | return is_admin() && $get_page == $page; |
||
| 273 | } |
||
| 274 | |||
| 275 | /** |
||
| 276 | * If the current page is for editing or creating a view. |
||
| 277 | * Returns false for the views listing page. |
||
| 278 | * |
||
| 279 | * @since 4.0 |
||
| 280 | */ |
||
| 281 | public static function is_view_builder_page() { |
||
| 282 | global $pagenow; |
||
| 283 | |||
| 284 | if ( $pagenow !== 'post.php' && $pagenow !== 'post-new.php' && $pagenow !== 'edit.php' ) { |
||
| 285 | return false; |
||
| 286 | } |
||
| 287 | |||
| 288 | $post_type = self::simple_get( 'post_type', 'sanitize_title' ); |
||
| 289 | |||
| 290 | if ( empty( $post_type ) ) { |
||
| 291 | $post_id = self::simple_get( 'post', 'absint' ); |
||
| 292 | $post = get_post( $post_id ); |
||
| 293 | $post_type = $post ? $post->post_type : ''; |
||
| 294 | } |
||
| 295 | |||
| 296 | return $post_type === 'frm_display'; |
||
| 297 | } |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Check for the form preview page |
||
| 301 | * |
||
| 302 | * @since 2.0 |
||
| 303 | * |
||
| 304 | * @param None |
||
| 305 | * |
||
| 306 | * @return boolean |
||
| 307 | */ |
||
| 308 | public static function is_preview_page() { |
||
| 309 | global $pagenow; |
||
| 310 | $action = self::simple_get( 'action', 'sanitize_title' ); |
||
| 311 | |||
| 312 | return $pagenow && $pagenow == 'admin-ajax.php' && $action == 'frm_forms_preview'; |
||
| 313 | } |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Check for ajax except the form preview page |
||
| 317 | * |
||
| 318 | * @since 2.0 |
||
| 319 | * |
||
| 320 | * @param None |
||
| 321 | * |
||
| 322 | * @return boolean |
||
| 323 | */ |
||
| 324 | public static function doing_ajax() { |
||
| 325 | return wp_doing_ajax() && ! self::is_preview_page(); |
||
| 326 | } |
||
| 327 | |||
| 328 | public static function js_suffix() { |
||
| 329 | return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
||
| 330 | } |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @since 2.0.8 |
||
| 334 | */ |
||
| 335 | public static function prevent_caching() { |
||
| 336 | global $frm_vars; |
||
| 337 | |||
| 338 | return isset( $frm_vars['prevent_caching'] ) && $frm_vars['prevent_caching']; |
||
| 339 | } |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Check if on an admin page |
||
| 343 | * |
||
| 344 | * @since 2.0 |
||
| 345 | * |
||
| 346 | * @param None |
||
| 347 | * |
||
| 348 | * @return boolean |
||
| 349 | */ |
||
| 350 | public static function is_admin() { |
||
| 351 | return is_admin() && ! wp_doing_ajax(); |
||
| 352 | } |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Check if value contains blank value or empty array |
||
| 356 | * |
||
| 357 | * @since 2.0 |
||
| 358 | * |
||
| 359 | * @param mixed $value - value to check |
||
| 360 | * @param string |
||
| 361 | * |
||
| 362 | * @return boolean |
||
| 363 | */ |
||
| 364 | public static function is_empty_value( $value, $empty = '' ) { |
||
| 365 | return ( is_array( $value ) && empty( $value ) ) || $value === $empty; |
||
| 366 | } |
||
| 367 | |||
| 368 | public static function is_not_empty_value( $value, $empty = '' ) { |
||
| 369 | return ! self::is_empty_value( $value, $empty ); |
||
| 370 | } |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Get any value from the $_SERVER |
||
| 374 | * |
||
| 375 | * @since 2.0 |
||
| 376 | * |
||
| 377 | * @param string $value |
||
| 378 | * |
||
| 379 | * @return string |
||
| 380 | */ |
||
| 381 | public static function get_server_value( $value ) { |
||
| 382 | return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( wp_unslash( $_SERVER[ $value ] ) ) : ''; |
||
| 383 | } |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Check for the IP address in several places |
||
| 387 | * Used by [ip] shortcode |
||
| 388 | * |
||
| 389 | * @return string The IP address of the current user |
||
| 390 | */ |
||
| 391 | public static function get_ip_address() { |
||
| 392 | $ip_options = array( |
||
| 393 | 'HTTP_CLIENT_IP', |
||
| 394 | 'HTTP_CF_CONNECTING_IP', |
||
| 395 | 'HTTP_X_FORWARDED_FOR', |
||
| 396 | 'HTTP_X_FORWARDED', |
||
| 397 | 'HTTP_X_CLUSTER_CLIENT_IP', |
||
| 398 | 'HTTP_X_REAL_IP', |
||
| 399 | 'HTTP_FORWARDED_FOR', |
||
| 400 | 'HTTP_FORWARDED', |
||
| 401 | 'REMOTE_ADDR', |
||
| 402 | ); |
||
| 403 | $ip = ''; |
||
| 404 | foreach ( $ip_options as $key ) { |
||
| 405 | if ( ! isset( $_SERVER[ $key ] ) ) { |
||
| 406 | continue; |
||
| 407 | } |
||
| 408 | |||
| 409 | $key = self::get_server_value( $key ); |
||
| 410 | foreach ( explode( ',', $key ) as $ip ) { |
||
| 411 | $ip = trim( $ip ); // just to be safe. |
||
| 412 | |||
| 413 | if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) { |
||
| 414 | return sanitize_text_field( $ip ); |
||
| 415 | } |
||
| 416 | } |
||
| 417 | } |
||
| 418 | |||
| 419 | return sanitize_text_field( $ip ); |
||
| 420 | } |
||
| 421 | |||
| 422 | public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) { |
||
| 423 | if ( strpos( $param, '[' ) ) { |
||
| 424 | $params = explode( '[', $param ); |
||
| 425 | $param = $params[0]; |
||
| 426 | } |
||
| 427 | |||
| 428 | if ( $src == 'get' ) { |
||
| 429 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
||
| 430 | $value = isset( $_POST[ $param ] ) ? wp_unslash( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? wp_unslash( $_GET[ $param ] ) : $default ); |
||
| 431 | if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) { |
||
| 432 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
||
| 433 | $value = htmlspecialchars_decode( wp_unslash( $_GET[ $param ] ) ); |
||
| 434 | } |
||
| 435 | self::sanitize_value( $sanitize, $value ); |
||
| 436 | } else { |
||
| 437 | $value = self::get_simple_request( |
||
| 438 | array( |
||
| 439 | 'type' => $src, |
||
| 440 | 'param' => $param, |
||
| 441 | 'default' => $default, |
||
| 442 | 'sanitize' => $sanitize, |
||
| 443 | ) |
||
| 444 | ); |
||
| 445 | } |
||
| 446 | |||
| 447 | if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) { |
||
| 448 | foreach ( $params as $k => $p ) { |
||
| 449 | if ( ! $k || ! is_array( $value ) ) { |
||
| 450 | continue; |
||
| 451 | } |
||
| 452 | |||
| 453 | $p = trim( $p, ']' ); |
||
| 454 | $value = isset( $value[ $p ] ) ? $value[ $p ] : $default; |
||
| 455 | } |
||
| 456 | } |
||
| 457 | |||
| 458 | return $value; |
||
| 459 | } |
||
| 460 | |||
| 461 | View Code Duplication | public static function get_post_param( $param, $default = '', $sanitize = '', $serialized = false ) { |
|
|
|
|||
| 462 | return self::get_simple_request( |
||
| 463 | array( |
||
| 464 | 'type' => 'post', |
||
| 465 | 'param' => $param, |
||
| 466 | 'default' => $default, |
||
| 467 | 'sanitize' => $sanitize, |
||
| 468 | 'serialized' => $serialized, |
||
| 469 | ) |
||
| 470 | ); |
||
| 471 | } |
||
| 472 | |||
| 473 | /** |
||
| 474 | * @since 2.0 |
||
| 475 | * |
||
| 476 | * @param string $param |
||
| 477 | * @param string $sanitize |
||
| 478 | * @param string $default |
||
| 479 | * |
||
| 480 | * @return string|array |
||
| 481 | */ |
||
| 482 | View Code Duplication | public static function simple_get( $param, $sanitize = 'sanitize_text_field', $default = '' ) { |
|
| 483 | return self::get_simple_request( |
||
| 484 | array( |
||
| 485 | 'type' => 'get', |
||
| 486 | 'param' => $param, |
||
| 487 | 'default' => $default, |
||
| 488 | 'sanitize' => $sanitize, |
||
| 489 | ) |
||
| 490 | ); |
||
| 491 | } |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Get a GET/POST/REQUEST value and sanitize it |
||
| 495 | * |
||
| 496 | * @since 2.0.6 |
||
| 497 | * |
||
| 498 | * @param array $args |
||
| 499 | * |
||
| 500 | * @return string|array |
||
| 501 | */ |
||
| 502 | public static function get_simple_request( $args ) { |
||
| 503 | $defaults = array( |
||
| 504 | 'param' => '', |
||
| 505 | 'default' => '', |
||
| 506 | 'type' => 'get', |
||
| 507 | 'sanitize' => 'sanitize_text_field', |
||
| 508 | 'serialized' => false, |
||
| 509 | ); |
||
| 510 | $args = wp_parse_args( $args, $defaults ); |
||
| 511 | |||
| 512 | $value = $args['default']; |
||
| 513 | if ( $args['type'] == 'get' ) { |
||
| 514 | View Code Duplication | if ( $_GET && isset( $_GET[ $args['param'] ] ) ) { |
|
| 515 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
||
| 516 | $value = wp_unslash( $_GET[ $args['param'] ] ); |
||
| 517 | } |
||
| 518 | } elseif ( $args['type'] == 'post' ) { |
||
| 519 | if ( isset( $_POST[ $args['param'] ] ) ) { |
||
| 520 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
||
| 521 | $value = wp_unslash( $_POST[ $args['param'] ] ); |
||
| 522 | if ( $args['serialized'] === true && is_serialized_string( $value ) && is_serialized( $value ) ) { |
||
| 523 | self::unserialize_or_decode( $value ); |
||
| 524 | } |
||
| 525 | } |
||
| 526 | View Code Duplication | } else { |
|
| 527 | if ( isset( $_REQUEST[ $args['param'] ] ) ) { |
||
| 528 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
||
| 529 | $value = wp_unslash( $_REQUEST[ $args['param'] ] ); |
||
| 530 | } |
||
| 531 | } |
||
| 532 | |||
| 533 | self::sanitize_value( $args['sanitize'], $value ); |
||
| 534 | |||
| 535 | return $value; |
||
| 536 | } |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Preserve backslashes in a value, but make sure value doesn't get compounding slashes |
||
| 540 | * |
||
| 541 | * @since 2.0.8 |
||
| 542 | * |
||
| 543 | * @param string $value |
||
| 544 | * |
||
| 545 | * @return string $value |
||
| 546 | */ |
||
| 547 | public static function preserve_backslashes( $value ) { |
||
| 548 | // If backslashes have already been added, don't add them again |
||
| 549 | if ( strpos( $value, '\\\\' ) === false ) { |
||
| 550 | $value = addslashes( $value ); |
||
| 551 | } |
||
| 552 | |||
| 553 | return $value; |
||
| 554 | } |
||
| 555 | |||
| 556 | public static function sanitize_value( $sanitize, &$value ) { |
||
| 557 | if ( ! empty( $sanitize ) ) { |
||
| 558 | if ( is_array( $value ) ) { |
||
| 559 | $temp_values = $value; |
||
| 560 | foreach ( $temp_values as $k => $v ) { |
||
| 561 | self::sanitize_value( $sanitize, $value[ $k ] ); |
||
| 562 | } |
||
| 563 | } else { |
||
| 564 | $value = call_user_func( $sanitize, $value ); |
||
| 565 | } |
||
| 566 | } |
||
| 567 | } |
||
| 568 | |||
| 569 | public static function sanitize_request( $sanitize_method, &$values ) { |
||
| 570 | $temp_values = $values; |
||
| 571 | foreach ( $temp_values as $k => $val ) { |
||
| 572 | if ( isset( $sanitize_method[ $k ] ) ) { |
||
| 573 | $values[ $k ] = call_user_func( $sanitize_method[ $k ], $val ); |
||
| 574 | } |
||
| 575 | } |
||
| 576 | } |
||
| 577 | |||
| 578 | /** |
||
| 579 | * @since 4.0.04 |
||
| 580 | */ |
||
| 581 | public static function sanitize_with_html( &$value ) { |
||
| 582 | self::sanitize_value( 'wp_kses_post', $value ); |
||
| 583 | self::decode_specialchars( $value ); |
||
| 584 | } |
||
| 585 | |||
| 586 | /** |
||
| 587 | * Do wp_specialchars_decode to get back '&' that wp_kses_post might have turned to '&' |
||
| 588 | * this MUST be done, else we'll be back to the '& entity' problem. |
||
| 589 | * |
||
| 590 | * @since 4.0.04 |
||
| 591 | */ |
||
| 592 | public static function decode_specialchars( &$value ) { |
||
| 593 | if ( is_array( $value ) ) { |
||
| 594 | $temp_values = $value; |
||
| 595 | foreach ( $temp_values as $k => $v ) { |
||
| 596 | self::decode_specialchars( $value[ $k ] ); |
||
| 597 | } |
||
| 598 | } else { |
||
| 599 | self::decode_amp( $value ); |
||
| 600 | } |
||
| 601 | } |
||
| 602 | |||
| 603 | /** |
||
| 604 | * The wp_specialchars_decode function changes too much. |
||
| 605 | * This will leave HTML as is, but still convert &. |
||
| 606 | * Adapted from wp_specialchars_decode(). |
||
| 607 | * |
||
| 608 | * @since 4.03.01 |
||
| 609 | * |
||
| 610 | * @param string $string The string to prep. |
||
| 611 | */ |
||
| 612 | private static function decode_amp( &$string ) { |
||
| 613 | // Don't bother if there are no entities - saves a lot of processing |
||
| 614 | if ( empty( $string ) || strpos( $string, '&' ) === false ) { |
||
| 615 | return; |
||
| 616 | } |
||
| 617 | |||
| 618 | $translation = array( |
||
| 619 | '"' => '"', |
||
| 620 | '"' => '"', |
||
| 621 | '"' => '"', |
||
| 622 | '< ' => '< ', // The space preserves the HTML. |
||
| 623 | '< ' => '< ', // The space preserves the HTML. |
||
| 624 | '>' => '>', |
||
| 625 | '>' => '>', |
||
| 626 | '&' => '&', |
||
| 627 | '&' => '&', |
||
| 628 | '&' => '&', |
||
| 629 | ); |
||
| 630 | |||
| 631 | $translation_preg = array( |
||
| 632 | '/�*34;/' => '"', |
||
| 633 | '/�*22;/i' => '"', |
||
| 634 | '/�*60;/' => '<', |
||
| 635 | '/�*62;/' => '>', |
||
| 636 | '/�*38;/' => '&', |
||
| 637 | '/�*26;/i' => '&', |
||
| 638 | ); |
||
| 639 | |||
| 640 | // Remove zero padding on numeric entities |
||
| 641 | $string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string ); |
||
| 642 | |||
| 643 | // Replace characters according to translation table |
||
| 644 | $string = strtr( $string, $translation ); |
||
| 645 | } |
||
| 646 | |||
| 647 | /** |
||
| 648 | * Sanitize the value, and allow some HTML |
||
| 649 | * |
||
| 650 | * @since 2.0 |
||
| 651 | * |
||
| 652 | * @param string $value |
||
| 653 | * @param array|string $allowed 'all' for everything included as defaults |
||
| 654 | * |
||
| 655 | * @return string |
||
| 656 | */ |
||
| 657 | public static function kses( $value, $allowed = array() ) { |
||
| 658 | $allowed_html = self::allowed_html( $allowed ); |
||
| 659 | |||
| 660 | return wp_kses( $value, $allowed_html ); |
||
| 661 | } |
||
| 662 | |||
| 663 | /** |
||
| 664 | * @since 2.05.03 |
||
| 665 | */ |
||
| 666 | private static function allowed_html( $allowed ) { |
||
| 667 | $html = self::safe_html(); |
||
| 668 | $allowed_html = array(); |
||
| 669 | if ( $allowed == 'all' ) { |
||
| 670 | $allowed_html = $html; |
||
| 671 | } elseif ( ! empty( $allowed ) ) { |
||
| 672 | foreach ( (array) $allowed as $a ) { |
||
| 673 | $allowed_html[ $a ] = isset( $html[ $a ] ) ? $html[ $a ] : array(); |
||
| 674 | } |
||
| 675 | } |
||
| 676 | |||
| 677 | return apply_filters( 'frm_striphtml_allowed_tags', $allowed_html ); |
||
| 678 | } |
||
| 679 | |||
| 680 | /** |
||
| 681 | * @since 2.05.03 |
||
| 682 | */ |
||
| 683 | private static function safe_html() { |
||
| 684 | $allow_class = array( |
||
| 685 | 'class' => true, |
||
| 686 | 'id' => true, |
||
| 687 | ); |
||
| 688 | |||
| 689 | return array( |
||
| 690 | 'a' => array( |
||
| 691 | 'class' => true, |
||
| 692 | 'href' => true, |
||
| 693 | 'id' => true, |
||
| 694 | 'rel' => true, |
||
| 695 | 'target' => true, |
||
| 696 | 'title' => true, |
||
| 697 | ), |
||
| 698 | 'abbr' => array( |
||
| 699 | 'title' => true, |
||
| 700 | ), |
||
| 701 | 'aside' => $allow_class, |
||
| 702 | 'b' => array(), |
||
| 703 | 'blockquote' => array( |
||
| 704 | 'cite' => true, |
||
| 705 | ), |
||
| 706 | 'br' => array(), |
||
| 707 | 'cite' => array( |
||
| 708 | 'title' => true, |
||
| 709 | ), |
||
| 710 | 'code' => array(), |
||
| 711 | 'defs' => array(), |
||
| 712 | 'del' => array( |
||
| 713 | 'datetime' => true, |
||
| 714 | 'title' => true, |
||
| 715 | ), |
||
| 716 | 'dd' => array(), |
||
| 717 | 'div' => array( |
||
| 718 | 'class' => true, |
||
| 719 | 'id' => true, |
||
| 720 | 'title' => true, |
||
| 721 | 'style' => true, |
||
| 722 | ), |
||
| 723 | 'dl' => array(), |
||
| 724 | 'dt' => array(), |
||
| 725 | 'em' => array(), |
||
| 726 | 'h1' => $allow_class, |
||
| 727 | 'h2' => $allow_class, |
||
| 728 | 'h3' => $allow_class, |
||
| 729 | 'h4' => $allow_class, |
||
| 730 | 'h5' => $allow_class, |
||
| 731 | 'h6' => $allow_class, |
||
| 732 | 'i' => array( |
||
| 733 | 'class' => true, |
||
| 734 | 'id' => true, |
||
| 735 | 'icon' => true, |
||
| 736 | 'style' => true, |
||
| 737 | ), |
||
| 738 | 'img' => array( |
||
| 739 | 'alt' => true, |
||
| 740 | 'class' => true, |
||
| 741 | 'height' => true, |
||
| 742 | 'id' => true, |
||
| 743 | 'src' => true, |
||
| 744 | 'width' => true, |
||
| 745 | ), |
||
| 746 | 'li' => $allow_class, |
||
| 747 | 'ol' => $allow_class, |
||
| 748 | 'p' => $allow_class, |
||
| 749 | 'path' => array( |
||
| 750 | 'd' => true, |
||
| 751 | 'fill' => true, |
||
| 752 | ), |
||
| 753 | 'pre' => array(), |
||
| 754 | 'q' => array( |
||
| 755 | 'cite' => true, |
||
| 756 | 'title' => true, |
||
| 757 | ), |
||
| 758 | 'rect' => array( |
||
| 759 | 'class' => true, |
||
| 760 | 'fill' => true, |
||
| 761 | 'height' => true, |
||
| 762 | 'width' => true, |
||
| 763 | 'x' => true, |
||
| 764 | 'y' => true, |
||
| 765 | 'rx' => true, |
||
| 766 | 'stroke' => true, |
||
| 767 | 'stroke-opacity' => true, |
||
| 768 | 'stroke-width' => true, |
||
| 769 | ), |
||
| 770 | 'section' => $allow_class, |
||
| 771 | 'span' => array( |
||
| 772 | 'class' => true, |
||
| 773 | 'id' => true, |
||
| 774 | 'title' => true, |
||
| 775 | 'style' => true, |
||
| 776 | ), |
||
| 777 | 'strike' => array(), |
||
| 778 | 'strong' => array(), |
||
| 779 | 'symbol' => array( |
||
| 780 | 'class' => true, |
||
| 781 | 'id' => true, |
||
| 782 | 'viewbox' => true, |
||
| 783 | ), |
||
| 784 | 'svg' => array( |
||
| 785 | 'class' => true, |
||
| 786 | 'id' => true, |
||
| 787 | 'xmlns' => true, |
||
| 788 | 'viewbox' => true, |
||
| 789 | 'width' => true, |
||
| 790 | 'height' => true, |
||
| 791 | 'style' => true, |
||
| 792 | 'fill' => true, |
||
| 793 | ), |
||
| 794 | 'use' => array( |
||
| 795 | 'href' => true, |
||
| 796 | 'xlink:href' => true, |
||
| 797 | ), |
||
| 798 | 'ul' => $allow_class, |
||
| 799 | ); |
||
| 800 | } |
||
| 801 | |||
| 802 | /** |
||
| 803 | * Used when switching the action for a bulk action |
||
| 804 | * |
||
| 805 | * @since 2.0 |
||
| 806 | */ |
||
| 807 | public static function remove_get_action() { |
||
| 808 | if ( ! isset( $_GET ) ) { |
||
| 809 | return; |
||
| 810 | } |
||
| 811 | |||
| 812 | $action_name = isset( $_GET['action'] ) ? 'action' : ( isset( $_GET['action2'] ) ? 'action2' : '' ); |
||
| 813 | if ( empty( $action_name ) ) { |
||
| 814 | return; |
||
| 815 | } |
||
| 816 | |||
| 817 | $new_action = self::get_param( $action_name, '', 'get', 'sanitize_text_field' ); |
||
| 818 | if ( ! empty( $new_action ) ) { |
||
| 819 | $_SERVER['REQUEST_URI'] = str_replace( '&action=' . $new_action, '', self::get_server_value( 'REQUEST_URI' ) ); |
||
| 820 | } |
||
| 821 | } |
||
| 822 | |||
| 823 | /** |
||
| 824 | * Check the WP query for a parameter |
||
| 825 | * |
||
| 826 | * @since 2.0 |
||
| 827 | * @return string|array |
||
| 828 | */ |
||
| 829 | public static function get_query_var( $value, $param ) { |
||
| 830 | if ( $value != '' ) { |
||
| 831 | return $value; |
||
| 832 | } |
||
| 833 | |||
| 834 | global $wp_query; |
||
| 835 | if ( isset( $wp_query->query_vars[ $param ] ) ) { |
||
| 836 | $value = $wp_query->query_vars[ $param ]; |
||
| 837 | } |
||
| 838 | |||
| 839 | return $value; |
||
| 840 | } |
||
| 841 | |||
| 842 | /** |
||
| 843 | * Try to show the SVG if possible. Otherwise, use the font icon. |
||
| 844 | * |
||
| 845 | * @since 4.0.02 |
||
| 846 | * @param string $class |
||
| 847 | * @param array $atts |
||
| 848 | */ |
||
| 849 | public static function icon_by_class( $class, $atts = array() ) { |
||
| 850 | $echo = ! isset( $atts['echo'] ) || $atts['echo']; |
||
| 851 | if ( isset( $atts['echo'] ) ) { |
||
| 852 | unset( $atts['echo'] ); |
||
| 853 | } |
||
| 854 | |||
| 855 | $html_atts = self::array_to_html_params( $atts ); |
||
| 856 | |||
| 857 | $icon = trim( str_replace( array( 'frm_icon_font', 'frmfont ' ), '', $class ) ); |
||
| 858 | if ( $icon === $class ) { |
||
| 859 | $icon = '<i class="' . esc_attr( $class ) . '"' . $html_atts . '></i>'; |
||
| 860 | } else { |
||
| 861 | $class = strpos( $icon, ' ' ) === false ? '' : ' ' . $icon; |
||
| 862 | if ( strpos( $icon, ' ' ) ) { |
||
| 863 | $icon = explode( ' ', $icon ); |
||
| 864 | $icon = reset( $icon ); |
||
| 865 | } |
||
| 866 | $icon = '<svg class="frmsvg' . esc_attr( $class ) . '"' . $html_atts . '> |
||
| 867 | <use xlink:href="#' . esc_attr( $icon ) . '" /> |
||
| 868 | </svg>'; |
||
| 869 | } |
||
| 870 | |||
| 871 | if ( $echo ) { |
||
| 872 | echo $icon; // WPCS: XSS ok. |
||
| 873 | } else { |
||
| 874 | return $icon; |
||
| 875 | } |
||
| 876 | } |
||
| 877 | |||
| 878 | /** |
||
| 879 | * Include svg images. |
||
| 880 | * |
||
| 881 | * @since 4.0.02 |
||
| 882 | */ |
||
| 883 | public static function include_svg() { |
||
| 884 | include_once( self::plugin_path() . '/images/icons.svg' ); |
||
| 885 | } |
||
| 886 | |||
| 887 | /** |
||
| 888 | * Convert an associative array to HTML values. |
||
| 889 | * |
||
| 890 | * @since 4.0.02 |
||
| 891 | * @param array $atts |
||
| 892 | * @return string |
||
| 893 | */ |
||
| 894 | public static function array_to_html_params( $atts ) { |
||
| 895 | $html = ''; |
||
| 896 | if ( ! empty( $atts ) ) { |
||
| 897 | foreach ( $atts as $key => $value ) { |
||
| 898 | $html .= ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
||
| 899 | } |
||
| 900 | } |
||
| 901 | return $html; |
||
| 902 | } |
||
| 903 | |||
| 904 | /** |
||
| 905 | * @since 3.0 |
||
| 906 | */ |
||
| 907 | public static function get_admin_header( $atts ) { |
||
| 908 | $has_nav = ( isset( $atts['form'] ) && ! empty( $atts['form'] ) && ( ! isset( $atts['is_template'] ) || ! $atts['is_template'] ) ); |
||
| 909 | if ( ! isset( $atts['close'] ) || empty( $atts['close'] ) ) { |
||
| 910 | $atts['close'] = admin_url( 'admin.php?page=formidable' ); |
||
| 911 | } |
||
| 912 | if ( ! isset( $atts['import_link'] ) ) { |
||
| 913 | $atts['import_link'] = false; |
||
| 914 | } |
||
| 915 | |||
| 916 | include( self::plugin_path() . '/classes/views/shared/admin-header.php' ); |
||
| 917 | } |
||
| 918 | |||
| 919 | /** |
||
| 920 | * @since 3.0 |
||
| 921 | */ |
||
| 922 | public static function add_new_item_link( $atts ) { |
||
| 923 | if ( isset( $atts['new_link'] ) && ! empty( $atts['new_link'] ) ) { |
||
| 924 | ?> |
||
| 925 | <a href="<?php echo esc_url( $atts['new_link'] ); ?>" class="button button-primary frm-button-primary frm-with-plus"> |
||
| 926 | <?php self::icon_by_class( 'frmfont frm_plus_icon frm_svg15' ); ?> |
||
| 927 | <?php esc_html_e( 'Add New', 'formidable' ); ?> |
||
| 928 | </a> |
||
| 929 | <?php |
||
| 930 | } elseif ( isset( $atts['link_hook'] ) ) { |
||
| 931 | do_action( $atts['link_hook']['hook'], $atts['link_hook']['param'] ); |
||
| 932 | } |
||
| 933 | } |
||
| 934 | |||
| 935 | /** |
||
| 936 | * @since 3.06 |
||
| 937 | */ |
||
| 938 | public static function show_search_box( $atts ) { |
||
| 939 | $defaults = array( |
||
| 940 | 'placeholder' => '', |
||
| 941 | 'tosearch' => '', |
||
| 942 | 'text' => __( 'Search', 'formidable' ), |
||
| 943 | 'input_id' => '', |
||
| 944 | ); |
||
| 945 | $atts = array_merge( $defaults, $atts ); |
||
| 946 | |||
| 947 | if ( $atts['input_id'] === 'template' && empty( $atts['tosearch'] ) ) { |
||
| 948 | $atts['tosearch'] = 'frm-card'; |
||
| 949 | } |
||
| 950 | |||
| 951 | $class = 'frm-search-input'; |
||
| 952 | if ( ! empty( $atts['tosearch'] ) ) { |
||
| 953 | $class .= ' frm-auto-search'; |
||
| 954 | } |
||
| 955 | |||
| 956 | $input_id = $atts['input_id'] . '-search-input'; |
||
| 957 | |||
| 958 | ?> |
||
| 959 | <p class="frm-search"> |
||
| 960 | <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"> |
||
| 961 | <?php echo esc_html( $atts['text'] ); ?>: |
||
| 962 | </label> |
||
| 963 | <span class="frmfont frm_search_icon"></span> |
||
| 964 | <input type="search" id="<?php echo esc_attr( $input_id ); ?>" name="s" |
||
| 965 | value="<?php _admin_search_query(); ?>" placeholder="<?php echo esc_attr( $atts['placeholder'] ); ?>" |
||
| 966 | class="<?php echo esc_attr( $class ); ?>" data-tosearch="<?php echo esc_attr( $atts['tosearch'] ); ?>" |
||
| 967 | <?php if ( ! empty( $atts['tosearch'] ) ) { ?> |
||
| 968 | autocomplete="off" |
||
| 969 | <?php } ?> |
||
| 970 | /> |
||
| 971 | <?php |
||
| 972 | if ( empty( $atts['tosearch'] ) ) { |
||
| 973 | submit_button( $atts['text'], 'button-secondary', '', false, array( 'id' => 'search-submit' ) ); |
||
| 974 | } |
||
| 975 | ?> |
||
| 976 | </p> |
||
| 977 | <?php |
||
| 978 | } |
||
| 979 | |||
| 980 | /** |
||
| 981 | * @param string $type |
||
| 982 | */ |
||
| 983 | public static function trigger_hook_load( $type, $object = null ) { |
||
| 984 | // Only load the form hooks once. |
||
| 985 | $hooks_loaded = apply_filters( 'frm_' . $type . '_hooks_loaded', false, $object ); |
||
| 986 | if ( ! $hooks_loaded ) { |
||
| 987 | do_action( 'frm_load_' . $type . '_hooks' ); |
||
| 988 | } |
||
| 989 | } |
||
| 990 | |||
| 991 | /** |
||
| 992 | * Save all front-end js scripts into a single file |
||
| 993 | * |
||
| 994 | * @since 3.0 |
||
| 995 | */ |
||
| 996 | public static function save_combined_js() { |
||
| 997 | $file_atts = apply_filters( |
||
| 998 | 'frm_js_location', |
||
| 999 | array( |
||
| 1000 | 'file_name' => 'frm.min.js', |
||
| 1001 | 'new_file_path' => self::plugin_path() . '/js', |
||
| 1002 | ) |
||
| 1003 | ); |
||
| 1004 | $new_file = new FrmCreateFile( $file_atts ); |
||
| 1005 | |||
| 1006 | $files = array( |
||
| 1007 | self::plugin_path() . '/js/jquery/jquery.placeholder.min.js', |
||
| 1008 | self::plugin_path() . '/js/formidable.min.js', |
||
| 1009 | ); |
||
| 1010 | $files = apply_filters( 'frm_combined_js_files', $files ); |
||
| 1011 | $new_file->combine_files( $files ); |
||
| 1012 | } |
||
| 1013 | |||
| 1014 | /** |
||
| 1015 | * Check a value from a shortcode to see if true or false. |
||
| 1016 | * True when value is 1, true, 'true', 'yes' |
||
| 1017 | * |
||
| 1018 | * @since 1.07.10 |
||
| 1019 | * |
||
| 1020 | * @param string $value The value to compare |
||
| 1021 | * |
||
| 1022 | * @return boolean True or False |
||
| 1023 | */ |
||
| 1024 | public static function is_true( $value ) { |
||
| 1025 | return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value ); |
||
| 1026 | } |
||
| 1027 | |||
| 1028 | public static function get_pages() { |
||
| 1029 | $query = array( |
||
| 1030 | 'post_type' => 'page', |
||
| 1031 | 'post_status' => array( 'publish', 'private' ), |
||
| 1032 | 'numberposts' => - 1, |
||
| 1033 | 'orderby' => 'title', |
||
| 1034 | 'order' => 'ASC', |
||
| 1035 | ); |
||
| 1036 | |||
| 1037 | return get_posts( $query ); |
||
| 1038 | } |
||
| 1039 | |||
| 1040 | /** |
||
| 1041 | * Renders an autocomplete page selection or a regular dropdown depending on |
||
| 1042 | * the total page count |
||
| 1043 | * |
||
| 1044 | * @since 4.03.06 |
||
| 1045 | */ |
||
| 1046 | public static function maybe_autocomplete_pages_options( $args ) { |
||
| 1047 | $args = self::preformat_selection_args( $args ); |
||
| 1048 | |||
| 1049 | $pages_count = wp_count_posts( 'page' ); |
||
| 1050 | |||
| 1051 | if ( $pages_count->publish <= 50 ) { |
||
| 1052 | self::wp_pages_dropdown( $args ); |
||
| 1053 | return; |
||
| 1054 | } |
||
| 1055 | |||
| 1056 | wp_enqueue_script( 'jquery-ui-autocomplete' ); |
||
| 1057 | |||
| 1058 | $selected = self::get_post_param( $args['field_name'], $args['page_id'], 'absint' ); |
||
| 1059 | $title = ''; |
||
| 1060 | |||
| 1061 | if ( $selected ) { |
||
| 1062 | $title = get_the_title( $selected ); |
||
| 1063 | } |
||
| 1064 | |||
| 1065 | ?> |
||
| 1066 | <input type="text" class="frm-page-search" |
||
| 1067 | placeholder="<?php esc_html_e( 'Select a Page', 'formidable' ); ?>" |
||
| 1068 | value="<?php echo esc_attr( $title ); ?>" /> |
||
| 1069 | <input type="hidden" name="<?php echo esc_attr( $args['field_name'] ); ?>" |
||
| 1070 | value="<?php echo esc_attr( $selected ); ?>" /> |
||
| 1071 | <?php |
||
| 1072 | } |
||
| 1073 | |||
| 1074 | /** |
||
| 1075 | * @param array $args |
||
| 1076 | * @param string $page_id Deprecated. |
||
| 1077 | * @param boolean $truncate Deprecated. |
||
| 1078 | */ |
||
| 1079 | public static function wp_pages_dropdown( $args = array(), $page_id = '', $truncate = false ) { |
||
| 1080 | self::prep_page_dropdown_params( $page_id, $truncate, $args ); |
||
| 1081 | |||
| 1082 | $pages = self::get_pages(); |
||
| 1083 | $selected = self::get_post_param( $args['field_name'], $args['page_id'], 'absint' ); |
||
| 1084 | |||
| 1085 | ?> |
||
| 1086 | <select name="<?php echo esc_attr( $args['field_name'] ); ?>" id="<?php echo esc_attr( $args['field_name'] ); ?>" class="frm-pages-dropdown"> |
||
| 1087 | <option value=""><?php echo esc_html( $args['placeholder'] ); ?></option> |
||
| 1088 | <?php foreach ( $pages as $page ) { ?> |
||
| 1089 | <option value="<?php echo esc_attr( $page->ID ); ?>" <?php selected( $selected, $page->ID ); ?>> |
||
| 1090 | <?php echo esc_html( $args['truncate'] ? self::truncate( $page->post_title, $args['truncate'] ) : $page->post_title ); ?> |
||
| 1091 | </option> |
||
| 1092 | <?php } ?> |
||
| 1093 | </select> |
||
| 1094 | <?php |
||
| 1095 | } |
||
| 1096 | |||
| 1097 | /** |
||
| 1098 | * Fill in missing parameters passed to wp_pages_dropdown(). |
||
| 1099 | * This is for reverse compatibility with switching 3 params to 1. |
||
| 1100 | * |
||
| 1101 | * @since 4.03.06 |
||
| 1102 | */ |
||
| 1103 | private static function prep_page_dropdown_params( $page_id, $truncate, &$args ) { |
||
| 1104 | if ( ! is_array( $args ) ) { |
||
| 1105 | $args = array( |
||
| 1106 | 'field_name' => $args, |
||
| 1107 | 'page_id' => $page_id, |
||
| 1108 | 'truncate' => $truncate, |
||
| 1109 | ); |
||
| 1110 | } |
||
| 1111 | |||
| 1112 | $args = self::preformat_selection_args( $args ); |
||
| 1113 | } |
||
| 1114 | |||
| 1115 | /** |
||
| 1116 | * Filter to format args for page dropdown or autocomplete |
||
| 1117 | * |
||
| 1118 | * @since 4.03.06 |
||
| 1119 | */ |
||
| 1120 | private static function preformat_selection_args( $args ) { |
||
| 1121 | $defaults = array( |
||
| 1122 | 'truncate' => false, |
||
| 1123 | 'placeholder' => ' ', |
||
| 1124 | 'field_name' => '', |
||
| 1125 | 'page_id' => '', |
||
| 1126 | ); |
||
| 1127 | |||
| 1128 | return array_merge( $defaults, $args ); |
||
| 1129 | } |
||
| 1130 | |||
| 1131 | public static function post_edit_link( $post_id ) { |
||
| 1132 | $post = get_post( $post_id ); |
||
| 1133 | if ( $post ) { |
||
| 1134 | $post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' ); |
||
| 1135 | $post_url = self::maybe_full_screen_link( $post_url ); |
||
| 1136 | |||
| 1137 | return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>'; |
||
| 1138 | } |
||
| 1139 | |||
| 1140 | return ''; |
||
| 1141 | } |
||
| 1142 | |||
| 1143 | /** |
||
| 1144 | * Hide the WordPress menus on some pages. |
||
| 1145 | * |
||
| 1146 | * @since 4.0 |
||
| 1147 | */ |
||
| 1148 | public static function is_full_screen() { |
||
| 1149 | $full_builder = self::is_form_builder_page(); |
||
| 1150 | $styler = self::is_admin_page( 'formidable-styles' ) || self::is_admin_page( 'formidable-styles2' ); |
||
| 1151 | $full_entries = self::simple_get( 'frm-full', 'absint' ); |
||
| 1152 | |||
| 1153 | return $full_builder || $full_entries || $styler || self::is_view_builder_page(); |
||
| 1154 | } |
||
| 1155 | |||
| 1156 | /** |
||
| 1157 | * @since 4.0 |
||
| 1158 | */ |
||
| 1159 | public static function maybe_full_screen_link( $link ) { |
||
| 1160 | $is_full = self::simple_get( 'frm-full', 'absint' ); |
||
| 1161 | if ( $is_full && ! empty( $link ) && $link !== '#' ) { |
||
| 1162 | $link .= '&frm-full=1'; |
||
| 1163 | } |
||
| 1164 | return $link; |
||
| 1165 | } |
||
| 1166 | |||
| 1167 | /** |
||
| 1168 | * @param string $field_name |
||
| 1169 | * @param string|array $capability |
||
| 1170 | * @param string $multiple 'single' and 'multiple' |
||
| 1171 | */ |
||
| 1172 | public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) { |
||
| 1173 | ?> |
||
| 1174 | <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>" |
||
| 1175 | <?php echo ( 'multiple' === $multiple ) ? 'multiple="multiple"' : ''; ?> |
||
| 1176 | class="frm_multiselect"> |
||
| 1177 | <?php self::roles_options( $capability ); ?> |
||
| 1178 | </select> |
||
| 1179 | <?php |
||
| 1180 | } |
||
| 1181 | |||
| 1182 | /** |
||
| 1183 | * @since 4.07 |
||
| 1184 | * @param array|string $selected |
||
| 1185 | * @param string $current |
||
| 1186 | */ |
||
| 1187 | private static function selected( $selected, $current ) { |
||
| 1188 | if ( is_callable( 'FrmProAppHelper::selected' ) ) { |
||
| 1189 | FrmProAppHelper::selected( $selected, $current ); |
||
| 1190 | } else { |
||
| 1191 | selected( in_array( $current, (array) $selected, true ) ); |
||
| 1192 | } |
||
| 1193 | } |
||
| 1194 | |||
| 1195 | /** |
||
| 1196 | * @param string|array $capability |
||
| 1197 | */ |
||
| 1198 | public static function roles_options( $capability ) { |
||
| 1199 | global $frm_vars; |
||
| 1200 | if ( isset( $frm_vars['editable_roles'] ) ) { |
||
| 1201 | $editable_roles = $frm_vars['editable_roles']; |
||
| 1202 | } else { |
||
| 1203 | $editable_roles = get_editable_roles(); |
||
| 1204 | $frm_vars['editable_roles'] = $editable_roles; |
||
| 1205 | } |
||
| 1206 | |||
| 1207 | foreach ( $editable_roles as $role => $details ) { |
||
| 1208 | $name = translate_user_role( $details['name'] ); |
||
| 1209 | ?> |
||
| 1210 | <option value="<?php echo esc_attr( $role ); ?>" <?php self::selected( $capability, $role ); ?>><?php echo esc_attr( $name ); ?> </option> |
||
| 1211 | <?php |
||
| 1212 | unset( $role, $details ); |
||
| 1213 | } |
||
| 1214 | } |
||
| 1215 | |||
| 1216 | public static function frm_capabilities( $type = 'auto' ) { |
||
| 1237 | |||
| 1238 | /** |
||
| 1239 | * Call the WordPress current_user_can but also validate empty strings as true for any logged in user |
||
| 1240 | * |
||
| 1241 | * @since 4.06.03 |
||
| 1242 | * |
||
| 1243 | * @param string $role |
||
| 1244 | * |
||
| 1245 | * @return bool |
||
| 1246 | */ |
||
| 1247 | public static function current_user_can( $role ) { |
||
| 1248 | if ( $role === '-1' ) { |
||
| 1249 | return false; |
||
| 1250 | } |
||
| 1251 | |||
| 1252 | if ( $role === 'loggedout' ) { |
||
| 1253 | return ! is_user_logged_in(); |
||
| 1254 | } |
||
| 1255 | |||
| 1256 | if ( $role === 'loggedin' || ! $role ) { |
||
| 1257 | return is_user_logged_in(); |
||
| 1258 | } |
||
| 1259 | |||
| 1260 | if ( $role == 1 ) { |
||
| 1261 | $role = 'administrator'; |
||
| 1262 | } |
||
| 1263 | |||
| 1264 | if ( ! is_user_logged_in() ) { |
||
| 1265 | return false; |
||
| 1266 | } |
||
| 1267 | |||
| 1268 | return current_user_can( $role ); |
||
| 1269 | } |
||
| 1270 | |||
| 1271 | /** |
||
| 1272 | * @param string|array $needed_role |
||
| 1273 | * @return bool |
||
| 1274 | */ |
||
| 1275 | public static function user_has_permission( $needed_role ) { |
||
| 1276 | if ( is_array( $needed_role ) ) { |
||
| 1277 | foreach ( $needed_role as $role ) { |
||
| 1278 | if ( self::current_user_can( $role ) ) { |
||
| 1279 | return true; |
||
| 1280 | } |
||
| 1281 | } |
||
| 1282 | |||
| 1283 | return false; |
||
| 1284 | } |
||
| 1285 | |||
| 1286 | $can = self::current_user_can( $needed_role ); |
||
| 1287 | |||
| 1288 | if ( $can || in_array( $needed_role, array( '-1', 'loggedout' ) ) ) { |
||
| 1289 | return $can; |
||
| 1290 | } |
||
| 1291 | |||
| 1292 | $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' ); |
||
| 1293 | foreach ( $roles as $role ) { |
||
| 1294 | if ( current_user_can( $role ) ) { |
||
| 1295 | return true; |
||
| 1296 | } |
||
| 1304 | |||
| 1305 | /** |
||
| 1306 | * Make sure administrators can see Formidable menu |
||
| 1307 | * |
||
| 1308 | * @since 2.0 |
||
| 1309 | */ |
||
| 1310 | public static function maybe_add_permissions() { |
||
| 1325 | |||
| 1326 | /** |
||
| 1327 | * Make sure admins have permission to see the menu items |
||
| 1328 | * |
||
| 1329 | * @since 2.0.6 |
||
| 1330 | */ |
||
| 1331 | public static function force_capability( $cap = 'frm_change_settings' ) { |
||
| 1340 | |||
| 1341 | /** |
||
| 1342 | * Check if the user has permision for action. |
||
| 1343 | * Return permission message and stop the action if no permission |
||
| 1344 | * |
||
| 1345 | * @since 2.0 |
||
| 1346 | * |
||
| 1347 | * @param string $permission |
||
| 1348 | */ |
||
| 1349 | public static function permission_check( $permission, $show_message = 'show' ) { |
||
| 1358 | |||
| 1359 | /** |
||
| 1360 | * Check user permission and nonce |
||
| 1361 | * |
||
| 1362 | * @since 2.0 |
||
| 1363 | * |
||
| 1364 | * @param string $permission |
||
| 1365 | * |
||
| 1366 | * @return false|string The permission message or false if allowed |
||
| 1367 | */ |
||
| 1368 | public static function permission_nonce_error( $permission, $nonce_name = '', $nonce = '' ) { |
||
| 1388 | |||
| 1389 | public static function checked( $values, $current ) { |
||
| 1394 | |||
| 1395 | public static function check_selected( $values, $current ) { |
||
| 1402 | |||
| 1403 | public static function recursive_function_map( $value, $function ) { |
||
| 1426 | |||
| 1427 | public static function is_assoc( $array ) { |
||
| 1430 | |||
| 1431 | /** |
||
| 1432 | * Flatten a multi-dimensional array |
||
| 1433 | */ |
||
| 1434 | public static function array_flatten( $array, $keys = 'keep' ) { |
||
| 1450 | |||
| 1451 | public static function esc_textarea( $text, $is_rich_text = false ) { |
||
| 1460 | |||
| 1461 | /** |
||
| 1462 | * Add auto paragraphs to text areas |
||
| 1463 | * |
||
| 1464 | * @since 2.0 |
||
| 1465 | */ |
||
| 1466 | public static function use_wpautop( $content ) { |
||
| 1473 | |||
| 1474 | public static function replace_quotes( $val ) { |
||
| 1483 | |||
| 1484 | /** |
||
| 1485 | * @since 2.0 |
||
| 1486 | * @return string The base Google APIS url for the current version of jQuery UI |
||
| 1487 | */ |
||
| 1488 | public static function jquery_ui_base_url() { |
||
| 1494 | |||
| 1495 | /** |
||
| 1496 | * @param string $handle |
||
| 1497 | */ |
||
| 1498 | public static function script_version( $handle, $default = 0 ) { |
||
| 1516 | |||
| 1517 | public static function js_redirect( $url ) { |
||
| 1520 | |||
| 1521 | public static function get_user_id_param( $user_id ) { |
||
| 1544 | |||
| 1545 | public static function get_file_contents( $filename, $atts = array() ) { |
||
| 1558 | |||
| 1559 | /** |
||
| 1560 | * @param string $table_name |
||
| 1561 | * @param string $column |
||
| 1562 | * @param int $id |
||
| 1563 | * @param int $num_chars |
||
| 1564 | */ |
||
| 1565 | public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 5 ) { |
||
| 1608 | |||
| 1609 | /** |
||
| 1610 | * Editing a Form or Entry |
||
| 1611 | * |
||
| 1612 | * @param string $table |
||
| 1613 | * |
||
| 1614 | * @return bool|array |
||
| 1615 | */ |
||
| 1616 | public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) { |
||
| 1650 | |||
| 1651 | private static function prepare_field_arrays( $fields, $record, array &$values, $args ) { |
||
| 1663 | |||
| 1664 | private static function fill_field_defaults( $field, $record, array &$values, $args ) { |
||
| 1715 | |||
| 1716 | /** |
||
| 1717 | * @since 3.0 |
||
| 1718 | * |
||
| 1719 | * @param object $field |
||
| 1720 | * |
||
| 1721 | * @return array |
||
| 1722 | */ |
||
| 1723 | public static function start_field_array( $field ) { |
||
| 1736 | |||
| 1737 | /** |
||
| 1738 | * @param string $table |
||
| 1739 | */ |
||
| 1740 | private static function fill_form_opts( $record, $table, $post_values, array &$values ) { |
||
| 1770 | |||
| 1771 | /** |
||
| 1772 | * Set to POST value or default |
||
| 1773 | */ |
||
| 1774 | private static function fill_form_defaults( $post_values, array &$values ) { |
||
| 1796 | |||
| 1797 | /** |
||
| 1798 | * @since 2.2.10 |
||
| 1799 | * |
||
| 1800 | * @param array $post_values |
||
| 1801 | * |
||
| 1802 | * @return boolean|int |
||
| 1803 | */ |
||
| 1804 | public static function custom_style_value( $post_values ) { |
||
| 1814 | |||
| 1815 | public static function truncate( $str, $length, $minword = 3, $continue = '...' ) { |
||
| 1856 | |||
| 1857 | public static function mb_function( $function_names, $args ) { |
||
| 1866 | |||
| 1867 | public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) { |
||
| 1890 | |||
| 1891 | private static function add_time_to_date( $time_format, $date ) { |
||
| 1904 | |||
| 1905 | /** |
||
| 1906 | * @since 2.0.8 |
||
| 1907 | */ |
||
| 1908 | public static function get_localized_date( $date_format, $date ) { |
||
| 1913 | |||
| 1914 | /** |
||
| 1915 | * Gets the time ago in words |
||
| 1916 | * |
||
| 1917 | * @param int $from in seconds |
||
| 1918 | * @param int|string $to in seconds |
||
| 1919 | * |
||
| 1920 | * @return string $time_ago |
||
| 1921 | */ |
||
| 1922 | public static function human_time_diff( $from, $to = '', $levels = 1 ) { |
||
| 1971 | |||
| 1972 | /** |
||
| 1973 | * @since 4.05.01 |
||
| 1974 | */ |
||
| 1975 | private static function time_format( $unit, $diff ) { |
||
| 1998 | |||
| 1999 | /** |
||
| 2000 | * @since 4.05.01 |
||
| 2001 | */ |
||
| 2002 | private static function convert_time( $from, $to ) { |
||
| 2015 | |||
| 2016 | /** |
||
| 2017 | * @since 4.05.01 |
||
| 2018 | */ |
||
| 2019 | private static function get_unit( $unit ) { |
||
| 2032 | |||
| 2033 | /** |
||
| 2034 | * Get the translatable time strings. The untranslated version is a failsafe |
||
| 2035 | * in case langauges are changing for the unit set in the shortcode. |
||
| 2036 | * |
||
| 2037 | * @since 2.0.20 |
||
| 2038 | * @return array |
||
| 2039 | */ |
||
| 2040 | private static function get_time_strings() { |
||
| 2079 | |||
| 2080 | // Pagination Methods. |
||
| 2081 | |||
| 2082 | /** |
||
| 2083 | * @param integer $current_p |
||
| 2084 | */ |
||
| 2085 | public static function get_last_record_num( $r_count, $current_p, $p_size ) { |
||
| 2088 | |||
| 2089 | /** |
||
| 2090 | * @param integer $current_p |
||
| 2091 | */ |
||
| 2092 | public static function get_first_record_num( $r_count, $current_p, $p_size ) { |
||
| 2099 | |||
| 2100 | /** |
||
| 2101 | * @return array |
||
| 2102 | */ |
||
| 2103 | public static function json_to_array( $json_vars ) { |
||
| 2153 | |||
| 2154 | /** |
||
| 2155 | * @param string $name |
||
| 2156 | * @param string $l1 |
||
| 2157 | */ |
||
| 2158 | public static function add_value_to_array( $name, $l1, $val, &$vars ) { |
||
| 2165 | |||
| 2166 | public static function maybe_add_tooltip( $name, $class = 'closed', $form_name = '' ) { |
||
| 2194 | |||
| 2195 | /** |
||
| 2196 | * Add the current_page class to that page in the form nav |
||
| 2197 | */ |
||
| 2198 | public static function select_current_page( $page, $current_page, $action = array() ) { |
||
| 2208 | |||
| 2209 | /** |
||
| 2210 | * Prepare and json_encode post content |
||
| 2211 | * |
||
| 2212 | * @since 2.0 |
||
| 2213 | * |
||
| 2214 | * @param array $post_content |
||
| 2215 | * |
||
| 2216 | * @return string $post_content ( json encoded array ) |
||
| 2217 | */ |
||
| 2218 | public static function prepare_and_encode( $post_content ) { |
||
| 2239 | |||
| 2240 | private static function prepare_action_slashes( $val, $key, &$post_content ) { |
||
| 2258 | |||
| 2259 | /** |
||
| 2260 | * Check for either json or serilized data. This is temporary while transitioning |
||
| 2261 | * all data to json. |
||
| 2262 | * |
||
| 2263 | * @since 4.02.03 |
||
| 2264 | */ |
||
| 2265 | public static function unserialize_or_decode( &$value ) { |
||
| 2276 | |||
| 2277 | /** |
||
| 2278 | * Decode a JSON string. |
||
| 2279 | * Do not switch shortcodes like [24] to array unless intentional ie XML values. |
||
| 2280 | */ |
||
| 2281 | public static function maybe_json_decode( $string, $single_to_array = true ) { |
||
| 2300 | |||
| 2301 | /** |
||
| 2302 | * Reformat the json serialized array in name => value array. |
||
| 2303 | * |
||
| 2304 | * @since 4.02.03 |
||
| 2305 | */ |
||
| 2306 | public static function format_form_data( &$form ) { |
||
| 2327 | |||
| 2328 | /** |
||
| 2329 | * @since 4.02.03 |
||
| 2330 | */ |
||
| 2331 | public static function maybe_json_encode( $value ) { |
||
| 2337 | |||
| 2338 | /** |
||
| 2339 | * @since 1.07.10 |
||
| 2340 | * |
||
| 2341 | * @param string $post_type The name of the post type that may need to be highlighted |
||
| 2342 | * echo The javascript to open and highlight the Formidable menu |
||
| 2343 | */ |
||
| 2344 | public static function maybe_highlight_menu( $post_type ) { |
||
| 2358 | |||
| 2359 | /** |
||
| 2360 | * Load the JS file on non-Formidable pages in the admin area |
||
| 2361 | * |
||
| 2362 | * @since 2.0 |
||
| 2363 | */ |
||
| 2364 | public static function load_admin_wide_js( $load = true ) { |
||
| 2382 | |||
| 2383 | /** |
||
| 2384 | * @since 2.0.9 |
||
| 2385 | */ |
||
| 2386 | public static function load_font_style() { |
||
| 2389 | |||
| 2390 | /** |
||
| 2391 | * @param string $location |
||
| 2392 | */ |
||
| 2393 | public static function localize_script( $location ) { |
||
| 2479 | |||
| 2480 | /** |
||
| 2481 | * Echo the message on the plugins listing page |
||
| 2482 | * |
||
| 2483 | * @since 1.07.10 |
||
| 2484 | * |
||
| 2485 | * @param float $min_version The version the add-on requires |
||
| 2486 | */ |
||
| 2487 | public static function min_version_notice( $min_version ) { |
||
| 2500 | |||
| 2501 | /** |
||
| 2502 | * If Pro is far outdated, show a message. |
||
| 2503 | * |
||
| 2504 | * @since 4.0.01 |
||
| 2505 | */ |
||
| 2506 | public static function min_pro_version_notice( $min_version ) { |
||
| 2534 | |||
| 2535 | /** |
||
| 2536 | * If Pro is installed, check the version number. |
||
| 2537 | * |
||
| 2538 | * @since 4.0.01 |
||
| 2539 | */ |
||
| 2540 | public static function meets_min_pro_version( $min_version ) { |
||
| 2543 | |||
| 2544 | /** |
||
| 2545 | * Show a message if the browser or PHP version is below the recommendations. |
||
| 2546 | * |
||
| 2547 | * @since 4.0.02 |
||
| 2548 | */ |
||
| 2549 | private static function php_version_notice() { |
||
| 2569 | |||
| 2570 | public static function locales( $type = 'date' ) { |
||
| 2650 | |||
| 2651 | /** |
||
| 2652 | * Use the WP 4.7 wp_doing_ajax function |
||
| 2653 | * |
||
| 2654 | * @since 2.05.07 |
||
| 2655 | * @deprecated 4.04.04 |
||
| 2656 | */ |
||
| 2657 | public static function wp_doing_ajax() { |
||
| 2661 | |||
| 2662 | /** |
||
| 2663 | * @deprecated 4.0 |
||
| 2664 | */ |
||
| 2665 | public static function insert_opt_html( $args ) { |
||
| 2669 | |||
| 2670 | /** |
||
| 2671 | * Used to filter shortcode in text widgets |
||
| 2672 | * |
||
| 2673 | * @deprecated 2.5.4 |
||
| 2674 | * @codeCoverageIgnore |
||
| 2675 | */ |
||
| 2676 | public static function widget_text_filter_callback( $matches ) { |
||
| 2679 | |||
| 2680 | /** |
||
| 2681 | * @deprecated 3.01 |
||
| 2682 | * @codeCoverageIgnore |
||
| 2683 | */ |
||
| 2684 | public static function sanitize_array( &$values ) { |
||
| 2687 | |||
| 2688 | /** |
||
| 2689 | * @param array $settings |
||
| 2690 | * @param string $group |
||
| 2691 | * |
||
| 2692 | * @since 2.0.6 |
||
| 2693 | * @deprecated 2.05.06 |
||
| 2694 | * @codeCoverageIgnore |
||
| 2695 | */ |
||
| 2696 | public static function save_settings( $settings, $group ) { |
||
| 2699 | |||
| 2700 | /** |
||
| 2701 | * @since 2.0.4 |
||
| 2702 | * @deprecated 2.05.06 |
||
| 2703 | * @codeCoverageIgnore |
||
| 2704 | */ |
||
| 2705 | public static function save_json_post( $settings ) { |
||
| 2708 | |||
| 2709 | /** |
||
| 2710 | * @since 2.0 |
||
| 2711 | * @deprecated 2.05.06 |
||
| 2712 | * @codeCoverageIgnore |
||
| 2713 | * |
||
| 2714 | * @param string $cache_key The unique name for this cache |
||
| 2715 | * @param string $group The name of the cache group |
||
| 2716 | * @param string $query If blank, don't run a db call |
||
| 2717 | * @param string $type The wpdb function to use with this query |
||
| 2718 | * |
||
| 2719 | * @return mixed $results The cache or query results |
||
| 2720 | */ |
||
| 2721 | public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) { |
||
| 2724 | |||
| 2725 | /** |
||
| 2726 | * @deprecated 2.05.06 |
||
| 2727 | * @codeCoverageIgnore |
||
| 2728 | */ |
||
| 2729 | public static function set_cache( $cache_key, $results, $group = '', $time = 300 ) { |
||
| 2732 | |||
| 2733 | /** |
||
| 2734 | * @deprecated 2.05.06 |
||
| 2735 | * @codeCoverageIgnore |
||
| 2736 | */ |
||
| 2737 | public static function add_key_to_group_cache( $key, $group ) { |
||
| 2740 | |||
| 2741 | /** |
||
| 2742 | * @deprecated 2.05.06 |
||
| 2743 | * @codeCoverageIgnore |
||
| 2744 | */ |
||
| 2745 | public static function get_group_cached_keys( $group ) { |
||
| 2748 | |||
| 2749 | /** |
||
| 2750 | * @since 2.0 |
||
| 2751 | * @deprecated 2.05.06 |
||
| 2752 | * @codeCoverageIgnore |
||
| 2753 | * @return mixed The cached value or false |
||
| 2754 | */ |
||
| 2755 | public static function check_cache_and_transient( $cache_key ) { |
||
| 2758 | |||
| 2759 | /** |
||
| 2760 | * @since 2.0 |
||
| 2761 | * @deprecated 2.05.06 |
||
| 2762 | * @codeCoverageIgnore |
||
| 2763 | * |
||
| 2764 | * @param string $cache_key |
||
| 2765 | */ |
||
| 2766 | public static function delete_cache_and_transient( $cache_key, $group = 'default' ) { |
||
| 2769 | |||
| 2770 | /** |
||
| 2771 | * @since 2.0 |
||
| 2772 | * @deprecated 2.05.06 |
||
| 2773 | * @codeCoverageIgnore |
||
| 2774 | * |
||
| 2775 | * @param string $group The name of the cache group |
||
| 2776 | */ |
||
| 2777 | public static function cache_delete_group( $group ) { |
||
| 2780 | |||
| 2781 | /** |
||
| 2782 | * @since 1.07.10 |
||
| 2783 | * @deprecated 2.05.06 |
||
| 2784 | * @codeCoverageIgnore |
||
| 2785 | * |
||
| 2786 | * @param string $term The value to escape |
||
| 2787 | * |
||
| 2788 | * @return string The escaped value |
||
| 2789 | */ |
||
| 2790 | public static function esc_like( $term ) { |
||
| 2793 | |||
| 2794 | /** |
||
| 2795 | * @param string $order_query |
||
| 2796 | * |
||
| 2797 | * @deprecated 2.05.06 |
||
| 2798 | * @codeCoverageIgnore |
||
| 2799 | */ |
||
| 2800 | public static function esc_order( $order_query ) { |
||
| 2803 | |||
| 2804 | /** |
||
| 2805 | * @deprecated 2.05.06 |
||
| 2806 | * @codeCoverageIgnore |
||
| 2807 | */ |
||
| 2808 | public static function esc_order_by( &$order_by ) { |
||
| 2811 | |||
| 2812 | /** |
||
| 2813 | * @param string $limit |
||
| 2814 | * |
||
| 2815 | * @deprecated 2.05.06 |
||
| 2816 | * @codeCoverageIgnore |
||
| 2817 | */ |
||
| 2818 | public static function esc_limit( $limit ) { |
||
| 2821 | |||
| 2822 | /** |
||
| 2823 | * @since 2.0 |
||
| 2824 | * @deprecated 2.05.06 |
||
| 2825 | * @codeCoverageIgnore |
||
| 2826 | */ |
||
| 2827 | public static function prepare_array_values( $array, $type = '%s' ) { |
||
| 2830 | |||
| 2831 | /** |
||
| 2832 | * @deprecated 2.05.06 |
||
| 2833 | * @codeCoverageIgnore |
||
| 2834 | */ |
||
| 2835 | public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) { |
||
| 2838 | } |
||
| 2839 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.