| 1 |
<?php |
| 2 |
/** |
| 3 |
* Sureforms - Advanced Heading |
| 4 |
* |
| 5 |
* @package Sureforms |
| 6 |
*/ |
| 7 |
|
| 8 |
use SRFM\Inc\Helper; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; // Exit if accessed directly. |
| 12 |
} |
| 13 |
|
| 14 |
if ( ! class_exists( 'Advanced_Heading' ) ) { |
| 15 |
|
| 16 |
/** |
| 17 |
* Class Advanced_Heading. |
| 18 |
*/ |
| 19 |
class Advanced_Heading { |
| 20 |
|
| 21 |
/** |
| 22 |
* Member Variable |
| 23 |
* |
| 24 |
* @var Advanced_Heading|null |
| 25 |
*/ |
| 26 |
private static $instance; |
| 27 |
|
| 28 |
/** |
| 29 |
* Initiator |
| 30 |
* |
| 31 |
* @return Advanced_Heading The instance of the Advanced_Heading class. |
| 32 |
*/ |
| 33 |
public static function get_instance() { |
| 34 |
if ( ! isset( self::$instance ) ) { |
| 35 |
self::$instance = new self(); |
| 36 |
} |
| 37 |
return self::$instance; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Constructor |
| 42 |
*/ |
| 43 |
public function __construct() { |
| 44 |
|
| 45 |
// Activation hook. |
| 46 |
add_action( 'init', [ $this, 'register_blocks' ] ); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Registers the `sureforms/advanced-heading` block on server. |
| 51 |
* |
| 52 |
* @since 0.0.1 |
| 53 |
* |
| 54 |
* @return void |
| 55 |
*/ |
| 56 |
public function register_blocks() { |
| 57 |
|
| 58 |
// Check if the register function exists. |
| 59 |
if ( ! function_exists( 'register_block_type' ) ) { |
| 60 |
return; |
| 61 |
} |
| 62 |
|
| 63 |
$attr = [ |
| 64 |
'block_id' => [ |
| 65 |
'type' => 'string', |
| 66 |
], |
| 67 |
'classMigrate' => [ |
| 68 |
'type' => 'boolean', |
| 69 |
'default' => false, |
| 70 |
], |
| 71 |
'blockBackgroundType' => [ |
| 72 |
'type' => 'string', |
| 73 |
'default' => 'classic', |
| 74 |
], |
| 75 |
'blockGradientBackground' => [ |
| 76 |
'type' => 'string', |
| 77 |
'default' => 'linear-gradient(90deg, rgb(6, 147, 227) 0%, rgb(155, 81, 224) 100%)', |
| 78 |
], |
| 79 |
'blockBackground' => [ |
| 80 |
'type' => 'string', |
| 81 |
], |
| 82 |
'headingTitleToggle' => [ |
| 83 |
'type' => 'boolean', |
| 84 |
'default' => true, |
| 85 |
], |
| 86 |
'headingTitle' => [ |
| 87 |
'type' => 'string', |
| 88 |
'default' => __( 'Your Attractive Heading', 'sureforms' ), |
| 89 |
], |
| 90 |
'headingId' => [ |
| 91 |
'type' => 'string', |
| 92 |
], |
| 93 |
'headingDescToggle' => [ |
| 94 |
'type' => 'boolean', |
| 95 |
'default' => false, |
| 96 |
], |
| 97 |
'headingDescPosition' => [ |
| 98 |
'type' => 'string', |
| 99 |
'default' => 'below-heading', |
| 100 |
], |
| 101 |
'headingDesc' => [ |
| 102 |
'type' => 'string', |
| 103 |
], |
| 104 |
'headingAlign' => [ |
| 105 |
'type' => 'string', |
| 106 |
'default' => 'left', |
| 107 |
], |
| 108 |
'headingAlignTablet' => [ |
| 109 |
'type' => 'string', |
| 110 |
'default' => '', |
| 111 |
], |
| 112 |
'headingAlignMobile' => [ |
| 113 |
'type' => 'string', |
| 114 |
'default' => '', |
| 115 |
], |
| 116 |
'headingColorType' => [ |
| 117 |
'type' => 'string', |
| 118 |
'default' => 'classic', |
| 119 |
], |
| 120 |
'headingColor' => [ |
| 121 |
'type' => 'string', |
| 122 |
'default' => '#000', |
| 123 |
], |
| 124 |
'headingGradientColor' => [ |
| 125 |
'type' => 'string', |
| 126 |
'default' => 'linear-gradient(90deg, rgb(155, 81, 224) 0%, rgb(6, 147, 227) 100%)', |
| 127 |
], |
| 128 |
'subHeadingColor' => [ |
| 129 |
'type' => 'string', |
| 130 |
'default' => '#000', |
| 131 |
], |
| 132 |
'separatorColor' => [ |
| 133 |
'type' => 'string', |
| 134 |
'default' => '#0170b9', |
| 135 |
], |
| 136 |
'headingTag' => [ |
| 137 |
'type' => 'string', |
| 138 |
'default' => 'h2', |
| 139 |
], |
| 140 |
'level' => [ |
| 141 |
'type' => 'number', |
| 142 |
'default' => 2, |
| 143 |
], |
| 144 |
'separatorStyle' => [ |
| 145 |
'type' => 'string', |
| 146 |
'default' => 'none', |
| 147 |
], |
| 148 |
'separatorPosition' => [ |
| 149 |
'type' => 'string', |
| 150 |
'default' => 'below-heading', |
| 151 |
], |
| 152 |
'separatorHeight' => [ |
| 153 |
'type' => 'number', |
| 154 |
'default' => 2, |
| 155 |
], |
| 156 |
'separatorHeightType' => [ |
| 157 |
'type' => 'string', |
| 158 |
'default' => 'px', |
| 159 |
], |
| 160 |
'separatorWidth' => [ |
| 161 |
'type' => 'number', |
| 162 |
'default' => 12, |
| 163 |
], |
| 164 |
'separatorWidthTablet' => [ |
| 165 |
'type' => 'number', |
| 166 |
], |
| 167 |
'separatorWidthMobile' => [ |
| 168 |
'type' => 'number', |
| 169 |
], |
| 170 |
'separatorWidthType' => [ |
| 171 |
'type' => 'string', |
| 172 |
'default' => '%', |
| 173 |
], |
| 174 |
'headSpace' => [ |
| 175 |
'type' => 'number', |
| 176 |
'default' => 15, |
| 177 |
], |
| 178 |
'headSpaceMobile' => [ |
| 179 |
'type' => 'number', |
| 180 |
'default' => '', |
| 181 |
], |
| 182 |
'headSpaceTablet' => [ |
| 183 |
'type' => 'number', |
| 184 |
'default' => '', |
| 185 |
], |
| 186 |
'headSpaceType' => [ |
| 187 |
'type' => 'string', |
| 188 |
'default' => 'px', |
| 189 |
], |
| 190 |
'subHeadSpace' => [ |
| 191 |
'type' => 'number', |
| 192 |
'default' => 15, |
| 193 |
], |
| 194 |
'subHeadSpaceMobile' => [ |
| 195 |
'type' => 'number', |
| 196 |
'default' => '', |
| 197 |
], |
| 198 |
'subHeadSpaceTablet' => [ |
| 199 |
'type' => 'number', |
| 200 |
'default' => '', |
| 201 |
], |
| 202 |
'subHeadSpaceType' => [ |
| 203 |
'type' => 'string', |
| 204 |
'default' => 'px', |
| 205 |
], |
| 206 |
'headFontFamily' => [ |
| 207 |
'type' => 'string', |
| 208 |
'default' => 'Default', |
| 209 |
], |
| 210 |
'headFontWeight' => [ |
| 211 |
'type' => 'string', |
| 212 |
], |
| 213 |
'headFontStyle' => [ |
| 214 |
'type' => 'string', |
| 215 |
'default' => 'normal', |
| 216 |
], |
| 217 |
'headTransform' => [ |
| 218 |
'type' => 'string', |
| 219 |
], |
| 220 |
'headDecoration' => [ |
| 221 |
'type' => 'string', |
| 222 |
], |
| 223 |
'headFontSizeType' => [ |
| 224 |
'type' => 'string', |
| 225 |
'default' => 'px', |
| 226 |
], |
| 227 |
'headFontSizeTypeMobile' => [ |
| 228 |
'type' => 'string', |
| 229 |
'default' => 'px', |
| 230 |
], |
| 231 |
'headFontSizeTypeTablet' => [ |
| 232 |
'type' => 'string', |
| 233 |
'default' => 'px', |
| 234 |
], |
| 235 |
'headLineHeightType' => [ |
| 236 |
'type' => 'string', |
| 237 |
'default' => 'em', |
| 238 |
], |
| 239 |
'headFontSize' => [ |
| 240 |
'type' => 'number', |
| 241 |
], |
| 242 |
'headFontSizeTablet' => [ |
| 243 |
'type' => 'number', |
| 244 |
], |
| 245 |
'headFontSizeMobile' => [ |
| 246 |
'type' => 'number', |
| 247 |
], |
| 248 |
'headLineHeight' => [ |
| 249 |
'type' => 'number', |
| 250 |
], |
| 251 |
'headLineHeightTablet' => [ |
| 252 |
'type' => 'number', |
| 253 |
], |
| 254 |
'headLineHeightMobile' => [ |
| 255 |
'type' => 'number', |
| 256 |
], |
| 257 |
'headLetterSpacing' => [ |
| 258 |
'type' => 'number', |
| 259 |
], |
| 260 |
'headLetterSpacingTablet' => [ |
| 261 |
'type' => 'number', |
| 262 |
], |
| 263 |
'headLetterSpacingMobile' => [ |
| 264 |
'type' => 'number', |
| 265 |
], |
| 266 |
'headLetterSpacingType' => [ |
| 267 |
'type' => 'string', |
| 268 |
'default' => 'px', |
| 269 |
], |
| 270 |
'headShadowColor' => [ |
| 271 |
'type' => 'string', |
| 272 |
'default' => '', |
| 273 |
], |
| 274 |
'headShadowHOffset' => [ |
| 275 |
'type' => 'number', |
| 276 |
'default' => 0, |
| 277 |
], |
| 278 |
'headShadowVOffset' => [ |
| 279 |
'type' => 'number', |
| 280 |
'default' => 0, |
| 281 |
], |
| 282 |
'headShadowBlur' => [ |
| 283 |
'type' => 'number', |
| 284 |
'default' => 10, |
| 285 |
], |
| 286 |
// sub headline. |
| 287 |
'subHeadFontFamily' => [ |
| 288 |
'type' => 'string', |
| 289 |
'default' => 'Default', |
| 290 |
], |
| 291 |
'subHeadFontWeight' => [ |
| 292 |
'type' => 'string', |
| 293 |
], |
| 294 |
'subHeadFontStyle' => [ |
| 295 |
'type' => 'string', |
| 296 |
'default' => 'normal', |
| 297 |
], |
| 298 |
'subHeadTransform' => [ |
| 299 |
'type' => 'string', |
| 300 |
], |
| 301 |
'subHeadDecoration' => [ |
| 302 |
'type' => 'string', |
| 303 |
], |
| 304 |
'subHeadFontSize' => [ |
| 305 |
'type' => 'number', |
| 306 |
], |
| 307 |
'subHeadFontSizeType' => [ |
| 308 |
'type' => 'string', |
| 309 |
'default' => 'px', |
| 310 |
], |
| 311 |
'subHeadFontSizeTypeMobile' => [ |
| 312 |
'type' => 'string', |
| 313 |
'default' => 'px', |
| 314 |
], |
| 315 |
'subHeadFontSizeTypeTablet' => [ |
| 316 |
'type' => 'string', |
| 317 |
'default' => 'px', |
| 318 |
], |
| 319 |
'subHeadFontSizeTablet' => [ |
| 320 |
'type' => 'number', |
| 321 |
], |
| 322 |
'subHeadFontSizeMobile' => [ |
| 323 |
'type' => 'number', |
| 324 |
], |
| 325 |
'subHeadLineHeight' => [ |
| 326 |
'type' => 'number', |
| 327 |
], |
| 328 |
'subHeadLineHeightType' => [ |
| 329 |
'type' => 'string', |
| 330 |
'default' => 'em', |
| 331 |
], |
| 332 |
'subHeadLineHeightTablet' => [ |
| 333 |
'type' => 'number', |
| 334 |
], |
| 335 |
'subHeadLineHeightMobile' => [ |
| 336 |
'type' => 'number', |
| 337 |
], |
| 338 |
'subHeadLetterSpacing' => [ |
| 339 |
'type' => 'number', |
| 340 |
], |
| 341 |
'subHeadLetterSpacingTablet' => [ |
| 342 |
'type' => 'number', |
| 343 |
], |
| 344 |
'subHeadLetterSpacingMobile' => [ |
| 345 |
'type' => 'number', |
| 346 |
], |
| 347 |
'subHeadLetterSpacingType' => [ |
| 348 |
'type' => 'string', |
| 349 |
'default' => 'px', |
| 350 |
], |
| 351 |
// separator. |
| 352 |
'separatorSpace' => [ |
| 353 |
'type' => 'number', |
| 354 |
'default' => 15, |
| 355 |
], |
| 356 |
'separatorSpaceTablet' => [ |
| 357 |
'type' => 'number', |
| 358 |
'default' => '', |
| 359 |
], |
| 360 |
'separatorSpaceMobile' => [ |
| 361 |
'type' => 'number', |
| 362 |
'default' => '', |
| 363 |
], |
| 364 |
'separatorSpaceType' => [ |
| 365 |
'type' => 'string', |
| 366 |
'default' => 'px', |
| 367 |
], |
| 368 |
'headLoadGoogleFonts' => [ |
| 369 |
'type' => 'boolean', |
| 370 |
'default' => false, |
| 371 |
], |
| 372 |
'subHeadLoadGoogleFonts' => [ |
| 373 |
'type' => 'boolean', |
| 374 |
'default' => false, |
| 375 |
], |
| 376 |
'separatorHoverColor' => [ |
| 377 |
'type' => 'string', |
| 378 |
], |
| 379 |
'isPreview' => [ |
| 380 |
'type' => 'boolean', |
| 381 |
'default' => false, |
| 382 |
], |
| 383 |
// padding. |
| 384 |
'blockTopPadding' => [ |
| 385 |
'type' => 'number', |
| 386 |
], |
| 387 |
'blockRightPadding' => [ |
| 388 |
'type' => 'number', |
| 389 |
], |
| 390 |
'blockLeftPadding' => [ |
| 391 |
'type' => 'number', |
| 392 |
], |
| 393 |
'blockBottomPadding' => [ |
| 394 |
'type' => 'number', |
| 395 |
], |
| 396 |
'blockTopPaddingTablet' => [ |
| 397 |
'type' => 'number', |
| 398 |
], |
| 399 |
'blockRightPaddingTablet' => [ |
| 400 |
'type' => 'number', |
| 401 |
], |
| 402 |
'blockLeftPaddingTablet' => [ |
| 403 |
'type' => 'number', |
| 404 |
], |
| 405 |
'blockBottomPaddingTablet' => [ |
| 406 |
'type' => 'number', |
| 407 |
], |
| 408 |
'blockTopPaddingMobile' => [ |
| 409 |
'type' => 'number', |
| 410 |
], |
| 411 |
'blockRightPaddingMobile' => [ |
| 412 |
'type' => 'number', |
| 413 |
], |
| 414 |
'blockLeftPaddingMobile' => [ |
| 415 |
'type' => 'number', |
| 416 |
], |
| 417 |
'blockBottomPaddingMobile' => [ |
| 418 |
'type' => 'number', |
| 419 |
], |
| 420 |
'blockPaddingUnit' => [ |
| 421 |
'type' => 'string', |
| 422 |
'default' => 'px', |
| 423 |
], |
| 424 |
'blockPaddingUnitTablet' => [ |
| 425 |
'type' => 'string', |
| 426 |
'default' => 'px', |
| 427 |
], |
| 428 |
'blockPaddingUnitMobile' => [ |
| 429 |
'type' => 'string', |
| 430 |
'default' => 'px', |
| 431 |
], |
| 432 |
'blockPaddingLink' => [ |
| 433 |
'type' => 'boolean', |
| 434 |
'default' => false, |
| 435 |
], |
| 436 |
// margin. |
| 437 |
'blockTopMargin' => [ |
| 438 |
'type' => 'number', |
| 439 |
], |
| 440 |
'blockRightMargin' => [ |
| 441 |
'type' => 'number', |
| 442 |
], |
| 443 |
'blockLeftMargin' => [ |
| 444 |
'type' => 'number', |
| 445 |
], |
| 446 |
'blockBottomMargin' => [ |
| 447 |
'type' => 'number', |
| 448 |
], |
| 449 |
'blockTopMarginTablet' => [ |
| 450 |
'type' => 'number', |
| 451 |
], |
| 452 |
'blockRightMarginTablet' => [ |
| 453 |
'type' => 'number', |
| 454 |
], |
| 455 |
'blockLeftMarginTablet' => [ |
| 456 |
'type' => 'number', |
| 457 |
], |
| 458 |
'blockBottomMarginTablet' => [ |
| 459 |
'type' => 'number', |
| 460 |
], |
| 461 |
'blockTopMarginMobile' => [ |
| 462 |
'type' => 'number', |
| 463 |
], |
| 464 |
'blockRightMarginMobile' => [ |
| 465 |
'type' => 'number', |
| 466 |
], |
| 467 |
'blockLeftMarginMobile' => [ |
| 468 |
'type' => 'number', |
| 469 |
], |
| 470 |
'blockBottomMarginMobile' => [ |
| 471 |
'type' => 'number', |
| 472 |
], |
| 473 |
'blockMarginUnit' => [ |
| 474 |
'type' => 'string', |
| 475 |
'default' => 'px', |
| 476 |
], |
| 477 |
'blockMarginUnitTablet' => [ |
| 478 |
'type' => 'string', |
| 479 |
'default' => 'px', |
| 480 |
], |
| 481 |
'blockMarginUnitMobile' => [ |
| 482 |
'type' => 'string', |
| 483 |
'default' => 'px', |
| 484 |
], |
| 485 |
'blockMarginLink' => [ |
| 486 |
'type' => 'boolean', |
| 487 |
'default' => false, |
| 488 |
], |
| 489 |
// link. |
| 490 |
'linkColor' => [ |
| 491 |
'type' => 'string', |
| 492 |
], |
| 493 |
'linkHColor' => [ |
| 494 |
'type' => 'string', |
| 495 |
], |
| 496 |
// Highlight. |
| 497 |
'highLightColor' => [ |
| 498 |
'type' => 'string', |
| 499 |
'default' => '#fff', |
| 500 |
], |
| 501 |
'highLightBackground' => [ |
| 502 |
'type' => 'string', |
| 503 |
'default' => '#007cba', |
| 504 |
], |
| 505 |
'highLightLoadGoogleFonts' => [ |
| 506 |
'type' => 'boolean', |
| 507 |
'default' => false, |
| 508 |
], |
| 509 |
'highLightFontFamily' => [ |
| 510 |
'type' => 'string', |
| 511 |
'default' => 'default', |
| 512 |
], |
| 513 |
'highLightFontWeight' => [ |
| 514 |
'type' => 'string', |
| 515 |
'default' => 'Default', |
| 516 |
], |
| 517 |
'highLightFontStyle' => [ |
| 518 |
'type' => 'string', |
| 519 |
'default' => 'normal', |
| 520 |
], |
| 521 |
'highLightTransform' => [ |
| 522 |
'type' => 'string', |
| 523 |
], |
| 524 |
'highLightDecoration' => [ |
| 525 |
'type' => 'string', |
| 526 |
], |
| 527 |
'highLightFontSizeType' => [ |
| 528 |
'type' => 'string', |
| 529 |
'default' => 'px', |
| 530 |
], |
| 531 |
'highLightFontSizeTypeMobile' => [ |
| 532 |
'type' => 'string', |
| 533 |
'default' => 'px', |
| 534 |
], |
| 535 |
'highLightFontSizeTypeTablet' => [ |
| 536 |
'type' => 'string', |
| 537 |
'default' => 'px', |
| 538 |
], |
| 539 |
'highLightLineHeightType' => [ |
| 540 |
'type' => 'string', |
| 541 |
'default' => 'em', |
| 542 |
], |
| 543 |
'highLightFontSize' => [ |
| 544 |
'type' => 'number', |
| 545 |
], |
| 546 |
'highLightFontSizeTablet' => [ |
| 547 |
'type' => 'number', |
| 548 |
], |
| 549 |
'highLightFontSizeMobile' => [ |
| 550 |
'type' => 'number', |
| 551 |
], |
| 552 |
'highLightLineHeight' => [ |
| 553 |
'type' => 'number', |
| 554 |
], |
| 555 |
'highLightLineHeightTablet' => [ |
| 556 |
'type' => 'number', |
| 557 |
], |
| 558 |
'highLightLineHeightMobile' => [ |
| 559 |
'type' => 'number', |
| 560 |
], |
| 561 |
'highLightLetterSpacing' => [ |
| 562 |
'type' => 'number', |
| 563 |
], |
| 564 |
'highLightLetterSpacingTablet' => [ |
| 565 |
'type' => 'number', |
| 566 |
], |
| 567 |
'highLightLetterSpacingMobile' => [ |
| 568 |
'type' => 'number', |
| 569 |
], |
| 570 |
'highLightLetterSpacingType' => [ |
| 571 |
'type' => 'string', |
| 572 |
'default' => 'px', |
| 573 |
], |
| 574 |
'highLightTopPadding' => [ |
| 575 |
'type' => 'number', |
| 576 |
], |
| 577 |
'highLightRightPadding' => [ |
| 578 |
'type' => 'number', |
| 579 |
], |
| 580 |
'highLightLeftPadding' => [ |
| 581 |
'type' => 'number', |
| 582 |
], |
| 583 |
'highLightBottomPadding' => [ |
| 584 |
'type' => 'number', |
| 585 |
], |
| 586 |
'highLightTopPaddingTablet' => [ |
| 587 |
'type' => 'number', |
| 588 |
], |
| 589 |
'highLightRightPaddingTablet' => [ |
| 590 |
'type' => 'number', |
| 591 |
], |
| 592 |
'highLightLeftPaddingTablet' => [ |
| 593 |
'type' => 'number', |
| 594 |
], |
| 595 |
'highLightBottomPaddingTablet' => [ |
| 596 |
'type' => 'number', |
| 597 |
], |
| 598 |
'highLightTopPaddingMobile' => [ |
| 599 |
'type' => 'number', |
| 600 |
], |
| 601 |
'highLightRightPaddingMobile' => [ |
| 602 |
'type' => 'number', |
| 603 |
], |
| 604 |
'highLightLeftPaddingMobile' => [ |
| 605 |
'type' => 'number', |
| 606 |
], |
| 607 |
'highLightBottomPaddingMobile' => [ |
| 608 |
'type' => 'number', |
| 609 |
], |
| 610 |
'highLightPaddingUnit' => [ |
| 611 |
'type' => 'string', |
| 612 |
'default' => 'px', |
| 613 |
], |
| 614 |
'highLightPaddingUnitTablet' => [ |
| 615 |
'type' => 'string', |
| 616 |
'default' => 'px', |
| 617 |
], |
| 618 |
'highLightPaddingUnitMobile' => [ |
| 619 |
'type' => 'string', |
| 620 |
'default' => 'px', |
| 621 |
], |
| 622 |
'highLightPaddingLink' => [ |
| 623 |
'type' => 'boolean', |
| 624 |
'default' => false, |
| 625 |
], |
| 626 |
]; |
| 627 |
|
| 628 |
$advaned_heading_border_attr = Spec_Gb_Helper::get_instance()->generate_php_border_attribute( 'highLight' ); |
| 629 |
|
| 630 |
$attr = array_merge( $advaned_heading_border_attr, $attr ); |
| 631 |
|
| 632 |
$attributes = apply_filters( 'srfm_gutenberg_advaned_heading_attributes_filters', $attr ); |
| 633 |
|
| 634 |
register_block_type( |
| 635 |
'srfm/advanced-heading', |
| 636 |
[ |
| 637 |
'attributes' => $attributes, |
| 638 |
'render_callback' => [ $this, 'render_html' ], |
| 639 |
] |
| 640 |
); |
| 641 |
} |
| 642 |
|
| 643 |
/** |
| 644 |
* Render CF HTML. |
| 645 |
* |
| 646 |
* @param array<mixed> $attributes Array of block attributes. |
| 647 |
* |
| 648 |
* @since 0.0.1 |
| 649 |
* |
| 650 |
* @return string|false |
| 651 |
*/ |
| 652 |
public function render_html( $attributes ) { |
| 653 |
|
| 654 |
$block_id = ''; |
| 655 |
$form_id = ''; |
| 656 |
$heading_wrapper = ''; |
| 657 |
if ( isset( $attributes['block_id'] ) ) { |
| 658 |
$block_id = $attributes['block_id']; |
| 659 |
} |
| 660 |
if ( isset( $attributes['formId'] ) ) { |
| 661 |
$form_id = $attributes['formId']; |
| 662 |
} |
| 663 |
if ( isset( $attributes['headingWrapper'] ) ) { |
| 664 |
$heading_wrapper = $attributes['headingWrapper']; |
| 665 |
} |
| 666 |
|
| 667 |
// Validate tag-name attributes against the editor UI options to prevent |
| 668 |
// arbitrary HTML injection in tag-name position (esc_attr() does not strip |
| 669 |
// `<`, `>`, spaces or `=`, which is unsafe when echoed as a tag name). |
| 670 |
$allowed_wrapper_tags = [ 'div', 'header' ]; |
| 671 |
$allowed_heading_tags = [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div' ]; |
| 672 |
|
| 673 |
$element = in_array( $heading_wrapper, $allowed_wrapper_tags, true ) ? $heading_wrapper : 'div'; |
| 674 |
|
| 675 |
$heading_tag = isset( $attributes['headingTag'] ) && in_array( $attributes['headingTag'], $allowed_heading_tags, true ) |
| 676 |
? $attributes['headingTag'] |
| 677 |
: 'h2'; |
| 678 |
|
| 679 |
$seperator = ''; |
| 680 |
|
| 681 |
if ( isset( $attributes['separatorStyle'] ) |
| 682 |
&& 'none' !== $attributes['separatorStyle'] |
| 683 |
) { |
| 684 |
$seperator = '<div class="uagb-separator"></div>'; |
| 685 |
} |
| 686 |
|
| 687 |
$heading_text = ''; |
| 688 |
|
| 689 |
if ( isset( $attributes['headingTitle'] ) ) { |
| 690 |
$heading_text = 'above-heading' === $attributes['separatorPosition'] ? $seperator : ''; |
| 691 |
$attributes['headingId'] = isset( $attributes['headingId'] ) ? "id='{$attributes['headingId']}'" : ''; |
| 692 |
$heading_text .= sprintf( |
| 693 |
'<%1$s class="uagb-heading-text" %3$s>%2$s</%1$s>', |
| 694 |
esc_attr( $heading_tag ), |
| 695 |
$attributes['headingTitle'], |
| 696 |
esc_attr( $attributes['headingId'] ) |
| 697 |
); |
| 698 |
$heading_text .= 'below-heading' === $attributes['separatorPosition'] ? $seperator : ''; |
| 699 |
} |
| 700 |
|
| 701 |
$desc_text = ''; |
| 702 |
|
| 703 |
if ( isset( $attributes['headingDesc'] ) ) { |
| 704 |
$desc_text = 'above-sub-heading' === $attributes['separatorPosition'] ? $seperator : ''; |
| 705 |
$desc_text .= sprintf( |
| 706 |
'<p class="uagb-desc-text">%1$s</p>', |
| 707 |
$attributes['headingDesc'] |
| 708 |
); |
| 709 |
$desc_text .= 'below-sub-heading' === $attributes['separatorPosition'] ? $seperator : ''; |
| 710 |
} |
| 711 |
|
| 712 |
$conditional_class = apply_filters( 'srfm_conditional_logic_classes', $form_id, $block_id ); |
| 713 |
|
| 714 |
$filter_classes = apply_filters( 'srfm_field_classes', '', [ 'attributes' => $attributes ] ); |
| 715 |
$field_config = apply_filters( |
| 716 |
'srfm_field_config', |
| 717 |
[], |
| 718 |
[ |
| 719 |
'attributes' => $attributes, |
| 720 |
'blockName' => 'srfm/advanced-heading', |
| 721 |
] |
| 722 |
); |
| 723 |
$field_config = $field_config ? htmlspecialchars( Helper::get_string_value( wp_json_encode( $field_config, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ), ENT_QUOTES, 'UTF-8' ) : ''; |
| 724 |
|
| 725 |
$main_classes = [ |
| 726 |
'wp-block-uagb-advanced-heading', |
| 727 |
'uagb-block', |
| 728 |
'uagb-block-' . $block_id, |
| 729 |
$conditional_class, |
| 730 |
$filter_classes, |
| 731 |
]; |
| 732 |
|
| 733 |
if ( isset( $attributes['className'] ) ) { |
| 734 |
$main_classes[] = $attributes['className']; |
| 735 |
} |
| 736 |
|
| 737 |
ob_start(); |
| 738 |
?> |
| 739 |
<<?php echo esc_attr( $element ); ?> data-block-id="<?php echo esc_attr( $block_id ); ?>" class="<?php echo esc_attr( implode( ' ', $main_classes ) ); ?>" <?php echo ! empty( $field_config ) ? "data-field-config='" . esc_attr( $field_config ) . "'" : ''; ?>> |
| 740 |
<?php |
| 741 |
if ( $attributes['headingDescToggle'] |
| 742 |
&& 'above-heading' === $attributes['headingDescPosition'] |
| 743 |
) { |
| 744 |
echo wp_kses( $desc_text, 'post' ); |
| 745 |
} |
| 746 |
if ( isset( $attributes['headingTitleToggle'] ) && true === $attributes['headingTitleToggle'] ) { |
| 747 |
echo wp_kses( $heading_text, 'post' ); |
| 748 |
} |
| 749 |
if ( $attributes['headingDescToggle'] |
| 750 |
&& 'below-heading' === $attributes['headingDescPosition'] |
| 751 |
) { |
| 752 |
echo wp_kses( $desc_text, 'post' ); |
| 753 |
} |
| 754 |
if ( ! $attributes['headingDescToggle'] |
| 755 |
&& ! $attributes['headingTitleToggle'] |
| 756 |
) { |
| 757 |
echo wp_kses( $seperator, 'post' ); |
| 758 |
} |
| 759 |
?> |
| 760 |
</<?php echo esc_attr( $element ); ?>> |
| 761 |
<?php |
| 762 |
return ob_get_clean(); |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
/** |
| 767 |
* Prepare if class 'Advanced_Heading' exist. |
| 768 |
* Kicking this off by calling 'get_instance()' method |
| 769 |
*/ |
| 770 |
Advanced_Heading::get_instance(); |
| 771 |
} |
| 772 |
|