$path, 'post_id' => (int) $post_id, 'title' => $title, ); }; $front = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; $add( home_url( '/' ), $front, __( 'Homepage', 'accesswell' ) ); $blog = (int) get_option( 'page_for_posts' ); if ( $blog ) { $add( get_permalink( $blog ), $blog, get_the_title( $blog ) ); } $ids = get_posts( array( 'post_type' => Accesswell_Settings::post_types(), 'post_status' => 'publish', 'posts_per_page' => $max, 'orderby' => 'modified', 'order' => 'DESC', 'fields' => 'ids', 'has_password' => false, 'suppress_filters' => true, ) ); foreach ( $ids as $id ) { if ( count( $out ) >= $max ) { break; } $add( get_permalink( $id ), $id, get_the_title( $id ) ); } return array_slice( $out, 0, $max ); } /** * Path of a site address relative to the home address, or null. * * @param string $url Address. * @return string|null */ public static function path_of( $url ) { $home = wp_parse_url( home_url( '/' ) ); $part = wp_parse_url( (string) $url ); if ( empty( $part['host'] ) || strtolower( $part['host'] ) !== strtolower( $home['host'] ) ) { return null; } $home_path = trailingslashit( isset( $home['path'] ) ? $home['path'] : '/' ); $path = isset( $part['path'] ) ? $part['path'] : '/'; if ( 0 === strpos( trailingslashit( $path ), $home_path ) ) { $path = '/' . ltrim( substr( $path, strlen( $home_path ) ), '/' ); } return $path . ( isset( $part['query'] ) ? '?' . $part['query'] : '' ); } }