| 1 |
<?php |
| 2 |
/** |
| 3 |
* The Gutenberg Block. |
| 4 |
* |
| 5 |
* @link https://codesupply.co |
| 6 |
* @since 1.0.0 |
| 7 |
* |
| 8 |
* @package Powerkit |
| 9 |
* @subpackage Modules/public |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* The initialize block. |
| 14 |
*/ |
| 15 |
class Powerkit_Subscription_Block { |
| 16 |
|
| 17 |
/** |
| 18 |
* Initialize |
| 19 |
*/ |
| 20 |
public function __construct() { |
| 21 |
add_action( 'init', array( $this, 'block' ) ); |
| 22 |
add_filter( 'canvas_register_block_type', array( $this, 'register_block_type' ) ); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Enqueue the block's assets for the editor. |
| 27 |
*/ |
| 28 |
public function block() { |
| 29 |
// Styles. |
| 30 |
wp_register_style( |
| 31 |
'powerkit-subscription-block-editor-style', |
| 32 |
plugins_url( 'css/public-powerkit-opt-in-forms.css', __FILE__ ), |
| 33 |
array( 'wp-edit-blocks' ), |
| 34 |
filemtime( plugin_dir_path( __FILE__ ) . 'css/public-powerkit-opt-in-forms.css' ) |
| 35 |
); |
| 36 |
|
| 37 |
wp_style_add_data( 'powerkit-subscription-block-editor-style', 'rtl', 'replace' ); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Register block |
| 42 |
* |
| 43 |
* @param array $blocks all registered blocks. |
| 44 |
* @return array |
| 45 |
*/ |
| 46 |
public function register_block_type( $blocks ) { |
| 47 |
$blocks[] = array( |
| 48 |
'name' => 'canvas/opt-in-form', |
| 49 |
'title' => esc_html__( 'Opt-In Form', 'powerkit' ), |
| 50 |
'description' => '', |
| 51 |
'category' => 'canvas', |
| 52 |
'keywords' => array( 'form', 'subscription', 'mailchimp' ), |
| 53 |
'icon' => ' |
| 54 |
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"> |
| 55 |
<path d="M19 15V19H5V15H19ZM20 13H4C3.45 13 3 13.45 3 14V20C3 20.55 3.45 21 4 21H20C20.55 21 21 20.55 21 20V14C21 13.45 20.55 13 20 13ZM7 18.5C6.18 18.5 5.5 17.83 5.5 17C5.5 16.17 6.18 15.5 7 15.5C7.82 15.5 8.5 16.17 8.5 17C8.5 17.83 7.83 18.5 7 18.5ZM19 5V9H5V5H19ZM20 3H4C3.45 3 3 3.45 3 4V10C3 10.55 3.45 11 4 11H20C20.55 11 21 10.55 21 10V4C21 3.45 20.55 3 20 3ZM7 8.5C6.18 8.5 5.5 7.83 5.5 7C5.5 6.17 6.18 5.5 7 5.5C7.82 5.5 8.5 6.18 8.5 7C8.5 7.82 7.83 8.5 7 8.5Z" /> |
| 56 |
</svg> |
| 57 |
', |
| 58 |
'supports' => array( |
| 59 |
'className' => true, |
| 60 |
'anchor' => true, |
| 61 |
'html' => false, |
| 62 |
'canvasSpacings' => true, |
| 63 |
'canvasBorder' => true, |
| 64 |
'canvasResponsive' => true, |
| 65 |
), |
| 66 |
'styles' => array(), |
| 67 |
'location' => array(), |
| 68 |
|
| 69 |
'sections' => array( |
| 70 |
'general' => array( |
| 71 |
'title' => esc_html__( 'Block Settings', 'powerkit' ), |
| 72 |
'priority' => 5, |
| 73 |
'open' => true, |
| 74 |
), |
| 75 |
), |
| 76 |
'layouts' => array(), |
| 77 |
'fields' => array( |
| 78 |
array( |
| 79 |
'key' => 'listId', |
| 80 |
'label' => esc_html__( 'List ID', 'powerkit' ), |
| 81 |
'help' => ' |
| 82 |
<em>' . esc_html__( 'If empty, List ID from Settings → Opt-In Forms will be used.', 'powerkit' ) . '</em> |
| 83 |
<ol> |
| 84 |
<li>' . esc_html__( 'Log in to your', 'powerkit' ) . ' <a href="https://mailchimp.com" target="_blank">' . esc_html__( 'MailChimp account', 'powerkit' ) . '</a></li> |
| 85 |
<li>' . esc_html__( 'Go to your Lists.', 'powerkit' ) . '</li> |
| 86 |
<li>' . esc_html__( 'Select the desired list and in the drop-down menu and go to Settings.', 'powerkit' ) . '</li> |
| 87 |
<li>' . esc_html__( 'Copy your list ID from the field “Unique ID for list …”.', 'powerkit' ) . '</li> |
| 88 |
</ol> |
| 89 |
', |
| 90 |
'section' => 'general', |
| 91 |
'type' => 'text', |
| 92 |
'default' => '', |
| 93 |
), |
| 94 |
array( |
| 95 |
'key' => 'showName', |
| 96 |
'label' => esc_html__( 'Display First Name Field', 'powerkit' ), |
| 97 |
'help' => esc_html__( 'Make sure you map the field in the MailChimp settings', 'powerkit' ), |
| 98 |
'section' => 'general', |
| 99 |
'type' => 'toggle', |
| 100 |
'default' => false, |
| 101 |
), |
| 102 |
|
| 103 |
array( |
| 104 |
'key' => 'colorLegend', |
| 105 |
'label' => esc_html__( 'Color Legend', 'powerkit' ), |
| 106 |
'section' => 'general', |
| 107 |
'type' => 'color', |
| 108 |
'output' => array( |
| 109 |
array( |
| 110 |
'element' => '$ .pk-subscribe-form-wrap .pk-privacy label', |
| 111 |
'property' => 'color', |
| 112 |
), |
| 113 |
), |
| 114 |
), |
| 115 |
), |
| 116 |
'template' => dirname( __FILE__ ) . '/block/render.php', |
| 117 |
|
| 118 |
// enqueue registered scripts/styles. |
| 119 |
'editor_style' => 'powerkit-subscription-block-editor-style', |
| 120 |
); |
| 121 |
|
| 122 |
return $blocks; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
new Powerkit_Subscription_Block(); |
| 127 |
|