@@ -74,6 +74,8 @@ public function __construct( Friends $friends ) {
74
74
* Register the WordPress hooks
75
75
*/
76
76
private function register_hooks () {
77
+ register_theme_directory ( __DIR__ . '/../themes ' );
78
+
77
79
add_filter ( 'pre_get_posts ' , array ( $ this , 'friend_posts_query ' ), 2 );
78
80
add_filter ( 'post_type_link ' , array ( $ this , 'friend_post_link ' ), 10 , 2 );
79
81
add_filter ( 'friends_header_widget_title ' , array ( $ this , 'header_widget_title ' ) );
@@ -100,6 +102,8 @@ private function register_hooks() {
100
102
add_action ( 'the_post ' , array ( $ this , 'the_post ' ), 10 , 2 );
101
103
add_action ( 'parse_query ' , array ( $ this , 'parse_query ' ) );
102
104
add_filter ( 'body_class ' , array ( $ this , 'add_body_class ' ) );
105
+ add_filter ( 'stylesheet ' , array ( $ this , 'stylesheet ' ) );
106
+ add_filter ( 'block_type_metadata_settings ' , array ( $ this , 'block_type_metadata_settings ' ), 15 );
103
107
104
108
add_filter ( 'friends_override_author_name ' , array ( $ this , 'override_author_name ' ), 10 , 3 );
105
109
}
@@ -284,11 +288,61 @@ public function parse_query( $query ) {
284
288
public function add_body_class ( $ classes ) {
285
289
if ( $ this ->friends ->on_frontend () ) {
286
290
$ classes [] = 'friends-page ' ;
291
+ $ classes [] = 'off-canvas ' ;
292
+ $ classes [] = 'off-canvas-sidebar-show ' ;
287
293
}
288
294
289
295
return $ classes ;
290
296
}
291
297
298
+ public function stylesheet ( $ stylesheet ) {
299
+ if ( ! Friends::on_frontend () ) {
300
+ return $ stylesheet ;
301
+ }
302
+
303
+ return 'friends ' ;
304
+ }
305
+
306
+ public function block_type_metadata_settings ( $ settings ) {
307
+ if ( ! Friends::on_frontend () || ! isset ( $ settings ['name ' ] ) ) {
308
+ return $ settings ;
309
+ }
310
+ if ( 'core/post-author-name ' === $ settings ['name ' ] ) {
311
+ $ settings ['render_callback ' ] = function ( $ attributes , $ content , $ block ) {
312
+ if ( isset ( $ block ->context ['postId ' ] ) ) {
313
+ $ author = User::get_post_author ( get_post ( $ block ->context ['postId ' ] ) );
314
+ } else {
315
+ return '' ;
316
+ }
317
+ if ( empty ( $ author ) ) {
318
+ return '' ;
319
+ }
320
+
321
+ $ author_name = $ author ->display_name ;
322
+ $ override_author_name = apply_filters ( 'friends_override_author_name ' , '' , $ author_name , $ block ->context ['postId ' ] );
323
+ if ( isset ( $ attributes ['isLink ' ] ) && $ attributes ['isLink ' ] ) {
324
+ $ author_name = sprintf ( '<a href="%1$s" target="%2$s" class="wp-block-post-author-name__link">%3$s</a> ' , $ author ->get_local_friends_page_url (), esc_attr ( $ attributes ['linkTarget ' ] ), $ author_name );
325
+ }
326
+
327
+ if ( $ override_author_name && trim ( str_replace ( $ override_author_name , '' , $ author_name ) ) === $ author_name ) {
328
+ $ author_name .= ' – ' . esc_html ( $ override_author_name );
329
+ }
330
+
331
+ $ classes = array ();
332
+ if ( isset ( $ attributes ['textAlign ' ] ) ) {
333
+ $ classes [] = 'has-text-align- ' . $ attributes ['textAlign ' ];
334
+ }
335
+ if ( isset ( $ attributes ['style ' ]['elements ' ]['link ' ]['color ' ]['text ' ] ) ) {
336
+ $ classes [] = 'has-link-color ' ;
337
+ }
338
+ $ wrapper_attributes = get_block_wrapper_attributes ( array ( 'class ' => implode ( ' ' , $ classes ) ) );
339
+
340
+ return sprintf ( '<div %1$s>%2$s</div> ' , $ wrapper_attributes , $ author_name );
341
+ };
342
+ }
343
+ return $ settings ;
344
+ }
345
+
292
346
/**
293
347
* Gets the minimal query variables.
294
348
*
@@ -801,6 +855,9 @@ public function template_override( $template ) {
801
855
return Friends::template_loader ()->get_template_part ( $ this ->template , null , $ args , false );
802
856
}
803
857
858
+ if ( wp_is_block_theme () ) {
859
+ return $ template ;
860
+ }
804
861
if ( isset ( $ _GET ['refresh ' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
805
862
add_filter ( 'notify_about_new_friend_post ' , '__return_false ' , 999 );
806
863
add_filter (
@@ -1283,6 +1340,8 @@ public function friend_posts_query( $query ) {
1283
1340
$ query ->is_friends_page = true ;
1284
1341
$ query ->is_singular = false ;
1285
1342
$ query ->is_single = false ;
1343
+ $ query ->is_category = false ;
1344
+ $ query ->is_archive = false ;
1286
1345
$ query ->queried_object = null ;
1287
1346
$ query ->queried_object_id = null ;
1288
1347
$ post_types = apply_filters ( 'friends_frontend_post_types ' , array () );
0 commit comments