| @@ -4,21 +4,8 @@ | ||
| 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; | |
| 14 | - | |
| 15 | - /** | |
| 16 | - * @param string $type | |
| 17 | - * @param int|string $form_id | |
| 18 | - * | |
| 19 | - * @return array | |
| 20 | - */ | |
| 21 | 8 | public static function setup_new_vars( $type = '', $form_id = '' ) { |
| 22 | 9 | |
| 23 | 10 | if ( strpos( $type, '|' ) ) { |
| 24 | 11 | list( $type, $setting ) = explode( '|', $type ); |
| @@ -26,14 +13,9 @@ | ||
| 26 | 13 | |
| 27 | 14 | $values = self::get_default_field( $type ); |
| 28 | 15 | |
| 29 | 16 | global $wpdb; |
| 30 | - $field_count = FrmDb::get_var( | |
| 31 | - 'frm_fields', | |
| 32 | - array( 'form_id' => $form_id ), | |
| 33 | - 'field_order', | |
| 34 | - array( 'order_by' => 'field_order DESC' ) | |
| 35 | - ); | |
| 17 | + $field_count = FrmDb::get_var( 'frm_fields', array( 'form_id' => $form_id ), 'field_order', array( 'order_by' => 'field_order DESC' ) ); | |
| 36 | 18 | |
| 37 | 19 | $values['field_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_fields', 'field_key' ); |
| 38 | 20 | $values['form_id'] = $form_id; |
| 39 | 21 | $values['field_order'] = $field_count + 1; |
| @@ -39,10 +21,10 @@ | ||
| 39 | 21 | $values['field_order'] = $field_count + 1; |
| 40 | 22 | |
| 41 | 23 | $values['field_options']['custom_html'] = self::get_default_html( $type ); |
| 42 | 24 | |
| 43 | - if ( ! empty( $setting ) ) { | |
| 44 | - if ( in_array( $type, array( 'data', 'lookup' ), true ) ) { | |
| 25 | + if ( isset( $setting ) && ! empty( $setting ) ) { | |
| 26 | + if ( in_array( $type, array( 'data', 'lookup' ) ) ) { | |
| 45 | 27 | $values['field_options']['data_type'] = $setting; |
| 46 | 28 | } else { |
| 47 | 29 | $values['field_options'][ $setting ] = 1; |
| 48 | 30 | } |
| @@ -47,30 +29,15 @@ | ||
| 47 | 29 | $values['field_options'][ $setting ] = 1; |
| 48 | 30 | } |
| 49 | 31 | } |
| 50 | 32 | |
| 51 | - // Increase the field order of submit field and fields in the same row. | |
| 52 | - FrmSubmitHelper::update_last_row_fields_order_when_adding_field( $field_count ); | |
| 53 | - | |
| 54 | 33 | return $values; |
| 55 | 34 | } |
| 56 | 35 | |
| 57 | - /** | |
| 58 | - * @param array $field | |
| 59 | - * @param string $plus | |
| 60 | - * | |
| 61 | - * @return string | |
| 62 | - */ | |
| 63 | 36 | public static function get_html_id( $field, $plus = '' ) { |
| 64 | 37 | return apply_filters( 'frm_field_html_id', 'field_' . $field['field_key'] . $plus, $field ); |
| 65 | 38 | } |
| 66 | 39 | |
| 67 | - /** | |
| 68 | - * @param object $field | |
| 69 | - * @param bool $doing_ajax | |
| 70 | - * | |
| 71 | - * @return array | |
| 72 | - */ | |
| 73 | 40 | public static function setup_edit_vars( $field, $doing_ajax = false ) { |
| 74 | 41 | $values = self::field_object_to_array( $field ); |
| 75 | 42 | |
| 76 | 43 | return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) ); |
| @@ -75,29 +42,18 @@ | ||
| 75 | 42 | |
| 76 | 43 | return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) ); |
| 77 | 44 | } |
| 78 | 45 | |
| 79 | - /** | |
| 80 | - * @param object $field | |
| 81 | - * | |
| 82 | - * @return array | |
| 83 | - */ | |
| 84 | 46 | public static function field_object_to_array( $field ) { |
| 85 | 47 | $values = (array) $field; |
| 86 | 48 | |
| 87 | 49 | self::fill_field_array( $field, $values ); |
| 88 | 50 | |
| 89 | - $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 ); | |
| 90 | 52 | |
| 91 | 53 | return $values; |
| 92 | 54 | } |
| 93 | 55 | |
| 94 | - /** | |
| 95 | - * @param object $field | |
| 96 | - * @param array $field_array | |
| 97 | - * | |
| 98 | - * @return void | |
| 99 | - */ | |
| 100 | 56 | private static function fill_field_array( $field, array &$field_array ) { |
| 101 | 57 | $field_array['options'] = $field->options; |
| 102 | 58 | $field_array['value'] = $field->default_value; |
| 103 | 59 | |
| @@ -106,17 +62,11 @@ | ||
| 106 | 62 | $field_array = array_merge( (array) $field->field_options, $field_array ); |
| 107 | 63 | } |
| 108 | 64 | |
| 109 | 65 | /** |
| 110 | - * Prepare field while creating a new entry. | |
| 66 | + * Prepare field while creating a new entry | |
| 111 | 67 | * |
| 112 | 68 | * @since 3.0 |
| 113 | - * | |
| 114 | - * @param array $field_array Field values array, passed by reference. | |
| 115 | - * @param stdClass $field Field object. | |
| 116 | - * @param array $args Additional arguments. | |
| 117 | - * | |
| 118 | - * @return void | |
| 119 | 69 | */ |
| 120 | 70 | public static function prepare_new_front_field( &$field_array, $field, $args = array() ) { |
| 121 | 71 | $args['action'] = 'new'; |
| 122 | 72 | self::prepare_front_field( $field_array, $field, $args ); |
| @@ -122,18 +72,11 @@ | ||
| 122 | 72 | self::prepare_front_field( $field_array, $field, $args ); |
| 123 | 73 | } |
| 124 | 74 | |
| 125 | 75 | /** |
| 126 | - * Prepare field while editing an entry. | |
| 76 | + * Prepare field while editing an entry | |
| 127 | 77 | * |
| 128 | 78 | * @since 3.0 |
| 129 | - * | |
| 130 | - * @param array $field_array Field values array, passed by reference. | |
| 131 | - * @param array|stdClass $field Field object or array. | |
| 132 | - * @param int $entry_id Entry ID. | |
| 133 | - * @param array $args Additional arguments. | |
| 134 | - * | |
| 135 | - * @return void | |
| 136 | 79 | */ |
| 137 | 80 | public static function prepare_edit_front_field( &$field_array, $field, $entry_id = 0, $args = array() ) { |
| 138 | 81 | $args['entry_id'] = $entry_id; |
| 139 | 82 | $args['action'] = 'edit'; |
| @@ -143,14 +86,8 @@ | ||
| 143 | 86 | /** |
| 144 | 87 | * Prepare field while creating a new entry |
| 145 | 88 | * |
| 146 | 89 | * @since 3.0 |
| 147 | - * | |
| 148 | - * @param array $field_array | |
| 149 | - * @param stdClass $field | |
| 150 | - * @param array $args | |
| 151 | - * | |
| 152 | - * @return void | |
| 153 | 90 | */ |
| 154 | 91 | private static function prepare_front_field( &$field_array, $field, $args ) { |
| 155 | 92 | self::fill_default_field_opts( $field, $field_array ); |
| 156 | 93 | self::fill_cleared_strings( $field, $field_array ); |
| @@ -155,26 +92,15 @@ | ||
| 155 | 92 | self::fill_default_field_opts( $field, $field_array ); |
| 156 | 93 | self::fill_cleared_strings( $field, $field_array ); |
| 157 | 94 | |
| 158 | 95 | // Track the original field's type |
| 159 | - $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; | |
| 160 | 97 | |
| 161 | 98 | self::prepare_field_options_for_display( $field_array, $field, $args ); |
| 162 | 99 | |
| 163 | - if ( $args['action'] === 'edit' ) { | |
| 164 | - /** | |
| 165 | - * @param array $field_array | |
| 166 | - * @param stdClass $field | |
| 167 | - * @param int|string $entry_id | |
| 168 | - * @param array $args | |
| 169 | - */ | |
| 100 | + if ( $args['action'] == 'edit' ) { | |
| 170 | 101 | $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $args['entry_id'], $args ); |
| 171 | 102 | } else { |
| 172 | - /** | |
| 173 | - * @param array $field_array | |
| 174 | - * @param stdClass $field | |
| 175 | - * @param array $args | |
| 176 | - */ | |
| 177 | 103 | $field_array = apply_filters( 'frm_setup_new_fields_vars', $field_array, $field, $args ); |
| 178 | 104 | } |
| 179 | 105 | } |
| 180 | 106 | |
| @@ -194,16 +120,14 @@ | ||
| 194 | 120 | /** |
| 195 | 121 | * @since 3.0 |
| 196 | 122 | * |
| 197 | 123 | * @param object $field |
| 198 | - * @param array $values | |
| 199 | - * | |
| 200 | - * @return void | |
| 124 | + * @param array $values | |
| 201 | 125 | */ |
| 202 | 126 | private static function fill_default_field_opts( $field, array &$values ) { |
| 203 | - $check_post = self::context_is_safe_to_load_field_options_from_request_data(); | |
| 204 | - $defaults = self::get_default_field_options_from_field( $field, $values ); | |
| 127 | + $check_post = FrmAppHelper::is_admin_page() && $_POST && isset( $_POST['field_options'] ); | |
| 205 | 128 | |
| 129 | + $defaults = self::get_default_field_options_from_field( $field, $values ); | |
| 206 | 130 | if ( ! $check_post ) { |
| 207 | 131 | $defaults['required_indicator'] = ''; |
| 208 | 132 | $defaults['original_type'] = $field->type; |
| 209 | 133 | } |
| @@ -208,65 +132,16 @@ | ||
| 208 | 132 | $defaults['original_type'] = $field->type; |
| 209 | 133 | } |
| 210 | 134 | |
| 211 | 135 | foreach ( $defaults as $opt => $default ) { |
| 212 | - $values[ $opt ] = $field->field_options[ $opt ] ?? $default; | |
| 136 | + $values[ $opt ] = isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default; | |
| 213 | 137 | |
| 214 | 138 | if ( $check_post ) { |
| 215 | 139 | self::get_posted_field_setting( $opt . '_' . $field->id, $values[ $opt ] ); |
| 216 | 140 | } |
| 217 | - } | |
| 218 | - } | |
| 219 | 141 | |
| 220 | - /** | |
| 221 | - * The fill_default_field_opts method is called when loading a field. | |
| 222 | - * This is used to preserve the $_POST data after updating settings for a field. | |
| 223 | - * To prevent this from happening when creating an entry, we need to check the context. | |
| 224 | - * | |
| 225 | - * @return bool | |
| 226 | - */ | |
| 227 | - private static function context_is_safe_to_load_field_options_from_request_data() { | |
| 228 | - if ( isset( self::$context_is_safe_to_load_field_options_from_request_data ) ) { | |
| 229 | - return self::$context_is_safe_to_load_field_options_from_request_data; | |
| 142 | + unset( $opt, $default ); | |
| 230 | 143 | } |
| 231 | - | |
| 232 | - $function = function () { | |
| 233 | - if ( ! FrmAppHelper::is_admin_page() ) { | |
| 234 | - return false; | |
| 235 | - } | |
| 236 | - | |
| 237 | - if ( ! $_POST || ! isset( $_POST['field_options'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 238 | - return false; | |
| 239 | - } | |
| 240 | - | |
| 241 | - if ( ! current_user_can( 'frm_edit_forms' ) ) { | |
| 242 | - return false; | |
| 243 | - } | |
| 244 | - | |
| 245 | - $action = FrmAppHelper::get_post_param( 'action', '', 'sanitize_title' ); | |
| 246 | - | |
| 247 | - if ( 'frm_forms_preview' === $action ) { | |
| 248 | - // Never trigger when previewing. | |
| 249 | - return false; | |
| 250 | - } | |
| 251 | - | |
| 252 | - // Confirm an allowed action is being used, and that the correct nonce is being used. | |
| 253 | - if ( 'update' === $action ) { | |
| 254 | - $nonce = FrmAppHelper::get_post_param( 'frm_save_form', '', 'sanitize_text_field' ); | |
| 255 | - return wp_verify_nonce( $nonce, 'frm_save_form_nonce' ); | |
| 256 | - } | |
| 257 | - | |
| 258 | - $action = FrmAppHelper::get_post_param( 'frm_action', '', 'sanitize_title' ); | |
| 259 | - | |
| 260 | - if ( 'update_settings' === $action ) { | |
| 261 | - $nonce = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); | |
| 262 | - return wp_verify_nonce( $nonce, 'process_form_nonce' ); | |
| 263 | - } | |
| 264 | - }; | |
| 265 | - | |
| 266 | - self::$context_is_safe_to_load_field_options_from_request_data = $function(); | |
| 267 | - | |
| 268 | - return self::$context_is_safe_to_load_field_options_from_request_data; | |
| 269 | 144 | } |
| 270 | 145 | |
| 271 | 146 | /** |
| 272 | 147 | * Fill the required message, invalid message, |
| @@ -274,23 +149,23 @@ | ||
| 274 | 149 | * |
| 275 | 150 | * @since 3.0 |
| 276 | 151 | * |
| 277 | 152 | * @param object $field |
| 278 | - * @param array $field_array | |
| 279 | - * | |
| 280 | - * @return void | |
| 153 | + * @param array $field_array | |
| 281 | 154 | */ |
| 282 | 155 | private static function fill_cleared_strings( $field, array &$field_array ) { |
| 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 | 171 | if ( '' == $field_array['custom_html'] ) { |
| @@ -298,68 +173,28 @@ | ||
| 298 | 173 | } |
| 299 | 174 | } |
| 300 | 175 | |
| 301 | 176 | /** |
| 302 | - * @since 6.8.3 | |
| 303 | - * | |
| 304 | - * @return string | |
| 305 | - */ | |
| 306 | - public static function default_invalid_msg() { | |
| 307 | - /* translators: %s: [field_name] shortcode (Which gets replaced by a Field Name) */ | |
| 308 | - return sprintf( __( '%s is invalid', 'formidable' ), '[field_name]' ); | |
| 309 | - } | |
| 310 | - | |
| 311 | - /** | |
| 312 | - * @since 6.8.3 | |
| 313 | - * | |
| 314 | - * @return string | |
| 315 | - */ | |
| 316 | - public static function default_unique_msg() { | |
| 317 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 318 | - $unique_message = $frm_settings->unique_msg; | |
| 319 | - $unique_message = str_replace( 'This value', '[field_name]', $unique_message ); | |
| 320 | - return $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 | - $blank_message = str_replace( 'This field', '[field_name]', $blank_message ); | |
| 332 | - return $blank_message; | |
| 333 | - } | |
| 334 | - | |
| 335 | - /** | |
| 336 | - * When loading settings for a field, check the $_POST data and possibly use that instead of the DB value. | |
| 337 | - * | |
| 338 | 177 | * @since 3.0 |
| 339 | 178 | * |
| 340 | 179 | * @param string $setting |
| 341 | - * @param mixed $value | |
| 342 | - * | |
| 343 | - * @return void | |
| 180 | + * @param mixed $value | |
| 344 | 181 | */ |
| 345 | 182 | private static function get_posted_field_setting( $setting, &$value ) { |
| 346 | - if ( ! isset( $_POST['field_options'][ $setting ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 183 | + if ( ! isset( $_POST['field_options'][ $setting ] ) ) { | |
| 347 | 184 | return; |
| 348 | 185 | } |
| 349 | 186 | |
| 350 | 187 | if ( strpos( $setting, 'html' ) !== false ) { |
| 351 | - $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing | |
| 352 | - | |
| 353 | - // Conditionally strip script tags if the user sending $_POST data is not allowed to use unfiltered HTML. | |
| 354 | - if ( ! FrmAppHelper::allow_unfiltered_html() ) { | |
| 355 | - $value = FrmAppHelper::kses( $value, 'all' ); | |
| 356 | - } | |
| 188 | + // Strip slashes from HTML but not regex or script tags. | |
| 189 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 190 | + $value = wp_unslash( $_POST['field_options'][ $setting ] ); | |
| 357 | 191 | } elseif ( strpos( $setting, 'format_' ) === 0 ) { |
| 358 | 192 | // TODO: Remove stripslashes on output, and use on input only. |
| 359 | - $value = sanitize_text_field( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing | |
| 193 | + $value = sanitize_text_field( $_POST['field_options'][ $setting ] ); // WPCS: sanitization ok. | |
| 360 | 194 | } else { |
| 361 | - $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing | |
| 195 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 196 | + $value = wp_unslash( $_POST['field_options'][ $setting ] ); | |
| 362 | 197 | FrmAppHelper::sanitize_value( 'wp_kses_post', $value ); |
| 363 | 198 | } |
| 364 | 199 | } |
| 365 | 200 | |
| @@ -366,9 +201,9 @@ | ||
| 366 | 201 | /** |
| 367 | 202 | * @since 3.0 |
| 368 | 203 | * |
| 369 | 204 | * @param object $field |
| 370 | - * @param array $values The field array is needed for hooks. | |
| 205 | + * @param array $values The field array is needed for hooks | |
| 371 | 206 | * |
| 372 | 207 | * @return array |
| 373 | 208 | */ |
| 374 | 209 | public static function get_default_field_options_from_field( $field, $values = array() ) { |
| @@ -385,13 +220,12 @@ | ||
| 385 | 220 | * @since 3.0 |
| 386 | 221 | * |
| 387 | 222 | * @param object $field |
| 388 | 223 | * |
| 389 | - * @return FrmFieldType | |
| 224 | + * @return array | |
| 390 | 225 | */ |
| 391 | 226 | private static function get_original_field( $field ) { |
| 392 | 227 | $original_type = FrmField::get_option( $field, 'original_type' ); |
| 393 | - | |
| 394 | 228 | if ( ! empty( $original_type ) && $field->type != $original_type ) { |
| 395 | 229 | $field->type = $original_type; |
| 396 | 230 | } |
| 397 | 231 | |
| @@ -400,13 +234,11 @@ | ||
| 400 | 234 | |
| 401 | 235 | /** |
| 402 | 236 | * @since 3.0 |
| 403 | 237 | * |
| 404 | - * @param array $field_array | |
| 238 | + * @param array $field_array | |
| 405 | 239 | * @param object $field |
| 406 | - * @param array $atts | |
| 407 | - * | |
| 408 | - * @return void | |
| 240 | + * @param array $atts | |
| 409 | 241 | */ |
| 410 | 242 | private static function prepare_field_options_for_display( &$field_array, $field, $atts ) { |
| 411 | 243 | $field_obj = FrmFieldFactory::get_field_object( $field ); |
| 412 | 244 | $field_array = $field_obj->prepare_front_field( $field_array, $atts ); |
| @@ -424,16 +256,8 @@ | ||
| 424 | 256 | |
| 425 | 257 | return $field_type->get_new_field_defaults(); |
| 426 | 258 | } |
| 427 | 259 | |
| 428 | - /** | |
| 429 | - * @param array $values | |
| 430 | - * @param object $field | |
| 431 | - * @param int|string $form_id | |
| 432 | - * @param string $new_key | |
| 433 | - * | |
| 434 | - * @return void | |
| 435 | - */ | |
| 436 | 260 | public static function fill_field( &$values, $field, $form_id, $new_key = '' ) { |
| 437 | 261 | global $wpdb; |
| 438 | 262 | |
| 439 | 263 | $values['field_key'] = FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
| @@ -448,27 +272,29 @@ | ||
| 448 | 272 | |
| 449 | 273 | /** |
| 450 | 274 | * @since 2.0 |
| 451 | 275 | * |
| 452 | - * @param array|object $field | |
| 453 | - * @param string $error | |
| 276 | + * @param $field | |
| 277 | + * @param $error | |
| 454 | 278 | * |
| 455 | 279 | * @return string |
| 456 | 280 | */ |
| 457 | 281 | public static function get_error_msg( $field, $error ) { |
| 458 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 282 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 283 | + $default_settings = $frm_settings->default_options(); | |
| 284 | + $field_name = is_array( $field ) ? $field['name'] : $field->name; | |
| 459 | 285 | |
| 460 | 286 | $conf_msg = __( 'The entered values do not match', 'formidable' ); |
| 461 | 287 | $defaults = array( |
| 462 | 288 | 'unique_msg' => array( |
| 463 | - 'full' => self::default_unique_msg(), | |
| 289 | + 'full' => $default_settings['unique_msg'], | |
| 464 | 290 | /* translators: %s: Field name */ |
| 465 | - 'part' => sprintf( __( '%s must be unique', 'formidable' ), '[field_name]' ), | |
| 291 | + 'part' => sprintf( __( '%s must be unique', 'formidable' ), $field_name ), | |
| 466 | 292 | ), |
| 467 | 293 | 'invalid' => array( |
| 468 | 294 | 'full' => __( 'This field is invalid', 'formidable' ), |
| 469 | 295 | /* translators: %s: Field name */ |
| 470 | - 'part' => sprintf( __( '%s is invalid', 'formidable' ), '[field_name]' ), | |
| 296 | + 'part' => sprintf( __( '%s is invalid', 'formidable' ), $field_name ), | |
| 471 | 297 | ), |
| 472 | 298 | 'blank' => array( |
| 473 | 299 | 'full' => $frm_settings->blank_msg, |
| 474 | 300 | 'part' => $frm_settings->blank_msg, |
| @@ -482,97 +308,17 @@ | ||
| 482 | 308 | $msg = FrmField::get_option( $field, $error ); |
| 483 | 309 | $msg = empty( $msg ) ? $defaults[ $error ]['part'] : $msg; |
| 484 | 310 | $msg = do_shortcode( $msg ); |
| 485 | 311 | |
| 486 | - $msg = self::maybe_replace_substrings_with_field_name( $msg, $error, $field ); | |
| 487 | - | |
| 488 | 312 | return $msg; |
| 489 | 313 | } |
| 490 | 314 | |
| 491 | - /** | |
| 492 | - * @since 6.8.3 | |
| 493 | - * | |
| 494 | - * @param string $msg | |
| 495 | - * @param string $error | |
| 496 | - * @param array|object $field | |
| 497 | - * | |
| 498 | - * @return string | |
| 499 | - */ | |
| 500 | - private static function maybe_replace_substrings_with_field_name( $msg, $error, $field ) { | |
| 501 | - $field_name = is_array( $field ) ? $field['name'] : $field->name; | |
| 502 | - $field_name = FrmAppHelper::maybe_kses( $field_name ); | |
| 503 | - $substrings = self::get_substrings_to_replace_with_field_name( $field_name, compact( 'msg', 'error', 'field' ) ); | |
| 504 | - | |
| 505 | - // Use the "This value"/"This field" placeholder strings if field name is empty. | |
| 506 | - if ( ! $field_name ) { | |
| 507 | - if ( 'unique_msg' === $error ) { | |
| 508 | - $field_name = __( 'This value', 'formidable' ); | |
| 509 | - } else { | |
| 510 | - $field_name = __( 'This field', 'formidable' ); | |
| 511 | - } | |
| 512 | - } | |
| 513 | - | |
| 514 | - $msg = str_replace( $substrings, $field_name, $msg ); | |
| 515 | - return $msg; | |
| 516 | - } | |
| 517 | - | |
| 518 | - /** | |
| 519 | - * @since 6.8.3 | |
| 520 | - * | |
| 521 | - * @param string $field_name | |
| 522 | - * @param array $filter_args { | |
| 523 | - * Filter arguments. | |
| 524 | - * | |
| 525 | - * @type string $msg The current error message before the substrings are replaced. | |
| 526 | - * @type string $error A key including 'unique_msg', 'invalid', 'blank', or 'conf_msg'. | |
| 527 | - * @type array|object $field The field with the error. | |
| 528 | - * } | |
| 529 | - * | |
| 530 | - * @return array | |
| 531 | - */ | |
| 532 | - private static function get_substrings_to_replace_with_field_name( $field_name, $filter_args ) { | |
| 533 | - $substrings = array( '[field_name]' ); | |
| 534 | - | |
| 535 | - if ( $field_name ) { | |
| 536 | - array_push( $substrings, 'This value', 'This field' ); | |
| 537 | - } | |
| 538 | - | |
| 539 | - /** | |
| 540 | - * @since 6.8.3 | |
| 541 | - * | |
| 542 | - * @param array<string> $substrings | |
| 543 | - * @param array $filter_args | |
| 544 | - */ | |
| 545 | - $filtered_substrings = apply_filters( 'frm_error_substrings_to_replace_with_field_name', $substrings, $filter_args ); | |
| 546 | - | |
| 547 | - if ( is_array( $filtered_substrings ) ) { | |
| 548 | - $substrings = $filtered_substrings; | |
| 549 | - } else { | |
| 550 | - _doing_it_wrong( __METHOD__, 'Only arrays should be returned when using the frm_error_substrings_to_replace_with_field_name filter.', '6.8.3' ); | |
| 551 | - } | |
| 552 | - | |
| 553 | - return $substrings; | |
| 554 | - } | |
| 555 | - | |
| 556 | - /** | |
| 557 | - * @param int|string $form_id | |
| 558 | - * @param array $error | |
| 559 | - * | |
| 560 | - * @return array | |
| 561 | - */ | |
| 562 | 315 | public static function get_form_fields( $form_id, $error = array() ) { |
| 563 | 316 | $fields = FrmField::get_all_for_form( $form_id ); |
| 564 | 317 | |
| 565 | - FrmFieldName::track_first_name_field( $fields ); | |
| 566 | - | |
| 567 | 318 | return apply_filters( 'frm_get_paged_fields', $fields, $form_id, $error ); |
| 568 | 319 | } |
| 569 | 320 | |
| 570 | - /** | |
| 571 | - * @param string $type | |
| 572 | - * | |
| 573 | - * @return string | |
| 574 | - */ | |
| 575 | 321 | public static function get_default_html( $type = 'text' ) { |
| 576 | 322 | $field = FrmFieldFactory::get_field_type( $type ); |
| 577 | 323 | $default_html = $field->default_html(); |
| 578 | 324 | |
| @@ -584,14 +330,12 @@ | ||
| 584 | 330 | return apply_filters( 'frm_custom_html', $default_html, $type ); |
| 585 | 331 | } |
| 586 | 332 | |
| 587 | 333 | /** |
| 588 | - * @param array $fields | |
| 589 | - * @param array $errors | |
| 334 | + * @param array $fields | |
| 335 | + * @param array $errors | |
| 590 | 336 | * @param object $form |
| 591 | - * @param object $form_action | |
| 592 | - * | |
| 593 | - * @return void | |
| 337 | + * @param $form_action | |
| 594 | 338 | */ |
| 595 | 339 | public static function show_fields( $fields, $errors, $form, $form_action ) { |
| 596 | 340 | foreach ( $fields as $field ) { |
| 597 | 341 | $field_obj = FrmFieldFactory::get_field_type( $field['type'], $field ); |
| @@ -601,21 +345,17 @@ | ||
| 601 | 345 | |
| 602 | 346 | /** |
| 603 | 347 | * @since 3.0 |
| 604 | 348 | * |
| 605 | - * @param array $atts | |
| 606 | - * @param array|string $value | |
| 607 | - * | |
| 608 | - * @return void | |
| 349 | + * @param array $atts | |
| 350 | + * @param string|array $value | |
| 609 | 351 | */ |
| 610 | 352 | public static function run_wpautop( $atts, &$value ) { |
| 611 | - $autop = $atts['wpautop'] ?? true; | |
| 612 | - | |
| 353 | + $autop = isset( $atts['wpautop'] ) ? $atts['wpautop'] : true; | |
| 613 | 354 | if ( apply_filters( 'frm_use_wpautop', $autop ) ) { |
| 614 | 355 | if ( is_array( $value ) ) { |
| 615 | 356 | $value = implode( "\n", $value ); |
| 616 | 357 | } |
| 617 | - | |
| 618 | 358 | $value = wpautop( $value ); |
| 619 | 359 | } |
| 620 | 360 | } |
| 621 | 361 | |
| @@ -622,18 +362,12 @@ | ||
| 622 | 362 | /** |
| 623 | 363 | * Get the class to use for the label position |
| 624 | 364 | * |
| 625 | 365 | * @since 2.05 |
| 626 | - * | |
| 627 | - * @param string $position | |
| 628 | - * @param array $field | |
| 629 | - * @param bool|object|string $form | |
| 630 | - * | |
| 631 | - * @return string | |
| 632 | 366 | */ |
| 633 | 367 | public static function &label_position( $position, $field, $form ) { |
| 634 | 368 | if ( $position && $position != '' ) { |
| 635 | - if ( $position === 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) { | |
| 369 | + if ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) { | |
| 636 | 370 | $position = 'top'; |
| 637 | 371 | } |
| 638 | 372 | |
| 639 | 373 | return $position; |
| @@ -639,19 +373,18 @@ | ||
| 639 | 373 | return $position; |
| 640 | 374 | } |
| 641 | 375 | |
| 642 | 376 | $position = FrmStylesController::get_style_val( 'position', $form ); |
| 643 | - | |
| 644 | - if ( $position === 'none' ) { | |
| 377 | + if ( $position == 'none' ) { | |
| 645 | 378 | $position = 'top'; |
| 646 | - } elseif ( $position === 'no_label' ) { | |
| 379 | + } elseif ( $position == 'no_label' ) { | |
| 647 | 380 | $position = 'none'; |
| 648 | - } elseif ( $position === 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) { | |
| 381 | + } elseif ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) { | |
| 649 | 382 | $position = 'top'; |
| 650 | 383 | } |
| 651 | 384 | |
| 652 | 385 | $position = apply_filters( 'frm_html_label_position', $position, $field, $form ); |
| 653 | - $position = ! empty( $position ) ? $position : 'top'; | |
| 386 | + $position = ( ! empty( $position ) ) ? $position : 'top'; | |
| 654 | 387 | |
| 655 | 388 | return $position; |
| 656 | 389 | } |
| 657 | 390 | |
| @@ -658,27 +391,15 @@ | ||
| 658 | 391 | /** |
| 659 | 392 | * Check if this field type allows placeholders |
| 660 | 393 | * |
| 661 | 394 | * @since 2.05 |
| 662 | - * | |
| 663 | - * @param string $type | |
| 664 | - * | |
| 665 | - * @return bool | |
| 666 | 395 | */ |
| 667 | 396 | public static function is_placeholder_field_type( $type ) { |
| 668 | - return ! in_array( $type, array( 'radio', 'checkbox', 'hidden', 'file' ), true ); | |
| 397 | + return ! in_array( $type, array( 'radio', 'checkbox', 'hidden', 'file' ) ); | |
| 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 | 402 | if ( isset( $field['in_section'] ) && $field['in_section'] && ! FrmAppHelper::is_admin_page( 'formidable' ) ) { |
| 682 | 403 | $id .= '-' . $field['in_section']; |
| 683 | 404 | } |
| 684 | 405 | |
| @@ -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'] ) ) { |
| @@ -697,12 +413,11 @@ | ||
| 697 | 413 | return; |
| 698 | 414 | } |
| 699 | 415 | |
| 700 | 416 | $base_name = 'default_value_' . $field['id']; |
| 701 | - $html_id = $field['html_id'] ?? self::get_html_id( $field ); | |
| 417 | + $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field ); | |
| 702 | 418 | |
| 703 | - $default_type = self::get_default_value_type( $field ); | |
| 704 | - $options_count = count( $field['options'] ); | |
| 419 | + $default_type = self::get_default_value_type( $field ); | |
| 705 | 420 | |
| 706 | 421 | foreach ( $field['options'] as $opt_key => $opt ) { |
| 707 | 422 | $field_val = self::get_value_from_array( $opt, $opt_key, $field ); |
| 708 | 423 | $opt = self::get_label_from_array( $opt, $opt_key, $field ); |
| @@ -713,12 +428,12 @@ | ||
| 713 | 428 | |
| 714 | 429 | // If this is an "Other" option, get the HTML for it. |
| 715 | 430 | if ( self::is_other_opt( $opt_key ) ) { |
| 716 | 431 | if ( FrmAppHelper::pro_is_installed() ) { |
| 717 | - require FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php'; | |
| 432 | + require( FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php' ); | |
| 718 | 433 | } |
| 719 | 434 | } else { |
| 720 | - require FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php'; | |
| 435 | + require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' ); | |
| 721 | 436 | } |
| 722 | 437 | |
| 723 | 438 | unset( $checked ); |
| 724 | 439 | } |
| @@ -727,17 +442,13 @@ | ||
| 727 | 442 | /** |
| 728 | 443 | * Include hidden row for javascript to duplicate. |
| 729 | 444 | * |
| 730 | 445 | * @since 4.0 |
| 731 | - * | |
| 732 | 446 | * @param array $field |
| 733 | - * | |
| 734 | - * @return void | |
| 735 | 447 | */ |
| 736 | 448 | private static function hidden_field_option( $field ) { |
| 737 | 449 | // Don't duplicate during an ajax add option. |
| 738 | 450 | $ajax_action = FrmAppHelper::get_param( 'action', '', 'post', 'sanitize_text_field' ); |
| 739 | - | |
| 740 | 451 | if ( $ajax_action === 'frm_add_field_option' ) { |
| 741 | 452 | return; |
| 742 | 453 | } |
| 743 | 454 | |
| @@ -745,14 +456,14 @@ | ||
| 745 | 456 | $field_val = __( 'New Option', 'formidable' ); |
| 746 | 457 | $opt = __( 'New Option', 'formidable' ); |
| 747 | 458 | $checked = false; |
| 748 | 459 | $field_name = 'default_value_' . $field['id']; |
| 749 | - $html_id = $field['html_id'] ?? self::get_html_id( $field ); | |
| 460 | + $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field ); | |
| 750 | 461 | |
| 751 | 462 | $default_type = self::get_default_value_type( $field ); |
| 752 | 463 | $field_name .= ( $default_type === 'checkbox' ? '[' . $opt_key . ']' : '' ); |
| 753 | 464 | |
| 754 | - require FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php'; | |
| 465 | + require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' ); | |
| 755 | 466 | } |
| 756 | 467 | |
| 757 | 468 | /** |
| 758 | 469 | * @since 4.0 |
| @@ -757,14 +468,12 @@ | ||
| 757 | 468 | /** |
| 758 | 469 | * @since 4.0 |
| 759 | 470 | * |
| 760 | 471 | * @param array $field |
| 761 | - * | |
| 762 | 472 | * @return string radio or checkbox |
| 763 | 473 | */ |
| 764 | 474 | private static function get_default_value_type( $field ) { |
| 765 | 475 | $default_type = $field['type']; |
| 766 | - | |
| 767 | 476 | if ( $field['type'] === 'select' ) { |
| 768 | 477 | $default_type = FrmField::is_multiple_select( $field ) ? 'checkbox' : 'radio'; |
| 769 | 478 | } |
| 770 | 479 | return $default_type; |
| @@ -769,15 +478,8 @@ | ||
| 769 | 478 | } |
| 770 | 479 | return $default_type; |
| 771 | 480 | } |
| 772 | 481 | |
| 773 | - /** | |
| 774 | - * @param array|string $opt | |
| 775 | - * @param int|string $opt_key | |
| 776 | - * @param array $field | |
| 777 | - * | |
| 778 | - * @return mixed | |
| 779 | - */ | |
| 780 | 482 | public static function get_value_from_array( $opt, $opt_key, $field ) { |
| 781 | 483 | $opt = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field ); |
| 782 | 484 | |
| 783 | 485 | return FrmFieldsController::check_value( $opt, $opt_key, $field ); |
| @@ -782,15 +484,8 @@ | ||
| 782 | 484 | |
| 783 | 485 | return FrmFieldsController::check_value( $opt, $opt_key, $field ); |
| 784 | 486 | } |
| 785 | 487 | |
| 786 | - /** | |
| 787 | - * @param array|string $opt | |
| 788 | - * @param int|string $opt_key | |
| 789 | - * @param array $field | |
| 790 | - * | |
| 791 | - * @return string | |
| 792 | - */ | |
| 793 | 488 | public static function get_label_from_array( $opt, $opt_key, $field ) { |
| 794 | 489 | $opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field ); |
| 795 | 490 | |
| 796 | 491 | return FrmFieldsController::check_label( $opt ); |
| @@ -796,66 +491,50 @@ | ||
| 796 | 491 | return FrmFieldsController::check_label( $opt ); |
| 797 | 492 | } |
| 798 | 493 | |
| 799 | 494 | /** |
| 800 | - * Shows the inline modal. | |
| 801 | - * | |
| 802 | 495 | * @since 4.0 |
| 803 | - * @since 6.4.1 Added `inside_class` in the arguments. | |
| 804 | - * | |
| 805 | - * @param array $args The arguments. | |
| 806 | - * | |
| 807 | - * @return void | |
| 808 | 496 | */ |
| 809 | 497 | public static function inline_modal( $args ) { |
| 810 | 498 | $defaults = array( |
| 811 | - 'id' => '', | |
| 812 | - 'class' => '', | |
| 813 | - 'show' => 0, | |
| 814 | - 'callback' => array(), | |
| 815 | - 'args' => array(), | |
| 816 | - 'title' => '', | |
| 817 | - 'inside_class' => 'inside', | |
| 818 | - 'dismiss-icon' => true, | |
| 499 | + 'id' => '', | |
| 500 | + 'class' => '', | |
| 501 | + 'show' => 0, | |
| 502 | + 'callback' => array(), | |
| 503 | + 'args' => array(), | |
| 504 | + 'title' => '', | |
| 819 | 505 | ); |
| 820 | - $args = array_merge( $defaults, $args ); | |
| 506 | + $args = array_merge( $defaults, $args ); | |
| 821 | 507 | |
| 822 | - 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' ); | |
| 823 | 509 | } |
| 824 | 510 | |
| 825 | 511 | /** |
| 826 | 512 | * @since 4.0 |
| 827 | - * | |
| 828 | - * @return void | |
| 829 | 513 | */ |
| 830 | 514 | public static function smart_values() { |
| 831 | 515 | $continue = apply_filters( 'frm_smart_values_box', true ); |
| 832 | - | |
| 833 | 516 | if ( $continue === true ) { |
| 834 | 517 | $upgrade_link = array( |
| 835 | 518 | 'medium' => 'builder', |
| 836 | 519 | 'content' => 'smart-tags', |
| 837 | 520 | ); |
| 838 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/smart-values.php'; | |
| 521 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/smart-values.php' ); | |
| 839 | 522 | } |
| 840 | 523 | } |
| 841 | 524 | |
| 842 | 525 | /** |
| 843 | 526 | * @since 4.0 |
| 844 | - * | |
| 845 | - * @return void | |
| 846 | 527 | */ |
| 847 | 528 | public static function input_mask() { |
| 848 | - 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' ); | |
| 849 | 530 | } |
| 850 | 531 | |
| 851 | 532 | /** |
| 852 | 533 | * @since 4.0 |
| 853 | - * | |
| 854 | - * @return void | |
| 855 | 534 | */ |
| 856 | 535 | public static function layout_classes() { |
| 857 | - 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' ); | |
| 858 | 537 | } |
| 859 | 538 | |
| 860 | 539 | /** |
| 861 | 540 | * @param int $tax_id |
| @@ -863,9 +542,8 @@ | ||
| 863 | 542 | * @return string |
| 864 | 543 | */ |
| 865 | 544 | public static function get_term_link( $tax_id ) { |
| 866 | 545 | $tax = get_taxonomy( $tax_id ); |
| 867 | - | |
| 868 | 546 | if ( ! $tax ) { |
| 869 | 547 | return ''; |
| 870 | 548 | } |
| 871 | 549 | |
| @@ -881,18 +559,11 @@ | ||
| 881 | 559 | |
| 882 | 560 | return $link; |
| 883 | 561 | } |
| 884 | 562 | |
| 885 | - /** | |
| 886 | - * @param array|string $observed_value | |
| 887 | - * @param string $cond | |
| 888 | - * @param array|string $hide_opt | |
| 889 | - * | |
| 890 | - * @return bool | |
| 891 | - */ | |
| 892 | 563 | public static function value_meets_condition( $observed_value, $cond, $hide_opt ) { |
| 893 | - $hide_opt = self::get_value_for_comparison( $hide_opt ); | |
| 894 | - $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 ); | |
| 895 | 566 | |
| 896 | 567 | if ( is_array( $observed_value ) ) { |
| 897 | 568 | return self::array_value_condition( $observed_value, $cond, $hide_opt ); |
| 898 | 569 | } |
| @@ -897,40 +568,28 @@ | ||
| 897 | 568 | return self::array_value_condition( $observed_value, $cond, $hide_opt ); |
| 898 | 569 | } |
| 899 | 570 | |
| 900 | 571 | $m = false; |
| 901 | - | |
| 902 | - if ( $cond === '==' ) { | |
| 572 | + if ( $cond == '==' ) { | |
| 903 | 573 | $m = $observed_value == $hide_opt; |
| 904 | - } elseif ( $cond === '!=' ) { | |
| 574 | + } elseif ( $cond == '!=' ) { | |
| 905 | 575 | $m = $observed_value != $hide_opt; |
| 906 | - } elseif ( $cond === '>' ) { | |
| 576 | + } elseif ( $cond == '>' ) { | |
| 907 | 577 | $m = $observed_value > $hide_opt; |
| 908 | - } elseif ( $cond === '>=' ) { | |
| 578 | + } elseif ( $cond == '>=' ) { | |
| 909 | 579 | $m = $observed_value >= $hide_opt; |
| 910 | - } elseif ( $cond === '<' ) { | |
| 580 | + } elseif ( $cond == '<' ) { | |
| 911 | 581 | $m = $observed_value < $hide_opt; |
| 912 | - } elseif ( $cond === '<=' ) { | |
| 582 | + } elseif ( $cond == '<=' ) { | |
| 913 | 583 | $m = $observed_value <= $hide_opt; |
| 914 | - } elseif ( $cond === 'LIKE' || $cond === 'not LIKE' ) { | |
| 584 | + } elseif ( $cond == 'LIKE' || $cond == 'not LIKE' ) { | |
| 915 | 585 | $m = stripos( $observed_value, $hide_opt ); |
| 916 | - | |
| 917 | - if ( $cond === 'not LIKE' ) { | |
| 918 | - $m = $m === false; | |
| 586 | + if ( $cond == 'not LIKE' ) { | |
| 587 | + $m = ( $m === false ) ? true : false; | |
| 919 | 588 | } else { |
| 920 | - $m = $m !== false; | |
| 589 | + $m = ( $m === false ) ? false : true; | |
| 921 | 590 | } |
| 922 | - } elseif ( $cond === '%LIKE' ) { | |
| 923 | - // ends with | |
| 924 | - $length = strlen( $hide_opt ); | |
| 925 | - $substr = substr( $observed_value, strlen( $observed_value ) - $length ); | |
| 926 | - $m = 0 === strcasecmp( $substr, $hide_opt ); | |
| 927 | - } elseif ( 'LIKE%' === $cond ) { | |
| 928 | - // starts with | |
| 929 | - $length = strlen( $hide_opt ); | |
| 930 | - $substr = substr( $observed_value, 0, $length ); | |
| 931 | - $m = 0 === strcasecmp( $substr, $hide_opt ); | |
| 932 | - }//end if | |
| 591 | + } | |
| 933 | 592 | |
| 934 | 593 | return $m; |
| 935 | 594 | } |
| 936 | 595 | |
| @@ -937,14 +596,10 @@ | ||
| 937 | 596 | /** |
| 938 | 597 | * Trim and sanitize the values |
| 939 | 598 | * |
| 940 | 599 | * @since 2.05 |
| 941 | - * | |
| 942 | - * @param array|string $value | |
| 943 | - * | |
| 944 | - * @return array|string | |
| 945 | 600 | */ |
| 946 | - private static function get_value_for_comparison( $value ) { | |
| 601 | + private static function get_value_for_comparision( $value ) { | |
| 947 | 602 | // Remove white space from hide_opt |
| 948 | 603 | if ( ! is_array( $value ) ) { |
| 949 | 604 | $value = trim( $value ); |
| 950 | 605 | } |
| @@ -953,37 +608,28 @@ | ||
| 953 | 608 | |
| 954 | 609 | return $value; |
| 955 | 610 | } |
| 956 | 611 | |
| 957 | - /** | |
| 958 | - * @param array $observed_value | |
| 959 | - * @param string $cond | |
| 960 | - * @param array|string $hide_opt | |
| 961 | - * | |
| 962 | - * @return bool | |
| 963 | - */ | |
| 964 | 612 | public static function array_value_condition( $observed_value, $cond, $hide_opt ) { |
| 965 | 613 | $m = false; |
| 966 | - | |
| 967 | - if ( $cond === '==' ) { | |
| 614 | + if ( $cond == '==' ) { | |
| 968 | 615 | if ( is_array( $hide_opt ) ) { |
| 969 | 616 | $m = array_intersect( $hide_opt, $observed_value ); |
| 970 | - $m = ! empty( $m ); | |
| 617 | + $m = empty( $m ) ? false : true; | |
| 971 | 618 | } else { |
| 972 | 619 | $m = in_array( $hide_opt, $observed_value ); |
| 973 | 620 | } |
| 974 | - } elseif ( $cond === '!=' ) { | |
| 621 | + } elseif ( $cond == '!=' ) { | |
| 975 | 622 | $m = ! in_array( $hide_opt, $observed_value ); |
| 976 | - } elseif ( $cond === '>' ) { | |
| 623 | + } elseif ( $cond == '>' ) { | |
| 977 | 624 | $min = min( $observed_value ); |
| 978 | 625 | $m = $min > $hide_opt; |
| 979 | - } elseif ( $cond === '<' ) { | |
| 626 | + } elseif ( $cond == '<' ) { | |
| 980 | 627 | $max = max( $observed_value ); |
| 981 | 628 | $m = $max < $hide_opt; |
| 982 | - } elseif ( $cond === 'LIKE' || $cond === 'not LIKE' ) { | |
| 629 | + } elseif ( $cond == 'LIKE' || $cond == 'not LIKE' ) { | |
| 983 | 630 | foreach ( $observed_value as $ob ) { |
| 984 | 631 | $m = strpos( $ob, $hide_opt ); |
| 985 | - | |
| 986 | 632 | if ( $m !== false ) { |
| 987 | 633 | $m = true; |
| 988 | 634 | break; |
| 989 | 635 | } |
| @@ -988,28 +634,12 @@ | ||
| 988 | 634 | break; |
| 989 | 635 | } |
| 990 | 636 | } |
| 991 | 637 | |
| 992 | - if ( $cond === 'not LIKE' ) { | |
| 993 | - $m = $m === false; | |
| 638 | + if ( $cond == 'not LIKE' ) { | |
| 639 | + $m = ( $m === false ) ? true : false; | |
| 994 | 640 | } |
| 995 | - } elseif ( $cond === '%LIKE' ) { | |
| 996 | - // ends with | |
| 997 | - foreach ( $observed_value as $ob ) { | |
| 998 | - if ( $hide_opt === substr( $ob, strlen( $ob ) - strlen( $hide_opt ) ) ) { | |
| 999 | - $m = true; | |
| 1000 | - break; | |
| 1001 | - } | |
| 1002 | - } | |
| 1003 | - } elseif ( $cond === 'LIKE%' ) { | |
| 1004 | - // starts with | |
| 1005 | - foreach ( $observed_value as $ob ) { | |
| 1006 | - if ( $hide_opt === substr( $ob, 0, strlen( $hide_opt ) ) ) { | |
| 1007 | - $m = true; | |
| 1008 | - break; | |
| 1009 | - } | |
| 1010 | - } | |
| 1011 | - }//end if | |
| 641 | + } | |
| 1012 | 642 | |
| 1013 | 643 | return $m; |
| 1014 | 644 | } |
| 1015 | 645 | |
| @@ -1016,13 +646,8 @@ | ||
| 1016 | 646 | /** |
| 1017 | 647 | * Replace a few basic shortcodes and field ids |
| 1018 | 648 | * |
| 1019 | 649 | * @since 2.0 |
| 1020 | - * | |
| 1021 | - * @param string $value | |
| 1022 | - * @param object $form | |
| 1023 | - * @param object $entry | |
| 1024 | - * | |
| 1025 | 650 | * @return string |
| 1026 | 651 | */ |
| 1027 | 652 | public static function basic_replace_shortcodes( $value, $form, $entry ) { |
| 1028 | 653 | if ( strpos( $value, '[sitename]' ) !== false ) { |
| @@ -1035,14 +660,8 @@ | ||
| 1035 | 660 | |
| 1036 | 661 | return $value; |
| 1037 | 662 | } |
| 1038 | 663 | |
| 1039 | - /** | |
| 1040 | - * @param string $content | |
| 1041 | - * @param int|string $form_id | |
| 1042 | - * | |
| 1043 | - * @return array | |
| 1044 | - */ | |
| 1045 | 664 | public static function get_shortcodes( $content, $form_id ) { |
| 1046 | 665 | if ( FrmAppHelper::pro_is_installed() ) { |
| 1047 | 666 | return FrmProDisplaysHelper::get_shortcodes( $content, $form_id ); |
| 1048 | 667 | } |
| @@ -1060,13 +679,8 @@ | ||
| 1060 | 679 | |
| 1061 | 680 | return $matches; |
| 1062 | 681 | } |
| 1063 | 682 | |
| 1064 | - /** | |
| 1065 | - * @param array $fields | |
| 1066 | - * | |
| 1067 | - * @return string | |
| 1068 | - */ | |
| 1069 | 683 | public static function allowed_shortcodes( $fields = array() ) { |
| 1070 | 684 | $tagregexp = array( |
| 1071 | 685 | 'editlink', |
| 1072 | 686 | 'id', |
| @@ -1074,16 +688,13 @@ | ||
| 1074 | 688 | 'ip', |
| 1075 | 689 | 'siteurl', |
| 1076 | 690 | 'sitename', |
| 1077 | 691 | 'admin_email', |
| 1078 | - 'default-email', | |
| 1079 | - 'default-from-email', | |
| 1080 | 692 | 'post[-|_]id', |
| 1081 | 693 | 'created[-|_]at', |
| 1082 | 694 | 'updated[-|_]at', |
| 1083 | 695 | 'updated[-|_]by', |
| 1084 | 696 | 'parent[-|_]id', |
| 1085 | - 'form_name', | |
| 1086 | 697 | ); |
| 1087 | 698 | |
| 1088 | 699 | foreach ( $fields as $field ) { |
| 1089 | 700 | $tagregexp[] = $field->id; |
| @@ -1094,15 +705,8 @@ | ||
| 1094 | 705 | |
| 1095 | 706 | return $tagregexp; |
| 1096 | 707 | } |
| 1097 | 708 | |
| 1098 | - /** | |
| 1099 | - * @param string $content | |
| 1100 | - * @param false|object $entry | |
| 1101 | - * @param array $shortcodes | |
| 1102 | - * | |
| 1103 | - * @return string | |
| 1104 | - */ | |
| 1105 | 709 | public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
| 1106 | 710 | foreach ( $shortcodes[0] as $short_key => $tag ) { |
| 1107 | 711 | if ( empty( $tag ) ) { |
| 1108 | 712 | continue; |
| @@ -1115,9 +719,8 @@ | ||
| 1115 | 719 | $atts['tag'] = $tag; |
| 1116 | 720 | $replace_with = self::get_value_for_shortcode( $atts ); |
| 1117 | 721 | |
| 1118 | 722 | if ( $replace_with !== null ) { |
| 1119 | - $replace_with = self::trigger_shortcode_atts( $replace_with, $atts ); | |
| 1120 | 723 | self::sanitize_embedded_shortcodes( compact( 'entry' ), $replace_with ); |
| 1121 | 724 | $content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content ); |
| 1122 | 725 | } |
| 1123 | 726 | |
| @@ -1127,78 +730,18 @@ | ||
| 1127 | 730 | return $content; |
| 1128 | 731 | } |
| 1129 | 732 | |
| 1130 | 733 | /** |
| 1131 | - * @param string $replace_with | |
| 1132 | - * @param array $atts | |
| 1133 | - * | |
| 1134 | - * @return string | |
| 1135 | - */ | |
| 1136 | - private static function trigger_shortcode_atts( $replace_with, $atts ) { | |
| 1137 | - $supported_atts = array( 'remove_accents', 'sanitize', 'sanitize_url' ); | |
| 1138 | - $included_atts = array_intersect( $supported_atts, array_keys( $atts ) ); | |
| 1139 | - | |
| 1140 | - foreach ( $included_atts as $included_att ) { | |
| 1141 | - if ( '0' === $atts[ $included_att ] ) { | |
| 1142 | - // Skip any option that uses 0 so sanitize_url=0 does not encode. | |
| 1143 | - continue; | |
| 1144 | - } | |
| 1145 | - | |
| 1146 | - $function = 'atts_' . $included_att; | |
| 1147 | - $replace_with = self::$function( $replace_with, $atts ); | |
| 1148 | - } | |
| 1149 | - return $replace_with; | |
| 1150 | - } | |
| 1151 | - | |
| 1152 | - /** | |
| 1153 | - * Converts all accent characters to ASCII characters. | |
| 1154 | - * | |
| 1155 | - * @since 6.3.1 | |
| 1156 | - * | |
| 1157 | - * @param string $replace_with The text to remove accents from. | |
| 1158 | - * | |
| 1159 | - * @return string | |
| 1160 | - */ | |
| 1161 | - public static function atts_remove_accents( $replace_with ) { | |
| 1162 | - return remove_accents( $replace_with ); | |
| 1163 | - } | |
| 1164 | - | |
| 1165 | - /** | |
| 1166 | - * @param string $replace_with | |
| 1167 | - * | |
| 1168 | - * @return string | |
| 1169 | - */ | |
| 1170 | - private static function atts_sanitize( $replace_with ) { | |
| 1171 | - return sanitize_title_with_dashes( $replace_with ); | |
| 1172 | - } | |
| 1173 | - | |
| 1174 | - /** | |
| 1175 | - * @param string $replace_with | |
| 1176 | - * | |
| 1177 | - * @return string | |
| 1178 | - */ | |
| 1179 | - private static function atts_sanitize_url( $replace_with ) { | |
| 1180 | - return urlencode( $replace_with ); | |
| 1181 | - } | |
| 1182 | - | |
| 1183 | - /** | |
| 1184 | 734 | * Prevent shortcodes in fields from being processed |
| 1185 | 735 | * |
| 1186 | 736 | * @since 3.01.02 |
| 1187 | 737 | * |
| 1188 | - * @param array $atts Includes entry object. | |
| 1189 | - * @param string|null $value | |
| 1190 | - * | |
| 1191 | - * @return void | |
| 738 | + * @param array $atts - includes entry object | |
| 739 | + * @param string $value | |
| 1192 | 740 | */ |
| 1193 | 741 | public static function sanitize_embedded_shortcodes( $atts, &$value ) { |
| 1194 | - if ( is_null( $value ) ) { | |
| 1195 | - return; | |
| 1196 | - } | |
| 1197 | - | |
| 1198 | 742 | $atts['value'] = $value; |
| 1199 | 743 | $should_sanitize = apply_filters( 'frm_sanitize_shortcodes', true, $atts ); |
| 1200 | - | |
| 1201 | 744 | if ( $should_sanitize ) { |
| 1202 | 745 | $value = str_replace( '[', '[', $value ); |
| 1203 | 746 | } |
| 1204 | 747 | } |
| @@ -1205,9 +748,9 @@ | ||
| 1205 | 748 | |
| 1206 | 749 | /** |
| 1207 | 750 | * @since 3.0 |
| 1208 | 751 | * |
| 1209 | - * @param array $atts | |
| 752 | + * @param $atts | |
| 1210 | 753 | * |
| 1211 | 754 | * @return string |
| 1212 | 755 | */ |
| 1213 | 756 | private static function get_value_for_shortcode( $atts ) { |
| @@ -1218,21 +761,21 @@ | ||
| 1218 | 761 | 'key' => $atts['entry']->item_key, |
| 1219 | 762 | 'ip' => $atts['entry']->ip, |
| 1220 | 763 | ); |
| 1221 | 764 | |
| 1222 | - $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get', 'default-email', 'default-from-email' ); | |
| 765 | + $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get' ); | |
| 1223 | 766 | |
| 1224 | 767 | if ( isset( $shortcode_values[ $atts['tag'] ] ) ) { |
| 1225 | 768 | $replace_with = $shortcode_values[ $atts['tag'] ]; |
| 1226 | - } elseif ( in_array( $atts['tag'], $dynamic_default, true ) ) { | |
| 769 | + } elseif ( in_array( $atts['tag'], $dynamic_default ) ) { | |
| 1227 | 770 | $replace_with = self::dynamic_default_values( $atts['tag'], $atts ); |
| 1228 | - } elseif ( $clean_tag === 'user_agent' ) { | |
| 771 | + } elseif ( $clean_tag == 'user_agent' ) { | |
| 1229 | 772 | $description = $atts['entry']->description; |
| 1230 | 773 | $replace_with = FrmEntriesHelper::get_browser( $description['browser'] ); |
| 1231 | - } elseif ( $clean_tag === 'created_at' || $clean_tag === 'updated_at' ) { | |
| 774 | + } elseif ( $clean_tag == 'created_at' || $clean_tag == 'updated_at' ) { | |
| 1232 | 775 | $atts['tag'] = $clean_tag; |
| 1233 | 776 | $replace_with = self::get_entry_timestamp( $atts ); |
| 1234 | - } elseif ( $clean_tag === 'created_by' || $clean_tag === 'updated_by' ) { | |
| 777 | + } elseif ( $clean_tag == 'created_by' || $clean_tag == 'updated_by' ) { | |
| 1235 | 778 | $replace_with = self::get_display_value( $atts['entry']->{$clean_tag}, (object) array( 'type' => 'user_id' ), $atts ); |
| 1236 | 779 | } else { |
| 1237 | 780 | $replace_with = self::get_field_shortcode_value( $atts ); |
| 1238 | 781 | } |
| @@ -1242,9 +785,9 @@ | ||
| 1242 | 785 | |
| 1243 | 786 | /** |
| 1244 | 787 | * @since 3.0 |
| 1245 | 788 | * |
| 1246 | - * @param array $atts | |
| 789 | + * @param $atts | |
| 1247 | 790 | * |
| 1248 | 791 | * @return string |
| 1249 | 792 | */ |
| 1250 | 793 | private static function get_entry_timestamp( $atts ) { |
| @@ -1260,30 +803,28 @@ | ||
| 1260 | 803 | |
| 1261 | 804 | /** |
| 1262 | 805 | * @since 3.0 |
| 1263 | 806 | * |
| 1264 | - * @param array $atts | |
| 807 | + * @param $atts | |
| 1265 | 808 | * |
| 1266 | - * @return string|null | |
| 809 | + * @return null|string | |
| 1267 | 810 | */ |
| 1268 | 811 | private static function get_field_shortcode_value( $atts ) { |
| 1269 | 812 | $field = FrmField::getOne( $atts['tag'] ); |
| 1270 | - | |
| 1271 | 813 | if ( empty( $field ) ) { |
| 1272 | 814 | return null; |
| 1273 | 815 | } |
| 1274 | 816 | |
| 1275 | - if ( isset( $atts['show'] ) && $atts['show'] === 'field_label' ) { | |
| 817 | + if ( isset( $atts['show'] ) && $atts['show'] == 'field_label' ) { | |
| 1276 | 818 | $replace_with = $field->name; |
| 1277 | - } elseif ( isset( $atts['show'] ) && $atts['show'] === 'description' ) { | |
| 819 | + } elseif ( isset( $atts['show'] ) && $atts['show'] == 'description' ) { | |
| 1278 | 820 | $replace_with = $field->description; |
| 1279 | 821 | } else { |
| 1280 | 822 | $replace_with = FrmEntryMeta::get_meta_value( $atts['entry'], $field->id ); |
| 1281 | 823 | $string_value = $replace_with; |
| 1282 | - | |
| 1283 | 824 | if ( is_array( $replace_with ) ) { |
| 1284 | - $sep = $atts['sep'] ?? ', '; | |
| 1285 | - $string_value = FrmAppHelper::safe_implode( $sep, $replace_with ); | |
| 825 | + $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', '; | |
| 826 | + $string_value = implode( $sep, $replace_with ); | |
| 1286 | 827 | } |
| 1287 | 828 | |
| 1288 | 829 | if ( empty( $string_value ) && $string_value != '0' ) { |
| 1289 | 830 | $replace_with = ''; |
| @@ -1291,9 +832,9 @@ | ||
| 1291 | 832 | $atts['entry_id'] = $atts['entry']->id; |
| 1292 | 833 | $atts['entry_key'] = $atts['entry']->item_key; |
| 1293 | 834 | $replace_with = self::get_display_value( $replace_with, $field, $atts ); |
| 1294 | 835 | } |
| 1295 | - }//end if | |
| 836 | + } | |
| 1296 | 837 | |
| 1297 | 838 | return $replace_with; |
| 1298 | 839 | } |
| 1299 | 840 | |
| @@ -1300,13 +841,8 @@ | ||
| 1300 | 841 | /** |
| 1301 | 842 | * Get the value to replace a few standard shortcodes |
| 1302 | 843 | * |
| 1303 | 844 | * @since 2.0 |
| 1304 | - * | |
| 1305 | - * @param string $tag | |
| 1306 | - * @param array $atts | |
| 1307 | - * @param bool $return_array | |
| 1308 | - * | |
| 1309 | 845 | * @return string |
| 1310 | 846 | */ |
| 1311 | 847 | public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) { |
| 1312 | 848 | $new_value = ''; |
| @@ -1313,16 +849,8 @@ | ||
| 1313 | 849 | switch ( $tag ) { |
| 1314 | 850 | case 'admin_email': |
| 1315 | 851 | $new_value = get_option( 'admin_email' ); |
| 1316 | 852 | break; |
| 1317 | - case 'default-email': | |
| 1318 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 1319 | - $new_value = ! empty( $frm_settings->default_email ) && is_email( $frm_settings->default_email ) ? $frm_settings->default_email : get_option( 'admin_email' ); | |
| 1320 | - break; | |
| 1321 | - case 'default-from-email': | |
| 1322 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 1323 | - $new_value = ! empty( $frm_settings->from_email ) && is_email( $frm_settings->from_email ) ? $frm_settings->from_email : get_option( 'admin_email' ); | |
| 1324 | - break; | |
| 1325 | 853 | case 'siteurl': |
| 1326 | 854 | $new_value = FrmAppHelper::site_url(); |
| 1327 | 855 | break; |
| 1328 | 856 | case 'frmurl': |
| @@ -1332,9 +860,9 @@ | ||
| 1332 | 860 | $new_value = FrmAppHelper::site_name(); |
| 1333 | 861 | break; |
| 1334 | 862 | case 'get': |
| 1335 | 863 | $new_value = self::process_get_shortcode( $atts, $return_array ); |
| 1336 | - }//end switch | |
| 864 | + } | |
| 1337 | 865 | |
| 1338 | 866 | return $new_value; |
| 1339 | 867 | } |
| 1340 | 868 | |
| @@ -1341,13 +869,9 @@ | ||
| 1341 | 869 | /** |
| 1342 | 870 | * Process the [get] shortcode |
| 1343 | 871 | * |
| 1344 | 872 | * @since 2.0 |
| 1345 | - * | |
| 1346 | - * @param array $atts | |
| 1347 | - * @param bool $return_array | |
| 1348 | - * | |
| 1349 | - * @return array|string | |
| 873 | + * @return string|array | |
| 1350 | 874 | */ |
| 1351 | 875 | public static function process_get_shortcode( $atts, $return_array = false ) { |
| 1352 | 876 | if ( ! isset( $atts['param'] ) ) { |
| 1353 | 877 | return ''; |
| @@ -1365,9 +889,9 @@ | ||
| 1365 | 889 | if ( ! isset( $atts['prev_val'] ) ) { |
| 1366 | 890 | $atts['prev_val'] = ''; |
| 1367 | 891 | } |
| 1368 | 892 | |
| 1369 | - $new_value = $atts['default'] ?? $atts['prev_val']; | |
| 893 | + $new_value = isset( $atts['default'] ) ? $atts['default'] : $atts['prev_val']; | |
| 1370 | 894 | } |
| 1371 | 895 | |
| 1372 | 896 | if ( is_array( $new_value ) && ! $return_array ) { |
| 1373 | 897 | $new_value = implode( ', ', $new_value ); |
| @@ -1375,15 +899,8 @@ | ||
| 1375 | 899 | |
| 1376 | 900 | return $new_value; |
| 1377 | 901 | } |
| 1378 | 902 | |
| 1379 | - /** | |
| 1380 | - * @param mixed $value | |
| 1381 | - * @param object $field | |
| 1382 | - * @param array $atts | |
| 1383 | - * | |
| 1384 | - * @return mixed | |
| 1385 | - */ | |
| 1386 | 903 | public static function get_display_value( $value, $field, $atts = array() ) { |
| 1387 | 904 | |
| 1388 | 905 | $value = apply_filters( 'frm_get_' . $field->type . '_display_value', $value, $field, $atts ); |
| 1389 | 906 | $value = apply_filters( 'frm_get_display_value', $value, $field, $atts ); |
| @@ -1393,16 +910,14 @@ | ||
| 1393 | 910 | return apply_filters( 'frm_display_value', $value, $field, $atts ); |
| 1394 | 911 | } |
| 1395 | 912 | |
| 1396 | 913 | /** |
| 1397 | - * @param array $atts Includes value, field, and atts. | |
| 1398 | - * | |
| 1399 | - * @return mixed | |
| 914 | + * @param $atts array Includes value, field, and atts | |
| 1400 | 915 | */ |
| 1401 | 916 | public static function get_unfiltered_display_value( $atts ) { |
| 1402 | 917 | $value = $atts['value']; |
| 1403 | 918 | $field = $atts['field']; |
| 1404 | - $atts = $atts['atts'] ?? $atts; | |
| 919 | + $atts = isset( $atts['atts'] ) ? $atts['atts'] : $atts; | |
| 1405 | 920 | |
| 1406 | 921 | if ( is_array( $field ) ) { |
| 1407 | 922 | $field = $field['id']; |
| 1408 | 923 | } |
| @@ -1415,14 +930,8 @@ | ||
| 1415 | 930 | /** |
| 1416 | 931 | * Get a value from the user profile from the user ID |
| 1417 | 932 | * |
| 1418 | 933 | * @since 3.0 |
| 1419 | - * | |
| 1420 | - * @param int|string $user_id | |
| 1421 | - * @param string $user_info | |
| 1422 | - * @param array $args | |
| 1423 | - * | |
| 1424 | - * @return string | |
| 1425 | 934 | */ |
| 1426 | 935 | public static function get_user_display_name( $user_id, $user_info = 'display_name', $args = array() ) { |
| 1427 | 936 | $defaults = array( |
| 1428 | 937 | 'blank' => false, |
| @@ -1435,14 +944,14 @@ | ||
| 1435 | 944 | $user = get_userdata( $user_id ); |
| 1436 | 945 | $info = ''; |
| 1437 | 946 | |
| 1438 | 947 | if ( $user ) { |
| 1439 | - if ( $user_info === 'avatar' ) { | |
| 948 | + if ( $user_info == 'avatar' ) { | |
| 1440 | 949 | $info = get_avatar( $user_id, $args['size'] ); |
| 1441 | - } elseif ( $user_info === 'author_link' ) { | |
| 950 | + } elseif ( $user_info == 'author_link' ) { | |
| 1442 | 951 | $info = get_author_posts_url( $user_id ); |
| 1443 | 952 | } else { |
| 1444 | - $info = $user->$user_info ?? ''; | |
| 953 | + $info = isset( $user->$user_info ) ? $user->$user_info : ''; | |
| 1445 | 954 | } |
| 1446 | 955 | |
| 1447 | 956 | if ( 'display_name' === $user_info && empty( $info ) && ! $args['blank'] ) { |
| 1448 | 957 | $info = $user->user_login; |
| @@ -1455,28 +964,24 @@ | ||
| 1455 | 964 | |
| 1456 | 965 | return $info; |
| 1457 | 966 | } |
| 1458 | 967 | |
| 1459 | - /** | |
| 1460 | - * @param string $type | |
| 1461 | - * | |
| 1462 | - * @return array | |
| 1463 | - */ | |
| 1464 | 968 | public static function get_field_types( $type ) { |
| 1465 | - $single_input = self::single_input_fields(); | |
| 1466 | - $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' ); | |
| 969 | + $single_input = self::single_input_fields(); | |
| 970 | + $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' ); | |
| 971 | + | |
| 1467 | 972 | $field_selection = FrmField::all_field_selection(); |
| 1468 | - $field_types = array(); | |
| 1469 | 973 | |
| 1470 | - if ( in_array( $type, $single_input, true ) ) { | |
| 974 | + $field_types = array(); | |
| 975 | + if ( in_array( $type, $single_input ) ) { | |
| 1471 | 976 | self::field_types_for_input( $single_input, $field_selection, $field_types ); |
| 1472 | - } elseif ( in_array( $type, $multiple_input, true ) ) { | |
| 977 | + } elseif ( in_array( $type, $multiple_input ) ) { | |
| 1473 | 978 | self::field_types_for_input( $multiple_input, $field_selection, $field_types ); |
| 1474 | 979 | } elseif ( isset( $field_selection[ $type ] ) ) { |
| 1475 | 980 | $field_types[ $type ] = $field_selection[ $type ]; |
| 1476 | 981 | } |
| 1477 | 982 | |
| 1478 | - $field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type', 'field_selection' ) ); | |
| 983 | + $field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type' ) ); | |
| 1479 | 984 | |
| 1480 | 985 | return $field_types; |
| 1481 | 986 | } |
| 1482 | 987 | |
| @@ -1483,10 +988,8 @@ | ||
| 1483 | 988 | /** |
| 1484 | 989 | * Get a list of all fields that use a single value input. |
| 1485 | 990 | * |
| 1486 | 991 | * @since 4.0 |
| 1487 | - * | |
| 1488 | - * @return array | |
| 1489 | 992 | */ |
| 1490 | 993 | public static function single_input_fields() { |
| 1491 | 994 | $fields = array( |
| 1492 | 995 | 'text', |
| @@ -1500,26 +1003,15 @@ | ||
| 1500 | 1003 | 'hidden', |
| 1501 | 1004 | 'time', |
| 1502 | 1005 | 'tag', |
| 1503 | 1006 | 'password', |
| 1504 | - 'gdpr', | |
| 1505 | 1007 | ); |
| 1506 | 1008 | return apply_filters( 'frm_single_input_fields', $fields ); |
| 1507 | 1009 | } |
| 1508 | 1010 | |
| 1509 | - /** | |
| 1510 | - * @param string[] $inputs | |
| 1511 | - * @param array $fields | |
| 1512 | - * @param array $field_types | |
| 1513 | - * | |
| 1514 | - * @return void | |
| 1515 | - */ | |
| 1516 | 1011 | private static function field_types_for_input( $inputs, $fields, &$field_types ) { |
| 1517 | 1012 | foreach ( $inputs as $input ) { |
| 1518 | - // This may not be set if a field type was removed using the frm_available_fields or frm_pro_available_fields filters. | |
| 1519 | - if ( array_key_exists( $input, $fields ) ) { | |
| 1520 | - $field_types[ $input ] = $fields[ $input ]; | |
| 1521 | - } | |
| 1013 | + $field_types[ $input ] = $fields[ $input ]; | |
| 1522 | 1014 | unset( $input ); |
| 1523 | 1015 | } |
| 1524 | 1016 | } |
| 1525 | 1017 | |
| @@ -1529,9 +1021,9 @@ | ||
| 1529 | 1021 | * @since 2.0.6 |
| 1530 | 1022 | * |
| 1531 | 1023 | * @param string $opt_key |
| 1532 | 1024 | * |
| 1533 | - * @return bool Returns true if current field option is an "Other" option | |
| 1025 | + * @return boolean Returns true if current field option is an "Other" option | |
| 1534 | 1026 | */ |
| 1535 | 1027 | public static function is_other_opt( $opt_key ) { |
| 1536 | 1028 | return $opt_key && strpos( $opt_key, 'other_' ) === 0; |
| 1537 | 1029 | } |
| @@ -1541,10 +1033,8 @@ | ||
| 1541 | 1033 | * |
| 1542 | 1034 | * @since 2.0.6 |
| 1543 | 1035 | * |
| 1544 | 1036 | * @param array $args |
| 1545 | - * | |
| 1546 | - * @return string | |
| 1547 | 1037 | */ |
| 1548 | 1038 | public static function get_other_val( $args ) { |
| 1549 | 1039 | $defaults = array( |
| 1550 | 1040 | 'opt_key' => 0, |
| @@ -1567,34 +1057,31 @@ | ||
| 1567 | 1057 | } |
| 1568 | 1058 | |
| 1569 | 1059 | // Check posted vals before checking saved values |
| 1570 | 1060 | // For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero |
| 1571 | - if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 1061 | + if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) { | |
| 1572 | 1062 | if ( FrmField::is_field_with_multiple_values( $field ) ) { |
| 1573 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 1574 | 1063 | $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 ] ) ) : ''; |
| 1575 | 1064 | } else { |
| 1576 | - $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 1065 | + $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ); | |
| 1577 | 1066 | } |
| 1578 | 1067 | |
| 1579 | 1068 | return $other_val; |
| 1580 | - } | |
| 1581 | 1069 | |
| 1582 | - if ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 1070 | + } elseif ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) { | |
| 1583 | 1071 | // For normal fields |
| 1584 | 1072 | |
| 1585 | 1073 | if ( FrmField::is_field_with_multiple_values( $field ) ) { |
| 1586 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 1587 | 1074 | $other_val = isset( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ) : ''; |
| 1588 | 1075 | } else { |
| 1589 | - $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 1076 | + $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ] ) ); | |
| 1590 | 1077 | } |
| 1591 | 1078 | |
| 1592 | 1079 | return $other_val; |
| 1593 | - }//end if | |
| 1080 | + } | |
| 1594 | 1081 | |
| 1595 | 1082 | // For checkboxes |
| 1596 | - if ( $field['type'] === 'checkbox' && is_array( $field['value'] ) ) { | |
| 1083 | + if ( $field['type'] == 'checkbox' && is_array( $field['value'] ) ) { | |
| 1597 | 1084 | // Check if there is an "other" val in saved value and make sure the |
| 1598 | 1085 | // "other" val is not equal to the Other checkbox option |
| 1599 | 1086 | if ( isset( $field['value'][ $opt_key ] ) && $field['options'][ $opt_key ] != $field['value'][ $opt_key ] ) { |
| 1600 | 1087 | $other_val = $field['value'][ $opt_key ]; |
| @@ -1603,15 +1090,13 @@ | ||
| 1603 | 1090 | /** |
| 1604 | 1091 | * For radio buttons and dropdowns |
| 1605 | 1092 | * Check if saved value equals any of the options. If not, set it as the other value. |
| 1606 | 1093 | */ |
| 1607 | - foreach ( $field['options'] as $opt_val ) { | |
| 1094 | + foreach ( $field['options'] as $opt_key => $opt_val ) { | |
| 1608 | 1095 | $temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val; |
| 1609 | - | |
| 1610 | 1096 | // Multi-select dropdowns - key is not preserved |
| 1611 | 1097 | if ( is_array( $field['value'] ) ) { |
| 1612 | 1098 | $o_key = array_search( $temp_val, $field['value'] ); |
| 1613 | - | |
| 1614 | 1099 | if ( isset( $field['value'][ $o_key ] ) ) { |
| 1615 | 1100 | unset( $field['value'][ $o_key ], $o_key ); |
| 1616 | 1101 | } |
| 1617 | 1102 | } elseif ( $temp_val == $field['value'] ) { |
| @@ -1619,16 +1104,15 @@ | ||
| 1619 | 1104 | return ''; |
| 1620 | 1105 | } else { |
| 1621 | 1106 | $other_val = $field['value']; |
| 1622 | 1107 | } |
| 1623 | - unset( $opt_val, $temp_val ); | |
| 1108 | + unset( $opt_key, $opt_val, $temp_val ); | |
| 1624 | 1109 | } |
| 1625 | - | |
| 1626 | 1110 | // For multi-select dropdowns only |
| 1627 | 1111 | if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) { |
| 1628 | 1112 | $other_val = reset( $field['value'] ); |
| 1629 | 1113 | } |
| 1630 | - }//end if | |
| 1114 | + } | |
| 1631 | 1115 | |
| 1632 | 1116 | return $other_val; |
| 1633 | 1117 | } |
| 1634 | 1118 | |
| @@ -1637,10 +1121,10 @@ | ||
| 1637 | 1121 | * Intended for front-end use |
| 1638 | 1122 | * |
| 1639 | 1123 | * @since 2.0.6 |
| 1640 | 1124 | * |
| 1641 | - * @param array $args Should include field, opt_key and field name. | |
| 1642 | - * @param bool $other_opt | |
| 1125 | + * @param array $args should include field, opt_key and field name | |
| 1126 | + * @param boolean $other_opt | |
| 1643 | 1127 | * @param string $checked |
| 1644 | 1128 | * |
| 1645 | 1129 | * @return array $other_args |
| 1646 | 1130 | */ |
| @@ -1649,14 +1133,14 @@ | ||
| 1649 | 1133 | 'name' => '', |
| 1650 | 1134 | 'value' => '', |
| 1651 | 1135 | ); |
| 1652 | 1136 | |
| 1653 | - // Check if this is an "Other" option. | |
| 1137 | + //Check if this is an "Other" option | |
| 1654 | 1138 | if ( ! self::is_other_opt( $args['opt_key'] ) ) { |
| 1655 | 1139 | return $other_args; |
| 1656 | 1140 | } |
| 1657 | 1141 | |
| 1658 | - $other_opt = true; | |
| 1142 | + $other_opt = true; | |
| 1659 | 1143 | |
| 1660 | 1144 | self::set_other_name( $args, $other_args ); |
| 1661 | 1145 | self::set_other_value( $args, $other_args ); |
| 1662 | 1146 | |
| @@ -1663,37 +1147,25 @@ | ||
| 1663 | 1147 | if ( '' !== $other_args['value'] ) { |
| 1664 | 1148 | $checked = 'checked="checked" '; |
| 1665 | 1149 | } |
| 1666 | 1150 | |
| 1667 | - // If 'other' is selected as one of the default values for a checkbox field, 'checked' attribute should be on. | |
| 1668 | - if ( ! $checked && | |
| 1669 | - $args['field']['type'] === 'checkbox' && | |
| 1670 | - is_array( $args['field']['value'] ) && | |
| 1671 | - isset( $args['field_val'] ) && | |
| 1672 | - in_array( $args['field_val'], $args['field']['value'], true ) | |
| 1673 | - ) { | |
| 1674 | - $checked = 'checked="checked" '; | |
| 1675 | - } | |
| 1676 | - | |
| 1677 | 1151 | return $other_args; |
| 1678 | 1152 | } |
| 1679 | 1153 | |
| 1680 | 1154 | /** |
| 1681 | - * @since 2.0.6 | |
| 1682 | - * | |
| 1683 | 1155 | * @param array $args |
| 1684 | 1156 | * @param array $other_args |
| 1685 | 1157 | * |
| 1686 | - * @return void | |
| 1158 | + * @since 2.0.6 | |
| 1687 | 1159 | */ |
| 1688 | 1160 | private static function set_other_name( $args, &$other_args ) { |
| 1689 | - // Set up name for other field | |
| 1161 | + //Set up name for other field | |
| 1690 | 1162 | $other_args['name'] = str_replace( '[]', '', $args['field_name'] ); |
| 1691 | 1163 | $other_args['name'] = preg_replace( '/\[' . $args['field']['id'] . '\]$/', '', $other_args['name'] ); |
| 1692 | 1164 | $other_args['name'] = $other_args['name'] . '[other][' . $args['field']['id'] . ']'; |
| 1693 | 1165 | |
| 1694 | - // Converts item_meta[field_id] => item_meta[other][field_id] and | |
| 1695 | - // item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id] | |
| 1166 | + //Converts item_meta[field_id] => item_meta[other][field_id] and | |
| 1167 | + //item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id] | |
| 1696 | 1168 | if ( FrmField::is_field_with_multiple_values( $args['field'] ) ) { |
| 1697 | 1169 | $other_args['name'] .= '[' . $args['opt_key'] . ']'; |
| 1698 | 1170 | } |
| 1699 | 1171 | } |
| @@ -1700,14 +1172,12 @@ | ||
| 1700 | 1172 | |
| 1701 | 1173 | /** |
| 1702 | 1174 | * Find the parent and pointer, and get text for "other" text field |
| 1703 | 1175 | * |
| 1704 | - * @since 2.0.6 | |
| 1705 | - * | |
| 1706 | 1176 | * @param array $args |
| 1707 | 1177 | * @param array $other_args |
| 1708 | 1178 | * |
| 1709 | - * @return void | |
| 1179 | + * @since 2.0.6 | |
| 1710 | 1180 | */ |
| 1711 | 1181 | private static function set_other_value( $args, &$other_args ) { |
| 1712 | 1182 | $parent = ''; |
| 1713 | 1183 | $pointer = ''; |
| @@ -1734,13 +1204,11 @@ | ||
| 1734 | 1204 | |
| 1735 | 1205 | /** |
| 1736 | 1206 | * If this field includes an other option, show it |
| 1737 | 1207 | * |
| 1208 | + * @param $args array | |
| 1209 | + * | |
| 1738 | 1210 | * @since 2.0.6 |
| 1739 | - * | |
| 1740 | - * @param array $args | |
| 1741 | - * | |
| 1742 | - * @return void | |
| 1743 | 1211 | */ |
| 1744 | 1212 | public static function include_other_input( $args ) { |
| 1745 | 1213 | if ( ! $args['other_opt'] ) { |
| 1746 | 1214 | return; |
| @@ -1746,15 +1214,13 @@ | ||
| 1746 | 1214 | return; |
| 1747 | 1215 | } |
| 1748 | 1216 | |
| 1749 | 1217 | $classes = array( 'frm_other_input' ); |
| 1750 | - | |
| 1751 | - if ( ! $args['checked'] || trim( $args['checked'] ) === '' ) { | |
| 1218 | + if ( ! $args['checked'] || trim( $args['checked'] ) == '' ) { | |
| 1752 | 1219 | // hide the field if the other option is not selected |
| 1753 | 1220 | $classes[] = 'frm_pos_none'; |
| 1754 | 1221 | } |
| 1755 | - | |
| 1756 | - if ( $args['field']['type'] === 'select' && ! empty( $args['field']['multiple'] ) ) { | |
| 1222 | + if ( $args['field']['type'] == 'select' && $args['field']['multiple'] ) { | |
| 1757 | 1223 | $classes[] = 'frm_other_full'; |
| 1758 | 1224 | } |
| 1759 | 1225 | |
| 1760 | 1226 | // Set up HTML ID for Other field |
| @@ -1759,9 +1225,9 @@ | ||
| 1759 | 1225 | |
| 1760 | 1226 | // Set up HTML ID for Other field |
| 1761 | 1227 | $other_id = self::get_other_field_html_id( $args['field']['type'], $args['html_id'], $args['opt_key'] ); |
| 1762 | 1228 | |
| 1763 | - $label = $args['opt_label'] ?? $args['field']['name']; | |
| 1229 | + $label = isset( $args['opt_label'] ) ? $args['opt_label'] : $args['field']['name']; | |
| 1764 | 1230 | |
| 1765 | 1231 | echo '<label for="' . esc_attr( $other_id ) . '" class="frm_screen_reader frm_hidden">' . |
| 1766 | 1232 | esc_html( $label ) . |
| 1767 | 1233 | '</label>' . |
| @@ -1775,11 +1241,11 @@ | ||
| 1775 | 1241 | * Note: This does not affect fields in repeating sections |
| 1776 | 1242 | * |
| 1777 | 1243 | * @since 2.0.08 |
| 1778 | 1244 | * |
| 1779 | - * @param string $type Field type. | |
| 1780 | - * @param string $html_id | |
| 1781 | - * @param bool|string $opt_key | |
| 1245 | + * @param string $type - field type | |
| 1246 | + * @param string $html_id | |
| 1247 | + * @param string|boolean $opt_key | |
| 1782 | 1248 | * |
| 1783 | 1249 | * @return string $other_id |
| 1784 | 1250 | */ |
| 1785 | 1251 | public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) { |
| @@ -1785,9 +1251,9 @@ | ||
| 1785 | 1251 | public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) { |
| 1786 | 1252 | $other_id = $html_id; |
| 1787 | 1253 | |
| 1788 | 1254 | // If hidden radio field, add an opt key of 0 |
| 1789 | - if ( $type === 'radio' && $opt_key === false ) { | |
| 1255 | + if ( $type == 'radio' && $opt_key === false ) { | |
| 1790 | 1256 | $opt_key = 0; |
| 1791 | 1257 | } |
| 1792 | 1258 | |
| 1793 | 1259 | if ( $opt_key !== false ) { |
| @@ -1798,18 +1264,12 @@ | ||
| 1798 | 1264 | |
| 1799 | 1265 | return $other_id; |
| 1800 | 1266 | } |
| 1801 | 1267 | |
| 1802 | - /** | |
| 1803 | - * @param string $val | |
| 1804 | - * | |
| 1805 | - * @return string | |
| 1806 | - */ | |
| 1807 | 1268 | public static function switch_field_ids( $val ) { |
| 1808 | 1269 | global $frm_duplicate_ids; |
| 1809 | 1270 | $replace = array(); |
| 1810 | 1271 | $replace_with = array(); |
| 1811 | - | |
| 1812 | 1272 | foreach ( (array) $frm_duplicate_ids as $old => $new ) { |
| 1813 | 1273 | $replace[] = '[if ' . $old . ']'; |
| 1814 | 1274 | $replace_with[] = '[if ' . $new . ']'; |
| 1815 | 1275 | $replace[] = '[if ' . $old . ' '; |
| @@ -1815,41 +1275,22 @@ | ||
| 1815 | 1275 | $replace[] = '[if ' . $old . ' '; |
| 1816 | 1276 | $replace_with[] = '[if ' . $new . ' '; |
| 1817 | 1277 | $replace[] = '[/if ' . $old . ']'; |
| 1818 | 1278 | $replace_with[] = '[/if ' . $new . ']'; |
| 1819 | - $replace[] = '[\/if ' . $old . ']'; | |
| 1820 | - $replace_with[] = '[\/if ' . $new . ']'; | |
| 1821 | 1279 | $replace[] = '[foreach ' . $old . ']'; |
| 1822 | 1280 | $replace_with[] = '[foreach ' . $new . ']'; |
| 1823 | 1281 | $replace[] = '[/foreach ' . $old . ']'; |
| 1824 | 1282 | $replace_with[] = '[/foreach ' . $new . ']'; |
| 1825 | - $replace[] = '[\/foreach ' . $old . ']'; | |
| 1826 | - $replace_with[] = '[\/foreach ' . $new . ']'; | |
| 1827 | 1283 | $replace[] = '[' . $old . ']'; |
| 1828 | 1284 | $replace_with[] = '[' . $new . ']'; |
| 1829 | 1285 | $replace[] = '[' . $old . ' '; |
| 1830 | 1286 | $replace_with[] = '[' . $new . ' '; |
| 1831 | - $replace[] = 'field_id="' . $old . '"'; | |
| 1832 | - $replace_with[] = 'field_id="' . $new . '"'; | |
| 1833 | - $replace[] = 'field_id=\"' . $old . '\"'; | |
| 1834 | - $replace_with[] = 'field_id=\"' . $new . '\"'; | |
| 1835 | - // This covers conditional logic. | |
| 1836 | - $replace[] = '_field":"' . $old . '","'; | |
| 1837 | - $replace_with[] = '_field":"' . $new . '","'; | |
| 1838 | 1287 | unset( $old, $new ); |
| 1839 | - }//end foreach | |
| 1840 | - | |
| 1288 | + } | |
| 1841 | 1289 | if ( is_array( $val ) ) { |
| 1842 | 1290 | foreach ( $val as $k => $v ) { |
| 1843 | - if ( is_string( $v ) ) { | |
| 1844 | - if ( 'custom_html' === $k ) { | |
| 1845 | - $val[ $k ] = self::switch_ids_except_strings( $replace, $replace_with, array( '[if description]', '[description]', '[/if description]' ), $v ); | |
| 1846 | - unset( $k, $v ); | |
| 1847 | - continue; | |
| 1848 | - } | |
| 1849 | - $val[ $k ] = str_replace( $replace, $replace_with, $v ); | |
| 1850 | - unset( $k, $v ); | |
| 1851 | - } | |
| 1291 | + $val[ $k ] = str_replace( $replace, $replace_with, $v ); | |
| 1292 | + unset( $k, $v ); | |
| 1852 | 1293 | } |
| 1853 | 1294 | } else { |
| 1854 | 1295 | $val = str_replace( $replace, $replace_with, $val ); |
| 1855 | 1296 | } |
| @@ -1857,49 +1298,17 @@ | ||
| 1857 | 1298 | return $val; |
| 1858 | 1299 | } |
| 1859 | 1300 | |
| 1860 | 1301 | /** |
| 1861 | - * Removes exception strings from replacement arrays and replaces the rest in the provided value string. | |
| 1862 | - * | |
| 1863 | - * @since 6.14 | |
| 1864 | - * | |
| 1865 | - * @param array $replace Values to be replaced. | |
| 1866 | - * @param array $replace_with Replacement values. | |
| 1867 | - * @param array $exceptions Array of strings to skip. | |
| 1868 | - * @param string $value Value to be updated. | |
| 1869 | - * | |
| 1870 | - * @return string | |
| 1871 | - */ | |
| 1872 | - private static function switch_ids_except_strings( $replace, $replace_with, $exceptions, $value ) { | |
| 1873 | - foreach ( $exceptions as $exception ) { | |
| 1874 | - $index = array_search( $exception, $replace, true ); | |
| 1875 | - | |
| 1876 | - if ( false === $index ) { | |
| 1877 | - continue; | |
| 1878 | - } | |
| 1879 | - unset( $replace[ $index ] ); | |
| 1880 | - unset( $replace_with[ $index ] ); | |
| 1881 | - } | |
| 1882 | - | |
| 1883 | - $value = str_replace( $replace, $replace_with, $value ); | |
| 1884 | - return $value; | |
| 1885 | - } | |
| 1886 | - | |
| 1887 | - /** | |
| 1888 | 1302 | * @since 4.0 |
| 1889 | - * | |
| 1890 | - * @return void | |
| 1891 | 1303 | */ |
| 1892 | 1304 | public static function bulk_options_overlay() { |
| 1893 | 1305 | $prepop = array(); |
| 1894 | - self::get_bulk_prefilled_opts( $prepop, true ); | |
| 1306 | + self::get_bulk_prefilled_opts( $prepop ); | |
| 1895 | 1307 | |
| 1896 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/bulk-options-overlay.php'; | |
| 1308 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/bulk-options-overlay.php' ); | |
| 1897 | 1309 | } |
| 1898 | 1310 | |
| 1899 | - /** | |
| 1900 | - * @return array | |
| 1901 | - */ | |
| 1902 | 1311 | public static function get_us_states() { |
| 1903 | 1312 | $states = array( |
| 1904 | 1313 | 'AL' => 'Alabama', |
| 1905 | 1314 | 'AK' => 'Alaska', |
| @@ -1956,11 +1365,8 @@ | ||
| 1956 | 1365 | |
| 1957 | 1366 | return apply_filters( 'frm_us_states', $states ); |
| 1958 | 1367 | } |
| 1959 | 1368 | |
| 1960 | - /** | |
| 1961 | - * @return array | |
| 1962 | - */ | |
| 1963 | 1369 | public static function get_countries() { |
| 1964 | 1370 | $countries = array( |
| 1965 | 1371 | __( 'Afghanistan', 'formidable' ), |
| 1966 | 1372 | __( 'Aland Islands', 'formidable' ), |
| @@ -2218,52 +1624,22 @@ | ||
| 2218 | 1624 | sort( $countries, SORT_LOCALE_STRING ); |
| 2219 | 1625 | return apply_filters( 'frm_countries', $countries ); |
| 2220 | 1626 | } |
| 2221 | 1627 | |
| 2222 | - /** | |
| 2223 | - * Gets bulk prefilled options. | |
| 2224 | - * | |
| 2225 | - * @since 5.0.04 Add `$include_class` param. | |
| 2226 | - * | |
| 2227 | - * @param array $prepop Bulk options. | |
| 2228 | - * @param array|false $include_class Include the class in the bulk options. | |
| 2229 | - * | |
| 2230 | - * @return void | |
| 2231 | - */ | |
| 2232 | - public static function get_bulk_prefilled_opts( array &$prepop, $include_class = false ) { | |
| 2233 | - // Countries. | |
| 2234 | - $countries = self::get_countries(); | |
| 1628 | + public static function get_bulk_prefilled_opts( array &$prepop ) { | |
| 1629 | + $prepop[ __( 'Countries', 'formidable' ) ] = self::get_countries(); | |
| 2235 | 1630 | |
| 2236 | - if ( $include_class ) { | |
| 2237 | - $countries['class'] = 'frm-countries-opts'; | |
| 2238 | - } | |
| 2239 | - | |
| 2240 | - $prepop[ __( 'Countries', 'formidable' ) ] = $countries; | |
| 2241 | - | |
| 2242 | - // State abv. | |
| 2243 | 1631 | $states = self::get_us_states(); |
| 2244 | 1632 | $state_abv = array_keys( $states ); |
| 2245 | 1633 | sort( $state_abv ); |
| 2246 | - | |
| 2247 | - if ( $include_class ) { | |
| 2248 | - $state_abv['class'] = 'frm-state-abv-opts'; | |
| 2249 | - } | |
| 2250 | - | |
| 2251 | 1634 | $prepop[ __( 'U.S. State Abbreviations', 'formidable' ) ] = $state_abv; |
| 2252 | 1635 | |
| 2253 | - // States. | |
| 2254 | 1636 | $states = array_values( $states ); |
| 2255 | 1637 | sort( $states ); |
| 2256 | - | |
| 2257 | - if ( $include_class ) { | |
| 2258 | - $states['class'] = 'frm-states-opts'; | |
| 2259 | - } | |
| 2260 | - | |
| 2261 | 1638 | $prepop[ __( 'U.S. States', 'formidable' ) ] = $states; |
| 2262 | 1639 | unset( $state_abv, $states ); |
| 2263 | 1640 | |
| 2264 | - // Age. | |
| 2265 | - $ages = array( | |
| 1641 | + $prepop[ __( 'Age', 'formidable' ) ] = array( | |
| 2266 | 1642 | __( 'Under 18', 'formidable' ), |
| 2267 | 1643 | __( '18-24', 'formidable' ), |
| 2268 | 1644 | __( '25-34', 'formidable' ), |
| 2269 | 1645 | __( '35-44', 'formidable' ), |
| @@ -2272,78 +1648,35 @@ | ||
| 2272 | 1648 | __( '65 or Above', 'formidable' ), |
| 2273 | 1649 | __( 'Prefer Not to Answer', 'formidable' ), |
| 2274 | 1650 | ); |
| 2275 | 1651 | |
| 2276 | - if ( $include_class ) { | |
| 2277 | - $ages['class'] = 'frm-age-opts'; | |
| 2278 | - } | |
| 2279 | - | |
| 2280 | - $prepop[ __( 'Age', 'formidable' ) ] = $ages; | |
| 2281 | - | |
| 2282 | - // Satisfaction. | |
| 2283 | - $satisfaction = array( | |
| 1652 | + $prepop[ __( 'Satisfaction', 'formidable' ) ] = array( | |
| 1653 | + __( 'Very Satisfied', 'formidable' ), | |
| 1654 | + __( 'Satisfied', 'formidable' ), | |
| 1655 | + __( 'Neutral', 'formidable' ), | |
| 1656 | + __( 'Unsatisfied', 'formidable' ), | |
| 2284 | 1657 | __( 'Very Unsatisfied', 'formidable' ), |
| 2285 | - __( 'Unsatisfied', 'formidable' ), | |
| 2286 | - __( 'Neutral', 'formidable' ), | |
| 2287 | - __( 'Satisfied', 'formidable' ), | |
| 2288 | - __( 'Very Satisfied', 'formidable' ), | |
| 2289 | 1658 | __( 'N/A', 'formidable' ), |
| 2290 | 1659 | ); |
| 2291 | 1660 | |
| 2292 | - if ( $include_class ) { | |
| 2293 | - $satisfaction['class'] = 'frm-satisfaction-opts'; | |
| 2294 | - } | |
| 2295 | - | |
| 2296 | - $prepop[ __( 'Satisfaction', 'formidable' ) ] = $satisfaction; | |
| 2297 | - | |
| 2298 | - // Importance. | |
| 2299 | - $importance = array( | |
| 1661 | + $prepop[ __( 'Importance', 'formidable' ) ] = array( | |
| 1662 | + __( 'Very Important', 'formidable' ), | |
| 1663 | + __( 'Important', 'formidable' ), | |
| 1664 | + __( 'Neutral', 'formidable' ), | |
| 1665 | + __( 'Somewhat Important', 'formidable' ), | |
| 2300 | 1666 | __( 'Not at all Important', 'formidable' ), |
| 2301 | - __( 'Somewhat Important', 'formidable' ), | |
| 2302 | - __( 'Neutral', 'formidable' ), | |
| 2303 | - __( 'Important', 'formidable' ), | |
| 2304 | - __( 'Very Important', 'formidable' ), | |
| 2305 | 1667 | __( 'N/A', 'formidable' ), |
| 2306 | 1668 | ); |
| 2307 | 1669 | |
| 2308 | - if ( $include_class ) { | |
| 2309 | - $importance['class'] = 'frm-importance-opts'; | |
| 2310 | - } | |
| 2311 | - | |
| 2312 | - $prepop[ __( 'Importance', 'formidable' ) ] = $importance; | |
| 2313 | - | |
| 2314 | - // Agreement. | |
| 2315 | - $agreement = array( | |
| 2316 | - __( 'Strongly Disagree', 'formidable' ), | |
| 2317 | - __( 'Disagree', 'formidable' ), | |
| 2318 | - __( 'Neutral', 'formidable' ), | |
| 1670 | + $prepop[ __( 'Agreement', 'formidable' ) ] = array( | |
| 1671 | + __( 'Strongly Agree', 'formidable' ), | |
| 2319 | 1672 | __( 'Agree', 'formidable' ), |
| 2320 | - __( 'Strongly Agree', 'formidable' ), | |
| 2321 | - __( 'N/A', 'formidable' ), | |
| 2322 | - ); | |
| 2323 | - | |
| 2324 | - if ( $include_class ) { | |
| 2325 | - $agreement['class'] = 'frm-agreement-opts'; | |
| 2326 | - } | |
| 2327 | - | |
| 2328 | - $prepop[ __( 'Agreement', 'formidable' ) ] = $agreement; | |
| 2329 | - | |
| 2330 | - // Likely. | |
| 2331 | - $likely = array( | |
| 2332 | - __( 'Extremely Unlikely', 'formidable' ), | |
| 2333 | - __( 'Unlikely', 'formidable' ), | |
| 2334 | 1673 | __( 'Neutral', 'formidable' ), |
| 2335 | - __( 'Likely', 'formidable' ), | |
| 2336 | - __( 'Extremely Likely', 'formidable' ), | |
| 1674 | + __( 'Disagree', 'formidable' ), | |
| 1675 | + __( 'Strongly Disagree', 'formidable' ), | |
| 2337 | 1676 | __( 'N/A', 'formidable' ), |
| 2338 | 1677 | ); |
| 2339 | 1678 | |
| 2340 | - if ( $include_class ) { | |
| 2341 | - $likely['class'] = 'frm-likely-opts'; | |
| 2342 | - } | |
| 2343 | - | |
| 2344 | - $prepop[ __( 'Likely', 'formidable' ) ] = $likely; | |
| 2345 | - | |
| 2346 | 1679 | $prepop = apply_filters( 'frm_bulk_field_choices', $prepop ); |
| 2347 | 1680 | } |
| 2348 | 1681 | |
| 2349 | 1682 | /** |
| @@ -2350,12 +1683,10 @@ | ||
| 2350 | 1683 | * Display a field value selector |
| 2351 | 1684 | * |
| 2352 | 1685 | * @since 2.03.05 |
| 2353 | 1686 | * |
| 2354 | - * @param int $selector_field_id | |
| 1687 | + * @param int $selector_field_id | |
| 2355 | 1688 | * @param array $selector_args |
| 2356 | - * | |
| 2357 | - * @return void | |
| 2358 | 1689 | */ |
| 2359 | 1690 | public static function display_field_value_selector( $selector_field_id, $selector_args ) { |
| 2360 | 1691 | $field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args ); |
| 2361 | 1692 | $field_value_selector->display(); |
| @@ -2370,9 +1701,9 @@ | ||
| 2370 | 1701 | * |
| 2371 | 1702 | * @return array |
| 2372 | 1703 | */ |
| 2373 | 1704 | public static function convert_field_object_to_flat_array( $field ) { |
| 2374 | - $field_options = is_array( $field->field_options ) ? $field->field_options : array(); | |
| 1705 | + $field_options = $field->field_options; | |
| 2375 | 1706 | $field_array = get_object_vars( $field ); |
| 2376 | 1707 | unset( $field_array['field_options'] ); |
| 2377 | 1708 | |
| 2378 | 1709 | return $field_array + $field_options; |
| @@ -2379,47 +1710,35 @@ | ||
| 2379 | 1710 | } |
| 2380 | 1711 | |
| 2381 | 1712 | /** |
| 2382 | 1713 | * @since 4.04 |
| 2383 | - * | |
| 2384 | - * @param array $args | |
| 2385 | - * | |
| 2386 | - * @return void | |
| 2387 | 1714 | */ |
| 2388 | 1715 | public static function show_add_field_buttons( $args ) { |
| 2389 | - $field_key = $args['field_key']; | |
| 2390 | - $field_type = $args['field_type']; | |
| 2391 | - $field_label = FrmAppHelper::icon_by_class( FrmFormsHelper::get_field_link_icon( $field_type ), array( 'echo' => false ) ); | |
| 2392 | - $field_name = FrmFormsHelper::get_field_link_name( $field_type ); | |
| 2393 | - $field_label .= ' <span>' . $field_name . '</span>'; | |
| 1716 | + $field_key = $args['field_key']; | |
| 1717 | + $field_type = $args['field_type']; | |
| 1718 | + $field_label = FrmAppHelper::icon_by_class( FrmFormsHelper::get_field_link_icon( $field_type ), array( 'echo' => false ) ); | |
| 1719 | + $field_name = FrmFormsHelper::get_field_link_name( $field_type ); | |
| 1720 | + $field_label .= ' <span>' . $field_name . '</span>'; | |
| 2394 | 1721 | |
| 2395 | - if ( ! empty( $field_type['is_new'] ) ) { | |
| 2396 | - ob_start(); | |
| 2397 | - FrmAppHelper::show_pill_text(); | |
| 2398 | - $field_label .= ob_get_clean(); | |
| 2399 | - } | |
| 1722 | + /* translators: %s: Field name */ | |
| 1723 | + $upgrade_label = sprintf( esc_html__( '%s fields', 'formidable' ), $field_name ); | |
| 2400 | 1724 | |
| 2401 | 1725 | // If the individual field isn't allowed, disable it. |
| 2402 | - $run_filter = true; | |
| 2403 | - $single_no_allow = ' '; | |
| 2404 | - $install_data = ''; | |
| 2405 | - $requires = ''; | |
| 2406 | - $link = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : ''; | |
| 2407 | - $has_show_upgrade_class = isset( $field_type['icon'] ) && strpos( $field_type['icon'], ' frm_show_upgrade' ); | |
| 2408 | - $show_upgrade = $has_show_upgrade_class || false !== strpos( $args['no_allow_class'], 'frm_show_upgrade' ); | |
| 2409 | - | |
| 2410 | - if ( $has_show_upgrade_class ) { | |
| 1726 | + $run_filter = true; | |
| 1727 | + $single_no_allow = ' '; | |
| 1728 | + $install_data = ''; | |
| 1729 | + $requires = ''; | |
| 1730 | + $upgrade_message = ''; | |
| 1731 | + $link = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : ''; | |
| 1732 | + if ( strpos( $field_type['icon'], ' frm_show_upgrade' ) ) { | |
| 2411 | 1733 | $single_no_allow .= 'frm_show_upgrade'; |
| 2412 | 1734 | $field_type['icon'] = str_replace( ' frm_show_upgrade', '', $field_type['icon'] ); |
| 2413 | 1735 | $run_filter = false; |
| 2414 | - | |
| 2415 | 1736 | if ( isset( $field_type['addon'] ) ) { |
| 2416 | 1737 | $upgrading = FrmAddonsController::install_link( $field_type['addon'] ); |
| 2417 | - | |
| 2418 | 1738 | if ( isset( $upgrading['url'] ) ) { |
| 2419 | 1739 | $install_data = json_encode( $upgrading ); |
| 2420 | 1740 | } |
| 2421 | - | |
| 2422 | 1741 | $requires = FrmFormsHelper::get_plan_required( $upgrading ); |
| 2423 | 1742 | } elseif ( isset( $field_type['require'] ) ) { |
| 2424 | 1743 | $requires = $field_type['require']; |
| 2425 | 1744 | } |
| @@ -2424,63 +1743,19 @@ | ||
| 2424 | 1743 | $requires = $field_type['require']; |
| 2425 | 1744 | } |
| 2426 | 1745 | } |
| 2427 | 1746 | |
| 2428 | - $upgrade_label = ''; | |
| 2429 | - $upgrade_message = ''; | |
| 2430 | - | |
| 2431 | - if ( $show_upgrade ) { | |
| 2432 | - /* translators: %s: Field name */ | |
| 2433 | - $upgrade_label = sprintf( esc_html__( '%s fields', 'formidable' ), $field_name ); | |
| 2434 | - | |
| 2435 | - if ( isset( $field_type['message'] ) ) { | |
| 2436 | - $upgrade_message = FrmAppHelper::kses( $field_type['message'], array( 'a', 'img' ) ); | |
| 2437 | - } | |
| 1747 | + if ( isset( $field_type['message'] ) ) { | |
| 1748 | + $upgrade_message = FrmAppHelper::kses( $field_type['message'], array( 'a', 'img' ) ); | |
| 2438 | 1749 | } |
| 2439 | 1750 | |
| 2440 | - $li_params = array( | |
| 2441 | - 'class' => 'frmbutton frm6 ' . $args['no_allow_class'] . $single_no_allow . ' frm_t' . str_replace( '|', '-', $field_key ), | |
| 2442 | - 'id' => $field_key, | |
| 2443 | - 'data-upgrade' => $upgrade_label, | |
| 2444 | - 'data-link' => $link, | |
| 2445 | - 'data-medium' => 'builder', | |
| 2446 | - 'data-oneclick' => $install_data, | |
| 2447 | - 'data-content' => $field_key, | |
| 2448 | - 'data-requires' => $requires, | |
| 2449 | - ); | |
| 2450 | - | |
| 2451 | - if ( ! empty( $field_type['hide'] ) ) { | |
| 2452 | - $li_params['class'] .= ' frm_hidden'; | |
| 2453 | - } | |
| 2454 | - | |
| 2455 | - if ( ! empty( $field_type['upsell_image'] ) ) { | |
| 2456 | - $li_params['data-upsell-image'] = $field_type['upsell_image']; | |
| 2457 | - } | |
| 2458 | - | |
| 2459 | - if ( ! empty( $field_type['learn-more'] ) ) { | |
| 2460 | - $li_params['data-learn-more'] = FrmAppHelper::get_doc_url( | |
| 2461 | - $field_type['learn-more'], | |
| 2462 | - 'form-builder-add-fields', | |
| 2463 | - false !== strpos( $field_type['learn-more'], '/' ) | |
| 2464 | - ); | |
| 2465 | - } | |
| 2466 | - | |
| 2467 | - if ( isset( $upgrading['url'] ) ) { | |
| 2468 | - $li_params['data-message'] = sprintf( | |
| 2469 | - // translators: %s: Field name | |
| 2470 | - esc_html__( 'You already have access to %s fields, you\'ll just need to activate to start using them.', 'formidable' ), | |
| 2471 | - $field_name | |
| 2472 | - ); | |
| 2473 | - } elseif ( $upgrade_message ) { | |
| 2474 | - $li_params['data-message'] = $upgrade_message; | |
| 2475 | - } | |
| 2476 | 1751 | ?> |
| 2477 | - <li <?php FrmAppHelper::array_to_html_params( $li_params, true ); ?>> | |
| 1752 | + <li class="frmbutton <?php echo esc_attr( $args['no_allow_class'] . $single_no_allow . ' frm_t' . str_replace( '|', '-', $field_key ) ); ?>" id="<?php echo esc_attr( $field_key ); ?>" data-upgrade="<?php echo esc_attr( $upgrade_label ); ?>" data-message="<?php echo esc_attr( $upgrade_message ); ?>" data-link="<?php echo esc_attr( $link ); ?>" data-medium="builder" data-oneclick="<?php echo esc_attr( $install_data ); ?>" data-content="<?php echo esc_attr( $field_key ); ?>" data-requires="<?php echo esc_attr( $requires ); ?>"> | |
| 2478 | 1753 | <?php |
| 2479 | 1754 | if ( $run_filter ) { |
| 2480 | 1755 | $field_label = apply_filters( 'frmpro_field_links', $field_label, $args['id'], $field_key ); |
| 2481 | 1756 | } |
| 2482 | - FrmAppHelper::kses_echo( $field_label, array( 'a', 'i', 'span', 'use', 'svg' ) ); | |
| 1757 | + echo FrmAppHelper::kses( $field_label, array( 'a', 'i', 'span', 'use', 'svg' ) ); // WPCS: XSS ok. | |
| 2483 | 1758 | ?> |
| 2484 | 1759 | </li> |
| 2485 | 1760 | <?php |
| 2486 | 1761 | } |
| @@ -2485,319 +1760,92 @@ | ||
| 2485 | 1760 | <?php |
| 2486 | 1761 | } |
| 2487 | 1762 | |
| 2488 | 1763 | /** |
| 2489 | - * Shows Display format option. | |
| 2490 | - * | |
| 2491 | - * @since 5.0.04 | |
| 2492 | - * | |
| 2493 | - * @param array $field Field data. | |
| 2494 | - * | |
| 2495 | - * @return void | |
| 1764 | + * @deprecated 4.0 | |
| 2496 | 1765 | */ |
| 2497 | - public static function show_radio_display_format( $field ) { | |
| 2498 | - $options = self::get_display_format_options( $field ); | |
| 2499 | - | |
| 2500 | - $args = self::get_display_format_args( $field, $options ); | |
| 2501 | - | |
| 2502 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/radio-display-format.php'; | |
| 1766 | + public static function show_icon_link_js( $atts ) { | |
| 1767 | + _deprecated_function( __METHOD__, '4.0' ); | |
| 1768 | + $atts['icon'] .= $atts['is_selected'] ? ' ' : ' frm_inactive_icon '; | |
| 1769 | + if ( isset( $atts['has_default'] ) && ! $atts['has_default'] ) { | |
| 1770 | + $atts['icon'] .= 'frm_hidden '; | |
| 1771 | + } | |
| 1772 | + 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>'; | |
| 2503 | 1773 | } |
| 2504 | 1774 | |
| 2505 | 1775 | /** |
| 2506 | - * Creates an array that contains variables used for display format options setting. | |
| 2507 | - * | |
| 2508 | - * @since 6.3.2 | |
| 2509 | - * | |
| 2510 | - * @param array $field The field. | |
| 2511 | - * | |
| 2512 | - * @return array | |
| 1776 | + * @deprecated 4.0 | |
| 2513 | 1777 | */ |
| 2514 | - public static function get_display_format_options( $field ) { | |
| 2515 | - $options = array( | |
| 2516 | - '0' => array( | |
| 2517 | - 'text' => __( 'Simple', 'formidable' ), | |
| 2518 | - 'svg' => 'frm_simple_radio', | |
| 2519 | - ), | |
| 2520 | - '1' => array( | |
| 2521 | - 'text' => __( 'Images', 'formidable' ), | |
| 2522 | - 'svg' => 'frm_image_as_option', | |
| 2523 | - 'addon' => 'pro', | |
| 2524 | - 'upgrade' => __( 'Image Options', 'formidable' ), | |
| 2525 | - '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" />', | |
| 2526 | - 'content' => 'image-options', | |
| 2527 | - ), | |
| 2528 | - 'buttons' => array( | |
| 2529 | - 'text' => __( 'Buttons', 'formidable' ), | |
| 2530 | - 'svg' => 'frm_button_as_option', | |
| 2531 | - 'addon' => 'surveys', | |
| 2532 | - 'upgrade' => __( 'Button Options', 'formidable' ), | |
| 2533 | - 'message' => __( 'Show buttons for radio buttons or check boxes. This is ideal for polls, surveys, segmenting questionnaires and more.', 'formidable' ), | |
| 2534 | - 'content' => 'button-options', | |
| 2535 | - ), | |
| 2536 | - ); | |
| 2537 | - | |
| 2538 | - /** | |
| 2539 | - * Allows modifying the options of Display format setting of Radio field. | |
| 2540 | - * | |
| 2541 | - * @since 5.0.04 | |
| 2542 | - * | |
| 2543 | - * @param array $options Options. | |
| 2544 | - * @param array $field | |
| 2545 | - */ | |
| 2546 | - $options = apply_filters( 'frm_' . $field['type'] . '_display_format_options', $options, $field ); | |
| 2547 | - | |
| 2548 | - return $options; | |
| 1778 | + public static function show_default_blank_js( $is_selected, $has_default_value = true ) { | |
| 1779 | + _deprecated_function( __METHOD__, '4.0' ); | |
| 2549 | 1780 | } |
| 2550 | 1781 | |
| 2551 | 1782 | /** |
| 2552 | - * Gets display format arguments to pass to the images_dropdown() method. | |
| 2553 | - * | |
| 2554 | - * @since 5.0.04 | |
| 2555 | - * | |
| 2556 | - * @param array $field Field data. | |
| 2557 | - * @param array $options Options array. | |
| 2558 | - * | |
| 2559 | - * @return array | |
| 1783 | + * @deprecated 4.0 | |
| 2560 | 1784 | */ |
| 2561 | - public static function get_display_format_args( $field, $options ) { | |
| 2562 | - $args = array( | |
| 2563 | - 'selected' => '0', | |
| 2564 | - 'options' => array(), | |
| 2565 | - 'name' => 'field_options[image_options_' . $field['id'] . ']', | |
| 2566 | - 'input_attrs' => array( | |
| 2567 | - 'class' => 'frm_toggle_image_options', | |
| 2568 | - ), | |
| 2569 | - ); | |
| 2570 | - | |
| 2571 | - self::fill_image_setting_options( $options, $args ); | |
| 2572 | - | |
| 2573 | - /** | |
| 2574 | - * Allows modifying the arguments of Display format setting of Radio field. | |
| 2575 | - * | |
| 2576 | - * @since 5.0.04 | |
| 2577 | - * | |
| 2578 | - * @param array $args Arguments. | |
| 2579 | - * @param array $method_args The arguments from the method. Contains `field`, `options`. | |
| 2580 | - */ | |
| 2581 | - return apply_filters( 'frm_' . $field['type'] . '_display_format_args', $args, compact( 'field', 'options' ) ); | |
| 1785 | + public static function clear_on_focus_html( $field, $display, $id = '' ) { | |
| 1786 | + _deprecated_function( __METHOD__, '4.0' ); | |
| 2582 | 1787 | } |
| 2583 | 1788 | |
| 2584 | 1789 | /** |
| 2585 | - * @since 5.0.04 | |
| 2586 | - * | |
| 2587 | - * @param array $options Options. | |
| 2588 | - * @param array $args Arguments. | |
| 2589 | - * | |
| 2590 | - * @return void | |
| 1790 | + * @deprecated 4.0 | |
| 2591 | 1791 | */ |
| 2592 | - private static function fill_image_setting_options( $options, &$args ) { | |
| 2593 | - foreach ( $options as $key => $option ) { | |
| 2594 | - $args['options'][ $key ] = $option; | |
| 2595 | - | |
| 2596 | - if ( ! empty( $option['addon'] ) ) { | |
| 2597 | - $args['options'][ $key ]['custom_attrs'] = self::fill_image_setting_addon_link( $option ); | |
| 2598 | - } | |
| 2599 | - | |
| 2600 | - unset( $args['options'][ $key ]['addon'] ); | |
| 2601 | - $fill = array( 'upgrade', 'message', 'content' ); | |
| 2602 | - | |
| 2603 | - foreach ( $fill as $f ) { | |
| 2604 | - unset( $args['options'][ $key ][ $f ], $f ); | |
| 2605 | - } | |
| 2606 | - } | |
| 1792 | + public static function show_onfocus_js( $is_selected, $has_default_value = true ) { | |
| 1793 | + _deprecated_function( __METHOD__, '4.0' ); | |
| 2607 | 1794 | } |
| 2608 | 1795 | |
| 2609 | 1796 | /** |
| 2610 | - * @since 5.0.04 | |
| 2611 | - * | |
| 2612 | - * @param array $option Option. | |
| 2613 | - * | |
| 2614 | - * @return array | |
| 1797 | + * @deprecated 3.0 | |
| 1798 | + * @codeCoverageIgnore | |
| 2615 | 1799 | */ |
| 2616 | - private static function fill_image_setting_addon_link( $option ) { | |
| 2617 | - $custom_attrs = array( | |
| 2618 | - 'class' => 'frm_noallow frm_show_upgrade', | |
| 2619 | - 'data-medium' => 'builder', | |
| 2620 | - ); | |
| 2621 | - | |
| 2622 | - // translators: Add-on name. | |
| 2623 | - $custom_attrs['data-upgrade'] = sprintf( __( 'Formidable %s', 'formidable' ), ucwords( $option['addon'] ) ); | |
| 2624 | - | |
| 2625 | - $fill = array( 'upgrade', 'message', 'content' ); | |
| 2626 | - | |
| 2627 | - foreach ( $fill as $f ) { | |
| 2628 | - if ( isset( $option[ $f ] ) ) { | |
| 2629 | - $custom_attrs[ 'data-' . $f ] = $option[ $f ]; | |
| 2630 | - } | |
| 2631 | - } | |
| 2632 | - | |
| 2633 | - if ( 'pro' === $option['addon'] ) { | |
| 2634 | - return $custom_attrs; | |
| 2635 | - } | |
| 2636 | - | |
| 2637 | - $upgrading = FrmAddonsController::install_link( $option['addon'] ); | |
| 2638 | - | |
| 2639 | - if ( isset( $upgrading['url'] ) ) { | |
| 2640 | - $install_data = wp_json_encode( $upgrading ); | |
| 2641 | - } else { | |
| 2642 | - $install_data = ''; | |
| 2643 | - } | |
| 2644 | - | |
| 2645 | - $custom_attrs['data-oneclick'] = $install_data; | |
| 2646 | - $custom_attrs['data-requires'] = FrmFormsHelper::get_plan_required( $upgrading ); | |
| 2647 | - | |
| 2648 | - return $custom_attrs; | |
| 1800 | + public static function display_recaptcha() { | |
| 1801 | + _deprecated_function( __FUNCTION__, '3.0', 'FrmFieldCaptcha::field_input' ); | |
| 2649 | 1802 | } |
| 2650 | 1803 | |
| 2651 | 1804 | /** |
| 2652 | - * Maybe adjust a field value based on type. | |
| 2653 | - * Some types require unserializing an array. | |
| 2654 | - * These types are defined by a array_allowed property on their field model class. | |
| 2655 | - * | |
| 2656 | - * @since 6.2 | |
| 2657 | - * | |
| 2658 | - * @param mixed $value | |
| 2659 | - * @param string $field_type | |
| 2660 | - * | |
| 2661 | - * @return void | |
| 1805 | + * @deprecated 3.0 | |
| 1806 | + * @codeCoverageIgnore | |
| 2662 | 1807 | */ |
| 2663 | - public static function prepare_field_value( &$value, $field_type ) { | |
| 2664 | - $field_object = FrmFieldFactory::get_field_type( $field_type ); | |
| 2665 | - $value = $field_object->maybe_decode_value( $value ); | |
| 1808 | + public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) { | |
| 1809 | + FrmDeprecated::remove_inline_conditions( $no_vars, $code, $replace_with, $html ); | |
| 2666 | 1810 | } |
| 2667 | 1811 | |
| 2668 | 1812 | /** |
| 2669 | - * @since 6.8 | |
| 2670 | - * | |
| 2671 | - * @param int|string $form_id | |
| 2672 | - * @param array $field_ids If this is not empty, the results will be filtered by field id. | |
| 2673 | - * | |
| 2674 | - * @return array | |
| 1813 | + * @deprecated 3.0 | |
| 1814 | + * @codeCoverageIgnore | |
| 2675 | 1815 | */ |
| 2676 | - public static function get_draft_field_results( $form_id, $field_ids = array() ) { | |
| 2677 | - if ( FrmAppHelper::pro_is_installed() ) { | |
| 2678 | - $child_form_ids = FrmDb::get_col( 'frm_forms', array( 'parent_form_id' => $form_id ) ); | |
| 2679 | - $form_ids = array_merge( array( $form_id ), $child_form_ids ); | |
| 2680 | - } else { | |
| 2681 | - $form_ids = array( $form_id ); | |
| 2682 | - } | |
| 2683 | - | |
| 2684 | - $where = array( | |
| 2685 | - 'form_id' => $form_ids, | |
| 2686 | - // Do a soft check for fields that look like drafts only. | |
| 2687 | - 'field_options LIKE' => 's:5:"draft";i:1;', | |
| 2688 | - ); | |
| 2689 | - | |
| 2690 | - if ( $field_ids ) { | |
| 2691 | - $where['id'] = $field_ids; | |
| 2692 | - } | |
| 2693 | - | |
| 2694 | - $rows = FrmDb::get_results( 'frm_fields', $where, 'id, field_options' ); | |
| 2695 | - | |
| 2696 | - return array_filter( | |
| 2697 | - $rows, | |
| 2698 | - function ( $row ) { | |
| 2699 | - FrmAppHelper::unserialize_or_decode( $row->field_options ); | |
| 2700 | - return is_array( $row->field_options ) && ! empty( $row->field_options['draft'] ); | |
| 2701 | - } | |
| 2702 | - ); | |
| 1816 | + public static function get_shortcode_tag( $shortcodes, $short_key, $args ) { | |
| 1817 | + return FrmDeprecated::get_shortcode_tag( $shortcodes, $short_key, $args ); | |
| 2703 | 1818 | } |
| 2704 | 1819 | |
| 2705 | 1820 | /** |
| 2706 | - * This is called when loading the form builder. | |
| 2707 | - * Any unsaved draft fields get added to a hidden draft_fields input on load. | |
| 1821 | + * @deprecated 3.0 | |
| 1822 | + * @codeCoverageIgnore | |
| 2708 | 1823 | * |
| 2709 | - * @since 6.8 | |
| 1824 | + * @param string $html | |
| 1825 | + * @param array $field | |
| 1826 | + * @param array $errors | |
| 1827 | + * @param object $form | |
| 1828 | + * @param array $args | |
| 2710 | 1829 | * |
| 2711 | - * @param int|string $form_id | |
| 2712 | - * | |
| 2713 | - * @return array | |
| 1830 | + * @return string | |
| 2714 | 1831 | */ |
| 2715 | - public static function get_all_draft_field_ids( $form_id ) { | |
| 2716 | - $draft_field_rows = self::get_draft_field_results( $form_id ); | |
| 2717 | - return wp_list_pluck( $draft_field_rows, 'id' ); | |
| 1832 | + public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) { | |
| 1833 | + return FrmDeprecated::replace_shortcodes( $html, $field, $errors, $form, $args ); | |
| 2718 | 1834 | } |
| 2719 | 1835 | |
| 2720 | 1836 | /** |
| 2721 | - * Render AI generate options button. | |
| 2722 | - * | |
| 2723 | - * @since 6.24 | |
| 2724 | - * | |
| 2725 | - * @param array $args Field arguments. | |
| 2726 | - * @param bool $should_hide_bulk_edit Whether to hide bulk edit. | |
| 2727 | - * | |
| 2728 | - * @return void | |
| 1837 | + * @deprecated 3.0 | |
| 1838 | + * @codeCoverageIgnore | |
| 2729 | 1839 | */ |
| 2730 | - public static function render_ai_generate_options_button( $args, $should_hide_bulk_edit = false ) { | |
| 2731 | - $attributes = array( | |
| 2732 | - 'type' => 'button', | |
| 2733 | - 'class' => self::get_ai_generate_options_button_class(), | |
| 2734 | - ); | |
| 2735 | - | |
| 2736 | - if ( ! empty( $should_hide_bulk_edit ) ) { | |
| 2737 | - $attributes['class'] .= ' frm-force-hidden'; | |
| 2738 | - } | |
| 2739 | - | |
| 2740 | - $data = FrmAppHelper::get_upgrade_data_params( | |
| 2741 | - 'ai', | |
| 2742 | - array( | |
| 2743 | - 'requires' => 'Business', | |
| 2744 | - 'upgrade' => __( 'Generate options with AI', 'formidable' ), | |
| 2745 | - 'medium' => 'builder', | |
| 2746 | - 'content' => 'generate-options-with-ai', | |
| 2747 | - ), | |
| 2748 | - true | |
| 2749 | - ); | |
| 2750 | - | |
| 2751 | - if ( in_array( FrmAddonsController::license_type(), array( 'elite', 'business' ), true ) && 'active' === $data['plugin-status'] ) { | |
| 2752 | - // Backwards compatibility "@since 6.24". | |
| 2753 | - if ( ! method_exists( 'FrmAIAppController', 'get_ai_generated_options_summary' ) ) { | |
| 2754 | - $data = array( | |
| 2755 | - 'modal-title' => __( 'Generate options with AI', 'formidable' ), | |
| 2756 | - 'modal-content' => __( 'Update the Formidable AI add-on to the last version to use this feature.', 'formidable' ), | |
| 2757 | - ); | |
| 2758 | - } else { | |
| 2759 | - $attributes['class'] .= ' frm-ai-generate-options-modal-trigger'; | |
| 2760 | - $attributes['data-fid'] = $args['likert_id'] ?? $args['field']['id']; | |
| 2761 | - } | |
| 2762 | - } | |
| 2763 | - | |
| 2764 | - if ( empty( $attributes['data-fid'] ) ) { | |
| 2765 | - unset( $data['plugin-status'] ); | |
| 2766 | - | |
| 2767 | - foreach ( $data as $key => $value ) { | |
| 2768 | - $attributes[ 'data-' . $key ] = $value; | |
| 2769 | - } | |
| 2770 | - } | |
| 2771 | - | |
| 2772 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/generate-options-with-ai.php'; | |
| 1840 | + public static function get_default_field_opts( $type, $field = null, $limit = false ) { | |
| 1841 | + return FrmDeprecated::get_default_field_opts( $type, $field, $limit ); | |
| 2773 | 1842 | } |
| 2774 | 1843 | |
| 2775 | 1844 | /** |
| 2776 | - * Get AI generate options button class. | |
| 2777 | - * | |
| 2778 | - * @since 6.24 | |
| 2779 | - * | |
| 2780 | - * @return string Button class. | |
| 1845 | + * @deprecated 2.02.07 | |
| 1846 | + * @codeCoverageIgnore | |
| 2781 | 1847 | */ |
| 2782 | - private static function get_ai_generate_options_button_class() { | |
| 2783 | - return implode( | |
| 2784 | - ' ', | |
| 2785 | - array( | |
| 2786 | - 'frm_form_field', | |
| 2787 | - 'frm6', | |
| 2788 | - 'frm6_followed', | |
| 2789 | - 'frm-h-stack', | |
| 2790 | - 'button', | |
| 2791 | - 'frm-button-secondary', | |
| 2792 | - 'frm-button-gradient', | |
| 2793 | - 'frm-rounded-6', | |
| 2794 | - 'frm-max-w-fit', | |
| 2795 | - 'frm-font-normal', | |
| 2796 | - 'frm-py-2xs', | |
| 2797 | - 'frm-px-xs', | |
| 2798 | - 'frm-mt-xs', | |
| 2799 | - 'frm-mb-12', | |
| 2800 | - ) | |
| 2801 | - ); | |
| 1848 | + public static function dropdown_categories( $args ) { | |
| 1849 | + return FrmDeprecated::dropdown_categories( $args ); | |
| 2802 | 1850 | } |
| 2803 | 1851 | } |