Changeset 13913 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins-2024/inc/block-config.php
- Timestamp:
- 07/22/2024 05:56:46 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins-2024/inc/block-config.php
r13903 r13913 5 5 6 6 namespace WordPressdotorg\Theme\Plugins_2024\Block_Config; 7 8 use WordPressdotorg\Plugin_Directory\Tools; 7 9 8 10 add_filter( 'wporg_block_navigation_menus', __NAMESPACE__ . '\add_site_navigation_menus' ); … … 12 14 add_filter( 'wporg_query_filter_in_form', __NAMESPACE__ . '\wporg_query_filter_in_form' ); 13 15 add_filter( 'wporg_query_total_label', __NAMESPACE__ . '\wporg_query_total_label', 10, 2 ); 16 add_filter( 'wporg_favorite_button_settings', __NAMESPACE__ . '\get_favorite_settings', 10, 2 ); 14 17 add_filter( 'render_block_core/search', __NAMESPACE__ . '\filter_search_block' ); 15 18 add_filter( 'render_block_core/site-title', __NAMESPACE__ . '\filter_site_title_block' ); … … 34 37 'label' => __( 'My favorites', 'wporg-plugins' ), 35 38 'url' => '/browse/favorites/', 36 'className' => 'has-separator' 39 'className' => 'has-separator', 37 40 ), 38 41 ), … … 249 252 250 253 /** 254 * Configure the favorite button. 255 * 256 * @param array $settings Array of settings for this filter. 257 * @param int $post_id The current post ID. 258 * 259 * @return array|bool Settings array. 260 */ 261 function get_favorite_settings( $settings, $post_id ) { 262 return array( 263 'is_favorite' => Tools::favorited_plugin( $post_id ), 264 'add_callback' => function( $_post_id ) { 265 $result = (bool) Tools::favorite_plugin( $_post_id, get_current_user_id(), true ); 266 // `favorite_plugin` can return false for a number of reasons (not logged in, no plugin found, ) 267 if ( ! $result ) { 268 return new \WP_Error( 'favorite-error', 'Plugin could not be favorited.' ); 269 } 270 return $result; 271 }, 272 'delete_callback' => function( $_post_id ) { 273 $result = (bool) Tools::favorite_plugin( $_post_id, get_current_user_id(), false ); 274 // `favorite_plugin` can return false for a number of reasons (not logged in, no plugin found, ) 275 if ( ! $result ) { 276 return new \WP_Error( 'unfavorite-error', 'Plugin could not be unfavorited.' ); 277 } 278 return $result; 279 }, 280 ); 281 } 282 283 /** 251 284 * Filters the search block to remove the required attribute, and add the query fields. 252 285 *
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)