From c618804aefb19069e1ecd6a0a0c8b3f56d6838e6 Mon Sep 17 00:00:00 2001 From: Nathan Schmidt <91974372+nathan-schmidt-viget@users.noreply.github.com> Date: Fri, 1 Mar 2024 11:54:04 -0700 Subject: [PATCH] [#495] pulling in the created pages into the new nav --- .../blocks/nonprofit-navigation/block.json | 13 ---- .../blocks/nonprofit-navigation/block.php | 23 ------ .../blocks/nonprofit-navigation/render.php | 15 ---- .../src/classes/Frontend/Patterns.php | 12 ---- .../goodbids/src/classes/Network/Sites.php | 70 +++++++++++++++---- .../views/parts/nonprofit-navigation.php | 14 ++++ .../views/patterns/nonprofit-navigation.php | 17 ----- themes/goodbids-main/functions.php | 11 --- .../patterns/header-nonprofit.php | 3 +- 9 files changed, 71 insertions(+), 107 deletions(-) delete mode 100644 client-mu-plugins/goodbids/blocks/nonprofit-navigation/block.json delete mode 100644 client-mu-plugins/goodbids/blocks/nonprofit-navigation/block.php delete mode 100644 client-mu-plugins/goodbids/blocks/nonprofit-navigation/render.php create mode 100644 client-mu-plugins/goodbids/views/parts/nonprofit-navigation.php delete mode 100644 client-mu-plugins/goodbids/views/patterns/nonprofit-navigation.php diff --git a/client-mu-plugins/goodbids/blocks/nonprofit-navigation/block.json b/client-mu-plugins/goodbids/blocks/nonprofit-navigation/block.json deleted file mode 100644 index 9a90082de..000000000 --- a/client-mu-plugins/goodbids/blocks/nonprofit-navigation/block.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "nonprofit-navigation", - "title": "Nonprofit Navigation", - "description": "Displays the Nonprofit Navigation", - "icon": "admin-links", - "textdomain": "goodbids", - "acf": { - "mode": "preview" - }, - "supports": { - "jsx": false - } -} diff --git a/client-mu-plugins/goodbids/blocks/nonprofit-navigation/block.php b/client-mu-plugins/goodbids/blocks/nonprofit-navigation/block.php deleted file mode 100644 index 364414ffb..000000000 --- a/client-mu-plugins/goodbids/blocks/nonprofit-navigation/block.php +++ /dev/null @@ -1,23 +0,0 @@ - - - - - diff --git a/client-mu-plugins/goodbids/src/classes/Frontend/Patterns.php b/client-mu-plugins/goodbids/src/classes/Frontend/Patterns.php index ab9ad8663..9dd6937f4 100644 --- a/client-mu-plugins/goodbids/src/classes/Frontend/Patterns.php +++ b/client-mu-plugins/goodbids/src/classes/Frontend/Patterns.php @@ -108,17 +108,6 @@ function (): void { 'inserter' => true, ]; - $nonprofit_navigation = [ - 'name' => 'nonprofit-navigation', - 'path' => goodbids()->get_view_path( 'patterns/nonprofit-navigation.php' ), - 'title' => __( 'Nonprofit Navigation', 'goodbids' ), - 'description' => _x( 'Default Nonprofit Navigation', 'Block pattern description', 'goodbids' ), - 'categories' => [ 'goodbids' ], - 'keywords' => [ 'navigation' ], - 'source' => 'plugin', - 'inserter' => true, - ]; - $section_sidebar_chapters = [ 'name' => 'section-sidebar-chapters', 'path' => goodbids()->get_view_path( 'patterns/section-sidebar-chapters.php' ), @@ -178,7 +167,6 @@ function (): void { $hero_banner, $logo_grid, $nonprofit_interest_form, - $nonprofit_navigation, $section_sidebar_chapters, $template_about, $template_auction, diff --git a/client-mu-plugins/goodbids/src/classes/Network/Sites.php b/client-mu-plugins/goodbids/src/classes/Network/Sites.php index 504a1adee..d9a15d210 100644 --- a/client-mu-plugins/goodbids/src/classes/Network/Sites.php +++ b/client-mu-plugins/goodbids/src/classes/Network/Sites.php @@ -17,6 +17,7 @@ use WP_Block_Type_Registry; use WP_Post; use WP_Site; +use WP_Query; /** * Network Sites Class @@ -31,6 +32,18 @@ class Sites { */ const ALL_AUCTIONS_TRANSIENT = '_goodbids_all_auctions'; + /** + * @since 1.0.0 + * @var array + */ + const ABOUT_OPTION = 'gb_about_page'; + + /** + * @since 1.0.0 + * @var array + */ + const AUCTIONS_OPTION = 'gb_auctions_page'; + /** * @since 1.0.0 */ @@ -63,6 +76,8 @@ public function __construct() { // Refresh transients when Auctions change status. $this->maybe_clear_transients(); + + $this->set_nonprofit_navigation(); } /** @@ -393,6 +408,8 @@ function (): void { if ( is_wp_error( $about_id ) ) { Log::error( $about_id->get_error_message() ); } + + update_option( self::ABOUT_OPTION, $about_id ); } ); } @@ -433,6 +450,8 @@ function (): void { if ( is_wp_error( $auctions_id ) ) { Log::error( $auctions_id->get_error_message() ); } + + update_option( self::AUCTIONS_OPTION, $auctions_id ); } ); } @@ -1084,24 +1103,45 @@ private function get_page_path( string $path ): ?WP_Post { /** - * Return the nonprofit navigation + * Set the nonprofit navigation * - * @return array + * @return void * * @since 1.0.0 */ - public function get_nonprofit_navigation(): array { - return [ - [ - 'label' => 'Explore Auctions', - 'ID' => 4, - 'url' => '/explore-auctions', - ], - [ - 'label' => 'About GOODBIDS', - 'ID' => 3, - 'url' => '/about', - ], - ]; + public function set_nonprofit_navigation(): void { + add_action( + 'goodbids_nonprofit_verified', + function ( int $site_id ): void { + $about_id = get_option( self::ABOUT_OPTION ); + $auctions_id = get_option( self::AUCTIONS_OPTION ); + $wp_navigation = new WP_Query( + [ + 'post_type' => 'wp_navigation', + 'post_status' => [ 'publish' ], + ] + ); + $nav_links = [ + get_post( $about_id ), + get_post( $auctions_id ), + ]; + + + ob_start(); + goodbids()->load_view( 'parts/nonprofit-navigation.php', compact( 'nav_links' ) ); + + $navigation_content = [ + 'ID' => $wp_navigation->posts[0]->ID, + 'post_content' => ob_get_clean(), + ]; + + // Update the navigation into the database + wp_update_post( $navigation_content ); + + if ( is_wp_error( $navigation_content ) ) { + Log::error( $navigation_content->get_error_message() ); + } + } + ); } } diff --git a/client-mu-plugins/goodbids/views/parts/nonprofit-navigation.php b/client-mu-plugins/goodbids/views/parts/nonprofit-navigation.php new file mode 100644 index 000000000..d51ac79ea --- /dev/null +++ b/client-mu-plugins/goodbids/views/parts/nonprofit-navigation.php @@ -0,0 +1,14 @@ + + + + + diff --git a/client-mu-plugins/goodbids/views/patterns/nonprofit-navigation.php b/client-mu-plugins/goodbids/views/patterns/nonprofit-navigation.php deleted file mode 100644 index ceaf0408e..000000000 --- a/client-mu-plugins/goodbids/views/patterns/nonprofit-navigation.php +++ /dev/null @@ -1,17 +0,0 @@ -sites->get_nonprofit_navigation(); -?> - - - - - - - diff --git a/themes/goodbids-main/functions.php b/themes/goodbids-main/functions.php index 1ace9e69b..1f7e9c393 100644 --- a/themes/goodbids-main/functions.php +++ b/themes/goodbids-main/functions.php @@ -209,14 +209,3 @@ function goodbids_main_pattern_categories() { * Disable remote block patterns. */ add_filter( 'should_load_remote_block_patterns', '__return_false' ); - - -function register_home_link_block_as_navigation_last_child( $hooked_blocks, $position, $anchor_block, $context ) { - if ( $anchor_block === 'core/navigation' && $position === 'last_child' ) { - $hooked_blocks[] = 'core/loginout'; - } - - return $hooked_blocks; -} - -add_filter( 'hooked_block_types', 'register_home_link_block_as_navigation_last_child', 10, 4 ); diff --git a/themes/goodbids-nonprofit/patterns/header-nonprofit.php b/themes/goodbids-nonprofit/patterns/header-nonprofit.php index 60cfb564e..c62a1e31a 100644 --- a/themes/goodbids-nonprofit/patterns/header-nonprofit.php +++ b/themes/goodbids-nonprofit/patterns/header-nonprofit.php @@ -21,7 +21,8 @@