| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 3 |
|
| 4 |
if ( ! class_exists( 'ewduwpmBlocks' ) ) { |
| 5 |
/** |
| 6 |
* Class to handle plugin Gutenberg blocks |
| 7 |
* |
| 8 |
* @since 1.0.0 |
| 9 |
*/ |
| 10 |
class ewduwpmBlocks { |
| 11 |
|
| 12 |
public function __construct() { |
| 13 |
|
| 14 |
add_action( 'init', array( $this, 'add_blocks' ) ); |
| 15 |
|
| 16 |
add_filter( 'block_categories_all', array( $this, 'add_block_category' ) ); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Add the Gutenberg block to the list of available blocks |
| 21 |
* @since 1.0.0 |
| 22 |
*/ |
| 23 |
public function add_blocks() { |
| 24 |
|
| 25 |
if ( ! function_exists( 'render_block_core_block' ) ) { return; } |
| 26 |
|
| 27 |
$this->enqueue_assets(); |
| 28 |
|
| 29 |
$args = array( |
| 30 |
'attributes' => array( |
| 31 |
'display_interests' => array( |
| 32 |
'type' => 'string', |
| 33 |
), |
| 34 |
), |
| 35 |
'editor_script' => 'ewd-uwpm-blocks-js', |
| 36 |
'editor_style' => 'ewd-uwpm-blocks-css', |
| 37 |
'render_callback' => 'ewd_uwpm_subscription_interests_shortcode', |
| 38 |
); |
| 39 |
|
| 40 |
register_block_type( 'ultimate-wp-mail/ewd-uwpm-subscription-interests-block', $args ); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Create a new category of blocks to hold our block |
| 45 |
* @since 1.0.0 |
| 46 |
*/ |
| 47 |
public function add_block_category( $categories ) { |
| 48 |
|
| 49 |
$categories[] = array( |
| 50 |
'slug' => 'ewd-uwpm-blocks', |
| 51 |
'title' => __( 'Ultimate WP Mail', 'ultimate-wp-mail' ), |
| 52 |
); |
| 53 |
|
| 54 |
return $categories; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Register the necessary JS and CSS to display the block in the editor |
| 59 |
* @since 1.0.0 |
| 60 |
*/ |
| 61 |
public function enqueue_assets() { |
| 62 |
|
| 63 |
wp_register_script( 'ewd-uwpm-blocks-js', EWD_UWPM_PLUGIN_URL . '/assets/js/ewd-uwpm-blocks.js', array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-editor' ), EWD_UWPM_VERSION ); |
| 64 |
wp_register_style( 'ewd-uwpm-blocks-css', EWD_UWPM_PLUGIN_URL . '/assets/css/ewd-uwpm-blocks.css', array( 'wp-edit-blocks' ), EWD_UWPM_VERSION ); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
} |