Skip to content

Commit

Permalink
[#495] pulling in the created pages into the new nav
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-schmidt-viget committed Mar 1, 2024
1 parent 93b801e commit 60eaf24
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 97 deletions.
13 changes: 0 additions & 13 deletions client-mu-plugins/goodbids/blocks/nonprofit-navigation/block.json

This file was deleted.

23 changes: 0 additions & 23 deletions client-mu-plugins/goodbids/blocks/nonprofit-navigation/block.php

This file was deleted.

15 changes: 0 additions & 15 deletions client-mu-plugins/goodbids/blocks/nonprofit-navigation/render.php

This file was deleted.

12 changes: 0 additions & 12 deletions client-mu-plugins/goodbids/src/classes/Frontend/Patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down Expand Up @@ -178,7 +167,6 @@ function (): void {
$hero_banner,
$logo_grid,
$nonprofit_interest_form,
$nonprofit_navigation,
$section_sidebar_chapters,
$template_about,
$template_auction,
Expand Down
72 changes: 56 additions & 16 deletions client-mu-plugins/goodbids/src/classes/Network/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use WP_Block_Type_Registry;
use WP_Post;
use WP_Site;
use WP_Query;

/**
* Network Sites Class
Expand All @@ -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
*/
Expand Down Expand Up @@ -63,6 +76,8 @@ public function __construct() {

// Refresh transients when Auctions change status.
$this->maybe_clear_transients();

$this->set_nonprofit_navigation();
}

/**
Expand Down Expand Up @@ -392,6 +407,8 @@ function (): void {
if ( is_wp_error( $about_id ) ) {
Log::error( $about_id->get_error_message() );
}

update_option( self::ABOUT_OPTION, $about_id );
}
);
}
Expand Down Expand Up @@ -432,6 +449,8 @@ function (): void {
if ( is_wp_error( $auctions_id ) ) {
Log::error( $auctions_id->get_error_message() );
}

update_option( self::AUCTIONS_OPTION, $auctions_id );
}
);
}
Expand Down Expand Up @@ -625,7 +644,6 @@ function () use ( $auction_data ) {
]
)
->all();

}

/**
Expand Down Expand Up @@ -1076,24 +1094,46 @@ 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 post into the database
wp_update_post( $navigation_content );

if ( is_wp_error( $navigation_content ) ) {
Log::error( $navigation_content->get_error_message() );
}
}
);
}
}
14 changes: 14 additions & 0 deletions client-mu-plugins/goodbids/views/parts/nonprofit-navigation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Links for displaying the navigation
*
* @var array $nav_links
*
* @since 1.0.0
* @package GoodBids
*/
?>

<?php foreach ( $nav_links as $nav_link ) : ?>
<!-- wp:navigation-link {"label":"<?php echo esc_attr( $nav_link->post_title ); ?>","type":"<?php echo esc_attr( $nav_link->post_type ); ?>","id":<?php echo esc_attr( $nav_link->ID ); ?>,"url":"/<?php echo esc_attr( $nav_link->post_name ); ?>","kind":"post-type"} /-->
<?php endforeach; ?>
17 changes: 0 additions & 17 deletions client-mu-plugins/goodbids/views/patterns/nonprofit-navigation.php

This file was deleted.

3 changes: 2 additions & 1 deletion themes/goodbids-nonprofit/patterns/header-nonprofit.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
<!-- wp:group {"style":{"spacing":{"blockGap":"var:preset|spacing|20"}},"layout":{"type":"flex","flexWrap":"wrap"}} -->
<div class="wp-block-group">
<!-- wp:pattern {"slug":"goodbids/nonprofit-navigation"} /-->
<!-- wp:navigation {"layout":{"type":"flex","justifyContent":"right","orientation":"horizontal"},"style":{"spacing":{"margin":{"top":"0"},"blockGap":"var:preset|spacing|20"},"layout":{"selfStretch":"fit","flexSize":null}},"fontSize":"x-small"} /-->
<!-- wp:woocommerce/customer-account {"displayStyle":"text_only","iconStyle":"alt","iconClass":"wc-block-customer-account__account-icon","className":"btn","textColor":"contrast","fontSize":"x-small","style":{"layout":{"selfStretch":"fit","flexSize":null},"elements":{"link":{"color":{"text":"var:preset|color|contrast"}}}}} /-->
</div>
<!-- /wp:group -->
</div>
Expand Down

0 comments on commit 60eaf24

Please sign in to comment.