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 39c0b37 commit 6b85bcc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 42 deletions.
89 changes: 51 additions & 38 deletions client-mu-plugins/goodbids/src/classes/Network/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,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 @@ -65,7 +77,7 @@ public function __construct() {
// Refresh transients when Auctions change status.
$this->maybe_clear_transients();

$this->get_nonprofit_navigation();
$this->set_nonprofit_navigation();
}

/**
Expand Down Expand Up @@ -395,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 @@ -435,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 @@ -1044,49 +1060,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(): WP_Query {

$args = [
'post_type' => 'wp_navigation',
'post_status' => [ 'publish' ],
];

$navigation = new WP_Query( array_merge_recursive( $args ) );

$nav_date = [
[
'label' => 'Test Auctions',
'ID' => 4,
'url' => '/explore-auctions',
],
[
'label' => 'About GOODBIDS',
'ID' => 3,
'url' => '/about',
],
];


ob_start();
$links = goodbids()->load_view( 'parts/nonprofit-navigation.php', compact( 'nav_date' ) );

dd( $links );
$my_post = array(
'ID' => $navigation->posts[0]->ID,
'post_content' => ob_get_clean(),
);
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 ),
];

// dd( $my_post );

// // Update the post into the database
// wp_update_post( $my_post );
ob_start();
goodbids()->load_view( 'parts/nonprofit-navigation.php', compact( 'nav_links' ) );

// dd( $navigation->posts[0] );
$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() );
}
}
);
}
}
10 changes: 6 additions & 4 deletions client-mu-plugins/goodbids/views/parts/nonprofit-navigation.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php
/**
* Part for displaying the navigation
* Links for displaying the navigation
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
* @var array $nav_links
*
* @since 1.0.0
* @package GoodBids
*/
?>


<!-- wp:navigation-link {"label":"<?php echo esc_html( $nav_item['label'] ); ?>","type":"page","id":<?php echo esc_html( $nav_item['ID'] ); ?>,"url":"<?php echo esc_url( $nav_item['url'] ); ?>","kind":"post-type"} /-->
<?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; ?>

0 comments on commit 6b85bcc

Please sign in to comment.