diff --git a/includes/class-friends.php b/includes/class-friends.php index 28761942..4b6b387e 100644 --- a/includes/class-friends.php +++ b/includes/class-friends.php @@ -797,7 +797,36 @@ public static function on_frontend() { } $pagename_parts = explode( '/', trim( $pagename, '/' ) ); - return count( $pagename_parts ) > 0 && 'friends' === $pagename_parts[0]; + if ( count( $pagename_parts ) > 0 && 'friends' === $pagename_parts[0] ) { + return true; + } + // phpcs:disable WordPress.Security.NonceVerification.Recommended + // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + if ( implode( '/', array_slice( $pagename_parts, 0, 2 ) ) === 'wp-admin/customize.php' && isset( $_REQUEST['url'] ) ) { + $pagename_parts = explode( '/', trim( str_replace( '://', '', wp_unslash( $_REQUEST['url'] ) ), '/' ) ); + if ( count( $pagename_parts ) > 0 && 'friends' === $pagename_parts[1] ) { + return true; + } + } + + if ( implode( '/', array_slice( $pagename_parts, 0, 2 ) ) === 'wp-admin/site-editor.php' && isset( $_REQUEST['postId'] ) ) { + $pagename_parts = explode( '//', wp_unslash( $_REQUEST['postId'] ) ); + if ( count( $pagename_parts ) > 0 && 'friends' === $pagename_parts[0] ) { + return true; + } + } + // phpcs:enable WordPress.Security.NonceVerification.Recommended + // phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + + if ( implode( '/', array_slice( $pagename_parts, 0, 5 ) ) === 'wp-json/wp/v2/templates/friends' ) { + return true; + } + + if ( implode( '/', array_slice( $pagename_parts, 0, 5 ) ) === 'wp-json/wp/v2/template-parts/friends' ) { + return true; + } + + return false; } /** diff --git a/includes/class-frontend.php b/includes/class-frontend.php index ec0da2ab..0c9c82ec 100644 --- a/includes/class-frontend.php +++ b/includes/class-frontend.php @@ -74,6 +74,8 @@ public function __construct( Friends $friends ) { * Register the WordPress hooks */ private function register_hooks() { + register_theme_directory( __DIR__ . '/../themes' ); + add_filter( 'pre_get_posts', array( $this, 'friend_posts_query' ), 2 ); add_filter( 'post_type_link', array( $this, 'friend_post_link' ), 10, 2 ); add_filter( 'friends_header_widget_title', array( $this, 'header_widget_title' ) ); @@ -100,6 +102,8 @@ private function register_hooks() { add_action( 'the_post', array( $this, 'the_post' ), 10, 2 ); add_action( 'parse_query', array( $this, 'parse_query' ) ); add_filter( 'body_class', array( $this, 'add_body_class' ) ); + add_filter( 'stylesheet', array( $this, 'stylesheet' ) ); + add_filter( 'block_type_metadata_settings', array( $this, 'block_type_metadata_settings' ), 15 ); add_filter( 'friends_override_author_name', array( $this, 'override_author_name' ), 10, 3 ); add_filter( 'friends_friend_posts_query_viewable', array( $this, 'expose_opml' ), 10, 2 ); @@ -291,11 +295,61 @@ public function parse_query( $query ) { public function add_body_class( $classes ) { if ( $this->friends->on_frontend() ) { $classes[] = 'friends-page'; + $classes[] = 'off-canvas'; + $classes[] = 'off-canvas-sidebar-show'; } return $classes; } + public function stylesheet( $stylesheet ) { + if ( ! Friends::on_frontend() ) { + return $stylesheet; + } + + return 'friends'; + } + + public function block_type_metadata_settings( $settings ) { + if ( ! Friends::on_frontend() || ! isset( $settings['name'] ) ) { + return $settings; + } + if ( 'core/post-author-name' === $settings['name'] ) { + $settings['render_callback'] = function ( $attributes, $content, $block ) { + if ( isset( $block->context['postId'] ) ) { + $author = User::get_post_author( get_post( $block->context['postId'] ) ); + } else { + return ''; + } + if ( empty( $author ) ) { + return ''; + } + + $author_name = $author->display_name; + $override_author_name = apply_filters( 'friends_override_author_name', '', $author_name, $block->context['postId'] ); + if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) { + $author_name = sprintf( '%3$s', $author->get_local_friends_page_url(), esc_attr( $attributes['linkTarget'] ), $author_name ); + } + + if ( $override_author_name && trim( str_replace( $override_author_name, '', $author_name ) ) === $author_name ) { + $author_name .= ' – ' . esc_html( $override_author_name ); + } + + $classes = array(); + if ( isset( $attributes['textAlign'] ) ) { + $classes[] = 'has-text-align-' . $attributes['textAlign']; + } + if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) { + $classes[] = 'has-link-color'; + } + $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); + + return sprintf( '
%2$s
', $wrapper_attributes, $author_name ); + }; + } + return $settings; + } + /** * Gets the minimal query variables. * @@ -813,6 +867,10 @@ public function template_override( $template ) { return Friends::template_loader()->get_template_part( $this->template, null, $args, false ); } + if ( wp_is_block_theme() ) { + return $template; + } + $args['frontend_default_view'] = get_option( 'friends_frontend_default_view', 'expanded' ); $args['blocks-everywhere'] = false; @@ -1300,6 +1358,8 @@ public function friend_posts_query( $query ) { $query->is_friends_page = true; $query->is_singular = false; $query->is_single = false; + $query->is_category = false; + $query->is_archive = false; $query->queried_object = null; $query->queried_object_id = null; $post_types = apply_filters( 'friends_frontend_post_types', array() ); diff --git a/themes/friends/parts/footer.html b/themes/friends/parts/footer.html new file mode 100644 index 00000000..64a0a691 --- /dev/null +++ b/themes/friends/parts/footer.html @@ -0,0 +1 @@ +footer diff --git a/themes/friends/parts/header.html b/themes/friends/parts/header.html new file mode 100644 index 00000000..35dbe530 --- /dev/null +++ b/themes/friends/parts/header.html @@ -0,0 +1 @@ + diff --git a/themes/friends/parts/sidebar.html b/themes/friends/parts/sidebar.html new file mode 100644 index 00000000..3ed7b141 --- /dev/null +++ b/themes/friends/parts/sidebar.html @@ -0,0 +1,9 @@ + +

Friends

+ + + + + + + diff --git a/themes/friends/style.css b/themes/friends/style.css new file mode 100644 index 00000000..c73625b0 --- /dev/null +++ b/themes/friends/style.css @@ -0,0 +1,11 @@ +/*! + * Theme Name: Friends + * Theme URI: https://wordpress.org/plugins/friends/ + * Author: akirk + * Author URI: https://alex.kirk.at + * Description: Theme for the Friends Plugin. + * Version: 1.0 + * License: GNU General Public License v2 or later + * License URI: http://www.gnu.org/licenses/gpl-2.0.html + * Text Domain: friends +*/ diff --git a/themes/friends/templates/index.html b/themes/friends/templates/index.html new file mode 100644 index 00000000..39784922 --- /dev/null +++ b/themes/friends/templates/index.html @@ -0,0 +1,17 @@ + +
+
+ + + +
+ + +
+ +
+ + +
+
+ diff --git a/themes/friends/theme.json b/themes/friends/theme.json new file mode 100644 index 00000000..163f7205 --- /dev/null +++ b/themes/friends/theme.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://schemas.wp.org/trunk/theme.json", + "version": 3, + "settings": { + "appearanceTools": true + }, + "styles": { + "color": { + "background": "var(--wp--preset--color--base)", + "text": "var(--wp--preset--color--contrast)" + } + + }, + "templateParts": [ + { + "area": "header", + "name": "header", + "title": "Header" + }, + { + "area": "footer", + "name": "footer", + "title": "Footer" + }, + { + "area": "uncategorized", + "name": "sidebar", + "title": "Sidebar" + } + ] +}