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