| @@ -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 ? __( '(no title)', 'formidable' ) : 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 | } |
| @@ -152,12 +126,11 @@ | ||
| 152 | 126 | $selected = $selected->name; |
| 153 | 127 | } |
| 154 | 128 | |
| 155 | 129 | $name = $selected === false ? __( 'Switch Form', 'formidable' ) : $selected; |
| 156 | - $name = '' === $name || is_null( $name ) ? self::get_no_title_text() : strip_tags( $name ); | |
| 130 | + $name = '' === $name ? __( '(no title)', 'formidable' ) : 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 ) ? __( '(no title)', 'formidable' ) : $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,43 +206,39 @@ | ||
| 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 |
| 255 | - * | |
| 256 | - * @param array|string $field_type | |
| 257 | - * | |
| 258 | - * @return string | |
| 259 | 219 | */ |
| 260 | 220 | public static function get_field_link_name( $field_type ) { |
| 261 | - return is_array( $field_type ) ? $field_type['name'] : $field_type; | |
| 221 | + if ( is_array( $field_type ) ) { | |
| 222 | + $field_label = $field_type['name']; | |
| 223 | + } else { | |
| 224 | + $field_label = $field_type; | |
| 225 | + } | |
| 226 | + | |
| 227 | + return $field_label; | |
| 262 | 228 | } |
| 263 | 229 | |
| 264 | 230 | /** |
| 265 | 231 | * @since 3.0 |
| 266 | - * | |
| 267 | - * @param array|string $field_type | |
| 268 | - * | |
| 269 | - * @return string | |
| 270 | 232 | */ |
| 271 | 233 | 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'; | |
| 234 | + if ( is_array( $field_type ) && isset( $field_type['icon'] ) ) { | |
| 235 | + $icon = $field_type['icon']; | |
| 236 | + } else { | |
| 237 | + $icon = 'frm_icon_font frm_pencil_icon'; | |
| 238 | + } | |
| 239 | + | |
| 240 | + return $icon; | |
| 273 | 241 | } |
| 274 | 242 | |
| 275 | 243 | /** |
| 276 | 244 | * Get the invalid form error message |
| @@ -282,9 +250,8 @@ | ||
| 282 | 250 | * @return string |
| 283 | 251 | */ |
| 284 | 252 | public static function get_invalid_error_message( $args ) { |
| 285 | 253 | $settings_args = $args; |
| 286 | - | |
| 287 | 254 | if ( isset( $args['form'] ) ) { |
| 288 | 255 | $settings_args['current_form'] = $args['form']->id; |
| 289 | 256 | } |
| 290 | 257 | |
| @@ -301,48 +268,24 @@ | ||
| 301 | 268 | * @type stdClass $form |
| 302 | 269 | * @type int $entry_id |
| 303 | 270 | * @type string $class |
| 304 | 271 | * } |
| 305 | - * | |
| 306 | 272 | * @return string |
| 307 | 273 | */ |
| 308 | 274 | public static function get_success_message( $atts ) { |
| 309 | 275 | $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>'; | |
| 276 | + $message = do_shortcode( FrmAppHelper::use_wpautop( $message ) ); | |
| 277 | + $message = '<div class="' . esc_attr( $atts['class'] ) . '" role="status">' . $message . '</div>'; | |
| 278 | + return $message; | |
| 332 | 279 | } |
| 333 | 280 | |
| 334 | 281 | /** |
| 335 | 282 | * Used when a form is created |
| 336 | - * | |
| 337 | - * @param array $values | |
| 338 | - * | |
| 339 | - * @return array | |
| 340 | 283 | */ |
| 341 | 284 | public static function setup_new_vars( $values = array() ) { |
| 342 | 285 | global $wpdb; |
| 343 | 286 | |
| 344 | - if ( $values ) { | |
| 287 | + if ( ! empty( $values ) ) { | |
| 345 | 288 | $post_values = $values; |
| 346 | 289 | } else { |
| 347 | 290 | $values = array(); |
| 348 | 291 | $post_values = ! empty( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| @@ -351,9 +294,8 @@ | ||
| 351 | 294 | $defaults = array( |
| 352 | 295 | 'name' => '', |
| 353 | 296 | 'description' => '', |
| 354 | 297 | ); |
| 355 | - | |
| 356 | 298 | foreach ( $defaults as $var => $default ) { |
| 357 | 299 | if ( ! isset( $values[ $var ] ) ) { |
| 358 | 300 | $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
| 359 | 301 | } |
| @@ -368,9 +310,8 @@ | ||
| 368 | 310 | 'is_template' => 0, |
| 369 | 311 | 'status' => 'published', |
| 370 | 312 | 'parent_form_id' => 0, |
| 371 | 313 | ); |
| 372 | - | |
| 373 | 314 | foreach ( $defaults as $var => $default ) { |
| 374 | 315 | if ( ! isset( $values[ $var ] ) ) { |
| 375 | 316 | $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
| 376 | 317 | } |
| @@ -377,9 +318,9 @@ | ||
| 377 | 318 | } |
| 378 | 319 | unset( $defaults ); |
| 379 | 320 | |
| 380 | 321 | 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 | |
| 322 | + $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 | 323 | } |
| 383 | 324 | |
| 384 | 325 | $values = self::fill_default_opts( $values, false, $post_values ); |
| 385 | 326 | $values['custom_style'] = FrmAppHelper::custom_style_value( $post_values ); |
| @@ -388,22 +329,16 @@ | ||
| 388 | 329 | } |
| 389 | 330 | |
| 390 | 331 | /** |
| 391 | 332 | * Used when editing a form |
| 392 | - * | |
| 393 | - * @param array $values | |
| 394 | - * @param object $record | |
| 395 | - * @param array $post_values | |
| 396 | - * | |
| 397 | - * @return array | |
| 398 | 333 | */ |
| 399 | 334 | public static function setup_edit_vars( $values, $record, $post_values = array() ) { |
| 400 | - if ( ! $post_values ) { | |
| 335 | + if ( empty( $post_values ) ) { | |
| 401 | 336 | $post_values = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 402 | 337 | } |
| 403 | 338 | |
| 404 | - $values['form_key'] = $post_values['form_key'] ?? $record->form_key; | |
| 405 | - $values['is_template'] = $post_values['is_template'] ?? $record->is_template; | |
| 339 | + $values['form_key'] = isset( $post_values['form_key'] ) ? $post_values['form_key'] : $record->form_key; | |
| 340 | + $values['is_template'] = isset( $post_values['is_template'] ) ? $post_values['is_template'] : $record->is_template; | |
| 406 | 341 | $values['status'] = $record->status; |
| 407 | 342 | |
| 408 | 343 | $values = self::fill_default_opts( $values, $record, $post_values ); |
| 409 | 344 | |
| @@ -409,18 +344,12 @@ | ||
| 409 | 344 | |
| 410 | 345 | return apply_filters( 'frm_setup_edit_form_vars', $values ); |
| 411 | 346 | } |
| 412 | 347 | |
| 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 | |
| 348 | + public static function fill_default_opts( $values, $record, $post_values ) { | |
| 421 | 349 | |
| 422 | - foreach ( self::get_default_opts() as $var => $default ) { | |
| 350 | + $defaults = self::get_default_opts(); | |
| 351 | + foreach ( $defaults as $var => $default ) { | |
| 423 | 352 | if ( is_array( $default ) ) { |
| 424 | 353 | if ( ! isset( $values[ $var ] ) ) { |
| 425 | 354 | $values[ $var ] = $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : array(); |
| 426 | 355 | } |
| @@ -425,13 +354,13 @@ | ||
| 425 | 354 | $values[ $var ] = $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : array(); |
| 426 | 355 | } |
| 427 | 356 | |
| 428 | 357 | 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 | |
| 358 | + $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 | 359 | |
| 431 | 360 | if ( is_array( $v ) ) { |
| 432 | 361 | 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 | |
| 362 | + $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 | 363 | unset( $k1, $v1 ); |
| 435 | 364 | } |
| 436 | 365 | } |
| 437 | 366 | |
| @@ -437,9 +366,9 @@ | ||
| 437 | 366 | |
| 438 | 367 | unset( $k, $v ); |
| 439 | 368 | } |
| 440 | 369 | } 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 | |
| 370 | + $values[ $var ] = $post_values && isset( $post_values['options'][ $var ] ) ? $post_values['options'][ $var ] : ( $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : $default ); | |
| 442 | 371 | } |
| 443 | 372 | |
| 444 | 373 | unset( $var, $default ); |
| 445 | 374 | }//end foreach |
| @@ -458,9 +387,9 @@ | ||
| 458 | 387 | 'success_action' => 'message', |
| 459 | 388 | 'success_msg' => $frm_settings->success_msg, |
| 460 | 389 | 'show_form' => 0, |
| 461 | 390 | 'akismet' => '', |
| 462 | - 'stopforumspam' => 0, | |
| 391 | + 'honeypot' => 'basic', | |
| 463 | 392 | 'antispam' => 0, |
| 464 | 393 | 'no_save' => 0, |
| 465 | 394 | 'ajax_load' => 0, |
| 466 | 395 | 'js_validate' => 0, |
| @@ -476,17 +405,15 @@ | ||
| 476 | 405 | } |
| 477 | 406 | |
| 478 | 407 | /** |
| 479 | 408 | * @since 2.0.6 |
| 480 | - * | |
| 481 | 409 | * @param array $options |
| 482 | 410 | * @param array $values |
| 483 | - * | |
| 484 | - * @return void | |
| 485 | 411 | */ |
| 486 | 412 | public static function fill_form_options( &$options, $values ) { |
| 487 | - foreach ( self::get_default_opts() as $var => $default ) { | |
| 488 | - $options[ $var ] = $values['options'][ $var ] ?? $default; | |
| 413 | + $defaults = self::get_default_opts(); | |
| 414 | + foreach ( $defaults as $var => $default ) { | |
| 415 | + $options[ $var ] = isset( $values['options'][ $var ] ) ? $values['options'][ $var ] : $default; | |
| 489 | 416 | unset( $var, $default ); |
| 490 | 417 | } |
| 491 | 418 | } |
| 492 | 419 | |
| @@ -491,10 +418,8 @@ | ||
| 491 | 418 | } |
| 492 | 419 | |
| 493 | 420 | /** |
| 494 | 421 | * @param string $loc |
| 495 | - * | |
| 496 | - * @return string | |
| 497 | 422 | */ |
| 498 | 423 | public static function get_default_html( $loc ) { |
| 499 | 424 | if ( $loc === 'submit' ) { |
| 500 | 425 | $draft_link = self::get_draft_link(); |
| @@ -519,13 +444,12 @@ | ||
| 519 | 444 | |
| 520 | 445 | return $default_html; |
| 521 | 446 | } |
| 522 | 447 | |
| 523 | - /** | |
| 524 | - * @return string | |
| 525 | - */ | |
| 526 | 448 | public static function get_draft_link() { |
| 527 | - return '[if save_draft]<button class="frm_save_draft" [draft_hook]>[draft_label]</button>[/if save_draft]'; | |
| 449 | + $link = '[if save_draft]<button class="frm_save_draft" [draft_hook]>[draft_label]</button>[/if save_draft]'; | |
| 450 | + | |
| 451 | + return $link; | |
| 528 | 452 | } |
| 529 | 453 | |
| 530 | 454 | /** |
| 531 | 455 | * Gets start over button shortcode. |
| @@ -537,21 +461,11 @@ | ||
| 537 | 461 | public static function get_start_over_shortcode() { |
| 538 | 462 | return '[if start_over]<a href="#" tabindex="0" class="frm_start_over" [start_over_hook]>[start_over_label]</a>[/if start_over]'; |
| 539 | 463 | } |
| 540 | 464 | |
| 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 | 465 | public static function get_custom_submit( $html, $form, $submit, $form_action, $values ) { |
| 551 | 466 | $button = self::replace_shortcodes( $html, $form, $submit, $form_action, $values ); |
| 552 | - | |
| 553 | - if ( ! str_contains( $button, '[button_action]' ) ) { | |
| 467 | + if ( ! strpos( $button, '[button_action]' ) ) { | |
| 554 | 468 | echo FrmAppHelper::maybe_kses( $button ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 555 | 469 | return; |
| 556 | 470 | } |
| 557 | 471 | |
| @@ -558,20 +472,17 @@ | ||
| 558 | 472 | /** |
| 559 | 473 | * @since 5.0.06 |
| 560 | 474 | */ |
| 561 | 475 | $button = apply_filters( 'frm_submit_button_html', $button, compact( 'form' ) ); |
| 562 | - | |
| 563 | 476 | if ( FrmAppHelper::should_never_allow_unfiltered_html() ) { |
| 564 | 477 | $button = FrmAppHelper::kses_submit_button( $button ); |
| 565 | 478 | } |
| 566 | - | |
| 567 | 479 | $button_parts = explode( '[button_action]', $button ); |
| 568 | - $classes = apply_filters( 'frm_submit_button_class', array(), $form ); | |
| 569 | 480 | |
| 570 | - if ( $classes ) { | |
| 481 | + $classes = apply_filters( 'frm_submit_button_class', array(), $form ); | |
| 482 | + if ( ! empty( $classes ) ) { | |
| 571 | 483 | $classes = implode( ' ', $classes ); |
| 572 | 484 | $button_class = 'frm_button_submit'; |
| 573 | - | |
| 574 | 485 | if ( preg_match( '/\bclass="[^"]*?\b' . preg_quote( $button_class, '/' ) . '\b[^"]*?"/', $button_parts[0] ) ) { |
| 575 | 486 | $button_parts[0] = str_replace( $button_class, $button_class . ' ' . esc_attr( $classes ), $button_parts[0] ); |
| 576 | 487 | } else { |
| 577 | 488 | $button_parts[0] .= ' class="' . esc_attr( $classes ) . '"'; |
| @@ -584,10 +495,8 @@ | ||
| 584 | 495 | } |
| 585 | 496 | |
| 586 | 497 | /** |
| 587 | 498 | * @since 4.0 |
| 588 | - * | |
| 589 | - * @return array | |
| 590 | 499 | */ |
| 591 | 500 | public static function html_shortcodes() { |
| 592 | 501 | $codes = array( |
| 593 | 502 | 'id' => array( |
| @@ -673,19 +582,15 @@ | ||
| 673 | 582 | |
| 674 | 583 | /** |
| 675 | 584 | * @since 4.0 |
| 676 | 585 | * |
| 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 | - * | |
| 586 | + * @param array $args | |
| 682 | 587 | * @return void |
| 683 | 588 | */ |
| 684 | 589 | public static function insert_opt_html( $args ) { |
| 685 | - $class = $args['class'] ?? ''; | |
| 590 | + $class = isset( $args['class'] ) ? $args['class'] : ''; | |
| 686 | 591 | $fields = self::get_field_type_data_for_insert_opt_html(); |
| 687 | - $field = $fields[ $args['type'] ] ?? array(); | |
| 592 | + $field = isset( $fields[ $args['type'] ] ) ? $fields[ $args['type'] ] : array(); | |
| 688 | 593 | |
| 689 | 594 | self::prepare_field_type( $field ); |
| 690 | 595 | |
| 691 | 596 | if ( ! isset( $field['icon'] ) ) { |
| @@ -692,9 +597,8 @@ | ||
| 692 | 597 | $field['icon'] = 'frmfont frm_pencil_icon'; |
| 693 | 598 | } |
| 694 | 599 | |
| 695 | 600 | $possible_email_field = FrmFieldFactory::field_has_property( $args['type'], 'holds_email_values' ); |
| 696 | - | |
| 697 | 601 | if ( $possible_email_field ) { |
| 698 | 602 | $class .= ' show_frm_not_email_to'; |
| 699 | 603 | } |
| 700 | 604 | |
| @@ -701,45 +605,38 @@ | ||
| 701 | 605 | if ( 'url' === $args['type'] ) { |
| 702 | 606 | $class .= ' frm_insert_url'; |
| 703 | 607 | } |
| 704 | 608 | |
| 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 | |
| 609 | + $truncated_name = FrmAppHelper::truncate( $args['name'], 60 ); | |
| 610 | + if ( isset( $field['icon'] ) ) { | |
| 611 | + $icon = FrmAppHelper::icon_by_class( | |
| 612 | + $field['icon'], | |
| 613 | + array( | |
| 614 | + 'aria-hidden' => 'true', | |
| 615 | + 'echo' => false, | |
| 616 | + ) | |
| 617 | + ); | |
| 618 | + } else { | |
| 619 | + $icon = ''; | |
| 620 | + } | |
| 709 | 621 | ?> |
| 710 | 622 | <li class="<?php echo esc_attr( $class ); ?>"> |
| 711 | 623 | <a href="javascript:void(0)" class="frmids frm_insert_code" data-code="<?php echo esc_attr( $args['id'] ); ?>"> |
| 712 | 624 | <?php |
| 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 | - ); | |
| 625 | + echo FrmAppHelper::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 626 | + echo esc_html( $truncated_name ); | |
| 722 | 627 | ?> |
| 723 | - <span>[<?php echo esc_html( $args['id_label'] ?? $args['id'] ); ?>]</span> | |
| 628 | + <span>[<?php echo esc_attr( isset( $args['id_label'] ) ? $args['id_label'] : $args['id'] ); ?>]</span> | |
| 724 | 629 | </a> |
| 725 | 630 | <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden" data-code="<?php echo esc_attr( $args['key'] ); ?>"> |
| 726 | 631 | <?php |
| 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 | - ); | |
| 632 | + echo FrmAppHelper::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 633 | + echo esc_html( $truncated_name ); | |
| 736 | 634 | ?> |
| 737 | - <span>[<?php echo esc_html( FrmAppHelper::truncate( $args['key_label'] ?? $args['key'], 7 ) . ( $args['key_suffix'] ?? '' ) ); ?>]</span> | |
| 635 | + <span>[<?php echo esc_attr( FrmAppHelper::truncate( isset( $args['key_label'] ) ? $args['key_label'] : $args['key'], 7 ) ); ?>]</span> | |
| 738 | 636 | </a> |
| 739 | 637 | </li> |
| 740 | 638 | <?php |
| 741 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 742 | 639 | } |
| 743 | 640 | |
| 744 | 641 | /** |
| 745 | 642 | * Store and re-use field selection data for use when outputting shortcodes options in shortcode pop up. |
| @@ -757,12 +654,9 @@ | ||
| 757 | 654 | } |
| 758 | 655 | |
| 759 | 656 | /** |
| 760 | 657 | * @since 4.0 |
| 761 | - * | |
| 762 | 658 | * @param array $args |
| 763 | - * | |
| 764 | - * @return void | |
| 765 | 659 | */ |
| 766 | 660 | public static function insert_code_html( $args ) { |
| 767 | 661 | $defaults = array( |
| 768 | 662 | 'class' => '', |
| @@ -773,22 +667,20 @@ | ||
| 773 | 667 | |
| 774 | 668 | $args = array_merge( $defaults, $args ); |
| 775 | 669 | $has_tooltip = ! empty( $args['title'] ); |
| 776 | 670 | |
| 777 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 778 | 671 | ?> |
| 779 | 672 | <li class="<?php echo esc_attr( $args['class'] ); ?>"> |
| 780 | 673 | <a href="javascript:void(0)" class="frm_insert_code <?php echo $has_tooltip ? 'frm_help' : ''; ?>" |
| 781 | 674 | <?php echo $has_tooltip ? 'title="' . esc_attr( $args['title'] ) . '"' : ''; ?> |
| 782 | 675 | data-code="<?php echo esc_attr( $args['code'] ); ?>"> |
| 783 | - <?php echo esc_html( FrmAppHelper::truncate( $args['label'], 60 ) ); ?> | |
| 676 | + <?php echo esc_attr( FrmAppHelper::truncate( $args['label'], 60 ) ); ?> | |
| 784 | 677 | <span> |
| 785 | - [<?php echo esc_html( FrmAppHelper::truncate( $args['code'], 10 ) ); ?>] | |
| 678 | + [<?php echo esc_attr( FrmAppHelper::truncate( $args['code'], 10 ) ); ?>] | |
| 786 | 679 | </span> |
| 787 | 680 | </a> |
| 788 | 681 | </li> |
| 789 | 682 | <?php |
| 790 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 791 | 683 | } |
| 792 | 684 | |
| 793 | 685 | /** |
| 794 | 686 | * Some field types in add-ons may have been added with only |
| @@ -796,9 +688,8 @@ | ||
| 796 | 688 | * |
| 797 | 689 | * @since 4.0 |
| 798 | 690 | * |
| 799 | 691 | * @param array|string $field |
| 800 | - * | |
| 801 | 692 | * @return void |
| 802 | 693 | */ |
| 803 | 694 | public static function prepare_field_type( &$field ) { |
| 804 | 695 | if ( ! is_array( $field ) ) { |
| @@ -803,9 +694,9 @@ | ||
| 803 | 694 | public static function prepare_field_type( &$field ) { |
| 804 | 695 | if ( ! is_array( $field ) ) { |
| 805 | 696 | $field = array( |
| 806 | 697 | 'name' => $field, |
| 807 | - 'icon' => 'frmfont frm_pencil_icon', | |
| 698 | + 'icon' => 'frm_icon_font frm_pencil_icon', | |
| 808 | 699 | ); |
| 809 | 700 | } |
| 810 | 701 | } |
| 811 | 702 | |
| @@ -816,13 +707,11 @@ | ||
| 816 | 707 | * |
| 817 | 708 | * @param object $form |
| 818 | 709 | * @param array $fields |
| 819 | 710 | * @param bool $reset_fields |
| 820 | - * | |
| 821 | - * @return void | |
| 822 | 711 | */ |
| 823 | 712 | public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) { |
| 824 | - if ( ! $fields ) { | |
| 713 | + if ( empty( $fields ) ) { | |
| 825 | 714 | return; |
| 826 | 715 | } |
| 827 | 716 | |
| 828 | 717 | $end_section_values = apply_filters( 'frm_before_field_created', FrmFieldsHelper::setup_new_vars( 'end_divider', $form->id ) ); |
| @@ -829,9 +718,8 @@ | ||
| 829 | 718 | $open = false; |
| 830 | 719 | $prev_order = false; |
| 831 | 720 | $add_order = 0; |
| 832 | 721 | $last_field = false; |
| 833 | - | |
| 834 | 722 | foreach ( $fields as $field ) { |
| 835 | 723 | if ( $prev_order === $field->field_order ) { |
| 836 | 724 | ++$add_order; |
| 837 | 725 | } |
| @@ -874,17 +762,8 @@ | ||
| 874 | 762 | |
| 875 | 763 | /** |
| 876 | 764 | * Create end section field if it doesn't exist. This is for migration from < 2.0 |
| 877 | 765 | * 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 | |
| 887 | 766 | */ |
| 888 | 767 | public static function maybe_create_end_section( &$open, &$reset_fields, &$add_order, $end_section_values, $field, $move = 'no' ) { |
| 889 | 768 | if ( ! $open ) { |
| 890 | 769 | return; |
| @@ -894,9 +773,9 @@ | ||
| 894 | 773 | |
| 895 | 774 | FrmField::create( $end_section_values ); |
| 896 | 775 | |
| 897 | 776 | if ( $move === 'move' ) { |
| 898 | - // Bump the order of current field unless we're at the end of the form | |
| 777 | + // bump the order of current field unless we're at the end of the form | |
| 899 | 778 | FrmField::update( $field->id, array( 'field_order' => $field->field_order + 2 ) ); |
| 900 | 779 | } |
| 901 | 780 | |
| 902 | 781 | $add_order += 2; |
| @@ -903,17 +782,8 @@ | ||
| 903 | 782 | $open = false; |
| 904 | 783 | $reset_fields = true; |
| 905 | 784 | } |
| 906 | 785 | |
| 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 | - */ | |
| 916 | 786 | public static function replace_shortcodes( $html, $form, $title = false, $description = false, $values = array() ) { |
| 917 | 787 | $codes = array( |
| 918 | 788 | 'form_name' => $title, |
| 919 | 789 | 'form_description' => $description, |
| @@ -918,9 +788,8 @@ | ||
| 918 | 788 | 'form_name' => $title, |
| 919 | 789 | 'form_description' => $description, |
| 920 | 790 | 'entry_key' => true, |
| 921 | 791 | ); |
| 922 | - | |
| 923 | 792 | foreach ( $codes as $code => $show ) { |
| 924 | 793 | if ( $code === 'form_name' ) { |
| 925 | 794 | $replace_with = $form->name; |
| 926 | 795 | } elseif ( $code === 'form_description' ) { |
| @@ -925,14 +794,14 @@ | ||
| 925 | 794 | $replace_with = $form->name; |
| 926 | 795 | } elseif ( $code === 'form_description' ) { |
| 927 | 796 | $replace_with = FrmAppHelper::use_wpautop( $form->description ); |
| 928 | 797 | } elseif ( $code === 'entry_key' && ! empty( $_GET ) && isset( $_GET['entry'] ) ) { |
| 929 | - $replace_with = FrmAppHelper::simple_get( 'entry', 'sanitize_title' ); | |
| 798 | + $replace_with = FrmAppHelper::simple_get( 'entry' ); | |
| 930 | 799 | } else { |
| 931 | 800 | $replace_with = ''; |
| 932 | 801 | } |
| 933 | 802 | |
| 934 | - FrmShortcodeHelper::remove_inline_conditions( FrmAppHelper::is_true( $show ) && $replace_with != '', $code, $replace_with, $html ); // phpcs:ignore Universal.Operators.StrictComparisons, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 803 | + FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html ); | |
| 935 | 804 | } |
| 936 | 805 | |
| 937 | 806 | // Replace [form_key]. |
| 938 | 807 | $html = str_replace( '[form_key]', $form->form_key, $html ); |
| @@ -939,9 +808,9 @@ | ||
| 939 | 808 | |
| 940 | 809 | // Replace [frmurl]. |
| 941 | 810 | $html = str_replace( '[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html ); |
| 942 | 811 | |
| 943 | - if ( str_contains( $html, '[button_label]' ) ) { | |
| 812 | + if ( strpos( $html, '[button_label]' ) ) { | |
| 944 | 813 | add_filter( 'frm_submit_button', 'FrmFormsHelper::submit_button_label', 1 ); |
| 945 | 814 | $submit_label = apply_filters( 'frm_submit_button', $title, $form ); |
| 946 | 815 | $submit_label = esc_attr( do_shortcode( $submit_label ) ); |
| 947 | 816 | $html = str_replace( '[button_label]', $submit_label, $html ); |
| @@ -948,32 +817,27 @@ | ||
| 948 | 817 | } |
| 949 | 818 | |
| 950 | 819 | $html = apply_filters( 'frm_form_replace_shortcodes', $html, $form, $values ); |
| 951 | 820 | |
| 952 | - if ( str_contains( $html, '[if back_button]' ) ) { | |
| 821 | + if ( strpos( $html, '[if back_button]' ) ) { | |
| 953 | 822 | $html = preg_replace( '/(\[if\s+back_button\])(.*?)(\[\/if\s+back_button\])/mis', '', $html ); |
| 954 | 823 | } |
| 955 | 824 | |
| 956 | - if ( str_contains( $html, '[if save_draft]' ) ) { | |
| 825 | + if ( strpos( $html, '[if save_draft]' ) ) { | |
| 957 | 826 | $html = preg_replace( '/(\[if\s+save_draft\])(.*?)(\[\/if\s+save_draft\])/mis', '', $html ); |
| 958 | 827 | } |
| 959 | 828 | |
| 960 | - if ( str_contains( $html, '[if start_over]' ) ) { | |
| 829 | + if ( strpos( $html, '[if start_over]' ) ) { | |
| 961 | 830 | $html = preg_replace( '/(\[if\s+start_over\])(.*?)(\[\/if\s+start_over\])/mis', '', $html ); |
| 962 | 831 | } |
| 963 | 832 | |
| 964 | 833 | if ( apply_filters( 'frm_do_html_shortcodes', true ) ) { |
| 965 | - return do_shortcode( $html ); | |
| 834 | + $html = do_shortcode( $html ); | |
| 966 | 835 | } |
| 967 | 836 | |
| 968 | 837 | return $html; |
| 969 | 838 | } |
| 970 | 839 | |
| 971 | - /** | |
| 972 | - * @param string $submit | |
| 973 | - * | |
| 974 | - * @return string | |
| 975 | - */ | |
| 976 | 840 | public static function submit_button_label( $submit ) { |
| 977 | 841 | if ( ! $submit ) { |
| 978 | 842 | $frm_settings = FrmAppHelper::get_settings(); |
| 979 | 843 | $submit = $frm_settings->submit_value; |
| @@ -991,9 +855,8 @@ | ||
| 991 | 855 | * @return void |
| 992 | 856 | */ |
| 993 | 857 | public static function maybe_hide_inline() { |
| 994 | 858 | $frm_settings = FrmAppHelper::get_settings(); |
| 995 | - | |
| 996 | 859 | if ( $frm_settings->load_style === 'none' ) { |
| 997 | 860 | echo ' style="display:none;"'; |
| 998 | 861 | } elseif ( $frm_settings->load_style === 'dynamic' ) { |
| 999 | 862 | FrmStylesController::enqueue_style(); |
| @@ -1000,10 +863,8 @@ | ||
| 1000 | 863 | } |
| 1001 | 864 | } |
| 1002 | 865 | |
| 1003 | 866 | /** |
| 1004 | - * @param array|bool|int|object|string $form | |
| 1005 | - * | |
| 1006 | 867 | * @return string|null |
| 1007 | 868 | */ |
| 1008 | 869 | public static function get_form_style_class( $form = false ) { |
| 1009 | 870 | $style = self::get_form_style( $form ); |
| @@ -1008,10 +869,13 @@ | ||
| 1008 | 869 | public static function get_form_style_class( $form = false ) { |
| 1009 | 870 | $style = self::get_form_style( $form ); |
| 1010 | 871 | $class = ' with_frm_style'; |
| 1011 | 872 | |
| 1012 | - if ( ! $style ) { | |
| 1013 | - return FrmAppHelper::is_admin_page( 'formidable-entries' ) ? $class : null; | |
| 873 | + if ( empty( $style ) ) { | |
| 874 | + if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) { | |
| 875 | + return $class; | |
| 876 | + } | |
| 877 | + return; | |
| 1014 | 878 | } |
| 1015 | 879 | |
| 1016 | 880 | // If submit button needs to be inline or centered. |
| 1017 | 881 | if ( is_object( $form ) ) { |
| @@ -1032,9 +896,11 @@ | ||
| 1032 | 896 | } elseif ( 'center' === $submit_align ) { |
| 1033 | 897 | $class .= ' frm_center_submit'; |
| 1034 | 898 | } |
| 1035 | 899 | |
| 1036 | - return apply_filters( 'frm_add_form_style_class', $class, $style, compact( 'form' ) ); | |
| 900 | + $class = apply_filters( 'frm_add_form_style_class', $class, $style, compact( 'form' ) ); | |
| 901 | + | |
| 902 | + return $class; | |
| 1037 | 903 | } |
| 1038 | 904 | |
| 1039 | 905 | /** |
| 1040 | 906 | * 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. |
| @@ -1041,17 +907,16 @@ | ||
| 1041 | 907 | * |
| 1042 | 908 | * @since 5.0.12 |
| 1043 | 909 | * |
| 1044 | 910 | * @param array $form |
| 1045 | - * | |
| 1046 | 911 | * @return bool |
| 1047 | 912 | */ |
| 1048 | 913 | private static function form_should_be_inline_and_missing_class( $form ) { |
| 1049 | - if ( isset( $form['form_class'] ) && str_contains( ' ' . $form['form_class'] . ' ', ' frm_inline_form ' ) ) { | |
| 1050 | - // Not missing class, avoid adding it twice. | |
| 914 | + if ( isset( $form['form_class'] ) && false !== strpos( ' ' . $form['form_class'] . ' ', ' frm_inline_form ' ) ) { | |
| 915 | + // not missing class, avoid adding it twice. | |
| 1051 | 916 | return false; |
| 1052 | 917 | } |
| 1053 | - return ! empty( $form['submit_html'] ) && str_contains( $form['submit_html'], 'frm_inline_submit' ); | |
| 918 | + return ! empty( $form['submit_html'] ) && false !== strpos( $form['submit_html'], 'frm_inline_submit' ); | |
| 1054 | 919 | } |
| 1055 | 920 | |
| 1056 | 921 | /** |
| 1057 | 922 | * Returns appropriate class if form has top labels |
| @@ -1076,9 +941,8 @@ | ||
| 1076 | 941 | return false; |
| 1077 | 942 | } |
| 1078 | 943 | |
| 1079 | 944 | $fields = $form['fields']; |
| 1080 | - | |
| 1081 | 945 | if ( count( $fields ) <= 0 ) { |
| 1082 | 946 | return false; |
| 1083 | 947 | } |
| 1084 | 948 | |
| @@ -1083,13 +947,11 @@ | ||
| 1083 | 947 | } |
| 1084 | 948 | |
| 1085 | 949 | // Start from the fields closest to the submit button. |
| 1086 | 950 | $fields = array_reverse( $fields ); |
| 1087 | - | |
| 1088 | 951 | foreach ( $fields as $field ) { |
| 1089 | - $type = $field['original_type'] ?? $field['type']; | |
| 952 | + $type = isset( $field['original_type'] ) ? $field['original_type'] : $field['type']; | |
| 1090 | 953 | $has_input = FrmFieldFactory::field_has_property( $type, 'has_input' ); |
| 1091 | - | |
| 1092 | 954 | if ( $has_input ) { |
| 1093 | 955 | return self::field_has_top_label( $field, $form ); |
| 1094 | 956 | } |
| 1095 | 957 | } |
| @@ -1106,25 +968,24 @@ | ||
| 1106 | 968 | * @return bool |
| 1107 | 969 | */ |
| 1108 | 970 | private static function field_has_top_label( $field, $form ) { |
| 1109 | 971 | $label_position = FrmFieldsHelper::label_position( $field['label'], $field, $form ); |
| 1110 | - return in_array( $label_position, array( 'top', 'inside', 'hidden' ), true ); | |
| 972 | + | |
| 973 | + return in_array( $label_position, array( 'top', 'inside', 'hidden' ) ); | |
| 1111 | 974 | } |
| 1112 | 975 | |
| 1113 | 976 | /** |
| 1114 | - * @param array|bool|int|object|string $form | |
| 1115 | - * | |
| 1116 | - * @return int|string | |
| 977 | + * @param array|bool|object|string $form | |
| 978 | + * @return string | |
| 1117 | 979 | */ |
| 1118 | 980 | public static function get_form_style( $form ) { |
| 1119 | 981 | $style = 1; |
| 1120 | - | |
| 1121 | - if ( ! $form || 'default' === $form ) { | |
| 982 | + if ( empty( $form ) || 'default' === $form ) { | |
| 1122 | 983 | return $style; |
| 1123 | 984 | } |
| 1124 | 985 | |
| 1125 | 986 | if ( is_object( $form ) && $form->parent_form_id ) { |
| 1126 | - // Get the parent form if this is a child | |
| 987 | + // get the parent form if this is a child | |
| 1127 | 988 | $form = $form->parent_form_id; |
| 1128 | 989 | } elseif ( is_array( $form ) && ! empty( $form['parent_form_id'] ) ) { |
| 1129 | 990 | $form = $form['parent_form_id']; |
| 1130 | 991 | } elseif ( is_array( $form ) && isset( $form['custom_style'] ) ) { |
| @@ -1130,13 +991,15 @@ | ||
| 1130 | 991 | } elseif ( is_array( $form ) && isset( $form['custom_style'] ) ) { |
| 1131 | 992 | $style = $form['custom_style']; |
| 1132 | 993 | } |
| 1133 | 994 | |
| 1134 | - if ( $form && ( is_string( $form ) || is_int( $form ) ) ) { | |
| 995 | + if ( $form && is_string( $form ) ) { | |
| 1135 | 996 | $form = FrmForm::getOne( $form ); |
| 1136 | 997 | } |
| 1137 | 998 | |
| 1138 | - return $form && is_object( $form ) && isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : $style; | |
| 999 | + $style = $form && is_object( $form ) && isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : $style; | |
| 1000 | + | |
| 1001 | + return $style; | |
| 1139 | 1002 | } |
| 1140 | 1003 | |
| 1141 | 1004 | /** |
| 1142 | 1005 | * Display the validation error messages when an entry is submitted |
| @@ -1141,21 +1004,18 @@ | ||
| 1141 | 1004 | /** |
| 1142 | 1005 | * Display the validation error messages when an entry is submitted |
| 1143 | 1006 | * |
| 1144 | 1007 | * @since 2.0.6 |
| 1145 | - * | |
| 1146 | 1008 | * @param array $args Includes img, errors. |
| 1147 | - * | |
| 1148 | - * @return void | |
| 1149 | 1009 | */ |
| 1150 | 1010 | public static function show_errors( $args ) { |
| 1151 | 1011 | $invalid_msg = self::get_invalid_error_message( $args ); |
| 1152 | 1012 | |
| 1153 | - if ( $invalid_msg ) { | |
| 1013 | + if ( empty( $invalid_msg ) ) { | |
| 1014 | + $show_img = false; | |
| 1015 | + } else { | |
| 1154 | 1016 | echo wp_kses_post( $invalid_msg ); |
| 1155 | 1017 | $show_img = true; |
| 1156 | - } else { | |
| 1157 | - $show_img = false; | |
| 1158 | 1018 | } |
| 1159 | 1019 | |
| 1160 | 1020 | self::show_error( |
| 1161 | 1021 | array( |
| @@ -1171,21 +1031,17 @@ | ||
| 1171 | 1031 | * The image was removed from the styling settings, but it may still be set with a hook |
| 1172 | 1032 | * If the message in the global settings is empty, show every validation message in the error box |
| 1173 | 1033 | * |
| 1174 | 1034 | * @since 2.0.6 |
| 1175 | - * | |
| 1176 | 1035 | * @param array $args Includes img, errors, and show_img. |
| 1177 | - * | |
| 1178 | - * @return void | |
| 1179 | 1036 | */ |
| 1180 | 1037 | public static function show_error( $args ) { |
| 1181 | - // Remove any blank messages | |
| 1038 | + // remove any blank messages | |
| 1182 | 1039 | $args['errors'] = array_filter( (array) $args['errors'] ); |
| 1183 | 1040 | |
| 1184 | 1041 | $line_break_first = $args['show_img']; |
| 1185 | - | |
| 1186 | 1042 | foreach ( $args['errors'] as $error_key => $error ) { |
| 1187 | - if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key === 'cptch_number' || str_starts_with( $error_key, 'field' ) ) ) { | |
| 1043 | + if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key === 'cptch_number' || strpos( $error_key, 'field' ) === 0 ) ) { | |
| 1188 | 1044 | continue; |
| 1189 | 1045 | } |
| 1190 | 1046 | |
| 1191 | 1047 | $id = str_replace( 'field', 'field_', $error_key ); |
| @@ -1202,27 +1058,15 @@ | ||
| 1202 | 1058 | echo '</div>'; |
| 1203 | 1059 | } |
| 1204 | 1060 | } |
| 1205 | 1061 | |
| 1206 | - /** | |
| 1207 | - * @param int|string $id | |
| 1208 | - * | |
| 1209 | - * @return void | |
| 1210 | - */ | |
| 1211 | 1062 | public static function maybe_get_scroll_js( $id ) { |
| 1212 | 1063 | $offset = apply_filters( 'frm_scroll_offset', 4, array( 'form_id' => $id ) ); |
| 1213 | - | |
| 1214 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 1215 | 1064 | if ( $offset != - 1 ) { |
| 1216 | 1065 | self::get_scroll_js( $id ); |
| 1217 | 1066 | } |
| 1218 | 1067 | } |
| 1219 | 1068 | |
| 1220 | - /** | |
| 1221 | - * @param int|string $form_id | |
| 1222 | - * | |
| 1223 | - * @return void | |
| 1224 | - */ | |
| 1225 | 1069 | public static function get_scroll_js( $form_id ) { |
| 1226 | 1070 | echo '<script type="text/javascript">document.addEventListener(\'DOMContentLoaded\',function(){frmFrontForm.scrollMsg(' . (int) $form_id . ');})</script>'; |
| 1227 | 1071 | } |
| 1228 | 1072 | |
| @@ -1227,13 +1071,8 @@ | ||
| 1227 | 1071 | } |
| 1228 | 1072 | |
| 1229 | 1073 | /** |
| 1230 | 1074 | * @since 3.0 |
| 1231 | - * | |
| 1232 | - * @param int|object|string $form_id | |
| 1233 | - * @param mixed $form | |
| 1234 | - * | |
| 1235 | - * @return array | |
| 1236 | 1075 | */ |
| 1237 | 1076 | public static function get_action_links( $form_id, $form ) { |
| 1238 | 1077 | if ( ! is_object( $form ) ) { |
| 1239 | 1078 | $form = FrmForm::getOne( $form_id ); |
| @@ -1240,10 +1079,9 @@ | ||
| 1240 | 1079 | } |
| 1241 | 1080 | |
| 1242 | 1081 | $actions = array(); |
| 1243 | 1082 | $trash_links = self::delete_trash_links( $form_id ); |
| 1244 | - | |
| 1245 | - if ( 'trash' === $form->status ) { | |
| 1083 | + if ( 'trash' == $form->status ) { | |
| 1246 | 1084 | $actions['restore'] = $trash_links['restore']; |
| 1247 | 1085 | |
| 1248 | 1086 | if ( current_user_can( 'frm_delete_forms' ) ) { |
| 1249 | 1087 | $actions['trash'] = $trash_links['delete']; |
| @@ -1249,20 +1087,19 @@ | ||
| 1249 | 1087 | $actions['trash'] = $trash_links['delete']; |
| 1250 | 1088 | } |
| 1251 | 1089 | } elseif ( current_user_can( 'frm_edit_forms' ) ) { |
| 1252 | 1090 | $duplicate_link = '?page=formidable&frm_action=duplicate&id=' . $form_id; |
| 1253 | - | |
| 1254 | 1091 | if ( $form->is_template ) { |
| 1255 | 1092 | $actions['frm_duplicate'] = array( |
| 1256 | 1093 | 'url' => wp_nonce_url( $duplicate_link ), |
| 1257 | 1094 | 'label' => __( 'Create Form from Template', 'formidable' ), |
| 1258 | - 'icon' => 'frmfont frm_clone_icon', | |
| 1095 | + 'icon' => 'frm_icon_font frm_clone_icon', | |
| 1259 | 1096 | ); |
| 1260 | 1097 | } else { |
| 1261 | 1098 | $actions['duplicate'] = array( |
| 1262 | 1099 | 'url' => wp_nonce_url( $duplicate_link ), |
| 1263 | - 'label' => __( 'Duplicate', 'formidable' ), | |
| 1264 | - 'icon' => 'frmfont frm_clone_icon', | |
| 1100 | + 'label' => __( 'Duplicate Form', 'formidable' ), | |
| 1101 | + 'icon' => 'frm_icon_font frm_clone_icon', | |
| 1265 | 1102 | ); |
| 1266 | 1103 | } |
| 1267 | 1104 | |
| 1268 | 1105 | $actions['trash'] = self::delete_trash_info( $form_id, $form->status ); |
| @@ -1270,13 +1107,8 @@ | ||
| 1270 | 1107 | |
| 1271 | 1108 | return $actions; |
| 1272 | 1109 | } |
| 1273 | 1110 | |
| 1274 | - /** | |
| 1275 | - * @param int|object|string $data | |
| 1276 | - * | |
| 1277 | - * @return string | |
| 1278 | - */ | |
| 1279 | 1111 | public static function edit_form_link( $data ) { |
| 1280 | 1112 | $form_id = self::get_form_id_from_data( $data ); |
| 1281 | 1113 | |
| 1282 | 1114 | if ( ! $form_id ) { |
| @@ -1283,114 +1115,82 @@ | ||
| 1283 | 1115 | return ''; |
| 1284 | 1116 | } |
| 1285 | 1117 | |
| 1286 | 1118 | $label = self::edit_form_link_label( $data ); |
| 1287 | - return '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>'; | |
| 1119 | + $link = '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>'; | |
| 1120 | + return $link; | |
| 1288 | 1121 | } |
| 1289 | 1122 | |
| 1290 | - /** | |
| 1291 | - * Returns a text used when no title is set. | |
| 1292 | - * | |
| 1293 | - * @since 6.16.1 | |
| 1294 | - * | |
| 1295 | - * @return string | |
| 1296 | - */ | |
| 1297 | - public static function get_no_title_text() { | |
| 1298 | - return __( '(no title)', 'formidable' ); | |
| 1299 | - } | |
| 1300 | - | |
| 1301 | - /** | |
| 1302 | - * @param int|object|string $data | |
| 1303 | - * | |
| 1304 | - * @return string | |
| 1305 | - */ | |
| 1306 | 1123 | public static function edit_form_link_label( $data ) { |
| 1307 | 1124 | $name = self::get_form_name_from_data( $data ); |
| 1308 | - | |
| 1309 | 1125 | if ( ! $name ) { |
| 1310 | - return self::get_no_title_text(); | |
| 1126 | + return __( '(no title)', 'formidable' ); | |
| 1311 | 1127 | } |
| 1312 | - | |
| 1313 | 1128 | return FrmAppHelper::truncate( $name, 40 ); |
| 1314 | 1129 | } |
| 1315 | 1130 | |
| 1316 | 1131 | /** |
| 1317 | - * @param int|object|string $data | |
| 1318 | - * | |
| 1319 | - * @return int|string | |
| 1132 | + * @param mixed $data | |
| 1133 | + * @return int | |
| 1320 | 1134 | */ |
| 1321 | 1135 | private static function get_form_id_from_data( $data ) { |
| 1322 | - return is_object( $data ) ? $data->id : $data; | |
| 1136 | + if ( is_object( $data ) ) { | |
| 1137 | + $form_id = $data->id; | |
| 1138 | + } else { | |
| 1139 | + $form_id = $data; | |
| 1140 | + } | |
| 1141 | + return $form_id; | |
| 1323 | 1142 | } |
| 1324 | 1143 | |
| 1325 | 1144 | /** |
| 1326 | 1145 | * @param mixed $data |
| 1327 | - * | |
| 1328 | 1146 | * @return string |
| 1329 | 1147 | */ |
| 1330 | 1148 | private static function get_form_name_from_data( $data ) { |
| 1331 | 1149 | if ( is_object( $data ) ) { |
| 1332 | - return $data->name; | |
| 1150 | + $form_name = $data->name; | |
| 1151 | + } else { | |
| 1152 | + $form_id = $data; | |
| 1153 | + $form_name = FrmForm::getName( $form_id ); | |
| 1333 | 1154 | } |
| 1334 | - | |
| 1335 | - $form_id = $data; | |
| 1336 | - return FrmForm::getName( $form_id ); | |
| 1155 | + return $form_name; | |
| 1337 | 1156 | } |
| 1338 | 1157 | |
| 1339 | - /** | |
| 1340 | - * @param int $id | |
| 1341 | - * @param string $status | |
| 1342 | - * @param string $length | |
| 1343 | - * | |
| 1344 | - * @return string | |
| 1345 | - */ | |
| 1346 | 1158 | public static function delete_trash_link( $id, $status, $length = 'label' ) { |
| 1347 | 1159 | $link_details = self::delete_trash_info( $id, $status ); |
| 1160 | + | |
| 1348 | 1161 | return self::format_link_html( $link_details, $length ); |
| 1349 | 1162 | } |
| 1350 | 1163 | |
| 1351 | 1164 | /** |
| 1352 | 1165 | * @since 3.0 |
| 1353 | - * | |
| 1354 | - * @param array $link_details | |
| 1355 | - * @param string $length | |
| 1356 | - * | |
| 1357 | - * @return string | |
| 1358 | 1166 | */ |
| 1359 | 1167 | public static function format_link_html( $link_details, $length = 'label' ) { |
| 1360 | 1168 | $link = ''; |
| 1169 | + if ( ! empty( $link_details ) ) { | |
| 1170 | + $link = '<a href="' . esc_url( $link_details['url'] ) . '" class="frm-trash-link"'; | |
| 1171 | + if ( isset( $link_details['data'] ) ) { | |
| 1172 | + foreach ( $link_details['data'] as $data => $value ) { | |
| 1173 | + $link .= ' data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '"'; | |
| 1174 | + } | |
| 1175 | + } elseif ( isset( $link_details['confirm'] ) ) { | |
| 1176 | + $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"'; | |
| 1177 | + } | |
| 1361 | 1178 | |
| 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 ) . '"'; | |
| 1179 | + $label = ( isset( $link_details[ $length ] ) ? $link_details[ $length ] : $link_details['label'] ); | |
| 1180 | + if ( $length === 'icon' && isset( $link_details[ $length ] ) ) { | |
| 1181 | + $label = '<span class="' . $label . '" title="' . esc_attr( $link_details['label'] ) . '" aria-hidden="true"></span>'; | |
| 1182 | + $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"'; | |
| 1371 | 1183 | } |
| 1372 | - } elseif ( isset( $link_details['confirm'] ) ) { | |
| 1373 | - $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"'; | |
| 1374 | - } | |
| 1375 | 1184 | |
| 1376 | - $label = $link_details[ $length ] ?? $link_details['label']; | |
| 1377 | - | |
| 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'] ) . '"'; | |
| 1185 | + $link .= '>' . $label . '</a>'; | |
| 1381 | 1186 | } |
| 1382 | 1187 | |
| 1383 | - return $link . ( '>' . $label . '</a>' ); | |
| 1188 | + return $link; | |
| 1384 | 1189 | } |
| 1385 | 1190 | |
| 1386 | 1191 | /** |
| 1387 | 1192 | * @since 3.0 |
| 1388 | - * | |
| 1389 | - * @param int $id | |
| 1390 | - * @param string $status | |
| 1391 | - * | |
| 1392 | - * @return array | |
| 1393 | 1193 | */ |
| 1394 | 1194 | public static function delete_trash_info( $id, $status ) { |
| 1395 | 1195 | $labels = self::delete_trash_links( $id ); |
| 1396 | 1196 | |
| @@ -1396,9 +1196,13 @@ | ||
| 1396 | 1196 | |
| 1397 | 1197 | if ( 'trash' === $status ) { |
| 1398 | 1198 | $info = $labels['restore']; |
| 1399 | 1199 | } elseif ( current_user_can( 'frm_delete_forms' ) ) { |
| 1400 | - $info = EMPTY_TRASH_DAYS ? $labels['trash'] : $labels['delete']; | |
| 1200 | + if ( EMPTY_TRASH_DAYS ) { | |
| 1201 | + $info = $labels['trash']; | |
| 1202 | + } else { | |
| 1203 | + $info = $labels['delete']; | |
| 1204 | + } | |
| 1401 | 1205 | } else { |
| 1402 | 1206 | $info = array(); |
| 1403 | 1207 | } |
| 1404 | 1208 | |
| @@ -1406,12 +1210,8 @@ | ||
| 1406 | 1210 | } |
| 1407 | 1211 | |
| 1408 | 1212 | /** |
| 1409 | 1213 | * @since 3.0 |
| 1410 | - * | |
| 1411 | - * @param int $id | |
| 1412 | - * | |
| 1413 | - * @return array | |
| 1414 | 1214 | */ |
| 1415 | 1215 | public static function delete_trash_links( $id ) { |
| 1416 | 1216 | $current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type' ) ); |
| 1417 | 1217 | $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id; |
| @@ -1425,9 +1225,9 @@ | ||
| 1425 | 1225 | 'trash' => array( |
| 1426 | 1226 | 'label' => __( 'Move Form to Trash', 'formidable' ), |
| 1427 | 1227 | 'short' => __( 'Trash', 'formidable' ), |
| 1428 | 1228 | 'url' => wp_nonce_url( $base_url . '&frm_action=trash', 'trash_form_' . absint( $id ) ), |
| 1429 | - 'icon' => 'frmfont frm_delete_icon', | |
| 1229 | + 'icon' => 'frm_icon_font frm_delete_icon', | |
| 1430 | 1230 | 'data' => array( |
| 1431 | 1231 | 'frmverify' => __( 'Do you want to move this form to the trash?', 'formidable' ), |
| 1432 | 1232 | 'frmverify-btn' => 'frm-button-red', |
| 1433 | 1233 | ), |
| @@ -1436,9 +1236,9 @@ | ||
| 1436 | 1236 | 'label' => __( 'Delete Permanently', 'formidable' ), |
| 1437 | 1237 | 'short' => __( 'Delete', 'formidable' ), |
| 1438 | 1238 | 'url' => wp_nonce_url( $base_url . '&frm_action=destroy', 'destroy_form_' . absint( $id ) ), |
| 1439 | 1239 | 'confirm' => __( 'Are you sure you want to delete this form and all its entries?', 'formidable' ), |
| 1440 | - 'icon' => 'frmfont frm_delete_icon', | |
| 1240 | + 'icon' => 'frm_icon_font frm_delete_icon', | |
| 1441 | 1241 | 'data' => array( |
| 1442 | 1242 | 'frmverify' => __( 'This will permanently delete the form and all its entries. This is irreversible. Are you sure you want to continue?', 'formidable' ), |
| 1443 | 1243 | 'frmverify-btn' => 'frm-button-red', |
| 1444 | 1244 | ), |
| @@ -1447,10 +1247,8 @@ | ||
| 1447 | 1247 | } |
| 1448 | 1248 | |
| 1449 | 1249 | /** |
| 1450 | 1250 | * @since 3.0 |
| 1451 | - * | |
| 1452 | - * @return array | |
| 1453 | 1251 | */ |
| 1454 | 1252 | public static function css_classes() { |
| 1455 | 1253 | $classes = array( |
| 1456 | 1254 | 'frm_total' => array( |
| @@ -1462,9 +1260,9 @@ | ||
| 1462 | 1260 | 'title' => __( 'Add this to a read-only field to display the text in large, bold text without a border or background.', 'formidable' ), |
| 1463 | 1261 | ), |
| 1464 | 1262 | 'frm_scroll_box' => array( |
| 1465 | 1263 | 'label' => __( 'Scroll Box', '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 | |
| 1264 | + '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' ), | |
| 1467 | 1265 | ), |
| 1468 | 1266 | 'frm_first' => array( |
| 1469 | 1267 | 'label' => __( 'First', 'formidable' ), |
| 1470 | 1268 | 'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm4', 'formidable' ), |
| @@ -1485,11 +1283,8 @@ | ||
| 1485 | 1283 | |
| 1486 | 1284 | return apply_filters( 'frm_layout_classes', $classes ); |
| 1487 | 1285 | } |
| 1488 | 1286 | |
| 1489 | - /** | |
| 1490 | - * @return array | |
| 1491 | - */ | |
| 1492 | 1287 | public static function grid_classes() { |
| 1493 | 1288 | return array( |
| 1494 | 1289 | 'frm_half' => '1/2', |
| 1495 | 1290 | 'frm_third' => '1/3', |
| @@ -1503,18 +1298,12 @@ | ||
| 1503 | 1298 | } |
| 1504 | 1299 | |
| 1505 | 1300 | /** |
| 1506 | 1301 | * @since 3.0 |
| 1507 | - * | |
| 1508 | - * @param mixed $style | |
| 1509 | - * @param string $class | |
| 1510 | - * | |
| 1511 | - * @return string | |
| 1512 | 1302 | */ |
| 1513 | 1303 | public static function style_class_label( $style, $class ) { |
| 1514 | 1304 | $label = ''; |
| 1515 | - | |
| 1516 | - if ( ! $style ) { | |
| 1305 | + if ( empty( $style ) ) { | |
| 1517 | 1306 | $label = $class; |
| 1518 | 1307 | } elseif ( ! is_array( $style ) ) { |
| 1519 | 1308 | $label = $style; |
| 1520 | 1309 | } elseif ( isset( $style['label'] ) ) { |
| @@ -1523,13 +1312,8 @@ | ||
| 1523 | 1312 | |
| 1524 | 1313 | return $label; |
| 1525 | 1314 | } |
| 1526 | 1315 | |
| 1527 | - /** | |
| 1528 | - * @param string $status | |
| 1529 | - * | |
| 1530 | - * @return string | |
| 1531 | - */ | |
| 1532 | 1316 | public static function status_nice_name( $status ) { |
| 1533 | 1317 | $nice_names = array( |
| 1534 | 1318 | 'draft' => __( 'Draft', 'formidable' ), |
| 1535 | 1319 | 'trash' => __( 'Trash', 'formidable' ), |
| @@ -1535,13 +1319,15 @@ | ||
| 1535 | 1319 | 'trash' => __( 'Trash', 'formidable' ), |
| 1536 | 1320 | 'publish' => __( 'Published', 'formidable' ), |
| 1537 | 1321 | ); |
| 1538 | 1322 | |
| 1539 | - if ( ! array_key_exists( $status, $nice_names ) ) { | |
| 1323 | + if ( ! in_array( $status, array_keys( $nice_names ), true ) ) { | |
| 1540 | 1324 | $status = 'publish'; |
| 1541 | 1325 | } |
| 1542 | 1326 | |
| 1543 | - return $nice_names[ $status ]; | |
| 1327 | + $name = $nice_names[ $status ]; | |
| 1328 | + | |
| 1329 | + return $name; | |
| 1544 | 1330 | } |
| 1545 | 1331 | |
| 1546 | 1332 | /** |
| 1547 | 1333 | * Renders a template icon based on the given categories. |
| @@ -1548,9 +1334,8 @@ | ||
| 1548 | 1334 | * |
| 1549 | 1335 | * @param array $categories The categories to render the icon for. |
| 1550 | 1336 | * @param array $atts { |
| 1551 | 1337 | * Optional. An array of attributes for rendering. |
| 1552 | - * | |
| 1553 | 1338 | * @type string $html 'span' or 'div'. Default 'span'. |
| 1554 | 1339 | * @type bool $bg Whether to add a background color or not. Default false. |
| 1555 | 1340 | * } |
| 1556 | 1341 | * |
| @@ -1563,9 +1348,9 @@ | ||
| 1563 | 1348 | ); |
| 1564 | 1349 | $atts = array_merge( $defaults, $atts ); |
| 1565 | 1350 | |
| 1566 | 1351 | // Filter out ignored categories. |
| 1567 | - $ignore = self::get_license_types(); | |
| 1352 | + $ignore = self::ignore_template_categories(); | |
| 1568 | 1353 | $categories = array_diff( $categories, $ignore ); |
| 1569 | 1354 | |
| 1570 | 1355 | // Define icons mapping. |
| 1571 | 1356 | $icons = array( |
| @@ -1600,13 +1385,12 @@ | ||
| 1600 | 1385 | ); |
| 1601 | 1386 | |
| 1602 | 1387 | // Determine the icon to be used. |
| 1603 | 1388 | $icon = $icons['']; |
| 1604 | - | |
| 1605 | 1389 | if ( count( $categories ) === 1 ) { |
| 1606 | 1390 | $category = reset( $categories ); |
| 1607 | - $icon = $icons[ $category ] ?? $icon; | |
| 1608 | - } elseif ( $categories ) { | |
| 1391 | + $icon = isset( $icons[ $category ] ) ? $icons[ $category ] : $icon; | |
| 1392 | + } elseif ( ! empty( $categories ) ) { | |
| 1609 | 1393 | $icons = array_intersect_key( $icons, array_flip( $categories ) ); |
| 1610 | 1394 | $icon = reset( $icons ); |
| 1611 | 1395 | } |
| 1612 | 1396 | |
| @@ -1611,23 +1395,32 @@ | ||
| 1611 | 1395 | } |
| 1612 | 1396 | |
| 1613 | 1397 | // Prepare variables for output. |
| 1614 | 1398 | $icon_name = $icon[0]; |
| 1615 | - $bg_color = $icon[1] ?? ''; | |
| 1399 | + $bg_color = isset( $icon[1] ) ? $icon[1] : ''; | |
| 1616 | 1400 | |
| 1617 | 1401 | // Render the icon. |
| 1618 | 1402 | echo '<span class="frm-category-icon frm-icon-wrapper"'; |
| 1619 | - | |
| 1620 | 1403 | if ( $bg_color && $atts['bg'] ) { |
| 1621 | 1404 | echo ' style="background-color:' . esc_attr( $bg_color ) . '"'; |
| 1622 | 1405 | } |
| 1623 | - | |
| 1624 | 1406 | echo '>'; |
| 1625 | - FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon_name . '_icon' ); | |
| 1407 | + FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon_name . '_icon' ); | |
| 1626 | 1408 | echo '</span>'; |
| 1627 | 1409 | } |
| 1628 | 1410 | |
| 1629 | 1411 | /** |
| 1412 | + * Retrieves the list of template categories to ignore. | |
| 1413 | + * | |
| 1414 | + * @since 4.03.01 | |
| 1415 | + * | |
| 1416 | + * @return string[] Array of categories to ignore. | |
| 1417 | + */ | |
| 1418 | + public static function ignore_template_categories() { | |
| 1419 | + return array( 'Business', 'Elite', 'Personal', 'Creator', 'Basic', 'free' ); | |
| 1420 | + } | |
| 1421 | + | |
| 1422 | + /** | |
| 1630 | 1423 | * Get template install link. |
| 1631 | 1424 | * |
| 1632 | 1425 | * @since 4.02 |
| 1633 | 1426 | * |
| @@ -1632,9 +1425,8 @@ | ||
| 1632 | 1425 | * @since 4.02 |
| 1633 | 1426 | * |
| 1634 | 1427 | * @param array $template Template details. |
| 1635 | 1428 | * @param array $args Additional arguments. |
| 1636 | - * | |
| 1637 | 1429 | * @return array The link attributes. |
| 1638 | 1430 | */ |
| 1639 | 1431 | public static function get_template_install_link( $template, $args ) { |
| 1640 | 1432 | $defaults = array( |
| @@ -1650,8 +1442,13 @@ | ||
| 1650 | 1442 | 'class' => 'frm-install-template', |
| 1651 | 1443 | 'href' => 'rel', |
| 1652 | 1444 | 'atts' => '', |
| 1653 | 1445 | ); |
| 1446 | + } elseif ( self::plan_is_allowed( $args ) ) { | |
| 1447 | + $link = array( | |
| 1448 | + 'url' => FrmAppHelper::admin_upgrade_link( 'addons', 'account/downloads/' ) . '&utm_content=' . $template['slug'], | |
| 1449 | + 'label' => __( 'Renew', 'formidable' ), | |
| 1450 | + ); | |
| 1654 | 1451 | } else { |
| 1655 | 1452 | $link = array( |
| 1656 | 1453 | 'url' => $args['pricing'], |
| 1657 | 1454 | 'label' => __( 'Upgrade', 'formidable' ), |
| @@ -1666,9 +1463,8 @@ | ||
| 1666 | 1463 | * |
| 1667 | 1464 | * @since 4.02.02 |
| 1668 | 1465 | * |
| 1669 | 1466 | * @param array $args |
| 1670 | - * | |
| 1671 | 1467 | * @return bool |
| 1672 | 1468 | */ |
| 1673 | 1469 | public static function plan_is_allowed( $args ) { |
| 1674 | 1470 | if ( empty( $args['license_type'] ) ) { |
| @@ -1687,9 +1483,8 @@ | ||
| 1687 | 1483 | foreach ( $plans as $plan ) { |
| 1688 | 1484 | if ( $included || $plan === $license_type ) { |
| 1689 | 1485 | break; |
| 1690 | 1486 | } |
| 1691 | - | |
| 1692 | 1487 | $included = $plan === $plan_required; |
| 1693 | 1488 | } |
| 1694 | 1489 | |
| 1695 | 1490 | return $included; |
| @@ -1699,29 +1494,22 @@ | ||
| 1699 | 1494 | * If a template or add-on cannot be installed, show a message |
| 1700 | 1495 | * about which plan is required. |
| 1701 | 1496 | * |
| 1702 | 1497 | * @since 4.0 |
| 1703 | - * | |
| 1704 | - * @param string $requires | |
| 1705 | - * @param string $link | |
| 1706 | - * | |
| 1707 | - * @return void | |
| 1708 | 1498 | */ |
| 1709 | 1499 | public static function show_plan_required( $requires, $link ) { |
| 1710 | - if ( ! $requires ) { | |
| 1500 | + if ( empty( $requires ) ) { | |
| 1711 | 1501 | return; |
| 1712 | 1502 | } |
| 1713 | 1503 | |
| 1714 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 1715 | 1504 | ?> |
| 1716 | 1505 | <p class="frm_plan_required"> |
| 1717 | - <?php esc_html_e( 'Plan required:', 'formidable' ); ?> | |
| 1506 | + <?php esc_html_e( 'License plan required:', 'formidable' ); ?> | |
| 1718 | 1507 | <a href="<?php echo esc_url( $link ); ?>" target="_blank" rel="noopener"> |
| 1719 | 1508 | <?php echo esc_html( $requires ); ?> |
| 1720 | 1509 | </a> |
| 1721 | 1510 | </p> |
| 1722 | 1511 | <?php |
| 1723 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 1724 | 1512 | } |
| 1725 | 1513 | |
| 1726 | 1514 | /** |
| 1727 | 1515 | * @since 4.0 |
| @@ -1726,9 +1514,8 @@ | ||
| 1726 | 1514 | /** |
| 1727 | 1515 | * @since 4.0 |
| 1728 | 1516 | * |
| 1729 | 1517 | * @param array $item |
| 1730 | - * | |
| 1731 | 1518 | * @return false|string |
| 1732 | 1519 | */ |
| 1733 | 1520 | public static function get_plan_required( &$item ) { |
| 1734 | 1521 | if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) { |
| @@ -1734,14 +1521,20 @@ | ||
| 1734 | 1521 | if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) { |
| 1735 | 1522 | return false; |
| 1736 | 1523 | } |
| 1737 | 1524 | |
| 1738 | - $plans = self::get_license_types(); | |
| 1525 | + $plans = array( 'free', 'Basic', 'Personal', 'Plus', 'Creator', 'Business', 'Elite' ); | |
| 1739 | 1526 | |
| 1740 | 1527 | foreach ( $item['categories'] as $k => $category ) { |
| 1741 | 1528 | if ( in_array( $category, $plans, true ) ) { |
| 1742 | 1529 | unset( $item['categories'][ $k ] ); |
| 1743 | - return self::convert_legacy_package_names( $category ); | |
| 1530 | + | |
| 1531 | + if ( in_array( $category, array( 'Creator', 'Personal' ), true ) ) { | |
| 1532 | + // Show the current package name. | |
| 1533 | + $category = 'Plus'; | |
| 1534 | + } | |
| 1535 | + | |
| 1536 | + return $category; | |
| 1744 | 1537 | } |
| 1745 | 1538 | } |
| 1746 | 1539 | |
| 1747 | 1540 | return false; |
| @@ -1747,53 +1540,8 @@ | ||
| 1747 | 1540 | return false; |
| 1748 | 1541 | } |
| 1749 | 1542 | |
| 1750 | 1543 | /** |
| 1751 | - * Converts legacy package names to the current standard package name. | |
| 1752 | - * | |
| 1753 | - * @since 6.15 | |
| 1754 | - * | |
| 1755 | - * @param string $package_name | |
| 1756 | - * | |
| 1757 | - * @return string The updated package name. | |
| 1758 | - */ | |
| 1759 | - public static function convert_legacy_package_names( $package_name ) { | |
| 1760 | - if ( in_array( $package_name, array( 'Creator', 'Personal' ), true ) ) { | |
| 1761 | - return 'Plus'; | |
| 1762 | - } | |
| 1763 | - | |
| 1764 | - return $package_name; | |
| 1765 | - } | |
| 1766 | - | |
| 1767 | - /** | |
| 1768 | - * Get the license types. | |
| 1769 | - * | |
| 1770 | - * @since 6.15 | |
| 1771 | - * | |
| 1772 | - * @param array $args | |
| 1773 | - * | |
| 1774 | - * @return array | |
| 1775 | - */ | |
| 1776 | - public static function get_license_types( $args = array() ) { | |
| 1777 | - $defaults = array( | |
| 1778 | - 'include_all' => true, | |
| 1779 | - 'case_lower' => false, | |
| 1780 | - ); | |
| 1781 | - $args = wp_parse_args( $args, $defaults ); | |
| 1782 | - $license_types = array( 'Basic', 'Plus', 'Business', 'Elite' ); | |
| 1783 | - | |
| 1784 | - if ( $args['include_all'] ) { | |
| 1785 | - $license_types = array_merge( array( 'free', 'Personal', 'Creator' ), $license_types ); | |
| 1786 | - } | |
| 1787 | - | |
| 1788 | - if ( $args['case_lower'] ) { | |
| 1789 | - return array_map( 'strtolower', $license_types ); | |
| 1790 | - } | |
| 1791 | - | |
| 1792 | - return $license_types; | |
| 1793 | - } | |
| 1794 | - | |
| 1795 | - /** | |
| 1796 | 1544 | * Checks for warnings to be displayed after form settings are saved. |
| 1797 | 1545 | * |
| 1798 | 1546 | * @since 4.04 |
| 1799 | 1547 | * |
| @@ -1801,9 +1549,10 @@ | ||
| 1801 | 1549 | * |
| 1802 | 1550 | * @return array An array of warnings or an empty array. |
| 1803 | 1551 | */ |
| 1804 | 1552 | public static function check_for_warnings( $values ) { |
| 1805 | - $warnings = array(); | |
| 1553 | + $warnings = array(); | |
| 1554 | + | |
| 1806 | 1555 | $redirect_warning = self::check_redirect_url_for_unsafe_params( $values ); |
| 1807 | 1556 | |
| 1808 | 1557 | if ( $redirect_warning ) { |
| 1809 | 1558 | $warnings[] = $redirect_warning; |
| @@ -1848,16 +1597,15 @@ | ||
| 1848 | 1597 | * @return array An array of params whose names are reserved words or an empty array. |
| 1849 | 1598 | */ |
| 1850 | 1599 | private static function get_unsafe_params( $url ) { |
| 1851 | 1600 | $redirect_components = parse_url( $url ); |
| 1852 | - | |
| 1853 | 1601 | if ( empty( $redirect_components['query'] ) ) { |
| 1854 | 1602 | return array(); |
| 1855 | 1603 | } |
| 1856 | - | |
| 1857 | 1604 | parse_str( $redirect_components['query'], $redirect_params ); |
| 1858 | 1605 | $redirect_param_names = array_keys( $redirect_params ); |
| 1859 | - $unsafe_params_in_redirect = array_intersect( $redirect_param_names, self::reserved_words() ); | |
| 1606 | + $reserved_words = self::reserved_words(); | |
| 1607 | + $unsafe_params_in_redirect = array_intersect( $redirect_param_names, $reserved_words ); | |
| 1860 | 1608 | |
| 1861 | 1609 | return array_values( $unsafe_params_in_redirect ); |
| 1862 | 1610 | } |
| 1863 | 1611 | |
| @@ -1870,27 +1618,26 @@ | ||
| 1870 | 1618 | * |
| 1871 | 1619 | * @return bool|string A string with an unsafe param message or false. |
| 1872 | 1620 | */ |
| 1873 | 1621 | private static function create_unsafe_param_warning( $unsafe_params_in_redirect ) { |
| 1874 | - $count = count( $unsafe_params_in_redirect ); | |
| 1622 | + $count = count( $unsafe_params_in_redirect ); | |
| 1623 | + $caution = esc_html__( 'Is this intentional?', 'formidable' ); | |
| 1624 | + $reserved_words_intro = esc_html__( 'See the list of reserved words in WordPress.', 'formidable' ); | |
| 1625 | + $reserved_words_link = '<a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank"> ' . $reserved_words_intro . '</a>'; | |
| 1875 | 1626 | |
| 1876 | 1627 | if ( $count === 0 ) { |
| 1877 | 1628 | return false; |
| 1878 | 1629 | } |
| 1879 | 1630 | |
| 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 ) { | |
| 1631 | + if ( $count == 1 ) { | |
| 1885 | 1632 | /* translators: %s: the name of a single parameter in the redirect URL */ |
| 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 | |
| 1633 | + 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; | |
| 1887 | 1634 | } |
| 1888 | 1635 | |
| 1889 | 1636 | $unsafe_params_string = implode( '", "', $unsafe_params_in_redirect ); |
| 1890 | 1637 | |
| 1891 | 1638 | /* translators: %s: the names of two or more parameters in the redirect URL, separated by commas */ |
| 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 | |
| 1639 | + 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; | |
| 1893 | 1640 | } |
| 1894 | 1641 | |
| 1895 | 1642 | /** |
| 1896 | 1643 | * Returns an array of common reserved words in WordPress. |
| @@ -1956,19 +1703,17 @@ | ||
| 1956 | 1703 | * @since 5.0.16 |
| 1957 | 1704 | * |
| 1958 | 1705 | * @param string $url |
| 1959 | 1706 | * @param int $form_id |
| 1960 | - * | |
| 1961 | 1707 | * @return string |
| 1962 | 1708 | */ |
| 1963 | 1709 | public static function maybe_add_sanitize_url_attr( $url, $form_id ) { |
| 1964 | - if ( ! str_contains( $url, '[' ) ) { | |
| 1710 | + if ( false === strpos( $url, '[' ) ) { | |
| 1965 | 1711 | // Do nothing if no shortcodes are detected. |
| 1966 | 1712 | return $url; |
| 1967 | 1713 | } |
| 1968 | 1714 | |
| 1969 | 1715 | $parsed = wp_parse_url( $url ); |
| 1970 | - | |
| 1971 | 1716 | if ( empty( $parsed['query'] ) ) { |
| 1972 | 1717 | // Do nothing if no query can be detected in the url string. |
| 1973 | 1718 | return $url; |
| 1974 | 1719 | } |
| @@ -1974,10 +1719,10 @@ | ||
| 1974 | 1719 | } |
| 1975 | 1720 | |
| 1976 | 1721 | $original_query = $parsed['query']; |
| 1977 | 1722 | $query = $parsed['query']; |
| 1978 | - $shortcodes = FrmFieldsHelper::get_shortcodes( $query, $form_id ); | |
| 1979 | 1723 | |
| 1724 | + $shortcodes = FrmFieldsHelper::get_shortcodes( $query, $form_id ); | |
| 1980 | 1725 | if ( empty( $shortcodes[0] ) ) { |
| 1981 | 1726 | // No shortcodes found, do nothing. |
| 1982 | 1727 | return $url; |
| 1983 | 1728 | } |
| @@ -1989,21 +1734,20 @@ | ||
| 1989 | 1734 | // Skip if shortcodes. |
| 1990 | 1735 | continue; |
| 1991 | 1736 | } |
| 1992 | 1737 | |
| 1993 | - if ( str_contains( $options, 'sanitize_url=' ) || str_contains( $options, 'sanitize=' ) ) { | |
| 1738 | + if ( false !== strpos( $options, 'sanitize_url=' ) || false !== strpos( $options, 'sanitize=' ) ) { | |
| 1994 | 1739 | // A sanitize option is already set so leave it alone. |
| 1995 | 1740 | continue; |
| 1996 | 1741 | } |
| 1997 | 1742 | |
| 1998 | 1743 | $new_shortcode = '[' . $shortcodes[2][ $key ]; |
| 1999 | - | |
| 2000 | 1744 | if ( $options ) { |
| 2001 | 1745 | $new_shortcode .= ' ' . $options; |
| 2002 | 1746 | } |
| 1747 | + $new_shortcode .= ' sanitize_url=1]'; | |
| 2003 | 1748 | |
| 2004 | - $new_shortcode .= ' sanitize_url=1]'; | |
| 2005 | - $query = str_replace( $shortcode, $new_shortcode, $query ); | |
| 1749 | + $query = str_replace( $shortcode, $new_shortcode, $query ); | |
| 2006 | 1750 | }//end foreach |
| 2007 | 1751 | |
| 2008 | 1752 | if ( $query === $original_query ) { |
| 2009 | 1753 | return $url; |
| @@ -2012,8 +1756,20 @@ | ||
| 2012 | 1756 | return str_replace( $original_query, $query, $url ); |
| 2013 | 1757 | } |
| 2014 | 1758 | |
| 2015 | 1759 | /** |
| 1760 | + * Check if Pro isn't up to date yet. | |
| 1761 | + * 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). | |
| 1762 | + * | |
| 1763 | + * @since 6.2 | |
| 1764 | + * | |
| 1765 | + * @return bool | |
| 1766 | + */ | |
| 1767 | + public static function should_use_pro_for_ajax_submit() { | |
| 1768 | + return is_callable( 'FrmProForm::is_ajax_on' ) && ! is_callable( 'FrmProFormsHelper::lite_supports_ajax_submit' ); | |
| 1769 | + } | |
| 1770 | + | |
| 1771 | + /** | |
| 2016 | 1772 | * Outputs the appropriate button text in the publish box. |
| 2017 | 1773 | * |
| 2018 | 1774 | * @return void |
| 2019 | 1775 | */ |
| @@ -2028,181 +1784,24 @@ | ||
| 2028 | 1784 | } |
| 2029 | 1785 | } |
| 2030 | 1786 | |
| 2031 | 1787 | /** |
| 2032 | - * Strip characters similar to the WordPress sanitize_html_class function, but allow for [ and ]. | |
| 2033 | - * This allows shortcodes inside of the layout classes setting. | |
| 1788 | + * @since 3.0 | |
| 1789 | + * @deprecated 6.11 | |
| 2034 | 1790 | * |
| 2035 | - * @since 6.16 | |
| 2036 | - * | |
| 2037 | - * @param string $classname | |
| 2038 | - * | |
| 2039 | - * @return string | |
| 2040 | - */ | |
| 2041 | - public static function sanitize_layout_class( $classname ) { | |
| 2042 | - // Strip out any percent-encoded characters. | |
| 2043 | - $sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $classname ); | |
| 2044 | - | |
| 2045 | - // Limit to A-Z, a-z, 0-9, '_', '-', '[', ']'. | |
| 2046 | - return preg_replace( '/[^A-Za-z0-9_\-\[\]]/', '', $sanitized ); | |
| 2047 | - } | |
| 2048 | - | |
| 2049 | - /** | |
| 2050 | - * Returns true if the preview should be blocked. | |
| 2051 | - * | |
| 2052 | - * @since 6.20 | |
| 2053 | - * | |
| 2054 | - * @param string $form_key | |
| 2055 | - * | |
| 2056 | - * @return bool | |
| 2057 | - */ | |
| 2058 | - public static function should_block_preview( $form_key ) { | |
| 2059 | - $should_block = in_array( $form_key, array( 'contact-form', 'contact-us' ), true ) && ! current_user_can( 'frm_view_forms' ); | |
| 2060 | - /** | |
| 2061 | - * Filters whether the form preview should be blocked. | |
| 2062 | - * | |
| 2063 | - * @since 6.20 | |
| 2064 | - * | |
| 2065 | - * @param bool $should_block | |
| 2066 | - * @param string $form_key | |
| 2067 | - */ | |
| 2068 | - return (bool) apply_filters( 'frm_block_preview', $should_block, $form_key ); | |
| 2069 | - } | |
| 2070 | - | |
| 2071 | - /** | |
| 2072 | - * Checks if the form is loaded by API. | |
| 2073 | - * | |
| 2074 | - * @since 6.21 | |
| 2075 | - * | |
| 2076 | - * @return bool | |
| 2077 | - */ | |
| 2078 | - public static function form_is_loaded_by_api() { | |
| 2079 | - global $frm_vars; | |
| 2080 | - | |
| 2081 | - if ( ! empty( $frm_vars['inplace_edit'] ) ) { | |
| 2082 | - return true; | |
| 2083 | - } | |
| 2084 | - | |
| 2085 | - return self::is_formidable_api_form() || self::is_block_or_page_builder_preview(); | |
| 2086 | - } | |
| 2087 | - | |
| 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 | - /** | |
| 2100 | - * @since 6.21 | |
| 2101 | - * | |
| 2102 | - * @return bool | |
| 2103 | - */ | |
| 2104 | - private static function is_visual_views_preview() { | |
| 2105 | - return 'frm_views_process_box_preview' === FrmAppHelper::get_post_param( 'action' ); | |
| 2106 | - } | |
| 2107 | - | |
| 2108 | - /** | |
| 2109 | - * @since 6.21 | |
| 2110 | - * | |
| 2111 | - * @return bool | |
| 2112 | - */ | |
| 2113 | - private static function is_elementor_ajax() { | |
| 2114 | - return 'elementor_ajax' === FrmAppHelper::get_post_param( 'action' ); | |
| 2115 | - } | |
| 2116 | - | |
| 2117 | - /** | |
| 2118 | - * @since 6.21 | |
| 2119 | - * | |
| 2120 | - * @return bool | |
| 2121 | - */ | |
| 2122 | - private static function is_gutenberg_editor() { | |
| 2123 | - $url = FrmAppHelper::get_server_value( 'REQUEST_URI' ); | |
| 2124 | - | |
| 2125 | - if ( str_contains( $url, '/wp-json/wp/v2/block-renderer/formidable/simple-form' ) ) { | |
| 2126 | - return true; | |
| 2127 | - } | |
| 2128 | - | |
| 2129 | - if ( str_contains( urldecode( $url ), 'rest_route=/wp/v2/block-renderer/formidable/' ) ) { | |
| 2130 | - return true; | |
| 2131 | - } | |
| 2132 | - | |
| 2133 | - global $pagenow; | |
| 2134 | - return 'post.php' === $pagenow; | |
| 2135 | - } | |
| 2136 | - | |
| 2137 | - /** | |
| 2138 | - * @since 6.21 | |
| 2139 | - * | |
| 2140 | - * @return bool | |
| 2141 | - */ | |
| 2142 | - private static function is_formidable_api_form() { | |
| 2143 | - if ( ! class_exists( 'FrmAPIAppController' ) ) { | |
| 2144 | - return false; | |
| 2145 | - } | |
| 2146 | - | |
| 2147 | - $url = FrmAppHelper::get_server_value( 'REQUEST_URI' ); | |
| 2148 | - | |
| 2149 | - if ( str_contains( $url, '/wp-json/frm/v2/forms/' ) ) { | |
| 2150 | - // Prevent the honeypot from appearing for an API loaded form. | |
| 2151 | - // This is to prevent conflicts where the script is not working. | |
| 2152 | - return true; | |
| 2153 | - } | |
| 2154 | - | |
| 2155 | - if ( is_callable( 'FrmProFormState::get_from_request' ) ) { | |
| 2156 | - $api = FrmProFormState::get_from_request( 'a', 0 ); | |
| 2157 | - | |
| 2158 | - if ( $api ) { | |
| 2159 | - return true; | |
| 2160 | - } | |
| 2161 | - } | |
| 2162 | - | |
| 2163 | - return false; | |
| 2164 | - } | |
| 2165 | - | |
| 2166 | - /** | |
| 2167 | - * @since 6.30 | |
| 2168 | - * | |
| 1791 | + * @param array $atts | |
| 2169 | 1792 | * @return void |
| 2170 | 1793 | */ |
| 2171 | - public static function load_currency_js() { | |
| 2172 | - global $frm_vars; | |
| 1794 | + public static function actions_dropdown( $atts ) { | |
| 1795 | + _deprecated_function( __METHOD__, '6.11' ); | |
| 2173 | 1796 | |
| 2174 | - if ( empty( $frm_vars['currency'] ) ) { | |
| 1797 | + if ( ! FrmAppHelper::is_admin_page( 'formidable' ) ) { | |
| 2175 | 1798 | return; |
| 2176 | 1799 | } |
| 2177 | 1800 | |
| 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>'; | |
| 2183 | - } | |
| 2184 | - | |
| 2185 | - /** | |
| 2186 | - * Returns the form name or the no title text if the form name is empty. | |
| 2187 | - * | |
| 2188 | - * @since 6.30 | |
| 2189 | - * | |
| 2190 | - * @param array|stdClass $form The form data. | |
| 2191 | - * @param int $length The form name length to truncate to. | |
| 2192 | - * | |
| 2193 | - * @return string | |
| 2194 | - */ | |
| 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 ); | |
| 1801 | + $status = $atts['status']; | |
| 1802 | + $form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); | |
| 1803 | + $trash_link = self::delete_trash_info( $form_id, $status ); | |
| 1804 | + $links = self::get_action_links( $form_id, $status ); | |
| 1805 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php'; | |
| 2207 | 1806 | } |
| 2208 | 1807 | } |