Skip to content

Commit

Permalink
Merge pull request #262 from Automattic/alpha
Browse files Browse the repository at this point in the history
Release May 30
  • Loading branch information
dkoo authored May 30, 2022
2 parents 6206fe5 + 31ff037 commit f8a2b9a
Show file tree
Hide file tree
Showing 16 changed files with 351 additions and 1,971 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
168 changes: 0 additions & 168 deletions includes/class-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.
*
Expand Down
13 changes: 0 additions & 13 deletions includes/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use \Newspack_Listings\Core;
use \Newspack_Listings\Products;
use \Newspack_Listings\Settings;
use \Newspack_Listings\Taxonomies;

defined( 'ABSPATH' ) || exit;

Expand Down Expand Up @@ -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;
Expand All @@ -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' ) ],

Expand Down
17 changes: 17 additions & 0 deletions includes/class-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ] );
Expand Down Expand Up @@ -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.
*
Expand Down
28 changes: 8 additions & 20 deletions includes/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -54,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;
}

Expand Down Expand Up @@ -154,22 +158,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.
Expand Down
Loading

0 comments on commit f8a2b9a

Please sign in to comment.