@@ -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
add_filter ( 'friends_friend_posts_query_viewable ' , array ( $ this , 'expose_opml ' ), 10 , 2 );
@@ -291,11 +295,61 @@ public function parse_query( $query ) {
291
295
public function add_body_class ( $ classes ) {
292
296
if ( $ this ->friends ->on_frontend () ) {
293
297
$ classes [] = 'friends-page ' ;
298
+ $ classes [] = 'off-canvas ' ;
299
+ $ classes [] = 'off-canvas-sidebar-show ' ;
294
300
}
295
301
296
302
return $ classes ;
297
303
}
298
304
305
+ public function stylesheet ( $ stylesheet ) {
306
+ if ( ! Friends::on_frontend () ) {
307
+ return $ stylesheet ;
308
+ }
309
+
310
+ return 'friends ' ;
311
+ }
312
+
313
+ public function block_type_metadata_settings ( $ settings ) {
314
+ if ( ! Friends::on_frontend () || ! isset ( $ settings ['name ' ] ) ) {
315
+ return $ settings ;
316
+ }
317
+ if ( 'core/post-author-name ' === $ settings ['name ' ] ) {
318
+ $ settings ['render_callback ' ] = function ( $ attributes , $ content , $ block ) {
319
+ if ( isset ( $ block ->context ['postId ' ] ) ) {
320
+ $ author = User::get_post_author ( get_post ( $ block ->context ['postId ' ] ) );
321
+ } else {
322
+ return '' ;
323
+ }
324
+ if ( empty ( $ author ) ) {
325
+ return '' ;
326
+ }
327
+
328
+ $ author_name = $ author ->display_name ;
329
+ $ override_author_name = apply_filters ( 'friends_override_author_name ' , '' , $ author_name , $ block ->context ['postId ' ] );
330
+ if ( isset ( $ attributes ['isLink ' ] ) && $ attributes ['isLink ' ] ) {
331
+ $ 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 );
332
+ }
333
+
334
+ if ( $ override_author_name && trim ( str_replace ( $ override_author_name , '' , $ author_name ) ) === $ author_name ) {
335
+ $ author_name .= ' – ' . esc_html ( $ override_author_name );
336
+ }
337
+
338
+ $ classes = array ();
339
+ if ( isset ( $ attributes ['textAlign ' ] ) ) {
340
+ $ classes [] = 'has-text-align- ' . $ attributes ['textAlign ' ];
341
+ }
342
+ if ( isset ( $ attributes ['style ' ]['elements ' ]['link ' ]['color ' ]['text ' ] ) ) {
343
+ $ classes [] = 'has-link-color ' ;
344
+ }
345
+ $ wrapper_attributes = get_block_wrapper_attributes ( array ( 'class ' => implode ( ' ' , $ classes ) ) );
346
+
347
+ return sprintf ( '<div %1$s>%2$s</div> ' , $ wrapper_attributes , $ author_name );
348
+ };
349
+ }
350
+ return $ settings ;
351
+ }
352
+
299
353
/**
300
354
* Gets the minimal query variables.
301
355
*
@@ -813,6 +867,10 @@ public function template_override( $template ) {
813
867
return Friends::template_loader ()->get_template_part ( $ this ->template , null , $ args , false );
814
868
}
815
869
870
+ if ( wp_is_block_theme () ) {
871
+ return $ template ;
872
+ }
873
+
816
874
$ args ['frontend_default_view ' ] = get_option ( 'friends_frontend_default_view ' , 'expanded ' );
817
875
$ args ['blocks-everywhere ' ] = false ;
818
876
@@ -1300,6 +1358,8 @@ public function friend_posts_query( $query ) {
1300
1358
$ query ->is_friends_page = true ;
1301
1359
$ query ->is_singular = false ;
1302
1360
$ query ->is_single = false ;
1361
+ $ query ->is_category = false ;
1362
+ $ query ->is_archive = false ;
1303
1363
$ query ->queried_object = null ;
1304
1364
$ query ->queried_object_id = null ;
1305
1365
$ post_types = apply_filters ( 'friends_frontend_post_types ' , array () );
0 commit comments