0 ) { $src = wp_get_attachment_image_src( $custom_logo_id, 'full' ); if ( is_array( $src ) && ! empty( $src[0] ) ) { $logo_url = (string) $src[0]; } } return array( 'url' => $home, 'name' => (string) get_bloginfo( 'name' ), 'description' => (string) get_bloginfo( 'description' ), 'logo_url' => $logo_url, 'language' => (string) ( get_bloginfo( 'language' ) ?: 'en-US' ), ); } /** * Per-post fields templates need. * * @param int $post_id Post ID. * @return array|null Post fields or null if post missing. */ public static function post( int $post_id ): ?array { $post = get_post( $post_id ); if ( ! $post ) { return null; } $image_url = null; $thumb_id = get_post_thumbnail_id( $post ); if ( $thumb_id ) { $img = wp_get_attachment_image_url( $thumb_id, 'full' ); if ( $img ) { $image_url = (string) $img; } } return array( 'id' => (int) $post->ID, 'post_type' => (string) $post->post_type, 'url' => (string) get_permalink( $post ), 'title' => (string) get_the_title( $post ), 'excerpt' => (string) get_the_excerpt( $post ), 'content' => (string) $post->post_content, 'date_published' => (string) get_the_date( 'c', $post ), 'date_modified' => (string) get_the_modified_date( 'c', $post ), 'author_name' => (string) get_the_author_meta( 'display_name', (int) $post->post_author ), 'image_url' => $image_url, ); } /** * Best-effort top-level navigation for SiteNavigationElement. * Returns an empty array when no menu is assigned. * * @return array */ public static function navigation_items(): array { $locations = (array) get_nav_menu_locations(); if ( empty( $locations ) ) { return array(); } $menu_id = 0; foreach ( $locations as $id ) { if ( $id ) { $menu_id = (int) $id; break; } } if ( 0 === $menu_id ) { return array(); } $items = wp_get_nav_menu_items( $menu_id ); if ( ! is_array( $items ) ) { return array(); } $out = array(); foreach ( $items as $item ) { if ( ! $item || ! isset( $item->title, $item->url ) ) { continue; } // Top-level only. if ( ! empty( $item->menu_item_parent ) ) { continue; } $name = trim( (string) $item->title ); $url = trim( (string) $item->url ); if ( '' === $name || '' === $url ) { continue; } $out[] = array( 'name' => $name, 'url' => esc_url_raw( $url ), ); } // Cap at 10 to keep the node reasonable. return array_slice( $out, 0, 10 ); } }