| @@ -4,23 +4,11 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmFieldsHelper { |
| 7 | 7 | |
| 8 | - /** | |
| 9 | - * The context is memoized for re-use as the context is checked for each field. | |
| 10 | - * | |
| 11 | - * @var bool|null | |
| 12 | - */ | |
| 13 | - private static $context_is_safe_to_load_field_options_from_request_data; | |
| 8 | + public static function setup_new_vars( $type = '', $form_id = '' ) { | |
| 14 | 9 | |
| 15 | - /** | |
| 16 | - * @param string $type | |
| 17 | - * @param int|string $form_id | |
| 18 | - * | |
| 19 | - * @return array | |
| 20 | - */ | |
| 21 | - public static function setup_new_vars( $type = '', $form_id = '' ) { | |
| 22 | - if ( str_contains( $type, '|' ) ) { | |
| 10 | + if ( strpos( $type, '|' ) ) { | |
| 23 | 11 | list( $type, $setting ) = explode( '|', $type ); |
| 24 | 12 | } |
| 25 | 13 | |
| 26 | 14 | $values = self::get_default_field( $type ); |
| @@ -25,14 +13,9 @@ | ||
| 25 | 13 | |
| 26 | 14 | $values = self::get_default_field( $type ); |
| 27 | 15 | |
| 28 | 16 | global $wpdb; |
| 29 | - $field_count = FrmDb::get_var( | |
| 30 | - 'frm_fields', | |
| 31 | - array( 'form_id' => $form_id ), | |
| 32 | - 'field_order', | |
| 33 | - array( 'order_by' => 'field_order DESC' ) | |
| 34 | - ); | |
| 17 | + $field_count = FrmDb::get_var( 'frm_fields', array( 'form_id' => $form_id ), 'field_order', array( 'order_by' => 'field_order DESC' ) ); | |
| 35 | 18 | |
| 36 | 19 | $values['field_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_fields', 'field_key' ); |
| 37 | 20 | $values['form_id'] = $form_id; |
| 38 | 21 | $values['field_order'] = $field_count + 1; |
| @@ -38,10 +21,10 @@ | ||
| 38 | 21 | $values['field_order'] = $field_count + 1; |
| 39 | 22 | |
| 40 | 23 | $values['field_options']['custom_html'] = self::get_default_html( $type ); |
| 41 | 24 | |
| 42 | - if ( ! empty( $setting ) ) { | |
| 43 | - if ( in_array( $type, array( 'data', 'lookup' ), true ) ) { | |
| 25 | + if ( isset( $setting ) && ! empty( $setting ) ) { | |
| 26 | + if ( in_array( $type, array( 'data', 'lookup' ) ) ) { | |
| 44 | 27 | $values['field_options']['data_type'] = $setting; |
| 45 | 28 | } else { |
| 46 | 29 | $values['field_options'][ $setting ] = 1; |
| 47 | 30 | } |
| @@ -46,56 +29,31 @@ | ||
| 46 | 29 | $values['field_options'][ $setting ] = 1; |
| 47 | 30 | } |
| 48 | 31 | } |
| 49 | 32 | |
| 50 | - // Increase the field order of submit field and fields in the same row. | |
| 51 | - FrmSubmitHelper::update_last_row_fields_order_when_adding_field( $field_count ); | |
| 52 | - | |
| 53 | 33 | return $values; |
| 54 | 34 | } |
| 55 | 35 | |
| 56 | - /** | |
| 57 | - * @param array $field | |
| 58 | - * @param string $plus | |
| 59 | - * | |
| 60 | - * @return string | |
| 61 | - */ | |
| 62 | 36 | public static function get_html_id( $field, $plus = '' ) { |
| 63 | 37 | return apply_filters( 'frm_field_html_id', 'field_' . $field['field_key'] . $plus, $field ); |
| 64 | 38 | } |
| 65 | 39 | |
| 66 | - /** | |
| 67 | - * @param object $field | |
| 68 | - * @param bool $doing_ajax | |
| 69 | - * | |
| 70 | - * @return array | |
| 71 | - */ | |
| 72 | 40 | public static function setup_edit_vars( $field, $doing_ajax = false ) { |
| 73 | 41 | $values = self::field_object_to_array( $field ); |
| 42 | + | |
| 74 | 43 | return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) ); |
| 75 | 44 | } |
| 76 | 45 | |
| 77 | - /** | |
| 78 | - * @param object $field | |
| 79 | - * | |
| 80 | - * @return array | |
| 81 | - */ | |
| 82 | 46 | public static function field_object_to_array( $field ) { |
| 83 | 47 | $values = (array) $field; |
| 84 | 48 | |
| 85 | 49 | self::fill_field_array( $field, $values ); |
| 86 | 50 | |
| 87 | - $values['custom_html'] = $field->field_options['custom_html'] ?? self::get_default_html( $field->type ); | |
| 51 | + $values['custom_html'] = ( isset( $field->field_options['custom_html'] ) ) ? $field->field_options['custom_html'] : self::get_default_html( $field->type ); | |
| 88 | 52 | |
| 89 | 53 | return $values; |
| 90 | 54 | } |
| 91 | 55 | |
| 92 | - /** | |
| 93 | - * @param object $field | |
| 94 | - * @param array $field_array | |
| 95 | - * | |
| 96 | - * @return void | |
| 97 | - */ | |
| 98 | 56 | private static function fill_field_array( $field, array &$field_array ) { |
| 99 | 57 | $field_array['options'] = $field->options; |
| 100 | 58 | $field_array['value'] = $field->default_value; |
| 101 | 59 | |
| @@ -104,17 +62,11 @@ | ||
| 104 | 62 | $field_array = array_merge( (array) $field->field_options, $field_array ); |
| 105 | 63 | } |
| 106 | 64 | |
| 107 | 65 | /** |
| 108 | - * Prepare field while creating a new entry. | |
| 66 | + * Prepare field while creating a new entry | |
| 109 | 67 | * |
| 110 | 68 | * @since 3.0 |
| 111 | - * | |
| 112 | - * @param array $field_array Field values array, passed by reference. | |
| 113 | - * @param stdClass $field Field object. | |
| 114 | - * @param array $args Additional arguments. | |
| 115 | - * | |
| 116 | - * @return void | |
| 117 | 69 | */ |
| 118 | 70 | public static function prepare_new_front_field( &$field_array, $field, $args = array() ) { |
| 119 | 71 | $args['action'] = 'new'; |
| 120 | 72 | self::prepare_front_field( $field_array, $field, $args ); |
| @@ -120,18 +72,11 @@ | ||
| 120 | 72 | self::prepare_front_field( $field_array, $field, $args ); |
| 121 | 73 | } |
| 122 | 74 | |
| 123 | 75 | /** |
| 124 | - * Prepare field while editing an entry. | |
| 76 | + * Prepare field while editing an entry | |
| 125 | 77 | * |
| 126 | 78 | * @since 3.0 |
| 127 | - * | |
| 128 | - * @param array $field_array Field values array, passed by reference. | |
| 129 | - * @param array|stdClass $field Field object or array. | |
| 130 | - * @param int $entry_id Entry ID. | |
| 131 | - * @param array $args Additional arguments. | |
| 132 | - * | |
| 133 | - * @return void | |
| 134 | 79 | */ |
| 135 | 80 | public static function prepare_edit_front_field( &$field_array, $field, $entry_id = 0, $args = array() ) { |
| 136 | 81 | $args['entry_id'] = $entry_id; |
| 137 | 82 | $args['action'] = 'edit'; |
| @@ -141,14 +86,8 @@ | ||
| 141 | 86 | /** |
| 142 | 87 | * Prepare field while creating a new entry |
| 143 | 88 | * |
| 144 | 89 | * @since 3.0 |
| 145 | - * | |
| 146 | - * @param array $field_array | |
| 147 | - * @param stdClass $field | |
| 148 | - * @param array $args | |
| 149 | - * | |
| 150 | - * @return void | |
| 151 | 90 | */ |
| 152 | 91 | private static function prepare_front_field( &$field_array, $field, $args ) { |
| 153 | 92 | self::fill_default_field_opts( $field, $field_array ); |
| 154 | 93 | self::fill_cleared_strings( $field, $field_array ); |
| @@ -153,30 +92,17 @@ | ||
| 153 | 92 | self::fill_default_field_opts( $field, $field_array ); |
| 154 | 93 | self::fill_cleared_strings( $field, $field_array ); |
| 155 | 94 | |
| 156 | 95 | // Track the original field's type |
| 157 | - $field_array['original_type'] = $field->field_options['original_type'] ?? $field->type; | |
| 96 | + $field_array['original_type'] = isset( $field->field_options['original_type'] ) ? $field->field_options['original_type'] : $field->type; | |
| 158 | 97 | |
| 159 | 98 | self::prepare_field_options_for_display( $field_array, $field, $args ); |
| 160 | 99 | |
| 161 | - if ( $args['action'] === 'edit' ) { | |
| 162 | - /** | |
| 163 | - * @param array $field_array | |
| 164 | - * @param stdClass $field | |
| 165 | - * @param int|string $entry_id | |
| 166 | - * @param array $args | |
| 167 | - */ | |
| 100 | + if ( $args['action'] == 'edit' ) { | |
| 168 | 101 | $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $args['entry_id'], $args ); |
| 169 | - | |
| 170 | - return; | |
| 102 | + } else { | |
| 103 | + $field_array = apply_filters( 'frm_setup_new_fields_vars', $field_array, $field, $args ); | |
| 171 | 104 | } |
| 172 | - | |
| 173 | - /** | |
| 174 | - * @param array $field_array | |
| 175 | - * @param stdClass $field | |
| 176 | - * @param array $args | |
| 177 | - */ | |
| 178 | - $field_array = apply_filters( 'frm_setup_new_fields_vars', $field_array, $field, $args ); | |
| 179 | 105 | } |
| 180 | 106 | |
| 181 | 107 | /** |
| 182 | 108 | * @since 3.0 |
| @@ -186,8 +112,9 @@ | ||
| 186 | 112 | * @return array |
| 187 | 113 | */ |
| 188 | 114 | public static function get_default_field_options( $type ) { |
| 189 | 115 | $field_type = FrmFieldFactory::get_field_type( $type ); |
| 116 | + | |
| 190 | 117 | return $field_type->get_default_field_options(); |
| 191 | 118 | } |
| 192 | 119 | |
| 193 | 120 | /** |
| @@ -193,16 +120,14 @@ | ||
| 193 | 120 | /** |
| 194 | 121 | * @since 3.0 |
| 195 | 122 | * |
| 196 | 123 | * @param object $field |
| 197 | - * @param array $values | |
| 198 | - * | |
| 199 | - * @return void | |
| 124 | + * @param array $values | |
| 200 | 125 | */ |
| 201 | 126 | private static function fill_default_field_opts( $field, array &$values ) { |
| 202 | - $check_post = self::context_is_safe_to_load_field_options_from_request_data(); | |
| 203 | - $defaults = self::get_default_field_options_from_field( $field, $values ); | |
| 127 | + $check_post = FrmAppHelper::is_admin_page() && $_POST && isset( $_POST['field_options'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 204 | 128 | |
| 129 | + $defaults = self::get_default_field_options_from_field( $field, $values ); | |
| 205 | 130 | if ( ! $check_post ) { |
| 206 | 131 | $defaults['required_indicator'] = ''; |
| 207 | 132 | $defaults['original_type'] = $field->type; |
| 208 | 133 | } |
| @@ -207,65 +132,16 @@ | ||
| 207 | 132 | $defaults['original_type'] = $field->type; |
| 208 | 133 | } |
| 209 | 134 | |
| 210 | 135 | foreach ( $defaults as $opt => $default ) { |
| 211 | - $values[ $opt ] = $field->field_options[ $opt ] ?? $default; | |
| 136 | + $values[ $opt ] = isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default; | |
| 212 | 137 | |
| 213 | 138 | if ( $check_post ) { |
| 214 | 139 | self::get_posted_field_setting( $opt . '_' . $field->id, $values[ $opt ] ); |
| 215 | 140 | } |
| 216 | - } | |
| 217 | - } | |
| 218 | 141 | |
| 219 | - /** | |
| 220 | - * The fill_default_field_opts method is called when loading a field. | |
| 221 | - * This is used to preserve the $_POST data after updating settings for a field. | |
| 222 | - * To prevent this from happening when creating an entry, we need to check the context. | |
| 223 | - * | |
| 224 | - * @return bool | |
| 225 | - */ | |
| 226 | - private static function context_is_safe_to_load_field_options_from_request_data() { | |
| 227 | - if ( isset( self::$context_is_safe_to_load_field_options_from_request_data ) ) { | |
| 228 | - return self::$context_is_safe_to_load_field_options_from_request_data; | |
| 142 | + unset( $opt, $default ); | |
| 229 | 143 | } |
| 230 | - | |
| 231 | - $function = function () { | |
| 232 | - if ( ! FrmAppHelper::is_admin_page() ) { | |
| 233 | - return false; | |
| 234 | - } | |
| 235 | - | |
| 236 | - if ( ! $_POST || ! isset( $_POST['field_options'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 237 | - return false; | |
| 238 | - } | |
| 239 | - | |
| 240 | - if ( ! current_user_can( 'frm_edit_forms' ) ) { | |
| 241 | - return false; | |
| 242 | - } | |
| 243 | - | |
| 244 | - $action = FrmAppHelper::get_post_param( 'action', '', 'sanitize_title' ); | |
| 245 | - | |
| 246 | - if ( 'frm_forms_preview' === $action ) { | |
| 247 | - // Never trigger when previewing. | |
| 248 | - return false; | |
| 249 | - } | |
| 250 | - | |
| 251 | - // Confirm an allowed action is being used, and that the correct nonce is being used. | |
| 252 | - if ( 'update' === $action ) { | |
| 253 | - $nonce = FrmAppHelper::get_post_param( 'frm_save_form', '', 'sanitize_text_field' ); | |
| 254 | - return wp_verify_nonce( $nonce, 'frm_save_form_nonce' ); | |
| 255 | - } | |
| 256 | - | |
| 257 | - $action = FrmAppHelper::get_post_param( 'frm_action', '', 'sanitize_title' ); | |
| 258 | - | |
| 259 | - if ( 'update_settings' === $action ) { | |
| 260 | - $nonce = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); | |
| 261 | - return wp_verify_nonce( $nonce, 'process_form_nonce' ); | |
| 262 | - } | |
| 263 | - }; | |
| 264 | - | |
| 265 | - self::$context_is_safe_to_load_field_options_from_request_data = $function(); | |
| 266 | - | |
| 267 | - return self::$context_is_safe_to_load_field_options_from_request_data; | |
| 268 | 144 | } |
| 269 | 145 | |
| 270 | 146 | /** |
| 271 | 147 | * Fill the required message, invalid message, |
| @@ -273,28 +149,26 @@ | ||
| 273 | 149 | * |
| 274 | 150 | * @since 3.0 |
| 275 | 151 | * |
| 276 | 152 | * @param object $field |
| 277 | - * @param array $field_array | |
| 278 | - * | |
| 279 | - * @return void | |
| 153 | + * @param array $field_array | |
| 280 | 154 | */ |
| 281 | 155 | private static function fill_cleared_strings( $field, array &$field_array ) { |
| 282 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 156 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 157 | + | |
| 283 | 158 | if ( '' == $field_array['blank'] && '1' === $field_array['required'] ) { |
| 284 | - $field_array['blank'] = self::default_blank_msg(); | |
| 159 | + $field_array['blank'] = $frm_settings->blank_msg; | |
| 285 | 160 | } |
| 286 | 161 | |
| 287 | - if ( '' === $field_array['invalid'] ) { | |
| 162 | + if ( '' == $field_array['invalid'] ) { | |
| 288 | 163 | if ( 'captcha' === $field->type ) { |
| 289 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 290 | 164 | $field_array['invalid'] = $frm_settings->re_msg; |
| 291 | 165 | } else { |
| 292 | - $field_array['invalid'] = self::default_invalid_msg(); | |
| 166 | + /* translators: %s: Field name */ | |
| 167 | + $field_array['invalid'] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] ); | |
| 293 | 168 | } |
| 294 | 169 | } |
| 295 | 170 | |
| 296 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 297 | 171 | if ( '' == $field_array['custom_html'] ) { |
| 298 | 172 | $field_array['custom_html'] = self::get_default_html( $field->type ); |
| 299 | 173 | } |
| 300 | 174 | } |
| @@ -299,48 +173,12 @@ | ||
| 299 | 173 | } |
| 300 | 174 | } |
| 301 | 175 | |
| 302 | 176 | /** |
| 303 | - * @since 6.8.3 | |
| 304 | - * | |
| 305 | - * @return string | |
| 306 | - */ | |
| 307 | - public static function default_invalid_msg() { | |
| 308 | - /* translators: %s: [field_name] shortcode (Which gets replaced by a Field Name) */ | |
| 309 | - return sprintf( __( '%s is invalid', 'formidable' ), '[field_name]' ); | |
| 310 | - } | |
| 311 | - | |
| 312 | - /** | |
| 313 | - * @since 6.8.3 | |
| 314 | - * | |
| 315 | - * @return string | |
| 316 | - */ | |
| 317 | - public static function default_unique_msg() { | |
| 318 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 319 | - $unique_message = $frm_settings->unique_msg; | |
| 320 | - return str_replace( 'This value', '[field_name]', $unique_message ); | |
| 321 | - } | |
| 322 | - | |
| 323 | - /** | |
| 324 | - * @since 6.8.3 | |
| 325 | - * | |
| 326 | - * @return string | |
| 327 | - */ | |
| 328 | - public static function default_blank_msg() { | |
| 329 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 330 | - $blank_message = $frm_settings->blank_msg; | |
| 331 | - return str_replace( 'This field', '[field_name]', $blank_message ); | |
| 332 | - } | |
| 333 | - | |
| 334 | - /** | |
| 335 | - * When loading settings for a field, check the $_POST data and possibly use that instead of the DB value. | |
| 336 | - * | |
| 337 | 177 | * @since 3.0 |
| 338 | 178 | * |
| 339 | 179 | * @param string $setting |
| 340 | - * @param mixed $value | |
| 341 | - * | |
| 342 | - * @return void | |
| 180 | + * @param mixed $value | |
| 343 | 181 | */ |
| 344 | 182 | private static function get_posted_field_setting( $setting, &$value ) { |
| 345 | 183 | if ( ! isset( $_POST['field_options'][ $setting ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 346 | 184 | return; |
| @@ -345,20 +183,16 @@ | ||
| 345 | 183 | if ( ! isset( $_POST['field_options'][ $setting ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 346 | 184 | return; |
| 347 | 185 | } |
| 348 | 186 | |
| 349 | - if ( str_contains( $setting, 'html' ) ) { | |
| 350 | - $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 351 | - | |
| 352 | - // Conditionally strip script tags if the user sending $_POST data is not allowed to use unfiltered HTML. | |
| 353 | - if ( ! FrmAppHelper::allow_unfiltered_html() ) { | |
| 354 | - $value = FrmAppHelper::kses( $value, 'all' ); | |
| 355 | - } | |
| 356 | - } elseif ( str_starts_with( $setting, 'format_' ) ) { | |
| 187 | + if ( strpos( $setting, 'html' ) !== false ) { | |
| 188 | + // Strip slashes from HTML but not regex or script tags. | |
| 189 | + $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing | |
| 190 | + } elseif ( strpos( $setting, 'format_' ) === 0 ) { | |
| 357 | 191 | // TODO: Remove stripslashes on output, and use on input only. |
| 358 | - $value = sanitize_text_field( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 192 | + $value = sanitize_text_field( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing | |
| 359 | 193 | } else { |
| 360 | - $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 194 | + $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing | |
| 361 | 195 | FrmAppHelper::sanitize_value( 'wp_kses_post', $value ); |
| 362 | 196 | } |
| 363 | 197 | } |
| 364 | 198 | |
| @@ -365,9 +199,9 @@ | ||
| 365 | 199 | /** |
| 366 | 200 | * @since 3.0 |
| 367 | 201 | * |
| 368 | 202 | * @param object $field |
| 369 | - * @param array $values The field array is needed for hooks. | |
| 203 | + * @param array $values The field array is needed for hooks | |
| 370 | 204 | * |
| 371 | 205 | * @return array |
| 372 | 206 | */ |
| 373 | 207 | public static function get_default_field_options_from_field( $field, $values = array() ) { |
| @@ -372,11 +206,13 @@ | ||
| 372 | 206 | */ |
| 373 | 207 | public static function get_default_field_options_from_field( $field, $values = array() ) { |
| 374 | 208 | $field_type = self::get_original_field( $field ); |
| 375 | 209 | $opts = $field_type->get_default_field_options(); |
| 376 | - $opts = apply_filters( 'frm_default_field_opts', $opts, $values, $field ); | |
| 377 | 210 | |
| 378 | - return apply_filters( 'frm_default_' . $field->type . '_field_opts', $opts, $values, $field ); | |
| 211 | + $opts = apply_filters( 'frm_default_field_opts', $opts, $values, $field ); | |
| 212 | + $opts = apply_filters( 'frm_default_' . $field->type . '_field_opts', $opts, $values, $field ); | |
| 213 | + | |
| 214 | + return $opts; | |
| 379 | 215 | } |
| 380 | 216 | |
| 381 | 217 | /** |
| 382 | 218 | * @since 3.0 |
| @@ -382,14 +218,13 @@ | ||
| 382 | 218 | * @since 3.0 |
| 383 | 219 | * |
| 384 | 220 | * @param object $field |
| 385 | 221 | * |
| 386 | - * @return FrmFieldType | |
| 222 | + * @return array | |
| 387 | 223 | */ |
| 388 | 224 | private static function get_original_field( $field ) { |
| 389 | 225 | $original_type = FrmField::get_option( $field, 'original_type' ); |
| 390 | - | |
| 391 | - if ( $original_type && $field->type !== $original_type ) { | |
| 226 | + if ( ! empty( $original_type ) && $field->type != $original_type ) { | |
| 392 | 227 | $field->type = $original_type; |
| 393 | 228 | } |
| 394 | 229 | |
| 395 | 230 | return FrmFieldFactory::get_field_object( $field ); |
| @@ -397,13 +232,11 @@ | ||
| 397 | 232 | |
| 398 | 233 | /** |
| 399 | 234 | * @since 3.0 |
| 400 | 235 | * |
| 401 | - * @param array $field_array | |
| 236 | + * @param array $field_array | |
| 402 | 237 | * @param object $field |
| 403 | - * @param array $atts | |
| 404 | - * | |
| 405 | - * @return void | |
| 238 | + * @param array $atts | |
| 406 | 239 | */ |
| 407 | 240 | private static function prepare_field_options_for_display( &$field_array, $field, $atts ) { |
| 408 | 241 | $field_obj = FrmFieldFactory::get_field_object( $field ); |
| 409 | 242 | $field_array = $field_obj->prepare_front_field( $field_array, $atts ); |
| @@ -417,19 +250,12 @@ | ||
| 417 | 250 | * @return array |
| 418 | 251 | */ |
| 419 | 252 | public static function get_default_field( $type ) { |
| 420 | 253 | $field_type = FrmFieldFactory::get_field_type( $type ); |
| 254 | + | |
| 421 | 255 | return $field_type->get_new_field_defaults(); |
| 422 | 256 | } |
| 423 | 257 | |
| 424 | - /** | |
| 425 | - * @param array $values | |
| 426 | - * @param object $field | |
| 427 | - * @param int|string $form_id | |
| 428 | - * @param string $new_key | |
| 429 | - * | |
| 430 | - * @return void | |
| 431 | - */ | |
| 432 | 258 | public static function fill_field( &$values, $field, $form_id, $new_key = '' ) { |
| 433 | 259 | global $wpdb; |
| 434 | 260 | |
| 435 | 261 | $values['field_key'] = FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
| @@ -444,26 +270,29 @@ | ||
| 444 | 270 | |
| 445 | 271 | /** |
| 446 | 272 | * @since 2.0 |
| 447 | 273 | * |
| 448 | - * @param array|object $field | |
| 449 | - * @param string $error | |
| 274 | + * @param $field | |
| 275 | + * @param $error | |
| 450 | 276 | * |
| 451 | 277 | * @return string |
| 452 | 278 | */ |
| 453 | 279 | public static function get_error_msg( $field, $error ) { |
| 454 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 455 | - $conf_msg = __( 'The entered values do not match', 'formidable' ); | |
| 456 | - $defaults = array( | |
| 280 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 281 | + $default_settings = $frm_settings->default_options(); | |
| 282 | + $field_name = is_array( $field ) ? $field['name'] : $field->name; | |
| 283 | + | |
| 284 | + $conf_msg = __( 'The entered values do not match', 'formidable' ); | |
| 285 | + $defaults = array( | |
| 457 | 286 | 'unique_msg' => array( |
| 458 | - 'full' => self::default_unique_msg(), | |
| 287 | + 'full' => $default_settings['unique_msg'], | |
| 459 | 288 | /* translators: %s: Field name */ |
| 460 | - 'part' => sprintf( __( '%s must be unique', 'formidable' ), '[field_name]' ), | |
| 289 | + 'part' => sprintf( __( '%s must be unique', 'formidable' ), $field_name ), | |
| 461 | 290 | ), |
| 462 | 291 | 'invalid' => array( |
| 463 | 292 | 'full' => __( 'This field is invalid', 'formidable' ), |
| 464 | 293 | /* translators: %s: Field name */ |
| 465 | - 'part' => sprintf( __( '%s is invalid', 'formidable' ), '[field_name]' ), | |
| 294 | + 'part' => sprintf( __( '%s is invalid', 'formidable' ), $field_name ), | |
| 466 | 295 | ), |
| 467 | 296 | 'blank' => array( |
| 468 | 297 | 'full' => $frm_settings->blank_msg, |
| 469 | 298 | 'part' => $frm_settings->blank_msg, |
| @@ -473,107 +302,26 @@ | ||
| 473 | 302 | 'part' => $conf_msg, |
| 474 | 303 | ), |
| 475 | 304 | ); |
| 476 | 305 | |
| 477 | - /** | |
| 478 | - * @since 6.28 | |
| 479 | - * | |
| 480 | - * @param array $defaults | |
| 481 | - * @param array|object $field | |
| 482 | - */ | |
| 483 | - $defaults = apply_filters( 'frm_default_field_validation_messages', $defaults, $field ); | |
| 484 | - | |
| 485 | 306 | $msg = FrmField::get_option( $field, $error ); |
| 486 | - $msg = $msg ? $msg : $defaults[ $error ]['part']; | |
| 307 | + $msg = empty( $msg ) ? $defaults[ $error ]['part'] : $msg; | |
| 487 | 308 | $msg = do_shortcode( $msg ); |
| 488 | 309 | |
| 489 | - return self::maybe_replace_substrings_with_field_name( $msg, $error, $field ); | |
| 310 | + return $msg; | |
| 490 | 311 | } |
| 491 | 312 | |
| 492 | - /** | |
| 493 | - * @since 6.8.3 | |
| 494 | - * | |
| 495 | - * @param string $msg | |
| 496 | - * @param string $error | |
| 497 | - * @param array|object $field | |
| 498 | - * | |
| 499 | - * @return string | |
| 500 | - */ | |
| 501 | - private static function maybe_replace_substrings_with_field_name( $msg, $error, $field ) { | |
| 502 | - $field_name = is_array( $field ) ? $field['name'] : $field->name; | |
| 503 | - $field_name = FrmAppHelper::maybe_kses( $field_name ); | |
| 504 | - $substrings = self::get_substrings_to_replace_with_field_name( $field_name, compact( 'msg', 'error', 'field' ) ); | |
| 505 | - | |
| 506 | - // Use the "This value"/"This field" placeholder strings if field name is empty. | |
| 507 | - if ( ! $field_name ) { | |
| 508 | - $field_name = 'unique_msg' === $error ? __( 'This value', 'formidable' ) : __( 'This field', 'formidable' ); | |
| 509 | - } | |
| 510 | - | |
| 511 | - return str_replace( $substrings, $field_name, $msg ); | |
| 512 | - } | |
| 513 | - | |
| 514 | - /** | |
| 515 | - * @since 6.8.3 | |
| 516 | - * | |
| 517 | - * @param string $field_name | |
| 518 | - * @param array $filter_args { | |
| 519 | - * Filter arguments. | |
| 520 | - * | |
| 521 | - * @type string $msg The current error message before the substrings are replaced. | |
| 522 | - * @type string $error A key including 'unique_msg', 'invalid', 'blank', or 'conf_msg'. | |
| 523 | - * @type array|object $field The field with the error. | |
| 524 | - * } | |
| 525 | - * | |
| 526 | - * @return array | |
| 527 | - */ | |
| 528 | - private static function get_substrings_to_replace_with_field_name( $field_name, $filter_args ) { | |
| 529 | - $substrings = array( '[field_name]' ); | |
| 530 | - | |
| 531 | - if ( $field_name ) { | |
| 532 | - array_push( $substrings, 'This value', 'This field' ); | |
| 533 | - } | |
| 534 | - | |
| 535 | - /** | |
| 536 | - * @since 6.8.3 | |
| 537 | - * | |
| 538 | - * @param array<string> $substrings | |
| 539 | - * @param array $filter_args | |
| 540 | - */ | |
| 541 | - $filtered_substrings = apply_filters( 'frm_error_substrings_to_replace_with_field_name', $substrings, $filter_args ); | |
| 542 | - | |
| 543 | - if ( is_array( $filtered_substrings ) ) { | |
| 544 | - $substrings = $filtered_substrings; | |
| 545 | - } else { | |
| 546 | - _doing_it_wrong( __METHOD__, 'Only arrays should be returned when using the frm_error_substrings_to_replace_with_field_name filter.', '6.8.3' ); | |
| 547 | - } | |
| 548 | - | |
| 549 | - return $substrings; | |
| 550 | - } | |
| 551 | - | |
| 552 | - /** | |
| 553 | - * @param int|string $form_id | |
| 554 | - * @param array $error | |
| 555 | - * | |
| 556 | - * @return array | |
| 557 | - */ | |
| 558 | 313 | public static function get_form_fields( $form_id, $error = array() ) { |
| 559 | 314 | $fields = FrmField::get_all_for_form( $form_id ); |
| 560 | 315 | |
| 561 | - FrmFieldName::track_first_name_field( $fields ); | |
| 562 | - | |
| 563 | 316 | return apply_filters( 'frm_get_paged_fields', $fields, $form_id, $error ); |
| 564 | 317 | } |
| 565 | 318 | |
| 566 | - /** | |
| 567 | - * @param string $type | |
| 568 | - * | |
| 569 | - * @return string | |
| 570 | - */ | |
| 571 | 319 | public static function get_default_html( $type = 'text' ) { |
| 572 | 320 | $field = FrmFieldFactory::get_field_type( $type ); |
| 573 | 321 | $default_html = $field->default_html(); |
| 574 | 322 | |
| 575 | - // These hooks are here for reverse compatibility since 3.0 | |
| 323 | + // these hooks are here for reverse compatibility since 3.0 | |
| 576 | 324 | if ( ! apply_filters( 'frm_normal_field_type_html', true, $type ) ) { |
| 577 | 325 | $default_html = apply_filters( 'frm_other_custom_html', '', $type ); |
| 578 | 326 | } |
| 579 | 327 | |
| @@ -580,21 +328,15 @@ | ||
| 580 | 328 | return apply_filters( 'frm_custom_html', $default_html, $type ); |
| 581 | 329 | } |
| 582 | 330 | |
| 583 | 331 | /** |
| 584 | - * @param array $fields | |
| 585 | - * @param array $errors | |
| 332 | + * @param array $fields | |
| 333 | + * @param array $errors | |
| 586 | 334 | * @param object $form |
| 587 | - * @param object $form_action | |
| 588 | - * | |
| 589 | - * @return void | |
| 335 | + * @param $form_action | |
| 590 | 336 | */ |
| 591 | 337 | public static function show_fields( $fields, $errors, $form, $form_action ) { |
| 592 | 338 | foreach ( $fields as $field ) { |
| 593 | - if ( ! is_array( $field ) ) { | |
| 594 | - continue; | |
| 595 | - } | |
| 596 | - | |
| 597 | 339 | $field_obj = FrmFieldFactory::get_field_type( $field['type'], $field ); |
| 598 | 340 | $field_obj->show_field( compact( 'errors', 'form', 'form_action' ) ); |
| 599 | 341 | } |
| 600 | 342 | } |
| @@ -601,25 +343,19 @@ | ||
| 601 | 343 | |
| 602 | 344 | /** |
| 603 | 345 | * @since 3.0 |
| 604 | 346 | * |
| 605 | - * @param array $atts | |
| 606 | - * @param array|string $value | |
| 607 | - * | |
| 608 | - * @return void | |
| 347 | + * @param array $atts | |
| 348 | + * @param string|array $value | |
| 609 | 349 | */ |
| 610 | 350 | public static function run_wpautop( $atts, &$value ) { |
| 611 | - $autop = $atts['wpautop'] ?? true; | |
| 612 | - | |
| 613 | - if ( ! apply_filters( 'frm_use_wpautop', $autop ) ) { | |
| 614 | - return; | |
| 351 | + $autop = isset( $atts['wpautop'] ) ? $atts['wpautop'] : true; | |
| 352 | + if ( apply_filters( 'frm_use_wpautop', $autop ) ) { | |
| 353 | + if ( is_array( $value ) ) { | |
| 354 | + $value = implode( "\n", $value ); | |
| 355 | + } | |
| 356 | + $value = wpautop( $value ); | |
| 615 | 357 | } |
| 616 | - | |
| 617 | - if ( is_array( $value ) ) { | |
| 618 | - $value = implode( "\n", $value ); | |
| 619 | - } | |
| 620 | - | |
| 621 | - $value = wpautop( $value ); | |
| 622 | 358 | } |
| 623 | 359 | |
| 624 | 360 | /** |
| 625 | 361 | * Get the class to use for the label position |
| @@ -624,19 +360,13 @@ | ||
| 624 | 360 | /** |
| 625 | 361 | * Get the class to use for the label position |
| 626 | 362 | * |
| 627 | 363 | * @since 2.05 |
| 628 | - * | |
| 629 | - * @param string $position | |
| 630 | - * @param array $field | |
| 631 | - * @param bool|object|string $form | |
| 632 | - * | |
| 633 | - * @return string | |
| 634 | 364 | */ |
| 635 | - public static function label_position( $position, $field, $form ) { | |
| 636 | - if ( $position ) { | |
| 637 | - if ( $position === 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) { | |
| 638 | - return 'top'; | |
| 365 | + public static function &label_position( $position, $field, $form ) { | |
| 366 | + if ( $position && $position != '' ) { | |
| 367 | + if ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) { | |
| 368 | + $position = 'top'; | |
| 639 | 369 | } |
| 640 | 370 | |
| 641 | 371 | return $position; |
| 642 | 372 | } |
| @@ -641,19 +371,20 @@ | ||
| 641 | 371 | return $position; |
| 642 | 372 | } |
| 643 | 373 | |
| 644 | 374 | $position = FrmStylesController::get_style_val( 'position', $form ); |
| 645 | - | |
| 646 | - if ( $position === 'none' ) { | |
| 375 | + if ( $position == 'none' ) { | |
| 647 | 376 | $position = 'top'; |
| 648 | - } elseif ( $position === 'no_label' ) { | |
| 377 | + } elseif ( $position == 'no_label' ) { | |
| 649 | 378 | $position = 'none'; |
| 650 | - } elseif ( $position === 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) { | |
| 379 | + } elseif ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) { | |
| 651 | 380 | $position = 'top'; |
| 652 | 381 | } |
| 653 | 382 | |
| 654 | 383 | $position = apply_filters( 'frm_html_label_position', $position, $field, $form ); |
| 655 | - return $position ? $position : 'top'; | |
| 384 | + $position = ( ! empty( $position ) ) ? $position : 'top'; | |
| 385 | + | |
| 386 | + return $position; | |
| 656 | 387 | } |
| 657 | 388 | |
| 658 | 389 | /** |
| 659 | 390 | * Check if this field type allows placeholders |
| @@ -658,11 +389,9 @@ | ||
| 658 | 389 | /** |
| 659 | 390 | * Check if this field type allows placeholders |
| 660 | 391 | * |
| 661 | 392 | * @since 2.05 |
| 662 | - * | |
| 663 | 393 | * @param string $type |
| 664 | - * | |
| 665 | 394 | * @return bool |
| 666 | 395 | */ |
| 667 | 396 | public static function is_placeholder_field_type( $type ) { |
| 668 | 397 | return ! in_array( $type, array( 'radio', 'checkbox', 'hidden', 'file' ), true ); |
| @@ -667,19 +396,11 @@ | ||
| 667 | 396 | public static function is_placeholder_field_type( $type ) { |
| 668 | 397 | return ! in_array( $type, array( 'radio', 'checkbox', 'hidden', 'file' ), true ); |
| 669 | 398 | } |
| 670 | 399 | |
| 671 | - /** | |
| 672 | - * @param array $field | |
| 673 | - * @param int|string $opt_key | |
| 674 | - * @param string $type | |
| 675 | - * | |
| 676 | - * @return string | |
| 677 | - */ | |
| 678 | 400 | public static function get_checkbox_id( $field, $opt_key, $type = 'checkbox' ) { |
| 679 | 401 | $id = $field['id']; |
| 680 | - | |
| 681 | - if ( ! empty( $field['in_section'] ) && ! FrmAppHelper::is_admin_page( 'formidable' ) ) { | |
| 402 | + if ( isset( $field['in_section'] ) && $field['in_section'] && ! FrmAppHelper::is_admin_page( 'formidable' ) ) { | |
| 682 | 403 | $id .= '-' . $field['in_section']; |
| 683 | 404 | } |
| 684 | 405 | |
| 685 | 406 | return 'frm_' . $type . '_' . $id . '-' . $opt_key; |
| @@ -684,13 +405,8 @@ | ||
| 684 | 405 | |
| 685 | 406 | return 'frm_' . $type . '_' . $id . '-' . $opt_key; |
| 686 | 407 | } |
| 687 | 408 | |
| 688 | - /** | |
| 689 | - * @param array $field | |
| 690 | - * | |
| 691 | - * @return void | |
| 692 | - */ | |
| 693 | 409 | public static function show_single_option( $field ) { |
| 694 | 410 | self::hidden_field_option( $field ); |
| 695 | 411 | |
| 696 | 412 | if ( ! is_array( $field['options'] ) ) { |
| @@ -696,28 +412,28 @@ | ||
| 696 | 412 | if ( ! is_array( $field['options'] ) ) { |
| 697 | 413 | return; |
| 698 | 414 | } |
| 699 | 415 | |
| 700 | - $base_name = 'default_value_' . $field['id']; | |
| 701 | - $html_id = $field['html_id'] ?? self::get_html_id( $field ); | |
| 702 | - $default_type = self::get_default_value_type( $field ); | |
| 703 | - $options_count = count( $field['options'] ); | |
| 416 | + $base_name = 'default_value_' . $field['id']; | |
| 417 | + $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field ); | |
| 704 | 418 | |
| 419 | + $default_type = self::get_default_value_type( $field ); | |
| 420 | + | |
| 705 | 421 | foreach ( $field['options'] as $opt_key => $opt ) { |
| 706 | - $field_val = self::get_value_from_array( $opt, $opt_key, $field ); | |
| 707 | - $opt = self::get_label_from_array( $opt, $opt_key, $field ); | |
| 422 | + $field_val = self::get_value_from_array( $opt, $opt_key, $field ); | |
| 423 | + $opt = self::get_label_from_array( $opt, $opt_key, $field ); | |
| 424 | + | |
| 708 | 425 | $field_name = $base_name . ( $default_type === 'checkbox' ? '[' . $opt_key . ']' : '' ); |
| 709 | 426 | |
| 710 | - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict, Universal.Operators.StrictComparisons, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 711 | - $checked = isset( $field['default_value'] ) && ( is_array( $field['default_value'] ) ? in_array( $field_val, $field['default_value'] ) : $field['default_value'] == $field_val ); | |
| 427 | + $checked = ( isset( $field['default_value'] ) && ( ( ! is_array( $field['default_value'] ) && $field['default_value'] == $field_val ) || ( is_array( $field['default_value'] ) && in_array( $field_val, $field['default_value'] ) ) ) ); | |
| 712 | 428 | |
| 713 | 429 | // If this is an "Other" option, get the HTML for it. |
| 714 | 430 | if ( self::is_other_opt( $opt_key ) ) { |
| 715 | 431 | if ( FrmAppHelper::pro_is_installed() ) { |
| 716 | - require FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php'; | |
| 432 | + require( FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php' ); | |
| 717 | 433 | } |
| 718 | 434 | } else { |
| 719 | - require FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php'; | |
| 435 | + require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' ); | |
| 720 | 436 | } |
| 721 | 437 | |
| 722 | 438 | unset( $checked ); |
| 723 | 439 | } |
| @@ -726,31 +442,28 @@ | ||
| 726 | 442 | /** |
| 727 | 443 | * Include hidden row for javascript to duplicate. |
| 728 | 444 | * |
| 729 | 445 | * @since 4.0 |
| 730 | - * | |
| 731 | 446 | * @param array $field |
| 732 | - * | |
| 733 | - * @return void | |
| 734 | 447 | */ |
| 735 | 448 | private static function hidden_field_option( $field ) { |
| 736 | 449 | // Don't duplicate during an ajax add option. |
| 737 | 450 | $ajax_action = FrmAppHelper::get_param( 'action', '', 'post', 'sanitize_text_field' ); |
| 738 | - | |
| 739 | 451 | if ( $ajax_action === 'frm_add_field_option' ) { |
| 740 | 452 | return; |
| 741 | 453 | } |
| 742 | 454 | |
| 743 | - $opt_key = '000'; | |
| 744 | - $field_val = __( 'New Option', 'formidable' ); | |
| 745 | - $opt = __( 'New Option', 'formidable' ); | |
| 746 | - $checked = false; | |
| 747 | - $field_name = 'default_value_' . $field['id']; | |
| 748 | - $html_id = $field['html_id'] ?? self::get_html_id( $field ); | |
| 455 | + $opt_key = '000'; | |
| 456 | + $field_val = __( 'New Option', 'formidable' ); | |
| 457 | + $opt = __( 'New Option', 'formidable' ); | |
| 458 | + $checked = false; | |
| 459 | + $field_name = 'default_value_' . $field['id']; | |
| 460 | + $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field ); | |
| 461 | + | |
| 749 | 462 | $default_type = self::get_default_value_type( $field ); |
| 750 | - $field_name .= $default_type === 'checkbox' ? '[' . $opt_key . ']' : ''; | |
| 463 | + $field_name .= ( $default_type === 'checkbox' ? '[' . $opt_key . ']' : '' ); | |
| 751 | 464 | |
| 752 | - require FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php'; | |
| 465 | + require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' ); | |
| 753 | 466 | } |
| 754 | 467 | |
| 755 | 468 | /** |
| 756 | 469 | * @since 4.0 |
| @@ -755,103 +468,73 @@ | ||
| 755 | 468 | /** |
| 756 | 469 | * @since 4.0 |
| 757 | 470 | * |
| 758 | 471 | * @param array $field |
| 759 | - * | |
| 760 | 472 | * @return string radio or checkbox |
| 761 | 473 | */ |
| 762 | 474 | private static function get_default_value_type( $field ) { |
| 475 | + $default_type = $field['type']; | |
| 763 | 476 | if ( $field['type'] === 'select' ) { |
| 764 | - return FrmField::is_multiple_select( $field ) ? 'checkbox' : 'radio'; | |
| 477 | + $default_type = FrmField::is_multiple_select( $field ) ? 'checkbox' : 'radio'; | |
| 765 | 478 | } |
| 766 | - return $field['type']; | |
| 479 | + return $default_type; | |
| 767 | 480 | } |
| 768 | 481 | |
| 769 | - /** | |
| 770 | - * @param array|string $opt | |
| 771 | - * @param int|string $opt_key | |
| 772 | - * @param array $field | |
| 773 | - * | |
| 774 | - * @return mixed | |
| 775 | - */ | |
| 776 | 482 | public static function get_value_from_array( $opt, $opt_key, $field ) { |
| 777 | 483 | $opt = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field ); |
| 484 | + | |
| 778 | 485 | return FrmFieldsController::check_value( $opt, $opt_key, $field ); |
| 779 | 486 | } |
| 780 | 487 | |
| 781 | - /** | |
| 782 | - * @param array|string $opt | |
| 783 | - * @param int|string $opt_key | |
| 784 | - * @param array $field | |
| 785 | - * | |
| 786 | - * @return string | |
| 787 | - */ | |
| 788 | 488 | public static function get_label_from_array( $opt, $opt_key, $field ) { |
| 789 | 489 | $opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field ); |
| 490 | + | |
| 790 | 491 | return FrmFieldsController::check_label( $opt ); |
| 791 | 492 | } |
| 792 | 493 | |
| 793 | 494 | /** |
| 794 | - * Shows the inline modal. | |
| 795 | - * | |
| 796 | 495 | * @since 4.0 |
| 797 | - * @since 6.4.1 Added `inside_class` in the arguments. | |
| 798 | - * | |
| 799 | - * @param array $args The arguments. | |
| 800 | - * | |
| 801 | - * @return void | |
| 802 | 496 | */ |
| 803 | 497 | public static function inline_modal( $args ) { |
| 804 | 498 | $defaults = array( |
| 805 | - 'id' => '', | |
| 806 | - 'class' => '', | |
| 807 | - 'show' => 0, | |
| 808 | - 'callback' => array(), | |
| 809 | - 'args' => array(), | |
| 810 | - 'title' => '', | |
| 811 | - 'inside_class' => 'inside', | |
| 812 | - 'dismiss-icon' => true, | |
| 499 | + 'id' => '', | |
| 500 | + 'class' => '', | |
| 501 | + 'show' => 0, | |
| 502 | + 'callback' => array(), | |
| 503 | + 'args' => array(), | |
| 504 | + 'title' => '', | |
| 813 | 505 | ); |
| 814 | - $args = array_merge( $defaults, $args ); | |
| 506 | + $args = array_merge( $defaults, $args ); | |
| 815 | 507 | |
| 816 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/inline-modal.php'; | |
| 508 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/inline-modal.php' ); | |
| 817 | 509 | } |
| 818 | 510 | |
| 819 | 511 | /** |
| 820 | 512 | * @since 4.0 |
| 821 | - * | |
| 822 | - * @return void | |
| 823 | 513 | */ |
| 824 | 514 | public static function smart_values() { |
| 825 | 515 | $continue = apply_filters( 'frm_smart_values_box', true ); |
| 826 | - | |
| 827 | - if ( $continue !== true ) { | |
| 828 | - return; | |
| 516 | + if ( $continue === true ) { | |
| 517 | + $upgrade_link = array( | |
| 518 | + 'medium' => 'builder', | |
| 519 | + 'content' => 'smart-tags', | |
| 520 | + ); | |
| 521 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/smart-values.php' ); | |
| 829 | 522 | } |
| 830 | - | |
| 831 | - $upgrade_link = array( | |
| 832 | - 'medium' => 'builder', | |
| 833 | - 'content' => 'smart-tags', | |
| 834 | - ); | |
| 835 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/smart-values.php'; | |
| 836 | 523 | } |
| 837 | 524 | |
| 838 | 525 | /** |
| 839 | 526 | * @since 4.0 |
| 840 | - * | |
| 841 | - * @return void | |
| 842 | 527 | */ |
| 843 | 528 | public static function input_mask() { |
| 844 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/input-mask-info.php'; | |
| 529 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/input-mask-info.php' ); | |
| 845 | 530 | } |
| 846 | 531 | |
| 847 | 532 | /** |
| 848 | 533 | * @since 4.0 |
| 849 | - * | |
| 850 | - * @return void | |
| 851 | 534 | */ |
| 852 | 535 | public static function layout_classes() { |
| 853 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/layout-classes.php'; | |
| 536 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/layout-classes.php' ); | |
| 854 | 537 | } |
| 855 | 538 | |
| 856 | 539 | /** |
| 857 | 540 | * @param int $tax_id |
| @@ -859,33 +542,28 @@ | ||
| 859 | 542 | * @return string |
| 860 | 543 | */ |
| 861 | 544 | public static function get_term_link( $tax_id ) { |
| 862 | 545 | $tax = get_taxonomy( $tax_id ); |
| 863 | - | |
| 864 | 546 | if ( ! $tax ) { |
| 865 | 547 | return ''; |
| 866 | 548 | } |
| 867 | 549 | |
| 868 | - return sprintf( | |
| 550 | + $link = sprintf( | |
| 869 | 551 | /* translators: %1$s: Start HTML link, %2$s: Content type label, %3$s: Content type, %4$s: End HTML link */ |
| 870 | 552 | esc_html__( 'Options are dynamically created from your %1$s%2$s: %3$s%4$s', 'formidable' ), |
| 871 | 553 | '<a href="' . esc_url( admin_url( 'edit-tags.php?taxonomy=' . $tax->name ) ) . '" target="_blank">', |
| 872 | 554 | esc_html__( 'taxonomy', 'formidable' ), |
| 873 | - ! empty( $tax->labels->name ) ? $tax->labels->name : esc_html__( 'Categories', 'formidable' ), | |
| 555 | + empty( $tax->labels->name ) ? esc_html__( 'Categories', 'formidable' ) : $tax->labels->name, | |
| 874 | 556 | '</a>' |
| 875 | 557 | ); |
| 558 | + unset( $tax ); | |
| 559 | + | |
| 560 | + return $link; | |
| 876 | 561 | } |
| 877 | 562 | |
| 878 | - /** | |
| 879 | - * @param array|string $observed_value | |
| 880 | - * @param string $cond | |
| 881 | - * @param array|string $hide_opt | |
| 882 | - * | |
| 883 | - * @return bool | |
| 884 | - */ | |
| 885 | 563 | public static function value_meets_condition( $observed_value, $cond, $hide_opt ) { |
| 886 | - $hide_opt = self::get_value_for_comparison( $hide_opt ); | |
| 887 | - $observed_value = self::get_value_for_comparison( $observed_value ); | |
| 564 | + $hide_opt = self::get_value_for_comparision( $hide_opt ); | |
| 565 | + $observed_value = self::get_value_for_comparision( $observed_value ); | |
| 888 | 566 | |
| 889 | 567 | if ( is_array( $observed_value ) ) { |
| 890 | 568 | return self::array_value_condition( $observed_value, $cond, $hide_opt ); |
| 891 | 569 | } |
| @@ -890,13 +568,12 @@ | ||
| 890 | 568 | return self::array_value_condition( $observed_value, $cond, $hide_opt ); |
| 891 | 569 | } |
| 892 | 570 | |
| 893 | 571 | $m = false; |
| 894 | - | |
| 895 | 572 | if ( $cond === '==' ) { |
| 896 | - $m = $observed_value == $hide_opt; // phpcs:ignore Universal.Operators.StrictComparisons | |
| 573 | + $m = $observed_value == $hide_opt; | |
| 897 | 574 | } elseif ( $cond === '!=' ) { |
| 898 | - $m = $observed_value != $hide_opt; // phpcs:ignore Universal.Operators.StrictComparisons | |
| 575 | + $m = $observed_value != $hide_opt; | |
| 899 | 576 | } elseif ( $cond === '>' ) { |
| 900 | 577 | $m = $observed_value > $hide_opt; |
| 901 | 578 | } elseif ( $cond === '>=' ) { |
| 902 | 579 | $m = $observed_value >= $hide_opt; |
| @@ -905,20 +582,24 @@ | ||
| 905 | 582 | } elseif ( $cond === '<=' ) { |
| 906 | 583 | $m = $observed_value <= $hide_opt; |
| 907 | 584 | } elseif ( $cond === 'LIKE' || $cond === 'not LIKE' ) { |
| 908 | 585 | $m = stripos( $observed_value, $hide_opt ); |
| 909 | - $m = $cond === 'not LIKE' ? $m === false : $m !== false; | |
| 586 | + if ( $cond === 'not LIKE' ) { | |
| 587 | + $m = ( $m === false ) ? true : false; | |
| 588 | + } else { | |
| 589 | + $m = ( $m === false ) ? false : true; | |
| 590 | + } | |
| 910 | 591 | } elseif ( $cond === '%LIKE' ) { |
| 911 | - // Ends with | |
| 592 | + // ends with | |
| 912 | 593 | $length = strlen( $hide_opt ); |
| 913 | 594 | $substr = substr( $observed_value, strlen( $observed_value ) - $length ); |
| 914 | 595 | $m = 0 === strcasecmp( $substr, $hide_opt ); |
| 915 | 596 | } elseif ( 'LIKE%' === $cond ) { |
| 916 | - // Starts with | |
| 597 | + // starts with | |
| 917 | 598 | $length = strlen( $hide_opt ); |
| 918 | 599 | $substr = substr( $observed_value, 0, $length ); |
| 919 | 600 | $m = 0 === strcasecmp( $substr, $hide_opt ); |
| 920 | - }//end if | |
| 601 | + } | |
| 921 | 602 | |
| 922 | 603 | return $m; |
| 923 | 604 | } |
| 924 | 605 | |
| @@ -925,14 +606,10 @@ | ||
| 925 | 606 | /** |
| 926 | 607 | * Trim and sanitize the values |
| 927 | 608 | * |
| 928 | 609 | * @since 2.05 |
| 929 | - * | |
| 930 | - * @param array|string $value | |
| 931 | - * | |
| 932 | - * @return array|string | |
| 933 | 610 | */ |
| 934 | - private static function get_value_for_comparison( $value ) { | |
| 611 | + private static function get_value_for_comparision( $value ) { | |
| 935 | 612 | // Remove white space from hide_opt |
| 936 | 613 | if ( ! is_array( $value ) ) { |
| 937 | 614 | $value = trim( $value ); |
| 938 | 615 | } |
| @@ -941,37 +618,28 @@ | ||
| 941 | 618 | |
| 942 | 619 | return $value; |
| 943 | 620 | } |
| 944 | 621 | |
| 945 | - /** | |
| 946 | - * @param array $observed_value | |
| 947 | - * @param string $cond | |
| 948 | - * @param array|string $hide_opt | |
| 949 | - * | |
| 950 | - * @return bool | |
| 951 | - */ | |
| 952 | 622 | public static function array_value_condition( $observed_value, $cond, $hide_opt ) { |
| 953 | 623 | $m = false; |
| 954 | - | |
| 955 | 624 | if ( $cond === '==' ) { |
| 956 | 625 | if ( is_array( $hide_opt ) ) { |
| 957 | 626 | $m = array_intersect( $hide_opt, $observed_value ); |
| 958 | - $m = $m !== array(); | |
| 627 | + $m = empty( $m ) ? false : true; | |
| 959 | 628 | } else { |
| 960 | - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict | |
| 961 | 629 | $m = in_array( $hide_opt, $observed_value ); |
| 962 | 630 | } |
| 963 | 631 | } elseif ( $cond === '!=' ) { |
| 964 | - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict | |
| 965 | 632 | $m = ! in_array( $hide_opt, $observed_value ); |
| 966 | 633 | } elseif ( $cond === '>' ) { |
| 967 | - $m = min( $observed_value ) > $hide_opt; | |
| 634 | + $min = min( $observed_value ); | |
| 635 | + $m = $min > $hide_opt; | |
| 968 | 636 | } elseif ( $cond === '<' ) { |
| 969 | - $m = max( $observed_value ) < $hide_opt; | |
| 637 | + $max = max( $observed_value ); | |
| 638 | + $m = $max < $hide_opt; | |
| 970 | 639 | } elseif ( $cond === 'LIKE' || $cond === 'not LIKE' ) { |
| 971 | 640 | foreach ( $observed_value as $ob ) { |
| 972 | 641 | $m = strpos( $ob, $hide_opt ); |
| 973 | - | |
| 974 | 642 | if ( $m !== false ) { |
| 975 | 643 | $m = true; |
| 976 | 644 | break; |
| 977 | 645 | } |
| @@ -977,12 +645,12 @@ | ||
| 977 | 645 | } |
| 978 | 646 | } |
| 979 | 647 | |
| 980 | 648 | if ( $cond === 'not LIKE' ) { |
| 981 | - $m = $m === false; | |
| 649 | + $m = ( $m === false ) ? true : false; | |
| 982 | 650 | } |
| 983 | 651 | } elseif ( $cond === '%LIKE' ) { |
| 984 | - // Ends with | |
| 652 | + // ends with | |
| 985 | 653 | foreach ( $observed_value as $ob ) { |
| 986 | 654 | if ( $hide_opt === substr( $ob, strlen( $ob ) - strlen( $hide_opt ) ) ) { |
| 987 | 655 | $m = true; |
| 988 | 656 | break; |
| @@ -988,16 +656,16 @@ | ||
| 988 | 656 | break; |
| 989 | 657 | } |
| 990 | 658 | } |
| 991 | 659 | } elseif ( $cond === 'LIKE%' ) { |
| 992 | - // Starts with | |
| 660 | + // starts with | |
| 993 | 661 | foreach ( $observed_value as $ob ) { |
| 994 | - if ( str_starts_with( $ob, $hide_opt ) ) { | |
| 662 | + if ( $hide_opt === substr( $ob, 0, strlen( $hide_opt ) ) ) { | |
| 995 | 663 | $m = true; |
| 996 | 664 | break; |
| 997 | 665 | } |
| 998 | 666 | } |
| 999 | - }//end if | |
| 667 | + } | |
| 1000 | 668 | |
| 1001 | 669 | return $m; |
| 1002 | 670 | } |
| 1003 | 671 | |
| @@ -1004,32 +672,22 @@ | ||
| 1004 | 672 | /** |
| 1005 | 673 | * Replace a few basic shortcodes and field ids |
| 1006 | 674 | * |
| 1007 | 675 | * @since 2.0 |
| 1008 | - * | |
| 1009 | - * @param string $value | |
| 1010 | - * @param object $form | |
| 1011 | - * @param object $entry | |
| 1012 | - * | |
| 1013 | 676 | * @return string |
| 1014 | 677 | */ |
| 1015 | 678 | public static function basic_replace_shortcodes( $value, $form, $entry ) { |
| 1016 | - if ( str_contains( $value, '[sitename]' ) ) { | |
| 679 | + if ( strpos( $value, '[sitename]' ) !== false ) { | |
| 1017 | 680 | $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
| 1018 | 681 | $value = str_replace( '[sitename]', $new_value, $value ); |
| 1019 | 682 | } |
| 1020 | 683 | |
| 1021 | 684 | $value = apply_filters( 'frm_content', $value, $form, $entry ); |
| 685 | + $value = do_shortcode( $value ); | |
| 1022 | 686 | |
| 1023 | - return do_shortcode( $value ); | |
| 687 | + return $value; | |
| 1024 | 688 | } |
| 1025 | 689 | |
| 1026 | - /** | |
| 1027 | - * @param string $content | |
| 1028 | - * @param int|string $form_id | |
| 1029 | - * | |
| 1030 | - * @return array | |
| 1031 | - */ | |
| 1032 | 690 | public static function get_shortcodes( $content, $form_id ) { |
| 1033 | 691 | if ( FrmAppHelper::pro_is_installed() ) { |
| 1034 | 692 | return FrmProDisplaysHelper::get_shortcodes( $content, $form_id ); |
| 1035 | 693 | } |
| @@ -1047,13 +705,8 @@ | ||
| 1047 | 705 | |
| 1048 | 706 | return $matches; |
| 1049 | 707 | } |
| 1050 | 708 | |
| 1051 | - /** | |
| 1052 | - * @param array $fields | |
| 1053 | - * | |
| 1054 | - * @return string | |
| 1055 | - */ | |
| 1056 | 709 | public static function allowed_shortcodes( $fields = array() ) { |
| 1057 | 710 | $tagregexp = array( |
| 1058 | 711 | 'editlink', |
| 1059 | 712 | 'id', |
| @@ -1061,16 +714,13 @@ | ||
| 1061 | 714 | 'ip', |
| 1062 | 715 | 'siteurl', |
| 1063 | 716 | 'sitename', |
| 1064 | 717 | 'admin_email', |
| 1065 | - 'default-email', | |
| 1066 | - 'default-from-email', | |
| 1067 | 718 | 'post[-|_]id', |
| 1068 | 719 | 'created[-|_]at', |
| 1069 | 720 | 'updated[-|_]at', |
| 1070 | 721 | 'updated[-|_]by', |
| 1071 | 722 | 'parent[-|_]id', |
| 1072 | - 'form_name', | |
| 1073 | 723 | ); |
| 1074 | 724 | |
| 1075 | 725 | foreach ( $fields as $field ) { |
| 1076 | 726 | $tagregexp[] = $field->id; |
| @@ -1076,21 +726,16 @@ | ||
| 1076 | 726 | $tagregexp[] = $field->id; |
| 1077 | 727 | $tagregexp[] = $field->field_key; |
| 1078 | 728 | } |
| 1079 | 729 | |
| 1080 | - return implode( '|', $tagregexp ); | |
| 730 | + $tagregexp = implode( '|', $tagregexp ); | |
| 731 | + | |
| 732 | + return $tagregexp; | |
| 1081 | 733 | } |
| 1082 | 734 | |
| 1083 | - /** | |
| 1084 | - * @param string $content | |
| 1085 | - * @param false|object $entry | |
| 1086 | - * @param array $shortcodes | |
| 1087 | - * | |
| 1088 | - * @return string | |
| 1089 | - */ | |
| 1090 | 735 | public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
| 1091 | 736 | foreach ( $shortcodes[0] as $short_key => $tag ) { |
| 1092 | - if ( ! $tag ) { | |
| 737 | + if ( empty( $tag ) ) { | |
| 1093 | 738 | continue; |
| 1094 | 739 | } |
| 1095 | 740 | |
| 1096 | 741 | $atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[3][ $short_key ] ); |
| @@ -1114,44 +759,21 @@ | ||
| 1114 | 759 | |
| 1115 | 760 | /** |
| 1116 | 761 | * @param string $replace_with |
| 1117 | 762 | * @param array $atts |
| 1118 | - * | |
| 1119 | - * @return string | |
| 1120 | 763 | */ |
| 1121 | 764 | private static function trigger_shortcode_atts( $replace_with, $atts ) { |
| 1122 | - $supported_atts = array( 'remove_accents', 'sanitize', 'sanitize_url' ); | |
| 765 | + $supported_atts = array( 'sanitize', 'sanitize_url' ); | |
| 1123 | 766 | $included_atts = array_intersect( $supported_atts, array_keys( $atts ) ); |
| 1124 | - | |
| 1125 | 767 | foreach ( $included_atts as $included_att ) { |
| 1126 | - if ( '0' === $atts[ $included_att ] ) { | |
| 1127 | - // Skip any option that uses 0 so sanitize_url=0 does not encode. | |
| 1128 | - continue; | |
| 1129 | - } | |
| 1130 | - | |
| 1131 | 768 | $function = 'atts_' . $included_att; |
| 1132 | - $replace_with = self::$function( $replace_with ); | |
| 769 | + $replace_with = self::$function( $replace_with, $atts ); | |
| 1133 | 770 | } |
| 1134 | - | |
| 1135 | 771 | return $replace_with; |
| 1136 | 772 | } |
| 1137 | 773 | |
| 1138 | 774 | /** |
| 1139 | - * Converts all accent characters to ASCII characters. | |
| 1140 | - * | |
| 1141 | - * @since 6.3.1 | |
| 1142 | - * | |
| 1143 | - * @param string $replace_with The text to remove accents from. | |
| 1144 | - * | |
| 1145 | - * @return string | |
| 1146 | - */ | |
| 1147 | - public static function atts_remove_accents( $replace_with ) { | |
| 1148 | - return remove_accents( $replace_with ); | |
| 1149 | - } | |
| 1150 | - | |
| 1151 | - /** | |
| 1152 | 775 | * @param string $replace_with |
| 1153 | - * | |
| 1154 | 776 | * @return string |
| 1155 | 777 | */ |
| 1156 | 778 | private static function atts_sanitize( $replace_with ) { |
| 1157 | 779 | return sanitize_title_with_dashes( $replace_with ); |
| @@ -1158,9 +780,8 @@ | ||
| 1158 | 780 | } |
| 1159 | 781 | |
| 1160 | 782 | /** |
| 1161 | 783 | * @param string $replace_with |
| 1162 | - * | |
| 1163 | 784 | * @return string |
| 1164 | 785 | */ |
| 1165 | 786 | private static function atts_sanitize_url( $replace_with ) { |
| 1166 | 787 | return urlencode( $replace_with ); |
| @@ -1170,21 +791,14 @@ | ||
| 1170 | 791 | * Prevent shortcodes in fields from being processed |
| 1171 | 792 | * |
| 1172 | 793 | * @since 3.01.02 |
| 1173 | 794 | * |
| 1174 | - * @param array $atts Includes entry object. | |
| 1175 | - * @param string|null $value | |
| 1176 | - * | |
| 1177 | - * @return void | |
| 795 | + * @param array $atts - includes entry object | |
| 796 | + * @param string $value | |
| 1178 | 797 | */ |
| 1179 | 798 | public static function sanitize_embedded_shortcodes( $atts, &$value ) { |
| 1180 | - if ( is_null( $value ) ) { | |
| 1181 | - return; | |
| 1182 | - } | |
| 1183 | - | |
| 1184 | 799 | $atts['value'] = $value; |
| 1185 | 800 | $should_sanitize = apply_filters( 'frm_sanitize_shortcodes', true, $atts ); |
| 1186 | - | |
| 1187 | 801 | if ( $should_sanitize ) { |
| 1188 | 802 | $value = str_replace( '[', '[', $value ); |
| 1189 | 803 | } |
| 1190 | 804 | } |
| @@ -1191,9 +805,9 @@ | ||
| 1191 | 805 | |
| 1192 | 806 | /** |
| 1193 | 807 | * @since 3.0 |
| 1194 | 808 | * |
| 1195 | - * @param array $atts | |
| 809 | + * @param $atts | |
| 1196 | 810 | * |
| 1197 | 811 | * @return string |
| 1198 | 812 | */ |
| 1199 | 813 | private static function get_value_for_shortcode( $atts ) { |
| @@ -1204,21 +818,21 @@ | ||
| 1204 | 818 | 'key' => $atts['entry']->item_key, |
| 1205 | 819 | 'ip' => $atts['entry']->ip, |
| 1206 | 820 | ); |
| 1207 | 821 | |
| 1208 | - $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get', 'default-email', 'default-from-email' ); | |
| 822 | + $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get' ); | |
| 1209 | 823 | |
| 1210 | 824 | if ( isset( $shortcode_values[ $atts['tag'] ] ) ) { |
| 1211 | 825 | $replace_with = $shortcode_values[ $atts['tag'] ]; |
| 1212 | - } elseif ( in_array( $atts['tag'], $dynamic_default, true ) ) { | |
| 826 | + } elseif ( in_array( $atts['tag'], $dynamic_default ) ) { | |
| 1213 | 827 | $replace_with = self::dynamic_default_values( $atts['tag'], $atts ); |
| 1214 | - } elseif ( $clean_tag === 'user_agent' ) { | |
| 828 | + } elseif ( $clean_tag == 'user_agent' ) { | |
| 1215 | 829 | $description = $atts['entry']->description; |
| 1216 | 830 | $replace_with = FrmEntriesHelper::get_browser( $description['browser'] ); |
| 1217 | - } elseif ( $clean_tag === 'created_at' || $clean_tag === 'updated_at' ) { | |
| 831 | + } elseif ( $clean_tag == 'created_at' || $clean_tag == 'updated_at' ) { | |
| 1218 | 832 | $atts['tag'] = $clean_tag; |
| 1219 | 833 | $replace_with = self::get_entry_timestamp( $atts ); |
| 1220 | - } elseif ( $clean_tag === 'created_by' || $clean_tag === 'updated_by' ) { | |
| 834 | + } elseif ( $clean_tag == 'created_by' || $clean_tag == 'updated_by' ) { | |
| 1221 | 835 | $replace_with = self::get_display_value( $atts['entry']->{$clean_tag}, (object) array( 'type' => 'user_id' ), $atts ); |
| 1222 | 836 | } else { |
| 1223 | 837 | $replace_with = self::get_field_shortcode_value( $atts ); |
| 1224 | 838 | } |
| @@ -1228,9 +842,9 @@ | ||
| 1228 | 842 | |
| 1229 | 843 | /** |
| 1230 | 844 | * @since 3.0 |
| 1231 | 845 | * |
| 1232 | - * @param array $atts | |
| 846 | + * @param $atts | |
| 1233 | 847 | * |
| 1234 | 848 | * @return string |
| 1235 | 849 | */ |
| 1236 | 850 | private static function get_entry_timestamp( $atts ) { |
| @@ -1246,16 +860,15 @@ | ||
| 1246 | 860 | |
| 1247 | 861 | /** |
| 1248 | 862 | * @since 3.0 |
| 1249 | 863 | * |
| 1250 | - * @param array $atts | |
| 864 | + * @param $atts | |
| 1251 | 865 | * |
| 1252 | - * @return string|null | |
| 866 | + * @return null|string | |
| 1253 | 867 | */ |
| 1254 | 868 | private static function get_field_shortcode_value( $atts ) { |
| 1255 | 869 | $field = FrmField::getOne( $atts['tag'] ); |
| 1256 | - | |
| 1257 | - if ( ! $field ) { | |
| 870 | + if ( empty( $field ) ) { | |
| 1258 | 871 | return null; |
| 1259 | 872 | } |
| 1260 | 873 | |
| 1261 | 874 | if ( isset( $atts['show'] ) && $atts['show'] === 'field_label' ) { |
| @@ -1264,16 +877,14 @@ | ||
| 1264 | 877 | $replace_with = $field->description; |
| 1265 | 878 | } else { |
| 1266 | 879 | $replace_with = FrmEntryMeta::get_meta_value( $atts['entry'], $field->id ); |
| 1267 | 880 | $string_value = $replace_with; |
| 1268 | - | |
| 1269 | 881 | if ( is_array( $replace_with ) ) { |
| 1270 | - $sep = $atts['sep'] ?? ', '; | |
| 1271 | - $string_value = FrmAppHelper::safe_implode( $sep, $replace_with ); | |
| 882 | + $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', '; | |
| 883 | + $string_value = implode( $sep, $replace_with ); | |
| 1272 | 884 | } |
| 1273 | 885 | |
| 1274 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 1275 | - if ( ! $string_value && $string_value != '0' ) { | |
| 886 | + if ( empty( $string_value ) && $string_value != '0' ) { | |
| 1276 | 887 | $replace_with = ''; |
| 1277 | 888 | } else { |
| 1278 | 889 | $atts['entry_id'] = $atts['entry']->id; |
| 1279 | 890 | $atts['entry_key'] = $atts['entry']->item_key; |
| @@ -1278,9 +889,9 @@ | ||
| 1278 | 889 | $atts['entry_id'] = $atts['entry']->id; |
| 1279 | 890 | $atts['entry_key'] = $atts['entry']->item_key; |
| 1280 | 891 | $replace_with = self::get_display_value( $replace_with, $field, $atts ); |
| 1281 | 892 | } |
| 1282 | - }//end if | |
| 893 | + } | |
| 1283 | 894 | |
| 1284 | 895 | return $replace_with; |
| 1285 | 896 | } |
| 1286 | 897 | |
| @@ -1287,13 +898,8 @@ | ||
| 1287 | 898 | /** |
| 1288 | 899 | * Get the value to replace a few standard shortcodes |
| 1289 | 900 | * |
| 1290 | 901 | * @since 2.0 |
| 1291 | - * | |
| 1292 | - * @param string $tag | |
| 1293 | - * @param array $atts | |
| 1294 | - * @param bool $return_array | |
| 1295 | - * | |
| 1296 | 902 | * @return string |
| 1297 | 903 | */ |
| 1298 | 904 | public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) { |
| 1299 | 905 | $new_value = ''; |
| @@ -1300,16 +906,8 @@ | ||
| 1300 | 906 | switch ( $tag ) { |
| 1301 | 907 | case 'admin_email': |
| 1302 | 908 | $new_value = get_option( 'admin_email' ); |
| 1303 | 909 | break; |
| 1304 | - case 'default-email': | |
| 1305 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 1306 | - $new_value = ! empty( $frm_settings->default_email ) && is_email( $frm_settings->default_email ) ? $frm_settings->default_email : get_option( 'admin_email' ); | |
| 1307 | - break; | |
| 1308 | - case 'default-from-email': | |
| 1309 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 1310 | - $new_value = ! empty( $frm_settings->from_email ) && is_email( $frm_settings->from_email ) ? $frm_settings->from_email : get_option( 'admin_email' ); | |
| 1311 | - break; | |
| 1312 | 910 | case 'siteurl': |
| 1313 | 911 | $new_value = FrmAppHelper::site_url(); |
| 1314 | 912 | break; |
| 1315 | 913 | case 'frmurl': |
| @@ -1319,9 +917,9 @@ | ||
| 1319 | 917 | $new_value = FrmAppHelper::site_name(); |
| 1320 | 918 | break; |
| 1321 | 919 | case 'get': |
| 1322 | 920 | $new_value = self::process_get_shortcode( $atts, $return_array ); |
| 1323 | - }//end switch | |
| 921 | + } | |
| 1324 | 922 | |
| 1325 | 923 | return $new_value; |
| 1326 | 924 | } |
| 1327 | 925 | |
| @@ -1328,13 +926,9 @@ | ||
| 1328 | 926 | /** |
| 1329 | 927 | * Process the [get] shortcode |
| 1330 | 928 | * |
| 1331 | 929 | * @since 2.0 |
| 1332 | - * | |
| 1333 | - * @param array $atts | |
| 1334 | - * @param bool $return_array | |
| 1335 | - * | |
| 1336 | - * @return array|string | |
| 930 | + * @return string|array | |
| 1337 | 931 | */ |
| 1338 | 932 | public static function process_get_shortcode( $atts, $return_array = false ) { |
| 1339 | 933 | if ( ! isset( $atts['param'] ) ) { |
| 1340 | 934 | return ''; |
| @@ -1339,9 +933,9 @@ | ||
| 1339 | 933 | if ( ! isset( $atts['param'] ) ) { |
| 1340 | 934 | return ''; |
| 1341 | 935 | } |
| 1342 | 936 | |
| 1343 | - if ( str_contains( $atts['param'], '[' ) ) { | |
| 937 | + if ( strpos( $atts['param'], '[' ) ) { | |
| 1344 | 938 | $atts['param'] = str_replace( '[', '[', $atts['param'] ); |
| 1345 | 939 | $atts['param'] = str_replace( ']', ']', $atts['param'] ); |
| 1346 | 940 | } |
| 1347 | 941 | |
| @@ -1347,34 +941,28 @@ | ||
| 1347 | 941 | |
| 1348 | 942 | $new_value = FrmAppHelper::get_param( $atts['param'], '', 'get', 'sanitize_text_field' ); |
| 1349 | 943 | $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] ); |
| 1350 | 944 | |
| 1351 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 1352 | 945 | if ( $new_value == '' ) { |
| 1353 | 946 | if ( ! isset( $atts['prev_val'] ) ) { |
| 1354 | 947 | $atts['prev_val'] = ''; |
| 1355 | 948 | } |
| 1356 | 949 | |
| 1357 | - $new_value = $atts['default'] ?? $atts['prev_val']; | |
| 950 | + $new_value = isset( $atts['default'] ) ? $atts['default'] : $atts['prev_val']; | |
| 1358 | 951 | } |
| 1359 | 952 | |
| 1360 | 953 | if ( is_array( $new_value ) && ! $return_array ) { |
| 1361 | - return implode( ', ', $new_value ); | |
| 954 | + $new_value = implode( ', ', $new_value ); | |
| 1362 | 955 | } |
| 1363 | 956 | |
| 1364 | 957 | return $new_value; |
| 1365 | 958 | } |
| 1366 | 959 | |
| 1367 | - /** | |
| 1368 | - * @param mixed $value | |
| 1369 | - * @param object $field | |
| 1370 | - * @param array $atts | |
| 1371 | - * | |
| 1372 | - * @return mixed | |
| 1373 | - */ | |
| 1374 | 960 | public static function get_display_value( $value, $field, $atts = array() ) { |
| 961 | + | |
| 1375 | 962 | $value = apply_filters( 'frm_get_' . $field->type . '_display_value', $value, $field, $atts ); |
| 1376 | 963 | $value = apply_filters( 'frm_get_display_value', $value, $field, $atts ); |
| 964 | + | |
| 1377 | 965 | $value = self::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) ); |
| 1378 | 966 | |
| 1379 | 967 | return apply_filters( 'frm_display_value', $value, $field, $atts ); |
| 1380 | 968 | } |
| @@ -1379,16 +967,14 @@ | ||
| 1379 | 967 | return apply_filters( 'frm_display_value', $value, $field, $atts ); |
| 1380 | 968 | } |
| 1381 | 969 | |
| 1382 | 970 | /** |
| 1383 | - * @param array $atts Includes value, field, and atts. | |
| 1384 | - * | |
| 1385 | - * @return mixed | |
| 971 | + * @param $atts array Includes value, field, and atts | |
| 1386 | 972 | */ |
| 1387 | 973 | public static function get_unfiltered_display_value( $atts ) { |
| 1388 | 974 | $value = $atts['value']; |
| 1389 | 975 | $field = $atts['field']; |
| 1390 | - $atts = $atts['atts'] ?? $atts; | |
| 976 | + $atts = isset( $atts['atts'] ) ? $atts['atts'] : $atts; | |
| 1391 | 977 | |
| 1392 | 978 | if ( is_array( $field ) ) { |
| 1393 | 979 | $field = $field['id']; |
| 1394 | 980 | } |
| @@ -1401,14 +987,8 @@ | ||
| 1401 | 987 | /** |
| 1402 | 988 | * Get a value from the user profile from the user ID |
| 1403 | 989 | * |
| 1404 | 990 | * @since 3.0 |
| 1405 | - * | |
| 1406 | - * @param int|string $user_id | |
| 1407 | - * @param string $user_info | |
| 1408 | - * @param array $args | |
| 1409 | - * | |
| 1410 | - * @return string | |
| 1411 | 991 | */ |
| 1412 | 992 | public static function get_user_display_name( $user_id, $user_info = 'display_name', $args = array() ) { |
| 1413 | 993 | $defaults = array( |
| 1414 | 994 | 'blank' => false, |
| @@ -1416,52 +996,51 @@ | ||
| 1416 | 996 | 'size' => 96, |
| 1417 | 997 | ); |
| 1418 | 998 | |
| 1419 | 999 | $args = wp_parse_args( $args, $defaults ); |
| 1000 | + | |
| 1420 | 1001 | $user = get_userdata( $user_id ); |
| 1421 | 1002 | $info = ''; |
| 1422 | 1003 | |
| 1423 | 1004 | if ( $user ) { |
| 1424 | - if ( $user_info === 'avatar' ) { | |
| 1005 | + if ( $user_info == 'avatar' ) { | |
| 1425 | 1006 | $info = get_avatar( $user_id, $args['size'] ); |
| 1426 | - } elseif ( $user_info === 'author_link' ) { | |
| 1007 | + } elseif ( $user_info == 'author_link' ) { | |
| 1427 | 1008 | $info = get_author_posts_url( $user_id ); |
| 1428 | 1009 | } else { |
| 1429 | - $info = $user->$user_info ?? ''; | |
| 1010 | + $info = isset( $user->$user_info ) ? $user->$user_info : ''; | |
| 1430 | 1011 | } |
| 1431 | 1012 | |
| 1432 | - if ( 'display_name' === $user_info && ! $info && ! $args['blank'] ) { | |
| 1013 | + if ( 'display_name' === $user_info && empty( $info ) && ! $args['blank'] ) { | |
| 1433 | 1014 | $info = $user->user_login; |
| 1434 | 1015 | } |
| 1435 | 1016 | } |
| 1436 | 1017 | |
| 1437 | 1018 | if ( $args['link'] ) { |
| 1438 | - return '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_id ) ) . '">' . $info . '</a>'; | |
| 1019 | + $info = '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_id ) ) . '">' . $info . '</a>'; | |
| 1439 | 1020 | } |
| 1440 | 1021 | |
| 1441 | 1022 | return $info; |
| 1442 | 1023 | } |
| 1443 | 1024 | |
| 1444 | - /** | |
| 1445 | - * @param string $type | |
| 1446 | - * | |
| 1447 | - * @return array | |
| 1448 | - */ | |
| 1449 | 1025 | public static function get_field_types( $type ) { |
| 1450 | - $single_input = self::single_input_fields(); | |
| 1451 | - $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' ); | |
| 1026 | + $single_input = self::single_input_fields(); | |
| 1027 | + $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' ); | |
| 1028 | + | |
| 1452 | 1029 | $field_selection = FrmField::all_field_selection(); |
| 1453 | - $field_types = array(); | |
| 1454 | 1030 | |
| 1455 | - if ( in_array( $type, $single_input, true ) ) { | |
| 1031 | + $field_types = array(); | |
| 1032 | + if ( in_array( $type, $single_input ) ) { | |
| 1456 | 1033 | self::field_types_for_input( $single_input, $field_selection, $field_types ); |
| 1457 | - } elseif ( in_array( $type, $multiple_input, true ) ) { | |
| 1034 | + } elseif ( in_array( $type, $multiple_input ) ) { | |
| 1458 | 1035 | self::field_types_for_input( $multiple_input, $field_selection, $field_types ); |
| 1459 | 1036 | } elseif ( isset( $field_selection[ $type ] ) ) { |
| 1460 | 1037 | $field_types[ $type ] = $field_selection[ $type ]; |
| 1461 | 1038 | } |
| 1462 | 1039 | |
| 1463 | - return apply_filters( 'frm_switch_field_types', $field_types, compact( 'type', 'field_selection' ) ); | |
| 1040 | + $field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type', 'field_selection' ) ); | |
| 1041 | + | |
| 1042 | + return $field_types; | |
| 1464 | 1043 | } |
| 1465 | 1044 | |
| 1466 | 1045 | /** |
| 1467 | 1046 | * Get a list of all fields that use a single value input. |
| @@ -1466,10 +1045,8 @@ | ||
| 1466 | 1045 | /** |
| 1467 | 1046 | * Get a list of all fields that use a single value input. |
| 1468 | 1047 | * |
| 1469 | 1048 | * @since 4.0 |
| 1470 | - * | |
| 1471 | - * @return array | |
| 1472 | 1049 | */ |
| 1473 | 1050 | public static function single_input_fields() { |
| 1474 | 1051 | $fields = array( |
| 1475 | 1052 | 'text', |
| @@ -1483,26 +1060,15 @@ | ||
| 1483 | 1060 | 'hidden', |
| 1484 | 1061 | 'time', |
| 1485 | 1062 | 'tag', |
| 1486 | 1063 | 'password', |
| 1487 | - 'gdpr', | |
| 1488 | 1064 | ); |
| 1489 | 1065 | return apply_filters( 'frm_single_input_fields', $fields ); |
| 1490 | 1066 | } |
| 1491 | 1067 | |
| 1492 | - /** | |
| 1493 | - * @param string[] $inputs | |
| 1494 | - * @param array $fields | |
| 1495 | - * @param array $field_types | |
| 1496 | - * | |
| 1497 | - * @return void | |
| 1498 | - */ | |
| 1499 | 1068 | private static function field_types_for_input( $inputs, $fields, &$field_types ) { |
| 1500 | 1069 | foreach ( $inputs as $input ) { |
| 1501 | - // This may not be set if a field type was removed using the frm_available_fields or frm_pro_available_fields filters. | |
| 1502 | - if ( array_key_exists( $input, $fields ) ) { | |
| 1503 | - $field_types[ $input ] = $fields[ $input ]; | |
| 1504 | - } | |
| 1070 | + $field_types[ $input ] = $fields[ $input ]; | |
| 1505 | 1071 | unset( $input ); |
| 1506 | 1072 | } |
| 1507 | 1073 | } |
| 1508 | 1074 | |
| @@ -1512,12 +1078,12 @@ | ||
| 1512 | 1078 | * @since 2.0.6 |
| 1513 | 1079 | * |
| 1514 | 1080 | * @param string $opt_key |
| 1515 | 1081 | * |
| 1516 | - * @return bool Returns true if current field option is an "Other" option | |
| 1082 | + * @return boolean Returns true if current field option is an "Other" option | |
| 1517 | 1083 | */ |
| 1518 | 1084 | public static function is_other_opt( $opt_key ) { |
| 1519 | - return $opt_key && str_starts_with( $opt_key, 'other_' ); | |
| 1085 | + return $opt_key && strpos( $opt_key, 'other_' ) === 0; | |
| 1520 | 1086 | } |
| 1521 | 1087 | |
| 1522 | 1088 | /** |
| 1523 | 1089 | * Get value that belongs in "Other" text box |
| @@ -1524,19 +1090,18 @@ | ||
| 1524 | 1090 | * |
| 1525 | 1091 | * @since 2.0.6 |
| 1526 | 1092 | * |
| 1527 | 1093 | * @param array $args |
| 1528 | - * | |
| 1529 | - * @return string | |
| 1530 | 1094 | */ |
| 1531 | - public static function get_other_val( $args ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh | |
| 1532 | - $defaults = array( | |
| 1095 | + public static function get_other_val( $args ) { | |
| 1096 | + $defaults = array( | |
| 1533 | 1097 | 'opt_key' => 0, |
| 1534 | 1098 | 'field' => array(), |
| 1535 | 1099 | 'parent' => false, |
| 1536 | 1100 | 'pointer' => false, |
| 1537 | 1101 | ); |
| 1538 | - $args = wp_parse_args( $args, $defaults ); | |
| 1102 | + $args = wp_parse_args( $args, $defaults ); | |
| 1103 | + | |
| 1539 | 1104 | $opt_key = $args['opt_key']; |
| 1540 | 1105 | $field = $args['field']; |
| 1541 | 1106 | $parent = $args['parent']; |
| 1542 | 1107 | $pointer = $args['pointer']; |
| @@ -1542,9 +1107,9 @@ | ||
| 1542 | 1107 | $pointer = $args['pointer']; |
| 1543 | 1108 | $other_val = ''; |
| 1544 | 1109 | |
| 1545 | 1110 | // If option is an "other" option and there is a value set for this field, |
| 1546 | - // Check if the value belongs in the current "Other" option text field | |
| 1111 | + // check if the value belongs in the current "Other" option text field | |
| 1547 | 1112 | if ( ! self::is_other_opt( $opt_key ) || ! FrmField::is_option_true( $field, 'value' ) ) { |
| 1548 | 1113 | return $other_val; |
| 1549 | 1114 | } |
| 1550 | 1115 | |
| @@ -1551,22 +1116,21 @@ | ||
| 1551 | 1116 | // Check posted vals before checking saved values |
| 1552 | 1117 | // For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero |
| 1553 | 1118 | if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 1554 | 1119 | if ( FrmField::is_field_with_multiple_values( $field ) ) { |
| 1555 | - $other_val = isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 1120 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 1121 | + $other_val = isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) ) : ''; | |
| 1556 | 1122 | } else { |
| 1557 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 1558 | - $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ); | |
| 1123 | + $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 1559 | 1124 | } |
| 1560 | 1125 | |
| 1561 | 1126 | return $other_val; |
| 1562 | - } | |
| 1563 | 1127 | |
| 1564 | - if ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 1128 | + } elseif ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 1565 | 1129 | // For normal fields |
| 1566 | 1130 | |
| 1567 | 1131 | if ( FrmField::is_field_with_multiple_values( $field ) ) { |
| 1568 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 1132 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 1569 | 1133 | $other_val = isset( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ) : ''; |
| 1570 | 1134 | } else { |
| 1571 | 1135 | $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 1572 | 1136 | } |
| @@ -1571,15 +1135,14 @@ | ||
| 1571 | 1135 | $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 1572 | 1136 | } |
| 1573 | 1137 | |
| 1574 | 1138 | return $other_val; |
| 1575 | - }//end if | |
| 1139 | + } | |
| 1576 | 1140 | |
| 1577 | 1141 | // For checkboxes |
| 1578 | 1142 | if ( $field['type'] === 'checkbox' && is_array( $field['value'] ) ) { |
| 1579 | 1143 | // Check if there is an "other" val in saved value and make sure the |
| 1580 | 1144 | // "other" val is not equal to the Other checkbox option |
| 1581 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 1582 | 1145 | if ( isset( $field['value'][ $opt_key ] ) && $field['options'][ $opt_key ] != $field['value'][ $opt_key ] ) { |
| 1583 | 1146 | $other_val = $field['value'][ $opt_key ]; |
| 1584 | 1147 | } |
| 1585 | 1148 | } else { |
| @@ -1586,33 +1149,29 @@ | ||
| 1586 | 1149 | /** |
| 1587 | 1150 | * For radio buttons and dropdowns |
| 1588 | 1151 | * Check if saved value equals any of the options. If not, set it as the other value. |
| 1589 | 1152 | */ |
| 1590 | - foreach ( $field['options'] as $opt_val ) { | |
| 1153 | + foreach ( $field['options'] as $opt_key => $opt_val ) { | |
| 1591 | 1154 | $temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val; |
| 1592 | - | |
| 1593 | 1155 | // Multi-select dropdowns - key is not preserved |
| 1594 | 1156 | if ( is_array( $field['value'] ) ) { |
| 1595 | - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict | |
| 1596 | 1157 | $o_key = array_search( $temp_val, $field['value'] ); |
| 1597 | - | |
| 1598 | 1158 | if ( isset( $field['value'][ $o_key ] ) ) { |
| 1599 | 1159 | unset( $field['value'][ $o_key ], $o_key ); |
| 1600 | 1160 | } |
| 1601 | - } elseif ( $temp_val == $field['value'] ) { // phpcs:ignore Universal.Operators.StrictComparisons | |
| 1161 | + } elseif ( $temp_val == $field['value'] ) { | |
| 1602 | 1162 | // For radio and regular dropdowns |
| 1603 | 1163 | return ''; |
| 1604 | 1164 | } else { |
| 1605 | 1165 | $other_val = $field['value']; |
| 1606 | 1166 | } |
| 1607 | - unset( $opt_val, $temp_val ); | |
| 1167 | + unset( $opt_key, $opt_val, $temp_val ); | |
| 1608 | 1168 | } |
| 1609 | - | |
| 1610 | 1169 | // For multi-select dropdowns only |
| 1611 | - if ( is_array( $field['value'] ) && $field['value'] ) { | |
| 1170 | + if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) { | |
| 1612 | 1171 | $other_val = reset( $field['value'] ); |
| 1613 | 1172 | } |
| 1614 | - }//end if | |
| 1173 | + } | |
| 1615 | 1174 | |
| 1616 | 1175 | return $other_val; |
| 1617 | 1176 | } |
| 1618 | 1177 | |
| @@ -1621,13 +1180,13 @@ | ||
| 1621 | 1180 | * Intended for front-end use |
| 1622 | 1181 | * |
| 1623 | 1182 | * @since 2.0.6 |
| 1624 | 1183 | * |
| 1625 | - * @param array $args Should include field, opt_key and field name. | |
| 1626 | - * @param bool $other_opt | |
| 1184 | + * @param array $args should include field, opt_key and field name | |
| 1185 | + * @param boolean $other_opt | |
| 1627 | 1186 | * @param string $checked |
| 1628 | 1187 | * |
| 1629 | - * @return array Other args. | |
| 1188 | + * @return array $other_args | |
| 1630 | 1189 | */ |
| 1631 | 1190 | public static function prepare_other_input( $args, &$other_opt, &$checked ) { |
| 1632 | 1191 | $other_args = array( |
| 1633 | 1192 | 'name' => '', |
| @@ -1633,14 +1192,14 @@ | ||
| 1633 | 1192 | 'name' => '', |
| 1634 | 1193 | 'value' => '', |
| 1635 | 1194 | ); |
| 1636 | 1195 | |
| 1637 | - // Check if this is an "Other" option. | |
| 1196 | + //Check if this is an "Other" option | |
| 1638 | 1197 | if ( ! self::is_other_opt( $args['opt_key'] ) ) { |
| 1639 | 1198 | return $other_args; |
| 1640 | 1199 | } |
| 1641 | 1200 | |
| 1642 | - $other_opt = true; | |
| 1201 | + $other_opt = true; | |
| 1643 | 1202 | |
| 1644 | 1203 | self::set_other_name( $args, $other_args ); |
| 1645 | 1204 | self::set_other_value( $args, $other_args ); |
| 1646 | 1205 | |
| @@ -1647,37 +1206,25 @@ | ||
| 1647 | 1206 | if ( '' !== $other_args['value'] ) { |
| 1648 | 1207 | $checked = 'checked="checked" '; |
| 1649 | 1208 | } |
| 1650 | 1209 | |
| 1651 | - // If 'other' is selected as one of the default values for a checkbox field, 'checked' attribute should be on. | |
| 1652 | - if ( ! $checked && | |
| 1653 | - $args['field']['type'] === 'checkbox' && | |
| 1654 | - is_array( $args['field']['value'] ) && | |
| 1655 | - isset( $args['field_val'] ) && | |
| 1656 | - in_array( $args['field_val'], $args['field']['value'], true ) | |
| 1657 | - ) { | |
| 1658 | - $checked = 'checked="checked" '; | |
| 1659 | - } | |
| 1660 | - | |
| 1661 | 1210 | return $other_args; |
| 1662 | 1211 | } |
| 1663 | 1212 | |
| 1664 | 1213 | /** |
| 1665 | - * @since 2.0.6 | |
| 1666 | - * | |
| 1667 | 1214 | * @param array $args |
| 1668 | 1215 | * @param array $other_args |
| 1669 | 1216 | * |
| 1670 | - * @return void | |
| 1217 | + * @since 2.0.6 | |
| 1671 | 1218 | */ |
| 1672 | 1219 | private static function set_other_name( $args, &$other_args ) { |
| 1673 | - // Set up name for other field | |
| 1220 | + //Set up name for other field | |
| 1674 | 1221 | $other_args['name'] = str_replace( '[]', '', $args['field_name'] ); |
| 1675 | 1222 | $other_args['name'] = preg_replace( '/\[' . $args['field']['id'] . '\]$/', '', $other_args['name'] ); |
| 1676 | 1223 | $other_args['name'] = $other_args['name'] . '[other][' . $args['field']['id'] . ']'; |
| 1677 | 1224 | |
| 1678 | - // Converts item_meta[field_id] => item_meta[other][field_id] and | |
| 1679 | - // item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id] | |
| 1225 | + //Converts item_meta[field_id] => item_meta[other][field_id] and | |
| 1226 | + //item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id] | |
| 1680 | 1227 | if ( FrmField::is_field_with_multiple_values( $args['field'] ) ) { |
| 1681 | 1228 | $other_args['name'] .= '[' . $args['opt_key'] . ']'; |
| 1682 | 1229 | } |
| 1683 | 1230 | } |
| @@ -1684,14 +1231,12 @@ | ||
| 1684 | 1231 | |
| 1685 | 1232 | /** |
| 1686 | 1233 | * Find the parent and pointer, and get text for "other" text field |
| 1687 | 1234 | * |
| 1688 | - * @since 2.0.6 | |
| 1689 | - * | |
| 1690 | 1235 | * @param array $args |
| 1691 | 1236 | * @param array $other_args |
| 1692 | 1237 | * |
| 1693 | - * @return void | |
| 1238 | + * @since 2.0.6 | |
| 1694 | 1239 | */ |
| 1695 | 1240 | private static function set_other_value( $args, &$other_args ) { |
| 1696 | 1241 | $parent = ''; |
| 1697 | 1242 | $pointer = ''; |
| @@ -1718,13 +1263,11 @@ | ||
| 1718 | 1263 | |
| 1719 | 1264 | /** |
| 1720 | 1265 | * If this field includes an other option, show it |
| 1721 | 1266 | * |
| 1267 | + * @param $args array | |
| 1268 | + * | |
| 1722 | 1269 | * @since 2.0.6 |
| 1723 | - * | |
| 1724 | - * @param array $args | |
| 1725 | - * | |
| 1726 | - * @return void | |
| 1727 | 1270 | */ |
| 1728 | 1271 | public static function include_other_input( $args ) { |
| 1729 | 1272 | if ( ! $args['other_opt'] ) { |
| 1730 | 1273 | return; |
| @@ -1730,15 +1273,13 @@ | ||
| 1730 | 1273 | return; |
| 1731 | 1274 | } |
| 1732 | 1275 | |
| 1733 | 1276 | $classes = array( 'frm_other_input' ); |
| 1734 | - | |
| 1735 | - if ( ! $args['checked'] || trim( $args['checked'] ) === '' ) { | |
| 1736 | - // Hide the field if the other option is not selected | |
| 1277 | + if ( ! $args['checked'] || trim( $args['checked'] ) == '' ) { | |
| 1278 | + // hide the field if the other option is not selected | |
| 1737 | 1279 | $classes[] = 'frm_pos_none'; |
| 1738 | 1280 | } |
| 1739 | - | |
| 1740 | - if ( $args['field']['type'] === 'select' && ! empty( $args['field']['multiple'] ) ) { | |
| 1281 | + if ( $args['field']['type'] == 'select' && $args['field']['multiple'] ) { | |
| 1741 | 1282 | $classes[] = 'frm_other_full'; |
| 1742 | 1283 | } |
| 1743 | 1284 | |
| 1744 | 1285 | // Set up HTML ID for Other field |
| @@ -1743,11 +1284,10 @@ | ||
| 1743 | 1284 | |
| 1744 | 1285 | // Set up HTML ID for Other field |
| 1745 | 1286 | $other_id = self::get_other_field_html_id( $args['field']['type'], $args['html_id'], $args['opt_key'] ); |
| 1746 | 1287 | |
| 1747 | - $label = $args['opt_label'] ?? $args['field']['name']; | |
| 1288 | + $label = isset( $args['opt_label'] ) ? $args['opt_label'] : $args['field']['name']; | |
| 1748 | 1289 | |
| 1749 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 1750 | 1290 | echo '<label for="' . esc_attr( $other_id ) . '" class="frm_screen_reader frm_hidden">' . |
| 1751 | 1291 | esc_html( $label ) . |
| 1752 | 1292 | '</label>' . |
| 1753 | 1293 | '<input type="text" id="' . esc_attr( $other_id ) . '" class="' . esc_attr( implode( ' ', $classes ) ) . '" ' . |
| @@ -1752,9 +1292,8 @@ | ||
| 1752 | 1292 | '</label>' . |
| 1753 | 1293 | '<input type="text" id="' . esc_attr( $other_id ) . '" class="' . esc_attr( implode( ' ', $classes ) ) . '" ' . |
| 1754 | 1294 | ( $args['read_only'] ? ' readonly="readonly" disabled="disabled"' : '' ) . |
| 1755 | 1295 | ' name="' . esc_attr( $args['name'] ) . '" value="' . esc_attr( $args['value'] ) . '" />'; |
| 1756 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 1757 | 1296 | } |
| 1758 | 1297 | |
| 1759 | 1298 | /** |
| 1760 | 1299 | * Get the HTML id for an "Other" text field |
| @@ -1761,19 +1300,19 @@ | ||
| 1761 | 1300 | * Note: This does not affect fields in repeating sections |
| 1762 | 1301 | * |
| 1763 | 1302 | * @since 2.0.08 |
| 1764 | 1303 | * |
| 1765 | - * @param string $type Field type. | |
| 1766 | - * @param string $html_id | |
| 1767 | - * @param bool|string $opt_key | |
| 1304 | + * @param string $type - field type | |
| 1305 | + * @param string $html_id | |
| 1306 | + * @param string|boolean $opt_key | |
| 1768 | 1307 | * |
| 1769 | - * @return string Other ID. | |
| 1308 | + * @return string $other_id | |
| 1770 | 1309 | */ |
| 1771 | 1310 | public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) { |
| 1772 | 1311 | $other_id = $html_id; |
| 1773 | 1312 | |
| 1774 | 1313 | // If hidden radio field, add an opt key of 0 |
| 1775 | - if ( $type === 'radio' && $opt_key === false ) { | |
| 1314 | + if ( $type == 'radio' && $opt_key === false ) { | |
| 1776 | 1315 | $opt_key = 0; |
| 1777 | 1316 | } |
| 1778 | 1317 | |
| 1779 | 1318 | if ( $opt_key !== false ) { |
| @@ -1779,21 +1318,17 @@ | ||
| 1779 | 1318 | if ( $opt_key !== false ) { |
| 1780 | 1319 | $other_id .= '-' . $opt_key; |
| 1781 | 1320 | } |
| 1782 | 1321 | |
| 1783 | - return $other_id . '-otext'; | |
| 1322 | + $other_id .= '-otext'; | |
| 1323 | + | |
| 1324 | + return $other_id; | |
| 1784 | 1325 | } |
| 1785 | 1326 | |
| 1786 | - /** | |
| 1787 | - * @param array|string $val | |
| 1788 | - * | |
| 1789 | - * @return array|string | |
| 1790 | - */ | |
| 1791 | 1327 | public static function switch_field_ids( $val ) { |
| 1792 | 1328 | global $frm_duplicate_ids; |
| 1793 | 1329 | $replace = array(); |
| 1794 | 1330 | $replace_with = array(); |
| 1795 | - | |
| 1796 | 1331 | foreach ( (array) $frm_duplicate_ids as $old => $new ) { |
| 1797 | 1332 | $replace[] = '[if ' . $old . ']'; |
| 1798 | 1333 | $replace_with[] = '[if ' . $new . ']'; |
| 1799 | 1334 | $replace[] = '[if ' . $old . ' '; |
| @@ -1815,31 +1350,19 @@ | ||
| 1815 | 1350 | $replace[] = 'field_id="' . $old . '"'; |
| 1816 | 1351 | $replace_with[] = 'field_id="' . $new . '"'; |
| 1817 | 1352 | $replace[] = 'field_id=\"' . $old . '\"'; |
| 1818 | 1353 | $replace_with[] = 'field_id=\"' . $new . '\"'; |
| 1819 | - // This covers conditional logic. | |
| 1820 | - $replace[] = '_field":"' . $old . '","'; | |
| 1821 | - $replace_with[] = '_field":"' . $new . '","'; | |
| 1822 | 1354 | unset( $old, $new ); |
| 1823 | - }//end foreach | |
| 1824 | - | |
| 1825 | - if ( ! is_array( $val ) ) { | |
| 1826 | - return str_replace( $replace, $replace_with, $val ); | |
| 1827 | 1355 | } |
| 1828 | - | |
| 1829 | - foreach ( $val as $k => $v ) { | |
| 1830 | - if ( ! is_string( $v ) ) { | |
| 1831 | - continue; | |
| 1356 | + if ( is_array( $val ) ) { | |
| 1357 | + foreach ( $val as $k => $v ) { | |
| 1358 | + if ( is_string( $v ) ) { | |
| 1359 | + $val[ $k ] = str_replace( $replace, $replace_with, $v ); | |
| 1360 | + unset( $k, $v ); | |
| 1361 | + } | |
| 1832 | 1362 | } |
| 1833 | - | |
| 1834 | - if ( 'custom_html' === $k ) { | |
| 1835 | - $val[ $k ] = self::switch_ids_except_strings( $replace, $replace_with, array( '[if description]', '[description]', '[/if description]' ), $v ); | |
| 1836 | - unset( $k, $v ); | |
| 1837 | - continue; | |
| 1838 | - } | |
| 1839 | - | |
| 1840 | - $val[ $k ] = str_replace( $replace, $replace_with, $v ); | |
| 1841 | - unset( $k, $v ); | |
| 1363 | + } else { | |
| 1364 | + $val = str_replace( $replace, $replace_with, $val ); | |
| 1842 | 1365 | } |
| 1843 | 1366 | |
| 1844 | 1367 | return $val; |
| 1845 | 1368 | } |
| @@ -1844,48 +1367,17 @@ | ||
| 1844 | 1367 | return $val; |
| 1845 | 1368 | } |
| 1846 | 1369 | |
| 1847 | 1370 | /** |
| 1848 | - * Removes exception strings from replacement arrays and replaces the rest in the provided value string. | |
| 1849 | - * | |
| 1850 | - * @since 6.14 | |
| 1851 | - * | |
| 1852 | - * @param array $replace Values to be replaced. | |
| 1853 | - * @param array $replace_with Replacement values. | |
| 1854 | - * @param array $exceptions Array of strings to skip. | |
| 1855 | - * @param string $value Value to be updated. | |
| 1856 | - * | |
| 1857 | - * @return string | |
| 1858 | - */ | |
| 1859 | - private static function switch_ids_except_strings( $replace, $replace_with, $exceptions, $value ) { | |
| 1860 | - foreach ( $exceptions as $exception ) { | |
| 1861 | - $index = array_search( $exception, $replace, true ); | |
| 1862 | - | |
| 1863 | - if ( false === $index ) { | |
| 1864 | - continue; | |
| 1865 | - } | |
| 1866 | - unset( $replace[ $index ] ); | |
| 1867 | - unset( $replace_with[ $index ] ); | |
| 1868 | - } | |
| 1869 | - | |
| 1870 | - return str_replace( $replace, $replace_with, $value ); | |
| 1871 | - } | |
| 1872 | - | |
| 1873 | - /** | |
| 1874 | 1371 | * @since 4.0 |
| 1875 | - * | |
| 1876 | - * @return void | |
| 1877 | 1372 | */ |
| 1878 | 1373 | public static function bulk_options_overlay() { |
| 1879 | 1374 | $prepop = array(); |
| 1880 | 1375 | self::get_bulk_prefilled_opts( $prepop, true ); |
| 1881 | 1376 | |
| 1882 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/bulk-options-overlay.php'; | |
| 1377 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/bulk-options-overlay.php' ); | |
| 1883 | 1378 | } |
| 1884 | 1379 | |
| 1885 | - /** | |
| 1886 | - * @return array | |
| 1887 | - */ | |
| 1888 | 1380 | public static function get_us_states() { |
| 1889 | 1381 | $states = array( |
| 1890 | 1382 | 'AL' => 'Alabama', |
| 1891 | 1383 | 'AK' => 'Alaska', |
| @@ -1942,11 +1434,8 @@ | ||
| 1942 | 1434 | |
| 1943 | 1435 | return apply_filters( 'frm_us_states', $states ); |
| 1944 | 1436 | } |
| 1945 | 1437 | |
| 1946 | - /** | |
| 1947 | - * @return array | |
| 1948 | - */ | |
| 1949 | 1438 | public static function get_countries() { |
| 1950 | 1439 | $countries = array( |
| 1951 | 1440 | __( 'Afghanistan', 'formidable' ), |
| 1952 | 1441 | __( 'Aland Islands', 'formidable' ), |
| @@ -2211,15 +1700,12 @@ | ||
| 2211 | 1700 | * @since 5.0.04 Add `$include_class` param. |
| 2212 | 1701 | * |
| 2213 | 1702 | * @param array $prepop Bulk options. |
| 2214 | 1703 | * @param array|false $include_class Include the class in the bulk options. |
| 2215 | - * | |
| 2216 | - * @return void | |
| 2217 | 1704 | */ |
| 2218 | 1705 | public static function get_bulk_prefilled_opts( array &$prepop, $include_class = false ) { |
| 2219 | 1706 | // Countries. |
| 2220 | 1707 | $countries = self::get_countries(); |
| 2221 | - | |
| 2222 | 1708 | if ( $include_class ) { |
| 2223 | 1709 | $countries['class'] = 'frm-countries-opts'; |
| 2224 | 1710 | } |
| 2225 | 1711 | |
| @@ -2228,9 +1714,8 @@ | ||
| 2228 | 1714 | // State abv. |
| 2229 | 1715 | $states = self::get_us_states(); |
| 2230 | 1716 | $state_abv = array_keys( $states ); |
| 2231 | 1717 | sort( $state_abv ); |
| 2232 | - | |
| 2233 | 1718 | if ( $include_class ) { |
| 2234 | 1719 | $state_abv['class'] = 'frm-state-abv-opts'; |
| 2235 | 1720 | } |
| 2236 | 1721 | |
| @@ -2238,9 +1723,8 @@ | ||
| 2238 | 1723 | |
| 2239 | 1724 | // States. |
| 2240 | 1725 | $states = array_values( $states ); |
| 2241 | 1726 | sort( $states ); |
| 2242 | - | |
| 2243 | 1727 | if ( $include_class ) { |
| 2244 | 1728 | $states['class'] = 'frm-states-opts'; |
| 2245 | 1729 | } |
| 2246 | 1730 | |
| @@ -2257,9 +1741,8 @@ | ||
| 2257 | 1741 | __( '55-64', 'formidable' ), |
| 2258 | 1742 | __( '65 or Above', 'formidable' ), |
| 2259 | 1743 | __( 'Prefer Not to Answer', 'formidable' ), |
| 2260 | 1744 | ); |
| 2261 | - | |
| 2262 | 1745 | if ( $include_class ) { |
| 2263 | 1746 | $ages['class'] = 'frm-age-opts'; |
| 2264 | 1747 | } |
| 2265 | 1748 | |
| @@ -2273,9 +1756,8 @@ | ||
| 2273 | 1756 | __( 'Satisfied', 'formidable' ), |
| 2274 | 1757 | __( 'Very Satisfied', 'formidable' ), |
| 2275 | 1758 | __( 'N/A', 'formidable' ), |
| 2276 | 1759 | ); |
| 2277 | - | |
| 2278 | 1760 | if ( $include_class ) { |
| 2279 | 1761 | $satisfaction['class'] = 'frm-satisfaction-opts'; |
| 2280 | 1762 | } |
| 2281 | 1763 | |
| @@ -2289,9 +1771,8 @@ | ||
| 2289 | 1771 | __( 'Important', 'formidable' ), |
| 2290 | 1772 | __( 'Very Important', 'formidable' ), |
| 2291 | 1773 | __( 'N/A', 'formidable' ), |
| 2292 | 1774 | ); |
| 2293 | - | |
| 2294 | 1775 | if ( $include_class ) { |
| 2295 | 1776 | $importance['class'] = 'frm-importance-opts'; |
| 2296 | 1777 | } |
| 2297 | 1778 | |
| @@ -2305,9 +1786,8 @@ | ||
| 2305 | 1786 | __( 'Agree', 'formidable' ), |
| 2306 | 1787 | __( 'Strongly Agree', 'formidable' ), |
| 2307 | 1788 | __( 'N/A', 'formidable' ), |
| 2308 | 1789 | ); |
| 2309 | - | |
| 2310 | 1790 | if ( $include_class ) { |
| 2311 | 1791 | $agreement['class'] = 'frm-agreement-opts'; |
| 2312 | 1792 | } |
| 2313 | 1793 | |
| @@ -2321,9 +1801,8 @@ | ||
| 2321 | 1801 | __( 'Likely', 'formidable' ), |
| 2322 | 1802 | __( 'Extremely Likely', 'formidable' ), |
| 2323 | 1803 | __( 'N/A', 'formidable' ), |
| 2324 | 1804 | ); |
| 2325 | - | |
| 2326 | 1805 | if ( $include_class ) { |
| 2327 | 1806 | $likely['class'] = 'frm-likely-opts'; |
| 2328 | 1807 | } |
| 2329 | 1808 | |
| @@ -2336,12 +1815,10 @@ | ||
| 2336 | 1815 | * Display a field value selector |
| 2337 | 1816 | * |
| 2338 | 1817 | * @since 2.03.05 |
| 2339 | 1818 | * |
| 2340 | - * @param int $selector_field_id | |
| 1819 | + * @param int $selector_field_id | |
| 2341 | 1820 | * @param array $selector_args |
| 2342 | - * | |
| 2343 | - * @return void | |
| 2344 | 1821 | */ |
| 2345 | 1822 | public static function display_field_value_selector( $selector_field_id, $selector_args ) { |
| 2346 | 1823 | $field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args ); |
| 2347 | 1824 | $field_value_selector->display(); |
| @@ -2356,9 +1833,9 @@ | ||
| 2356 | 1833 | * |
| 2357 | 1834 | * @return array |
| 2358 | 1835 | */ |
| 2359 | 1836 | public static function convert_field_object_to_flat_array( $field ) { |
| 2360 | - $field_options = is_array( $field->field_options ) ? $field->field_options : array(); | |
| 1837 | + $field_options = $field->field_options; | |
| 2361 | 1838 | $field_array = get_object_vars( $field ); |
| 2362 | 1839 | unset( $field_array['field_options'] ); |
| 2363 | 1840 | |
| 2364 | 1841 | return $field_array + $field_options; |
| @@ -2364,44 +1841,10 @@ | ||
| 2364 | 1841 | return $field_array + $field_options; |
| 2365 | 1842 | } |
| 2366 | 1843 | |
| 2367 | 1844 | /** |
| 2368 | - * Shows add field link. | |
| 2369 | - * | |
| 2370 | - * @since 6.30 | |
| 2371 | - * | |
| 2372 | - * @param array $field_type See file `classes/views/frm-forms/add_field_links.php`. | |
| 2373 | - * | |
| 2374 | - * @return void | |
| 2375 | - */ | |
| 2376 | - public static function show_add_field_link( $field_type ) { | |
| 2377 | - $field_label = FrmFormsHelper::get_field_link_name( $field_type ); | |
| 2378 | - $classes = 'frmbutton frm6 frm_t' . $field_type['key']; | |
| 2379 | - | |
| 2380 | - if ( ! empty( $field_type['hide'] ) ) { | |
| 2381 | - $classes .= ' frm_hidden'; | |
| 2382 | - } | |
| 2383 | - ?> | |
| 2384 | -<li class="<?php echo esc_attr( $classes ); ?>" id="<?php echo esc_attr( $field_type['key'] ); ?>"> | |
| 2385 | - <a href="#" class="frm_add_field" title="<?php echo esc_attr( $field_label ); ?>" role="button" aria-label="<?php echo esc_attr( $field_label ); ?>"> | |
| 2386 | - <?php FrmAppHelper::icon_by_class( FrmFormsHelper::get_field_link_icon( $field_type ) ); ?> | |
| 2387 | - <span><?php echo esc_html( $field_label ); ?></span> | |
| 2388 | - <?php | |
| 2389 | - if ( 'credit_card' === $field_type['key'] && ! FrmTransLiteAppHelper::payments_table_exists() ) { | |
| 2390 | - FrmAppHelper::show_pill_text(); | |
| 2391 | - } | |
| 2392 | - ?> | |
| 2393 | - </a> | |
| 2394 | -</li> | |
| 2395 | - <?php | |
| 2396 | - } | |
| 2397 | - | |
| 2398 | - /** | |
| 2399 | 1845 | * @since 4.04 |
| 2400 | - * | |
| 2401 | 1846 | * @param array $args |
| 2402 | - * | |
| 2403 | - * @return void | |
| 2404 | 1847 | */ |
| 2405 | 1848 | public static function show_add_field_buttons( $args ) { |
| 2406 | 1849 | $field_key = $args['field_key']; |
| 2407 | 1850 | $field_type = $args['field_type']; |
| @@ -2408,32 +1851,34 @@ | ||
| 2408 | 1851 | $field_label = FrmAppHelper::icon_by_class( FrmFormsHelper::get_field_link_icon( $field_type ), array( 'echo' => false ) ); |
| 2409 | 1852 | $field_name = FrmFormsHelper::get_field_link_name( $field_type ); |
| 2410 | 1853 | $field_label .= ' <span>' . $field_name . '</span>'; |
| 2411 | 1854 | |
| 2412 | - if ( ! empty( $field_type['is_new'] ) ) { | |
| 2413 | - ob_start(); | |
| 2414 | - FrmAppHelper::show_pill_text(); | |
| 2415 | - $field_label .= ob_get_clean(); | |
| 2416 | - } | |
| 2417 | - | |
| 2418 | 1855 | // If the individual field isn't allowed, disable it. |
| 2419 | - $link = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : ''; | |
| 1856 | + $run_filter = true; | |
| 1857 | + $single_no_allow = ' '; | |
| 1858 | + $install_data = ''; | |
| 1859 | + $requires = ''; | |
| 1860 | + $link = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : ''; | |
| 1861 | + $has_show_upgrade_class = strpos( $field_type['icon'], ' frm_show_upgrade' ); | |
| 1862 | + $show_upgrade = $has_show_upgrade_class || false !== strpos( $args['no_allow_class'], 'frm_show_upgrade' ); | |
| 2420 | 1863 | |
| 2421 | - list( | |
| 2422 | - $run_filter, | |
| 2423 | - $single_no_allow, | |
| 2424 | - $install_data, | |
| 2425 | - $requires, | |
| 2426 | - $has_show_upgrade_class, | |
| 2427 | - $has_show_update_class, | |
| 2428 | - $upgrading, | |
| 2429 | - $update_addon_name | |
| 2430 | - ) = self::get_field_upgrade_state( $field_type ); | |
| 1864 | + if ( $has_show_upgrade_class ) { | |
| 1865 | + $single_no_allow .= 'frm_show_upgrade'; | |
| 1866 | + $field_type['icon'] = str_replace( ' frm_show_upgrade', '', $field_type['icon'] ); | |
| 1867 | + $run_filter = false; | |
| 1868 | + if ( isset( $field_type['addon'] ) ) { | |
| 1869 | + $upgrading = FrmAddonsController::install_link( $field_type['addon'] ); | |
| 1870 | + if ( isset( $upgrading['url'] ) ) { | |
| 1871 | + $install_data = json_encode( $upgrading ); | |
| 1872 | + } | |
| 1873 | + $requires = FrmFormsHelper::get_plan_required( $upgrading ); | |
| 1874 | + } elseif ( isset( $field_type['require'] ) ) { | |
| 1875 | + $requires = $field_type['require']; | |
| 1876 | + } | |
| 1877 | + } | |
| 2431 | 1878 | |
| 2432 | - $show_upgrade = $has_show_upgrade_class || $has_show_update_class || str_contains( $args['no_allow_class'], 'frm_show_upgrade' ); | |
| 2433 | 1879 | $upgrade_label = ''; |
| 2434 | 1880 | $upgrade_message = ''; |
| 2435 | - | |
| 2436 | 1881 | if ( $show_upgrade ) { |
| 2437 | 1882 | /* translators: %s: Field name */ |
| 2438 | 1883 | $upgrade_label = sprintf( esc_html__( '%s fields', 'formidable' ), $field_name ); |
| 2439 | 1884 | |
| @@ -2452,45 +1897,11 @@ | ||
| 2452 | 1897 | 'data-content' => $field_key, |
| 2453 | 1898 | 'data-requires' => $requires, |
| 2454 | 1899 | ); |
| 2455 | 1900 | |
| 2456 | - if ( ! empty( $field_type['hide'] ) ) { | |
| 2457 | - $li_params['class'] .= ' frm_hidden'; | |
| 2458 | - } | |
| 2459 | - | |
| 2460 | - if ( ! $show_upgrade && ! empty( $field_type['limit'] ) ) { | |
| 2461 | - $li_params = self::update_params_with_limit_data( $li_params, $args['id'], $field_key, $field_type['limit'] ); | |
| 2462 | - } | |
| 2463 | - | |
| 2464 | - if ( ! empty( $field_type['upsell_image'] ) ) { | |
| 2465 | - $li_params['data-upsell-image'] = $field_type['upsell_image']; | |
| 2466 | - } | |
| 2467 | - | |
| 2468 | - if ( ! empty( $field_type['learn-more'] ) ) { | |
| 2469 | - $li_params['data-learn-more'] = FrmAppHelper::get_doc_url( | |
| 2470 | - $field_type['learn-more'], | |
| 2471 | - 'form-builder-add-fields', | |
| 2472 | - str_contains( $field_type['learn-more'], '/' ) | |
| 2473 | - ); | |
| 2474 | - } | |
| 2475 | - | |
| 2476 | - if ( $has_show_update_class ) { | |
| 2477 | - $li_params['data-message'] = sprintf( | |
| 2478 | - // translators: %1$s: Add-on name, %2$s: Field type name. | |
| 2479 | - esc_html__( 'You need a newer version of %1$s for %2$s fields.', 'formidable' ), | |
| 2480 | - $update_addon_name, | |
| 2481 | - $field_name | |
| 2482 | - ); | |
| 2483 | - } elseif ( isset( $upgrading['url'] ) ) { | |
| 2484 | - $li_params['data-message'] = sprintf( | |
| 2485 | - // translators: %s: Field name | |
| 2486 | - esc_html__( 'You already have access to %s fields, you\'ll just need to activate to start using them.', 'formidable' ), | |
| 2487 | - $field_name | |
| 2488 | - ); | |
| 2489 | - } elseif ( $upgrade_message ) { | |
| 1901 | + if ( $upgrade_message ) { | |
| 2490 | 1902 | $li_params['data-message'] = $upgrade_message; |
| 2491 | 1903 | } |
| 2492 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 2493 | 1904 | ?> |
| 2494 | 1905 | <li <?php FrmAppHelper::array_to_html_params( $li_params, true ); ?>> |
| 2495 | 1906 | <?php |
| 2496 | 1907 | if ( $run_filter ) { |
| @@ -2495,147 +1906,26 @@ | ||
| 2495 | 1906 | <?php |
| 2496 | 1907 | if ( $run_filter ) { |
| 2497 | 1908 | $field_label = apply_filters( 'frmpro_field_links', $field_label, $args['id'], $field_key ); |
| 2498 | 1909 | } |
| 2499 | - | |
| 2500 | - FrmAppHelper::kses_echo( $field_label, array( 'a', 'i', 'span', 'use', 'svg' ) ); | |
| 1910 | + echo FrmAppHelper::kses( $field_label, array( 'a', 'i', 'span', 'use', 'svg' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2501 | 1911 | ?> |
| 2502 | 1912 | </li> |
| 2503 | 1913 | <?php |
| 2504 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 2505 | 1914 | } |
| 2506 | 1915 | |
| 2507 | 1916 | /** |
| 2508 | - * Parse the upgrade and update flags from a field type's icon class. | |
| 2509 | - * | |
| 2510 | - * @since 6.29 | |
| 2511 | - * | |
| 2512 | - * @param array $field_type Field type configuration, modified in place to strip icon flag classes. | |
| 2513 | - * | |
| 2514 | - * @return array Upgrade and update state values for the field button, in positional order. | |
| 2515 | - */ | |
| 2516 | - private static function get_field_upgrade_state( &$field_type ) { | |
| 2517 | - $single_no_allow = ' '; | |
| 2518 | - $run_filter = true; | |
| 2519 | - $has_show_upgrade_class = false; | |
| 2520 | - $has_show_update_class = false; | |
| 2521 | - $install_data = ''; | |
| 2522 | - $requires = ''; | |
| 2523 | - $upgrading = array(); | |
| 2524 | - $update_addon_name = ''; | |
| 2525 | - | |
| 2526 | - if ( isset( $field_type['icon'] ) ) { | |
| 2527 | - $has_show_upgrade_class = str_contains( $field_type['icon'], ' frm_show_upgrade' ); | |
| 2528 | - $has_show_update_class = str_contains( $field_type['icon'], ' frm_show_update' ); | |
| 2529 | - } | |
| 2530 | - | |
| 2531 | - if ( $has_show_upgrade_class ) { | |
| 2532 | - $single_no_allow .= 'frm_show_upgrade'; | |
| 2533 | - $field_type['icon'] = str_replace( ' frm_show_upgrade', '', $field_type['icon'] ); | |
| 2534 | - $run_filter = false; | |
| 2535 | - | |
| 2536 | - if ( isset( $field_type['addon'] ) ) { | |
| 2537 | - $upgrading = FrmAddonsController::install_link( $field_type['addon'] ); | |
| 2538 | - | |
| 2539 | - if ( isset( $upgrading['url'] ) ) { | |
| 2540 | - $install_data = json_encode( $upgrading ); | |
| 2541 | - } | |
| 2542 | - | |
| 2543 | - $requires = FrmFormsHelper::get_plan_required( $upgrading ); | |
| 2544 | - } elseif ( isset( $field_type['require'] ) ) { | |
| 2545 | - $requires = $field_type['require']; | |
| 2546 | - } | |
| 2547 | - } | |
| 2548 | - | |
| 2549 | - if ( $has_show_update_class ) { | |
| 2550 | - $single_no_allow .= ' frm_show_update'; | |
| 2551 | - $field_type['icon'] = str_replace( ' frm_show_update', '', $field_type['icon'] ); | |
| 2552 | - $run_filter = false; | |
| 2553 | - $addon_slug = $field_type['addon'] ?? 'pro'; | |
| 2554 | - | |
| 2555 | - if ( 'pro' === $addon_slug ) { | |
| 2556 | - $update_addon_name = __( 'Formidable Pro', 'formidable' ); | |
| 2557 | - } else { | |
| 2558 | - $addon_data = FrmAddonsController::get_addon( $addon_slug ); | |
| 2559 | - $update_addon_name = $addon_data && ! empty( $addon_data['title'] ) ? $addon_data['title'] : ucfirst( $addon_slug ); | |
| 2560 | - } | |
| 2561 | - | |
| 2562 | - $install_data = FrmAddonsController::get_update_install_data( $addon_slug ); | |
| 2563 | - } | |
| 2564 | - | |
| 2565 | - return array( | |
| 2566 | - $run_filter, | |
| 2567 | - $single_no_allow, | |
| 2568 | - $install_data, | |
| 2569 | - $requires, | |
| 2570 | - $has_show_upgrade_class, | |
| 2571 | - $has_show_update_class, | |
| 2572 | - $upgrading, | |
| 2573 | - $update_addon_name, | |
| 2574 | - ); | |
| 2575 | - } | |
| 2576 | - | |
| 2577 | - /** | |
| 2578 | - * Updates the params with limit data (the data-limit attribute, and possibly the frm_at_limit class). | |
| 2579 | - * Some field types are limited to a certain number per form, including coupon fields. | |
| 2580 | - * | |
| 2581 | - * @since 6.27 | |
| 2582 | - * | |
| 2583 | - * @param array $li_params The params. | |
| 2584 | - * @param int $form_id The form ID. | |
| 2585 | - * @param string $field_type The field type. | |
| 2586 | - * @param int $limit The limit. | |
| 2587 | - * | |
| 2588 | - * @return array The updated params. | |
| 2589 | - */ | |
| 2590 | - private static function update_params_with_limit_data( $li_params, $form_id, $field_type, $limit ) { | |
| 2591 | - $fields_in_form = FrmDb::get_count( | |
| 2592 | - 'frm_fields', | |
| 2593 | - array( | |
| 2594 | - 'form_id' => $form_id, | |
| 2595 | - 'type' => $field_type, | |
| 2596 | - ) | |
| 2597 | - ); | |
| 2598 | - | |
| 2599 | - if ( $fields_in_form >= $limit ) { | |
| 2600 | - $li_params['class'] .= ' frm_at_limit'; | |
| 2601 | - } | |
| 2602 | - | |
| 2603 | - $li_params['data-limit'] = $limit; | |
| 2604 | - | |
| 2605 | - return $li_params; | |
| 2606 | - } | |
| 2607 | - | |
| 2608 | - /** | |
| 2609 | 1917 | * Shows Display format option. |
| 2610 | 1918 | * |
| 2611 | 1919 | * @since 5.0.04 |
| 2612 | 1920 | * |
| 2613 | 1921 | * @param array $field Field data. |
| 2614 | - * | |
| 2615 | - * @return void | |
| 2616 | 1922 | */ |
| 2617 | 1923 | public static function show_radio_display_format( $field ) { |
| 2618 | - $options = self::get_display_format_options( $field ); | |
| 2619 | - $args = self::get_display_format_args( $field, $options ); | |
| 2620 | - | |
| 2621 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/radio-display-format.php'; | |
| 2622 | - } | |
| 2623 | - | |
| 2624 | - /** | |
| 2625 | - * Creates an array that contains variables used for display format options setting. | |
| 2626 | - * | |
| 2627 | - * @since 6.3.2 | |
| 2628 | - * | |
| 2629 | - * @param array $field The field. | |
| 2630 | - * | |
| 2631 | - * @return array | |
| 2632 | - */ | |
| 2633 | - public static function get_display_format_options( $field ) { | |
| 2634 | 1924 | $options = array( |
| 2635 | 1925 | '0' => array( |
| 2636 | - 'text' => __( 'Simple', 'formidable' ), | |
| 2637 | - 'svg' => 'frm_simple_radio', | |
| 1926 | + 'text' => __( 'Simple', 'formidable' ), | |
| 1927 | + 'svg' => 'frm_simple_radio', | |
| 2638 | 1928 | ), |
| 2639 | 1929 | '1' => array( |
| 2640 | 1930 | 'text' => __( 'Images', 'formidable' ), |
| 2641 | 1931 | 'svg' => 'frm_image_as_option', |
| @@ -2640,9 +1930,9 @@ | ||
| 2640 | 1930 | 'text' => __( 'Images', 'formidable' ), |
| 2641 | 1931 | 'svg' => 'frm_image_as_option', |
| 2642 | 1932 | 'addon' => 'pro', |
| 2643 | 1933 | 'upgrade' => __( 'Image Options', 'formidable' ), |
| 2644 | - 'message' => __( 'Show images instead of radio buttons or check boxes. This is ideal for polls, surveys, segmenting questionnaires and more.', 'formidable' ) . '<img src="' . esc_url( FrmAppHelper::plugin_url() ) . '/images/image-options.png" />', // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 1934 | + 'message' => __( 'Show images instead of radio buttons or check boxes. This is ideal for polls, surveys, segmenting questionnaires and more.', 'formidable' ) . '<img src="' . esc_url( FrmAppHelper::plugin_url() ) . '/images/image-options.png" />', | |
| 2645 | 1935 | 'content' => 'image-options', |
| 2646 | 1936 | ), |
| 2647 | 1937 | 'buttons' => array( |
| 2648 | 1938 | 'text' => __( 'Buttons', 'formidable' ), |
| @@ -2653,12 +1943,8 @@ | ||
| 2653 | 1943 | 'content' => 'button-options', |
| 2654 | 1944 | ), |
| 2655 | 1945 | ); |
| 2656 | 1946 | |
| 2657 | - if ( 'product' === FrmField::get_field_type( $field ) ) { | |
| 2658 | - unset( $options['buttons'] ); | |
| 2659 | - } | |
| 2660 | - | |
| 2661 | 1947 | /** |
| 2662 | 1948 | * Allows modifying the options of Display format setting of Radio field. |
| 2663 | 1949 | * |
| 2664 | 1950 | * @since 5.0.04 |
| @@ -2663,11 +1949,14 @@ | ||
| 2663 | 1949 | * |
| 2664 | 1950 | * @since 5.0.04 |
| 2665 | 1951 | * |
| 2666 | 1952 | * @param array $options Options. |
| 2667 | - * @param array $field | |
| 2668 | 1953 | */ |
| 2669 | - return apply_filters( 'frm_' . $field['type'] . '_display_format_options', $options, $field ); | |
| 1954 | + $options = apply_filters( 'frm_radio_display_format_options', $options ); | |
| 1955 | + | |
| 1956 | + $args = self::get_display_format_args( $field, $options ); | |
| 1957 | + | |
| 1958 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/radio-display-format.php'; | |
| 2670 | 1959 | } |
| 2671 | 1960 | |
| 2672 | 1961 | /** |
| 2673 | 1962 | * Gets display format arguments to pass to the images_dropdown() method. |
| @@ -2675,12 +1964,11 @@ | ||
| 2675 | 1964 | * @since 5.0.04 |
| 2676 | 1965 | * |
| 2677 | 1966 | * @param array $field Field data. |
| 2678 | 1967 | * @param array $options Options array. |
| 2679 | - * | |
| 2680 | 1968 | * @return array |
| 2681 | 1969 | */ |
| 2682 | - public static function get_display_format_args( $field, $options ) { | |
| 1970 | + private static function get_display_format_args( $field, $options ) { | |
| 2683 | 1971 | $args = array( |
| 2684 | 1972 | 'selected' => '0', |
| 2685 | 1973 | 'options' => array(), |
| 2686 | 1974 | 'name' => 'field_options[image_options_' . $field['id'] . ']', |
| @@ -2698,18 +1986,13 @@ | ||
| 2698 | 1986 | * |
| 2699 | 1987 | * @param array $args Arguments. |
| 2700 | 1988 | * @param array $method_args The arguments from the method. Contains `field`, `options`. |
| 2701 | 1989 | */ |
| 2702 | - return apply_filters( 'frm_' . $field['type'] . '_display_format_args', $args, compact( 'field', 'options' ) ); | |
| 1990 | + return apply_filters( 'frm_radio_display_format_args', $args, compact( 'field', 'options' ) ); | |
| 2703 | 1991 | } |
| 2704 | 1992 | |
| 2705 | 1993 | /** |
| 2706 | 1994 | * @since 5.0.04 |
| 2707 | - * | |
| 2708 | - * @param array $options Options. | |
| 2709 | - * @param array $args Arguments. | |
| 2710 | - * | |
| 2711 | - * @return void | |
| 2712 | 1995 | */ |
| 2713 | 1996 | private static function fill_image_setting_options( $options, &$args ) { |
| 2714 | 1997 | foreach ( $options as $key => $option ) { |
| 2715 | 1998 | $args['options'][ $key ] = $option; |
| @@ -2719,9 +2002,8 @@ | ||
| 2719 | 2002 | } |
| 2720 | 2003 | |
| 2721 | 2004 | unset( $args['options'][ $key ]['addon'] ); |
| 2722 | 2005 | $fill = array( 'upgrade', 'message', 'content' ); |
| 2723 | - | |
| 2724 | 2006 | foreach ( $fill as $f ) { |
| 2725 | 2007 | unset( $args['options'][ $key ][ $f ], $f ); |
| 2726 | 2008 | } |
| 2727 | 2009 | } |
| @@ -2729,10 +2011,8 @@ | ||
| 2729 | 2011 | |
| 2730 | 2012 | /** |
| 2731 | 2013 | * @since 5.0.04 |
| 2732 | 2014 | * |
| 2733 | - * @param array $option Option. | |
| 2734 | - * | |
| 2735 | 2015 | * @return array |
| 2736 | 2016 | */ |
| 2737 | 2017 | private static function fill_image_setting_addon_link( $option ) { |
| 2738 | 2018 | $custom_attrs = array( |
| @@ -2743,9 +2023,8 @@ | ||
| 2743 | 2023 | // translators: Add-on name. |
| 2744 | 2024 | $custom_attrs['data-upgrade'] = sprintf( __( 'Formidable %s', 'formidable' ), ucwords( $option['addon'] ) ); |
| 2745 | 2025 | |
| 2746 | 2026 | $fill = array( 'upgrade', 'message', 'content' ); |
| 2747 | - | |
| 2748 | 2027 | foreach ( $fill as $f ) { |
| 2749 | 2028 | if ( isset( $option[ $f ] ) ) { |
| 2750 | 2029 | $custom_attrs[ 'data-' . $f ] = $option[ $f ]; |
| 2751 | 2030 | } |
| @@ -2755,10 +2034,15 @@ | ||
| 2755 | 2034 | return $custom_attrs; |
| 2756 | 2035 | } |
| 2757 | 2036 | |
| 2758 | 2037 | $upgrading = FrmAddonsController::install_link( $option['addon'] ); |
| 2038 | + if ( isset( $upgrading['url'] ) ) { | |
| 2039 | + $install_data = wp_json_encode( $upgrading ); | |
| 2040 | + } else { | |
| 2041 | + $install_data = ''; | |
| 2042 | + } | |
| 2759 | 2043 | |
| 2760 | - $custom_attrs['data-oneclick'] = isset( $upgrading['url'] ) ? wp_json_encode( $upgrading ) : ''; | |
| 2044 | + $custom_attrs['data-oneclick'] = $install_data; | |
| 2761 | 2045 | $custom_attrs['data-requires'] = FrmFormsHelper::get_plan_required( $upgrading ); |
| 2762 | 2046 | |
| 2763 | 2047 | return $custom_attrs; |
| 2764 | 2048 | } |
| @@ -2763,238 +2047,92 @@ | ||
| 2763 | 2047 | return $custom_attrs; |
| 2764 | 2048 | } |
| 2765 | 2049 | |
| 2766 | 2050 | /** |
| 2767 | - * Maybe adjust a field value based on type. | |
| 2768 | - * Some types require unserializing an array. | |
| 2769 | - * These types are defined by a array_allowed property on their field model class. | |
| 2770 | - * | |
| 2771 | - * @since 6.2 | |
| 2772 | - * | |
| 2773 | - * @param mixed $value | |
| 2774 | - * @param string $field_type | |
| 2775 | - * | |
| 2776 | - * @return void | |
| 2051 | + * @deprecated 4.0 | |
| 2777 | 2052 | */ |
| 2778 | - public static function prepare_field_value( &$value, $field_type ) { | |
| 2779 | - $field_object = FrmFieldFactory::get_field_type( $field_type ); | |
| 2780 | - $value = $field_object->maybe_decode_value( $value ); | |
| 2053 | + public static function show_icon_link_js( $atts ) { | |
| 2054 | + _deprecated_function( __METHOD__, '4.0' ); | |
| 2055 | + $atts['icon'] .= $atts['is_selected'] ? ' ' : ' frm_inactive_icon '; | |
| 2056 | + if ( isset( $atts['has_default'] ) && ! $atts['has_default'] ) { | |
| 2057 | + $atts['icon'] .= 'frm_hidden '; | |
| 2058 | + } | |
| 2059 | + echo '<a href="javascript:void(0)" class="frm_bstooltip ' . esc_attr( $atts['icon'] ) . 'frm_default_val_icons frm_action_icon frm_icon_font" title="' . esc_attr( $atts['message'] ) . '"></a>'; | |
| 2781 | 2060 | } |
| 2782 | 2061 | |
| 2783 | 2062 | /** |
| 2784 | - * @since 6.8 | |
| 2785 | - * | |
| 2786 | - * @param int|string $form_id | |
| 2787 | - * @param array $field_ids If this is not empty, the results will be filtered by field id. | |
| 2788 | - * | |
| 2789 | - * @return array | |
| 2063 | + * @deprecated 4.0 | |
| 2790 | 2064 | */ |
| 2791 | - public static function get_draft_field_results( $form_id, $field_ids = array() ) { | |
| 2792 | - if ( FrmAppHelper::pro_is_installed() ) { | |
| 2793 | - $child_form_ids = FrmDb::get_col( 'frm_forms', array( 'parent_form_id' => $form_id ) ); | |
| 2794 | - $form_ids = array_merge( array( $form_id ), $child_form_ids ); | |
| 2795 | - } else { | |
| 2796 | - $form_ids = array( $form_id ); | |
| 2797 | - } | |
| 2065 | + public static function show_default_blank_js( $is_selected, $has_default_value = true ) { | |
| 2066 | + _deprecated_function( __METHOD__, '4.0' ); | |
| 2067 | + } | |
| 2798 | 2068 | |
| 2799 | - $where = array( | |
| 2800 | - 'form_id' => $form_ids, | |
| 2801 | - // Do a soft check for fields that look like drafts only. | |
| 2802 | - 'field_options LIKE' => 's:5:"draft";i:1;', | |
| 2803 | - ); | |
| 2804 | - | |
| 2805 | - if ( $field_ids ) { | |
| 2806 | - $where['id'] = $field_ids; | |
| 2807 | - } | |
| 2808 | - | |
| 2809 | - $rows = FrmDb::get_results( 'frm_fields', $where, 'id, field_options' ); | |
| 2810 | - | |
| 2811 | - return array_filter( | |
| 2812 | - $rows, | |
| 2813 | - function ( $row ) { | |
| 2814 | - FrmAppHelper::unserialize_or_decode( $row->field_options ); | |
| 2815 | - return is_array( $row->field_options ) && ! empty( $row->field_options['draft'] ); | |
| 2816 | - } | |
| 2817 | - ); | |
| 2069 | + /** | |
| 2070 | + * @deprecated 4.0 | |
| 2071 | + */ | |
| 2072 | + public static function clear_on_focus_html( $field, $display, $id = '' ) { | |
| 2073 | + _deprecated_function( __METHOD__, '4.0' ); | |
| 2818 | 2074 | } |
| 2819 | 2075 | |
| 2820 | 2076 | /** |
| 2821 | - * This is called when loading the form builder. | |
| 2822 | - * Any unsaved draft fields get added to a hidden draft_fields input on load. | |
| 2823 | - * | |
| 2824 | - * @since 6.8 | |
| 2825 | - * | |
| 2826 | - * @param int|string $form_id | |
| 2827 | - * | |
| 2828 | - * @return array | |
| 2077 | + * @deprecated 4.0 | |
| 2829 | 2078 | */ |
| 2830 | - public static function get_all_draft_field_ids( $form_id ) { | |
| 2831 | - $draft_field_rows = self::get_draft_field_results( $form_id ); | |
| 2832 | - return wp_list_pluck( $draft_field_rows, 'id' ); | |
| 2079 | + public static function show_onfocus_js( $is_selected, $has_default_value = true ) { | |
| 2080 | + _deprecated_function( __METHOD__, '4.0' ); | |
| 2833 | 2081 | } |
| 2834 | 2082 | |
| 2835 | 2083 | /** |
| 2836 | - * Render AI generate options button. | |
| 2837 | - * | |
| 2838 | - * @since 6.24 | |
| 2839 | - * | |
| 2840 | - * @param array $args Field arguments. | |
| 2841 | - * @param bool $should_hide_bulk_edit Whether to hide bulk edit. | |
| 2842 | - * | |
| 2843 | - * @return void | |
| 2084 | + * @deprecated 3.0 | |
| 2085 | + * @codeCoverageIgnore | |
| 2844 | 2086 | */ |
| 2845 | - public static function render_ai_generate_options_button( $args, $should_hide_bulk_edit = false ) { | |
| 2846 | - $attributes = array( | |
| 2847 | - 'type' => 'button', | |
| 2848 | - ); | |
| 2849 | - | |
| 2850 | - $attributes['class'] = ! empty( $args['class'] ) ? $args['class'] : self::get_ai_generate_options_button_class(); | |
| 2851 | - | |
| 2852 | - if ( $should_hide_bulk_edit ) { | |
| 2853 | - $attributes['class'] .= ' frm-force-hidden'; | |
| 2854 | - } | |
| 2855 | - | |
| 2856 | - $data = FrmAppHelper::get_upgrade_data_params( | |
| 2857 | - 'ai', | |
| 2858 | - array( | |
| 2859 | - 'requires' => 'Business', | |
| 2860 | - 'upgrade' => $args['upgrade_text'] ?? __( 'Generate options with AI', 'formidable' ), | |
| 2861 | - 'medium' => 'builder', | |
| 2862 | - 'content' => 'generate-options-with-ai', | |
| 2863 | - ), | |
| 2864 | - true | |
| 2865 | - ); | |
| 2866 | - | |
| 2867 | - if ( in_array( FrmAddonsController::license_type(), array( 'elite', 'business' ), true ) && 'active' === $data['plugin-status'] ) { | |
| 2868 | - // Backwards compatibility "@since 6.24". | |
| 2869 | - if ( method_exists( 'FrmAIAppController', 'get_ai_generated_options_summary' ) ) { | |
| 2870 | - $attributes['class'] .= ' frm-ai-generate-options-modal-trigger'; | |
| 2871 | - $attributes['data-fid'] = $args['likert_id'] ?? $args['field']['id']; | |
| 2872 | - } else { | |
| 2873 | - $data = array( | |
| 2874 | - 'modal-title' => __( 'Generate options with AI', 'formidable' ), | |
| 2875 | - 'modal-content' => __( 'Update the Formidable AI add-on to the last version to use this feature.', 'formidable' ), | |
| 2876 | - ); | |
| 2877 | - } | |
| 2878 | - } | |
| 2879 | - | |
| 2880 | - if ( empty( $attributes['data-fid'] ) ) { | |
| 2881 | - unset( $data['plugin-status'] ); | |
| 2882 | - | |
| 2883 | - foreach ( $data as $key => $value ) { | |
| 2884 | - $attributes[ 'data-' . $key ] = $value; | |
| 2885 | - } | |
| 2886 | - } | |
| 2887 | - | |
| 2888 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/generate-options-with-ai.php'; | |
| 2087 | + public static function display_recaptcha() { | |
| 2088 | + _deprecated_function( __FUNCTION__, '3.0', 'FrmFieldCaptcha::field_input' ); | |
| 2889 | 2089 | } |
| 2890 | 2090 | |
| 2891 | 2091 | /** |
| 2892 | - * Get AI generate options button class. | |
| 2893 | - * | |
| 2894 | - * @since 6.24 | |
| 2895 | - * | |
| 2896 | - * @return string Button class. | |
| 2092 | + * @deprecated 3.0 | |
| 2093 | + * @codeCoverageIgnore | |
| 2897 | 2094 | */ |
| 2898 | - private static function get_ai_generate_options_button_class() { | |
| 2899 | - return implode( | |
| 2900 | - ' ', | |
| 2901 | - array( | |
| 2902 | - 'frm_form_field', | |
| 2903 | - 'frm6', | |
| 2904 | - 'frm6_followed', | |
| 2905 | - 'frm-h-stack', | |
| 2906 | - 'button', | |
| 2907 | - 'frm-button-secondary', | |
| 2908 | - 'frm-button-gradient', | |
| 2909 | - 'frm-rounded-6', | |
| 2910 | - 'frm-max-w-fit', | |
| 2911 | - 'frm-font-normal', | |
| 2912 | - 'frm-py-2xs', | |
| 2913 | - 'frm-px-xs', | |
| 2914 | - 'frm-mt-xs', | |
| 2915 | - 'frm-mb-12', | |
| 2916 | - ) | |
| 2917 | - ); | |
| 2095 | + public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) { | |
| 2096 | + FrmDeprecated::remove_inline_conditions( $no_vars, $code, $replace_with, $html ); | |
| 2918 | 2097 | } |
| 2919 | 2098 | |
| 2920 | 2099 | /** |
| 2921 | - * Checks if the field choice should be hidden due to choice limit being reached. | |
| 2922 | - * | |
| 2923 | - * @since 6.28 | |
| 2924 | - * | |
| 2925 | - * @param string $choice_key | |
| 2926 | - * @param array $field | |
| 2927 | - * | |
| 2928 | - * @return bool | |
| 2100 | + * @deprecated 3.0 | |
| 2101 | + * @codeCoverageIgnore | |
| 2929 | 2102 | */ |
| 2930 | - public static function should_hide_field_choice( $choice_key, $field ) { | |
| 2931 | - /** | |
| 2932 | - * @since 6.28 | |
| 2933 | - * | |
| 2934 | - * @param bool $hide_field_choice | |
| 2935 | - * @param string $choice_key | |
| 2936 | - * @param array $field | |
| 2937 | - */ | |
| 2938 | - return (bool) apply_filters( 'frm_hide_field_choice', false, $choice_key, $field ); | |
| 2103 | + public static function get_shortcode_tag( $shortcodes, $short_key, $args ) { | |
| 2104 | + return FrmDeprecated::get_shortcode_tag( $shortcodes, $short_key, $args ); | |
| 2939 | 2105 | } |
| 2940 | 2106 | |
| 2941 | 2107 | /** |
| 2942 | - * @since 6.28 | |
| 2108 | + * @deprecated 3.0 | |
| 2109 | + * @codeCoverageIgnore | |
| 2943 | 2110 | * |
| 2944 | - * @param array $field | |
| 2111 | + * @param string $html | |
| 2112 | + * @param array $field | |
| 2113 | + * @param array $errors | |
| 2114 | + * @param object|false $form | |
| 2115 | + * @param array $args | |
| 2945 | 2116 | * |
| 2946 | - * @return bool | |
| 2117 | + * @return string | |
| 2947 | 2118 | */ |
| 2948 | - public static function should_skip_rendering_choices_for_field( $field ) { | |
| 2949 | - /** | |
| 2950 | - * @since 6.28 | |
| 2951 | - * | |
| 2952 | - * @param bool $skip_rendering_options_for_field | |
| 2953 | - * @param array $field | |
| 2954 | - */ | |
| 2955 | - return (bool) apply_filters( 'frm_should_skip_rendering_choices_for_field', false, $field ); | |
| 2119 | + public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) { | |
| 2120 | + return FrmDeprecated::replace_shortcodes( $html, $field, $errors, $form, $args ); | |
| 2956 | 2121 | } |
| 2957 | 2122 | |
| 2958 | 2123 | /** |
| 2959 | - * Determine if 'disabled' attribute should be echoed in a field choice's HTML. | |
| 2960 | - * | |
| 2961 | - * @since 6.28 | |
| 2962 | - * | |
| 2963 | - * @param string $choice_key | |
| 2964 | - * @param bool $is_selected_choice | |
| 2965 | - * @param array $field | |
| 2966 | - * | |
| 2967 | - * @return bool | |
| 2124 | + * @deprecated 3.0 | |
| 2125 | + * @codeCoverageIgnore | |
| 2968 | 2126 | */ |
| 2969 | - public static function should_disable_choice( $choice_key, $is_selected_choice, $field ) { | |
| 2970 | - /** | |
| 2971 | - * @since 6.28 | |
| 2972 | - * | |
| 2973 | - * @param bool $echo_disabled_attribute | |
| 2974 | - * @param string $choice_key | |
| 2975 | - * @param bool $is_selected_choice | |
| 2976 | - * @param array $field | |
| 2977 | - */ | |
| 2978 | - return (bool) apply_filters( 'frm_disable_choice', false, $choice_key, $is_selected_choice, $field ); | |
| 2127 | + public static function get_default_field_opts( $type, $field = null, $limit = false ) { | |
| 2128 | + return FrmDeprecated::get_default_field_opts( $type, $field, $limit ); | |
| 2979 | 2129 | } |
| 2980 | 2130 | |
| 2981 | 2131 | /** |
| 2982 | - * @since 6.28 | |
| 2983 | - * | |
| 2984 | - * @param array $field | |
| 2985 | - * @param string $choice_key | |
| 2986 | - * | |
| 2987 | - * @return void | |
| 2132 | + * @deprecated 2.02.07 | |
| 2133 | + * @codeCoverageIgnore | |
| 2988 | 2134 | */ |
| 2989 | - public static function after_choice_input( $field, $choice_key ) { | |
| 2990 | - /** | |
| 2991 | - * Allows adding content after checkbox, radio button, or dropdown fields. | |
| 2992 | - * | |
| 2993 | - * @since 6.28 | |
| 2994 | - * | |
| 2995 | - * @param array $field The field data. | |
| 2996 | - * @param string $choice_key The option key. | |
| 2997 | - */ | |
| 2998 | - do_action( 'frm_after_choice_input', $field, $choice_key ); | |
| 2135 | + public static function dropdown_categories( $args ) { | |
| 2136 | + return FrmDeprecated::dropdown_categories( $args ); | |
| 2999 | 2137 | } |
| 3000 | 2138 | } |