@@ -87,6 +87,8 @@ public function __construct( Friends $friends ) {
87
87
* Register the WordPress hooks
88
88
*/
89
89
private function register_hooks () {
90
+ register_theme_directory ( __DIR__ . '/../themes ' );
91
+
90
92
add_filter ( 'pre_get_posts ' , array ( $ this , 'friend_posts_query ' ), 2 );
91
93
add_filter ( 'post_type_link ' , array ( $ this , 'friend_post_link ' ), 10 , 2 );
92
94
add_filter ( 'friends_header_widget_title ' , array ( $ this , 'header_widget_title ' ) );
@@ -118,6 +120,8 @@ private function register_hooks() {
118
120
add_action ( 'the_post ' , array ( $ this , 'the_post ' ), 10 , 2 );
119
121
add_action ( 'parse_query ' , array ( $ this , 'parse_query ' ) );
120
122
add_filter ( 'body_class ' , array ( $ this , 'add_body_class ' ) );
123
+ add_filter ( 'stylesheet ' , array ( $ this , 'stylesheet ' ) );
124
+ add_filter ( 'block_type_metadata_settings ' , array ( $ this , 'block_type_metadata_settings ' ), 15 );
121
125
122
126
add_filter ( 'friends_override_author_name ' , array ( $ this , 'override_author_name ' ), 10 , 3 );
123
127
add_filter ( 'friends_friend_posts_query_viewable ' , array ( $ this , 'expose_opml ' ), 10 , 2 );
@@ -354,11 +358,61 @@ public function parse_query( $query ) {
354
358
public function add_body_class ( $ classes ) {
355
359
if ( $ this ->friends ->on_frontend () ) {
356
360
$ classes [] = 'friends-page ' ;
361
+ $ classes [] = 'off-canvas ' ;
362
+ $ classes [] = 'off-canvas-sidebar-show ' ;
357
363
}
358
364
359
365
return $ classes ;
360
366
}
361
367
368
+ public function stylesheet ( $ stylesheet ) {
369
+ if ( ! Friends::on_frontend () ) {
370
+ return $ stylesheet ;
371
+ }
372
+
373
+ return 'friends ' ;
374
+ }
375
+
376
+ public function block_type_metadata_settings ( $ settings ) {
377
+ if ( ! Friends::on_frontend () || ! isset ( $ settings ['name ' ] ) ) {
378
+ return $ settings ;
379
+ }
380
+ if ( 'core/post-author-name ' === $ settings ['name ' ] ) {
381
+ $ settings ['render_callback ' ] = function ( $ attributes , $ content , $ block ) {
382
+ if ( isset ( $ block ->context ['postId ' ] ) ) {
383
+ $ author = User::get_post_author ( get_post ( $ block ->context ['postId ' ] ) );
384
+ } else {
385
+ return '' ;
386
+ }
387
+ if ( empty ( $ author ) ) {
388
+ return '' ;
389
+ }
390
+
391
+ $ author_name = $ author ->display_name ;
392
+ $ override_author_name = apply_filters ( 'friends_override_author_name ' , '' , $ author_name , $ block ->context ['postId ' ] );
393
+ if ( isset ( $ attributes ['isLink ' ] ) && $ attributes ['isLink ' ] ) {
394
+ $ 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 );
395
+ }
396
+
397
+ if ( $ override_author_name && trim ( str_replace ( $ override_author_name , '' , $ author_name ) ) === $ author_name ) {
398
+ $ author_name .= ' – ' . esc_html ( $ override_author_name );
399
+ }
400
+
401
+ $ classes = array ();
402
+ if ( isset ( $ attributes ['textAlign ' ] ) ) {
403
+ $ classes [] = 'has-text-align- ' . $ attributes ['textAlign ' ];
404
+ }
405
+ if ( isset ( $ attributes ['style ' ]['elements ' ]['link ' ]['color ' ]['text ' ] ) ) {
406
+ $ classes [] = 'has-link-color ' ;
407
+ }
408
+ $ wrapper_attributes = get_block_wrapper_attributes ( array ( 'class ' => implode ( ' ' , $ classes ) ) );
409
+
410
+ return sprintf ( '<div %1$s>%2$s</div> ' , $ wrapper_attributes , $ author_name );
411
+ };
412
+ }
413
+ return $ settings ;
414
+ }
415
+
362
416
/**
363
417
* Gets the minimal query variables.
364
418
*
@@ -890,7 +944,11 @@ public function template_override( $template ) {
890
944
return Friends::template_loader ()->get_template_part ( $ this ->template , null , $ args , false );
891
945
}
892
946
893
- $ args ['frontend_default_view ' ] = get_user_option ( 'friends_frontend_default_view ' , get_current_user_id () );
947
+ if ( wp_is_block_theme () ) {
948
+ return $ template ;
949
+ }
950
+
951
+ $ args ['frontend_default_view ' ] = get_user_option ( 'friends_frontend_default_view ' , 'expanded ' );
894
952
$ args ['blocks-everywhere ' ] = false ;
895
953
896
954
if ( isset ( $ _GET ['welcome ' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
@@ -1436,6 +1494,8 @@ public function friend_posts_query( $query ) {
1436
1494
$ query ->is_friends_page = true ;
1437
1495
$ query ->is_singular = false ;
1438
1496
$ query ->is_single = false ;
1497
+ $ query ->is_category = false ;
1498
+ $ query ->is_archive = false ;
1439
1499
$ query ->queried_object = null ;
1440
1500
$ query ->queried_object_id = null ;
1441
1501
$ post_types = apply_filters ( 'friends_frontend_post_types ' , array () );
0 commit comments