| 1 |
<?php |
| 2 |
/** |
| 3 |
* Section Heading Block. |
| 4 |
* |
| 5 |
* @package Canvas |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Initialize Section Heading Block. |
| 10 |
*/ |
| 11 |
class CNVS_Block_Section_Heading { |
| 12 |
|
| 13 |
/** |
| 14 |
* Initialize |
| 15 |
*/ |
| 16 |
public function __construct() { |
| 17 |
add_action( 'init', array( $this, 'init' ) ); |
| 18 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ), 5 ); |
| 19 |
add_filter( 'canvas_register_block_type', array( $this, 'register_block_type' ) ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Enqueue the block's assets for the editor. |
| 24 |
*/ |
| 25 |
public function init() { |
| 26 |
// Editor Scripts. |
| 27 |
wp_register_script( |
| 28 |
'canvas-block-section-heading-editor-script', |
| 29 |
plugins_url( 'block-section-heading/block.js', __FILE__ ), |
| 30 |
array( 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-editor', 'lodash', 'jquery' ), |
| 31 |
filemtime( plugin_dir_path( __FILE__ ) . 'block-section-heading/block.js' ), |
| 32 |
true |
| 33 |
); |
| 34 |
|
| 35 |
wp_register_style( |
| 36 |
'canvas-block-section-heading-editor-style', |
| 37 |
plugins_url( 'block-section-heading/block-editor.css', __FILE__ ), |
| 38 |
array(), |
| 39 |
filemtime( plugin_dir_path( __FILE__ ) . 'block-section-heading/block-editor.css' ) |
| 40 |
); |
| 41 |
|
| 42 |
wp_style_add_data( 'canvas-block-section-heading-editor-style', 'rtl', 'replace' ); |
| 43 |
|
| 44 |
// Styles. |
| 45 |
wp_register_style( |
| 46 |
'canvas-block-section-heading-style', |
| 47 |
plugins_url( 'block-section-heading/block.css', __FILE__ ), |
| 48 |
array(), |
| 49 |
filemtime( plugin_dir_path( __FILE__ ) . 'block-section-heading/block.css' ) |
| 50 |
); |
| 51 |
|
| 52 |
wp_style_add_data( 'canvas-block-section-heading-style', 'rtl', 'replace' ); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* This function will register scripts and styles for admin dashboard. |
| 57 |
* |
| 58 |
* @param string $page Current page. |
| 59 |
*/ |
| 60 |
public function admin_enqueue_scripts( $page ) { |
| 61 |
wp_localize_script( |
| 62 |
'jquery-ui-core', |
| 63 |
'canvasBSHLocalize', |
| 64 |
array( |
| 65 |
'sectionHeadingAlign' => apply_filters( 'canvas_section_heading_align', 'halignleft' ), |
| 66 |
'sectionHeadingTag' => apply_filters( 'canvas_section_heading_tag', 'h2' ), |
| 67 |
) |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Register block |
| 73 |
* |
| 74 |
* @param array $blocks all registered blocks. |
| 75 |
* @return array |
| 76 |
*/ |
| 77 |
public function register_block_type( $blocks ) { |
| 78 |
|
| 79 |
$blocks[] = array( |
| 80 |
'name' => 'canvas/section-heading', |
| 81 |
'title' => esc_html__( 'Section Heading', 'canvas' ), |
| 82 |
'description' => '', |
| 83 |
'category' => 'canvas', |
| 84 |
'keywords' => array(), |
| 85 |
'icon' => 'heading', |
| 86 |
'supports' => array( |
| 87 |
'className' => true, |
| 88 |
'anchor' => true, |
| 89 |
'html' => false, |
| 90 |
'canvasSpacings' => true, |
| 91 |
'canvasBorder' => true, |
| 92 |
'canvasResponsive' => true, |
| 93 |
'align' => false, |
| 94 |
), |
| 95 |
'styles' => array( |
| 96 |
array( |
| 97 |
'name' => 'cnvs-block-section-heading-default', |
| 98 |
'label' => esc_html__( 'Default', 'canvas' ), |
| 99 |
), |
| 100 |
array( |
| 101 |
'name' => 'cnvs-block-section-heading-1', |
| 102 |
'label' => esc_html__( 'Plain', 'canvas' ), |
| 103 |
), |
| 104 |
array( |
| 105 |
'name' => 'cnvs-block-section-heading-2', |
| 106 |
'label' => esc_html__( 'Thin Bottom Line', 'canvas' ), |
| 107 |
), |
| 108 |
array( |
| 109 |
'name' => 'cnvs-block-section-heading-3', |
| 110 |
'label' => esc_html__( 'Thick Bottom Line', 'canvas' ), |
| 111 |
), |
| 112 |
array( |
| 113 |
'name' => 'cnvs-block-section-heading-4', |
| 114 |
'label' => esc_html__( 'Thin Side Line', 'canvas' ), |
| 115 |
), |
| 116 |
array( |
| 117 |
'name' => 'cnvs-block-section-heading-5', |
| 118 |
'label' => esc_html__( 'Thick Side Line', 'canvas' ), |
| 119 |
), |
| 120 |
array( |
| 121 |
'name' => 'cnvs-block-section-heading-6', |
| 122 |
'label' => esc_html__( 'Top Line', 'canvas' ), |
| 123 |
), |
| 124 |
array( |
| 125 |
'name' => 'cnvs-block-section-heading-7', |
| 126 |
'label' => esc_html__( 'Bottom Line, Medium Length', 'canvas' ), |
| 127 |
), |
| 128 |
array( |
| 129 |
'name' => 'cnvs-block-section-heading-8', |
| 130 |
'label' => esc_html__( 'Side Line with Angle', 'canvas' ), |
| 131 |
), |
| 132 |
array( |
| 133 |
'name' => 'cnvs-block-section-heading-9', |
| 134 |
'label' => esc_html__( 'Cross Icon', 'canvas' ), |
| 135 |
), |
| 136 |
array( |
| 137 |
'name' => 'cnvs-block-section-heading-10', |
| 138 |
'label' => esc_html__( 'Scewed Background', 'canvas' ), |
| 139 |
), |
| 140 |
array( |
| 141 |
'name' => 'cnvs-block-section-heading-11', |
| 142 |
'label' => esc_html__( 'Scewed Background, Side Line', 'canvas' ), |
| 143 |
), |
| 144 |
array( |
| 145 |
'name' => 'cnvs-block-section-heading-12', |
| 146 |
'label' => esc_html__( 'Solid Background', 'canvas' ), |
| 147 |
), |
| 148 |
array( |
| 149 |
'name' => 'cnvs-block-section-heading-13', |
| 150 |
'label' => esc_html__( 'Bordered', 'canvas' ), |
| 151 |
), |
| 152 |
array( |
| 153 |
'name' => 'cnvs-block-section-heading-14', |
| 154 |
'label' => esc_html__( 'Solid Background, Fullwidth', 'canvas' ), |
| 155 |
), |
| 156 |
array( |
| 157 |
'name' => 'cnvs-block-section-heading-15', |
| 158 |
'label' => esc_html__( 'Bordered, Fullwidth', 'canvas' ), |
| 159 |
), |
| 160 |
array( |
| 161 |
'name' => 'cnvs-block-section-heading-16', |
| 162 |
'label' => esc_html__( 'Double Line with Angle', 'canvas' ), |
| 163 |
), |
| 164 |
array( |
| 165 |
'name' => 'cnvs-block-section-heading-17', |
| 166 |
'label' => esc_html__( 'Bottom Line, Short Length', 'canvas' ), |
| 167 |
), |
| 168 |
), |
| 169 |
'location' => array(), |
| 170 |
'sections' => array( |
| 171 |
'color' => array( |
| 172 |
'title' => esc_html__( 'Color Settings', 'canvas' ), |
| 173 |
'priority' => 50, |
| 174 |
), |
| 175 |
'typography' => array( |
| 176 |
'title' => esc_html__( 'Typography Settings', 'canvas' ), |
| 177 |
'priority' => 45, |
| 178 |
), |
| 179 |
), |
| 180 |
'layouts' => array(), |
| 181 |
|
| 182 |
// Set fields just for add block attributes. |
| 183 |
// Editor render for this block is custom JSX |
| 184 |
// so we don't need to render fields automatically. |
| 185 |
'fields' => array( |
| 186 |
array( |
| 187 |
'key' => 'halign', |
| 188 |
'type' => 'type-string', |
| 189 |
), |
| 190 |
array( |
| 191 |
'key' => 'tag', |
| 192 |
'type' => 'type-string', |
| 193 |
), |
| 194 |
array( |
| 195 |
'key' => 'content', |
| 196 |
'type' => 'type-string', |
| 197 |
), |
| 198 |
array( |
| 199 |
'key' => 'colorHeadingBorder', |
| 200 |
'label' => esc_html__( 'Border Color', 'canvas' ), |
| 201 |
'section' => 'color', |
| 202 |
'type' => 'color', |
| 203 |
'output' => array( |
| 204 |
array( |
| 205 |
'element' => '$, $ .cnvs-section-title, $:before, $:after, $ .cnvs-section-title:before, $ .cnvs-section-title:after', |
| 206 |
'property' => 'border-color', |
| 207 |
'suffix' => '!important', |
| 208 |
), |
| 209 |
), |
| 210 |
), |
| 211 |
array( |
| 212 |
'key' => 'colorHeadingAccent', |
| 213 |
'label' => esc_html__( 'Accent Color', 'canvas' ), |
| 214 |
'section' => 'color', |
| 215 |
'type' => 'color', |
| 216 |
'output' => array( |
| 217 |
array( |
| 218 |
'element' => '$.is-style-cnvs-block-section-heading-11 .cnvs-section-title:before, $.is-style-cnvs-block-section-heading-10 .cnvs-section-title:before, $.is-style-cnvs-block-section-heading-9 .cnvs-section-title:before, $.is-style-cnvs-block-section-heading-9 .cnvs-section-title:after, $.is-style-cnvs-block-section-heading-12 .cnvs-section-title, $.is-style-cnvs-block-section-heading-14, .section-heading-default-style-11 $.is-style-cnvs-block-section-heading-default .cnvs-section-title:before, .section-heading-default-style-10 $.is-style-cnvs-block-section-heading-default .cnvs-section-title:before, .section-heading-default-style-9 $.is-style-cnvs-block-section-heading-default .cnvs-section-title:before, .section-heading-default-style-9 $.is-style-cnvs-block-section-heading-default .cnvs-section-title:after, .section-heading-default-style-12 $.is-style-cnvs-block-section-heading-default .cnvs-section-title, .section-heading-default-style-14 $.is-style-cnvs-block-section-heading-default', |
| 219 |
'property' => 'background-color', |
| 220 |
'suffix' => '!important', |
| 221 |
), |
| 222 |
), |
| 223 |
), |
| 224 |
array( |
| 225 |
'key' => 'colorHeading', |
| 226 |
'label' => esc_html__( 'Text Color', 'canvas' ), |
| 227 |
'section' => 'color', |
| 228 |
'type' => 'color', |
| 229 |
'output' => array( |
| 230 |
array( |
| 231 |
'element' => '$ .cnvs-section-title', |
| 232 |
'property' => 'color', |
| 233 |
'suffix' => '!important', |
| 234 |
), |
| 235 |
), |
| 236 |
), |
| 237 |
array( |
| 238 |
'key' => 'typographyHeading', |
| 239 |
'label' => esc_html__( 'Font Size', 'canvas' ), |
| 240 |
'section' => 'typography', |
| 241 |
'type' => 'dimension', |
| 242 |
'responsive' => true, |
| 243 |
'output' => array( |
| 244 |
array( |
| 245 |
'element' => '$ .cnvs-section-title', |
| 246 |
'property' => 'font-size', |
| 247 |
'suffix' => '!important', |
| 248 |
), |
| 249 |
), |
| 250 |
), |
| 251 |
), |
| 252 |
'template' => dirname( __FILE__ ) . '/block-section-heading/render.php', |
| 253 |
|
| 254 |
// enqueue registered scripts/styles. |
| 255 |
'style' => 'canvas-block-section-heading-style', |
| 256 |
'editor_style' => 'canvas-block-section-heading-editor-style', |
| 257 |
'editor_script' => 'canvas-block-section-heading-editor-script', |
| 258 |
); |
| 259 |
|
| 260 |
return $blocks; |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
new CNVS_Block_Section_Heading(); |
| 265 |
|