class-do-css.php
4 years ago
class-enqueue-css.php
4 years ago
class-legacy-attributes.php
4 years ago
class-plugin-update.php
5 years ago
class-render-blocks.php
4 years ago
class-rest.php
4 years ago
class-settings.php
5 years ago
dashboard.php
5 years ago
defaults.php
4 years ago
functions.php
4 years ago
general.php
4 years ago
generate-css.php
4 years ago
functions.php
755 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Functions used throughout the plugin. |
| 4 | * |
| 5 | * @package GenerateBlocks |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; // Exit if accessed directly. |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Retrive attributes from our blocks. |
| 14 | * |
| 15 | * @since 0.1 |
| 16 | * @param array $content The content of our page. |
| 17 | * @param array $data Data used to loop through the function as needed. |
| 18 | * @param int $depth Keep track of how deep we are in nested blocks. |
| 19 | * |
| 20 | * @return array |
| 21 | */ |
| 22 | function generateblocks_get_block_data( $content, $data = array(), $depth = 0 ) { |
| 23 | if ( ! is_array( $content ) || empty( $content ) ) { |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | foreach ( $content as $index => $block ) { |
| 28 | if ( ! is_object( $block ) && is_array( $block ) && isset( $block['blockName'] ) ) { |
| 29 | if ( 'generateblocks/grid' === $block['blockName'] ) { |
| 30 | $data['grid'][] = $block['attrs']; |
| 31 | $depth++; |
| 32 | $data[ 'tempGridId-' . $depth ] = $block['attrs']['uniqueId']; |
| 33 | } |
| 34 | |
| 35 | if ( 'generateblocks/container' === $block['blockName'] ) { |
| 36 | if ( isset( $block['attrs']['isGrid'] ) && $block['attrs']['isGrid'] && isset( $data[ 'tempGridId-' . $depth ] ) ) { |
| 37 | $block['attrs']['gridId'] = $data[ 'tempGridId-' . $depth ]; |
| 38 | } |
| 39 | |
| 40 | $data['container'][] = $block['attrs']; |
| 41 | } |
| 42 | |
| 43 | if ( 'generateblocks/headline' === $block['blockName'] ) { |
| 44 | if ( isset( $block['innerHTML'] ) ) { |
| 45 | if ( strpos( trim( $block['innerHTML'] ), '<div class="gb-headline-wrapper' ) === 0 ) { |
| 46 | $block['attrs']['hasWrapper'] = true; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | $data['headline'][] = $block['attrs']; |
| 51 | } |
| 52 | |
| 53 | if ( 'generateblocks/button-container' === $block['blockName'] ) { |
| 54 | $data['button-container'][] = $block['attrs']; |
| 55 | } |
| 56 | |
| 57 | if ( 'generateblocks/button' === $block['blockName'] ) { |
| 58 | if ( ! isset( $block['attrs']['hasUrl'] ) && isset( $block['innerHTML'] ) ) { |
| 59 | if ( strpos( trim( $block['innerHTML'] ), '<a' ) === 0 ) { |
| 60 | $block['attrs']['hasUrl'] = true; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | $data['button'][] = $block['attrs']; |
| 65 | } |
| 66 | |
| 67 | if ( 'core/block' === $block['blockName'] ) { |
| 68 | if ( isset( $block['attrs'] ) && is_array( $block['attrs'] ) ) { |
| 69 | $atts = $block['attrs']; |
| 70 | |
| 71 | if ( isset( $atts['ref'] ) && ( empty( $data['reusableBlockIds'] ) || ! in_array( $atts['ref'], (array) $data['reusableBlockIds'] ) ) ) { |
| 72 | $reusable_block = get_post( $atts['ref'] ); |
| 73 | |
| 74 | if ( $reusable_block && 'wp_block' === $reusable_block->post_type && 'publish' === $reusable_block->post_status ) { |
| 75 | $reuse_data_block = parse_blocks( $reusable_block->post_content ); |
| 76 | |
| 77 | if ( ! empty( $reuse_data_block ) ) { |
| 78 | $data['reusableBlockIds'][] = $atts['ref']; |
| 79 | $data = generateblocks_get_block_data( $reuse_data_block, $data ); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | if ( isset( $block['innerBlocks'] ) && ! empty( $block['innerBlocks'] ) && is_array( $block['innerBlocks'] ) ) { |
| 87 | $data = generateblocks_get_block_data( $block['innerBlocks'], $data, $depth ); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return $data; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Parse our content for blocks. |
| 97 | * |
| 98 | * @param string $content Optional content to parse. |
| 99 | * @since 1.1 |
| 100 | */ |
| 101 | function generateblocks_get_parsed_content( $content = '' ) { |
| 102 | if ( ! function_exists( 'has_blocks' ) ) { |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | if ( ! $content && has_blocks( get_the_ID() ) ) { |
| 107 | global $post; |
| 108 | |
| 109 | if ( ! is_object( $post ) ) { |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | $content = $post->post_content; |
| 114 | } |
| 115 | |
| 116 | $content = apply_filters( 'generateblocks_do_content', $content ); |
| 117 | |
| 118 | if ( ! function_exists( 'parse_blocks' ) ) { |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | $content = parse_blocks( $content ); |
| 123 | |
| 124 | return $content; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Shorthand CSS values (padding, margin, border etc..). |
| 129 | * |
| 130 | * @since 0.1 |
| 131 | * |
| 132 | * @param int $top The first value. |
| 133 | * @param int $right The second value. |
| 134 | * @param int $bottom The third value. |
| 135 | * @param int $left The fourth value. |
| 136 | * @param string $unit The unit we're adding. |
| 137 | * |
| 138 | * @return string The shorthand value. |
| 139 | */ |
| 140 | function generateblocks_get_shorthand_css( $top, $right, $bottom, $left, $unit ) { |
| 141 | if ( '' === $top && '' === $right && '' === $bottom && '' === $left ) { |
| 142 | return; |
| 143 | } |
| 144 | |
| 145 | $top = ( floatval( $top ) <> 0 ) ? floatval( $top ) . $unit . ' ' : '0 '; // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
| 146 | $right = ( floatval( $right ) <> 0 ) ? floatval( $right ) . $unit . ' ' : '0 '; // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
| 147 | $bottom = ( floatval( $bottom ) <> 0 ) ? floatval( $bottom ) . $unit . ' ' : '0 '; // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
| 148 | $left = ( floatval( $left ) <> 0 ) ? floatval( $left ) . $unit . ' ' : '0 '; // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
| 149 | |
| 150 | if ( $right === $left ) { |
| 151 | $left = ''; |
| 152 | |
| 153 | if ( $top === $bottom ) { |
| 154 | $bottom = ''; |
| 155 | |
| 156 | if ( $top === $right ) { |
| 157 | $right = ''; |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | return trim( $top . $right . $bottom . $left ); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Get our media query. |
| 167 | * |
| 168 | * @since 0.1 |
| 169 | * @param string $type The media query we're getting. |
| 170 | * |
| 171 | * @return string |
| 172 | */ |
| 173 | function generateblocks_get_media_query( $type ) { |
| 174 | $queries = apply_filters( |
| 175 | 'generateblocks_media_query', |
| 176 | array( |
| 177 | 'desktop' => '(min-width: 1025px)', |
| 178 | 'tablet' => '(max-width: 1024px)', |
| 179 | 'tablet_only' => '(max-width: 1024px) and (min-width: 768px)', |
| 180 | 'mobile' => '(max-width: 767px)', |
| 181 | ) |
| 182 | ); |
| 183 | |
| 184 | return $queries[ $type ]; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Build our list of Google fonts on this page. |
| 189 | * |
| 190 | * @since 0.1 |
| 191 | * @param string $content Optional content to parse. |
| 192 | * @return array |
| 193 | */ |
| 194 | function generateblocks_get_google_fonts( $content = '' ) { |
| 195 | $content = generateblocks_get_parsed_content( $content ); |
| 196 | |
| 197 | if ( ! $content ) { |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | $data = generateblocks_get_block_data( $content ); |
| 202 | |
| 203 | $defaults = generateblocks_get_block_defaults(); |
| 204 | $font_data = array(); |
| 205 | |
| 206 | if ( ! empty( $data ) ) { |
| 207 | foreach ( $data as $name => $blockData ) { |
| 208 | if ( 'button' === $name ) { |
| 209 | foreach ( $blockData as $atts ) { |
| 210 | $button_settings = wp_parse_args( |
| 211 | $atts, |
| 212 | $defaults['button'] |
| 213 | ); |
| 214 | |
| 215 | if ( $button_settings['googleFont'] ) { |
| 216 | $id = $atts['uniqueId']; |
| 217 | |
| 218 | $variants = $button_settings['googleFontVariants']; |
| 219 | |
| 220 | if ( $variants ) { |
| 221 | $variants = str_replace( ' ', '', $variants ); |
| 222 | $variants = explode( ',', $variants ); |
| 223 | } |
| 224 | |
| 225 | $font_data[ $id ] = array( |
| 226 | 'name' => $button_settings['fontFamily'], |
| 227 | 'variants' => $variants, |
| 228 | ); |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | if ( 'headline' === $name ) { |
| 234 | foreach ( $blockData as $atts ) { |
| 235 | $headline_settings = wp_parse_args( |
| 236 | $atts, |
| 237 | $defaults['headline'] |
| 238 | ); |
| 239 | |
| 240 | if ( $headline_settings['googleFont'] ) { |
| 241 | $id = $atts['uniqueId']; |
| 242 | $variants = $headline_settings['googleFontVariants']; |
| 243 | |
| 244 | if ( $variants ) { |
| 245 | $variants = str_replace( ' ', '', $variants ); |
| 246 | $variants = explode( ',', $variants ); |
| 247 | } |
| 248 | |
| 249 | $font_data[ $id ] = array( |
| 250 | 'name' => $headline_settings['fontFamily'], |
| 251 | 'variants' => $variants, |
| 252 | ); |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | if ( 'container' === $name ) { |
| 258 | foreach ( $blockData as $atts ) { |
| 259 | $container_settings = wp_parse_args( |
| 260 | $atts, |
| 261 | $defaults['container'] |
| 262 | ); |
| 263 | |
| 264 | if ( $container_settings['googleFont'] ) { |
| 265 | $id = $atts['uniqueId']; |
| 266 | $variants = $container_settings['googleFontVariants']; |
| 267 | |
| 268 | if ( $variants ) { |
| 269 | $variants = str_replace( ' ', '', $variants ); |
| 270 | $variants = explode( ',', $variants ); |
| 271 | } |
| 272 | |
| 273 | $font_data[ $id ] = array( |
| 274 | 'name' => $container_settings['fontFamily'], |
| 275 | 'variants' => $variants, |
| 276 | ); |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | $fonts = array(); |
| 284 | |
| 285 | foreach ( (array) $font_data as $font ) { |
| 286 | $id = str_replace( ' ', '', strtolower( $font['name'] ) ); |
| 287 | |
| 288 | $fonts[ $id ]['name'] = $font['name']; |
| 289 | |
| 290 | if ( ! empty( $font['variants'] ) ) { |
| 291 | foreach ( $font['variants'] as $variant ) { |
| 292 | if ( isset( $fonts[ $id ]['variants'] ) ) { |
| 293 | if ( in_array( $variant, (array) $fonts[ $id ]['variants'] ) ) { |
| 294 | continue; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | $fonts[ $id ]['variants'][] = $variant; |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | return apply_filters( 'generateblocks_google_fonts', $fonts ); |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Build the Google Font request URI. |
| 308 | * |
| 309 | * @since 0.1 |
| 310 | * |
| 311 | * @return string The request URI to Google Fonts. |
| 312 | */ |
| 313 | function generateblocks_get_google_fonts_uri() { |
| 314 | $google_fonts = generateblocks_get_google_fonts(); |
| 315 | |
| 316 | if ( ! $google_fonts ) { |
| 317 | return; |
| 318 | } |
| 319 | |
| 320 | $data = array(); |
| 321 | |
| 322 | foreach ( $google_fonts as $font ) { |
| 323 | $variants = array(); |
| 324 | |
| 325 | if ( ! empty( $font['variants'] ) ) { |
| 326 | foreach ( $font['variants'] as $variant ) { |
| 327 | $variants[] = $variant; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | $variants = apply_filters( 'generateblocks_google_font_variants', $variants, $font['name'] ); |
| 332 | |
| 333 | $name = str_replace( ' ', '+', $font['name'] ); |
| 334 | |
| 335 | if ( $variants ) { |
| 336 | $data[] = $name . ':' . implode( ',', $variants ); |
| 337 | } else { |
| 338 | $data[] = $name; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | $font_args = apply_filters( |
| 343 | 'generateblocks_google_font_args', |
| 344 | array( |
| 345 | 'family' => implode( '|', $data ), |
| 346 | 'subset' => null, |
| 347 | 'display' => 'swap', |
| 348 | ) |
| 349 | ); |
| 350 | |
| 351 | return add_query_arg( $font_args, 'https://fonts.googleapis.com/css' ); |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Convert hex to RGBA |
| 356 | * |
| 357 | * @since 0.1 |
| 358 | * @param string $hex The hex value. |
| 359 | * @param int $alpha The opacity value. |
| 360 | * |
| 361 | * @return string The RGBA value. |
| 362 | */ |
| 363 | function generateblocks_hex2rgba( $hex, $alpha ) { |
| 364 | if ( ! $hex ) { |
| 365 | return; |
| 366 | } |
| 367 | |
| 368 | if ( 1 === $alpha || ! is_numeric( $alpha ) ) { |
| 369 | return $hex; |
| 370 | } |
| 371 | |
| 372 | // Make sure we're dealing with a hex value. |
| 373 | if ( isset( $hex[0] ) && '#' !== $hex[0] ) { |
| 374 | return $hex; |
| 375 | } |
| 376 | |
| 377 | $hex = str_replace( '#', '', $hex ); |
| 378 | |
| 379 | if ( strlen( $hex ) == 3 ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
| 380 | $r = hexdec( substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) ); |
| 381 | $g = hexdec( substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) ); |
| 382 | $b = hexdec( substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ) ); |
| 383 | } else { |
| 384 | $r = hexdec( substr( $hex, 0, 2 ) ); |
| 385 | $g = hexdec( substr( $hex, 2, 2 ) ); |
| 386 | $b = hexdec( substr( $hex, 4, 2 ) ); |
| 387 | } |
| 388 | |
| 389 | $rgba = 'rgba(' . $r . ', ' . $g . ', ' . $b . ', ' . $alpha . ')'; |
| 390 | |
| 391 | return $rgba; |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Return old flexblocks values for old browsers. |
| 396 | * |
| 397 | * @since 0.1 |
| 398 | * @param string $value The value to convert. |
| 399 | * |
| 400 | * @return string The old browser value. |
| 401 | */ |
| 402 | function generateblocks_get_vendor_prefix( $value ) { |
| 403 | if ( 'flex-start' === $value || 'left' === $value ) { |
| 404 | return 'start'; |
| 405 | } |
| 406 | |
| 407 | if ( 'flex-end' === $value || 'right' === $value ) { |
| 408 | return 'end'; |
| 409 | } |
| 410 | |
| 411 | return $value; |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Return flexbox alignment values from left/right. |
| 416 | * |
| 417 | * @since 0.1 |
| 418 | * @param string $value The value to convert. |
| 419 | * |
| 420 | * @return string The flexbox alignment value. |
| 421 | */ |
| 422 | function generateblocks_get_flexbox_alignment( $value ) { |
| 423 | if ( 'left' === $value || 'top' === $value ) { |
| 424 | return 'flex-start'; |
| 425 | } |
| 426 | |
| 427 | if ( 'right' === $value || 'bottom' === $value ) { |
| 428 | return 'flex-end'; |
| 429 | } |
| 430 | |
| 431 | return $value; |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Get an option from the database. |
| 436 | * |
| 437 | * @param string $option The option to get. |
| 438 | * @since 0.1 |
| 439 | */ |
| 440 | function generateblocks_get_option( $option ) { |
| 441 | $defaults = generateblocks_get_option_defaults(); |
| 442 | |
| 443 | if ( ! isset( $defaults[ $option ] ) ) { |
| 444 | return; |
| 445 | } |
| 446 | |
| 447 | $options = wp_parse_args( |
| 448 | get_option( 'generateblocks', array() ), |
| 449 | $defaults |
| 450 | ); |
| 451 | |
| 452 | return $options[ $option ]; |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * Checks whether a value exists, even if it's a 0. |
| 457 | * |
| 458 | * @param int|string $value The value to check. |
| 459 | * @since 1.0 |
| 460 | */ |
| 461 | function generateblocks_has_number_value( $value ) { |
| 462 | if ( $value || 0 === $value || '0' === $value ) { |
| 463 | return true; |
| 464 | } |
| 465 | |
| 466 | return false; |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * Get the background-image value for our Container block. |
| 471 | * |
| 472 | * @param string $type Gradient or background image. |
| 473 | * @param array $settings Our background image settings. |
| 474 | */ |
| 475 | function generateblocks_get_background_image_css( $type, $settings ) { |
| 476 | $gradient = ''; |
| 477 | |
| 478 | if ( $settings['gradient'] ) { |
| 479 | $gradientColorStopOneValue = ''; |
| 480 | $gradientColorStopTwoValue = ''; |
| 481 | $gradientColorOneValue = generateblocks_hex2rgba( $settings['gradientColorOne'], $settings['gradientColorOneOpacity'] ); |
| 482 | $gradientColorTwoValue = generateblocks_hex2rgba( $settings['gradientColorTwo'], $settings['gradientColorTwoOpacity'] ); |
| 483 | |
| 484 | if ( $settings['gradientColorOne'] && '' !== $settings['gradientColorStopOne'] ) { |
| 485 | $gradientColorStopOneValue = ' ' . $settings['gradientColorStopOne'] . '%'; |
| 486 | } |
| 487 | |
| 488 | if ( $settings['gradientColorTwo'] && '' !== $settings['gradientColorStopTwo'] ) { |
| 489 | $gradientColorStopTwoValue = ' ' . $settings['gradientColorStopTwo'] . '%'; |
| 490 | } |
| 491 | |
| 492 | $gradient = 'linear-gradient(' . $settings['gradientDirection'] . 'deg, ' . $gradientColorOneValue . $gradientColorStopOneValue . ', ' . $gradientColorTwoValue . $gradientColorStopTwoValue . ')'; |
| 493 | } |
| 494 | |
| 495 | if ( 'gradient' === $type ) { |
| 496 | return $gradient; |
| 497 | } |
| 498 | |
| 499 | $backgroundImage = ''; |
| 500 | |
| 501 | if ( $settings['bgImage'] ) { |
| 502 | $url = ''; |
| 503 | |
| 504 | if ( isset( $settings['bgImage']['id'] ) ) { |
| 505 | $image_src = wp_get_attachment_image_src( $settings['bgImage']['id'], $settings['bgImageSize'] ); |
| 506 | |
| 507 | if ( is_array( $image_src ) ) { |
| 508 | $url = $image_src[0]; |
| 509 | } else { |
| 510 | $url = $settings['bgImage']['image']['url']; |
| 511 | } |
| 512 | } else { |
| 513 | $url = $settings['bgImage']['image']['url']; |
| 514 | } |
| 515 | |
| 516 | $url = apply_filters( 'generateblocks_background_image_url', $url, $settings ); |
| 517 | |
| 518 | // Old background image overlays mixed with our gradients. |
| 519 | if ( |
| 520 | 'element' === $settings['bgOptions']['selector'] && |
| 521 | ( $settings['backgroundColor'] || $settings['gradient'] ) && |
| 522 | isset( $settings['bgOptions']['overlay'] ) && |
| 523 | $settings['bgOptions']['overlay'] |
| 524 | ) { |
| 525 | if ( $settings['gradient'] ) { |
| 526 | $backgroundImage = $gradient . ', url(' . esc_url( $url ) . ')'; |
| 527 | } elseif ( $settings['backgroundColor'] ) { |
| 528 | $settings['backgroundColor'] = generateblocks_hex2rgba( $settings['backgroundColor'], $settings['backgroundColorOpacity'] ); |
| 529 | $backgroundImage = 'linear-gradient(0deg, ' . $settings['backgroundColor'] . ', ' . $settings['backgroundColor'] . '), url(' . esc_url( $url ) . ')'; |
| 530 | } |
| 531 | } else { |
| 532 | $backgroundImage = 'url(' . esc_url( $url ) . ')'; |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | return $backgroundImage; |
| 537 | } |
| 538 | |
| 539 | /** |
| 540 | * Build list of attributes into a string and apply contextual filter on string. |
| 541 | * |
| 542 | * The contextual filter is of the form `generateblocks_attr_{context}_output`. |
| 543 | * |
| 544 | * @since 1.2.0 |
| 545 | * |
| 546 | * @param string $context The context, to build filter name. |
| 547 | * @param array $attributes Optional. Extra attributes to merge with defaults. |
| 548 | * @param array $settings Optional. Custom data to pass to filter. |
| 549 | * @return string String of HTML attributes and values. |
| 550 | */ |
| 551 | function generateblocks_attr( $context, $attributes = array(), $settings = array() ) { |
| 552 | $attributes = generateblocks_parse_attr( $context, $attributes, $settings ); |
| 553 | |
| 554 | $output = ''; |
| 555 | |
| 556 | // Cycle through attributes, build tag attribute string. |
| 557 | foreach ( $attributes as $key => $value ) { |
| 558 | |
| 559 | if ( ! $value ) { |
| 560 | continue; |
| 561 | } |
| 562 | |
| 563 | if ( true === $value ) { |
| 564 | $output .= esc_html( $key ) . ' '; |
| 565 | } else { |
| 566 | $output .= sprintf( '%s="%s" ', esc_html( $key ), esc_attr( $value ) ); |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | $output = apply_filters( "generateblocks_attr_{$context}_output", $output, $attributes, $settings, $context ); |
| 571 | |
| 572 | return trim( $output ); |
| 573 | } |
| 574 | |
| 575 | /** |
| 576 | * Merge array of attributes with defaults, and apply contextual filter on array. |
| 577 | * |
| 578 | * The contextual filter is of the form `generateblocks_attr_{context}`. |
| 579 | * |
| 580 | * @since 1.2.0 |
| 581 | * |
| 582 | * @param string $context The context, to build filter name. |
| 583 | * @param array $attributes Optional. Extra attributes to merge with defaults. |
| 584 | * @param array $settings Optional. Custom data to pass to filter. |
| 585 | * @return array Merged and filtered attributes. |
| 586 | */ |
| 587 | function generateblocks_parse_attr( $context, $attributes = array(), $settings = array() ) { |
| 588 | $defaults = array( |
| 589 | 'class' => sanitize_html_class( $context ), |
| 590 | ); |
| 591 | |
| 592 | $attributes = wp_parse_args( $attributes, $defaults ); |
| 593 | |
| 594 | // Contextual filter. |
| 595 | return apply_filters( "generateblocks_attr_{$context}", $attributes, $settings, $context ); |
| 596 | } |
| 597 | |
| 598 | /** |
| 599 | * Generate our SVG shape dividers. |
| 600 | * |
| 601 | * @since 1.2.0 |
| 602 | */ |
| 603 | function generateblocks_get_svg_shapes() { |
| 604 | return apply_filters( |
| 605 | 'generateblocks_svg_shapes', |
| 606 | array( |
| 607 | 'gb-waves' => array( |
| 608 | 'group' => esc_attr__( 'Waves', 'generateblocks' ), |
| 609 | 'svgs' => array( |
| 610 | 'gb-waves-1' => array( |
| 611 | /* translators: Shape number */ |
| 612 | 'label' => sprintf( __( 'Wave %s', 'generateblocks' ), '1' ), |
| 613 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 194.3" preserveAspectRatio="none"><path d="M1200 133.3l-50 8.9c-50 8.6-150 26.9-250 31.1-100 4.2-200-4.2-300-26.7S400 89.2 300 62.2C200 35.8 100 17.5 50 8.9L0 0v194.3h1200v-61z"/></svg>', |
| 614 | ), |
| 615 | 'gb-waves-2' => array( |
| 616 | /* translators: Shape number */ |
| 617 | 'label' => sprintf( __( 'Wave %s', 'generateblocks' ), '2' ), |
| 618 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 137.6" preserveAspectRatio="none"><path d="M0 137.6h1200V21.9l-66.7 26.7c-66.7 26.7-200 80-333.3 66.7S533.3 21.9 400 4.2C266.7-13.9 133.3 31.1 66.7 53L0 75.3v62.3z"/></svg>', |
| 619 | ), |
| 620 | 'gb-waves-3' => array( |
| 621 | /* translators: Shape number */ |
| 622 | 'label' => sprintf( __( 'Wave %s', 'generateblocks' ), '3' ), |
| 623 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 96.2" preserveAspectRatio="none"><path d="M0 96.2h1200V72.9l-50-8.9c-50-8.6-150-26.9-250-22.2C800 46.2 700 72.9 600 64 500 55.4 400 10.4 300 1.8 200-7.1 100 19.5 50 32.9L0 46.2v50z"/></svg>', |
| 624 | ), |
| 625 | 'gb-waves-4' => array( |
| 626 | /* translators: Shape number */ |
| 627 | 'label' => sprintf( __( 'Wave %s', 'generateblocks' ), '4' ), |
| 628 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 130.3" preserveAspectRatio="none"><path d="M0 107.9l40-22.2c40-21.9 120-66.9 200-62.2 80 4.4 160 57.8 240 53.3C560 72 640 10.4 720 1.2S880 37 960 59c80 22.3 160 22.3 200 22.3h40v49H0v-22.4z"/></svg>', |
| 629 | ), |
| 630 | 'gb-waves-5' => array( |
| 631 | /* translators: Shape number */ |
| 632 | 'label' => sprintf( __( 'Wave %s', 'generateblocks' ), '5' ), |
| 633 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 218" preserveAspectRatio="none"><path d="M0 218h1200v-31.3l-40 4.4c-40 4.8-120 13.1-200 0-80-13.6-160-48.6-240-66.7-80-17.8-160-17.8-240-8.8-80 8.6-160 26.9-240 8.8-80-17.7-160-71.1-200-97.7L0 0v218z"/></svg>', |
| 634 | ), |
| 635 | 'gb-waves-6' => array( |
| 636 | /* translators: Shape number */ |
| 637 | 'label' => sprintf( __( 'Wave %s', 'generateblocks' ), '6' ), |
| 638 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 234" preserveAspectRatio="none"><path d="M0 0l40 40c40 40 120 120 200 115.6 80-4.8 160-93.1 240-111.2C560 26.7 640 80 720 88.9c80 8.6 160-26.4 240-13.3 80 13.6 160 75.2 200 106.7l40 31.1V234H0V0z"/></svg>', |
| 639 | ), |
| 640 | 'gb-waves-7' => array( |
| 641 | /* translators: Shape number */ |
| 642 | 'label' => sprintf( __( 'Wave %s', 'generateblocks' ), '7' ), |
| 643 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 217.3" preserveAspectRatio="none"><path d="M1200 195.6l-25-22.2c-25-21.9-75-66.9-125-75.5-50-8.9-100 17.8-150 26.7-50 8.6-100 .2-150-13.3-50-13.1-100-31.4-150-26.7-50 4.4-100 31.1-150 26.7-50-4.8-100-39.8-150-66.7C250 18.1 200-.2 150 0 100-.2 50 18.1 25 26.7L0 35.6v181.7h1200v-21.7z"/></svg>', |
| 644 | ), |
| 645 | 'gb-waves-8' => array( |
| 646 | /* translators: Shape number */ |
| 647 | 'label' => sprintf( __( 'Wave %s', 'generateblocks' ), '8' ), |
| 648 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 230.8" preserveAspectRatio="none"><path d="M1200 179.5l-22.2-26.7c-22.2-26.7-66.9-80-111.1-75.6-44.4 4.8-89.2 66.4-133.3 102.2-44.4 35.8-89.2 44.2-133.3 8.9-44.4-35.6-89.2-115.6-133.3-155.6-44.4-40-89.2-40-133.3-17.8C488.9 37 444.2 82 400 81.7c-44.4.2-89.2-44.8-133.3-57.8-44.4-13.6-89.2 4.8-133.3 26.7-44.5 22.2-89.2 48.9-110.9 62.2L0 126.1v104.7H1199.7l.3-51.3z"/></svg>', |
| 649 | ), |
| 650 | ), |
| 651 | ), |
| 652 | 'gb-angles' => array( |
| 653 | 'group' => esc_attr__( 'Angles', 'generateblocks' ), |
| 654 | 'svgs' => array( |
| 655 | 'gb-angle-1' => array( |
| 656 | /* translators: Shape number */ |
| 657 | 'label' => sprintf( __( 'Angle %s', 'generateblocks' ), '1' ), |
| 658 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 360" preserveAspectRatio="none"><path d="M1200 360H0V0l1200 348z"/></svg>', |
| 659 | ), |
| 660 | ), |
| 661 | ), |
| 662 | 'gb-curves' => array( |
| 663 | 'group' => esc_attr__( 'Curves', 'generateblocks' ), |
| 664 | 'svgs' => array( |
| 665 | 'gb-curve-1' => array( |
| 666 | /* translators: Shape number */ |
| 667 | 'label' => sprintf( __( 'Curve %s', 'generateblocks' ), '1' ), |
| 668 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 350" preserveAspectRatio="none"><path d="M1200 336.7V350H0V0s22.4 276.4 1200 336.7z"/></svg>', |
| 669 | ), |
| 670 | 'gb-curve-2' => array( |
| 671 | /* translators: Shape number */ |
| 672 | 'label' => sprintf( __( 'Curve %s', 'generateblocks' ), '2' ), |
| 673 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 350" preserveAspectRatio="none"><path d="M1200 350V0C22.4 60.3 0 336.7 0 336.7V350h1200z"/></svg>', |
| 674 | ), |
| 675 | 'gb-curve-3' => array( |
| 676 | /* translators: Shape number */ |
| 677 | 'label' => sprintf( __( 'Curve %s', 'generateblocks' ), '3' ), |
| 678 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 211.2" preserveAspectRatio="none"><path d="M600 188.4C321.1 188.4 84.3 109.5 0 0v211.2h1200V0c-84.3 109.5-321.1 188.4-600 188.4z"/></svg>', |
| 679 | ), |
| 680 | 'gb-curve-4' => array( |
| 681 | /* translators: Shape number */ |
| 682 | 'label' => sprintf( __( 'Curve %s', 'generateblocks' ), '4' ), |
| 683 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 211.2" preserveAspectRatio="none"><path d="M1200 188.4v22.8H0v-22.8C84.3 78.9 321.1 0 600 0s515.7 78.9 600 188.4z"/></svg>', |
| 684 | ), |
| 685 | ), |
| 686 | ), |
| 687 | 'gb-triangles' => array( |
| 688 | 'group' => esc_attr__( 'Triangles', 'generateblocks' ), |
| 689 | 'svgs' => array( |
| 690 | 'gb-triangle-1' => array( |
| 691 | /* translators: Shape number */ |
| 692 | 'label' => sprintf( __( 'Triangle %s', 'generateblocks' ), '1' ), |
| 693 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 100" preserveAspectRatio="none"><path d="M1200 100H0V0l400 77.2L1200 0z"/></svg>', |
| 694 | ), |
| 695 | 'gb-triangle-2' => array( |
| 696 | /* translators: Shape number */ |
| 697 | 'label' => sprintf( __( 'Triangle %s', 'generateblocks' ), '2' ), |
| 698 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 100" preserveAspectRatio="none"><path d="M1200 77.2L400 0 0 77.2V100h1200z"/></svg>', |
| 699 | ), |
| 700 | 'gb-triangle-3' => array( |
| 701 | /* translators: Shape number */ |
| 702 | 'label' => sprintf( __( 'Triangle %s', 'generateblocks' ), '3' ), |
| 703 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 70" preserveAspectRatio="none"><path d="M1200 0v70H0V0h530l70 50 70-50z"/></svg>', |
| 704 | ), |
| 705 | 'gb-triangle-4' => array( |
| 706 | /* translators: Shape number */ |
| 707 | 'label' => sprintf( __( 'Triangle %s', 'generateblocks' ), '4' ), |
| 708 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 70" preserveAspectRatio="none"><path d="M670 50L600 0l-70 50H0v20h1200V50z"/></svg>', |
| 709 | ), |
| 710 | 'gb-triangle-5' => array( |
| 711 | /* translators: Shape number */ |
| 712 | 'label' => sprintf( __( 'Triangle %s', 'generateblocks' ), '5' ), |
| 713 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 50" preserveAspectRatio="none"><path d="M1200 0v50H0V0h560l40 30 40-30z"/></svg>', |
| 714 | ), |
| 715 | 'gb-triangle-6' => array( |
| 716 | /* translators: Shape number */ |
| 717 | 'label' => sprintf( __( 'Triangle %s', 'generateblocks' ), '6' ), |
| 718 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 50" preserveAspectRatio="none"><path d="M640 30L600 0l-40 30H0v20h1200V30z"/></svg>', |
| 719 | ), |
| 720 | 'gb-triangle-7' => array( |
| 721 | /* translators: Shape number */ |
| 722 | 'label' => sprintf( __( 'Triangle %s', 'generateblocks' ), '7' ), |
| 723 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 230" preserveAspectRatio="none"><path d="M1200 230H0V0l600 207.2L1200 0z"/></svg>', |
| 724 | ), |
| 725 | 'gb-triangle-8' => array( |
| 726 | /* translators: Shape number */ |
| 727 | 'label' => sprintf( __( 'Triangle %s', 'generateblocks' ), '8' ), |
| 728 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 230" preserveAspectRatio="none"><path d="M1200 207.2L600 0 0 207.2V230h1200z"/></svg>', |
| 729 | ), |
| 730 | 'gb-triangle-9' => array( |
| 731 | /* translators: Shape number */ |
| 732 | 'label' => sprintf( __( 'Triangle %s', 'generateblocks' ), '9' ), |
| 733 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 131" preserveAspectRatio="none"><path d="M1200 131H0V40l154.8 50L410 35l277 69L899 0l301 110z"/></svg>', |
| 734 | ), |
| 735 | 'gb-triangle-10' => array( |
| 736 | /* translators: Shape number */ |
| 737 | 'label' => sprintf( __( 'Triangle %s', 'generateblocks' ), '10' ), |
| 738 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 131" preserveAspectRatio="none"><path d="M1200 0L899 110 687 6 410 75 154.8 20 0 70v61h1200z"/></svg>', |
| 739 | ), |
| 740 | 'gb-triangle-11' => array( |
| 741 | /* translators: Shape number */ |
| 742 | 'label' => sprintf( __( 'Triangle %s', 'generateblocks' ), '11' ), |
| 743 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 176" preserveAspectRatio="none"><path d="M0 0l400 156 400-88 400 74v34H0z"/></svg>', |
| 744 | ), |
| 745 | 'gb-triangle-12' => array( |
| 746 | /* translators: Shape number */ |
| 747 | 'label' => sprintf( __( 'Triangle %s', 'generateblocks' ), '12' ), |
| 748 | 'icon' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 176" preserveAspectRatio="none"><path d="M0 176h1200V14L800 88 400 0 0 156z"/></svg>', |
| 749 | ), |
| 750 | ), |
| 751 | ), |
| 752 | ) |
| 753 | ); |
| 754 | } |
| 755 |