Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Remove the Favorite API & block, use shared block
  • Loading branch information
ryelle committed Jul 2, 2024
commit a416354c49205283ed84b4f08a402a7d65ce6e96
2 changes: 0 additions & 2 deletions source/wp-content/themes/wporg-themes-2024/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
require_once( __DIR__ . '/inc/block-config.php' );
require_once( __DIR__ . '/inc/embed.php' );
require_once( __DIR__ . '/inc/i18n.php' );
require_once( __DIR__ . '/inc/rest-api.php' );
require_once( __DIR__ . '/inc/seo-social-meta.php' );

// Block files
require_once( __DIR__ . '/src/business-model-notice/index.php' );
require_once( __DIR__ . '/src/child-theme-notice/index.php' );
require_once( __DIR__ . '/src/favorite-button/index.php' );
require_once( __DIR__ . '/src/meta-list/index.php' );
require_once( __DIR__ . '/src/ratings-bars/index.php' );
require_once( __DIR__ . '/src/ratings-stars/index.php' );
Expand Down
38 changes: 37 additions & 1 deletion source/wp-content/themes/wporg-themes-2024/inc/block-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use WP_HTML_Tag_Processor, WP_Block_Supports;
use const WordPressdotorg\Theme\Theme_Directory_2024\THEME_POST_TYPE;
use function WordPressdotorg\Theme\Theme_Directory_2024\{ get_query_tags, wporg_themes_get_feature_list };
use function WordPressdotorg\Theme\Theme_Directory_2024\{ get_query_tags, get_theme_information, wporg_themes_get_feature_list };
use function WordPressdotorg\Theme\Theme_Directory_2024\SEO_Social_Meta\{get_archive_title};

add_filter( 'wporg_query_total_label', __NAMESPACE__ . '\update_query_total_label', 10, 2 );
Expand All @@ -16,6 +16,7 @@
add_filter( 'wporg_query_filter_options_subjects', __NAMESPACE__ . '\get_subjects_options' );
add_action( 'wporg_query_filter_in_form', __NAMESPACE__ . '\inject_other_filters', 10, 2 );
add_filter( 'wporg_block_navigation_menus', __NAMESPACE__ . '\add_site_navigation_menus' );
add_filter( 'wporg_favorite_button_settings', __NAMESPACE__ . '\get_favorite_settings', 10, 2 );
add_filter( 'render_block_wporg/link-wrapper', __NAMESPACE__ . '\inject_permalink_link_wrapper' );
add_filter( 'render_block_wporg/language-suggest', __NAMESPACE__ . '\inject_language_suggest_endpoint' );
add_filter( 'render_block_core/search', __NAMESPACE__ . '\inject_browse_search_block' );
Expand Down Expand Up @@ -240,6 +241,41 @@ function add_site_navigation_menus( $menus ) {
);
}

/**
* Configure the favorite button.
*
* @param array $settings Array of settings for this filter.
* @param int $post_id The current post ID.
*
* @return array|bool Settings array or false if not a theme.
*/
function get_favorite_settings( $settings, $post_id ) {
$theme_post = get_theme_information( $post_id );
if ( ! $theme_post ) {
return false;
}

return array(
'is_favorite' => wporg_themes_is_favourited( $theme_post->slug ),
'add_callback' => function( $post_id ) {
$theme_post = get_theme_information( $post_id );
if ( ! $theme_post ) {
return new \WP_Error( 'theme-not-found', 'Theme not found.' );
}

return wporg_themes_add_favorite( $theme_post->slug );
},
'delete_callback' => function( $post_id ) {
$theme_post = get_theme_information( $post_id );
if ( ! $theme_post ) {
return new \WP_Error( 'theme-not-found', 'Theme not found.' );
}

return wporg_themes_remove_favorite( $theme_post->slug );
},
);
}

/**
* Update the link in `wporg/link-wrapper` to use the current post permalink.
*
Expand Down
77 changes: 0 additions & 77 deletions source/wp-content/themes/wporg-themes-2024/inc/rest-api.php

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.