| @@ -8,9 +8,8 @@ | ||
| 8 | 8 | /** |
| 9 | 9 | * The meta name of default template style. |
| 10 | 10 | * |
| 11 | 11 | * @since 6.14 |
| 12 | - * | |
| 13 | 12 | * @var string |
| 14 | 13 | */ |
| 15 | 14 | private $default_template_style_meta_name = 'frm_style_default'; |
| 16 | 15 | |
| @@ -43,9 +42,9 @@ | ||
| 43 | 42 | |
| 44 | 43 | $max_slug_value = 2147483647; |
| 45 | 44 | // We want to have at least 2 characters in the slug. |
| 46 | 45 | $min_slug_value = 37; |
| 47 | - $key = base_convert( random_int( $min_slug_value, $max_slug_value ), 10, 36 ); | |
| 46 | + $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 ); | |
| 48 | 47 | |
| 49 | 48 | $style = array( |
| 50 | 49 | 'post_type' => FrmStylesController::$post_type, |
| 51 | 50 | 'ID' => '', |
| @@ -60,9 +59,8 @@ | ||
| 60 | 59 | } |
| 61 | 60 | |
| 62 | 61 | /** |
| 63 | 62 | * @param array $settings |
| 64 | - * | |
| 65 | 63 | * @return int|WP_Error |
| 66 | 64 | */ |
| 67 | 65 | public function save( $settings ) { |
| 68 | 66 | return FrmDb::save_settings( $settings, 'frm_styles' ); |
| @@ -68,10 +66,8 @@ | ||
| 68 | 66 | return FrmDb::save_settings( $settings, 'frm_styles' ); |
| 69 | 67 | } |
| 70 | 68 | |
| 71 | 69 | /** |
| 72 | - * @param int|string $id The id of the stylesheet or 'default'. | |
| 73 | - * | |
| 74 | 70 | * @return void |
| 75 | 71 | */ |
| 76 | 72 | public function duplicate( $id ) { |
| 77 | 73 | // Duplicating is a pro feature. This is handled in FrmProStyle::duplicate instead. |
| @@ -80,17 +76,16 @@ | ||
| 80 | 76 | /** |
| 81 | 77 | * Handle save actions in the visual styler edit page. |
| 82 | 78 | * |
| 83 | 79 | * @param mixed $id |
| 84 | - * | |
| 85 | 80 | * @return array<int|WP_Error> |
| 86 | 81 | */ |
| 87 | 82 | public function update( $id = 'default' ) { |
| 88 | - $all_instances = $this->get_all(); | |
| 89 | - $css_scope_helper = new FrmCssScopeHelper(); | |
| 83 | + $all_instances = $this->get_all(); | |
| 90 | 84 | |
| 91 | 85 | if ( ! $id ) { |
| 92 | - $all_instances[] = (array) $this->get_new(); | |
| 86 | + $new_style = (array) $this->get_new(); | |
| 87 | + $all_instances[] = $new_style; | |
| 93 | 88 | } |
| 94 | 89 | |
| 95 | 90 | $action_ids = array(); |
| 96 | 91 | |
| @@ -97,10 +92,9 @@ | ||
| 97 | 92 | foreach ( $all_instances as $new_instance ) { |
| 98 | 93 | $new_instance = (array) $new_instance; |
| 99 | 94 | $this->id = $new_instance['ID']; |
| 100 | 95 | |
| 101 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing, Universal.Operators.StrictComparisons | |
| 102 | - if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) { | |
| 96 | + if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 103 | 97 | // Don't continue if not saving this style. |
| 104 | 98 | continue; |
| 105 | 99 | } |
| 106 | 100 | |
| @@ -105,9 +99,9 @@ | ||
| 105 | 99 | } |
| 106 | 100 | |
| 107 | 101 | // Custom CSS is no longer used from the default style, but it is still checked if the Global Setting is missing. |
| 108 | 102 | // Preserve the previous value in case Custom CSS has not been saved as a Global Setting yet. |
| 109 | - $custom_css = $new_instance['post_content']['custom_css'] ?? ''; | |
| 103 | + $custom_css = isset( $new_instance['post_content']['custom_css'] ) ? $new_instance['post_content']['custom_css'] : ''; | |
| 110 | 104 | |
| 111 | 105 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 112 | 106 | if ( ! empty( $_POST['frm_style_setting']['post_title'] ) ) { |
| 113 | 107 | // The nonce check happens in FrmStylesController::save_style before this is called. |
| @@ -114,17 +108,12 @@ | ||
| 114 | 108 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 115 | 109 | $new_instance['post_title'] = sanitize_text_field( wp_unslash( $_POST['frm_style_setting']['post_title'] ) ); |
| 116 | 110 | } |
| 117 | 111 | |
| 118 | - $new_instance['post_content'] = isset( $_POST['frm_style_setting']['post_content'] ) ? $this->sanitize_post_content( wp_unslash( $_POST['frm_style_setting']['post_content'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 112 | + $new_instance['post_content'] = isset( $_POST['frm_style_setting']['post_content'] ) ? $this->sanitize_post_content( wp_unslash( $_POST['frm_style_setting']['post_content'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing | |
| 119 | 113 | $new_instance['post_content']['custom_css'] = $custom_css; |
| 120 | 114 | unset( $custom_css ); |
| 121 | 115 | |
| 122 | - if ( ! empty( $new_instance['post_content']['single_style_custom_css'] ) ) { | |
| 123 | - $css_scope = 'frm_style_' . $new_instance['post_name']; | |
| 124 | - $new_instance['post_content']['single_style_custom_css'] = $css_scope_helper->nest( $new_instance['post_content']['single_style_custom_css'], $css_scope ); | |
| 125 | - } | |
| 126 | - | |
| 127 | 116 | $new_instance['post_type'] = FrmStylesController::$post_type; |
| 128 | 117 | $new_instance['post_status'] = 'publish'; |
| 129 | 118 | |
| 130 | 119 | if ( ! $id ) { |
| @@ -139,10 +128,9 @@ | ||
| 139 | 128 | } |
| 140 | 129 | |
| 141 | 130 | if ( $this->is_color( $setting ) ) { |
| 142 | 131 | $color_val = $new_instance['post_content'][ $setting ]; |
| 143 | - | |
| 144 | - if ( $color_val !== '' && str_contains( $color_val, 'rgb' ) ) { | |
| 132 | + if ( $color_val !== '' && false !== strpos( $color_val, 'rgb' ) ) { | |
| 145 | 133 | // Maybe sanitize if invalid rgba value is entered. |
| 146 | 134 | $this->maybe_sanitize_rgba_value( $color_val ); |
| 147 | 135 | } |
| 148 | 136 | $new_instance['post_content'][ $setting ] = str_replace( '#', '', $color_val ); |
| @@ -153,9 +141,10 @@ | ||
| 153 | 141 | } |
| 154 | 142 | } |
| 155 | 143 | |
| 156 | 144 | $new_instance['post_content'] = FrmStylesHelper::update_base_font_size( $new_instance['post_content'], $this->get_defaults() ); |
| 157 | - $action_ids[] = $this->save( $new_instance ); | |
| 145 | + | |
| 146 | + $action_ids[] = $this->save( $new_instance ); | |
| 158 | 147 | }//end foreach |
| 159 | 148 | |
| 160 | 149 | $this->save_settings(); |
| 161 | 150 | |
| @@ -167,12 +156,11 @@ | ||
| 167 | 156 | * |
| 168 | 157 | * @since 5.3.2 |
| 169 | 158 | * |
| 170 | 159 | * @param string $color_val The color value, by reference. |
| 171 | - * | |
| 172 | 160 | * @return void |
| 173 | 161 | */ |
| 174 | - private function maybe_sanitize_rgba_value( &$color_val ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh | |
| 162 | + private function maybe_sanitize_rgba_value( &$color_val ) { | |
| 175 | 163 | if ( preg_match( '/(rgb|rgba)\(/', $color_val ) !== 1 ) { |
| 176 | 164 | return; |
| 177 | 165 | } |
| 178 | 166 | |
| @@ -179,9 +167,8 @@ | ||
| 179 | 167 | $color_val = trim( $color_val ); |
| 180 | 168 | // Remove leading braces so (rgba(1,1,1,1) doesn't cause inconsistent braces. |
| 181 | 169 | $color_val = ltrim( $color_val, '(' ); |
| 182 | 170 | $patterns = array( '/rgba\((\s*\d+\s*,){3}[[0-1]\.]+\)/', '/rgb\((\s*\d+\s*,){2}\s*[\d]+\)/' ); |
| 183 | - | |
| 184 | 171 | foreach ( $patterns as $pattern ) { |
| 185 | 172 | if ( preg_match( $pattern, $color_val ) === 1 ) { |
| 186 | 173 | return; |
| 187 | 174 | } |
| @@ -201,9 +188,9 @@ | ||
| 201 | 188 | foreach ( explode( ',', $color_rgba ) as $index => $value ) { |
| 202 | 189 | $new_value = null; |
| 203 | 190 | $value_is_empty_string = '' === trim( $value ) || '' === $value; |
| 204 | 191 | |
| 205 | - if ( 3 === $length_of_color_codes || $index !== $length_of_color_codes - 1 ) { | |
| 192 | + if ( 3 === $length_of_color_codes || ( $index !== $length_of_color_codes - 1 ) ) { | |
| 206 | 193 | // Insert a value for r, g, or b. |
| 207 | 194 | if ( $value < 0 ) { |
| 208 | 195 | $new_value = 0; |
| 209 | 196 | } elseif ( $value > 255 ) { |
| @@ -223,14 +210,13 @@ | ||
| 223 | 210 | $new_value = floatval( $value ); |
| 224 | 211 | } |
| 225 | 212 | }//end if |
| 226 | 213 | |
| 227 | - $new_color_values[] = $new_value; | |
| 214 | + $new_color_values[] = null === $new_value ? $value : $new_value; | |
| 228 | 215 | }//end foreach |
| 229 | 216 | |
| 230 | 217 | // add more 0s and 1 (if alpha position) if needed. |
| 231 | 218 | $missing_values = $length_of_color_codes - count( $new_color_values ); |
| 232 | - | |
| 233 | 219 | if ( $missing_values > 1 ) { |
| 234 | 220 | $insert_values = array_fill( 0, $missing_values - 1, 0 ); |
| 235 | 221 | $last_value = 4 === $length_of_color_codes ? 1 : 0; |
| 236 | 222 | array_push( $insert_values, $last_value ); |
| @@ -236,9 +222,8 @@ | ||
| 236 | 222 | array_push( $insert_values, $last_value ); |
| 237 | 223 | } elseif ( $missing_values === 1 ) { |
| 238 | 224 | $insert_values = 4 === $length_of_color_codes ? array( 1 ) : array( 0 ); |
| 239 | 225 | } |
| 240 | - | |
| 241 | 226 | if ( ! empty( $insert_values ) ) { |
| 242 | 227 | $new_color_values = array_merge( $new_color_values, $insert_values ); |
| 243 | 228 | } |
| 244 | 229 | |
| @@ -246,8 +231,9 @@ | ||
| 246 | 231 | $prefix = substr( $color_val, 0, strpos( $color_val, '(' ) + 1 ); |
| 247 | 232 | // Limit the number of opening braces after rgb/rgba. There should only be one. |
| 248 | 233 | $prefix = rtrim( $prefix, '(' ) . '('; |
| 249 | 234 | $new_color = $prefix . $new_color . ')'; |
| 235 | + | |
| 250 | 236 | $color_val = $new_color; |
| 251 | 237 | } |
| 252 | 238 | |
| 253 | 239 | /** |
| @@ -253,9 +239,8 @@ | ||
| 253 | 239 | /** |
| 254 | 240 | * @since 5.0.13 |
| 255 | 241 | * |
| 256 | 242 | * @param array $settings |
| 257 | - * | |
| 258 | 243 | * @return array |
| 259 | 244 | */ |
| 260 | 245 | public function sanitize_post_content( $settings ) { |
| 261 | 246 | $defaults = $this->get_defaults(); |
| @@ -260,17 +245,19 @@ | ||
| 260 | 245 | public function sanitize_post_content( $settings ) { |
| 261 | 246 | $defaults = $this->get_defaults(); |
| 262 | 247 | $valid_keys = array_keys( $defaults ); |
| 263 | 248 | $sanitized_settings = array(); |
| 264 | - | |
| 265 | 249 | foreach ( $valid_keys as $key ) { |
| 266 | - $sanitized_settings[ $key ] = isset( $settings[ $key ] ) ? sanitize_textarea_field( $settings[ $key ] ) : $defaults[ $key ]; | |
| 250 | + if ( isset( $settings[ $key ] ) ) { | |
| 251 | + $sanitized_settings[ $key ] = sanitize_textarea_field( $settings[ $key ] ); | |
| 252 | + } else { | |
| 253 | + $sanitized_settings[ $key ] = $defaults[ $key ]; | |
| 254 | + } | |
| 267 | 255 | |
| 268 | - if ( 'custom_css' !== $key && 'single_style_custom_css' !== $key ) { | |
| 256 | + if ( 'custom_css' !== $key ) { | |
| 269 | 257 | $sanitized_settings[ $key ] = $this->strip_invalid_characters( $sanitized_settings[ $key ] ); |
| 270 | 258 | } |
| 271 | 259 | } |
| 272 | - | |
| 273 | 260 | return $sanitized_settings; |
| 274 | 261 | } |
| 275 | 262 | |
| 276 | 263 | /** |
| @@ -278,9 +265,8 @@ | ||
| 278 | 265 | * |
| 279 | 266 | * @since 6.2.3 |
| 280 | 267 | * |
| 281 | 268 | * @param string $setting |
| 282 | - * | |
| 283 | 269 | * @return string |
| 284 | 270 | */ |
| 285 | 271 | private function strip_invalid_characters( $setting ) { |
| 286 | 272 | $characters_to_remove = array( '{', '}', ';', '[', ']' ); |
| @@ -285,9 +271,9 @@ | ||
| 285 | 271 | private function strip_invalid_characters( $setting ) { |
| 286 | 272 | $characters_to_remove = array( '{', '}', ';', '[', ']' ); |
| 287 | 273 | |
| 288 | 274 | // RGB is handled instead in self::maybe_sanitize_rgba_value. |
| 289 | - if ( ! str_starts_with( $setting, 'rgb' ) ) { | |
| 275 | + if ( 0 !== strpos( $setting, 'rgb' ) ) { | |
| 290 | 276 | $setting = $this->maybe_fix_braces( $setting, $characters_to_remove ); |
| 291 | 277 | } |
| 292 | 278 | |
| 293 | 279 | return str_replace( $characters_to_remove, '', $setting ); |
| @@ -297,9 +283,8 @@ | ||
| 297 | 283 | * @since 6.2.3 |
| 298 | 284 | * |
| 299 | 285 | * @param string $setting |
| 300 | 286 | * @param array $characters_to_remove |
| 301 | - * | |
| 302 | 287 | * @return string |
| 303 | 288 | */ |
| 304 | 289 | private function maybe_fix_braces( $setting, &$characters_to_remove ) { |
| 305 | 290 | $number_of_opening_braces = substr_count( $setting, '(' ); |
| @@ -321,28 +306,23 @@ | ||
| 321 | 306 | /** |
| 322 | 307 | * @since 6.2.3 |
| 323 | 308 | * |
| 324 | 309 | * @param string $input |
| 325 | - * | |
| 326 | 310 | * @return string |
| 327 | 311 | */ |
| 328 | 312 | private function trim_braces( $input ) { |
| 329 | 313 | $output = $input; |
| 330 | - | |
| 331 | 314 | // Remove any ( from the start of the string as no CSS values expect at the first character. |
| 332 | 315 | if ( $output && in_array( $output[0], array( '(', ')' ), true ) ) { |
| 333 | 316 | $output = ltrim( $output, '()' ); |
| 334 | 317 | } |
| 335 | - | |
| 336 | 318 | // Remove extra braces from the end. |
| 337 | 319 | if ( in_array( substr( $output, -1 ), array( '(', ')' ), true ) ) { |
| 338 | 320 | $output = rtrim( $output, '()' ); |
| 339 | - | |
| 340 | - if ( str_contains( $output, '(' ) ) { | |
| 321 | + if ( false !== strpos( $output, '(' ) ) { | |
| 341 | 322 | $output .= ')'; |
| 342 | 323 | } |
| 343 | 324 | } |
| 344 | - | |
| 345 | 325 | return $output; |
| 346 | 326 | } |
| 347 | 327 | |
| 348 | 328 | /** |
| @@ -348,13 +328,12 @@ | ||
| 348 | 328 | /** |
| 349 | 329 | * @since 6.2.3 |
| 350 | 330 | * |
| 351 | 331 | * @param string $setting |
| 352 | - * | |
| 353 | 332 | * @return bool |
| 354 | 333 | */ |
| 355 | 334 | private function should_remove_every_brace( $setting ) { |
| 356 | - if ( str_starts_with( trim( $setting, '()' ), 'calc' ) ) { | |
| 335 | + if ( 0 === strpos( trim( $setting, '()' ), 'calc' ) ) { | |
| 357 | 336 | // Support calc() sizes. We do not want to remove all braces when calc is used. |
| 358 | 337 | return false; |
| 359 | 338 | } |
| 360 | 339 | |
| @@ -359,9 +338,8 @@ | ||
| 359 | 338 | } |
| 360 | 339 | |
| 361 | 340 | // Matches hex values but also checks for unexpected ( and ). |
| 362 | 341 | $looks_like_a_hex_value = preg_match( '/^(?:\()?(?!#?[a-fA-F0-9]*[^\(#\)\da-fA-F])[a-fA-F0-9\(\)]*(?:\))?$/', $setting ); |
| 363 | - | |
| 364 | 342 | if ( $looks_like_a_hex_value ) { |
| 365 | 343 | return true; |
| 366 | 344 | } |
| 367 | 345 | |
| @@ -367,9 +345,13 @@ | ||
| 367 | 345 | |
| 368 | 346 | // Matches size values but also checks for unexpected ( and ). |
| 369 | 347 | // This is case insensitive so it will catch PX, PT, etc, as well. |
| 370 | 348 | $looks_like_a_size = preg_match( '/\(?[+-]?\d*\.?\d+(?:px|%|em|rem|ex|pt|pc|mm|cm|in)\)?/i', $setting ); |
| 371 | - return (bool) $looks_like_a_size; | |
| 349 | + if ( $looks_like_a_size ) { | |
| 350 | + return true; | |
| 351 | + } | |
| 352 | + | |
| 353 | + return false; | |
| 372 | 354 | } |
| 373 | 355 | |
| 374 | 356 | /** |
| 375 | 357 | * @since 3.01.01 |
| @@ -374,17 +356,13 @@ | ||
| 374 | 356 | /** |
| 375 | 357 | * @since 3.01.01 |
| 376 | 358 | * |
| 377 | 359 | * @param string $setting |
| 378 | - * | |
| 379 | 360 | * @return bool |
| 380 | 361 | */ |
| 381 | 362 | private function is_color( $setting ) { |
| 382 | - if ( str_contains( $setting, 'color' ) ) { | |
| 383 | - return true; | |
| 384 | - } | |
| 385 | - | |
| 386 | - return in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ), true ); | |
| 363 | + $extra_colors = array( 'error_bg', 'error_border', 'error_text' ); | |
| 364 | + return strpos( $setting, 'color' ) !== false || in_array( $setting, $extra_colors, true ); | |
| 387 | 365 | } |
| 388 | 366 | |
| 389 | 367 | /** |
| 390 | 368 | * @since 3.01.01 |
| @@ -421,25 +399,26 @@ | ||
| 421 | 399 | ) |
| 422 | 400 | ); |
| 423 | 401 | $create_file->create_file( $css ); |
| 424 | 402 | |
| 425 | - update_option( 'frmpro_css', $css, false ); | |
| 403 | + update_option( 'frmpro_css', $css, 'no' ); | |
| 426 | 404 | set_transient( 'frmpro_css', $css, MONTH_IN_SECONDS ); |
| 427 | 405 | } |
| 428 | 406 | |
| 429 | 407 | /** |
| 430 | 408 | * @param string $filename |
| 431 | - * | |
| 432 | 409 | * @return string |
| 433 | 410 | */ |
| 434 | 411 | private function get_css_content( $filename ) { |
| 435 | - $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n"; | |
| 412 | + $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n"; | |
| 413 | + | |
| 436 | 414 | $saving = true; |
| 437 | 415 | $frm_style = $this; |
| 438 | 416 | |
| 439 | 417 | ob_start(); |
| 440 | 418 | include $filename; |
| 441 | - $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_clean() ) ); | |
| 419 | + $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) ); | |
| 420 | + ob_end_clean(); | |
| 442 | 421 | |
| 443 | 422 | return FrmStylesController::replace_relative_url( $css ); |
| 444 | 423 | } |
| 445 | 424 | |
| @@ -463,9 +442,8 @@ | ||
| 463 | 442 | /** |
| 464 | 443 | * Delete a style by its post ID. |
| 465 | 444 | * |
| 466 | 445 | * @param int $id |
| 467 | - * | |
| 468 | 446 | * @return false|WP_Post|null |
| 469 | 447 | */ |
| 470 | 448 | public function destroy( $id ) { |
| 471 | 449 | if ( $id === $this->get_default_style()->ID ) { |
| @@ -479,11 +457,14 @@ | ||
| 479 | 457 | */ |
| 480 | 458 | public function get_one() { |
| 481 | 459 | if ( 'default' === $this->id ) { |
| 482 | 460 | $style = $this->get_default_style(); |
| 461 | + if ( $style ) { | |
| 462 | + $this->id = $style->ID; | |
| 463 | + } else { | |
| 464 | + $this->id = 0; | |
| 465 | + } | |
| 483 | 466 | |
| 484 | - $this->id = $style ? $style->ID : 0; | |
| 485 | - | |
| 486 | 467 | return $style; |
| 487 | 468 | } |
| 488 | 469 | |
| 489 | 470 | $style = get_post( $this->id ); |
| @@ -495,9 +476,9 @@ | ||
| 495 | 476 | $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content ); |
| 496 | 477 | |
| 497 | 478 | $default_values = $this->get_defaults(); |
| 498 | 479 | |
| 499 | - // Fill default values | |
| 480 | + // fill default values | |
| 500 | 481 | $style->post_content = $this->override_defaults( $style->post_content ); |
| 501 | 482 | $style->post_content = wp_parse_args( $style->post_content, $default_values ); |
| 502 | 483 | |
| 503 | 484 | return $style; |
| @@ -506,9 +487,8 @@ | ||
| 506 | 487 | /** |
| 507 | 488 | * @param string $orderby |
| 508 | 489 | * @param string $order |
| 509 | 490 | * @param int $limit |
| 510 | - * | |
| 511 | 491 | * @return array |
| 512 | 492 | */ |
| 513 | 493 | public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) { |
| 514 | 494 | $post_atts = array( |
| @@ -520,16 +500,16 @@ | ||
| 520 | 500 | ); |
| 521 | 501 | |
| 522 | 502 | $temp_styles = FrmDb::check_cache( json_encode( $post_atts ), 'frm_styles', $post_atts, 'get_posts' ); |
| 523 | 503 | |
| 524 | - if ( ! $temp_styles ) { | |
| 504 | + if ( empty( $temp_styles ) ) { | |
| 525 | 505 | global $wpdb; |
| 526 | - // Make sure there wasn't a conflict with the query | |
| 527 | - $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 506 | + // make sure there wasn't a conflict with the query | |
| 507 | + $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' ); | |
| 528 | 508 | $temp_styles = FrmDb::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' ); |
| 529 | 509 | |
| 530 | - if ( ! $temp_styles ) { | |
| 531 | - // Create a new style if there are none | |
| 510 | + if ( empty( $temp_styles ) ) { | |
| 511 | + // create a new style if there are none | |
| 532 | 512 | $new = $this->get_new(); |
| 533 | 513 | $new->post_title = __( 'Formidable Style', 'formidable' ); |
| 534 | 514 | $new->post_name = $new->post_title; |
| 535 | 515 | $new->menu_order = 1; |
| @@ -536,25 +516,25 @@ | ||
| 536 | 516 | $new = $this->save( (array) $new ); |
| 537 | 517 | $this->update( 'default' ); |
| 538 | 518 | |
| 539 | 519 | $post_atts['include'] = $new; |
| 540 | - $temp_styles = get_posts( $post_atts ); | |
| 520 | + | |
| 521 | + $temp_styles = get_posts( $post_atts ); | |
| 541 | 522 | } |
| 542 | 523 | } |
| 543 | 524 | |
| 544 | 525 | $default_values = $this->get_defaults(); |
| 545 | 526 | $default_style = false; |
| 546 | - $styles = array(); | |
| 547 | 527 | |
| 528 | + $styles = array(); | |
| 548 | 529 | foreach ( $temp_styles as $style ) { |
| 549 | 530 | $this->id = $style->ID; |
| 550 | - | |
| 551 | 531 | if ( $style->menu_order ) { |
| 552 | 532 | if ( $default_style ) { |
| 553 | - // Only return one default | |
| 533 | + // only return one default | |
| 554 | 534 | $style->menu_order = 0; |
| 555 | 535 | } else { |
| 556 | - // Check for a default style | |
| 536 | + // check for a default style | |
| 557 | 537 | $default_style = $style->ID; |
| 558 | 538 | } |
| 559 | 539 | } |
| 560 | 540 | |
| @@ -559,17 +539,18 @@ | ||
| 559 | 539 | } |
| 560 | 540 | |
| 561 | 541 | $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content ); |
| 562 | 542 | |
| 563 | - // Fill default values | |
| 543 | + // fill default values | |
| 564 | 544 | $style->post_content = $this->override_defaults( $style->post_content ); |
| 565 | 545 | $style->post_content = wp_parse_args( $style->post_content, $default_values ); |
| 566 | 546 | |
| 567 | 547 | $styles[ $style->ID ] = $style; |
| 568 | - }//end foreach | |
| 548 | + } | |
| 569 | 549 | |
| 570 | 550 | if ( ! $default_style ) { |
| 571 | - $default_style = reset( $styles ); | |
| 551 | + $default_style = reset( $styles ); | |
| 552 | + | |
| 572 | 553 | $styles[ $default_style->ID ]->menu_order = 1; |
| 573 | 554 | } |
| 574 | 555 | |
| 575 | 556 | return $styles; |
| @@ -576,10 +557,8 @@ | ||
| 576 | 557 | } |
| 577 | 558 | |
| 578 | 559 | /** |
| 579 | 560 | * @param array|null $styles |
| 580 | - * | |
| 581 | - * @return object|null | |
| 582 | 561 | */ |
| 583 | 562 | public function get_default_style( $styles = null ) { |
| 584 | 563 | if ( ! isset( $styles ) ) { |
| 585 | 564 | $styles = $this->get_all( 'menu_order', 'DESC', 1 ); |
| @@ -589,15 +568,12 @@ | ||
| 589 | 568 | if ( $style->menu_order ) { |
| 590 | 569 | return $style; |
| 591 | 570 | } |
| 592 | 571 | } |
| 593 | - | |
| 594 | - return null; | |
| 595 | 572 | } |
| 596 | 573 | |
| 597 | 574 | /** |
| 598 | 575 | * @param mixed $settings |
| 599 | - * | |
| 600 | 576 | * @return mixed |
| 601 | 577 | */ |
| 602 | 578 | public function override_defaults( $settings ) { |
| 603 | 579 | if ( ! is_array( $settings ) ) { |
| @@ -603,9 +579,9 @@ | ||
| 603 | 579 | if ( ! is_array( $settings ) ) { |
| 604 | 580 | return $settings; |
| 605 | 581 | } |
| 606 | 582 | |
| 607 | - $settings['line_height'] = ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] === 'auto' ? 'normal' : $settings['field_height']; // phpcs:ignore Universal.Operators.StrictComparisons, SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 583 | + $settings['line_height'] = ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] === 'auto' ? 'normal' : $settings['field_height']; | |
| 608 | 584 | |
| 609 | 585 | if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) { |
| 610 | 586 | $settings['form_desc_size'] = $settings['description_font_size']; |
| 611 | 587 | $settings['form_desc_color'] = $settings['description_color']; |
| @@ -770,11 +746,8 @@ | ||
| 770 | 746 | 'custom_css' => '', |
| 771 | 747 | 'use_base_font_size' => false, |
| 772 | 748 | 'base_font_size' => '15px', |
| 773 | 749 | 'field_shape_type' => 'rounded-corner', |
| 774 | - | |
| 775 | - 'enable_style_custom_css' => false, | |
| 776 | - 'single_style_custom_css' => '', | |
| 777 | 750 | ); |
| 778 | 751 | |
| 779 | 752 | return apply_filters( 'frm_default_style_settings', $defaults ); |
| 780 | 753 | } |
| @@ -783,13 +756,12 @@ | ||
| 783 | 756 | * Get a name attribute value for a style setting input. |
| 784 | 757 | * |
| 785 | 758 | * @param string $field_name |
| 786 | 759 | * @param string $post_field |
| 787 | - * | |
| 788 | 760 | * @return string |
| 789 | 761 | */ |
| 790 | 762 | public function get_field_name( $field_name, $post_field = 'post_content' ) { |
| 791 | - return 'frm_style_setting' . ( $post_field ? '[' . $post_field . ']' : '' ) . '[' . $field_name . ']'; | |
| 763 | + return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']'; | |
| 792 | 764 | } |
| 793 | 765 | |
| 794 | 766 | /** |
| 795 | 767 | * @return array |
| @@ -811,17 +783,15 @@ | ||
| 811 | 783 | /** |
| 812 | 784 | * Don't let imbalanced font families ruin the whole stylesheet. |
| 813 | 785 | * |
| 814 | 786 | * @param string $value |
| 815 | - * | |
| 816 | 787 | * @return string |
| 817 | 788 | */ |
| 818 | 789 | public function force_balanced_quotation( $value ) { |
| 819 | 790 | $balanced_characters = array( '"', "'" ); |
| 820 | - | |
| 821 | 791 | foreach ( $balanced_characters as $char ) { |
| 822 | 792 | $char_count = substr_count( $value, $char ); |
| 823 | - $is_balanced = $char_count % 2 === 0; | |
| 793 | + $is_balanced = $char_count % 2 == 0; | |
| 824 | 794 | |
| 825 | 795 | if ( $is_balanced ) { |
| 826 | 796 | continue; |
| 827 | 797 | } |
| @@ -831,9 +801,8 @@ | ||
| 831 | 801 | } else { |
| 832 | 802 | $value .= $char; |
| 833 | 803 | } |
| 834 | 804 | } |
| 835 | - | |
| 836 | 805 | return $value; |
| 837 | 806 | } |
| 838 | 807 | |
| 839 | 808 | /** |
| @@ -839,19 +808,16 @@ | ||
| 839 | 808 | /** |
| 840 | 809 | * Get the default template style |
| 841 | 810 | * |
| 842 | 811 | * @since 6.14 |
| 812 | + * @param int $style_id The post type "frm_styles" ID. | |
| 843 | 813 | * |
| 844 | - * @param int|string $style_id The post type "frm_styles" ID. | |
| 845 | - * | |
| 846 | 814 | * @return string The json encoded template data |
| 847 | 815 | */ |
| 848 | 816 | public function get_default_template_style( $style_id ) { |
| 849 | 817 | $default_template = get_post_meta( (int) $style_id, $this->default_template_style_meta_name, true ); |
| 850 | - | |
| 851 | - if ( ! $default_template ) { | |
| 818 | + if ( empty( $default_template ) ) { | |
| 852 | 819 | return FrmAppHelper::prepare_and_encode( $this->get_defaults() ); |
| 853 | 820 | } |
| 854 | - | |
| 855 | 821 | return $default_template; |
| 856 | 822 | } |
| 857 | 823 | } |