| 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 |
// Wrapper Style |
| 27 |
'advanceId' => '', |
| 28 |
'advanceZindex' => '', |
| 29 |
'hideExtraLarge' => false, |
| 30 |
'hideTablet' => false, |
| 31 |
'hideMobile' => false, |
| 32 |
'advanceCss' => '', |
| 33 |
); |
| 34 |
} |
| 35 |
|
| 36 |
public function register() { |
| 37 |
register_block_type( 'ultimate-post/heading', |
| 38 |
array( |
| 39 |
'editor_script' => 'ultp-blocks-editor-script', |
| 40 |
'editor_style' => 'ultp-blocks-editor-css', |
| 41 |
'render_callback' => array( $this, 'content' ) |
| 42 |
) |
| 43 |
); |
| 44 |
} |
| 45 |
|
| 46 |
public function content( $attr, $noAjax ) { |
| 47 |
$attr = wp_parse_args( $attr, $this->get_attributes() ); |
| 48 |
|
| 49 |
$wraper_before = ''; |
| 50 |
$block_name = 'heading'; |
| 51 |
$attr['headingShow'] = true; |
| 52 |
$attr['className'] = isset($attr['className']) && $attr['className'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['className']) : ''; |
| 53 |
$attr['align'] = isset($attr['align']) && $attr['align'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['align']) : ''; |
| 54 |
$attr['advanceId'] = isset($attr['advanceId']) ? sanitize_html_class( $attr['advanceId'] ) : ''; |
| 55 |
$attr['blockId'] = isset($attr['blockId']) ? sanitize_html_class( $attr['blockId'] ) : ''; |
| 56 |
|
| 57 |
$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"]:'').'">'; |
| 58 |
$wraper_before .= '<div class="ultp-block-wrapper">'; |
| 59 |
include ULTP_PATH . 'blocks/template/heading.php'; |
| 60 |
$wraper_before .= '</div>'; |
| 61 |
$wraper_before .= '</div>'; |
| 62 |
|
| 63 |
return $wraper_before; |
| 64 |
} |
| 65 |
} |