Skip to content

Commit

Permalink
[#495] Some fixes/adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
bd-viget authored and nathan-schmidt-viget committed Mar 6, 2024
1 parent 0eae952 commit 387c02f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
26 changes: 15 additions & 11 deletions client-mu-plugins/goodbids/src/classes/Network/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,6 @@ private function get_page_path( string $path ): ?WP_Post {
return get_page_by_path( $path ); // phpcs:ignore
}


/**
* Set the nonprofit navigation
*
Expand All @@ -1115,14 +1114,16 @@ private function get_page_path( string $path ): ?WP_Post {
* @since 1.0.0
*/
public function set_nonprofit_navigation(): void {
// TODO: Figure out why it does not fire on setup
add_action(
'goodbids_initialize_site',
function (): void {
$about_id = get_option( self::ABOUT_OPTION );
$auctions_id = get_option( self::AUCTIONS_OPTION );
$nav_links = [
intval( get_option( self::ABOUT_OPTION ) ), // About Page ID.
intval( get_option( self::AUCTIONS_OPTION ) ), // Auctions Page ID.
];

if ( ! $about_id && ! $auctions_id ) {
if ( 2 !== count( array_filter( $nav_links ) ) ) {
Log::warning( 'Missing one or more Nonprofit Navigation items' );
return;
}

Expand All @@ -1133,17 +1134,19 @@ function (): void {
]
);

$nav_links = [
get_post( $about_id ),
get_post( $auctions_id ),
];
if ( ! $wp_navigation->have_posts() ) {
Log::error( 'Unable to locate Nonprofit Navigation' );
return;
}

$navigation_id = $wp_navigation->posts[0]->ID;

// Set the navigation content
ob_start();
goodbids()->load_view( 'parts/nonprofit-navigation.php', compact( 'nav_links' ) );

$navigation_content = [
'ID' => $wp_navigation->post->ID,
'ID' => $navigation_id,
'post_content' => ob_get_clean(),
];

Expand All @@ -1153,7 +1156,8 @@ function (): void {
if ( is_wp_error( $update ) ) {
Log::error( 'Error updating Nonprofit Navigation: ' . $update->get_error_message() );
}
}
},
50
);
}
}
13 changes: 7 additions & 6 deletions client-mu-plugins/goodbids/views/parts/nonprofit-navigation.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php
/**
* Links for displaying the navigation
* Links for displaying the default navigation
*
* @var array $nav_links
* @var int[] $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; ?>
foreach ( $nav_links as $page_id ) :
?>
<!-- wp:navigation-link {"label":"<?php echo esc_attr( get_the_title( $page_id ) ); ?>","type":"<?php echo esc_attr( get_post_type( $page_id ) ); ?>","id":<?php echo esc_attr( $page_id ); ?>,"url":"/<?php echo esc_attr( get_post_field( 'post_name', $page_id, 'edit' ) ); ?>","kind":"post-type"} /-->
<?php
endforeach;

0 comments on commit 387c02f

Please sign in to comment.