| 1 |
<?php |
| 2 |
namespace ULTP\blocks; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || exit; |
| 5 |
|
| 6 |
class Heading { |
| 7 |
|
| 8 |
public function __construct() { |
| 9 |
add_action( 'init', array( $this, 'register' ) ); |
| 10 |
} |
| 11 |
|
| 12 |
public function get_attributes() { |
| 13 |
|
| 14 |
return array( |
| 15 |
'blockId' => '', |
| 16 |
// Heading Setting/Style |
| 17 |
'headingText' => 'This is a Heading Example', |
| 18 |
'headingURL' => '', |
| 19 |
'openInTab' => false, |
| 20 |
'headingBtnText' => 'View More', |
| 21 |
'headingStyle' => 'style9', |
| 22 |
'headingTag' => 'h2', |
| 23 |
'headingAlign' => 'left', |
| 24 |
'subHeadingShow' => false, |
| 25 |
'subHeadingText' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ut sem augue. Sed at felis ut enim dignissim sodales.', |
| 26 |
|
| 27 |
// Custom Meta Support |
| 28 |
|
| 29 |
// Wrapper Style |
| 30 |
'advanceId' => '', |
| 31 |
'advanceZindex' => '', |
| 32 |
'hideExtraLarge' => false, |
| 33 |
'hideTablet' => false, |
| 34 |
'hideMobile' => false, |
| 35 |
'advanceCss' => '', |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
public function register() { |
| 40 |
register_block_type( |
| 41 |
'ultimate-post/heading', |
| 42 |
array( |
| 43 |
'editor_script' => 'ultp-blocks-editor-script', |
| 44 |
'editor_style' => 'ultp-blocks-editor-css', |
| 45 |
'render_callback' => array( $this, 'content' ), |
| 46 |
) |
| 47 |
); |
| 48 |
} |
| 49 |
|
| 50 |
public function content( $attr, $noAjax ) { |
| 51 |
$attr = wp_parse_args( $attr, $this->get_attributes() ); |
| 52 |
|
| 53 |
$wraper_before = ''; |
| 54 |
$block_name = 'heading'; |
| 55 |
$attr['headingShow'] = true; |
| 56 |
$attr['className'] = isset( $attr['className'] ) && $attr['className'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['className'] ) : ''; |
| 57 |
$attr['align'] = isset( $attr['align'] ) && $attr['align'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['align'] ) : ''; |
| 58 |
$attr['advanceId'] = isset( $attr['advanceId'] ) ? sanitize_html_class( $attr['advanceId'] ) : ''; |
| 59 |
$attr['blockId'] = isset( $attr['blockId'] ) ? sanitize_html_class( $attr['blockId'] ) : ''; |
| 60 |
|
| 61 |
$wraper_before .= '<div ' . ( $attr['advanceId'] ? 'id="' . $attr['advanceId'] . '" ' : '' ) . ' class="wp-block-ultimate-post-' . $block_name . ' ultp-block-' . $attr['blockId'] . '' . ( $attr['align'] ? ' align' . $attr['align'] : '' ) . '' . ( $attr['className'] ? ' ' . $attr['className'] : '' ) . '">'; |
| 62 |
$wraper_before .= '<div class="ultp-block-wrapper">'; |
| 63 |
include ULTP_PATH . 'blocks/template/heading.php'; |
| 64 |
$wraper_before .= '</div>'; |
| 65 |
$wraper_before .= '</div>'; |
| 66 |
|
| 67 |
return $wraper_before; |
| 68 |
} |
| 69 |
} |
| 70 |
|