| @@ -3,14 +3,35 @@ | ||
| 3 | 3 | die( 'You are not allowed to call this page directly.' ); |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmStyle { |
| 7 | - public $number = false; // Unique ID number of the current instance. | |
| 8 | - public $id = 0; // the id of the post | |
| 9 | 7 | |
| 10 | 8 | /** |
| 11 | - * @param int|string $id The id of the stylsheet or 'default' | |
| 9 | + * The meta name of default template style. | |
| 10 | + * | |
| 11 | + * @since 6.14 | |
| 12 | + * | |
| 13 | + * @var string | |
| 12 | 14 | */ |
| 15 | + private $default_template_style_meta_name = 'frm_style_default'; | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * Unique ID number of the current instance. | |
| 19 | + * | |
| 20 | + * @var int | |
| 21 | + */ | |
| 22 | + public $number = false; | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * The id of the post. | |
| 26 | + * | |
| 27 | + * @var int|string | |
| 28 | + */ | |
| 29 | + public $id = 0; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * @param int|string $id The id of the stylesheet or 'default'. | |
| 33 | + */ | |
| 13 | 34 | public function __construct( $id = 0 ) { |
| 14 | 35 | $this->id = $id; |
| 15 | 36 | } |
| 16 | 37 | |
| @@ -20,10 +41,11 @@ | ||
| 20 | 41 | public function get_new() { |
| 21 | 42 | $this->id = 0; |
| 22 | 43 | |
| 23 | 44 | $max_slug_value = 2147483647; |
| 24 | - $min_slug_value = 37; // we want to have at least 2 characters in the slug | |
| 25 | - $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 ); | |
| 45 | + // We want to have at least 2 characters in the slug. | |
| 46 | + $min_slug_value = 37; | |
| 47 | + $key = base_convert( random_int( $min_slug_value, $max_slug_value ), 10, 36 ); | |
| 26 | 48 | |
| 27 | 49 | $style = array( |
| 28 | 50 | 'post_type' => FrmStylesController::$post_type, |
| 29 | 51 | 'ID' => '', |
| @@ -38,8 +60,9 @@ | ||
| 38 | 60 | } |
| 39 | 61 | |
| 40 | 62 | /** |
| 41 | 63 | * @param array $settings |
| 64 | + * | |
| 42 | 65 | * @return int|WP_Error |
| 43 | 66 | */ |
| 44 | 67 | public function save( $settings ) { |
| 45 | 68 | return FrmDb::save_settings( $settings, 'frm_styles' ); |
| @@ -45,8 +68,10 @@ | ||
| 45 | 68 | return FrmDb::save_settings( $settings, 'frm_styles' ); |
| 46 | 69 | } |
| 47 | 70 | |
| 48 | 71 | /** |
| 72 | + * @param int|string $id The id of the stylesheet or 'default'. | |
| 73 | + * | |
| 49 | 74 | * @return void |
| 50 | 75 | */ |
| 51 | 76 | public function duplicate( $id ) { |
| 52 | 77 | // Duplicating is a pro feature. This is handled in FrmProStyle::duplicate instead. |
| @@ -55,25 +80,27 @@ | ||
| 55 | 80 | /** |
| 56 | 81 | * Handle save actions in the visual styler edit page. |
| 57 | 82 | * |
| 58 | 83 | * @param mixed $id |
| 84 | + * | |
| 59 | 85 | * @return array<int|WP_Error> |
| 60 | 86 | */ |
| 61 | 87 | public function update( $id = 'default' ) { |
| 62 | - $all_instances = $this->get_all(); | |
| 88 | + $all_instances = $this->get_all(); | |
| 89 | + $css_scope_helper = new FrmCssScopeHelper(); | |
| 63 | 90 | |
| 64 | 91 | if ( ! $id ) { |
| 65 | - $new_style = (array) $this->get_new(); | |
| 66 | - $all_instances[] = $new_style; | |
| 92 | + $all_instances[] = (array) $this->get_new(); | |
| 67 | 93 | } |
| 68 | 94 | |
| 69 | 95 | $action_ids = array(); |
| 70 | 96 | |
| 71 | - foreach ( $all_instances as $number => $new_instance ) { | |
| 97 | + foreach ( $all_instances as $new_instance ) { | |
| 72 | 98 | $new_instance = (array) $new_instance; |
| 73 | 99 | $this->id = $new_instance['ID']; |
| 74 | 100 | |
| 75 | - if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 101 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing, Universal.Operators.StrictComparisons | |
| 102 | + if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) { | |
| 76 | 103 | // Don't continue if not saving this style. |
| 77 | 104 | continue; |
| 78 | 105 | } |
| 79 | 106 | |
| @@ -78,9 +105,9 @@ | ||
| 78 | 105 | } |
| 79 | 106 | |
| 80 | 107 | // Custom CSS is no longer used from the default style, but it is still checked if the Global Setting is missing. |
| 81 | 108 | // Preserve the previous value in case Custom CSS has not been saved as a Global Setting yet. |
| 82 | - $custom_css = isset( $new_instance['post_content']['custom_css'] ) ? $new_instance['post_content']['custom_css'] : ''; | |
| 109 | + $custom_css = $new_instance['post_content']['custom_css'] ?? ''; | |
| 83 | 110 | |
| 84 | 111 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 85 | 112 | if ( ! empty( $_POST['frm_style_setting']['post_title'] ) ) { |
| 86 | 113 | // The nonce check happens in FrmStylesController::save_style before this is called. |
| @@ -87,19 +114,28 @@ | ||
| 87 | 114 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 88 | 115 | $new_instance['post_title'] = sanitize_text_field( wp_unslash( $_POST['frm_style_setting']['post_title'] ) ); |
| 89 | 116 | } |
| 90 | 117 | |
| 91 | - $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 | |
| 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 | |
| 92 | 119 | $new_instance['post_content']['custom_css'] = $custom_css; |
| 93 | 120 | unset( $custom_css ); |
| 94 | 121 | |
| 95 | - $new_instance['post_type'] = FrmStylesController::$post_type; | |
| 96 | - $new_instance['post_status'] = 'publish'; | |
| 122 | + $new_instance['post_type'] = FrmStylesController::$post_type; | |
| 123 | + $new_instance['post_status'] = 'publish'; | |
| 97 | 124 | |
| 98 | 125 | if ( ! $id ) { |
| 99 | - $new_instance['post_name'] = $new_instance['post_title']; | |
| 126 | + // For a new style (including a duplicate), the post_name is derived from the title. | |
| 127 | + // Resolve slug uniqueness up front (WordPress appends -2, -3, etc. to duplicate slugs) | |
| 128 | + // so the CSS scope below matches the slug WordPress will actually store. | |
| 129 | + $slug = sanitize_title( $new_instance['post_title'] ); | |
| 130 | + $new_instance['post_name'] = wp_unique_post_slug( $slug, 0, $new_instance['post_status'], $new_instance['post_type'], 0 ); | |
| 100 | 131 | } |
| 101 | 132 | |
| 133 | + if ( ! empty( $new_instance['post_content']['single_style_custom_css'] ) ) { | |
| 134 | + $css_scope = 'frm_style_' . $new_instance['post_name']; | |
| 135 | + $new_instance['post_content']['single_style_custom_css'] = $css_scope_helper->nest( $new_instance['post_content']['single_style_custom_css'], $css_scope ); | |
| 136 | + } | |
| 137 | + | |
| 102 | 138 | $default_settings = $this->get_defaults(); |
| 103 | 139 | |
| 104 | 140 | foreach ( $default_settings as $setting => $default ) { |
| 105 | 141 | if ( ! isset( $new_instance['post_content'][ $setting ] ) ) { |
| @@ -107,9 +143,10 @@ | ||
| 107 | 143 | } |
| 108 | 144 | |
| 109 | 145 | if ( $this->is_color( $setting ) ) { |
| 110 | 146 | $color_val = $new_instance['post_content'][ $setting ]; |
| 111 | - if ( $color_val !== '' && false !== strpos( $color_val, 'rgb' ) ) { | |
| 147 | + | |
| 148 | + if ( $color_val !== '' && str_contains( $color_val, 'rgb' ) ) { | |
| 112 | 149 | // Maybe sanitize if invalid rgba value is entered. |
| 113 | 150 | $this->maybe_sanitize_rgba_value( $color_val ); |
| 114 | 151 | } |
| 115 | 152 | $new_instance['post_content'][ $setting ] = str_replace( '#', '', $color_val ); |
| @@ -119,10 +156,11 @@ | ||
| 119 | 156 | $new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] ); |
| 120 | 157 | } |
| 121 | 158 | } |
| 122 | 159 | |
| 123 | - $action_ids[] = $this->save( $new_instance ); | |
| 124 | - } | |
| 160 | + $new_instance['post_content'] = FrmStylesHelper::update_base_font_size( $new_instance['post_content'], $this->get_defaults() ); | |
| 161 | + $action_ids[] = $this->save( $new_instance ); | |
| 162 | + }//end foreach | |
| 125 | 163 | |
| 126 | 164 | $this->save_settings(); |
| 127 | 165 | |
| 128 | 166 | return $action_ids; |
| @@ -132,19 +170,22 @@ | ||
| 132 | 170 | * Sanitize custom color values and convert it to valid one filling missing values. |
| 133 | 171 | * |
| 134 | 172 | * @since 5.3.2 |
| 135 | 173 | * |
| 136 | - * @param string $color_val, The color value, by reference. | |
| 174 | + * @param string $color_val The color value, by reference. | |
| 175 | + * | |
| 137 | 176 | * @return void |
| 138 | 177 | */ |
| 139 | - private function maybe_sanitize_rgba_value( &$color_val ) { | |
| 178 | + private function maybe_sanitize_rgba_value( &$color_val ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh | |
| 140 | 179 | if ( preg_match( '/(rgb|rgba)\(/', $color_val ) !== 1 ) { |
| 141 | 180 | return; |
| 142 | 181 | } |
| 143 | 182 | |
| 144 | 183 | $color_val = trim( $color_val ); |
| 145 | - $color_val = ltrim( $color_val, '(' ); // Remove leading braces so (rgba(1,1,1,1) doesn't cause inconsistent braces. | |
| 184 | + // Remove leading braces so (rgba(1,1,1,1) doesn't cause inconsistent braces. | |
| 185 | + $color_val = ltrim( $color_val, '(' ); | |
| 146 | 186 | $patterns = array( '/rgba\((\s*\d+\s*,){3}[[0-1]\.]+\)/', '/rgb\((\s*\d+\s*,){2}\s*[\d]+\)/' ); |
| 187 | + | |
| 147 | 188 | foreach ( $patterns as $pattern ) { |
| 148 | 189 | if ( preg_match( $pattern, $color_val ) === 1 ) { |
| 149 | 190 | return; |
| 150 | 191 | } |
| @@ -153,10 +194,11 @@ | ||
| 153 | 194 | // Remove all leading ')' braces, then add one back. This way there's always a single brace. |
| 154 | 195 | $color_val = rtrim( $color_val, ')' ); |
| 155 | 196 | $color_val .= ')'; |
| 156 | 197 | |
| 157 | - $color_rgba = substr( $color_val, strpos( $color_val, '(' ) + 1, strlen( $color_val ) - strpos( $color_val, '(' ) - 2 ); | |
| 158 | - $color_rgba = trim( $color_rgba, '()' ); // Remove any excessive braces from the rgba like rgba((. | |
| 198 | + $color_rgba = substr( $color_val, strpos( $color_val, '(' ) + 1, strlen( $color_val ) - strpos( $color_val, '(' ) - 2 ); | |
| 199 | + // Remove any excessive braces from the rgba like rgba((. | |
| 200 | + $color_rgba = trim( $color_rgba, '()' ); | |
| 159 | 201 | $length_of_color_codes = strpos( $color_val, '(' ); |
| 160 | 202 | $new_color_values = array(); |
| 161 | 203 | |
| 162 | 204 | // replace empty values by 0 or 1 (if alpha position). |
| @@ -163,9 +205,9 @@ | ||
| 163 | 205 | foreach ( explode( ',', $color_rgba ) as $index => $value ) { |
| 164 | 206 | $new_value = null; |
| 165 | 207 | $value_is_empty_string = '' === trim( $value ) || '' === $value; |
| 166 | 208 | |
| 167 | - if ( 3 === $length_of_color_codes || ( $index !== $length_of_color_codes - 1 ) ) { | |
| 209 | + if ( 3 === $length_of_color_codes || $index !== $length_of_color_codes - 1 ) { | |
| 168 | 210 | // Insert a value for r, g, or b. |
| 169 | 211 | if ( $value < 0 ) { |
| 170 | 212 | $new_value = 0; |
| 171 | 213 | } elseif ( $value > 255 ) { |
| @@ -174,9 +216,9 @@ | ||
| 174 | 216 | $new_value = 0; |
| 175 | 217 | } else { |
| 176 | 218 | $new_value = absint( $value ); |
| 177 | 219 | } |
| 178 | - } else { | |
| 220 | + } else { // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found | |
| 179 | 221 | // Insert a value for alpha. |
| 180 | 222 | if ( $value_is_empty_string ) { |
| 181 | 223 | $new_value = 4 === $length_of_color_codes ? 1 : 0; |
| 182 | 224 | } elseif ( $value > 1 || $value < 0 ) { |
| @@ -183,15 +225,16 @@ | ||
| 183 | 225 | $new_value = 1; |
| 184 | 226 | } else { |
| 185 | 227 | $new_value = floatval( $value ); |
| 186 | 228 | } |
| 187 | - } | |
| 229 | + }//end if | |
| 188 | 230 | |
| 189 | - $new_color_values[] = null === $new_value ? $value : $new_value; | |
| 190 | - } | |
| 231 | + $new_color_values[] = $new_value; | |
| 232 | + }//end foreach | |
| 191 | 233 | |
| 192 | 234 | // add more 0s and 1 (if alpha position) if needed. |
| 193 | 235 | $missing_values = $length_of_color_codes - count( $new_color_values ); |
| 236 | + | |
| 194 | 237 | if ( $missing_values > 1 ) { |
| 195 | 238 | $insert_values = array_fill( 0, $missing_values - 1, 0 ); |
| 196 | 239 | $last_value = 4 === $length_of_color_codes ? 1 : 0; |
| 197 | 240 | array_push( $insert_values, $last_value ); |
| @@ -197,8 +240,9 @@ | ||
| 197 | 240 | array_push( $insert_values, $last_value ); |
| 198 | 241 | } elseif ( $missing_values === 1 ) { |
| 199 | 242 | $insert_values = 4 === $length_of_color_codes ? array( 1 ) : array( 0 ); |
| 200 | 243 | } |
| 244 | + | |
| 201 | 245 | if ( ! empty( $insert_values ) ) { |
| 202 | 246 | $new_color_values = array_merge( $new_color_values, $insert_values ); |
| 203 | 247 | } |
| 204 | 248 | |
| @@ -203,33 +247,19 @@ | ||
| 203 | 247 | } |
| 204 | 248 | |
| 205 | 249 | $new_color = implode( ',', $new_color_values ); |
| 206 | 250 | $prefix = substr( $color_val, 0, strpos( $color_val, '(' ) + 1 ); |
| 207 | - $prefix = rtrim( $prefix, '(' ) . '('; // Limit the number of opening braces after rgb/rgba. There should only be one. | |
| 251 | + // Limit the number of opening braces after rgb/rgba. There should only be one. | |
| 252 | + $prefix = rtrim( $prefix, '(' ) . '('; | |
| 208 | 253 | $new_color = $prefix . $new_color . ')'; |
| 209 | - | |
| 210 | 254 | $color_val = $new_color; |
| 211 | 255 | } |
| 212 | 256 | |
| 213 | 257 | /** |
| 214 | - * Unslash everything in post_content but custom_css | |
| 215 | - * | |
| 216 | 258 | * @since 5.0.13 |
| 217 | 259 | * |
| 218 | 260 | * @param array $settings |
| 219 | - * @return array | |
| 220 | - */ | |
| 221 | - private function unslash_post_content( $settings ) { | |
| 222 | - $custom_css = isset( $settings['custom_css'] ) ? $settings['custom_css'] : ''; | |
| 223 | - $settings = wp_unslash( $settings ); | |
| 224 | - $settings['custom_css'] = $custom_css; | |
| 225 | - return $settings; | |
| 226 | - } | |
| 227 | - | |
| 228 | - /** | |
| 229 | - * @since 5.0.13 | |
| 230 | 261 | * |
| 231 | - * @param array $settings | |
| 232 | 262 | * @return array |
| 233 | 263 | */ |
| 234 | 264 | public function sanitize_post_content( $settings ) { |
| 235 | 265 | $defaults = $this->get_defaults(); |
| @@ -234,19 +264,17 @@ | ||
| 234 | 264 | public function sanitize_post_content( $settings ) { |
| 235 | 265 | $defaults = $this->get_defaults(); |
| 236 | 266 | $valid_keys = array_keys( $defaults ); |
| 237 | 267 | $sanitized_settings = array(); |
| 268 | + | |
| 238 | 269 | foreach ( $valid_keys as $key ) { |
| 239 | - if ( isset( $settings[ $key ] ) ) { | |
| 240 | - $sanitized_settings[ $key ] = sanitize_textarea_field( $settings[ $key ] ); | |
| 241 | - } else { | |
| 242 | - $sanitized_settings[ $key ] = $defaults[ $key ]; | |
| 243 | - } | |
| 270 | + $sanitized_settings[ $key ] = isset( $settings[ $key ] ) ? sanitize_textarea_field( $settings[ $key ] ) : $defaults[ $key ]; | |
| 244 | 271 | |
| 245 | - if ( 'custom_css' !== $key ) { | |
| 272 | + if ( 'custom_css' !== $key && 'single_style_custom_css' !== $key ) { | |
| 246 | 273 | $sanitized_settings[ $key ] = $this->strip_invalid_characters( $sanitized_settings[ $key ] ); |
| 247 | 274 | } |
| 248 | 275 | } |
| 276 | + | |
| 249 | 277 | return $sanitized_settings; |
| 250 | 278 | } |
| 251 | 279 | |
| 252 | 280 | /** |
| @@ -254,8 +282,9 @@ | ||
| 254 | 282 | * |
| 255 | 283 | * @since 6.2.3 |
| 256 | 284 | * |
| 257 | 285 | * @param string $setting |
| 286 | + * | |
| 258 | 287 | * @return string |
| 259 | 288 | */ |
| 260 | 289 | private function strip_invalid_characters( $setting ) { |
| 261 | 290 | $characters_to_remove = array( '{', '}', ';', '[', ']' ); |
| @@ -260,9 +289,9 @@ | ||
| 260 | 289 | private function strip_invalid_characters( $setting ) { |
| 261 | 290 | $characters_to_remove = array( '{', '}', ';', '[', ']' ); |
| 262 | 291 | |
| 263 | 292 | // RGB is handled instead in self::maybe_sanitize_rgba_value. |
| 264 | - if ( 0 !== strpos( $setting, 'rgb' ) ) { | |
| 293 | + if ( ! str_starts_with( $setting, 'rgb' ) ) { | |
| 265 | 294 | $setting = $this->maybe_fix_braces( $setting, $characters_to_remove ); |
| 266 | 295 | } |
| 267 | 296 | |
| 268 | 297 | return str_replace( $characters_to_remove, '', $setting ); |
| @@ -272,8 +301,9 @@ | ||
| 272 | 301 | * @since 6.2.3 |
| 273 | 302 | * |
| 274 | 303 | * @param string $setting |
| 275 | 304 | * @param array $characters_to_remove |
| 305 | + * | |
| 276 | 306 | * @return string |
| 277 | 307 | */ |
| 278 | 308 | private function maybe_fix_braces( $setting, &$characters_to_remove ) { |
| 279 | 309 | $number_of_opening_braces = substr_count( $setting, '(' ); |
| @@ -295,25 +325,28 @@ | ||
| 295 | 325 | /** |
| 296 | 326 | * @since 6.2.3 |
| 297 | 327 | * |
| 298 | 328 | * @param string $input |
| 329 | + * | |
| 299 | 330 | * @return string |
| 300 | 331 | */ |
| 301 | 332 | private function trim_braces( $input ) { |
| 302 | 333 | $output = $input; |
| 334 | + | |
| 303 | 335 | // Remove any ( from the start of the string as no CSS values expect at the first character. |
| 304 | - if ( $output ) { | |
| 305 | - if ( in_array( $output[0], array( '(', ')' ), true ) ) { | |
| 306 | - $output = ltrim( $output, '()' ); | |
| 307 | - } | |
| 336 | + if ( $output && in_array( $output[0], array( '(', ')' ), true ) ) { | |
| 337 | + $output = ltrim( $output, '()' ); | |
| 308 | 338 | } |
| 339 | + | |
| 309 | 340 | // Remove extra braces from the end. |
| 310 | 341 | if ( in_array( substr( $output, -1 ), array( '(', ')' ), true ) ) { |
| 311 | 342 | $output = rtrim( $output, '()' ); |
| 312 | - if ( false !== strpos( $output, '(' ) ) { | |
| 343 | + | |
| 344 | + if ( str_contains( $output, '(' ) ) { | |
| 313 | 345 | $output .= ')'; |
| 314 | 346 | } |
| 315 | 347 | } |
| 348 | + | |
| 316 | 349 | return $output; |
| 317 | 350 | } |
| 318 | 351 | |
| 319 | 352 | /** |
| @@ -319,12 +352,13 @@ | ||
| 319 | 352 | /** |
| 320 | 353 | * @since 6.2.3 |
| 321 | 354 | * |
| 322 | 355 | * @param string $setting |
| 356 | + * | |
| 323 | 357 | * @return bool |
| 324 | 358 | */ |
| 325 | 359 | private function should_remove_every_brace( $setting ) { |
| 326 | - if ( 0 === strpos( trim( $setting, '()' ), 'calc' ) ) { | |
| 360 | + if ( str_starts_with( trim( $setting, '()' ), 'calc' ) ) { | |
| 327 | 361 | // Support calc() sizes. We do not want to remove all braces when calc is used. |
| 328 | 362 | return false; |
| 329 | 363 | } |
| 330 | 364 | |
| @@ -329,8 +363,9 @@ | ||
| 329 | 363 | } |
| 330 | 364 | |
| 331 | 365 | // Matches hex values but also checks for unexpected ( and ). |
| 332 | 366 | $looks_like_a_hex_value = preg_match( '/^(?:\()?(?!#?[a-fA-F0-9]*[^\(#\)\da-fA-F])[a-fA-F0-9\(\)]*(?:\))?$/', $setting ); |
| 367 | + | |
| 333 | 368 | if ( $looks_like_a_hex_value ) { |
| 334 | 369 | return true; |
| 335 | 370 | } |
| 336 | 371 | |
| @@ -336,13 +371,9 @@ | ||
| 336 | 371 | |
| 337 | 372 | // Matches size values but also checks for unexpected ( and ). |
| 338 | 373 | // This is case insensitive so it will catch PX, PT, etc, as well. |
| 339 | 374 | $looks_like_a_size = preg_match( '/\(?[+-]?\d*\.?\d+(?:px|%|em|rem|ex|pt|pc|mm|cm|in)\)?/i', $setting ); |
| 340 | - if ( $looks_like_a_size ) { | |
| 341 | - return true; | |
| 342 | - } | |
| 343 | - | |
| 344 | - return false; | |
| 375 | + return (bool) $looks_like_a_size; | |
| 345 | 376 | } |
| 346 | 377 | |
| 347 | 378 | /** |
| 348 | 379 | * @since 3.01.01 |
| @@ -347,13 +378,17 @@ | ||
| 347 | 378 | /** |
| 348 | 379 | * @since 3.01.01 |
| 349 | 380 | * |
| 350 | 381 | * @param string $setting |
| 382 | + * | |
| 351 | 383 | * @return bool |
| 352 | 384 | */ |
| 353 | 385 | private function is_color( $setting ) { |
| 354 | - $extra_colors = array( 'error_bg', 'error_border', 'error_text' ); | |
| 355 | - return strpos( $setting, 'color' ) !== false || in_array( $setting, $extra_colors, true ); | |
| 386 | + if ( str_contains( $setting, 'color' ) ) { | |
| 387 | + return true; | |
| 388 | + } | |
| 389 | + | |
| 390 | + return in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ), true ); | |
| 356 | 391 | } |
| 357 | 392 | |
| 358 | 393 | /** |
| 359 | 394 | * @since 3.01.01 |
| @@ -360,11 +395,9 @@ | ||
| 360 | 395 | * |
| 361 | 396 | * @return array |
| 362 | 397 | */ |
| 363 | 398 | public function get_color_settings() { |
| 364 | - $defaults = $this->get_defaults(); | |
| 365 | - $settings = array_keys( $defaults ); | |
| 366 | - | |
| 399 | + $settings = array_keys( $this->get_defaults() ); | |
| 367 | 400 | return array_filter( $settings, array( $this, 'is_color' ) ); |
| 368 | 401 | } |
| 369 | 402 | |
| 370 | 403 | /** |
| @@ -382,34 +415,95 @@ | ||
| 382 | 415 | |
| 383 | 416 | $this->clear_cache(); |
| 384 | 417 | |
| 385 | 418 | $css = $this->get_css_content( $filename ); |
| 386 | - $create_file = new FrmCreateFile( | |
| 387 | - array( | |
| 388 | - 'file_name' => FrmStylesController::get_file_name(), | |
| 389 | - 'new_file_path' => FrmAppHelper::plugin_path() . '/css', | |
| 390 | - ) | |
| 391 | - ); | |
| 419 | + $create_file = new FrmCreateFile( self::get_create_style_file_args() ); | |
| 392 | 420 | $create_file->create_file( $css ); |
| 393 | 421 | |
| 394 | - update_option( 'frmpro_css', $css, 'no' ); | |
| 422 | + update_option( 'frmpro_css', $css, false ); | |
| 395 | 423 | set_transient( 'frmpro_css', $css, MONTH_IN_SECONDS ); |
| 396 | 424 | } |
| 397 | 425 | |
| 398 | 426 | /** |
| 427 | + * @since 6.32 | |
| 428 | + * | |
| 429 | + * @return array | |
| 430 | + */ | |
| 431 | + private static function get_create_style_file_args() { | |
| 432 | + $add_css_to_uploads_dir = self::add_css_to_uploads_dir(); | |
| 433 | + $create_file_args = array( | |
| 434 | + 'file_name' => FrmStylesController::get_file_name(), | |
| 435 | + 'new_file_path' => self::get_generated_css_file_path( $add_css_to_uploads_dir ), | |
| 436 | + ); | |
| 437 | + | |
| 438 | + if ( $add_css_to_uploads_dir ) { | |
| 439 | + $create_file_args['folder_name'] = 'formidable/css'; | |
| 440 | + } | |
| 441 | + | |
| 442 | + return $create_file_args; | |
| 443 | + } | |
| 444 | + | |
| 445 | + /** | |
| 446 | + * @since 6.32 | |
| 447 | + * | |
| 448 | + * @param bool $add_css_to_uploads_dir | |
| 449 | + * | |
| 450 | + * @return string | |
| 451 | + */ | |
| 452 | + public static function get_generated_css_file_path( $add_css_to_uploads_dir ) { | |
| 453 | + if ( $add_css_to_uploads_dir ) { | |
| 454 | + return self::target_css_uploads_dir(); | |
| 455 | + } | |
| 456 | + return self::target_css_plugin_dir(); | |
| 457 | + } | |
| 458 | + | |
| 459 | + /** | |
| 460 | + * Returns true if generated css file should be saved in the uploads directory. | |
| 461 | + * | |
| 462 | + * @since 6.32 | |
| 463 | + * | |
| 464 | + * @return bool | |
| 465 | + */ | |
| 466 | + public static function add_css_to_uploads_dir() { | |
| 467 | + /** | |
| 468 | + * @since 6.32 | |
| 469 | + * | |
| 470 | + * @param bool $add_css_to_uploads_dir | |
| 471 | + */ | |
| 472 | + return apply_filters( 'frm_add_css_to_uploads_dir', ! wp_is_file_mod_allowed( 'frm_save_css_to_plugin_folder' ) ); | |
| 473 | + } | |
| 474 | + | |
| 475 | + /** | |
| 476 | + * @since 6.32 | |
| 477 | + * | |
| 478 | + * @return string | |
| 479 | + */ | |
| 480 | + private static function target_css_uploads_dir() { | |
| 481 | + return wp_upload_dir()['basedir'] . '/formidable/css'; | |
| 482 | + } | |
| 483 | + | |
| 484 | + /** | |
| 485 | + * @since 6.32 | |
| 486 | + * | |
| 487 | + * @return string | |
| 488 | + */ | |
| 489 | + private static function target_css_plugin_dir() { | |
| 490 | + return FrmAppHelper::plugin_path() . '/css'; | |
| 491 | + } | |
| 492 | + | |
| 493 | + /** | |
| 399 | 494 | * @param string $filename |
| 495 | + * | |
| 400 | 496 | * @return string |
| 401 | 497 | */ |
| 402 | 498 | private function get_css_content( $filename ) { |
| 403 | - $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n"; | |
| 404 | - | |
| 499 | + $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n"; | |
| 405 | 500 | $saving = true; |
| 406 | 501 | $frm_style = $this; |
| 407 | 502 | |
| 408 | 503 | ob_start(); |
| 409 | 504 | include $filename; |
| 410 | - $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) ); | |
| 411 | - ob_end_clean(); | |
| 505 | + $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_clean() ) ); | |
| 412 | 506 | |
| 413 | 507 | return FrmStylesController::replace_relative_url( $css ); |
| 414 | 508 | } |
| 415 | 509 | |
| @@ -433,9 +527,10 @@ | ||
| 433 | 527 | /** |
| 434 | 528 | * Delete a style by its post ID. |
| 435 | 529 | * |
| 436 | 530 | * @param int $id |
| 437 | - * @return WP_Post|false|null | |
| 531 | + * | |
| 532 | + * @return false|WP_Post|null | |
| 438 | 533 | */ |
| 439 | 534 | public function destroy( $id ) { |
| 440 | 535 | if ( $id === $this->get_default_style()->ID ) { |
| 441 | 536 | return false; |
| @@ -443,19 +538,16 @@ | ||
| 443 | 538 | return wp_delete_post( $id ); |
| 444 | 539 | } |
| 445 | 540 | |
| 446 | 541 | /** |
| 447 | - * @return WP_Post|stdClass | |
| 542 | + * @return stdClass|WP_Post | |
| 448 | 543 | */ |
| 449 | 544 | public function get_one() { |
| 450 | 545 | if ( 'default' === $this->id ) { |
| 451 | 546 | $style = $this->get_default_style(); |
| 452 | - if ( $style ) { | |
| 453 | - $this->id = $style->ID; | |
| 454 | - } else { | |
| 455 | - $this->id = 0; | |
| 456 | - } | |
| 457 | 547 | |
| 548 | + $this->id = $style ? $style->ID : 0; | |
| 549 | + | |
| 458 | 550 | return $style; |
| 459 | 551 | } |
| 460 | 552 | |
| 461 | 553 | $style = get_post( $this->id ); |
| @@ -467,9 +559,9 @@ | ||
| 467 | 559 | $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content ); |
| 468 | 560 | |
| 469 | 561 | $default_values = $this->get_defaults(); |
| 470 | 562 | |
| 471 | - // fill default values | |
| 563 | + // Fill default values | |
| 472 | 564 | $style->post_content = $this->override_defaults( $style->post_content ); |
| 473 | 565 | $style->post_content = wp_parse_args( $style->post_content, $default_values ); |
| 474 | 566 | |
| 475 | 567 | return $style; |
| @@ -478,8 +570,9 @@ | ||
| 478 | 570 | /** |
| 479 | 571 | * @param string $orderby |
| 480 | 572 | * @param string $order |
| 481 | 573 | * @param int $limit |
| 574 | + * | |
| 482 | 575 | * @return array |
| 483 | 576 | */ |
| 484 | 577 | public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) { |
| 485 | 578 | $post_atts = array( |
| @@ -491,16 +584,16 @@ | ||
| 491 | 584 | ); |
| 492 | 585 | |
| 493 | 586 | $temp_styles = FrmDb::check_cache( json_encode( $post_atts ), 'frm_styles', $post_atts, 'get_posts' ); |
| 494 | 587 | |
| 495 | - if ( empty( $temp_styles ) ) { | |
| 588 | + if ( ! $temp_styles ) { | |
| 496 | 589 | global $wpdb; |
| 497 | - // make sure there wasn't a conflict with the query | |
| 498 | - $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' ); | |
| 590 | + // Make sure there wasn't a conflict with the query | |
| 591 | + $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 | |
| 499 | 592 | $temp_styles = FrmDb::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' ); |
| 500 | 593 | |
| 501 | - if ( empty( $temp_styles ) ) { | |
| 502 | - // create a new style if there are none | |
| 594 | + if ( ! $temp_styles ) { | |
| 595 | + // Create a new style if there are none | |
| 503 | 596 | $new = $this->get_new(); |
| 504 | 597 | $new->post_title = __( 'Formidable Style', 'formidable' ); |
| 505 | 598 | $new->post_name = $new->post_title; |
| 506 | 599 | $new->menu_order = 1; |
| @@ -507,25 +600,25 @@ | ||
| 507 | 600 | $new = $this->save( (array) $new ); |
| 508 | 601 | $this->update( 'default' ); |
| 509 | 602 | |
| 510 | 603 | $post_atts['include'] = $new; |
| 511 | - | |
| 512 | - $temp_styles = get_posts( $post_atts ); | |
| 604 | + $temp_styles = get_posts( $post_atts ); | |
| 513 | 605 | } |
| 514 | 606 | } |
| 515 | 607 | |
| 516 | 608 | $default_values = $this->get_defaults(); |
| 517 | 609 | $default_style = false; |
| 610 | + $styles = array(); | |
| 518 | 611 | |
| 519 | - $styles = array(); | |
| 520 | 612 | foreach ( $temp_styles as $style ) { |
| 521 | 613 | $this->id = $style->ID; |
| 614 | + | |
| 522 | 615 | if ( $style->menu_order ) { |
| 523 | 616 | if ( $default_style ) { |
| 524 | - // only return one default | |
| 617 | + // Only return one default | |
| 525 | 618 | $style->menu_order = 0; |
| 526 | 619 | } else { |
| 527 | - // check for a default style | |
| 620 | + // Check for a default style | |
| 528 | 621 | $default_style = $style->ID; |
| 529 | 622 | } |
| 530 | 623 | } |
| 531 | 624 | |
| @@ -530,18 +623,17 @@ | ||
| 530 | 623 | } |
| 531 | 624 | |
| 532 | 625 | $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content ); |
| 533 | 626 | |
| 534 | - // fill default values | |
| 627 | + // Fill default values | |
| 535 | 628 | $style->post_content = $this->override_defaults( $style->post_content ); |
| 536 | 629 | $style->post_content = wp_parse_args( $style->post_content, $default_values ); |
| 537 | 630 | |
| 538 | 631 | $styles[ $style->ID ] = $style; |
| 539 | - } | |
| 632 | + }//end foreach | |
| 540 | 633 | |
| 541 | 634 | if ( ! $default_style ) { |
| 542 | - $default_style = reset( $styles ); | |
| 543 | - | |
| 635 | + $default_style = reset( $styles ); | |
| 544 | 636 | $styles[ $default_style->ID ]->menu_order = 1; |
| 545 | 637 | } |
| 546 | 638 | |
| 547 | 639 | return $styles; |
| @@ -548,8 +640,10 @@ | ||
| 548 | 640 | } |
| 549 | 641 | |
| 550 | 642 | /** |
| 551 | 643 | * @param array|null $styles |
| 644 | + * | |
| 645 | + * @return object|null | |
| 552 | 646 | */ |
| 553 | 647 | public function get_default_style( $styles = null ) { |
| 554 | 648 | if ( ! isset( $styles ) ) { |
| 555 | 649 | $styles = $this->get_all( 'menu_order', 'DESC', 1 ); |
| @@ -559,12 +653,15 @@ | ||
| 559 | 653 | if ( $style->menu_order ) { |
| 560 | 654 | return $style; |
| 561 | 655 | } |
| 562 | 656 | } |
| 657 | + | |
| 658 | + return null; | |
| 563 | 659 | } |
| 564 | 660 | |
| 565 | 661 | /** |
| 566 | 662 | * @param mixed $settings |
| 663 | + * | |
| 567 | 664 | * @return mixed |
| 568 | 665 | */ |
| 569 | 666 | public function override_defaults( $settings ) { |
| 570 | 667 | if ( ! is_array( $settings ) ) { |
| @@ -570,9 +667,9 @@ | ||
| 570 | 667 | if ( ! is_array( $settings ) ) { |
| 571 | 668 | return $settings; |
| 572 | 669 | } |
| 573 | 670 | |
| 574 | - $settings['line_height'] = ( ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] == 'auto' ) ? 'normal' : $settings['field_height']; | |
| 671 | + $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 | |
| 575 | 672 | |
| 576 | 673 | if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) { |
| 577 | 674 | $settings['form_desc_size'] = $settings['description_font_size']; |
| 578 | 675 | $settings['form_desc_color'] = $settings['description_color']; |
| @@ -601,142 +698,147 @@ | ||
| 601 | 698 | * @return array |
| 602 | 699 | */ |
| 603 | 700 | public function get_defaults() { |
| 604 | 701 | $defaults = array( |
| 605 | - 'theme_css' => 'ui-lightness', | |
| 606 | - 'theme_name' => 'UI Lightness', | |
| 702 | + 'theme_css' => 'ui-lightness', | |
| 703 | + 'theme_name' => 'UI Lightness', | |
| 607 | 704 | |
| 608 | - 'center_form' => '', | |
| 609 | - 'form_width' => '100%', | |
| 610 | - 'form_align' => 'left', | |
| 611 | - 'direction' => is_rtl() ? 'rtl' : 'ltr', | |
| 612 | - 'fieldset' => '0px', | |
| 613 | - 'fieldset_color' => '000000', | |
| 614 | - 'fieldset_padding' => '0 0 15px 0', | |
| 615 | - 'fieldset_bg_color' => '', | |
| 705 | + 'center_form' => '', | |
| 706 | + 'form_width' => '100%', | |
| 707 | + 'form_align' => 'left', | |
| 708 | + 'direction' => is_rtl() ? 'rtl' : 'ltr', | |
| 709 | + 'fieldset' => '0px', | |
| 710 | + 'fieldset_color' => '000000', | |
| 711 | + 'fieldset_padding' => '0px 0px 15px 0px', | |
| 712 | + 'fieldset_bg_color' => '', | |
| 616 | 713 | |
| 617 | - 'title_size' => '40px', | |
| 618 | - 'title_color' => '444444', | |
| 619 | - 'title_margin_top' => '10px', | |
| 620 | - 'title_margin_bottom' => '60px', | |
| 621 | - 'form_desc_size' => '14px', | |
| 622 | - 'form_desc_color' => '666666', | |
| 623 | - 'form_desc_margin_top' => '10px', | |
| 624 | - 'form_desc_margin_bottom' => '25px', | |
| 625 | - 'form_desc_padding' => '0', | |
| 714 | + 'title_size' => '40px', | |
| 715 | + 'title_color' => '444444', | |
| 716 | + 'title_margin_top' => '10px', | |
| 717 | + 'title_margin_bottom' => '60px', | |
| 718 | + 'form_desc_size' => '14px', | |
| 719 | + 'form_desc_color' => '98A2B3', | |
| 720 | + 'form_desc_margin_top' => '10px', | |
| 721 | + 'form_desc_margin_bottom' => '25px', | |
| 722 | + 'form_desc_padding' => '0px', | |
| 626 | 723 | |
| 627 | - 'font' => '', | |
| 628 | - 'font_size' => '15px', | |
| 629 | - 'label_color' => '3f4b5b', | |
| 630 | - 'weight' => 'normal', | |
| 631 | - 'position' => 'none', | |
| 632 | - 'align' => 'left', | |
| 633 | - 'width' => '150px', | |
| 634 | - 'required_color' => 'B94A48', | |
| 635 | - 'required_weight' => 'bold', | |
| 636 | - 'label_padding' => '0 0 3px 0', | |
| 724 | + 'font' => '', | |
| 725 | + 'font_size' => '15px', | |
| 726 | + 'label_color' => '344054', | |
| 727 | + 'weight' => 'normal', | |
| 728 | + 'position' => 'none', | |
| 729 | + 'align' => 'left', | |
| 730 | + 'width' => '150px', | |
| 731 | + 'required_color' => 'F04438', | |
| 732 | + 'required_weight' => 'bold', | |
| 733 | + 'label_padding' => '0px 0px 5px 0px', | |
| 637 | 734 | |
| 638 | - 'description_font_size' => '12px', | |
| 639 | - 'description_color' => '666666', | |
| 640 | - 'description_weight' => 'normal', | |
| 641 | - 'description_style' => 'normal', | |
| 642 | - 'description_align' => 'left', | |
| 643 | - 'description_margin' => '0', | |
| 735 | + 'description_font_size' => '12px', | |
| 736 | + 'description_color' => '667085', | |
| 737 | + 'description_weight' => 'normal', | |
| 738 | + 'description_style' => 'normal', | |
| 739 | + 'description_align' => 'left', | |
| 740 | + 'description_margin' => '0px', | |
| 644 | 741 | |
| 645 | - 'field_font_size' => '14px', | |
| 646 | - 'field_height' => '32px', | |
| 647 | - 'line_height' => 'normal', | |
| 648 | - 'field_width' => '100%', | |
| 649 | - 'auto_width' => false, | |
| 650 | - 'field_pad' => '6px 10px', | |
| 651 | - 'field_margin' => '20px', | |
| 652 | - 'field_weight' => 'normal', | |
| 653 | - 'text_color' => '555555', | |
| 654 | - //'border_color_hv' => 'cccccc', | |
| 655 | - 'border_color' => 'BFC3C8', | |
| 656 | - 'field_border_width' => '1px', | |
| 657 | - 'field_border_style' => 'solid', | |
| 742 | + 'field_font_size' => '14px', | |
| 743 | + 'field_height' => '36px', | |
| 744 | + 'line_height' => 'normal', | |
| 745 | + 'field_width' => '100%', | |
| 746 | + 'auto_width' => false, | |
| 747 | + 'field_pad' => '8px 12px', | |
| 748 | + 'field_margin' => '20px', | |
| 749 | + 'field_weight' => 'normal', | |
| 750 | + 'text_color' => '1D2939', | |
| 751 | + // 'border_color_hv' => 'cccccc', | |
| 752 | + 'border_color' => 'D0D5DD', | |
| 753 | + 'field_border_width' => '1px', | |
| 754 | + 'field_border_style' => 'solid', | |
| 658 | 755 | |
| 659 | - 'bg_color' => 'ffffff', | |
| 660 | - //'bg_color_hv' => 'ffffff', | |
| 661 | - 'remove_box_shadow' => '', | |
| 662 | - 'bg_color_active' => 'ffffff', | |
| 663 | - 'border_color_active' => '66afe9', | |
| 664 | - 'remove_box_shadow_active' => '', | |
| 665 | - 'text_color_error' => '444444', | |
| 666 | - 'bg_color_error' => 'ffffff', | |
| 667 | - 'border_color_error' => 'B94A48', | |
| 668 | - 'border_width_error' => '1px', | |
| 669 | - 'border_style_error' => 'solid', | |
| 670 | - 'bg_color_disabled' => 'ffffff', | |
| 671 | - 'border_color_disabled' => 'E5E5E5', | |
| 672 | - 'text_color_disabled' => 'A1A1A1', | |
| 756 | + 'bg_color' => 'ffffff', | |
| 757 | + // 'bg_color_hv' => 'ffffff', | |
| 758 | + 'remove_box_shadow' => '', | |
| 759 | + 'bg_color_active' => 'ffffff', | |
| 760 | + 'border_color_active' => '4199FD', | |
| 761 | + 'remove_box_shadow_active' => '', | |
| 762 | + 'text_color_error' => '444444', | |
| 763 | + 'bg_color_error' => 'ffffff', | |
| 764 | + 'border_color_error' => 'F04438', | |
| 765 | + 'border_width_error' => '1px', | |
| 766 | + 'border_style_error' => 'solid', | |
| 767 | + 'bg_color_disabled' => 'F9FAFB', | |
| 768 | + 'border_color_disabled' => 'D0D5DD', | |
| 769 | + 'text_color_disabled' => '667085', | |
| 673 | 770 | |
| 674 | - 'radio_align' => 'block', | |
| 675 | - 'check_align' => 'block', | |
| 676 | - 'check_font_size' => '13px', | |
| 677 | - 'check_label_color' => '444444', | |
| 678 | - 'check_weight' => 'normal', | |
| 771 | + 'radio_align' => 'block', | |
| 772 | + 'check_align' => 'block', | |
| 773 | + 'check_font_size' => '14px', | |
| 774 | + 'check_label_color' => '1D2939', | |
| 775 | + 'check_weight' => 'normal', | |
| 679 | 776 | |
| 680 | - 'section_font_size' => '18px', | |
| 681 | - 'section_color' => '444444', | |
| 682 | - 'section_weight' => 'bold', | |
| 683 | - 'section_pad' => '15px 0 3px 0', | |
| 684 | - 'section_mar_top' => '15px', | |
| 685 | - 'section_mar_bottom' => '30px', | |
| 686 | - 'section_bg_color' => '', | |
| 687 | - 'section_border_color' => 'e8e8e8', | |
| 688 | - 'section_border_width' => '2px', | |
| 689 | - 'section_border_style' => 'solid', | |
| 690 | - 'section_border_loc' => '-top', | |
| 691 | - 'collapse_icon' => '6', | |
| 692 | - 'collapse_pos' => 'after', | |
| 693 | - 'repeat_icon' => '1', | |
| 694 | - 'repeat_icon_color' => 'ffffff', | |
| 777 | + 'section_font_size' => '18px', | |
| 778 | + 'section_color' => '344054', | |
| 779 | + 'section_weight' => 'bold', | |
| 780 | + 'section_pad' => '32px 0px 3px 0px', | |
| 781 | + 'section_mar_top' => '30px', | |
| 782 | + 'section_mar_bottom' => '30px', | |
| 783 | + 'section_bg_color' => '', | |
| 784 | + 'section_border_color' => 'EAECF0', | |
| 785 | + 'section_border_width' => '1px', | |
| 786 | + 'section_border_style' => 'solid', | |
| 787 | + 'section_border_loc' => '-top', | |
| 788 | + 'collapse_icon' => '6', | |
| 789 | + 'collapse_pos' => 'after', | |
| 790 | + 'repeat_icon' => '1', | |
| 791 | + 'repeat_icon_color' => 'ffffff', | |
| 695 | 792 | |
| 696 | 793 | 'submit_style' => false, |
| 697 | - 'submit_font_size' => '15px', | |
| 794 | + 'submit_font_size' => '14px', | |
| 698 | 795 | 'submit_width' => 'auto', |
| 699 | 796 | 'submit_height' => 'auto', |
| 700 | - 'submit_bg_color' => '579AF6', | |
| 701 | - 'submit_border_color' => '579AF6', | |
| 797 | + 'submit_bg_color' => '4199FD', | |
| 798 | + 'submit_border_color' => '4199FD', | |
| 702 | 799 | 'submit_border_width' => '1px', |
| 703 | 800 | 'submit_text_color' => 'ffffff', |
| 704 | 801 | 'submit_weight' => 'normal', |
| 705 | - 'submit_border_radius' => '4px', | |
| 802 | + 'submit_border_radius' => '8px', | |
| 706 | 803 | 'submit_bg_img' => '', |
| 707 | 804 | 'submit_margin' => '10px', |
| 708 | - 'submit_padding' => '10px 20px', | |
| 805 | + 'submit_padding' => '8px 16px', | |
| 709 | 806 | 'submit_shadow_color' => 'eeeeee', |
| 710 | - 'submit_hover_bg_color' => 'efefef', | |
| 711 | - 'submit_hover_color' => '444444', | |
| 712 | - 'submit_hover_border_color' => 'cccccc', | |
| 713 | - 'submit_active_bg_color' => 'efefef', | |
| 714 | - 'submit_active_color' => '444444', | |
| 715 | - 'submit_active_border_color' => 'cccccc', | |
| 807 | + 'submit_hover_bg_color' => '3680D3', | |
| 808 | + 'submit_hover_color' => 'ffffff', | |
| 809 | + 'submit_hover_border_color' => '3680D3', | |
| 810 | + 'submit_active_bg_color' => '3680D3', | |
| 811 | + 'submit_active_color' => 'ffffff', | |
| 812 | + 'submit_active_border_color' => '3680D3', | |
| 716 | 813 | |
| 717 | - 'border_radius' => '4px', | |
| 718 | - 'error_bg' => 'F2DEDE', | |
| 719 | - 'error_border' => 'EBCCD1', | |
| 720 | - 'error_text' => 'B94A48', | |
| 721 | - 'error_font_size' => '14px', | |
| 814 | + 'border_radius' => '8px', | |
| 815 | + 'error_bg' => 'FEE4E2', | |
| 816 | + 'error_border' => 'F5B8AA', | |
| 817 | + 'error_text' => 'F04438', | |
| 818 | + 'error_font_size' => '14px', | |
| 722 | 819 | |
| 723 | - 'success_bg_color' => 'DFF0D8', | |
| 724 | - 'success_border_color' => 'D6E9C6', | |
| 725 | - 'success_text_color' => '468847', | |
| 726 | - 'success_font_size' => '14px', | |
| 820 | + 'success_bg_color' => 'DFF0D8', | |
| 821 | + 'success_border_color' => 'D6E9C6', | |
| 822 | + 'success_text_color' => '468847', | |
| 823 | + 'success_font_size' => '14px', | |
| 727 | 824 | |
| 728 | - 'important_style' => false, | |
| 825 | + 'important_style' => false, | |
| 729 | 826 | |
| 730 | - 'progress_bg_color' => 'eaeaea', | |
| 731 | - 'progress_active_color' => 'ffffff', | |
| 732 | - 'progress_active_bg_color' => '579AF6', | |
| 733 | - 'progress_color' => '3f4b5b', | |
| 734 | - 'progress_border_color' => 'E5E5E5', | |
| 735 | - 'progress_border_size' => '2px', | |
| 736 | - 'progress_size' => '24px', | |
| 827 | + 'progress_bg_color' => 'EAECF0', | |
| 828 | + 'progress_color' => '1D2939', | |
| 829 | + 'progress_active_bg_color' => '4199FD', | |
| 830 | + 'progress_active_color' => 'ffffff', | |
| 831 | + 'progress_border_color' => 'EAECF0', | |
| 832 | + 'progress_border_size' => '1px', | |
| 833 | + 'progress_size' => '30px', | |
| 834 | + 'custom_css' => '', | |
| 835 | + 'use_base_font_size' => false, | |
| 836 | + 'base_font_size' => '15px', | |
| 837 | + 'field_shape_type' => 'rounded-corner', | |
| 737 | 838 | |
| 738 | - 'custom_css' => '', | |
| 839 | + 'enable_style_custom_css' => false, | |
| 840 | + 'single_style_custom_css' => '', | |
| 739 | 841 | ); |
| 740 | 842 | |
| 741 | 843 | return apply_filters( 'frm_default_style_settings', $defaults ); |
| 742 | 844 | } |
| @@ -745,12 +847,13 @@ | ||
| 745 | 847 | * Get a name attribute value for a style setting input. |
| 746 | 848 | * |
| 747 | 849 | * @param string $field_name |
| 748 | 850 | * @param string $post_field |
| 851 | + * | |
| 749 | 852 | * @return string |
| 750 | 853 | */ |
| 751 | 854 | public function get_field_name( $field_name, $post_field = 'post_content' ) { |
| 752 | - return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']'; | |
| 855 | + return 'frm_style_setting' . ( $post_field ? '[' . $post_field . ']' : '' ) . '[' . $field_name . ']'; | |
| 753 | 856 | } |
| 754 | 857 | |
| 755 | 858 | /** |
| 756 | 859 | * @return array |
| @@ -756,17 +859,17 @@ | ||
| 756 | 859 | * @return array |
| 757 | 860 | */ |
| 758 | 861 | public static function get_bold_options() { |
| 759 | 862 | return array( |
| 760 | - 100 => 100, | |
| 761 | - 200 => 200, | |
| 762 | - 300 => 300, | |
| 763 | - 'normal' => __( 'normal', 'formidable' ), | |
| 764 | - 500 => 500, | |
| 765 | - 600 => 600, | |
| 766 | - 'bold' => __( 'bold', 'formidable' ), | |
| 767 | - 800 => 800, | |
| 768 | - 900 => 900, | |
| 863 | + 100 => __( 'Thin', 'formidable' ), | |
| 864 | + 200 => __( 'Extra Light', 'formidable' ), | |
| 865 | + 300 => __( 'Light', 'formidable' ), | |
| 866 | + 'normal' => __( 'Regular', 'formidable' ), | |
| 867 | + 500 => __( 'Medium', 'formidable' ), | |
| 868 | + 600 => __( 'Semi Bold', 'formidable' ), | |
| 869 | + 'bold' => __( 'Bold', 'formidable' ), | |
| 870 | + 800 => __( 'Extra Bold', 'formidable' ), | |
| 871 | + 900 => __( 'Black', 'formidable' ), | |
| 769 | 872 | ); |
| 770 | 873 | } |
| 771 | 874 | |
| 772 | 875 | /** |
| @@ -772,15 +875,17 @@ | ||
| 772 | 875 | /** |
| 773 | 876 | * Don't let imbalanced font families ruin the whole stylesheet. |
| 774 | 877 | * |
| 775 | 878 | * @param string $value |
| 879 | + * | |
| 776 | 880 | * @return string |
| 777 | 881 | */ |
| 778 | 882 | public function force_balanced_quotation( $value ) { |
| 779 | 883 | $balanced_characters = array( '"', "'" ); |
| 884 | + | |
| 780 | 885 | foreach ( $balanced_characters as $char ) { |
| 781 | 886 | $char_count = substr_count( $value, $char ); |
| 782 | - $is_balanced = $char_count % 2 == 0; | |
| 887 | + $is_balanced = $char_count % 2 === 0; | |
| 783 | 888 | |
| 784 | 889 | if ( $is_balanced ) { |
| 785 | 890 | continue; |
| 786 | 891 | } |
| @@ -790,7 +895,27 @@ | ||
| 790 | 895 | } else { |
| 791 | 896 | $value .= $char; |
| 792 | 897 | } |
| 793 | 898 | } |
| 899 | + | |
| 794 | 900 | return $value; |
| 901 | + } | |
| 902 | + | |
| 903 | + /** | |
| 904 | + * Get the default template style | |
| 905 | + * | |
| 906 | + * @since 6.14 | |
| 907 | + * | |
| 908 | + * @param int|string $style_id The post type "frm_styles" ID. | |
| 909 | + * | |
| 910 | + * @return string The json encoded template data | |
| 911 | + */ | |
| 912 | + public function get_default_template_style( $style_id ) { | |
| 913 | + $default_template = get_post_meta( (int) $style_id, $this->default_template_style_meta_name, true ); | |
| 914 | + | |
| 915 | + if ( ! $default_template ) { | |
| 916 | + return FrmAppHelper::prepare_and_encode( $this->get_defaults() ); | |
| 917 | + } | |
| 918 | + | |
| 919 | + return $default_template; | |
| 795 | 920 | } |
| 796 | 921 | } |