PluginProbe
Canvas / 2.4.9
Canvas v2.4.9
2.5.5 2.5.4 trunk 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 All 54 releases
canvas / components / basic-elements / class-block-alert.php

class-block-alert.php in Canvas 2.4.9, at components/basic-elements/class-block-alert.php

146 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Alert Block.
4 *
5 * @package Canvas
6 */
7
8 /**
9 * Initialize Alert block.
10 */
11 class CNVS_Block_Alert {
12
13 /**
14 * Initialize
15 */
16 public function __construct() {
17 add_action( 'init', array( $this, 'init' ) );
18 add_filter( 'canvas_register_block_type', array( $this, 'register_block_type' ) );
19 }
20
21 /**
22 * Enqueue the block's assets for the editor.
23 */
24 public function init() {
25 // Editor Scripts.
26 wp_register_script(
27 'canvas-block-alert-editor-script',
28 plugins_url( 'block-alert/block.js', __FILE__ ),
29 array( 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-editor', 'lodash', 'jquery' ),
30 filemtime( plugin_dir_path( __FILE__ ) . 'block-alert/block.js' ),
31 true
32 );
33
34 wp_register_style(
35 'canvas-block-alert-editor-style',
36 plugins_url( 'block-alert/block-editor.css', __FILE__ ),
37 array(),
38 filemtime( plugin_dir_path( __FILE__ ) . 'block-alert/block-editor.css' )
39 );
40
41 wp_style_add_data( 'canvas-block-alert-editor-style', 'rtl', 'replace' );
42
43 // Styles.
44 wp_register_style(
45 'canvas-block-alert-style',
46 plugins_url( 'block-alert/block.css', __FILE__ ),
47 array(),
48 filemtime( plugin_dir_path( __FILE__ ) . 'block-alert/block.css' )
49 );
50
51 wp_style_add_data( 'canvas-block-alert-style', 'rtl', 'replace' );
52
53 // Scripts.
54 wp_register_script( 'canvas-block-alert-script', plugin_dir_url( __FILE__ ) . 'block-alert/public-block-alert.js', array( 'jquery' ), cnvs_get_setting( 'version' ), true );
55 }
56
57 /**
58 * Register block
59 *
60 * @param array $blocks all registered blocks.
61 * @return array
62 */
63 public function register_block_type( $blocks ) {
64 $blocks[] = array(
65 'name' => 'canvas/alert',
66 'title' => esc_html__( 'Alert', 'canvas' ),
67 'description' => '',
68 'category' => 'canvas',
69 'keywords' => array(),
70 'icon' => '
71 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
72 <path d="M11 15H13V17H11V15ZM11 7H13V13H11V7ZM11.99 2C6.47 2 2 6.48 2 12C2 17.52 6.47 22 11.99 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 11.99 2ZM12 20C7.58 20 4 16.42 4 12C4 7.58 7.58 4 12 4C16.42 4 20 7.58 20 12C20 16.42 16.42 20 12 20Z" />
73 </svg>
74 ',
75 'supports' => array(
76 'className' => true,
77 'anchor' => true,
78 'html' => false,
79 'canvasSpacings' => true,
80 'canvasBorder' => true,
81 'canvasResponsive' => true,
82 ),
83 'styles' => array(
84 array(
85 'name' => 'cnvs-block-alert-primary',
86 'label' => esc_html__( 'Primary', 'canvas' ),
87 ),
88 array(
89 'name' => 'cnvs-block-alert-success',
90 'label' => esc_html__( 'Success', 'canvas' ),
91 ),
92 array(
93 'name' => 'cnvs-block-alert-info',
94 'label' => esc_html__( 'Info', 'canvas' ),
95 ),
96 array(
97 'name' => 'cnvs-block-alert-warning',
98 'label' => esc_html__( 'Warning', 'canvas' ),
99 ),
100 array(
101 'name' => 'cnvs-block-alert-danger',
102 'label' => esc_html__( 'Danger', 'canvas' ),
103 ),
104 array(
105 'name' => 'cnvs-block-alert-dark',
106 'label' => esc_html__( 'Dark', 'canvas' ),
107 ),
108 ),
109 'location' => array(),
110
111 'sections' => array(
112 'general' => array(
113 'title' => esc_html__( 'Block Settings', 'canvas' ),
114 'priority' => 5,
115 'open' => true,
116 ),
117 ),
118 'layouts' => array(),
119
120 // Set fields just for add block attributes.
121 // Editor render for this block is custom JSX
122 // so we don't need to render fields automatically.
123 'fields' => array(
124 array(
125 'key' => 'dismissible',
126 'label' => esc_html__( 'Dismissible', 'canvas' ),
127 'type' => 'toggle',
128 'default' => false,
129 'section' => 'general',
130 ),
131 ),
132 'template' => dirname( __FILE__ ) . '/block-alert/render.php',
133
134 // enqueue registered scripts/styles.
135 'style' => 'canvas-block-alert-style',
136 'script' => is_admin() ? '' : 'canvas-block-alert-script',
137 'editor_style' => 'canvas-block-alert-editor-style',
138 'editor_script' => 'canvas-block-alert-editor-script',
139 );
140
141 return $blocks;
142 }
143 }
144
145 new CNVS_Block_Alert();
146