diff --git a/includes/blocks/class-convertkit-block-broadcasts.php b/includes/blocks/class-convertkit-block-broadcasts.php index 8464a153b..3abb986dd 100644 --- a/includes/blocks/class-convertkit-block-broadcasts.php +++ b/includes/blocks/class-convertkit-block-broadcasts.php @@ -91,6 +91,28 @@ public function get_name() { } + /** + * Returns this block's title. + * + * @since 3.1.1 + */ + public function get_title() { + + return __( 'Kit Broadcasts', 'convertkit' ); + + } + + /** + * Returns this block's icon. + * + * @since 3.1.1 + */ + public function get_icon() { + + return 'resources/backend/images/block-icon-broadcasts.svg'; + + } + /** * Returns this block's Title, Icon, Categories, Keywords and properties. * @@ -103,9 +125,9 @@ public function get_overview() { $settings = new ConvertKit_Settings(); return array( - 'title' => __( 'Kit Broadcasts', 'convertkit' ), + 'title' => $this->get_title(), 'description' => __( 'Displays a list of your Kit broadcasts.', 'convertkit' ), - 'icon' => 'resources/backend/images/block-icon-broadcasts.svg', + 'icon' => $this->get_icon(), 'category' => 'convertkit', 'keywords' => array( __( 'ConvertKit', 'convertkit' ), @@ -272,11 +294,6 @@ public function get_supports() { */ public function get_fields() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - return array( 'display_grid' => array( 'label' => __( 'Display as grid', 'convertkit' ), @@ -380,11 +397,6 @@ public function get_fields() { */ public function get_panels() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - return array( 'general' => array( 'label' => __( 'General', 'convertkit' ), diff --git a/includes/blocks/class-convertkit-block-content.php b/includes/blocks/class-convertkit-block-content.php index 7f16f4b62..45c2bc4f6 100644 --- a/includes/blocks/class-convertkit-block-content.php +++ b/includes/blocks/class-convertkit-block-content.php @@ -44,6 +44,28 @@ public function get_name() { } + /** + * Returns this block's title. + * + * @since 3.1.1 + */ + public function get_title() { + + return __( 'Kit Custom Content', 'convertkit' ); + + } + + /** + * Returns this block's icon. + * + * @since 3.1.1 + */ + public function get_icon() { + + return 'resources/backend/images/block-icon-content.svg'; + + } + /** * Returns this block's Title, Icon, Categories, Keywords and properties. * @@ -54,9 +76,9 @@ public function get_name() { public function get_overview() { return array( - 'title' => __( 'Kit Custom Content', 'convertkit' ), + 'title' => $this->get_title(), 'description' => __( 'Displays Kit Custom Content for a subscriber if their tag matches the Page\'s tag.', 'convertkit' ), - 'icon' => 'resources/backend/images/block-icon-content.svg', + 'icon' => $this->get_icon(), 'category' => 'convertkit', 'keywords' => array( __( 'ConvertKit', 'convertkit' ), @@ -104,11 +126,6 @@ public function get_attributes() { */ public function get_fields() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - // Get ConvertKit Tags. $tags = array(); $convertkit_tags = new ConvertKit_Resource_Tags(); @@ -137,11 +154,6 @@ public function get_fields() { */ public function get_panels() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - return array( 'general' => array( 'label' => __( 'General', 'convertkit' ), diff --git a/includes/blocks/class-convertkit-block-form-builder-field-custom.php b/includes/blocks/class-convertkit-block-form-builder-field-custom.php index 0df3c5472..83e727869 100644 --- a/includes/blocks/class-convertkit-block-form-builder-field-custom.php +++ b/includes/blocks/class-convertkit-block-form-builder-field-custom.php @@ -31,6 +31,28 @@ public function get_name() { } + /** + * Returns this block's title. + * + * @since 3.1.1 + */ + public function get_title() { + + return __( 'Kit Form Builder: Custom Field', 'convertkit' ); + + } + + /** + * Returns this block's icon. + * + * @since 3.1.1 + */ + public function get_icon() { + + return 'resources/backend/images/block-icon-form-builder-field-custom.svg'; + + } + /** * Returns this block's Title, Icon, Categories, Keywords and properties. * @@ -41,9 +63,9 @@ public function get_name() { public function get_overview() { return array( - 'title' => __( 'Kit Form Builder: Custom Field', 'convertkit' ), + 'title' => $this->get_title(), 'description' => __( 'Adds a text field to the Kit Form Builder, whose value is stored in a Kit custom field.', 'convertkit' ), - 'icon' => 'resources/backend/images/block-icon-form-builder-field-custom.svg', + 'icon' => $this->get_icon(), 'category' => 'convertkit', 'keywords' => array( __( 'ConvertKit', 'convertkit' ), @@ -101,11 +123,6 @@ public function get_attributes() { */ public function get_fields() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - // Get Kit Custom Fields. $custom_fields = new ConvertKit_Resource_Custom_Fields( 'block_form_builder' ); $values = array(); @@ -150,11 +167,6 @@ public function get_fields() { */ public function get_panels() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - // Get Panels from parent class. $panels = parent::get_panels(); diff --git a/includes/blocks/class-convertkit-block-form-builder-field-email.php b/includes/blocks/class-convertkit-block-form-builder-field-email.php index 71e02e8a7..5389d463c 100644 --- a/includes/blocks/class-convertkit-block-form-builder-field-email.php +++ b/includes/blocks/class-convertkit-block-form-builder-field-email.php @@ -58,6 +58,28 @@ public function get_name() { } + /** + * Returns this block's title. + * + * @since 3.1.1 + */ + public function get_title() { + + return __( 'Kit Form Builder: Email Field', 'convertkit' ); + + } + + /** + * Returns this block's icon. + * + * @since 3.1.1 + */ + public function get_icon() { + + return 'resources/backend/images/block-icon-form-builder-field-email.svg'; + + } + /** * Returns this block's Title, Icon, Categories, Keywords and properties. * @@ -68,9 +90,9 @@ public function get_name() { public function get_overview() { return array( - 'title' => __( 'Kit Form Builder: Email Field', 'convertkit' ), + 'title' => $this->get_title(), 'description' => __( 'Adds an email field to the Kit Form Builder.', 'convertkit' ), - 'icon' => 'resources/backend/images/block-icon-form-builder-field-email.svg', + 'icon' => $this->get_icon(), 'category' => 'convertkit', 'keywords' => array( __( 'ConvertKit', 'convertkit' ), @@ -120,11 +142,6 @@ public function get_attributes() { */ public function get_fields() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - // The `required` field is not used for this block, // as we always require an email address. $fields = parent::get_fields(); diff --git a/includes/blocks/class-convertkit-block-form-builder-field-name.php b/includes/blocks/class-convertkit-block-form-builder-field-name.php index f75ca1c9b..77b226ee6 100644 --- a/includes/blocks/class-convertkit-block-form-builder-field-name.php +++ b/includes/blocks/class-convertkit-block-form-builder-field-name.php @@ -49,6 +49,28 @@ public function get_name() { } + /** + * Returns this block's title. + * + * @since 3.1.1 + */ + public function get_title() { + + return __( 'Kit Form Builder: Name Field', 'convertkit' ); + + } + + /** + * Returns this block's icon. + * + * @since 3.1.1 + */ + public function get_icon() { + + return 'resources/backend/images/block-icon-form-builder-field-name.svg'; + + } + /** * Returns this block's Title, Icon, Categories, Keywords and properties. * @@ -59,9 +81,9 @@ public function get_name() { public function get_overview() { return array( - 'title' => __( 'Kit Form Builder: Name Field', 'convertkit' ), + 'title' => $this->get_title(), 'description' => __( 'Adds a name field to the Kit Form Builder.', 'convertkit' ), - 'icon' => 'resources/backend/images/block-icon-form-builder-field-name.svg', + 'icon' => $this->get_icon(), 'category' => 'convertkit', 'keywords' => array( __( 'ConvertKit', 'convertkit' ), diff --git a/includes/blocks/class-convertkit-block-form-builder-field.php b/includes/blocks/class-convertkit-block-form-builder-field.php index 295fa480b..96f68c9bb 100644 --- a/includes/blocks/class-convertkit-block-form-builder-field.php +++ b/includes/blocks/class-convertkit-block-form-builder-field.php @@ -110,6 +110,28 @@ public function get_name() { } + /** + * Returns this block's title. + * + * @since 3.1.1 + */ + public function get_title() { + + return __( 'Kit Form Builder: Field', 'convertkit' ); + + } + + /** + * Returns this block's icon. + * + * @since 3.1.1 + */ + public function get_icon() { + + return 'resources/backend/images/block-icon-form-builder-field.svg'; + + } + /** * Returns this block's Attributes * @@ -194,11 +216,6 @@ public function get_supports() { */ public function get_fields() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - return array( 'label' => array( 'label' => __( 'Label', 'convertkit' ), @@ -223,11 +240,6 @@ public function get_fields() { */ public function get_panels() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - return array( 'general' => array( 'label' => __( 'General', 'convertkit' ), diff --git a/includes/blocks/class-convertkit-block-form-builder.php b/includes/blocks/class-convertkit-block-form-builder.php index 4aa8b2a1b..a6d87a620 100644 --- a/includes/blocks/class-convertkit-block-form-builder.php +++ b/includes/blocks/class-convertkit-block-form-builder.php @@ -309,6 +309,28 @@ public function get_name() { } + /** + * Returns this block's title. + * + * @since 3.1.1 + */ + public function get_title() { + + return __( 'Kit Form Builder', 'convertkit' ); + + } + + /** + * Returns this block's icon. + * + * @since 3.1.1 + */ + public function get_icon() { + + return 'resources/backend/images/block-icon-form-builder.svg'; + + } + /** * Returns this block's Title, Icon, Categories, Keywords and properties. * @@ -322,9 +344,9 @@ public function get_overview() { $settings = new ConvertKit_Settings(); return array( - 'title' => __( 'Kit Form Builder', 'convertkit' ), + 'title' => $this->get_title(), 'description' => __( 'Build a subscription form with Kit.', 'convertkit' ), - 'icon' => 'resources/backend/images/block-icon-form-builder.svg', + 'icon' => $this->get_icon(), 'category' => 'convertkit', 'keywords' => array( __( 'ConvertKit', 'convertkit' ), @@ -475,11 +497,6 @@ public function get_supports() { */ public function get_fields() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - // Get Kit Forms. $forms = new ConvertKit_Resource_Forms( 'block_form_builder' ); $forms_options = array(); @@ -568,11 +585,6 @@ public function get_fields() { */ public function get_panels() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - return array( 'general' => array( 'label' => __( 'General', 'convertkit' ), diff --git a/includes/blocks/class-convertkit-block-form-trigger.php b/includes/blocks/class-convertkit-block-form-trigger.php index 5133b916f..423561557 100644 --- a/includes/blocks/class-convertkit-block-form-trigger.php +++ b/includes/blocks/class-convertkit-block-form-trigger.php @@ -62,6 +62,28 @@ public function get_name() { } + /** + * Returns this block's title. + * + * @since 3.1.1 + */ + public function get_title() { + + return __( 'Kit Form Trigger', 'convertkit' ); + + } + + /** + * Returns this block's icon. + * + * @since 3.1.1 + */ + public function get_icon() { + + return 'resources/backend/images/block-icon-formtrigger.svg'; + + } + /** * Returns this block's Title, Icon, Categories, Keywords and properties. * @@ -73,9 +95,9 @@ public function get_overview() { $settings = new ConvertKit_Settings(); return array( - 'title' => __( 'Kit Form Trigger', 'convertkit' ), + 'title' => $this->get_title(), 'description' => __( 'Displays a modal, sticky bar or slide in form to display when the button is pressed.', 'convertkit' ), - 'icon' => 'resources/backend/images/block-icon-formtrigger.svg', + 'icon' => $this->get_icon(), 'category' => 'convertkit', 'keywords' => array( __( 'ConvertKit', 'convertkit' ), @@ -212,11 +234,6 @@ public function get_supports() { */ public function get_fields() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - // Get non-inline ConvertKit Forms. $forms = array(); $convertkit_forms = new ConvertKit_Resource_Forms( 'block_edit' ); @@ -270,11 +287,6 @@ public function get_fields() { */ public function get_panels() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - // Gutenberg's built-in fields (such as styling, padding etc) don't need to be defined here, as they'll be included // automatically by Gutenberg. return array( diff --git a/includes/blocks/class-convertkit-block-form.php b/includes/blocks/class-convertkit-block-form.php index b3e7c1615..4332483e2 100644 --- a/includes/blocks/class-convertkit-block-form.php +++ b/includes/blocks/class-convertkit-block-form.php @@ -90,6 +90,28 @@ public function get_name() { } + /** + * Returns this block's title. + * + * @since 3.1.1 + */ + public function get_title() { + + return __( 'Kit Form', 'convertkit' ); + + } + + /** + * Returns this block's icon. + * + * @since 3.1.1 + */ + public function get_icon() { + + return 'resources/backend/images/block-icon-form.svg'; + + } + /** * Returns this block's Title, Icon, Categories, Keywords and properties. * @@ -103,9 +125,9 @@ public function get_overview() { $settings = new ConvertKit_Settings(); return array( - 'title' => __( 'Kit Form', 'convertkit' ), + 'title' => $this->get_title(), 'description' => __( 'Displays a Kit Form.', 'convertkit' ), - 'icon' => 'resources/backend/images/block-icon-form.svg', + 'icon' => $this->get_icon(), 'category' => 'convertkit', 'keywords' => array( __( 'ConvertKit', 'convertkit' ), @@ -240,11 +262,6 @@ public function get_supports() { */ public function get_fields() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - // Get ConvertKit Forms. $forms = array(); $convertkit_forms = new ConvertKit_Resource_Forms( 'block_edit' ); @@ -285,11 +302,6 @@ public function get_fields() { */ public function get_panels() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - return array( 'general' => array( 'label' => __( 'General', 'convertkit' ), diff --git a/includes/blocks/class-convertkit-block-product.php b/includes/blocks/class-convertkit-block-product.php index ba847ab6d..1a4cbce91 100644 --- a/includes/blocks/class-convertkit-block-product.php +++ b/includes/blocks/class-convertkit-block-product.php @@ -84,6 +84,28 @@ public function get_name() { } + /** + * Returns this block's title. + * + * @since 3.1.1 + */ + public function get_title() { + + return __( 'Kit Product', 'convertkit' ); + + } + + /** + * Returns this block's icon. + * + * @since 3.1.1 + */ + public function get_icon() { + + return 'resources/backend/images/block-icon-product.svg'; + + } + /** * Returns this block's Title, Icon, Categories, Keywords and properties. * @@ -95,9 +117,9 @@ public function get_overview() { $settings = new ConvertKit_Settings(); return array( - 'title' => __( 'Kit Product', 'convertkit' ), + 'title' => $this->get_title(), 'description' => __( 'Displays a button to purchase a Kit product.', 'convertkit' ), - 'icon' => 'resources/backend/images/block-icon-product.svg', + 'icon' => $this->get_icon(), 'category' => 'convertkit', 'keywords' => array( __( 'ConvertKit', 'convertkit' ), @@ -245,11 +267,6 @@ public function get_supports() { */ public function get_fields() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - // Get ConvertKit Products. $products = array(); $convertkit_products = new ConvertKit_Resource_Products(); @@ -312,11 +329,6 @@ public function get_fields() { */ public function get_panels() { - // Bail if the request is not for the WordPress Administration, frontend editor or REST API request. - if ( ! $this->is_admin_frontend_editor_or_rest_request() ) { - return false; - } - // Gutenberg's built-in fields (such as styling, padding etc) don't need to be defined here, as they'll be included // automatically by Gutenberg. return array( diff --git a/includes/blocks/class-convertkit-block.php b/includes/blocks/class-convertkit-block.php index 1b75ba135..12a82447e 100644 --- a/includes/blocks/class-convertkit-block.php +++ b/includes/blocks/class-convertkit-block.php @@ -24,6 +24,21 @@ class ConvertKit_Block { */ public function register( $blocks ) { + // If the request is for the frontend, return the minimum block definition required + // to register and render the block on the frontend site using register_block_type(). + if ( ! $this->is_admin_frontend_editor_or_admin_rest_request() ) { + $blocks[ $this->get_name() ] = array( + 'title' => $this->get_title(), + 'icon' => $this->get_icon(), + 'attributes' => $this->get_attributes(), + 'render_callback' => array( $this, 'render' ), + ); + + return $blocks; + } + + // Request is for the WordPress Administration, frontend editor or REST API request. + // Register the full block definition, including fields, panels, default values and supports. $blocks[ $this->get_name() ] = array_merge( $this->get_overview(), array( @@ -57,6 +72,28 @@ public function get_name() { } + /** + * Returns this block's title. + * + * @since 3.1.1 + */ + public function get_title() { + + return ''; + + } + + /** + * Returns this block's icon. + * + * @since 3.1.1 + */ + public function get_icon() { + + return ''; + + } + /** * Returns this block's Title, Icon, Categories, Keywords and properties. * @@ -396,15 +433,16 @@ public function get_atts_as_html_data_attributes( $atts ) { } /** - * Determines if the request is a WordPress REST API request. + * Determines if the request is a WordPress REST API request + * made by a logged in WordPress user who has the capability to edit posts. * * @since 3.1.0 * * @return bool */ - public function is_rest_request() { + public function is_admin_rest_request() { - return defined( 'REST_REQUEST' ) && REST_REQUEST; + return defined( 'REST_REQUEST' ) && REST_REQUEST && current_user_can( 'edit_posts' ); } @@ -415,9 +453,9 @@ public function is_rest_request() { * * @return bool */ - public function is_admin_frontend_editor_or_rest_request() { + public function is_admin_frontend_editor_or_admin_rest_request() { - return WP_ConvertKit()->is_admin_or_frontend_editor() || $this->is_rest_request(); + return WP_ConvertKit()->is_admin_or_frontend_editor() || $this->is_admin_rest_request(); } @@ -431,7 +469,7 @@ public function is_admin_frontend_editor_or_rest_request() { public function is_block_editor_request() { // Return false if not a WordPress REST API request, which Gutenberg uses. - if ( ! $this->is_rest_request() ) { + if ( ! $this->is_admin_rest_request() ) { return false; } diff --git a/includes/integrations/divi/class-convertkit-divi-module.php b/includes/integrations/divi/class-convertkit-divi-module.php index 6cf76a564..ef4c5c95f 100644 --- a/includes/integrations/divi/class-convertkit-divi-module.php +++ b/includes/integrations/divi/class-convertkit-divi-module.php @@ -98,7 +98,10 @@ public function get_fields() { return array(); } - // Bail if no fields. + // Bail if no fields i.e. this is a frontend request. + if ( ! array_key_exists( 'fields', $this->block ) ) { + return array(); + } if ( ! is_array( $this->block['fields'] ) ) { return array(); }