diff --git a/includes/plugin-sidebars/class-convertkit-plugin-sidebar-post-settings.php b/includes/plugin-sidebars/class-convertkit-plugin-sidebar-post-settings.php index 9e4d934aa..5f319715b 100644 --- a/includes/plugin-sidebars/class-convertkit-plugin-sidebar-post-settings.php +++ b/includes/plugin-sidebars/class-convertkit-plugin-sidebar-post-settings.php @@ -157,12 +157,16 @@ public function get_fields() { // Get Products. $restrict_content = array( - '0' => esc_html__( 'Don\'t restrict content to member-only', 'convertkit' ), + '0' => esc_html__( 'Do not restrict content to member-only', 'convertkit' ), ); if ( $convertkit_forms->exist() ) { + $restrict_content['forms'] = array( + 'label' => esc_html__( 'Forms', 'convertkit' ), + 'values' => array(), + ); foreach ( $convertkit_forms->get() as $form ) { // Legacy forms don't include a `format` key, so define them as inline. - $restrict_content[ 'form_' . absint( $form['id'] ) ] = sprintf( + $restrict_content['forms']['values'][ 'form_' . absint( $form['id'] ) ] = sprintf( '%s [%s]', sanitize_text_field( $form['name'] ), ( ! empty( $form['format'] ) ? sanitize_text_field( $form['format'] ) : 'inline' ) @@ -170,13 +174,21 @@ public function get_fields() { } } if ( $convertkit_tags->exist() ) { + $restrict_content['tags'] = array( + 'label' => esc_html__( 'Tags', 'convertkit' ), + 'values' => array(), + ); foreach ( $convertkit_tags->get() as $tag ) { - $restrict_content[ 'tag_' . absint( $tag['id'] ) ] = sanitize_text_field( $tag['name'] ); + $restrict_content['tags']['values'][ 'tag_' . absint( $tag['id'] ) ] = sanitize_text_field( $tag['name'] ); } } if ( $convertkit_products->exist() ) { + $restrict_content['products'] = array( + 'label' => esc_html__( 'Products', 'convertkit' ), + 'values' => array(), + ); foreach ( $convertkit_products->get() as $product ) { - $restrict_content[ 'product_' . $product['id'] ] = sanitize_text_field( $product['name'] ); + $restrict_content['products']['values'][ 'product_' . $product['id'] ] = sanitize_text_field( $product['name'] ); } } @@ -196,6 +208,7 @@ public function get_fields() { 'type' => 'select', 'description' => __( 'Select a landing page to make it appear in place of this page.', 'convertkit' ), 'values' => $landing_pages, + 'post_type' => 'page', ), 'tag' => array( 'label' => __( 'Tag', 'convertkit' ), diff --git a/resources/backend/js/gutenberg.js b/resources/backend/js/gutenberg.js index a45df3db2..3b1047548 100644 --- a/resources/backend/js/gutenberg.js +++ b/resources/backend/js/gutenberg.js @@ -936,7 +936,7 @@ function convertKitGutenbergRegisterPluginSidebar(sidebar) { const { registerPlugin } = plugins; const { PluginSidebar } = editor; const { TextControl, SelectControl, PanelBody, PanelRow } = components; - const { useSelect, useDispatch } = data; + const { useSelect, useDispatch, select } = data; /** * Returns a PluginDocumentSettingPanel for this plugin, containing @@ -952,6 +952,7 @@ function convertKitGutenbergRegisterPluginSidebar(sidebar) { }, []); const { editPost: wpEditPost } = useDispatch('core/editor'); const settings = meta[sidebar.meta_key] || sidebar.default_values; + const currentPostType = select('core/editor').getCurrentPostType(); /** * Updates the Post meta meta_key object. @@ -1002,13 +1003,77 @@ function convertKitGutenbergRegisterPluginSidebar(sidebar) { }, }; - const fieldOptions = []; - // Define additional Field Properties and the Field Element, // depending on the Field Type (select, textarea, text etc). switch (field.type) { case 'select': - // Build options for