| @@ -15,33 +15,20 @@ | ||
| 15 | 15 | private static $field_type_data_for_insert_opt_html; |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * @since 2.2.10 |
| 19 | - * | |
| 20 | - * @return string | |
| 21 | 19 | */ |
| 22 | 20 | public static function form_error_class() { |
| 23 | 21 | return apply_filters( 'frm_form_error_class', 'frm_error_style' ); |
| 24 | 22 | } |
| 25 | 23 | |
| 26 | - /** | |
| 27 | - * @param string $key | |
| 28 | - * @param false|object $form | |
| 29 | - * | |
| 30 | - * @return string | |
| 31 | - */ | |
| 32 | 24 | public static function get_direct_link( $key, $form = false ) { |
| 33 | 25 | $target_url = esc_url( admin_url( 'admin-ajax.php?action=frm_forms_preview&form=' . $key ) ); |
| 34 | - return apply_filters( 'frm_direct_link', $target_url, $key, $form ); | |
| 26 | + $target_url = apply_filters( 'frm_direct_link', $target_url, $key, $form ); | |
| 27 | + | |
| 28 | + return $target_url; | |
| 35 | 29 | } |
| 36 | 30 | |
| 37 | - /** | |
| 38 | - * @param string $field_name | |
| 39 | - * @param int|string $field_value | |
| 40 | - * @param array $args | |
| 41 | - * | |
| 42 | - * @return void | |
| 43 | - */ | |
| 44 | 31 | public static function forms_dropdown( $field_name, $field_value = '', $args = array() ) { |
| 45 | 32 | $defaults = array( |
| 46 | 33 | 'blank' => true, |
| 47 | 34 | 'field_id' => false, |
| @@ -56,9 +43,8 @@ | ||
| 56 | 43 | $args['field_id'] = $field_name; |
| 57 | 44 | } |
| 58 | 45 | |
| 59 | 46 | $query = array(); |
| 60 | - | |
| 61 | 47 | if ( $args['exclude'] ) { |
| 62 | 48 | $query['id !'] = $args['exclude']; |
| 63 | 49 | } |
| 64 | 50 | |
| @@ -67,47 +53,40 @@ | ||
| 67 | 53 | $add_html = array(); |
| 68 | 54 | self::add_html_attr( $args['onchange'], 'onchange', $add_html ); |
| 69 | 55 | self::add_html_attr( $args['class'], 'class', $add_html ); |
| 70 | 56 | |
| 71 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 72 | 57 | ?> |
| 73 | 58 | <select name="<?php echo esc_attr( $field_name ); ?>" |
| 74 | 59 | id="<?php echo esc_attr( $args['field_id'] ); ?>" |
| 75 | 60 | <?php echo wp_strip_all_tags( implode( ' ', $add_html ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> |
| 76 | 61 | <?php if ( $args['blank'] ) { ?> |
| 77 | - <option value=""><?php echo $args['blank'] == 1 ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; // phpcs:ignore Universal.Operators.StrictComparisons ?></option> | |
| 62 | + <option value=""><?php echo $args['blank'] == 1 ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; ?></option> | |
| 78 | 63 | <?php } ?> |
| 79 | 64 | <?php foreach ( $forms as $form ) { ?> |
| 80 | 65 | <option value="<?php echo esc_attr( $form->id ); ?>" <?php selected( $field_value, $form->id ); ?>> |
| 81 | - <?php echo esc_html( '' === $form->name ? self::get_no_title_text() : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?> | |
| 66 | + <?php echo esc_html( '' === $form->name ? self::get_no_title_text() : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); ?> | |
| 82 | 67 | </option> |
| 83 | 68 | <?php } ?> |
| 84 | 69 | </select> |
| 85 | 70 | <?php |
| 86 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 87 | 71 | } |
| 88 | 72 | |
| 89 | 73 | /** |
| 90 | 74 | * @since 2.0.6 |
| 91 | - * | |
| 92 | 75 | * @param string $class |
| 93 | 76 | * @param string $param |
| 94 | 77 | * @param array $add_html |
| 95 | - * | |
| 96 | - * @return void | |
| 97 | 78 | */ |
| 98 | 79 | public static function add_html_attr( $class, $param, &$add_html ) { |
| 99 | - if ( $class ) { | |
| 100 | - $add_html[ $param ] = sanitize_title( $param ) . '="' . esc_attr( sanitize_text_field( $class ) ) . '"'; | |
| 80 | + if ( ! empty( $class ) ) { | |
| 81 | + $add_html[ $param ] = sanitize_title( $param ) . '="' . esc_attr( trim( sanitize_text_field( $class ) ) ) . '"'; | |
| 101 | 82 | } |
| 102 | 83 | } |
| 103 | 84 | |
| 104 | 85 | /** |
| 105 | 86 | * @param false|object|string $selected - The label for the placeholder, or the form object. |
| 106 | - * | |
| 107 | - * @return void | |
| 108 | 87 | */ |
| 109 | - public static function form_switcher( $selected = false ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh, Generic.Metrics.CyclomaticComplexity.MaxExceeded, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 88 | + public static function form_switcher( $selected = false ) { | |
| 110 | 89 | $where = apply_filters( 'frm_forms_dropdown', array(), '' ); |
| 111 | 90 | $forms = FrmForm::get_published_forms( $where ); |
| 112 | 91 | |
| 113 | 92 | $args = array( |
| @@ -113,9 +92,8 @@ | ||
| 113 | 92 | $args = array( |
| 114 | 93 | 'id' => 0, |
| 115 | 94 | 'form' => 0, |
| 116 | 95 | ); |
| 117 | - | |
| 118 | 96 | if ( isset( $_GET['id'] ) && ! isset( $_GET['form'] ) ) { |
| 119 | 97 | unset( $args['form'] ); |
| 120 | 98 | } elseif ( isset( $_GET['form'] ) && ! isset( $_GET['id'] ) ) { |
| 121 | 99 | unset( $args['id'] ); |
| @@ -121,9 +99,8 @@ | ||
| 121 | 99 | unset( $args['id'] ); |
| 122 | 100 | } |
| 123 | 101 | |
| 124 | 102 | $frm_action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
| 125 | - | |
| 126 | 103 | if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $frm_action, array( 'edit', 'show', 'destroy', 'destroy_all' ), true ) ) { |
| 127 | 104 | $args['frm_action'] = 'list'; |
| 128 | 105 | $args['form'] = 0; |
| 129 | 106 | } elseif ( FrmAppHelper::is_admin_page( 'formidable' ) && in_array( $frm_action, array( 'new', 'duplicate' ), true ) ) { |
| @@ -133,21 +110,18 @@ | ||
| 133 | 110 | unset( $args['id'] ); |
| 134 | 111 | $query_args = array( |
| 135 | 112 | 'page' => 'formidable-styles', |
| 136 | 113 | ); |
| 137 | - | |
| 138 | 114 | if ( $frm_action ) { |
| 139 | 115 | $query_args['frm_action'] = $frm_action; |
| 140 | 116 | } |
| 141 | - | |
| 142 | 117 | $base = add_query_arg( $query_args, admin_url( 'admin.php' ) ); |
| 143 | 118 | } elseif ( isset( $_GET['post'] ) ) { |
| 144 | 119 | $args['form'] = 0; |
| 145 | 120 | $base = admin_url( 'edit.php?post_type=frm_display' ); |
| 146 | - }//end if | |
| 121 | + } | |
| 147 | 122 | |
| 148 | 123 | $form_id = 0; |
| 149 | - | |
| 150 | 124 | if ( is_object( $selected ) ) { |
| 151 | 125 | $form_id = $selected->id; |
| 152 | 126 | $selected = $selected->name; |
| 153 | 127 | } |
| @@ -155,9 +129,8 @@ | ||
| 155 | 129 | $name = $selected === false ? __( 'Switch Form', 'formidable' ) : $selected; |
| 156 | 130 | $name = '' === $name || is_null( $name ) ? self::get_no_title_text() : strip_tags( $name ); |
| 157 | 131 | $truncated_name = FrmAppHelper::truncate( $name, 25 ); |
| 158 | 132 | |
| 159 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 160 | 133 | if ( count( $forms ) < 2 ) { |
| 161 | 134 | ?> |
| 162 | 135 | <div id="frm_bs_dropdown"> |
| 163 | 136 | <h1> |
| @@ -204,15 +177,14 @@ | ||
| 204 | 177 | |
| 205 | 178 | if ( isset( $args['id'] ) ) { |
| 206 | 179 | $args['id'] = $form->id; |
| 207 | 180 | } |
| 208 | - | |
| 209 | 181 | if ( isset( $args['form'] ) ) { |
| 210 | 182 | $args['form'] = $form->id; |
| 211 | 183 | } |
| 212 | 184 | |
| 213 | 185 | $url = isset( $base ) ? add_query_arg( $args, $base ) : add_query_arg( $args ); |
| 214 | - $form_name = ! empty( $form->name ) ? $form->name : self::get_no_title_text(); | |
| 186 | + $form_name = empty( $form->name ) ? self::get_no_title_text() : $form->name; | |
| 215 | 187 | ?> |
| 216 | 188 | <li class="frm-dropdown-form"> |
| 217 | 189 | <a href="<?php echo esc_url( $url ); ?>" tabindex="-1" class="frm-justify-between"> |
| 218 | 190 | <?php echo esc_html( $form_name ); ?> |
| @@ -234,21 +206,13 @@ | ||
| 234 | 206 | ?> |
| 235 | 207 | </ul> |
| 236 | 208 | </div> |
| 237 | 209 | <?php |
| 238 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 239 | 210 | } |
| 240 | 211 | |
| 241 | - /** | |
| 242 | - * @param string $col | |
| 243 | - * @param string $sort_col | |
| 244 | - * @param string $sort_dir | |
| 245 | - * | |
| 246 | - * @return void | |
| 247 | - */ | |
| 248 | 212 | public static function get_sortable_classes( $col, $sort_col, $sort_dir ) { |
| 249 | - echo $sort_col == $col ? 'sorted' : 'sortable'; // phpcs:ignore Universal.Operators.StrictComparisons | |
| 250 | - echo $sort_col == $col && $sort_dir === 'desc' ? ' asc' : ' desc'; // phpcs:ignore Universal.Operators.StrictComparisons | |
| 213 | + echo $sort_col == $col ? 'sorted' : 'sortable'; | |
| 214 | + echo $sort_col == $col && $sort_dir === 'desc' ? ' asc' : ' desc'; | |
| 251 | 215 | } |
| 252 | 216 | |
| 253 | 217 | /** |
| 254 | 218 | * @since 3.0 |
| @@ -253,13 +217,18 @@ | ||
| 253 | 217 | /** |
| 254 | 218 | * @since 3.0 |
| 255 | 219 | * |
| 256 | 220 | * @param array|string $field_type |
| 257 | - * | |
| 258 | 221 | * @return string |
| 259 | 222 | */ |
| 260 | 223 | public static function get_field_link_name( $field_type ) { |
| 261 | - return is_array( $field_type ) ? $field_type['name'] : $field_type; | |
| 224 | + if ( is_array( $field_type ) ) { | |
| 225 | + $field_label = $field_type['name']; | |
| 226 | + } else { | |
| 227 | + $field_label = $field_type; | |
| 228 | + } | |
| 229 | + | |
| 230 | + return $field_label; | |
| 262 | 231 | } |
| 263 | 232 | |
| 264 | 233 | /** |
| 265 | 234 | * @since 3.0 |
| @@ -264,13 +233,18 @@ | ||
| 264 | 233 | /** |
| 265 | 234 | * @since 3.0 |
| 266 | 235 | * |
| 267 | 236 | * @param array|string $field_type |
| 268 | - * | |
| 269 | 237 | * @return string |
| 270 | 238 | */ |
| 271 | 239 | public static function get_field_link_icon( $field_type ) { |
| 272 | - return is_array( $field_type ) && isset( $field_type['icon'] ) ? $field_type['icon'] : 'frmfont frm_pencil_icon'; | |
| 240 | + if ( is_array( $field_type ) && isset( $field_type['icon'] ) ) { | |
| 241 | + $icon = $field_type['icon']; | |
| 242 | + } else { | |
| 243 | + $icon = 'frm_icon_font frm_pencil_icon'; | |
| 244 | + } | |
| 245 | + | |
| 246 | + return $icon; | |
| 273 | 247 | } |
| 274 | 248 | |
| 275 | 249 | /** |
| 276 | 250 | * Get the invalid form error message |
| @@ -282,9 +256,8 @@ | ||
| 282 | 256 | * @return string |
| 283 | 257 | */ |
| 284 | 258 | public static function get_invalid_error_message( $args ) { |
| 285 | 259 | $settings_args = $args; |
| 286 | - | |
| 287 | 260 | if ( isset( $args['form'] ) ) { |
| 288 | 261 | $settings_args['current_form'] = $args['form']->id; |
| 289 | 262 | } |
| 290 | 263 | |
| @@ -301,48 +274,24 @@ | ||
| 301 | 274 | * @type stdClass $form |
| 302 | 275 | * @type int $entry_id |
| 303 | 276 | * @type string $class |
| 304 | 277 | * } |
| 305 | - * | |
| 306 | 278 | * @return string |
| 307 | 279 | */ |
| 308 | 280 | public static function get_success_message( $atts ) { |
| 309 | 281 | $message = apply_filters( 'frm_content', $atts['message'], $atts['form'], $atts['entry_id'] ); |
| 310 | - | |
| 311 | - // Only autop if the message includes line breaks. | |
| 312 | - $autop = str_contains( $message, "\n" ); | |
| 313 | - | |
| 314 | - /** | |
| 315 | - * Filters whether to autop the success message. | |
| 316 | - * This is false by default if the message does not include line breaks. | |
| 317 | - * | |
| 318 | - * @since 6.23 | |
| 319 | - * | |
| 320 | - * @param bool $autop | |
| 321 | - * @param string $message | |
| 322 | - * @param object $form | |
| 323 | - */ | |
| 324 | - $autop = (bool) apply_filters( 'frm_wpautop_success_message', $autop, $message, $atts['form'] ); | |
| 325 | - | |
| 326 | - if ( $autop ) { | |
| 327 | - $message = FrmAppHelper::use_wpautop( $message ); | |
| 328 | - } | |
| 329 | - | |
| 330 | - $message = do_shortcode( $message ); | |
| 331 | - return '<div class="' . esc_attr( $atts['class'] ) . '" role="status">' . $message . '</div>'; | |
| 282 | + $message = do_shortcode( FrmAppHelper::use_wpautop( $message ) ); | |
| 283 | + $message = '<div class="' . esc_attr( $atts['class'] ) . '" role="status">' . $message . '</div>'; | |
| 284 | + return $message; | |
| 332 | 285 | } |
| 333 | 286 | |
| 334 | 287 | /** |
| 335 | 288 | * Used when a form is created |
| 336 | - * | |
| 337 | - * @param array $values | |
| 338 | - * | |
| 339 | - * @return array | |
| 340 | 289 | */ |
| 341 | 290 | public static function setup_new_vars( $values = array() ) { |
| 342 | 291 | global $wpdb; |
| 343 | 292 | |
| 344 | - if ( $values ) { | |
| 293 | + if ( ! empty( $values ) ) { | |
| 345 | 294 | $post_values = $values; |
| 346 | 295 | } else { |
| 347 | 296 | $values = array(); |
| 348 | 297 | $post_values = ! empty( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| @@ -351,9 +300,8 @@ | ||
| 351 | 300 | $defaults = array( |
| 352 | 301 | 'name' => '', |
| 353 | 302 | 'description' => '', |
| 354 | 303 | ); |
| 355 | - | |
| 356 | 304 | foreach ( $defaults as $var => $default ) { |
| 357 | 305 | if ( ! isset( $values[ $var ] ) ) { |
| 358 | 306 | $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
| 359 | 307 | } |
| @@ -368,9 +316,8 @@ | ||
| 368 | 316 | 'is_template' => 0, |
| 369 | 317 | 'status' => 'published', |
| 370 | 318 | 'parent_form_id' => 0, |
| 371 | 319 | ); |
| 372 | - | |
| 373 | 320 | foreach ( $defaults as $var => $default ) { |
| 374 | 321 | if ( ! isset( $values[ $var ] ) ) { |
| 375 | 322 | $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
| 376 | 323 | } |
| @@ -377,9 +324,9 @@ | ||
| 377 | 324 | } |
| 378 | 325 | unset( $defaults ); |
| 379 | 326 | |
| 380 | 327 | if ( ! isset( $values['form_key'] ) ) { |
| 381 | - $values['form_key'] = $post_values && isset( $post_values['form_key'] ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 328 | + $values['form_key'] = $post_values && isset( $post_values['form_key'] ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' ); | |
| 382 | 329 | } |
| 383 | 330 | |
| 384 | 331 | $values = self::fill_default_opts( $values, false, $post_values ); |
| 385 | 332 | $values['custom_style'] = FrmAppHelper::custom_style_value( $post_values ); |
| @@ -388,22 +335,16 @@ | ||
| 388 | 335 | } |
| 389 | 336 | |
| 390 | 337 | /** |
| 391 | 338 | * Used when editing a form |
| 392 | - * | |
| 393 | - * @param array $values | |
| 394 | - * @param object $record | |
| 395 | - * @param array $post_values | |
| 396 | - * | |
| 397 | - * @return array | |
| 398 | 339 | */ |
| 399 | 340 | public static function setup_edit_vars( $values, $record, $post_values = array() ) { |
| 400 | - if ( ! $post_values ) { | |
| 341 | + if ( empty( $post_values ) ) { | |
| 401 | 342 | $post_values = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 402 | 343 | } |
| 403 | 344 | |
| 404 | - $values['form_key'] = $post_values['form_key'] ?? $record->form_key; | |
| 405 | - $values['is_template'] = $post_values['is_template'] ?? $record->is_template; | |
| 345 | + $values['form_key'] = isset( $post_values['form_key'] ) ? $post_values['form_key'] : $record->form_key; | |
| 346 | + $values['is_template'] = isset( $post_values['is_template'] ) ? $post_values['is_template'] : $record->is_template; | |
| 406 | 347 | $values['status'] = $record->status; |
| 407 | 348 | |
| 408 | 349 | $values = self::fill_default_opts( $values, $record, $post_values ); |
| 409 | 350 | |
| @@ -409,18 +350,12 @@ | ||
| 409 | 350 | |
| 410 | 351 | return apply_filters( 'frm_setup_edit_form_vars', $values ); |
| 411 | 352 | } |
| 412 | 353 | |
| 413 | - /** | |
| 414 | - * @param array $values | |
| 415 | - * @param false|object $record | |
| 416 | - * @param array|false $post_values | |
| 417 | - * | |
| 418 | - * @return array | |
| 419 | - */ | |
| 420 | - public static function fill_default_opts( $values, $record, $post_values ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh | |
| 354 | + public static function fill_default_opts( $values, $record, $post_values ) { | |
| 421 | 355 | |
| 422 | - foreach ( self::get_default_opts() as $var => $default ) { | |
| 356 | + $defaults = self::get_default_opts(); | |
| 357 | + foreach ( $defaults as $var => $default ) { | |
| 423 | 358 | if ( is_array( $default ) ) { |
| 424 | 359 | if ( ! isset( $values[ $var ] ) ) { |
| 425 | 360 | $values[ $var ] = $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : array(); |
| 426 | 361 | } |
| @@ -425,13 +360,13 @@ | ||
| 425 | 360 | $values[ $var ] = $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : array(); |
| 426 | 361 | } |
| 427 | 362 | |
| 428 | 363 | foreach ( $default as $k => $v ) { |
| 429 | - $values[ $var ][ $k ] = $post_values && isset( $post_values[ $var ][ $k ] ) ? $post_values[ $var ][ $k ] : ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) ? $record->options[ $var ][ $k ] : $v ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 364 | + $values[ $var ][ $k ] = $post_values && isset( $post_values[ $var ][ $k ] ) ? $post_values[ $var ][ $k ] : ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) ? $record->options[ $var ][ $k ] : $v ); | |
| 430 | 365 | |
| 431 | 366 | if ( is_array( $v ) ) { |
| 432 | 367 | foreach ( $v as $k1 => $v1 ) { |
| 433 | - $values[ $var ][ $k ][ $k1 ] = $post_values && isset( $post_values[ $var ][ $k ][ $k1 ] ) ? $post_values[ $var ][ $k ][ $k1 ] : ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) && isset( $record->options[ $var ][ $k ][ $k1 ] ) ? $record->options[ $var ][ $k ][ $k1 ] : $v1 ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 368 | + $values[ $var ][ $k ][ $k1 ] = $post_values && isset( $post_values[ $var ][ $k ][ $k1 ] ) ? $post_values[ $var ][ $k ][ $k1 ] : ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) && isset( $record->options[ $var ][ $k ][ $k1 ] ) ? $record->options[ $var ][ $k ][ $k1 ] : $v1 ); | |
| 434 | 369 | unset( $k1, $v1 ); |
| 435 | 370 | } |
| 436 | 371 | } |
| 437 | 372 | |
| @@ -437,9 +372,9 @@ | ||
| 437 | 372 | |
| 438 | 373 | unset( $k, $v ); |
| 439 | 374 | } |
| 440 | 375 | } else { |
| 441 | - $values[ $var ] = $post_values && isset( $post_values['options'][ $var ] ) ? $post_values['options'][ $var ] : ( $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : $default ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 376 | + $values[ $var ] = $post_values && isset( $post_values['options'][ $var ] ) ? $post_values['options'][ $var ] : ( $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : $default ); | |
| 442 | 377 | } |
| 443 | 378 | |
| 444 | 379 | unset( $var, $default ); |
| 445 | 380 | }//end foreach |
| @@ -476,17 +411,15 @@ | ||
| 476 | 411 | } |
| 477 | 412 | |
| 478 | 413 | /** |
| 479 | 414 | * @since 2.0.6 |
| 480 | - * | |
| 481 | 415 | * @param array $options |
| 482 | 416 | * @param array $values |
| 483 | - * | |
| 484 | - * @return void | |
| 485 | 417 | */ |
| 486 | 418 | public static function fill_form_options( &$options, $values ) { |
| 487 | - foreach ( self::get_default_opts() as $var => $default ) { | |
| 488 | - $options[ $var ] = $values['options'][ $var ] ?? $default; | |
| 419 | + $defaults = self::get_default_opts(); | |
| 420 | + foreach ( $defaults as $var => $default ) { | |
| 421 | + $options[ $var ] = isset( $values['options'][ $var ] ) ? $values['options'][ $var ] : $default; | |
| 489 | 422 | unset( $var, $default ); |
| 490 | 423 | } |
| 491 | 424 | } |
| 492 | 425 | |
| @@ -491,10 +424,8 @@ | ||
| 491 | 424 | } |
| 492 | 425 | |
| 493 | 426 | /** |
| 494 | 427 | * @param string $loc |
| 495 | - * | |
| 496 | - * @return string | |
| 497 | 428 | */ |
| 498 | 429 | public static function get_default_html( $loc ) { |
| 499 | 430 | if ( $loc === 'submit' ) { |
| 500 | 431 | $draft_link = self::get_draft_link(); |
| @@ -519,13 +450,12 @@ | ||
| 519 | 450 | |
| 520 | 451 | return $default_html; |
| 521 | 452 | } |
| 522 | 453 | |
| 523 | - /** | |
| 524 | - * @return string | |
| 525 | - */ | |
| 526 | 454 | public static function get_draft_link() { |
| 527 | - return '[if save_draft]<button class="frm_save_draft" [draft_hook]>[draft_label]</button>[/if save_draft]'; | |
| 455 | + $link = '[if save_draft]<button class="frm_save_draft" [draft_hook]>[draft_label]</button>[/if save_draft]'; | |
| 456 | + | |
| 457 | + return $link; | |
| 528 | 458 | } |
| 529 | 459 | |
| 530 | 460 | /** |
| 531 | 461 | * Gets start over button shortcode. |
| @@ -537,21 +467,11 @@ | ||
| 537 | 467 | public static function get_start_over_shortcode() { |
| 538 | 468 | return '[if start_over]<a href="#" tabindex="0" class="frm_start_over" [start_over_hook]>[start_over_label]</a>[/if start_over]'; |
| 539 | 469 | } |
| 540 | 470 | |
| 541 | - /** | |
| 542 | - * @param string $html | |
| 543 | - * @param object $form | |
| 544 | - * @param string $submit | |
| 545 | - * @param object|null $form_action | |
| 546 | - * @param array $values | |
| 547 | - * | |
| 548 | - * @return void | |
| 549 | - */ | |
| 550 | 471 | public static function get_custom_submit( $html, $form, $submit, $form_action, $values ) { |
| 551 | 472 | $button = self::replace_shortcodes( $html, $form, $submit, $form_action, $values ); |
| 552 | - | |
| 553 | - if ( ! str_contains( $button, '[button_action]' ) ) { | |
| 473 | + if ( ! strpos( $button, '[button_action]' ) ) { | |
| 554 | 474 | echo FrmAppHelper::maybe_kses( $button ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 555 | 475 | return; |
| 556 | 476 | } |
| 557 | 477 | |
| @@ -558,20 +478,17 @@ | ||
| 558 | 478 | /** |
| 559 | 479 | * @since 5.0.06 |
| 560 | 480 | */ |
| 561 | 481 | $button = apply_filters( 'frm_submit_button_html', $button, compact( 'form' ) ); |
| 562 | - | |
| 563 | 482 | if ( FrmAppHelper::should_never_allow_unfiltered_html() ) { |
| 564 | 483 | $button = FrmAppHelper::kses_submit_button( $button ); |
| 565 | 484 | } |
| 566 | - | |
| 567 | 485 | $button_parts = explode( '[button_action]', $button ); |
| 568 | - $classes = apply_filters( 'frm_submit_button_class', array(), $form ); | |
| 569 | 486 | |
| 570 | - if ( $classes ) { | |
| 487 | + $classes = apply_filters( 'frm_submit_button_class', array(), $form ); | |
| 488 | + if ( ! empty( $classes ) ) { | |
| 571 | 489 | $classes = implode( ' ', $classes ); |
| 572 | 490 | $button_class = 'frm_button_submit'; |
| 573 | - | |
| 574 | 491 | if ( preg_match( '/\bclass="[^"]*?\b' . preg_quote( $button_class, '/' ) . '\b[^"]*?"/', $button_parts[0] ) ) { |
| 575 | 492 | $button_parts[0] = str_replace( $button_class, $button_class . ' ' . esc_attr( $classes ), $button_parts[0] ); |
| 576 | 493 | } else { |
| 577 | 494 | $button_parts[0] .= ' class="' . esc_attr( $classes ) . '"'; |
| @@ -584,10 +501,8 @@ | ||
| 584 | 501 | } |
| 585 | 502 | |
| 586 | 503 | /** |
| 587 | 504 | * @since 4.0 |
| 588 | - * | |
| 589 | - * @return array | |
| 590 | 505 | */ |
| 591 | 506 | public static function html_shortcodes() { |
| 592 | 507 | $codes = array( |
| 593 | 508 | 'id' => array( |
| @@ -674,15 +589,14 @@ | ||
| 674 | 589 | /** |
| 675 | 590 | * @since 4.0 |
| 676 | 591 | * |
| 677 | 592 | * @param array $args |
| 678 | - * | |
| 679 | 593 | * @return void |
| 680 | 594 | */ |
| 681 | 595 | public static function insert_opt_html( $args ) { |
| 682 | - $class = $args['class'] ?? ''; | |
| 596 | + $class = isset( $args['class'] ) ? $args['class'] : ''; | |
| 683 | 597 | $fields = self::get_field_type_data_for_insert_opt_html(); |
| 684 | - $field = $fields[ $args['type'] ] ?? array(); | |
| 598 | + $field = isset( $fields[ $args['type'] ] ) ? $fields[ $args['type'] ] : array(); | |
| 685 | 599 | |
| 686 | 600 | self::prepare_field_type( $field ); |
| 687 | 601 | |
| 688 | 602 | if ( ! isset( $field['icon'] ) ) { |
| @@ -689,9 +603,8 @@ | ||
| 689 | 603 | $field['icon'] = 'frmfont frm_pencil_icon'; |
| 690 | 604 | } |
| 691 | 605 | |
| 692 | 606 | $possible_email_field = FrmFieldFactory::field_has_property( $args['type'], 'holds_email_values' ); |
| 693 | - | |
| 694 | 607 | if ( $possible_email_field ) { |
| 695 | 608 | $class .= ' show_frm_not_email_to'; |
| 696 | 609 | } |
| 697 | 610 | |
| @@ -699,35 +612,37 @@ | ||
| 699 | 612 | $class .= ' frm_insert_url'; |
| 700 | 613 | } |
| 701 | 614 | |
| 702 | 615 | $truncated_name = FrmAppHelper::truncate( $args['name'], 60 ); |
| 703 | - | |
| 704 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 616 | + if ( isset( $field['icon'] ) ) { | |
| 617 | + $icon = FrmAppHelper::icon_by_class( | |
| 618 | + $field['icon'], | |
| 619 | + array( | |
| 620 | + 'aria-hidden' => 'true', | |
| 621 | + 'echo' => false, | |
| 622 | + ) | |
| 623 | + ); | |
| 624 | + } else { | |
| 625 | + $icon = ''; | |
| 626 | + } | |
| 705 | 627 | ?> |
| 706 | 628 | <li class="<?php echo esc_attr( $class ); ?>"> |
| 707 | 629 | <a href="javascript:void(0)" class="frmids frm_insert_code" data-code="<?php echo esc_attr( $args['id'] ); ?>"> |
| 708 | 630 | <?php |
| 709 | - if ( isset( $field['icon'] ) ) { | |
| 710 | - FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); | |
| 711 | - } | |
| 712 | - | |
| 631 | + echo FrmAppHelper::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 713 | 632 | echo esc_html( $truncated_name ); |
| 714 | 633 | ?> |
| 715 | - <span>[<?php echo esc_html( $args['id_label'] ?? $args['id'] ); ?>]</span> | |
| 634 | + <span>[<?php echo esc_attr( isset( $args['id_label'] ) ? $args['id_label'] : $args['id'] ); ?>]</span> | |
| 716 | 635 | </a> |
| 717 | 636 | <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden" data-code="<?php echo esc_attr( $args['key'] ); ?>"> |
| 718 | 637 | <?php |
| 719 | - if ( isset( $field['icon'] ) ) { | |
| 720 | - FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); | |
| 721 | - } | |
| 722 | - | |
| 638 | + echo FrmAppHelper::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 723 | 639 | echo esc_html( $truncated_name ); |
| 724 | 640 | ?> |
| 725 | - <span>[<?php echo esc_html( FrmAppHelper::truncate( $args['key_label'] ?? $args['key'], 7 ) ); ?>]</span> | |
| 641 | + <span>[<?php echo esc_attr( FrmAppHelper::truncate( isset( $args['key_label'] ) ? $args['key_label'] : $args['key'], 7 ) ); ?>]</span> | |
| 726 | 642 | </a> |
| 727 | 643 | </li> |
| 728 | 644 | <?php |
| 729 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 730 | 645 | } |
| 731 | 646 | |
| 732 | 647 | /** |
| 733 | 648 | * Store and re-use field selection data for use when outputting shortcodes options in shortcode pop up. |
| @@ -745,12 +660,9 @@ | ||
| 745 | 660 | } |
| 746 | 661 | |
| 747 | 662 | /** |
| 748 | 663 | * @since 4.0 |
| 749 | - * | |
| 750 | 664 | * @param array $args |
| 751 | - * | |
| 752 | - * @return void | |
| 753 | 665 | */ |
| 754 | 666 | public static function insert_code_html( $args ) { |
| 755 | 667 | $defaults = array( |
| 756 | 668 | 'class' => '', |
| @@ -761,22 +673,20 @@ | ||
| 761 | 673 | |
| 762 | 674 | $args = array_merge( $defaults, $args ); |
| 763 | 675 | $has_tooltip = ! empty( $args['title'] ); |
| 764 | 676 | |
| 765 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 766 | 677 | ?> |
| 767 | 678 | <li class="<?php echo esc_attr( $args['class'] ); ?>"> |
| 768 | 679 | <a href="javascript:void(0)" class="frm_insert_code <?php echo $has_tooltip ? 'frm_help' : ''; ?>" |
| 769 | 680 | <?php echo $has_tooltip ? 'title="' . esc_attr( $args['title'] ) . '"' : ''; ?> |
| 770 | 681 | data-code="<?php echo esc_attr( $args['code'] ); ?>"> |
| 771 | - <?php echo esc_html( FrmAppHelper::truncate( $args['label'], 60 ) ); ?> | |
| 682 | + <?php echo esc_attr( FrmAppHelper::truncate( $args['label'], 60 ) ); ?> | |
| 772 | 683 | <span> |
| 773 | - [<?php echo esc_html( FrmAppHelper::truncate( $args['code'], 10 ) ); ?>] | |
| 684 | + [<?php echo esc_attr( FrmAppHelper::truncate( $args['code'], 10 ) ); ?>] | |
| 774 | 685 | </span> |
| 775 | 686 | </a> |
| 776 | 687 | </li> |
| 777 | 688 | <?php |
| 778 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 779 | 689 | } |
| 780 | 690 | |
| 781 | 691 | /** |
| 782 | 692 | * Some field types in add-ons may have been added with only |
| @@ -784,9 +694,8 @@ | ||
| 784 | 694 | * |
| 785 | 695 | * @since 4.0 |
| 786 | 696 | * |
| 787 | 697 | * @param array|string $field |
| 788 | - * | |
| 789 | 698 | * @return void |
| 790 | 699 | */ |
| 791 | 700 | public static function prepare_field_type( &$field ) { |
| 792 | 701 | if ( ! is_array( $field ) ) { |
| @@ -791,9 +700,9 @@ | ||
| 791 | 700 | public static function prepare_field_type( &$field ) { |
| 792 | 701 | if ( ! is_array( $field ) ) { |
| 793 | 702 | $field = array( |
| 794 | 703 | 'name' => $field, |
| 795 | - 'icon' => 'frmfont frm_pencil_icon', | |
| 704 | + 'icon' => 'frm_icon_font frm_pencil_icon', | |
| 796 | 705 | ); |
| 797 | 706 | } |
| 798 | 707 | } |
| 799 | 708 | |
| @@ -804,13 +713,11 @@ | ||
| 804 | 713 | * |
| 805 | 714 | * @param object $form |
| 806 | 715 | * @param array $fields |
| 807 | 716 | * @param bool $reset_fields |
| 808 | - * | |
| 809 | - * @return void | |
| 810 | 717 | */ |
| 811 | 718 | public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) { |
| 812 | - if ( ! $fields ) { | |
| 719 | + if ( empty( $fields ) ) { | |
| 813 | 720 | return; |
| 814 | 721 | } |
| 815 | 722 | |
| 816 | 723 | $end_section_values = apply_filters( 'frm_before_field_created', FrmFieldsHelper::setup_new_vars( 'end_divider', $form->id ) ); |
| @@ -817,9 +724,8 @@ | ||
| 817 | 724 | $open = false; |
| 818 | 725 | $prev_order = false; |
| 819 | 726 | $add_order = 0; |
| 820 | 727 | $last_field = false; |
| 821 | - | |
| 822 | 728 | foreach ( $fields as $field ) { |
| 823 | 729 | if ( $prev_order === $field->field_order ) { |
| 824 | 730 | ++$add_order; |
| 825 | 731 | } |
| @@ -862,17 +768,8 @@ | ||
| 862 | 768 | |
| 863 | 769 | /** |
| 864 | 770 | * Create end section field if it doesn't exist. This is for migration from < 2.0 |
| 865 | 771 | * Fix any ordering that may be messed up |
| 866 | - * | |
| 867 | - * @param bool $open | |
| 868 | - * @param bool $reset_fields | |
| 869 | - * @param int $add_order | |
| 870 | - * @param array $end_section_values | |
| 871 | - * @param object $field | |
| 872 | - * @param string $move | |
| 873 | - * | |
| 874 | - * @return void | |
| 875 | 772 | */ |
| 876 | 773 | public static function maybe_create_end_section( &$open, &$reset_fields, &$add_order, $end_section_values, $field, $move = 'no' ) { |
| 877 | 774 | if ( ! $open ) { |
| 878 | 775 | return; |
| @@ -882,9 +779,9 @@ | ||
| 882 | 779 | |
| 883 | 780 | FrmField::create( $end_section_values ); |
| 884 | 781 | |
| 885 | 782 | if ( $move === 'move' ) { |
| 886 | - // Bump the order of current field unless we're at the end of the form | |
| 783 | + // bump the order of current field unless we're at the end of the form | |
| 887 | 784 | FrmField::update( $field->id, array( 'field_order' => $field->field_order + 2 ) ); |
| 888 | 785 | } |
| 889 | 786 | |
| 890 | 787 | $add_order += 2; |
| @@ -891,17 +788,8 @@ | ||
| 891 | 788 | $open = false; |
| 892 | 789 | $reset_fields = true; |
| 893 | 790 | } |
| 894 | 791 | |
| 895 | - /** | |
| 896 | - * @param string $html | |
| 897 | - * @param object $form | |
| 898 | - * @param bool $title | |
| 899 | - * @param bool $description | |
| 900 | - * @param array $values | |
| 901 | - * | |
| 902 | - * @return string | |
| 903 | - */ | |
| 904 | 792 | public static function replace_shortcodes( $html, $form, $title = false, $description = false, $values = array() ) { |
| 905 | 793 | $codes = array( |
| 906 | 794 | 'form_name' => $title, |
| 907 | 795 | 'form_description' => $description, |
| @@ -906,9 +794,8 @@ | ||
| 906 | 794 | 'form_name' => $title, |
| 907 | 795 | 'form_description' => $description, |
| 908 | 796 | 'entry_key' => true, |
| 909 | 797 | ); |
| 910 | - | |
| 911 | 798 | foreach ( $codes as $code => $show ) { |
| 912 | 799 | if ( $code === 'form_name' ) { |
| 913 | 800 | $replace_with = $form->name; |
| 914 | 801 | } elseif ( $code === 'form_description' ) { |
| @@ -918,9 +805,9 @@ | ||
| 918 | 805 | } else { |
| 919 | 806 | $replace_with = ''; |
| 920 | 807 | } |
| 921 | 808 | |
| 922 | - FrmShortcodeHelper::remove_inline_conditions( FrmAppHelper::is_true( $show ) && $replace_with != '', $code, $replace_with, $html ); // phpcs:ignore Universal.Operators.StrictComparisons, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 809 | + FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html ); | |
| 923 | 810 | } |
| 924 | 811 | |
| 925 | 812 | // Replace [form_key]. |
| 926 | 813 | $html = str_replace( '[form_key]', $form->form_key, $html ); |
| @@ -927,9 +814,9 @@ | ||
| 927 | 814 | |
| 928 | 815 | // Replace [frmurl]. |
| 929 | 816 | $html = str_replace( '[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html ); |
| 930 | 817 | |
| 931 | - if ( str_contains( $html, '[button_label]' ) ) { | |
| 818 | + if ( strpos( $html, '[button_label]' ) ) { | |
| 932 | 819 | add_filter( 'frm_submit_button', 'FrmFormsHelper::submit_button_label', 1 ); |
| 933 | 820 | $submit_label = apply_filters( 'frm_submit_button', $title, $form ); |
| 934 | 821 | $submit_label = esc_attr( do_shortcode( $submit_label ) ); |
| 935 | 822 | $html = str_replace( '[button_label]', $submit_label, $html ); |
| @@ -936,32 +823,27 @@ | ||
| 936 | 823 | } |
| 937 | 824 | |
| 938 | 825 | $html = apply_filters( 'frm_form_replace_shortcodes', $html, $form, $values ); |
| 939 | 826 | |
| 940 | - if ( str_contains( $html, '[if back_button]' ) ) { | |
| 827 | + if ( strpos( $html, '[if back_button]' ) ) { | |
| 941 | 828 | $html = preg_replace( '/(\[if\s+back_button\])(.*?)(\[\/if\s+back_button\])/mis', '', $html ); |
| 942 | 829 | } |
| 943 | 830 | |
| 944 | - if ( str_contains( $html, '[if save_draft]' ) ) { | |
| 831 | + if ( strpos( $html, '[if save_draft]' ) ) { | |
| 945 | 832 | $html = preg_replace( '/(\[if\s+save_draft\])(.*?)(\[\/if\s+save_draft\])/mis', '', $html ); |
| 946 | 833 | } |
| 947 | 834 | |
| 948 | - if ( str_contains( $html, '[if start_over]' ) ) { | |
| 835 | + if ( strpos( $html, '[if start_over]' ) ) { | |
| 949 | 836 | $html = preg_replace( '/(\[if\s+start_over\])(.*?)(\[\/if\s+start_over\])/mis', '', $html ); |
| 950 | 837 | } |
| 951 | 838 | |
| 952 | 839 | if ( apply_filters( 'frm_do_html_shortcodes', true ) ) { |
| 953 | - return do_shortcode( $html ); | |
| 840 | + $html = do_shortcode( $html ); | |
| 954 | 841 | } |
| 955 | 842 | |
| 956 | 843 | return $html; |
| 957 | 844 | } |
| 958 | 845 | |
| 959 | - /** | |
| 960 | - * @param string $submit | |
| 961 | - * | |
| 962 | - * @return string | |
| 963 | - */ | |
| 964 | 846 | public static function submit_button_label( $submit ) { |
| 965 | 847 | if ( ! $submit ) { |
| 966 | 848 | $frm_settings = FrmAppHelper::get_settings(); |
| 967 | 849 | $submit = $frm_settings->submit_value; |
| @@ -979,9 +861,8 @@ | ||
| 979 | 861 | * @return void |
| 980 | 862 | */ |
| 981 | 863 | public static function maybe_hide_inline() { |
| 982 | 864 | $frm_settings = FrmAppHelper::get_settings(); |
| 983 | - | |
| 984 | 865 | if ( $frm_settings->load_style === 'none' ) { |
| 985 | 866 | echo ' style="display:none;"'; |
| 986 | 867 | } elseif ( $frm_settings->load_style === 'dynamic' ) { |
| 987 | 868 | FrmStylesController::enqueue_style(); |
| @@ -988,10 +869,8 @@ | ||
| 988 | 869 | } |
| 989 | 870 | } |
| 990 | 871 | |
| 991 | 872 | /** |
| 992 | - * @param array|bool|int|object|string $form | |
| 993 | - * | |
| 994 | 873 | * @return string|null |
| 995 | 874 | */ |
| 996 | 875 | public static function get_form_style_class( $form = false ) { |
| 997 | 876 | $style = self::get_form_style( $form ); |
| @@ -996,10 +875,13 @@ | ||
| 996 | 875 | public static function get_form_style_class( $form = false ) { |
| 997 | 876 | $style = self::get_form_style( $form ); |
| 998 | 877 | $class = ' with_frm_style'; |
| 999 | 878 | |
| 1000 | - if ( ! $style ) { | |
| 1001 | - return FrmAppHelper::is_admin_page( 'formidable-entries' ) ? $class : null; | |
| 879 | + if ( empty( $style ) ) { | |
| 880 | + if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) { | |
| 881 | + return $class; | |
| 882 | + } | |
| 883 | + return; | |
| 1002 | 884 | } |
| 1003 | 885 | |
| 1004 | 886 | // If submit button needs to be inline or centered. |
| 1005 | 887 | if ( is_object( $form ) ) { |
| @@ -1020,9 +902,11 @@ | ||
| 1020 | 902 | } elseif ( 'center' === $submit_align ) { |
| 1021 | 903 | $class .= ' frm_center_submit'; |
| 1022 | 904 | } |
| 1023 | 905 | |
| 1024 | - return apply_filters( 'frm_add_form_style_class', $class, $style, compact( 'form' ) ); | |
| 906 | + $class = apply_filters( 'frm_add_form_style_class', $class, $style, compact( 'form' ) ); | |
| 907 | + | |
| 908 | + return $class; | |
| 1025 | 909 | } |
| 1026 | 910 | |
| 1027 | 911 | /** |
| 1028 | 912 | * In order for frm_inline_submit to inline the submit button the form must also have the frm_inline_form that adds the grid-column style rules required for it to work. |
| @@ -1029,17 +913,16 @@ | ||
| 1029 | 913 | * |
| 1030 | 914 | * @since 5.0.12 |
| 1031 | 915 | * |
| 1032 | 916 | * @param array $form |
| 1033 | - * | |
| 1034 | 917 | * @return bool |
| 1035 | 918 | */ |
| 1036 | 919 | private static function form_should_be_inline_and_missing_class( $form ) { |
| 1037 | - if ( isset( $form['form_class'] ) && str_contains( ' ' . $form['form_class'] . ' ', ' frm_inline_form ' ) ) { | |
| 1038 | - // Not missing class, avoid adding it twice. | |
| 920 | + if ( isset( $form['form_class'] ) && false !== strpos( ' ' . $form['form_class'] . ' ', ' frm_inline_form ' ) ) { | |
| 921 | + // not missing class, avoid adding it twice. | |
| 1039 | 922 | return false; |
| 1040 | 923 | } |
| 1041 | - return ! empty( $form['submit_html'] ) && str_contains( $form['submit_html'], 'frm_inline_submit' ); | |
| 924 | + return ! empty( $form['submit_html'] ) && false !== strpos( $form['submit_html'], 'frm_inline_submit' ); | |
| 1042 | 925 | } |
| 1043 | 926 | |
| 1044 | 927 | /** |
| 1045 | 928 | * Returns appropriate class if form has top labels |
| @@ -1064,9 +947,8 @@ | ||
| 1064 | 947 | return false; |
| 1065 | 948 | } |
| 1066 | 949 | |
| 1067 | 950 | $fields = $form['fields']; |
| 1068 | - | |
| 1069 | 951 | if ( count( $fields ) <= 0 ) { |
| 1070 | 952 | return false; |
| 1071 | 953 | } |
| 1072 | 954 | |
| @@ -1071,13 +953,11 @@ | ||
| 1071 | 953 | } |
| 1072 | 954 | |
| 1073 | 955 | // Start from the fields closest to the submit button. |
| 1074 | 956 | $fields = array_reverse( $fields ); |
| 1075 | - | |
| 1076 | 957 | foreach ( $fields as $field ) { |
| 1077 | - $type = $field['original_type'] ?? $field['type']; | |
| 958 | + $type = isset( $field['original_type'] ) ? $field['original_type'] : $field['type']; | |
| 1078 | 959 | $has_input = FrmFieldFactory::field_has_property( $type, 'has_input' ); |
| 1079 | - | |
| 1080 | 960 | if ( $has_input ) { |
| 1081 | 961 | return self::field_has_top_label( $field, $form ); |
| 1082 | 962 | } |
| 1083 | 963 | } |
| @@ -1094,25 +974,24 @@ | ||
| 1094 | 974 | * @return bool |
| 1095 | 975 | */ |
| 1096 | 976 | private static function field_has_top_label( $field, $form ) { |
| 1097 | 977 | $label_position = FrmFieldsHelper::label_position( $field['label'], $field, $form ); |
| 1098 | - return in_array( $label_position, array( 'top', 'inside', 'hidden' ), true ); | |
| 978 | + | |
| 979 | + return in_array( $label_position, array( 'top', 'inside', 'hidden' ) ); | |
| 1099 | 980 | } |
| 1100 | 981 | |
| 1101 | 982 | /** |
| 1102 | 983 | * @param array|bool|int|object|string $form |
| 1103 | - * | |
| 1104 | - * @return int|string | |
| 984 | + * @return string | |
| 1105 | 985 | */ |
| 1106 | 986 | public static function get_form_style( $form ) { |
| 1107 | 987 | $style = 1; |
| 1108 | - | |
| 1109 | - if ( ! $form || 'default' === $form ) { | |
| 988 | + if ( empty( $form ) || 'default' === $form ) { | |
| 1110 | 989 | return $style; |
| 1111 | 990 | } |
| 1112 | 991 | |
| 1113 | 992 | if ( is_object( $form ) && $form->parent_form_id ) { |
| 1114 | - // Get the parent form if this is a child | |
| 993 | + // get the parent form if this is a child | |
| 1115 | 994 | $form = $form->parent_form_id; |
| 1116 | 995 | } elseif ( is_array( $form ) && ! empty( $form['parent_form_id'] ) ) { |
| 1117 | 996 | $form = $form['parent_form_id']; |
| 1118 | 997 | } elseif ( is_array( $form ) && isset( $form['custom_style'] ) ) { |
| @@ -1122,9 +1001,11 @@ | ||
| 1122 | 1001 | if ( $form && ( is_string( $form ) || is_int( $form ) ) ) { |
| 1123 | 1002 | $form = FrmForm::getOne( $form ); |
| 1124 | 1003 | } |
| 1125 | 1004 | |
| 1126 | - return $form && is_object( $form ) && isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : $style; | |
| 1005 | + $style = $form && is_object( $form ) && isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : $style; | |
| 1006 | + | |
| 1007 | + return $style; | |
| 1127 | 1008 | } |
| 1128 | 1009 | |
| 1129 | 1010 | /** |
| 1130 | 1011 | * Display the validation error messages when an entry is submitted |
| @@ -1129,21 +1010,18 @@ | ||
| 1129 | 1010 | /** |
| 1130 | 1011 | * Display the validation error messages when an entry is submitted |
| 1131 | 1012 | * |
| 1132 | 1013 | * @since 2.0.6 |
| 1133 | - * | |
| 1134 | 1014 | * @param array $args Includes img, errors. |
| 1135 | - * | |
| 1136 | - * @return void | |
| 1137 | 1015 | */ |
| 1138 | 1016 | public static function show_errors( $args ) { |
| 1139 | 1017 | $invalid_msg = self::get_invalid_error_message( $args ); |
| 1140 | 1018 | |
| 1141 | - if ( $invalid_msg ) { | |
| 1019 | + if ( empty( $invalid_msg ) ) { | |
| 1020 | + $show_img = false; | |
| 1021 | + } else { | |
| 1142 | 1022 | echo wp_kses_post( $invalid_msg ); |
| 1143 | 1023 | $show_img = true; |
| 1144 | - } else { | |
| 1145 | - $show_img = false; | |
| 1146 | 1024 | } |
| 1147 | 1025 | |
| 1148 | 1026 | self::show_error( |
| 1149 | 1027 | array( |
| @@ -1159,21 +1037,17 @@ | ||
| 1159 | 1037 | * The image was removed from the styling settings, but it may still be set with a hook |
| 1160 | 1038 | * If the message in the global settings is empty, show every validation message in the error box |
| 1161 | 1039 | * |
| 1162 | 1040 | * @since 2.0.6 |
| 1163 | - * | |
| 1164 | 1041 | * @param array $args Includes img, errors, and show_img. |
| 1165 | - * | |
| 1166 | - * @return void | |
| 1167 | 1042 | */ |
| 1168 | 1043 | public static function show_error( $args ) { |
| 1169 | - // Remove any blank messages | |
| 1044 | + // remove any blank messages | |
| 1170 | 1045 | $args['errors'] = array_filter( (array) $args['errors'] ); |
| 1171 | 1046 | |
| 1172 | 1047 | $line_break_first = $args['show_img']; |
| 1173 | - | |
| 1174 | 1048 | foreach ( $args['errors'] as $error_key => $error ) { |
| 1175 | - if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key === 'cptch_number' || str_starts_with( $error_key, 'field' ) ) ) { | |
| 1049 | + if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key === 'cptch_number' || strpos( $error_key, 'field' ) === 0 ) ) { | |
| 1176 | 1050 | continue; |
| 1177 | 1051 | } |
| 1178 | 1052 | |
| 1179 | 1053 | $id = str_replace( 'field', 'field_', $error_key ); |
| @@ -1190,27 +1064,15 @@ | ||
| 1190 | 1064 | echo '</div>'; |
| 1191 | 1065 | } |
| 1192 | 1066 | } |
| 1193 | 1067 | |
| 1194 | - /** | |
| 1195 | - * @param int|string $id | |
| 1196 | - * | |
| 1197 | - * @return void | |
| 1198 | - */ | |
| 1199 | 1068 | public static function maybe_get_scroll_js( $id ) { |
| 1200 | 1069 | $offset = apply_filters( 'frm_scroll_offset', 4, array( 'form_id' => $id ) ); |
| 1201 | - | |
| 1202 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 1203 | 1070 | if ( $offset != - 1 ) { |
| 1204 | 1071 | self::get_scroll_js( $id ); |
| 1205 | 1072 | } |
| 1206 | 1073 | } |
| 1207 | 1074 | |
| 1208 | - /** | |
| 1209 | - * @param int|string $form_id | |
| 1210 | - * | |
| 1211 | - * @return void | |
| 1212 | - */ | |
| 1213 | 1075 | public static function get_scroll_js( $form_id ) { |
| 1214 | 1076 | echo '<script type="text/javascript">document.addEventListener(\'DOMContentLoaded\',function(){frmFrontForm.scrollMsg(' . (int) $form_id . ');})</script>'; |
| 1215 | 1077 | } |
| 1216 | 1078 | |
| @@ -1215,13 +1077,8 @@ | ||
| 1215 | 1077 | } |
| 1216 | 1078 | |
| 1217 | 1079 | /** |
| 1218 | 1080 | * @since 3.0 |
| 1219 | - * | |
| 1220 | - * @param int|object|string $form_id | |
| 1221 | - * @param mixed $form | |
| 1222 | - * | |
| 1223 | - * @return array | |
| 1224 | 1081 | */ |
| 1225 | 1082 | public static function get_action_links( $form_id, $form ) { |
| 1226 | 1083 | if ( ! is_object( $form ) ) { |
| 1227 | 1084 | $form = FrmForm::getOne( $form_id ); |
| @@ -1228,10 +1085,9 @@ | ||
| 1228 | 1085 | } |
| 1229 | 1086 | |
| 1230 | 1087 | $actions = array(); |
| 1231 | 1088 | $trash_links = self::delete_trash_links( $form_id ); |
| 1232 | - | |
| 1233 | - if ( 'trash' === $form->status ) { | |
| 1089 | + if ( 'trash' == $form->status ) { | |
| 1234 | 1090 | $actions['restore'] = $trash_links['restore']; |
| 1235 | 1091 | |
| 1236 | 1092 | if ( current_user_can( 'frm_delete_forms' ) ) { |
| 1237 | 1093 | $actions['trash'] = $trash_links['delete']; |
| @@ -1237,20 +1093,19 @@ | ||
| 1237 | 1093 | $actions['trash'] = $trash_links['delete']; |
| 1238 | 1094 | } |
| 1239 | 1095 | } elseif ( current_user_can( 'frm_edit_forms' ) ) { |
| 1240 | 1096 | $duplicate_link = '?page=formidable&frm_action=duplicate&id=' . $form_id; |
| 1241 | - | |
| 1242 | 1097 | if ( $form->is_template ) { |
| 1243 | 1098 | $actions['frm_duplicate'] = array( |
| 1244 | 1099 | 'url' => wp_nonce_url( $duplicate_link ), |
| 1245 | 1100 | 'label' => __( 'Create Form from Template', 'formidable' ), |
| 1246 | - 'icon' => 'frmfont frm_clone_icon', | |
| 1101 | + 'icon' => 'frm_icon_font frm_clone_icon', | |
| 1247 | 1102 | ); |
| 1248 | 1103 | } else { |
| 1249 | 1104 | $actions['duplicate'] = array( |
| 1250 | 1105 | 'url' => wp_nonce_url( $duplicate_link ), |
| 1251 | 1106 | 'label' => __( 'Duplicate Form', 'formidable' ), |
| 1252 | - 'icon' => 'frmfont frm_clone_icon', | |
| 1107 | + 'icon' => 'frm_icon_font frm_clone_icon', | |
| 1253 | 1108 | ); |
| 1254 | 1109 | } |
| 1255 | 1110 | |
| 1256 | 1111 | $actions['trash'] = self::delete_trash_info( $form_id, $form->status ); |
| @@ -1260,9 +1115,8 @@ | ||
| 1260 | 1115 | } |
| 1261 | 1116 | |
| 1262 | 1117 | /** |
| 1263 | 1118 | * @param int|object|string $data |
| 1264 | - * | |
| 1265 | 1119 | * @return string |
| 1266 | 1120 | */ |
| 1267 | 1121 | public static function edit_form_link( $data ) { |
| 1268 | 1122 | $form_id = self::get_form_id_from_data( $data ); |
| @@ -1271,9 +1125,10 @@ | ||
| 1271 | 1125 | return ''; |
| 1272 | 1126 | } |
| 1273 | 1127 | |
| 1274 | 1128 | $label = self::edit_form_link_label( $data ); |
| 1275 | - return '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>'; | |
| 1129 | + $link = '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>'; | |
| 1130 | + return $link; | |
| 1276 | 1131 | } |
| 1277 | 1132 | |
| 1278 | 1133 | /** |
| 1279 | 1134 | * Returns a text used when no title is set. |
| @@ -1287,98 +1142,80 @@ | ||
| 1287 | 1142 | } |
| 1288 | 1143 | |
| 1289 | 1144 | /** |
| 1290 | 1145 | * @param int|object|string $data |
| 1291 | - * | |
| 1292 | 1146 | * @return string |
| 1293 | 1147 | */ |
| 1294 | 1148 | public static function edit_form_link_label( $data ) { |
| 1295 | 1149 | $name = self::get_form_name_from_data( $data ); |
| 1296 | - | |
| 1297 | 1150 | if ( ! $name ) { |
| 1298 | 1151 | return self::get_no_title_text(); |
| 1299 | 1152 | } |
| 1300 | - | |
| 1301 | 1153 | return FrmAppHelper::truncate( $name, 40 ); |
| 1302 | 1154 | } |
| 1303 | 1155 | |
| 1304 | 1156 | /** |
| 1305 | 1157 | * @param int|object|string $data |
| 1306 | - * | |
| 1307 | 1158 | * @return int|string |
| 1308 | 1159 | */ |
| 1309 | 1160 | private static function get_form_id_from_data( $data ) { |
| 1310 | - return is_object( $data ) ? $data->id : $data; | |
| 1161 | + if ( is_object( $data ) ) { | |
| 1162 | + $form_id = $data->id; | |
| 1163 | + } else { | |
| 1164 | + $form_id = $data; | |
| 1165 | + } | |
| 1166 | + return $form_id; | |
| 1311 | 1167 | } |
| 1312 | 1168 | |
| 1313 | 1169 | /** |
| 1314 | 1170 | * @param mixed $data |
| 1315 | - * | |
| 1316 | 1171 | * @return string |
| 1317 | 1172 | */ |
| 1318 | 1173 | private static function get_form_name_from_data( $data ) { |
| 1319 | 1174 | if ( is_object( $data ) ) { |
| 1320 | - return $data->name; | |
| 1175 | + $form_name = $data->name; | |
| 1176 | + } else { | |
| 1177 | + $form_id = $data; | |
| 1178 | + $form_name = FrmForm::getName( $form_id ); | |
| 1321 | 1179 | } |
| 1322 | - | |
| 1323 | - $form_id = $data; | |
| 1324 | - return FrmForm::getName( $form_id ); | |
| 1180 | + return $form_name; | |
| 1325 | 1181 | } |
| 1326 | 1182 | |
| 1327 | - /** | |
| 1328 | - * @param int $id | |
| 1329 | - * @param string $status | |
| 1330 | - * @param string $length | |
| 1331 | - * | |
| 1332 | - * @return string | |
| 1333 | - */ | |
| 1334 | 1183 | public static function delete_trash_link( $id, $status, $length = 'label' ) { |
| 1335 | 1184 | $link_details = self::delete_trash_info( $id, $status ); |
| 1185 | + | |
| 1336 | 1186 | return self::format_link_html( $link_details, $length ); |
| 1337 | 1187 | } |
| 1338 | 1188 | |
| 1339 | 1189 | /** |
| 1340 | 1190 | * @since 3.0 |
| 1341 | - * | |
| 1342 | - * @param array $link_details | |
| 1343 | - * @param string $length | |
| 1344 | - * | |
| 1345 | - * @return string | |
| 1346 | 1191 | */ |
| 1347 | 1192 | public static function format_link_html( $link_details, $length = 'label' ) { |
| 1348 | 1193 | $link = ''; |
| 1194 | + if ( ! empty( $link_details ) ) { | |
| 1195 | + $link = '<a href="' . esc_url( $link_details['url'] ) . '" class="frm-trash-link"'; | |
| 1196 | + if ( isset( $link_details['data'] ) ) { | |
| 1197 | + foreach ( $link_details['data'] as $data => $value ) { | |
| 1198 | + $link .= ' data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '"'; | |
| 1199 | + } | |
| 1200 | + } elseif ( isset( $link_details['confirm'] ) ) { | |
| 1201 | + $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"'; | |
| 1202 | + } | |
| 1349 | 1203 | |
| 1350 | - if ( ! $link_details ) { | |
| 1351 | - return $link; | |
| 1352 | - } | |
| 1353 | - | |
| 1354 | - $link = '<a href="' . esc_url( $link_details['url'] ) . '" class="frm-trash-link"'; | |
| 1355 | - | |
| 1356 | - if ( isset( $link_details['data'] ) ) { | |
| 1357 | - foreach ( $link_details['data'] as $data => $value ) { | |
| 1358 | - $link .= ' data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '"'; | |
| 1204 | + $label = ( isset( $link_details[ $length ] ) ? $link_details[ $length ] : $link_details['label'] ); | |
| 1205 | + if ( $length === 'icon' && isset( $link_details[ $length ] ) ) { | |
| 1206 | + $label = '<span class="' . $label . '" title="' . esc_attr( $link_details['label'] ) . '" aria-hidden="true"></span>'; | |
| 1207 | + $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"'; | |
| 1359 | 1208 | } |
| 1360 | - } elseif ( isset( $link_details['confirm'] ) ) { | |
| 1361 | - $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"'; | |
| 1362 | - } | |
| 1363 | 1209 | |
| 1364 | - $label = $link_details[ $length ] ?? $link_details['label']; | |
| 1365 | - | |
| 1366 | - if ( $length === 'icon' && isset( $link_details[ $length ] ) ) { | |
| 1367 | - $label = '<span class="' . $label . '" title="' . esc_attr( $link_details['label'] ) . '" aria-hidden="true"></span>'; | |
| 1368 | - $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"'; | |
| 1210 | + $link .= '>' . $label . '</a>'; | |
| 1369 | 1211 | } |
| 1370 | 1212 | |
| 1371 | - return $link . ( '>' . $label . '</a>' ); | |
| 1213 | + return $link; | |
| 1372 | 1214 | } |
| 1373 | 1215 | |
| 1374 | 1216 | /** |
| 1375 | 1217 | * @since 3.0 |
| 1376 | - * | |
| 1377 | - * @param int $id | |
| 1378 | - * @param string $status | |
| 1379 | - * | |
| 1380 | - * @return array | |
| 1381 | 1218 | */ |
| 1382 | 1219 | public static function delete_trash_info( $id, $status ) { |
| 1383 | 1220 | $labels = self::delete_trash_links( $id ); |
| 1384 | 1221 | |
| @@ -1384,9 +1221,13 @@ | ||
| 1384 | 1221 | |
| 1385 | 1222 | if ( 'trash' === $status ) { |
| 1386 | 1223 | $info = $labels['restore']; |
| 1387 | 1224 | } elseif ( current_user_can( 'frm_delete_forms' ) ) { |
| 1388 | - $info = EMPTY_TRASH_DAYS ? $labels['trash'] : $labels['delete']; | |
| 1225 | + if ( EMPTY_TRASH_DAYS ) { | |
| 1226 | + $info = $labels['trash']; | |
| 1227 | + } else { | |
| 1228 | + $info = $labels['delete']; | |
| 1229 | + } | |
| 1389 | 1230 | } else { |
| 1390 | 1231 | $info = array(); |
| 1391 | 1232 | } |
| 1392 | 1233 | |
| @@ -1394,12 +1235,8 @@ | ||
| 1394 | 1235 | } |
| 1395 | 1236 | |
| 1396 | 1237 | /** |
| 1397 | 1238 | * @since 3.0 |
| 1398 | - * | |
| 1399 | - * @param int $id | |
| 1400 | - * | |
| 1401 | - * @return array | |
| 1402 | 1239 | */ |
| 1403 | 1240 | public static function delete_trash_links( $id ) { |
| 1404 | 1241 | $current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type' ) ); |
| 1405 | 1242 | $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id; |
| @@ -1413,9 +1250,9 @@ | ||
| 1413 | 1250 | 'trash' => array( |
| 1414 | 1251 | 'label' => __( 'Move Form to Trash', 'formidable' ), |
| 1415 | 1252 | 'short' => __( 'Trash', 'formidable' ), |
| 1416 | 1253 | 'url' => wp_nonce_url( $base_url . '&frm_action=trash', 'trash_form_' . absint( $id ) ), |
| 1417 | - 'icon' => 'frmfont frm_delete_icon', | |
| 1254 | + 'icon' => 'frm_icon_font frm_delete_icon', | |
| 1418 | 1255 | 'data' => array( |
| 1419 | 1256 | 'frmverify' => __( 'Do you want to move this form to the trash?', 'formidable' ), |
| 1420 | 1257 | 'frmverify-btn' => 'frm-button-red', |
| 1421 | 1258 | ), |
| @@ -1424,9 +1261,9 @@ | ||
| 1424 | 1261 | 'label' => __( 'Delete Permanently', 'formidable' ), |
| 1425 | 1262 | 'short' => __( 'Delete', 'formidable' ), |
| 1426 | 1263 | 'url' => wp_nonce_url( $base_url . '&frm_action=destroy', 'destroy_form_' . absint( $id ) ), |
| 1427 | 1264 | 'confirm' => __( 'Are you sure you want to delete this form and all its entries?', 'formidable' ), |
| 1428 | - 'icon' => 'frmfont frm_delete_icon', | |
| 1265 | + 'icon' => 'frm_icon_font frm_delete_icon', | |
| 1429 | 1266 | 'data' => array( |
| 1430 | 1267 | 'frmverify' => __( 'This will permanently delete the form and all its entries. This is irreversible. Are you sure you want to continue?', 'formidable' ), |
| 1431 | 1268 | 'frmverify-btn' => 'frm-button-red', |
| 1432 | 1269 | ), |
| @@ -1435,10 +1272,8 @@ | ||
| 1435 | 1272 | } |
| 1436 | 1273 | |
| 1437 | 1274 | /** |
| 1438 | 1275 | * @since 3.0 |
| 1439 | - * | |
| 1440 | - * @return array | |
| 1441 | 1276 | */ |
| 1442 | 1277 | public static function css_classes() { |
| 1443 | 1278 | $classes = array( |
| 1444 | 1279 | 'frm_total' => array( |
| @@ -1450,9 +1285,9 @@ | ||
| 1450 | 1285 | 'title' => __( 'Add this to a read-only field to display the text in large, bold text without a border or background.', 'formidable' ), |
| 1451 | 1286 | ), |
| 1452 | 1287 | 'frm_scroll_box' => array( |
| 1453 | 1288 | 'label' => __( 'Scroll Box', 'formidable' ), |
| 1454 | - 'title' => __( 'If you have many checkbox or radio button options, you may add this class to allow your user to easily scroll through the options. Or add a scrolling area around content in an HTML field.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 1289 | + 'title' => __( 'If you have many checkbox or radio button options, you may add this class to allow your user to easily scroll through the options. Or add a scrolling area around content in an HTML field.', 'formidable' ), | |
| 1455 | 1290 | ), |
| 1456 | 1291 | 'frm_first' => array( |
| 1457 | 1292 | 'label' => __( 'First', 'formidable' ), |
| 1458 | 1293 | 'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm4', 'formidable' ), |
| @@ -1473,11 +1308,8 @@ | ||
| 1473 | 1308 | |
| 1474 | 1309 | return apply_filters( 'frm_layout_classes', $classes ); |
| 1475 | 1310 | } |
| 1476 | 1311 | |
| 1477 | - /** | |
| 1478 | - * @return array | |
| 1479 | - */ | |
| 1480 | 1312 | public static function grid_classes() { |
| 1481 | 1313 | return array( |
| 1482 | 1314 | 'frm_half' => '1/2', |
| 1483 | 1315 | 'frm_third' => '1/3', |
| @@ -1491,18 +1323,12 @@ | ||
| 1491 | 1323 | } |
| 1492 | 1324 | |
| 1493 | 1325 | /** |
| 1494 | 1326 | * @since 3.0 |
| 1495 | - * | |
| 1496 | - * @param mixed $style | |
| 1497 | - * @param string $class | |
| 1498 | - * | |
| 1499 | - * @return string | |
| 1500 | 1327 | */ |
| 1501 | 1328 | public static function style_class_label( $style, $class ) { |
| 1502 | 1329 | $label = ''; |
| 1503 | - | |
| 1504 | - if ( ! $style ) { | |
| 1330 | + if ( empty( $style ) ) { | |
| 1505 | 1331 | $label = $class; |
| 1506 | 1332 | } elseif ( ! is_array( $style ) ) { |
| 1507 | 1333 | $label = $style; |
| 1508 | 1334 | } elseif ( isset( $style['label'] ) ) { |
| @@ -1511,13 +1337,8 @@ | ||
| 1511 | 1337 | |
| 1512 | 1338 | return $label; |
| 1513 | 1339 | } |
| 1514 | 1340 | |
| 1515 | - /** | |
| 1516 | - * @param string $status | |
| 1517 | - * | |
| 1518 | - * @return string | |
| 1519 | - */ | |
| 1520 | 1341 | public static function status_nice_name( $status ) { |
| 1521 | 1342 | $nice_names = array( |
| 1522 | 1343 | 'draft' => __( 'Draft', 'formidable' ), |
| 1523 | 1344 | 'trash' => __( 'Trash', 'formidable' ), |
| @@ -1523,13 +1344,15 @@ | ||
| 1523 | 1344 | 'trash' => __( 'Trash', 'formidable' ), |
| 1524 | 1345 | 'publish' => __( 'Published', 'formidable' ), |
| 1525 | 1346 | ); |
| 1526 | 1347 | |
| 1527 | - if ( ! array_key_exists( $status, $nice_names ) ) { | |
| 1348 | + if ( ! in_array( $status, array_keys( $nice_names ), true ) ) { | |
| 1528 | 1349 | $status = 'publish'; |
| 1529 | 1350 | } |
| 1530 | 1351 | |
| 1531 | - return $nice_names[ $status ]; | |
| 1352 | + $name = $nice_names[ $status ]; | |
| 1353 | + | |
| 1354 | + return $name; | |
| 1532 | 1355 | } |
| 1533 | 1356 | |
| 1534 | 1357 | /** |
| 1535 | 1358 | * Renders a template icon based on the given categories. |
| @@ -1536,9 +1359,8 @@ | ||
| 1536 | 1359 | * |
| 1537 | 1360 | * @param array $categories The categories to render the icon for. |
| 1538 | 1361 | * @param array $atts { |
| 1539 | 1362 | * Optional. An array of attributes for rendering. |
| 1540 | - * | |
| 1541 | 1363 | * @type string $html 'span' or 'div'. Default 'span'. |
| 1542 | 1364 | * @type bool $bg Whether to add a background color or not. Default false. |
| 1543 | 1365 | * } |
| 1544 | 1366 | * |
| @@ -1588,13 +1410,12 @@ | ||
| 1588 | 1410 | ); |
| 1589 | 1411 | |
| 1590 | 1412 | // Determine the icon to be used. |
| 1591 | 1413 | $icon = $icons['']; |
| 1592 | - | |
| 1593 | 1414 | if ( count( $categories ) === 1 ) { |
| 1594 | 1415 | $category = reset( $categories ); |
| 1595 | - $icon = $icons[ $category ] ?? $icon; | |
| 1596 | - } elseif ( $categories ) { | |
| 1416 | + $icon = isset( $icons[ $category ] ) ? $icons[ $category ] : $icon; | |
| 1417 | + } elseif ( ! empty( $categories ) ) { | |
| 1597 | 1418 | $icons = array_intersect_key( $icons, array_flip( $categories ) ); |
| 1598 | 1419 | $icon = reset( $icons ); |
| 1599 | 1420 | } |
| 1600 | 1421 | |
| @@ -1599,19 +1420,17 @@ | ||
| 1599 | 1420 | } |
| 1600 | 1421 | |
| 1601 | 1422 | // Prepare variables for output. |
| 1602 | 1423 | $icon_name = $icon[0]; |
| 1603 | - $bg_color = $icon[1] ?? ''; | |
| 1424 | + $bg_color = isset( $icon[1] ) ? $icon[1] : ''; | |
| 1604 | 1425 | |
| 1605 | 1426 | // Render the icon. |
| 1606 | 1427 | echo '<span class="frm-category-icon frm-icon-wrapper"'; |
| 1607 | - | |
| 1608 | 1428 | if ( $bg_color && $atts['bg'] ) { |
| 1609 | 1429 | echo ' style="background-color:' . esc_attr( $bg_color ) . '"'; |
| 1610 | 1430 | } |
| 1611 | - | |
| 1612 | 1431 | echo '>'; |
| 1613 | - FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon_name . '_icon' ); | |
| 1432 | + FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon_name . '_icon' ); | |
| 1614 | 1433 | echo '</span>'; |
| 1615 | 1434 | } |
| 1616 | 1435 | |
| 1617 | 1436 | /** |
| @@ -1620,9 +1439,8 @@ | ||
| 1620 | 1439 | * @since 4.02 |
| 1621 | 1440 | * |
| 1622 | 1441 | * @param array $template Template details. |
| 1623 | 1442 | * @param array $args Additional arguments. |
| 1624 | - * | |
| 1625 | 1443 | * @return array The link attributes. |
| 1626 | 1444 | */ |
| 1627 | 1445 | public static function get_template_install_link( $template, $args ) { |
| 1628 | 1446 | $defaults = array( |
| @@ -1654,9 +1472,8 @@ | ||
| 1654 | 1472 | * |
| 1655 | 1473 | * @since 4.02.02 |
| 1656 | 1474 | * |
| 1657 | 1475 | * @param array $args |
| 1658 | - * | |
| 1659 | 1476 | * @return bool |
| 1660 | 1477 | */ |
| 1661 | 1478 | public static function plan_is_allowed( $args ) { |
| 1662 | 1479 | if ( empty( $args['license_type'] ) ) { |
| @@ -1675,9 +1492,8 @@ | ||
| 1675 | 1492 | foreach ( $plans as $plan ) { |
| 1676 | 1493 | if ( $included || $plan === $license_type ) { |
| 1677 | 1494 | break; |
| 1678 | 1495 | } |
| 1679 | - | |
| 1680 | 1496 | $included = $plan === $plan_required; |
| 1681 | 1497 | } |
| 1682 | 1498 | |
| 1683 | 1499 | return $included; |
| @@ -1687,20 +1503,14 @@ | ||
| 1687 | 1503 | * If a template or add-on cannot be installed, show a message |
| 1688 | 1504 | * about which plan is required. |
| 1689 | 1505 | * |
| 1690 | 1506 | * @since 4.0 |
| 1691 | - * | |
| 1692 | - * @param string $requires | |
| 1693 | - * @param string $link | |
| 1694 | - * | |
| 1695 | - * @return void | |
| 1696 | 1507 | */ |
| 1697 | 1508 | public static function show_plan_required( $requires, $link ) { |
| 1698 | - if ( ! $requires ) { | |
| 1509 | + if ( empty( $requires ) ) { | |
| 1699 | 1510 | return; |
| 1700 | 1511 | } |
| 1701 | 1512 | |
| 1702 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 1703 | 1513 | ?> |
| 1704 | 1514 | <p class="frm_plan_required"> |
| 1705 | 1515 | <?php esc_html_e( 'Plan required:', 'formidable' ); ?> |
| 1706 | 1516 | <a href="<?php echo esc_url( $link ); ?>" target="_blank" rel="noopener"> |
| @@ -1707,9 +1517,8 @@ | ||
| 1707 | 1517 | <?php echo esc_html( $requires ); ?> |
| 1708 | 1518 | </a> |
| 1709 | 1519 | </p> |
| 1710 | 1520 | <?php |
| 1711 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 1712 | 1521 | } |
| 1713 | 1522 | |
| 1714 | 1523 | /** |
| 1715 | 1524 | * @since 4.0 |
| @@ -1714,9 +1523,8 @@ | ||
| 1714 | 1523 | /** |
| 1715 | 1524 | * @since 4.0 |
| 1716 | 1525 | * |
| 1717 | 1526 | * @param array $item |
| 1718 | - * | |
| 1719 | 1527 | * @return false|string |
| 1720 | 1528 | */ |
| 1721 | 1529 | public static function get_plan_required( &$item ) { |
| 1722 | 1530 | if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) { |
| @@ -1727,9 +1535,12 @@ | ||
| 1727 | 1535 | |
| 1728 | 1536 | foreach ( $item['categories'] as $k => $category ) { |
| 1729 | 1537 | if ( in_array( $category, $plans, true ) ) { |
| 1730 | 1538 | unset( $item['categories'][ $k ] ); |
| 1731 | - return self::convert_legacy_package_names( $category ); | |
| 1539 | + | |
| 1540 | + $category = self::convert_legacy_package_names( $category ); | |
| 1541 | + | |
| 1542 | + return $category; | |
| 1732 | 1543 | } |
| 1733 | 1544 | } |
| 1734 | 1545 | |
| 1735 | 1546 | return false; |
| @@ -1738,16 +1549,14 @@ | ||
| 1738 | 1549 | /** |
| 1739 | 1550 | * Converts legacy package names to the current standard package name. |
| 1740 | 1551 | * |
| 1741 | 1552 | * @since 6.15 |
| 1742 | - * | |
| 1743 | 1553 | * @param string $package_name |
| 1744 | - * | |
| 1745 | 1554 | * @return string The updated package name. |
| 1746 | 1555 | */ |
| 1747 | 1556 | public static function convert_legacy_package_names( $package_name ) { |
| 1748 | 1557 | if ( in_array( $package_name, array( 'Creator', 'Personal' ), true ) ) { |
| 1749 | - return 'Plus'; | |
| 1558 | + $package_name = 'Plus'; | |
| 1750 | 1559 | } |
| 1751 | 1560 | |
| 1752 | 1561 | return $package_name; |
| 1753 | 1562 | } |
| @@ -1757,17 +1566,17 @@ | ||
| 1757 | 1566 | * |
| 1758 | 1567 | * @since 6.15 |
| 1759 | 1568 | * |
| 1760 | 1569 | * @param array $args |
| 1761 | - * | |
| 1762 | 1570 | * @return array |
| 1763 | 1571 | */ |
| 1764 | 1572 | public static function get_license_types( $args = array() ) { |
| 1765 | - $defaults = array( | |
| 1573 | + $defaults = array( | |
| 1766 | 1574 | 'include_all' => true, |
| 1767 | 1575 | 'case_lower' => false, |
| 1768 | 1576 | ); |
| 1769 | - $args = wp_parse_args( $args, $defaults ); | |
| 1577 | + $args = wp_parse_args( $args, $defaults ); | |
| 1578 | + | |
| 1770 | 1579 | $license_types = array( 'Basic', 'Plus', 'Business', 'Elite' ); |
| 1771 | 1580 | |
| 1772 | 1581 | if ( $args['include_all'] ) { |
| 1773 | 1582 | $license_types = array_merge( array( 'free', 'Personal', 'Creator' ), $license_types ); |
| @@ -1773,9 +1582,9 @@ | ||
| 1773 | 1582 | $license_types = array_merge( array( 'free', 'Personal', 'Creator' ), $license_types ); |
| 1774 | 1583 | } |
| 1775 | 1584 | |
| 1776 | 1585 | if ( $args['case_lower'] ) { |
| 1777 | - return array_map( 'strtolower', $license_types ); | |
| 1586 | + $license_types = array_map( 'strtolower', $license_types ); | |
| 1778 | 1587 | } |
| 1779 | 1588 | |
| 1780 | 1589 | return $license_types; |
| 1781 | 1590 | } |
| @@ -1789,9 +1598,10 @@ | ||
| 1789 | 1598 | * |
| 1790 | 1599 | * @return array An array of warnings or an empty array. |
| 1791 | 1600 | */ |
| 1792 | 1601 | public static function check_for_warnings( $values ) { |
| 1793 | - $warnings = array(); | |
| 1602 | + $warnings = array(); | |
| 1603 | + | |
| 1794 | 1604 | $redirect_warning = self::check_redirect_url_for_unsafe_params( $values ); |
| 1795 | 1605 | |
| 1796 | 1606 | if ( $redirect_warning ) { |
| 1797 | 1607 | $warnings[] = $redirect_warning; |
| @@ -1836,16 +1646,15 @@ | ||
| 1836 | 1646 | * @return array An array of params whose names are reserved words or an empty array. |
| 1837 | 1647 | */ |
| 1838 | 1648 | private static function get_unsafe_params( $url ) { |
| 1839 | 1649 | $redirect_components = parse_url( $url ); |
| 1840 | - | |
| 1841 | 1650 | if ( empty( $redirect_components['query'] ) ) { |
| 1842 | 1651 | return array(); |
| 1843 | 1652 | } |
| 1844 | - | |
| 1845 | 1653 | parse_str( $redirect_components['query'], $redirect_params ); |
| 1846 | 1654 | $redirect_param_names = array_keys( $redirect_params ); |
| 1847 | - $unsafe_params_in_redirect = array_intersect( $redirect_param_names, self::reserved_words() ); | |
| 1655 | + $reserved_words = self::reserved_words(); | |
| 1656 | + $unsafe_params_in_redirect = array_intersect( $redirect_param_names, $reserved_words ); | |
| 1848 | 1657 | |
| 1849 | 1658 | return array_values( $unsafe_params_in_redirect ); |
| 1850 | 1659 | } |
| 1851 | 1660 | |
| @@ -1858,27 +1667,26 @@ | ||
| 1858 | 1667 | * |
| 1859 | 1668 | * @return bool|string A string with an unsafe param message or false. |
| 1860 | 1669 | */ |
| 1861 | 1670 | private static function create_unsafe_param_warning( $unsafe_params_in_redirect ) { |
| 1862 | - $count = count( $unsafe_params_in_redirect ); | |
| 1671 | + $count = count( $unsafe_params_in_redirect ); | |
| 1672 | + $caution = esc_html__( 'Is this intentional?', 'formidable' ); | |
| 1673 | + $reserved_words_intro = esc_html__( 'See the list of reserved words in WordPress.', 'formidable' ); | |
| 1674 | + $reserved_words_link = '<a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank"> ' . $reserved_words_intro . '</a>'; | |
| 1863 | 1675 | |
| 1864 | 1676 | if ( $count === 0 ) { |
| 1865 | 1677 | return false; |
| 1866 | 1678 | } |
| 1867 | 1679 | |
| 1868 | - $caution = esc_html__( 'Is this intentional?', 'formidable' ); | |
| 1869 | - $reserved_words_intro = esc_html__( 'See the list of reserved words in WordPress.', 'formidable' ); | |
| 1870 | - $reserved_words_link = '<a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank"> ' . $reserved_words_intro . '</a>'; | |
| 1871 | - | |
| 1872 | - if ( $count === 1 ) { | |
| 1680 | + if ( $count == 1 ) { | |
| 1873 | 1681 | /* translators: %s: the name of a single parameter in the redirect URL */ |
| 1874 | - return sprintf( esc_html__( 'The redirect URL is using the parameter "%s", which is reserved by WordPress. ', 'formidable' ), $unsafe_params_in_redirect[0] ) . $caution . $reserved_words_link; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 1682 | + return sprintf( esc_html__( 'The redirect URL is using the parameter "%s", which is reserved by WordPress. ', 'formidable' ), $unsafe_params_in_redirect[0] ) . $caution . $reserved_words_link; | |
| 1875 | 1683 | } |
| 1876 | 1684 | |
| 1877 | 1685 | $unsafe_params_string = implode( '", "', $unsafe_params_in_redirect ); |
| 1878 | 1686 | |
| 1879 | 1687 | /* translators: %s: the names of two or more parameters in the redirect URL, separated by commas */ |
| 1880 | - return sprintf( esc_html__( 'The redirect URL is using the parameters "%s", which are reserved by WordPress. ', 'formidable' ), $unsafe_params_string ) . $caution . $reserved_words_link; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 1688 | + return sprintf( esc_html__( 'The redirect URL is using the parameters "%s", which are reserved by WordPress. ', 'formidable' ), $unsafe_params_string ) . $caution . $reserved_words_link; | |
| 1881 | 1689 | } |
| 1882 | 1690 | |
| 1883 | 1691 | /** |
| 1884 | 1692 | * Returns an array of common reserved words in WordPress. |
| @@ -1944,19 +1752,17 @@ | ||
| 1944 | 1752 | * @since 5.0.16 |
| 1945 | 1753 | * |
| 1946 | 1754 | * @param string $url |
| 1947 | 1755 | * @param int $form_id |
| 1948 | - * | |
| 1949 | 1756 | * @return string |
| 1950 | 1757 | */ |
| 1951 | 1758 | public static function maybe_add_sanitize_url_attr( $url, $form_id ) { |
| 1952 | - if ( ! str_contains( $url, '[' ) ) { | |
| 1759 | + if ( false === strpos( $url, '[' ) ) { | |
| 1953 | 1760 | // Do nothing if no shortcodes are detected. |
| 1954 | 1761 | return $url; |
| 1955 | 1762 | } |
| 1956 | 1763 | |
| 1957 | 1764 | $parsed = wp_parse_url( $url ); |
| 1958 | - | |
| 1959 | 1765 | if ( empty( $parsed['query'] ) ) { |
| 1960 | 1766 | // Do nothing if no query can be detected in the url string. |
| 1961 | 1767 | return $url; |
| 1962 | 1768 | } |
| @@ -1962,10 +1768,10 @@ | ||
| 1962 | 1768 | } |
| 1963 | 1769 | |
| 1964 | 1770 | $original_query = $parsed['query']; |
| 1965 | 1771 | $query = $parsed['query']; |
| 1966 | - $shortcodes = FrmFieldsHelper::get_shortcodes( $query, $form_id ); | |
| 1967 | 1772 | |
| 1773 | + $shortcodes = FrmFieldsHelper::get_shortcodes( $query, $form_id ); | |
| 1968 | 1774 | if ( empty( $shortcodes[0] ) ) { |
| 1969 | 1775 | // No shortcodes found, do nothing. |
| 1970 | 1776 | return $url; |
| 1971 | 1777 | } |
| @@ -1977,21 +1783,20 @@ | ||
| 1977 | 1783 | // Skip if shortcodes. |
| 1978 | 1784 | continue; |
| 1979 | 1785 | } |
| 1980 | 1786 | |
| 1981 | - if ( str_contains( $options, 'sanitize_url=' ) || str_contains( $options, 'sanitize=' ) ) { | |
| 1787 | + if ( false !== strpos( $options, 'sanitize_url=' ) || false !== strpos( $options, 'sanitize=' ) ) { | |
| 1982 | 1788 | // A sanitize option is already set so leave it alone. |
| 1983 | 1789 | continue; |
| 1984 | 1790 | } |
| 1985 | 1791 | |
| 1986 | 1792 | $new_shortcode = '[' . $shortcodes[2][ $key ]; |
| 1987 | - | |
| 1988 | 1793 | if ( $options ) { |
| 1989 | 1794 | $new_shortcode .= ' ' . $options; |
| 1990 | 1795 | } |
| 1796 | + $new_shortcode .= ' sanitize_url=1]'; | |
| 1991 | 1797 | |
| 1992 | - $new_shortcode .= ' sanitize_url=1]'; | |
| 1993 | - $query = str_replace( $shortcode, $new_shortcode, $query ); | |
| 1798 | + $query = str_replace( $shortcode, $new_shortcode, $query ); | |
| 1994 | 1799 | }//end foreach |
| 1995 | 1800 | |
| 1996 | 1801 | if ( $query === $original_query ) { |
| 1997 | 1802 | return $url; |
| @@ -2022,9 +1827,8 @@ | ||
| 2022 | 1827 | * |
| 2023 | 1828 | * @since 6.16 |
| 2024 | 1829 | * |
| 2025 | 1830 | * @param string $classname |
| 2026 | - * | |
| 2027 | 1831 | * @return string |
| 2028 | 1832 | */ |
| 2029 | 1833 | public static function sanitize_layout_class( $classname ) { |
| 2030 | 1834 | // Strip out any percent-encoded characters. |
| @@ -2030,9 +1834,11 @@ | ||
| 2030 | 1834 | // Strip out any percent-encoded characters. |
| 2031 | 1835 | $sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $classname ); |
| 2032 | 1836 | |
| 2033 | 1837 | // Limit to A-Z, a-z, 0-9, '_', '-', '[', ']'. |
| 2034 | - return preg_replace( '/[^A-Za-z0-9_\-\[\]]/', '', $sanitized ); | |
| 1838 | + $sanitized = preg_replace( '/[^A-Za-z0-9_\-\[\]]/', '', $sanitized ); | |
| 1839 | + | |
| 1840 | + return $sanitized; | |
| 2035 | 1841 | } |
| 2036 | 1842 | |
| 2037 | 1843 | /** |
| 2038 | 1844 | * Returns true if the preview should be blocked. |
| @@ -2039,13 +1845,12 @@ | ||
| 2039 | 1845 | * |
| 2040 | 1846 | * @since 6.20 |
| 2041 | 1847 | * |
| 2042 | 1848 | * @param string $form_key |
| 2043 | - * | |
| 2044 | 1849 | * @return bool |
| 2045 | 1850 | */ |
| 2046 | 1851 | public static function should_block_preview( $form_key ) { |
| 2047 | - $should_block = in_array( $form_key, array( 'contact-form', 'contact-us' ), true ) && ! current_user_can( 'frm_view_forms' ); | |
| 1852 | + $should_block = 'contact-form' === $form_key && ! current_user_can( 'frm_view_forms' ); | |
| 2048 | 1853 | /** |
| 2049 | 1854 | * Filters whether the form preview should be blocked. |
| 2050 | 1855 | * |
| 2051 | 1856 | * @since 6.20 |
| @@ -2052,9 +1857,10 @@ | ||
| 2052 | 1857 | * |
| 2053 | 1858 | * @param bool $should_block |
| 2054 | 1859 | * @param string $form_key |
| 2055 | 1860 | */ |
| 2056 | - return (bool) apply_filters( 'frm_block_preview', $should_block, $form_key ); | |
| 1861 | + $should_block = (bool) apply_filters( 'frm_block_preview', $should_block, $form_key ); | |
| 1862 | + return $should_block; | |
| 2057 | 1863 | } |
| 2058 | 1864 | |
| 2059 | 1865 | /** |
| 2060 | 1866 | * Checks if the form is loaded by API. |
| @@ -2063,29 +1869,12 @@ | ||
| 2063 | 1869 | * |
| 2064 | 1870 | * @return bool |
| 2065 | 1871 | */ |
| 2066 | 1872 | public static function form_is_loaded_by_api() { |
| 2067 | - global $frm_vars; | |
| 2068 | - | |
| 2069 | - if ( ! empty( $frm_vars['inplace_edit'] ) ) { | |
| 2070 | - return true; | |
| 2071 | - } | |
| 2072 | - | |
| 2073 | - return self::is_formidable_api_form() || self::is_block_or_page_builder_preview(); | |
| 1873 | + return self::is_formidable_api_form() || self::is_gutenberg_editor() || self::is_elementor_ajax() || self::is_visual_views_preview(); | |
| 2074 | 1874 | } |
| 2075 | 1875 | |
| 2076 | 1876 | /** |
| 2077 | - * Checks if the form is rendered inside a block editor or page builder preview. | |
| 2078 | - * | |
| 2079 | - * @since 6.29 | |
| 2080 | - * | |
| 2081 | - * @return bool | |
| 2082 | - */ | |
| 2083 | - public static function is_block_or_page_builder_preview() { | |
| 2084 | - return self::is_gutenberg_editor() || self::is_elementor_ajax() || self::is_visual_views_preview(); | |
| 2085 | - } | |
| 2086 | - | |
| 2087 | - /** | |
| 2088 | 1877 | * @since 6.21 |
| 2089 | 1878 | * |
| 2090 | 1879 | * @return bool |
| 2091 | 1880 | */ |
| @@ -2108,19 +1897,18 @@ | ||
| 2108 | 1897 | * @return bool |
| 2109 | 1898 | */ |
| 2110 | 1899 | private static function is_gutenberg_editor() { |
| 2111 | 1900 | $url = FrmAppHelper::get_server_value( 'REQUEST_URI' ); |
| 2112 | - | |
| 2113 | - if ( str_contains( $url, '/wp-json/wp/v2/block-renderer/formidable/simple-form' ) ) { | |
| 1901 | + if ( false !== strpos( $url, '/wp-json/wp/v2/block-renderer/formidable/simple-form' ) ) { | |
| 2114 | 1902 | return true; |
| 2115 | 1903 | } |
| 2116 | 1904 | |
| 2117 | - if ( str_contains( urldecode( $url ), 'rest_route=/wp/v2/block-renderer/formidable/' ) ) { | |
| 1905 | + global $pagenow; | |
| 1906 | + if ( 'post.php' === $pagenow ) { | |
| 2118 | 1907 | return true; |
| 2119 | 1908 | } |
| 2120 | 1909 | |
| 2121 | - global $pagenow; | |
| 2122 | - return 'post.php' === $pagenow; | |
| 1910 | + return false; | |
| 2123 | 1911 | } |
| 2124 | 1912 | |
| 2125 | 1913 | /** |
| 2126 | 1914 | * @since 6.21 |
| @@ -2132,10 +1920,9 @@ | ||
| 2132 | 1920 | return false; |
| 2133 | 1921 | } |
| 2134 | 1922 | |
| 2135 | 1923 | $url = FrmAppHelper::get_server_value( 'REQUEST_URI' ); |
| 2136 | - | |
| 2137 | - if ( str_contains( $url, '/wp-json/frm/v2/forms/' ) ) { | |
| 1924 | + if ( false !== strpos( $url, '/wp-json/frm/v2/forms/' ) ) { | |
| 2138 | 1925 | // Prevent the honeypot from appearing for an API loaded form. |
| 2139 | 1926 | // This is to prevent conflicts where the script is not working. |
| 2140 | 1927 | return true; |
| 2141 | 1928 | } |
| @@ -2151,46 +1938,38 @@ | ||
| 2151 | 1938 | return false; |
| 2152 | 1939 | } |
| 2153 | 1940 | |
| 2154 | 1941 | /** |
| 2155 | - * @since 6.30 | |
| 1942 | + * @since 3.0 | |
| 1943 | + * @deprecated 6.11 | |
| 2156 | 1944 | * |
| 1945 | + * @param array $atts | |
| 2157 | 1946 | * @return void |
| 2158 | 1947 | */ |
| 2159 | - public static function load_currency_js() { | |
| 2160 | - global $frm_vars; | |
| 1948 | + public static function actions_dropdown( $atts ) { | |
| 1949 | + _deprecated_function( __METHOD__, '6.11' ); | |
| 2161 | 1950 | |
| 2162 | - if ( empty( $frm_vars['currency'] ) ) { | |
| 1951 | + if ( ! FrmAppHelper::is_admin_page( 'formidable' ) ) { | |
| 2163 | 1952 | return; |
| 2164 | 1953 | } |
| 2165 | 1954 | |
| 2166 | - echo '<script>'; | |
| 2167 | - echo 'var frmcurrency=' . json_encode( $frm_vars['currency'] ) . ";\n"; | |
| 2168 | - echo 'if(typeof __FRMCURR == "undefined"){__FRMCURR=frmcurrency;}'; | |
| 2169 | - echo 'else{__FRMCURR=jQuery.extend(true,{},__FRMCURR,frmcurrency);}'; | |
| 2170 | - echo '</script>'; | |
| 1955 | + $status = $atts['status']; | |
| 1956 | + $form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); | |
| 1957 | + $trash_link = self::delete_trash_info( $form_id, $status ); | |
| 1958 | + $links = self::get_action_links( $form_id, $status ); | |
| 1959 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php'; | |
| 2171 | 1960 | } |
| 2172 | 1961 | |
| 2173 | 1962 | /** |
| 2174 | - * Returns the form name or the no title text if the form name is empty. | |
| 1963 | + * Check if Pro isn't up to date yet. | |
| 1964 | + * If Pro is active but using a version earlier than v6.2 fallback to Pro for AJAX submit (so things don't all happen twice). | |
| 2175 | 1965 | * |
| 2176 | - * @since 6.30 | |
| 1966 | + * @since 6.2 | |
| 1967 | + * @deprecated 6.20 | |
| 2177 | 1968 | * |
| 2178 | - * @param array|stdClass $form The form data. | |
| 2179 | - * @param int $length The form name length to truncate to. | |
| 2180 | - * | |
| 2181 | - * @return string | |
| 1969 | + * @return bool | |
| 2182 | 1970 | */ |
| 2183 | - public static function get_form_name( $form, $length = 0 ) { | |
| 2184 | - $form_name = is_object( $form ) ? $form->name : $form['name']; | |
| 2185 | - | |
| 2186 | - if ( '' === $form_name || null === $form_name ) { | |
| 2187 | - return self::get_no_title_text(); | |
| 2188 | - } | |
| 2189 | - | |
| 2190 | - if ( ! $length ) { | |
| 2191 | - return $form_name; | |
| 2192 | - } | |
| 2193 | - | |
| 2194 | - return FrmAppHelper::truncate( $form_name, $length ); | |
| 1971 | + public static function should_use_pro_for_ajax_submit() { | |
| 1972 | + _deprecated_function( __METHOD__, '6.20' ); | |
| 1973 | + return false; | |
| 2195 | 1974 | } |
| 2196 | 1975 | } |