From 0aef82b1a3d1101495e41a7484dcd0723f9dade0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 May 2022 06:11:57 +0000 Subject: [PATCH 1/7] chore(deps-dev): bump postcss from 8.4.13 to 8.4.14 Bumps [postcss](https://github.com/postcss/postcss) from 8.4.13 to 8.4.14. - [Release notes](https://github.com/postcss/postcss/releases) - [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md) - [Commits](https://github.com/postcss/postcss/compare/8.4.13...8.4.14) --- updated-dependencies: - dependency-name: postcss dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 30 +++++++++++++++--------------- package.json | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 53518c93..55d1a96a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "eslint": "^7.32.0", "lint-staged": "^12.4.1", "newspack-scripts": "^3.3.0", - "postcss": "^8.4.13", + "postcss": "^8.4.14", "prettier": "npm:wp-prettier@^2.2.1-beta-1", "stylelint": "^13.13.1" } @@ -18017,9 +18017,9 @@ "optional": true }, "node_modules/nanoid": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.3.tgz", - "integrity": "sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==", + "version": "3.3.4", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", + "integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==", "dev": true, "bin": { "nanoid": "bin/nanoid.cjs" @@ -23237,9 +23237,9 @@ } }, "node_modules/postcss": { - "version": "8.4.13", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.13.tgz", - "integrity": "sha512-jtL6eTBrza5MPzy8oJLFuUscHDXTV5KcLlqAWHl5q5WYRfnNRGSmOZmOZ1T6Gy7A99mOZfqungmZMpMmCVJ8ZA==", + "version": "8.4.14", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.14.tgz", + "integrity": "sha512-E398TUmfAYFPBSdzgeieK2Y1+1cpdxJx8yXbK/m57nRhKSmk1GB2tO4lbLBtlkfPQTDKfe4Xqv1ASWPpayPEig==", "dev": true, "funding": [ { @@ -23252,7 +23252,7 @@ } ], "dependencies": { - "nanoid": "^3.3.3", + "nanoid": "^3.3.4", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" }, @@ -44792,9 +44792,9 @@ "optional": true }, "nanoid": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.3.tgz", - "integrity": "sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==", + "version": "3.3.4", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", + "integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==", "dev": true }, "nanomatch": { @@ -48571,12 +48571,12 @@ "dev": true }, "postcss": { - "version": "8.4.13", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.13.tgz", - "integrity": "sha512-jtL6eTBrza5MPzy8oJLFuUscHDXTV5KcLlqAWHl5q5WYRfnNRGSmOZmOZ1T6Gy7A99mOZfqungmZMpMmCVJ8ZA==", + "version": "8.4.14", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.14.tgz", + "integrity": "sha512-E398TUmfAYFPBSdzgeieK2Y1+1cpdxJx8yXbK/m57nRhKSmk1GB2tO4lbLBtlkfPQTDKfe4Xqv1ASWPpayPEig==", "dev": true, "requires": { - "nanoid": "^3.3.3", + "nanoid": "^3.3.4", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" } diff --git a/package.json b/package.json index d944b142..7e465fd8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "eslint": "^7.32.0", "lint-staged": "^12.4.1", "newspack-scripts": "^3.3.0", - "postcss": "^8.4.13", + "postcss": "^8.4.14", "prettier": "npm:wp-prettier@^2.2.1-beta-1", "stylelint": "^13.13.1" } From 0dac9fb482b577de74e886900a7cf85eed2bd571 Mon Sep 17 00:00:00 2001 From: Derrick Koo Date: Wed, 25 May 2022 10:33:18 -0600 Subject: [PATCH 2/7] feat: enable jetpack share buttons on listings (#257) --- includes/class-core.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/includes/class-core.php b/includes/class-core.php index d5bddd50..9372a0c6 100644 --- a/includes/class-core.php +++ b/includes/class-core.php @@ -82,6 +82,8 @@ public function __construct() { add_filter( 'newspack_sponsors_post_types', [ __CLASS__, 'support_newspack_sponsors' ] ); add_filter( 'jetpack_relatedposts_filter_options', [ __CLASS__, 'disable_jetpack_related_posts' ] ); add_filter( 'jetpack_related_posts_customize_options', [ __CLASS__, 'disable_jetpack_related_posts_customizer' ] ); + add_filter( 'sharing_enqueue_scripts', [ __CLASS__, 'enable_jetpack_social_share_buttons' ] ); + add_filter( 'sharing_show', [ __CLASS__, 'enable_jetpack_social_share_buttons' ] ); add_filter( 'wpseo_primary_term_taxonomies', [ __CLASS__, 'disable_yoast_primary_categories' ], 10, 2 ); add_action( 'pre_get_posts', [ __CLASS__, 'enable_listing_category_archives' ], 11 ); register_activation_hook( NEWSPACK_LISTINGS_FILE, [ __CLASS__, 'activation_hook' ] ); @@ -809,6 +811,21 @@ public static function disable_jetpack_related_posts_customizer( $options ) { return $options; } + /** + * If social share buttons are enabled in Jetpack, allow them to appear on listings. + * + * @param bool $show True if the sharing buttons should be displayed. + * + * @return bool The filtered value. + */ + public static function enable_jetpack_social_share_buttons( $show ) { + if ( is_singular( array_values( self::NEWSPACK_LISTINGS_POST_TYPES ) ) ) { + return true; + } + + return $show; + } + /** * Disable the Yoast primary category picker for Listing CPTs. * From 25f4be8dd216b00ee73cc952dd2e9f93728def03 Mon Sep 17 00:00:00 2001 From: Derrick Koo Date: Wed, 25 May 2022 11:16:09 -0600 Subject: [PATCH 3/7] feat: remove related listings functionality (#256) * feat: remove shadow taxonomies features * feat: remove parent/child listing API routes * feat: remove shadow taxonomies settings * refactor: remove Taxonomies class * refactor: remove shadow taxonomy handling in migration scripts * refactor: remove Taxonomies from api class * fix: remove Related Listings settings section --- includes/class-api.php | 168 ----- includes/class-blocks.php | 13 - includes/class-settings.php | 20 - includes/class-taxonomies.php | 636 ------------------ includes/migration/class-migration.php | 175 ----- newspack-listings.php | 1 - src/editor/index.js | 10 - .../shadow-taxonomies/child-listings.js | 291 -------- src/editor/shadow-taxonomies/index.js | 20 - .../shadow-taxonomies/parent-listings.js | 367 ---------- src/editor/shadow-taxonomies/style.scss | 72 -- src/editor/utils.js | 115 ---- 12 files changed, 1888 deletions(-) delete mode 100644 includes/class-taxonomies.php delete mode 100644 src/editor/shadow-taxonomies/child-listings.js delete mode 100644 src/editor/shadow-taxonomies/index.js delete mode 100644 src/editor/shadow-taxonomies/parent-listings.js delete mode 100644 src/editor/shadow-taxonomies/style.scss diff --git a/includes/class-api.php b/includes/class-api.php index 547c22fa..323412bf 100644 --- a/includes/class-api.php +++ b/includes/class-api.php @@ -12,7 +12,6 @@ use \Newspack_Listings\Core; use \Newspack_Listings\Blocks; use \Newspack_Listings\Featured; -use \Newspack_Listings\Taxonomies; use \Newspack_Listings\Utils; defined( 'ABSPATH' ) || exit; @@ -117,85 +116,6 @@ public static function register_routes() { ] ); - // GET listings parent terms. - register_rest_route( - 'newspack-listings/v1', - 'parents', - [ - [ - 'methods' => \WP_REST_Server::READABLE, - 'callback' => [ __CLASS__, 'get_parents' ], - 'permission_callback' => '__return_true', - ], - ] - ); - - // GET listings child posts. - register_rest_route( - self::$namespace, - 'children', - [ - [ - 'methods' => \WP_REST_Server::READABLE, - 'callback' => [ __CLASS__, 'get_children' ], - 'permission_callback' => '__return_true', - 'args' => [ - 'post_id' => [ - 'sanitize_callback' => 'absint', - ], - ], - ], - ] - ); - - // Set listings parent posts. - register_rest_route( - 'newspack-listings/v1', - 'parents', - [ - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ __CLASS__, 'set_parents' ], - 'permission_callback' => [ __CLASS__, 'api_permissions_check' ], - 'args' => [ - 'post_id' => [ - 'sanitize_callback' => 'absint', - ], - 'added' => [ - 'sanitize_callback' => [ __CLASS__, 'sanitize_array' ], - ], - 'removed' => [ - 'sanitize_callback' => [ __CLASS__, 'sanitize_array' ], - ], - ], - ], - ] - ); - - // Set listings child posts. - register_rest_route( - self::$namespace, - 'children', - [ - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ __CLASS__, 'set_children' ], - 'permission_callback' => [ __CLASS__, 'api_permissions_check' ], - 'args' => [ - 'post_id' => [ - 'sanitize_callback' => 'absint', - ], - 'added' => [ - 'sanitize_callback' => [ __CLASS__, 'sanitize_array' ], - ], - 'removed' => [ - 'sanitize_callback' => [ __CLASS__, 'sanitize_array' ], - ], - ], - ], - ] - ); - // Get and set listing priority level. if ( Featured::is_active() ) { register_rest_route( @@ -548,94 +468,6 @@ function( $term ) { return new \WP_REST_Response( [] ); } - /** - * Look up parent terms by post ID. - * - * @param WP_REST_Request $request Request object. - * @return WP_REST_Response. - */ - public static function get_parents( $request ) { - $params = $request->get_params(); - $parents = Taxonomies::get_parent_terms( $params ); - - if ( is_array( $parents ) ) { - return rest_ensure_response( - array_values( - array_map( - function( $term ) { - return [ - 'value' => $term->term_id, - 'label' => $term->name, - 'post_type' => $term->taxonomy, - ]; - }, - $parents - ) - ), - 200 - ); - } - - return rest_ensure_response( [] ); - } - - /** - * Look up child posts by post ID. - * - * @param WP_REST_Request $request Request object. - * @return WP_REST_Response. - */ - public static function get_children( $request ) { - $params = $request->get_params(); - $children = Taxonomies::get_child_posts( $params ); - - if ( is_array( $children ) ) { - return rest_ensure_response( - array_values( - array_map( - function( $post ) { - return [ - 'value' => $post->ID, - 'label' => $post->post_title, - 'post_type' => $post->post_type, - ]; - }, - $children - ) - ), - 200 - ); - } - - return rest_ensure_response( [] ); - } - - /** - * Apply shadow term for the parent post to the given post_id, - * and/or remove the shadow term from the given children to remove. - * - * @param WP_REST_Request $request Request object. - * @return WP_REST_Response. - */ - public static function set_parents( $request ) { - $params = $request->get_params(); - $response = Taxonomies::set_parent_posts( $params ); - return new \WP_REST_Response( $response ); - } - - /** - * Apply shadow term for the parent post to the given children, - * and/or remove the shadow term from the given children to remove. - * - * @param WP_REST_Request $request Request object. - * @return WP_REST_Response. - */ - public static function set_children( $request ) { - $params = $request->get_params(); - $response = Taxonomies::set_child_posts( $params ); - return new \WP_REST_Response( $response ); - } - /** * Get featured priority by post ID. * diff --git a/includes/class-blocks.php b/includes/class-blocks.php index bf220003..69e2ca47 100644 --- a/includes/class-blocks.php +++ b/includes/class-blocks.php @@ -12,7 +12,6 @@ use \Newspack_Listings\Core; use \Newspack_Listings\Products; use \Newspack_Listings\Settings; -use \Newspack_Listings\Taxonomies; defined( 'ABSPATH' ) || exit; @@ -67,7 +66,6 @@ public static function manage_editor_assets() { $post_type = get_post_type(); $post_types = []; $post_type_label = ! empty( $post_type ) ? get_post_type_object( $post_type )->labels->singular_name : 'Post'; - $taxonomies = []; foreach ( Core::NEWSPACK_LISTINGS_POST_TYPES as $slug => $name ) { $post_count = wp_count_posts( $name )->publish; @@ -79,22 +77,11 @@ public static function manage_editor_assets() { ]; } - $shadow_taxonomy_config = Taxonomies::get_shadow_taxonomy_config(); - - foreach ( Taxonomies::NEWSPACK_LISTINGS_TAXONOMIES as $slug => $name ) { - $taxonomies[ $slug ] = [ - 'name' => $name, - 'label' => get_post_type_object( Core::NEWSPACK_LISTINGS_POST_TYPES[ $slug ] )->labels->singular_name, - 'post_types' => $shadow_taxonomy_config[ $slug ]['post_types'], - ]; - } - $localized_data = [ 'post_type_label' => $post_type_label, 'post_type' => $post_type, 'post_type_slug' => array_search( $post_type, Core::NEWSPACK_LISTINGS_POST_TYPES ), 'post_types' => $post_types, - 'taxonomies' => $taxonomies, 'currency' => function_exists( 'get_woocommerce_currency' ) ? get_woocommerce_currency() : __( 'USD', 'newspack-listings' ), 'currencies' => function_exists( 'get_woocommerce_currencies' ) ? get_woocommerce_currencies() : [ 'USD' => __( 'United States (US) dollar', 'newspack-listings' ) ], diff --git a/includes/class-settings.php b/includes/class-settings.php index ef171248..48c71eaf 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -40,10 +40,6 @@ public static function get_sections() { 'slug' => 'newspack_listings_meta_settings', 'title' => __( 'Post Meta Settings', 'newspack-listings' ), ], - 'related' => [ - 'slug' => 'newspack_listings_related_settings', - 'title' => __( 'Related Content Settings', 'newspack-listings' ), - ], ]; // Product settings are only relevant if WooCommerce is available. @@ -154,22 +150,6 @@ public static function get_default_settings() { 'value' => false, 'section' => $sections['meta']['slug'], ], - [ - 'description' => __( 'This setting can be overridden per listing, post, or page.', 'newspack-listings' ), - 'key' => 'newspack_listings_hide_parents', - 'label' => __( 'Hide parent listings by default', 'newpack-listings' ), - 'type' => 'checkbox', - 'value' => false, - 'section' => $sections['related']['slug'], - ], - [ - 'description' => __( 'This setting can be overridden per listing, post, or page.', 'newspack-listings' ), - 'key' => 'newspack_listings_hide_children', - 'label' => __( 'Hide child listings by default', 'newpack-listings' ), - 'type' => 'checkbox', - 'value' => false, - 'section' => $sections['related']['slug'], - ], ]; // If Related Posts is on, show the setting to hide it. diff --git a/includes/class-taxonomies.php b/includes/class-taxonomies.php deleted file mode 100644 index b47458ad..00000000 --- a/includes/class-taxonomies.php +++ /dev/null @@ -1,636 +0,0 @@ - 'newspack_lstngs_evt', - 'generic' => 'newspack_lstngs_gen', - 'marketplace' => 'newspack_lstngs_mkt', - 'place' => 'newspack_lstngs_plc', - ]; - - /** - * The single instance of the class. - * - * @var Taxonomies - */ - protected static $instance = null; - - /** - * Main Taxonomies instance. - * Ensures only one instance of Taxonomies is loaded or can be loaded. - * - * @return Taxonomies - Main instance. - */ - public static function instance() { - if ( is_null( self::$instance ) ) { - self::$instance = new self(); - } - return self::$instance; - } - - /** - * Constructor. - */ - public function __construct() { - add_action( 'init', [ __CLASS__, 'init' ] ); - add_filter( 'rest_prepare_taxonomy', [ __CLASS__, 'hide_taxonomy_sidebar' ], 10, 2 ); - register_activation_hook( NEWSPACK_LISTINGS_FILE, [ __CLASS__, 'activation_hook' ] ); - } - - /** - * After WP init. - */ - public static function init() { - self::register_tax(); - self::create_shadow_relationship(); - } - - /** - * Get shadow taxonomy config object. - * - * @return object Config options for all shadow taxonomies. - */ - public static function get_shadow_taxonomy_config() { - $default_config = [ - 'hierarchical' => true, - 'public' => true, - 'show_in_menu' => false, // Set to 'true' to show in WP admin for debugging purposes. - 'show_in_quick_edit' => false, - 'show_in_rest' => true, - 'show_tagcloud' => false, - 'show_ui' => true, - ]; - - return [ - 'event' => [ - 'post_types' => [ - 'post', - 'page', - Core::NEWSPACK_LISTINGS_POST_TYPES['event'], - Core::NEWSPACK_LISTINGS_POST_TYPES['generic'], - ], - 'config' => wp_parse_args( - [ - 'rewrite' => [ 'slug' => self::NEWSPACK_LISTINGS_TAXONOMIES['event'] ], - 'labels' => get_post_type_object( Core::NEWSPACK_LISTINGS_POST_TYPES['event'] )->labels, - ], - $default_config - ), - ], - 'generic' => [ - 'post_types' => [ - 'post', - 'page', - Core::NEWSPACK_LISTINGS_POST_TYPES['generic'], - ], - 'config' => wp_parse_args( - [ - 'rewrite' => [ 'slug' => self::NEWSPACK_LISTINGS_TAXONOMIES['generic'] ], - 'labels' => get_post_type_object( Core::NEWSPACK_LISTINGS_POST_TYPES['generic'] )->labels, - ], - $default_config - ), - ], - 'marketplace' => [ - 'post_types' => [ - 'post', - 'page', - Core::NEWSPACK_LISTINGS_POST_TYPES['generic'], - Core::NEWSPACK_LISTINGS_POST_TYPES['marketplace'], - ], - 'config' => wp_parse_args( - [ - 'rewrite' => [ 'slug' => self::NEWSPACK_LISTINGS_TAXONOMIES['marketplace'] ], - 'labels' => get_post_type_object( Core::NEWSPACK_LISTINGS_POST_TYPES['marketplace'] )->labels, - ], - $default_config - ), - ], - 'place' => [ - 'post_types' => [ - 'post', - 'page', - Core::NEWSPACK_LISTINGS_POST_TYPES['event'], - Core::NEWSPACK_LISTINGS_POST_TYPES['generic'], - Core::NEWSPACK_LISTINGS_POST_TYPES['marketplace'], - Core::NEWSPACK_LISTINGS_POST_TYPES['place'], - ], - 'config' => wp_parse_args( - [ - 'rewrite' => [ 'slug' => self::NEWSPACK_LISTINGS_TAXONOMIES['place'] ], - 'labels' => get_post_type_object( Core::NEWSPACK_LISTINGS_POST_TYPES['place'] )->labels, - ], - $default_config - ), - ], - ]; - } - - /** - * Registers shadow taxonomies which can be applied to other listing CPTs, pages, or posts. - * Terms in these taxonomies are not created or edited directly, but are linked to Listing CPT posts. - */ - public static function register_tax() { - $shadow_taxonomies = self::get_shadow_taxonomy_config(); - - // Register shadow taxonomies for each source post type. - foreach ( $shadow_taxonomies as $post_type_to_shadow => $shadow_taxonomy ) { - $taxonomy_slug = self::NEWSPACK_LISTINGS_TAXONOMIES[ $post_type_to_shadow ]; - register_taxonomy( - $taxonomy_slug, - $shadow_taxonomy['post_types'], - $shadow_taxonomy['config'] - ); - } - } - - /** - * Using the array of shadow taxonomies, get an array of corresponding post types being shadowed. - * - * @return array Array of post types being shadowed. - */ - public static function get_post_types_to_shadow() { - return array_values( - array_intersect_key( - Core::NEWSPACK_LISTINGS_POST_TYPES, - self::NEWSPACK_LISTINGS_TAXONOMIES - ) - ); - } - - /** - * Given a shadow taxonomy, get the name of the post type the taxonomy shadows. - * - * @param string $taxonomy Taxonomy slug. - * @return string}boolean The post type the taxonomy shadows, or false if none. - */ - public static function get_post_type_by_taxonomy( $taxonomy ) { - $post_type = false; - $taxonomy_slugs = array_keys( self::NEWSPACK_LISTINGS_TAXONOMIES, $taxonomy ); - $taxonomy_slug = reset( $taxonomy_slugs ); - - if ( ! empty( $taxonomy_slug ) && ! empty( Core::NEWSPACK_LISTINGS_POST_TYPES[ $taxonomy_slug ] ) ) { - $post_type = Core::NEWSPACK_LISTINGS_POST_TYPES[ $taxonomy_slug ]; - } - - return $post_type; - } - - /** - * Given a post type, get the name of the shadow taxonomy for that post type. - * - * @param string $post_type Post type. - * @return string}boolean The shadow taxonomy for the given post type, or false if none. - */ - public static function get_taxonomy_by_post_type( $post_type ) { - $shadow_taxonomy = false; - $post_type_slugs = array_keys( Core::NEWSPACK_LISTINGS_POST_TYPES, $post_type ); - $post_type_slug = reset( $post_type_slugs ); - - if ( ! empty( $post_type_slug ) && ! empty( self::NEWSPACK_LISTINGS_TAXONOMIES[ $post_type_slug ] ) ) { - $shadow_taxonomy = self::NEWSPACK_LISTINGS_TAXONOMIES[ $post_type_slug ]; - } - - return $shadow_taxonomy; - } - - /** - * Create shadow relationships between taxonomies and their posts. - */ - public static function create_shadow_relationship() { - add_action( 'wp_insert_post', [ __CLASS__, 'update_or_delete_shadow_term' ], 10, 2 ); - add_action( 'before_delete_post', [ __CLASS__, 'delete_shadow_term' ] ); - } - - /** - * When a listing post type changes status, add/update its shadow term if the status is `publish`, otherwise delete it. - * - * @param int $post_id ID for the post being inserted or saved. - * @param array $post Post object for the post being inserted or saved. - * @return void - */ - public static function update_or_delete_shadow_term( $post_id, $post ) { - // Get the taxonomy to update or delete. - $shadow_taxonomy = self::get_taxonomy_by_post_type( $post->post_type ); - - // Bail if not a shadowable post. - if ( ! $shadow_taxonomy ) { - return; - } - - // If the post is a valid post, update or create the shadow term. Otherwise, delete it. - if ( self::should_update_shadow_term( $post ) ) { - self::update_shadow_term( $post, $shadow_taxonomy ); - } else { - self::delete_shadow_term( $post, $shadow_taxonomy ); - } - } - - /** - * Check whether a given post object should have a shadow term. - * - * @param object $post Post object to check. - * @return bool True if the post should have a shadow term, otherwise false. - */ - public static function should_update_shadow_term( $post ) { - $should_update_shadow_term = true; - - // If post isn't published. - if ( 'publish' !== $post->post_status ) { - $should_update_shadow_term = false; - } - - // If post lacks a valid title. - if ( ! $post->post_title || 'Auto Draft' === $post->post_title ) { - $should_update_shadow_term = false; - } - - // If post lacks a valid slug. - if ( ! $post->post_name ) { - $should_update_shadow_term = false; - } - - // If post type isn't a shadowable type. - if ( ! in_array( $post->post_type, self::get_post_types_to_shadow() ) ) { - $should_update_shadow_term = false; - } - - return $should_update_shadow_term; - } - - /** - * Creates a new taxonomy term, or updates an existing one. - * - * @param array $post Post object for the post being inserted or saved. - * @param string|null $taxonomy Name of taxonomy to create or update. - * @return bool|void Nothing if successful, or false if not. - */ - public static function update_shadow_term( $post, $taxonomy = null ) { - // Bail if post or taxonomy isn't valid. - if ( ! self::should_update_shadow_term( $post ) || empty( $taxonomy ) ) { - return false; - } - - // Check for a shadow term associated with this post. - $shadow_term = self::get_shadow_term( $post, $taxonomy ); - - // If there isn't already a shadow term, create it. - if ( empty( $shadow_term ) ) { - self::create_shadow_term( $post, $taxonomy ); - } else { - // Otherwise, update the existing term. - wp_update_term( - $shadow_term->term_id, - $taxonomy, - [ - 'name' => $post->post_title, - 'slug' => $post->post_name, - ] - ); - } - } - - /** - * Deletes an existing shadow taxonomy term when the post is being deleted. - * - * @param array $post Post object for the post being deleted. - * @param string $taxonomy Name of taxonomy to delete. - * @return bool|void Nothing if successful, or false if not. - */ - public static function delete_shadow_term( $post, $taxonomy = null ) { - // Bail if no taxonomy passed. - if ( empty( $taxonomy ) ) { - return false; - } - - // Check for a shadow term associated with this post. - $shadow_term = self::get_shadow_term( $post, $taxonomy ); - - if ( empty( $shadow_term ) ) { - return false; - } - - wp_delete_term( $shadow_term->term_id, $taxonomy ); - } - - /** - * Looks up a shadow taxonomy term linked to a given post. - * - * @param array $post Post object to look up. - * @param string $taxonomy Name of taxonomy to get. - * @return array|bool Term object of the linked term, if any, or false. - */ - public static function get_shadow_term( $post, $taxonomy = null ) { - if ( empty( $post ) || empty( $post->post_title ) || empty( $taxonomy ) ) { - return false; - } - - // Try finding the shadow term by slug first. - $shadow_term = get_term_by( 'slug', $post->post_name, $taxonomy ); - - // If we can't find a term by slug, the post slug may have been updated. Try finding by title instead. - if ( empty( $shadow_term ) ) { - $shadow_term = get_term_by( 'name', $post->post_title, $taxonomy ); - } - - // If we can't find a term by either slug or title, it probably doesn't exist. - if ( empty( $shadow_term ) ) { - return false; - } - - return $shadow_term; - } - - /** - * Creates a shadow taxonomy term linked to the given post. - * - * @param array $post Post object for which to create a shadow term. - * @param string $taxonomy Name of taxonomy to create. - * @return array|bool Term object if successful, false if not. - */ - public static function create_shadow_term( $post, $taxonomy = null ) { - // Bail if no taxonomy passed. - if ( empty( $taxonomy ) ) { - return false; - } - - $new_term = wp_insert_term( - $post->post_title, - $taxonomy, - [ - 'slug' => $post->post_name, - ] - ); - - if ( is_wp_error( $new_term ) ) { - return false; - } - - $post_id = $post->ID; - $new_term_id = $new_term['term_id']; - - // Apply the term to the parent post. This lets us check for missing terms. - wp_set_post_terms( $post_id, $new_term_id, $taxonomy, true ); - - return $new_term; - } - - /** - * Workaround to hide the default taxonomy sidebars, since we're registering our own UI for managing shadow terms. - * The taxonomies must be available via REST from our custom UI, but hidden to Gutenberg's default taxonomy UI. - * This workaround is necessary until the parent issue is resolved and merged to WP Core: - * https://github.com/WordPress/gutenberg/issues/6912#issuecomment-428403380 - * - * @param WP_REST_Response $response The response object. - * @param WP_Taxonomy $taxonomy The taxonomy object. - * - * @return WP_REST_Response The filtered response object. - */ - public static function hide_taxonomy_sidebar( $response, $taxonomy ) { - if ( in_array( $taxonomy->name, array_values( self::NEWSPACK_LISTINGS_TAXONOMIES ) ) ) { - $response->data['visibility']['show_ui'] = false; - } - return $response; - } - - /** - * Get parent listing posts for the given shadow taxonomy terms by term slug. - * Parent listings are listings that are assigned to a post, page, or other listing - * via their corresponding shadow term. - * - * @param array $slugs Array of term slug to use for looking up post. - * @return array Array of parent listing posts. - */ - public static function get_parent_listings( $slugs ) { - $parent_listings = new \WP_Query( - [ - 'post_type' => self::get_post_types_to_shadow(), - 'posts_per_page' => 100, - 'post_status' => 'publish', - 'post_name__in' => $slugs, - 'no_found_rows' => true, - 'fields' => 'ids', - 'order' => 'ASC', - 'orderby' => 'type title', - ] - ); - - if ( empty( $parent_listings->posts ) || is_wp_error( $parent_listings ) ) { - return []; - } - - return $parent_listings->posts; - } - - /** - * Get parent terms for the given post ID. - * Parents are the listing shadow terms that have been assigned to a post, page, or other listing. - * - * @param object $params Array of WP_Query args, including at least the post ID of the parent post. - * @return array Array of parent terms for the given post ID. - */ - public static function get_parent_terms( $params ) { - $post_id = $params['post_id']; - $per_page = ! empty( $params['per_page'] ) ? $params['per_page'] : 10; - $taxonomy = ! empty( $params['taxonomy'] ) ? $params['taxonomy'] : array_values( self::NEWSPACK_LISTINGS_TAXONOMIES ); - $parent_terms = wp_get_post_terms( $post_id, $taxonomy ); - $parent_terms = array_filter( - $parent_terms, - function( $parent_term ) use ( $post_id ) { - // Don't show the post on itself. - return get_post_field( 'post_name', get_post( $post_id ) ) !== $parent_term->slug; - } - ); - - return $parent_terms; - } - - /** - * Get child listings, posts, and pages for the given post ID. - * Children are the posts, pages, and other listings that have been assigned a listing shadow term. - * - * @param object $params Array of WP_Query args, including at least the post ID of the parent post. - * @return array Array of child posts that have the parent's shadow term assigned. - */ - public static function get_child_posts( $params ) { - $post_id = $params['post_id']; - $per_page = ! empty( $params['per_page'] ) ? $params['per_page'] : 10; - $post = get_post( $post_id ); - $shadow_taxonomy = self::get_taxonomy_by_post_type( $post->post_type ); - $shadow_term = self::get_shadow_term( $post, $shadow_taxonomy ); - $post_type = ! empty( $params['post_type'] ) ? $params['post_type'] : [ - 'post', - 'page', - Core::NEWSPACK_LISTINGS_POST_TYPES['event'], - Core::NEWSPACK_LISTINGS_POST_TYPES['generic'], - Core::NEWSPACK_LISTINGS_POST_TYPES['marketplace'], - Core::NEWSPACK_LISTINGS_POST_TYPES['place'], - ]; - - // If no shadow term. - if ( ! $shadow_term ) { - return []; - } - - $child_posts = new \WP_Query( - [ - 'post_type' => $post_type, - 'posts_per_page' => $per_page, - 'post_status' => [ 'publish', 'draft', 'pending', 'future' ], // Can still set parent listings on draft posts. - 'no_found_rows' => true, - 'tax_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query - [ - 'taxonomy' => $shadow_taxonomy, - 'terms' => $shadow_term->slug, - 'field' => 'slug', - ], - ], - ] - ); - - if ( empty( $child_posts->posts ) || is_wp_error( $child_posts ) ) { - return []; - } - - // Filter out the passed post ID. - return array_filter( - $child_posts->posts, - function( $post ) use ( $post_id ) { - return $post->ID != $post_id; - } - ); - } - - /** - * Apply or remove a parent shadow term to the given child post. - * - * @param object $params Params passed from the REST API request. - * @return bool|WP_Error True if parent was updated successfully, false if missing required params, or WP_Error. - */ - public static function set_parent_posts( $params ) { - $child = ! empty( $params['post_id'] ) ? $params['post_id'] : null; - $added = ! empty( $params['added'] ) ? $params['added'] : null; - $removed = ! empty( $params['removed'] ) ? $params['removed'] : null; - - if ( empty( $child ) ) { - return false; - } - - // Apply the added parent term to the given child post ID. - if ( ! empty( $added ) ) { - $taxonomies_to_add = []; - - foreach ( $added as $term_to_add ) { - if ( ! isset( $taxonomies_to_add[ $term_to_add['taxonomy'] ] ) ) { - $taxonomies_to_add[ $term_to_add['taxonomy'] ] = []; - } - - $taxonomies_to_add[ $term_to_add['taxonomy'] ][] = intval( $term_to_add['id'] ); - } - - foreach ( $taxonomies_to_add as $taxonomy_to_add => $terms_to_add ) { - $added_parents = wp_set_post_terms( $child, $terms_to_add, $taxonomy_to_add, true ); - - // Bail if error. - if ( is_wp_error( $added_parents ) ) { - return $added_parents; - } - } - } - - // Remove the parent's shadow term from the child post ID. - if ( ! empty( $removed ) ) { - $taxonomies_to_remove = []; - - foreach ( $removed as $term_to_remove ) { - if ( ! isset( $taxonomies_to_remove[ $term_to_remove['taxonomy'] ] ) ) { - $taxonomies_to_remove[ $term_to_remove['taxonomy'] ] = []; - } - - $taxonomies_to_remove[ $term_to_remove['taxonomy'] ][] = intval( $term_to_remove['id'] ); - }; - - foreach ( $taxonomies_to_remove as $taxonomy_to_remove => $terms_to_remove ) { - $removed_parents = wp_remove_object_terms( $child, $terms_to_remove, $taxonomy_to_remove ); - - // Bail if error. - if ( is_wp_error( $removed_parents ) ) { - return $removed_parents; - } - } - } - - return true; - } - - /** - * Apply or remove the given parent post's shadow term to or from the given child posts. - * - * @param object $params Params passed from the REST API request. - * @return bool|WP_Error True if children were updated successfully, false if missing required params, or WP_Error. - */ - public static function set_child_posts( $params ) { - $parent = ! empty( $params['post_id'] ) ? $params['post_id'] : null; - $added = ! empty( $params['added'] ) ? $params['added'] : []; - $removed = ! empty( $params['removed'] ) ? $params['removed'] : []; - - if ( empty( $parent ) ) { - return false; - } - - $parent_post = get_post( $parent ); - if ( ! self::should_update_shadow_term( $parent_post ) ) { - return false; - } - - $taxonomy = self::get_taxonomy_by_post_type( $parent_post->post_type ); - $shadow_term = self::get_shadow_term( $parent_post, $taxonomy ); - - // Apply the parent's shadow term to the `added` post IDs. - foreach ( $added as $child_to_add ) { - $added_child = wp_set_post_terms( $child_to_add, $shadow_term->term_id, $taxonomy, true ); - - // Bail if error. - if ( is_wp_error( $added_child ) ) { - return $added_child; - } - } - - // Remove the parent's shadow term from the `removed` post IDs. - foreach ( $removed as $child_to_remove ) { - $removed_child = wp_remove_object_terms( $child_to_remove, $shadow_term->term_id, $taxonomy ); - - // Bail if error. - if ( is_wp_error( $removed_child ) ) { - return $removed_child; - } - } - - return true; - } - - /** - * Register taxonomies on plugin activation. - */ - public static function activation_hook() { - self::register_tax(); - } -} - -Taxonomies::instance(); diff --git a/includes/migration/class-migration.php b/includes/migration/class-migration.php index 82dedf24..29a1f272 100644 --- a/includes/migration/class-migration.php +++ b/includes/migration/class-migration.php @@ -9,7 +9,6 @@ use \WP_CLI; use \Newspack_Listings\Core; -use \Newspack_Listings\Taxonomies; defined( 'ABSPATH' ) || exit; @@ -76,23 +75,6 @@ public static function add_cli_commands() { ], ] ); - - WP_CLI::add_command( - 'newspack-listings taxonomies sync', - [ __CLASS__, 'cli_taxonomy_sync' ], - [ - 'shortdesc' => 'Handle missing and orphaned shadow taxonomy terms, and create new terms as needed.', - 'synopsis' => [ - [ - 'type' => 'flag', - 'name' => 'dry-run', - 'description' => 'Whether to do a dry run.', - 'optional' => true, - 'repeating' => false, - ], - ], - ] - ); } /** @@ -253,163 +235,6 @@ public static function convert_legacy_taxonomies() { return $converted_taxonomies; } - - /** - * Run the 'newspack-listings taxonomy sync' WP CLI command. - * - * @param array $args Positional args. - * @param array $assoc_args Associative args. - */ - public static function cli_taxonomy_sync( $args, $assoc_args ) { - // If a dry run, we won't persist any data. - self::$is_dry_run = isset( $assoc_args['dry-run'] ) ? true : false; - - if ( self::$is_dry_run ) { - WP_CLI::log( "\n===================\n= Dry Run =\n===================\n" ); - } - - WP_CLI::log( "Checking for missing shadow taxonomy terms...\n" ); - - $missing_shadow_terms = self::handle_missing_terms(); - - if ( 0 === count( $missing_shadow_terms ) ) { - WP_CLI::success( 'Good news! No missing shadow terms.' ); - } else { - WP_CLI::success( - sprintf( - 'Created %1$s missing shadow %2$s.', - count( $missing_shadow_terms ), - 1 < count( $missing_shadow_terms ) ? 'terms' : 'term' - ) - ); - } - - WP_CLI::log( "\nChecking for orphaned shadow taxonomy terms...\n" ); - - $orphaned_shadow_terms = self::handle_orphaned_terms(); - - if ( 0 === count( $orphaned_shadow_terms ) ) { - WP_CLI::success( 'Good news! No orphaned shadow terms found.' ); - } else { - WP_CLI::success( - sprintf( - 'Deleted %1$s orphaned shadow %2$s.', - count( $orphaned_shadow_terms ), - 1 < count( $orphaned_shadow_terms ) ? 'terms' : 'term' - ) - ); - } - } - - /** - * Handle any published posts of the relevant types that are missing a corresponding shadow term. - */ - public static function handle_missing_terms() { - $missing_terms = []; - $tax_query = [ 'relation' => 'OR' ]; - - foreach ( Taxonomies::NEWSPACK_LISTINGS_TAXONOMIES as $post_type_to_shadow => $shadow_taxonomy ) { - $tax_query[] = [ - 'taxonomy' => $shadow_taxonomy, - 'operator' => 'NOT EXISTS', - ]; - } - - $query = new \WP_Query( - [ - 'post_type' => Taxonomies::get_post_types_to_shadow(), - 'post_status' => 'publish', - 'posts_per_page' => 100, - 'tax_query' => $tax_query, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query - ] - ); - - if ( $query->have_posts() ) { - while ( $query->have_posts() ) { - $query->the_post(); - $post_id = get_the_ID(); - $post = get_post( $post_id ); - $post_type = $post->post_type; - $term_slug = array_keys( Core::NEWSPACK_LISTINGS_POST_TYPES, $post_type ); - $term_slug = reset( $term_slug ); - - // Bail if not a post type to be shadowed. - if ( empty( $term_slug ) || ! Taxonomies::should_update_shadow_term( $post ) ) { - continue; - } - - // Check for a shadow term associated with this post. - $shadow_term = Taxonomies::get_shadow_term( $post, Taxonomies::NEWSPACK_LISTINGS_TAXONOMIES[ $term_slug ] ); - - // If there isn't already a shadow term, create it. Otherwise, apply the term to the post. - if ( empty( $shadow_term ) ) { - if ( ! self::$is_dry_run ) { - $shadow_term = Taxonomies::create_shadow_term( $post, Taxonomies::NEWSPACK_LISTINGS_TAXONOMIES[ $term_slug ] ); - } - WP_CLI::log( - sprintf( - 'Created missing shadow term for %s.', - $post->post_title - ) - ); - $missing_terms[] = $shadow_term; - } else { - if ( ! self::$is_dry_run ) { - wp_set_post_terms( $post_id, $shadow_term->term_id, Taxonomies::NEWSPACK_LISTINGS_TAXONOMIES[ $term_slug ], true ); - } - } - } - } - - return $missing_terms; - } - - /** - * Delete any shadow terms that no longer have a post to shadow. - */ - public static function handle_orphaned_terms() { - $orphaned_terms = []; - $all_terms = get_terms( - [ - 'taxonomy' => array_values( Taxonomies::NEWSPACK_LISTINGS_TAXONOMIES ), - 'hide_empty' => false, - ] - ); - $term_slugs = array_column( $all_terms, 'slug' ); - $query = new \WP_Query( - [ - 'post_type' => Taxonomies::get_post_types_to_shadow(), - 'post_status' => 'publish', - 'posts_per_page' => 100, - 'post_name__in' => $term_slugs, - ] - ); - - if ( $query->have_posts() ) { - $post_slugs = array_column( $query->posts, 'post_name' ); - $orphaned_slugs = array_diff( $term_slugs, $post_slugs ); - $orphaned_terms = array_filter( - $all_terms, - function( $term ) use ( $orphaned_slugs ) { - return in_array( $term->slug, $orphaned_slugs ); - } - ); - - foreach ( $orphaned_terms as $orphaned_term ) { - if ( ! self::$is_dry_run ) { - wp_delete_term( $orphaned_term->term_id, $orphaned_term->taxonomy ); - } - WP_CLI::log( - sprintf( - 'Deleted orphaned shadow term %s.', - $orphaned_term->name - ) - ); - } - } - - return $orphaned_terms; - } } Migration::instance(); diff --git a/newspack-listings.php b/newspack-listings.php index e4b2568a..233260df 100644 --- a/newspack-listings.php +++ b/newspack-listings.php @@ -29,7 +29,6 @@ require_once NEWSPACK_LISTINGS_PLUGIN_FILE . '/includes/class-core.php'; require_once NEWSPACK_LISTINGS_PLUGIN_FILE . '/includes/class-blocks.php'; require_once NEWSPACK_LISTINGS_PLUGIN_FILE . '/includes/class-block-patterns.php'; -require_once NEWSPACK_LISTINGS_PLUGIN_FILE . '/includes/class-taxonomies.php'; require_once NEWSPACK_LISTINGS_PLUGIN_FILE . '/includes/class-api.php'; // Enable experimental/in-progress self-serve listings functionality. diff --git a/src/editor/index.js b/src/editor/index.js index 2cbed6cc..1c74a6a2 100644 --- a/src/editor/index.js +++ b/src/editor/index.js @@ -22,7 +22,6 @@ import { registerSelfServeListingsBlock, setCustomCategory, } from '../blocks'; -import { ShadowTaxonomies } from './shadow-taxonomies'; import { FeaturedListings } from './featured-listings'; import { isListing } from './utils'; import './style.scss'; @@ -142,12 +141,3 @@ if ( isListingCustomer ) { }, 1000 ); } ); } - -// If we don't have a post type, we're probably not in a post editor, so we don't need to register the post taxonomy sidebars. -if ( postType ) { - // Register plugin editor settings. - registerPlugin( 'newspack-listings-shadow-taxonomies', { - render: ShadowTaxonomies, - icon: null, - } ); -} diff --git a/src/editor/shadow-taxonomies/child-listings.js b/src/editor/shadow-taxonomies/child-listings.js deleted file mode 100644 index 78173350..00000000 --- a/src/editor/shadow-taxonomies/child-listings.js +++ /dev/null @@ -1,291 +0,0 @@ -/** - * UI for managing child listings and posts. - */ - -/** - * WordPress dependencies - */ -import { __, sprintf } from '@wordpress/i18n'; -import apiFetch from '@wordpress/api-fetch'; -import { - Button, - ExternalLink, - Modal, - Notice, - PanelRow, - ToggleControl, -} from '@wordpress/components'; -import { compose } from '@wordpress/compose'; -import { withDispatch, withSelect } from '@wordpress/data'; -import { PluginDocumentSettingPanel } from '@wordpress/edit-post'; -import { useEffect, useState } from '@wordpress/element'; -import { addQueryArgs } from '@wordpress/url'; - -/** - * External dependencies - */ -import { AutocompleteWithSuggestions } from 'newspack-components'; - -/** - * Internal dependencies - */ -import { getPostTypeLabel, getTaxonomyForPostType, isListing } from '../utils'; -import './style.scss'; - -const ChildListingsComponent = ( { hideChildren, postId, updateMetaValue } ) => { - const [ modalVisible, setModalVisible ] = useState( false ); - const [ isUpdating, setIsUpdating ] = useState( false ); - const [ initialChildPosts, setInitialChildPosts ] = useState( [] ); - const [ childPosts, setChildPosts ] = useState( [] ); - const [ selectedPostType, setSelectedPostType ] = useState( null ); - const [ message, setMessage ] = useState( null ); - const postType = window?.newspack_listings_data.post_type; - const listingPostTypes = window?.newspack_listings_data.post_types || {}; - const taxonomyForPostType = getTaxonomyForPostType(); - const childPostTypes = taxonomyForPostType?.post_types || []; - const filteredChildPostTypes = childPostTypes.filter( - childPostType => childPostType !== postType - ); - const canHaveChildren = 0 < filteredChildPostTypes.length && isListing(); - - // Fetch suggestions for suggestions list on component mount. - useEffect( () => { - if ( canHaveChildren ) { - setMessage( null ); - apiFetch( { - path: addQueryArgs( '/newspack-listings/v1/children', { - per_page: 100, - post_id: postId, - } ), - } ) - .then( response => { - if ( response ) { - const mappedResponse = response.map( post => ( { - value: post.value, - label: post.label, - postType: post.post_type, - } ) ); - setChildPosts( mappedResponse ); - setInitialChildPosts( mappedResponse ); - } - } ) - .catch( e => { - setMessage( { - status: 'error', - children: e.message || __( 'Error fetching suggestions.', 'newspack-listings' ), - isDismissible: false, - } ); - } ); - } - }, [] ); - - // Bail early if the post type can't have child listings. - if ( ! canHaveChildren ) { - return null; - } - - // Get an array of post types that can be children of this post. - const validPostTypes = [ - ...Object.keys( listingPostTypes ).reduce( ( acc, listingType ) => { - if ( - -1 < childPostTypes.indexOf( listingPostTypes[ listingType ].name ) && - listingPostTypes[ listingType ].name !== postType - ) { - acc.push( { - slug: listingPostTypes[ listingType ].name, - label: listingPostTypes[ listingType ].label, - } ); - } - - return acc; - }, [] ), - { slug: 'post', label: 'Post' }, - { slug: 'page', label: 'Page' }, - ]; - - // Update shadow terms for the children selected for this post. - const update = async () => { - setIsUpdating( true ); - setMessage( null ); - const addedPostIds = childPosts.reduce( ( acc, childPostToAdd ) => { - if ( ! initialChildPosts.find( childPost => childPost.value === childPostToAdd.value ) ) { - acc.push( childPostToAdd.value ); - } - - return acc; - }, [] ); - const removedPostIds = initialChildPosts.reduce( ( acc, childPostToRemove ) => { - if ( ! childPosts.find( childPost => childPost.value === childPostToRemove.value ) ) { - acc.push( childPostToRemove.value ); - } - - return acc; - }, [] ); - - try { - const response = await apiFetch( { - path: addQueryArgs( '/newspack-listings/v1/children', { - post_id: postId, - added: addedPostIds, - removed: removedPostIds, - } ), - method: 'POST', - } ); - - /** - * Because updating parent or child listings happens in real time instead of - * after clicking "Save" or "Update" on the current post, we should show a - * notice with the result of the operation in the editor to indicate whether - * the update happened successfully or not. - */ - if ( true === response ) { - setInitialChildPosts( childPosts ); // Update saved state. - setMessage( { - status: 'success', - children: __( 'Related content updated.', 'newspack-listings' ), - isDismissible: false, - } ); - } else { - setMessage( { - status: 'error', - children: __( 'Error updating related content.', 'newspack-listings' ), - isDismissible: false, - } ); - } - } catch ( e ) { - setMessage( { - status: 'error', - children: e.message || __( 'Error updating related content.', 'newspack-listings' ), - isDismissible: false, - } ); - } - - setIsUpdating( false ); - }; - - const getLabel = () => { - if ( selectedPostType ) { - return sprintf( - // Translators: Search help message. - __( 'Search %ss', 'newspack-listings' ), - getPostTypeLabel( selectedPostType ) - ); - } - - return __( 'Search', 'newspack-listings' ); - }; - - return ( - - - ( -

- { __( 'Overrides ', 'newspack-listings' ) } - - { __( 'global settings', 'newspack-listings' ) } - -

- ) } - checked={ hideChildren } - onChange={ value => updateMetaValue( 'newspack_listings_hide_children', value ) } - /> -
- { ! hideChildren && ( - - ) } - { modalVisible && ( - { - setModalVisible( false ); - setMessage( null ); - } } - > - { message && } - { childPosts && 0 === childPosts.length && ( -

- { __( 'No items selected.', 'newspack-listings' ) } -

- ) } - { - setMessage( null ); - setChildPosts( items ); - } } - onPostTypeChange={ _postType => setSelectedPostType( _postType ) } - postTypes={ validPostTypes } - selectedItems={ childPosts } - /> -
- - -
-
- ) } -
- ); -}; - -const mapStateToProps = select => { - const { getCurrentPostId, getEditedPostAttribute } = select( 'core/editor' ); - const meta = getEditedPostAttribute( 'meta' ) || {}; - - return { - getEditedPostAttribute, - hideChildren: meta?.newspack_listings_hide_children, - postId: getCurrentPostId(), - }; -}; - -const mapDispatchToProps = dispatch => { - const { editPost } = dispatch( 'core/editor' ); - const { createNotice } = dispatch( 'core/notices' ); - - return { - createNotice, - editPost, - updateMetaValue: ( key, value ) => editPost( { meta: { [ key ]: value } } ), - }; -}; - -export const ChildListings = compose( [ - withSelect( mapStateToProps ), - withDispatch( mapDispatchToProps ), -] )( ChildListingsComponent ); diff --git a/src/editor/shadow-taxonomies/index.js b/src/editor/shadow-taxonomies/index.js deleted file mode 100644 index d49275bb..00000000 --- a/src/editor/shadow-taxonomies/index.js +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Filtered taxonomy UI for Listings shadow taxonomies. - * Replaces the default "add new" buttons with a link to create a new post of the corresponding type. - */ - -/** - * Internal dependencies - */ -import { ParentListings } from './parent-listings'; -import { ChildListings } from './child-listings'; -import './style.scss'; - -export const ShadowTaxonomies = () => { - return ( - <> - - - - ); -}; diff --git a/src/editor/shadow-taxonomies/parent-listings.js b/src/editor/shadow-taxonomies/parent-listings.js deleted file mode 100644 index fb1291b6..00000000 --- a/src/editor/shadow-taxonomies/parent-listings.js +++ /dev/null @@ -1,367 +0,0 @@ -/** - * UI for managing parent listings. - */ - -/** - * WordPress dependencies - */ -import { __, sprintf, _x } from '@wordpress/i18n'; -import apiFetch from '@wordpress/api-fetch'; -import { - Button, - ExternalLink, - Modal, - Notice, - PanelRow, - Spinner, - ToggleControl, -} from '@wordpress/components'; -import { compose } from '@wordpress/compose'; -import { withDispatch, withSelect } from '@wordpress/data'; -import { PluginDocumentSettingPanel } from '@wordpress/edit-post'; -import { useEffect, useState } from '@wordpress/element'; -import { decodeEntities } from '@wordpress/html-entities'; -import { addQueryArgs } from '@wordpress/url'; - -/** - * External dependencies - */ -import { AutocompleteWithSuggestions } from 'newspack-components'; - -/** - * Internal dependencies - */ -import { getPostTypeByTaxonomy, getTaxonomyLabel, isListing } from '../utils'; -import './style.scss'; - -const ParentListingsComponent = ( { hideParents, postId, updateMetaValue } ) => { - const [ isUpdating, setIsUpdating ] = useState( false ); - const [ modalVisible, setModalVisible ] = useState( false ); - const [ initialParentTerms, setInitialParentTerms ] = useState( [] ); - const [ parentTerms, setParentTerms ] = useState( [] ); - const [ selectedPostType, setSelectedPostType ] = useState( null ); - const [ message, setMessage ] = useState( null ); - const postType = window?.newspack_listings_data.post_type; - const postTypes = window?.newspack_listings_data.post_types || {}; - const taxonomies = window?.newspack_listings_data.taxonomies || {}; - - // Determine whether the current post can have parent listings. - let canHaveParents = false; - for ( const taxonomy in taxonomies ) { - const taxonomyPostType = getPostTypeByTaxonomy( taxonomies[ taxonomy ].name ); - const postTypeIsChild = -1 < taxonomies[ taxonomy ].post_types.indexOf( postType ); - - // Posts, pages, and listings can have parents if they can be assigned listing shadow terms. - if ( ! isListing() && postTypeIsChild && taxonomyPostType !== postType ) { - canHaveParents = true; - } - } - - // Fetch suggestions for suggestions list on component mount. - useEffect( () => { - if ( canHaveParents ) { - setMessage( null ); - apiFetch( { - path: addQueryArgs( '/newspack-listings/v1/parents', { - per_page: 100, - post_id: postId, - } ), - } ) - .then( response => { - const mappedResponse = response.map( post => ( { - value: post.value, - label: post.label, - postType: post.post_type, - } ) ); - setParentTerms( mappedResponse ); - setInitialParentTerms( mappedResponse ); - } ) - .catch( e => { - setMessage( { - status: 'error', - children: e.message || __( 'Error fetching suggestions.', 'newspack-listings' ), - isDismissible: false, - } ); - } ); - } - }, [] ); - - // Bail early if the post type can't have parent listings. - if ( ! canHaveParents ) { - return null; - } - - // Get an array of taxonomies that can be parents of this post. - const validTaxonomies = Object.keys( taxonomies ).reduce( ( acc, type ) => { - const taxonomy = taxonomies[ type ]; - if ( -1 < taxonomy.post_types.indexOf( postType ) && postTypes[ type ].name !== postType ) { - acc.push( { slug: taxonomy.name, label: taxonomy.label } ); - } - return acc; - }, [] ); - - // Update shadow terms for this post. - const update = async () => { - setIsUpdating( true ); - setMessage( null ); - const addedTerms = parentTerms.reduce( ( acc, termToAdd ) => { - if ( ! initialParentTerms.find( term => term.value === termToAdd.value ) ) { - acc.push( { id: termToAdd.value, taxonomy: termToAdd.postType } ); - } - - return acc; - }, [] ); - const removedTerms = initialParentTerms.reduce( ( acc, termToRemove ) => { - if ( ! parentTerms.find( term => term.value === termToRemove.value ) ) { - acc.push( { id: termToRemove.value, taxonomy: termToRemove.postType } ); - } - - return acc; - }, [] ); - - try { - const response = await apiFetch( { - path: addQueryArgs( '/newspack-listings/v1/parents', { - post_id: postId, - added: addedTerms, - removed: removedTerms, - } ), - method: 'POST', - } ); - - /** - * Because updating parent or child listings happens in real time instead of - * after clicking "Save" or "Update" on the current post, we should show a - * notice with the result of the operation in the editor to indicate whether - * the update happened successfully or not. - */ - if ( true === response ) { - setInitialParentTerms( parentTerms ); // Update saved state. - setMessage( { - status: 'success', - children: sprintf( - // Translators: Parent listing update success message. - __( '%1$s listing%2$s updated.', 'newspack-listings' ), - isListing() - ? __( 'Parent', 'newspack-listings' ) - : __( 'Related', 'newspack-listings' ), - isListing() ? '' : _x( 's', 'pluralization', 'newspack-listings' ) - ), - isDismissible: false, - } ); - } else { - setMessage( { - status: 'error', - children: sprintf( - // Translators: Parent listing update error message. - __( 'Error updating %1$s listing%2$s.', 'newspack-listings' ), - isListing() - ? __( 'parent', 'newspack-listings' ) - : __( 'related', 'newspack-listings' ), - isListing() ? '' : _x( 's', 'pluralization', 'newspack-listings' ) - ), - isDismissible: false, - } ); - } - } catch ( e ) { - setMessage( { - status: 'error', - children: - e.message || - sprintf( - // Translators: Parent listing update error message. - __( 'Error updating %1$s listing%2$s.', 'newspack-listings' ), - isListing() - ? __( 'parent', 'newspack-listings' ) - : __( 'related', 'newspack-listings' ), - isListing() ? '' : _x( 's', 'pluralization', 'newspack-listings' ) - ), - isDismissible: false, - } ); - } - - setIsUpdating( false ); - }; - - const getLabel = () => { - if ( selectedPostType ) { - switch ( selectedPostType ) { - case 'post': - return __( 'Search Posts', 'newspack-listings' ); - case 'page': - return __( 'Search Pages', 'newspack-listings' ); - default: - return sprintf( - // Translators: Taxonomy search help message. - __( 'Search %ss', 'newspack-listings' ), - getTaxonomyLabel( selectedPostType ) - ); - } - } - - return __( 'Search', 'newspack-listings' ); - }; - - return ( - - - ( -

- { __( 'Overrides ', 'newspack-listings' ) } - - { __( 'global settings', 'newspack-listings' ) } - -

- ) } - checked={ hideParents } - onChange={ value => updateMetaValue( 'newspack_listings_hide_parents', value ) } - /> -
- { ! hideParents && ( - - ) } - { modalVisible && ( - { - setModalVisible( false ); - setMessage( null ); - } } - > - { message && } - { parentTerms && 0 === parentTerms.length && ( -

- { __( 'No items selected.', 'newspack-listings' ) } -

- ) } - { null === parentTerms && } - - { - if ( taxonomyToSearch ) { - const terms = await apiFetch( { - path: addQueryArgs( '/wp/v2/' + taxonomyToSearch, { - search, - offset, - per_page: 100, - } ), - } ); - - return terms.map( term => ( { - value: term.id, - label: decodeEntities( term.name ) || __( '(no title)', 'newspack' ), - postType: term.taxonomy, - } ) ); - } - - return []; - } } - onChange={ items => { - setMessage( null ); - setParentTerms( items ); - } } - onPostTypeChange={ _postType => setSelectedPostType( _postType ) } - postTypes={ validTaxonomies } - selectedItems={ parentTerms } - /> -
- - -
-
- ) } -
- ); -}; - -const mapStateToProps = select => { - const { getCurrentPostId, getEditedPostAttribute } = select( 'core/editor' ); - const meta = getEditedPostAttribute( 'meta' ) || {}; - - return { - getEditedPostAttribute, - hideParents: meta?.newspack_listings_hide_parents, - postId: getCurrentPostId(), - }; -}; - -const mapDispatchToProps = dispatch => { - const { editPost } = dispatch( 'core/editor' ); - const { createNotice } = dispatch( 'core/notices' ); - - return { - createNotice, - editPost, - updateMetaValue: ( key, value ) => editPost( { meta: { [ key ]: value } } ), - }; -}; - -export const ParentListings = compose( [ - withSelect( mapStateToProps ), - withDispatch( mapDispatchToProps ), -] )( ParentListingsComponent ); diff --git a/src/editor/shadow-taxonomies/style.scss b/src/editor/shadow-taxonomies/style.scss deleted file mode 100644 index d90ce758..00000000 --- a/src/editor/shadow-taxonomies/style.scss +++ /dev/null @@ -1,72 +0,0 @@ -@import '../../assets/shared/variables.scss'; -@import '~@wordpress/base-styles/colors'; - -.newspack-listings { - &__shadow-taxonomy-panel { - position: relative; - - + .newspack-listings__shadow-taxonomy-panel { - margin-top: 1.5rem; - } - - .components-form-token-field__help { - display: none; - } - - .components-spinner { - margin: 0; - position: absolute; - right: 0.5rem; - top: 1.75rem; - } - } - - &__modal { - .components-notice { - margin: 0; - } - - @media only screen and ( min-width: $tablet_width ) { - width: 562px; - } - } - - &__empty-message { - border-bottom: 1px solid var( --newspack-listings--grey-light ); - margin-bottom: 2rem; - padding-bottom: 1.75rem; - } - - &__modal-actions { - margin-top: 1rem; - text-align: right; - - .components-button + .components-button { - margin-left: 1rem; - } - } - - &__term-title { - margin-bottom: 0.5em; - } - - &__term-button.components-button.is-tertiary { - background-color: #ddd; - border-radius: 2px; - color: #1e1e1e; - font-size: 13px; - height: auto; - padding-left: 8px; - padding-right: 8px; - - &::after { - content: '✕'; - margin-left: 8px; - } - - &:hover { - box-shadow: none; - color: black; - } - } -} diff --git a/src/editor/utils.js b/src/editor/utils.js index f4cab4f5..2d682715 100644 --- a/src/editor/utils.js +++ b/src/editor/utils.js @@ -36,121 +36,6 @@ export const isListing = ( listingType = null ) => { return false; }; -/** - * Given a post type string, get the human-readable label for the post type. - * - * @param {string} postType Name of the post type. - * @return {string} The label of the post type, or the post type itself if we can't determine. - */ -export const getPostTypeLabel = postType => { - if ( ! window.newspack_listings_data ) { - return capitalize( postTypes ); - } - - const { post_types: postTypes } = window.newspack_listings_data; - - // Check whether the given taxonomy is a Listings shadow taxonomy. - for ( const slug in postTypes ) { - if ( postTypes.hasOwnProperty( slug ) && postType === postTypes[ slug ].name ) { - return postTypes[ slug ].label; - } - } - - return capitalize( postType ); -}; - -/** - * Check if the given taxonomy is a Listings shadow taxonomy. - * - * @param {string} taxonomyName Name of the taxonomy. - * @return {boolean} Whether or not the given taxonomy is a Listings shadow taxonomy. - */ -export const isShadowTaxonomy = taxonomyName => { - if ( ! window.newspack_listings_data ) { - return false; - } - - const { taxonomies } = window.newspack_listings_data; - - // Check whether the given taxonomy is a Listings shadow taxonomy. - for ( const slug in taxonomies ) { - if ( taxonomies.hasOwnProperty( slug ) && taxonomyName === taxonomies[ slug ].name ) { - return true; - } - } - - return false; -}; - -/** - * Given a shadow taxonomy name, get the human-readable label for the taxonomy. - * - * @param {string} taxonomyName Name of the taxonomy. - * @return {string} The label of the taxonomy, or the taxonomy name itself if we can't determine. - */ -export const getTaxonomyLabel = taxonomyName => { - if ( ! window.newspack_listings_data ) { - return capitalize( taxonomyName ); - } - - const { taxonomies } = window.newspack_listings_data; - - // Check whether the given taxonomy is a Listings shadow taxonomy. - for ( const slug in taxonomies ) { - if ( taxonomies.hasOwnProperty( slug ) && taxonomyName === taxonomies[ slug ].name ) { - return taxonomies[ slug ].label; - } - } - - return capitalize( taxonomyName ); -}; - -/** - * Given a shadow taxonomy name, find the correponding post type it shadows. - * - * @param {string} taxonomyName Name of the taxonomy. - * @return {string|boolean} The post type the given taxonomy shadows, or false if none. - */ -export const getPostTypeByTaxonomy = taxonomyName => { - if ( ! window.newspack_listings_data ) { - return false; - } - - const { post_types: postTypes, taxonomies } = window.newspack_listings_data; - - // Check whether the given taxonomy is a Listings shadow taxonomy. - for ( const slug in taxonomies ) { - if ( taxonomies.hasOwnProperty( slug ) && taxonomyName === taxonomies[ slug ].name ) { - return postTypes[ slug ].name; - } - } - - return false; -}; - -/** - * Given a post type, get the corresopnding shadow taxonomy that shadows it. - * - * @param {string|null} postType (Optional) Post type to check. If not given, will extract from global data. - * @return {Object|boolean} The taxonomy that shadows the given post type, or false if none. - */ -export const getTaxonomyForPostType = ( postType = null ) => { - if ( ! window.newspack_listings_data ) { - return false; - } - - const { post_type, post_types: postTypes, taxonomies } = window.newspack_listings_data; - const postTypeToCheck = postType || post_type; - - for ( const slug in postTypes ) { - if ( postTypes[ slug ].name === postTypeToCheck ) { - return taxonomies[ slug ]; - } - } - - return false; -}; - /** * Convert hex color to RGB. * From https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb From b2810fdfa346486c0095f64991bf91dcf6aa232f Mon Sep 17 00:00:00 2001 From: matticbot Date: Wed, 25 May 2022 17:19:22 +0000 Subject: [PATCH 4/7] chore(release): 2.11.0-alpha.1 [skip ci] # [2.11.0-alpha.1](https://github.com/Automattic/newspack-listings/compare/v2.10.0...v2.11.0-alpha.1) (2022-05-25) ### Features * enable jetpack share buttons on listings ([#257](https://github.com/Automattic/newspack-listings/issues/257)) ([0dac9fb](https://github.com/Automattic/newspack-listings/commit/0dac9fb482b577de74e886900a7cf85eed2bd571)) * remove related listings functionality ([#256](https://github.com/Automattic/newspack-listings/issues/256)) ([25f4be8](https://github.com/Automattic/newspack-listings/commit/25f4be8dd216b00ee73cc952dd2e9f93728def03)) --- CHANGELOG.md | 8 ++++++++ newspack-listings.php | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99dba098..813136e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# [2.11.0-alpha.1](https://github.com/Automattic/newspack-listings/compare/v2.10.0...v2.11.0-alpha.1) (2022-05-25) + + +### Features + +* enable jetpack share buttons on listings ([#257](https://github.com/Automattic/newspack-listings/issues/257)) ([0dac9fb](https://github.com/Automattic/newspack-listings/commit/0dac9fb482b577de74e886900a7cf85eed2bd571)) +* remove related listings functionality ([#256](https://github.com/Automattic/newspack-listings/issues/256)) ([25f4be8](https://github.com/Automattic/newspack-listings/commit/25f4be8dd216b00ee73cc952dd2e9f93728def03)) + # [2.10.0](https://github.com/Automattic/newspack-listings/compare/v2.9.4...v2.10.0) (2022-05-03) diff --git a/newspack-listings.php b/newspack-listings.php index 233260df..0a0ff093 100644 --- a/newspack-listings.php +++ b/newspack-listings.php @@ -7,7 +7,7 @@ * Author URI: https://newspack.pub * Text Domain: newspack-listings * Domain Path: /languages - * Version: 2.10.0 + * Version: 2.11.0-alpha.1 * * @package Newspack_Listings */ diff --git a/package-lock.json b/package-lock.json index 55d1a96a..f63845e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "newspack-listings", - "version": "2.10.0", + "version": "2.11.0-alpha.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "newspack-listings", - "version": "2.10.0", + "version": "2.11.0-alpha.1", "license": "GPL-2.0-or-later", "dependencies": { "newspack-components": "^2.0.3" diff --git a/package.json b/package.json index 7e465fd8..c0862068 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "newspack-listings", - "version": "2.10.0", + "version": "2.11.0-alpha.1", "description": "", "scripts": { "cm": "newspack-scripts commit", From d4e8193528696e4081d71e6839ce0a1a3e09b3f0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 May 2022 06:12:57 +0000 Subject: [PATCH 5/7] chore(deps-dev): bump newspack-scripts from 3.3.0 to 3.3.1 Bumps [newspack-scripts](https://github.com/Automattic/newspack-scripts) from 3.3.0 to 3.3.1. - [Release notes](https://github.com/Automattic/newspack-scripts/releases) - [Commits](https://github.com/Automattic/newspack-scripts/compare/v3.3.0...v3.3.1) --- updated-dependencies: - dependency-name: newspack-scripts dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 343 ++++++++++++++++++++++++++++++++++++++-------- package.json | 2 +- 2 files changed, 290 insertions(+), 55 deletions(-) diff --git a/package-lock.json b/package-lock.json index 55d1a96a..b54fd6e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "@rushstack/eslint-patch": "^1.1.3", "eslint": "^7.32.0", "lint-staged": "^12.4.1", - "newspack-scripts": "^3.3.0", + "newspack-scripts": "^3.3.1", "postcss": "^8.4.14", "prettier": "npm:wp-prettier@^2.2.1-beta-1", "stylelint": "^13.13.1" @@ -5132,6 +5132,178 @@ "integrity": "sha512-37RSHht+gzzgYeobbG+KWryeAW8J33Nhr69cjTqSYymXVZEN9NbRYWoYlRtDhHKPVT1FyNKwaTPC1NynKZpzRA==", "dev": true }, + "node_modules/@typescript-eslint/parser": { + "version": "5.26.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.26.0.tgz", + "integrity": "sha512-n/IzU87ttzIdnAH5vQ4BBDnLPly7rC5VnjN3m0xBG82HK6rhRxnCb3w/GyWbNDghPd+NktJqB/wl6+YkzZ5T5Q==", + "dev": true, + "dependencies": { + "@typescript-eslint/scope-manager": "5.26.0", + "@typescript-eslint/types": "5.26.0", + "@typescript-eslint/typescript-estree": "5.26.0", + "debug": "^4.3.4" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/scope-manager": { + "version": "5.26.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.26.0.tgz", + "integrity": "sha512-gVzTJUESuTwiju/7NiTb4c5oqod8xt5GhMbExKsCTp6adU3mya6AGJ4Pl9xC7x2DX9UYFsjImC0mA62BCY22Iw==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "5.26.0", + "@typescript-eslint/visitor-keys": "5.26.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/types": { + "version": "5.26.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.26.0.tgz", + "integrity": "sha512-8794JZFE1RN4XaExLWLI2oSXsVImNkl79PzTOOWt9h0UHROwJedNOD2IJyfL0NbddFllcktGIO2aOu10avQQyA==", + "dev": true, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/typescript-estree": { + "version": "5.26.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.26.0.tgz", + "integrity": "sha512-EyGpw6eQDsfD6jIqmXP3rU5oHScZ51tL/cZgFbFBvWuCwrIptl+oueUZzSmLtxFuSOQ9vDcJIs+279gnJkfd1w==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "5.26.0", + "@typescript-eslint/visitor-keys": "5.26.0", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "semver": "^7.3.7", + "tsutils": "^3.21.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/visitor-keys": { + "version": "5.26.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.26.0.tgz", + "integrity": "sha512-wei+ffqHanYDOQgg/fS6Hcar6wAWv0CUPQ3TZzOWd2BLfgP539rb49bwua8WRAs7R6kOSLn82rfEu2ro6Llt8Q==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "5.26.0", + "eslint-visitor-keys": "^3.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/eslint-visitor-keys": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz", + "integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==", + "dev": true, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/globby": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", + "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", + "dev": true, + "dependencies": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", + "slash": "^3.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/ignore": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", + "integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==", + "dev": true, + "engines": { + "node": ">= 4" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/semver": { + "version": "7.3.7", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", + "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/slash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", + "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/@typescript-eslint/scope-manager": { "version": "5.10.2", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.10.2.tgz", @@ -9465,9 +9637,9 @@ } }, "node_modules/debug": { - "version": "4.3.3", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz", - "integrity": "sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==", + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", "dependencies": { "ms": "2.1.2" }, @@ -18186,13 +18358,12 @@ } }, "node_modules/newspack-scripts": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/newspack-scripts/-/newspack-scripts-3.3.0.tgz", - "integrity": "sha512-aKkgBinpiIA/TVSqYJJyxl3gKCXoOTu0riTAnQ3fLT8pDwoquhPHrjN/CUgkcXi2ScMfFiIUJbUowEJGvBMYDw==", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/newspack-scripts/-/newspack-scripts-3.3.1.tgz", + "integrity": "sha512-gbbHa/4gQ4rkXtNnrxns/RbFt33MoQhQEkX0FzwS7wmqeCq/dpbXSrgIEr3wjEfscTvLWMJ+oXUgOCpM6w5yqg==", "dev": true, "dependencies": { "@automattic/calypso-build": "^10.0.0", - "@babel/eslint-parser": "^7.16.3", "@babel/preset-env": "^7.16.4", "@commitlint/cli": "^15.0.0", "@commitlint/config-conventional": "^15.0.0", @@ -18201,6 +18372,7 @@ "@testing-library/jest-dom": "^5.15.1", "@testing-library/react": "^12.1.2", "@types/wordpress__data": "^4.6.10", + "@typescript-eslint/parser": "^5.26.0", "@wordpress/a11y": "^3.2.4", "@wordpress/api-fetch": "^5.2.6", "@wordpress/base-styles": "^4.0.4", @@ -18372,33 +18544,6 @@ "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, - "node_modules/newspack-scripts/node_modules/@typescript-eslint/parser": { - "version": "5.10.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.10.2.tgz", - "integrity": "sha512-JaNYGkaQVhP6HNF+lkdOr2cAs2wdSZBoalE22uYWq8IEv/OVH0RksSGydk+sW8cLoSeYmC+OHvRyv2i4AQ7Czg==", - "dev": true, - "dependencies": { - "@typescript-eslint/scope-manager": "5.10.2", - "@typescript-eslint/types": "5.10.2", - "@typescript-eslint/typescript-estree": "5.10.2", - "debug": "^4.3.2" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, "node_modules/newspack-scripts/node_modules/@typescript-eslint/type-utils": { "version": "5.10.2", "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.10.2.tgz", @@ -34799,6 +34944,108 @@ "integrity": "sha512-37RSHht+gzzgYeobbG+KWryeAW8J33Nhr69cjTqSYymXVZEN9NbRYWoYlRtDhHKPVT1FyNKwaTPC1NynKZpzRA==", "dev": true }, + "@typescript-eslint/parser": { + "version": "5.26.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.26.0.tgz", + "integrity": "sha512-n/IzU87ttzIdnAH5vQ4BBDnLPly7rC5VnjN3m0xBG82HK6rhRxnCb3w/GyWbNDghPd+NktJqB/wl6+YkzZ5T5Q==", + "dev": true, + "requires": { + "@typescript-eslint/scope-manager": "5.26.0", + "@typescript-eslint/types": "5.26.0", + "@typescript-eslint/typescript-estree": "5.26.0", + "debug": "^4.3.4" + }, + "dependencies": { + "@typescript-eslint/scope-manager": { + "version": "5.26.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.26.0.tgz", + "integrity": "sha512-gVzTJUESuTwiju/7NiTb4c5oqod8xt5GhMbExKsCTp6adU3mya6AGJ4Pl9xC7x2DX9UYFsjImC0mA62BCY22Iw==", + "dev": true, + "requires": { + "@typescript-eslint/types": "5.26.0", + "@typescript-eslint/visitor-keys": "5.26.0" + } + }, + "@typescript-eslint/types": { + "version": "5.26.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.26.0.tgz", + "integrity": "sha512-8794JZFE1RN4XaExLWLI2oSXsVImNkl79PzTOOWt9h0UHROwJedNOD2IJyfL0NbddFllcktGIO2aOu10avQQyA==", + "dev": true + }, + "@typescript-eslint/typescript-estree": { + "version": "5.26.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.26.0.tgz", + "integrity": "sha512-EyGpw6eQDsfD6jIqmXP3rU5oHScZ51tL/cZgFbFBvWuCwrIptl+oueUZzSmLtxFuSOQ9vDcJIs+279gnJkfd1w==", + "dev": true, + "requires": { + "@typescript-eslint/types": "5.26.0", + "@typescript-eslint/visitor-keys": "5.26.0", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "semver": "^7.3.7", + "tsutils": "^3.21.0" + } + }, + "@typescript-eslint/visitor-keys": { + "version": "5.26.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.26.0.tgz", + "integrity": "sha512-wei+ffqHanYDOQgg/fS6Hcar6wAWv0CUPQ3TZzOWd2BLfgP539rb49bwua8WRAs7R6kOSLn82rfEu2ro6Llt8Q==", + "dev": true, + "requires": { + "@typescript-eslint/types": "5.26.0", + "eslint-visitor-keys": "^3.3.0" + } + }, + "array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true + }, + "eslint-visitor-keys": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz", + "integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==", + "dev": true + }, + "globby": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", + "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", + "dev": true, + "requires": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", + "slash": "^3.0.0" + } + }, + "ignore": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", + "integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==", + "dev": true + }, + "semver": { + "version": "7.3.7", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", + "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "slash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", + "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", + "dev": true + } + } + }, "@typescript-eslint/scope-manager": { "version": "5.10.2", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.10.2.tgz", @@ -38247,9 +38494,9 @@ "dev": true }, "debug": { - "version": "4.3.3", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz", - "integrity": "sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==", + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", "requires": { "ms": "2.1.2" } @@ -44929,13 +45176,12 @@ } }, "newspack-scripts": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/newspack-scripts/-/newspack-scripts-3.3.0.tgz", - "integrity": "sha512-aKkgBinpiIA/TVSqYJJyxl3gKCXoOTu0riTAnQ3fLT8pDwoquhPHrjN/CUgkcXi2ScMfFiIUJbUowEJGvBMYDw==", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/newspack-scripts/-/newspack-scripts-3.3.1.tgz", + "integrity": "sha512-gbbHa/4gQ4rkXtNnrxns/RbFt33MoQhQEkX0FzwS7wmqeCq/dpbXSrgIEr3wjEfscTvLWMJ+oXUgOCpM6w5yqg==", "dev": true, "requires": { "@automattic/calypso-build": "^10.0.0", - "@babel/eslint-parser": "^7.16.3", "@babel/preset-env": "^7.16.4", "@commitlint/cli": "^15.0.0", "@commitlint/config-conventional": "^15.0.0", @@ -44944,6 +45190,7 @@ "@testing-library/jest-dom": "^5.15.1", "@testing-library/react": "^12.1.2", "@types/wordpress__data": "^4.6.10", + "@typescript-eslint/parser": "^5.26.0", "@wordpress/a11y": "^3.2.4", "@wordpress/api-fetch": "^5.2.6", "@wordpress/base-styles": "^4.0.4", @@ -45071,18 +45318,6 @@ "@typescript-eslint/utils": "5.10.2" } }, - "@typescript-eslint/parser": { - "version": "5.10.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.10.2.tgz", - "integrity": "sha512-JaNYGkaQVhP6HNF+lkdOr2cAs2wdSZBoalE22uYWq8IEv/OVH0RksSGydk+sW8cLoSeYmC+OHvRyv2i4AQ7Czg==", - "dev": true, - "requires": { - "@typescript-eslint/scope-manager": "5.10.2", - "@typescript-eslint/types": "5.10.2", - "@typescript-eslint/typescript-estree": "5.10.2", - "debug": "^4.3.2" - } - }, "@typescript-eslint/type-utils": { "version": "5.10.2", "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.10.2.tgz", diff --git a/package.json b/package.json index 7e465fd8..3c91fee5 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@rushstack/eslint-patch": "^1.1.3", "eslint": "^7.32.0", "lint-staged": "^12.4.1", - "newspack-scripts": "^3.3.0", + "newspack-scripts": "^3.3.1", "postcss": "^8.4.14", "prettier": "npm:wp-prettier@^2.2.1-beta-1", "stylelint": "^13.13.1" From f3fc14f0b9bcfd1f2d9d44f8450733a607d06fbb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 May 2022 06:16:30 +0000 Subject: [PATCH 6/7] chore(deps-dev): bump lint-staged from 12.4.1 to 12.4.2 Bumps [lint-staged](https://github.com/okonet/lint-staged) from 12.4.1 to 12.4.2. - [Release notes](https://github.com/okonet/lint-staged/releases) - [Commits](https://github.com/okonet/lint-staged/compare/v12.4.1...v12.4.2) --- updated-dependencies: - dependency-name: lint-staged dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index b54fd6e1..8035b2e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "devDependencies": { "@rushstack/eslint-patch": "^1.1.3", "eslint": "^7.32.0", - "lint-staged": "^12.4.1", + "lint-staged": "^12.4.2", "newspack-scripts": "^3.3.1", "postcss": "^8.4.14", "prettier": "npm:wp-prettier@^2.2.1-beta-1", @@ -16597,9 +16597,9 @@ "integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=" }, "node_modules/lint-staged": { - "version": "12.4.1", - "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-12.4.1.tgz", - "integrity": "sha512-PTXgzpflrQ+pODQTG116QNB+Q6uUTDg5B5HqGvNhoQSGt8Qy+MA/6zSnR8n38+sxP5TapzeQGTvoKni0KRS8Vg==", + "version": "12.4.2", + "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-12.4.2.tgz", + "integrity": "sha512-JAJGIzY/OioIUtrRePr8go6qUxij//mL+RGGoFKU3VWQRtIHgWoHizSqH0QVn2OwrbXS9Q6CICQjfj+E5qvrXg==", "dev": true, "dependencies": { "cli-truncate": "^3.1.0", @@ -43827,9 +43827,9 @@ "integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=" }, "lint-staged": { - "version": "12.4.1", - "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-12.4.1.tgz", - "integrity": "sha512-PTXgzpflrQ+pODQTG116QNB+Q6uUTDg5B5HqGvNhoQSGt8Qy+MA/6zSnR8n38+sxP5TapzeQGTvoKni0KRS8Vg==", + "version": "12.4.2", + "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-12.4.2.tgz", + "integrity": "sha512-JAJGIzY/OioIUtrRePr8go6qUxij//mL+RGGoFKU3VWQRtIHgWoHizSqH0QVn2OwrbXS9Q6CICQjfj+E5qvrXg==", "dev": true, "requires": { "cli-truncate": "^3.1.0", diff --git a/package.json b/package.json index 3c91fee5..611a1a15 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "devDependencies": { "@rushstack/eslint-patch": "^1.1.3", "eslint": "^7.32.0", - "lint-staged": "^12.4.1", + "lint-staged": "^12.4.2", "newspack-scripts": "^3.3.1", "postcss": "^8.4.14", "prettier": "npm:wp-prettier@^2.2.1-beta-1", From 877b71b9fc2a4067920766e22086a8078c562e10 Mon Sep 17 00:00:00 2001 From: Derrick Koo Date: Mon, 30 May 2022 11:24:23 -0600 Subject: [PATCH 7/7] fix: restore Related Content settings section, but only if Jetpack Related Posts is on (#263) --- includes/class-settings.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/includes/class-settings.php b/includes/class-settings.php index 48c71eaf..4fff8c47 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -50,6 +50,14 @@ public static function get_sections() { ]; } + // If Related Posts is on, add a section for it. + if ( class_exists( 'Jetpack_RelatedPosts' ) ) { + $sections['related'] = [ + 'slug' => 'newspack_listings_related_settings', + 'title' => __( 'Related Content Settings', 'newspack-listings' ), + ]; + } + return $sections; }