get( 'Version' ) ); // Enqueue theme stylesheet. wp_enqueue_style( 'benday-style' ); } endif; add_action( 'wp_enqueue_scripts', 'benday_styles' ); if ( ! function_exists( 'benday_register_icons' ) ) : /** * Registers the theme icons so they can be picked in the Icon block. * * @since Benday 1.0 * @return void */ function benday_register_icons() { if ( ! function_exists( 'wp_register_icon_collection' ) ) { return; } wp_register_icon_collection( 'benday', array( 'label' => __( 'Benday', 'benday' ), ) ); $icons = array( 'arrow' => __( 'Arrow', 'benday' ), 'clock' => __( 'Clock', 'benday' ), 'dots' => __( 'Dots', 'benday' ), 'update' => __( 'Update', 'benday' ), 'folder' => __( 'Folder', 'benday' ), 'plus' => __( 'Plus', 'benday' ), 'user' => __( 'User', 'benday' ), 'site-title-detail' => __( 'Site title detail', 'benday' ), ); foreach ( $icons as $slug => $label ) { wp_register_icon( 'benday/' . $slug, array( 'label' => $label, 'file_path' => get_theme_file_path( 'assets/icons/' . $slug . '.svg' ), ) ); } } endif; add_action( 'init', 'benday_register_icons' ); if ( ! function_exists( 'benday_single_no_image_template' ) ) : /** * Uses the "Single (No Featured Image)" template for posts without a featured image. * * A template picked for the post in the editor always wins. The same rule * answers the editor's template lookup, so the post editor previews the * template the site will use. * * @since Benday 1.0 * * @param string[] $templates Template candidates, most specific first. * @return string[] Filtered template candidates. */ function benday_single_no_image_template( $templates ) { $post = get_queried_object(); // The editor's template lookup has no queried post; its first candidate is "single-post-{slug}". if ( ! $post instanceof WP_Post ) { $post = null; foreach ( $templates as $candidate ) { $slug = preg_replace( '/\.php$/', '', $candidate ); if ( str_starts_with( $slug, 'single-post-' ) ) { $post = get_page_by_path( substr( $slug, strlen( 'single-post-' ) ), OBJECT, 'post' ); break; } } } if ( ! $post instanceof WP_Post || 'post' !== $post->post_type || has_post_thumbnail( $post ) || get_page_template_slug( $post ) ) { return $templates; } $uses_files = isset( $templates[0] ) && str_ends_with( $templates[0], '.php' ); array_unshift( $templates, $uses_files ? 'single-no-image.php' : 'single-no-image' ); return $templates; } endif; add_filter( 'single_template_hierarchy', 'benday_single_no_image_template' ); if ( ! function_exists( 'benday_sort_includes_sticky' ) ) : /** * Sorts sticky posts by date with the rest when the blog has an explicit order. * * The Sort links (Newest, Oldest) add "order" to the URL. Without it, the * blog keeps the usual behaviour of pinning sticky posts on top of page one. * * @since Benday 1.0 * * @param WP_Query $query The query being set up. * @return void */ function benday_sort_includes_sticky( $query ) { if ( is_admin() || ! $query->is_main_query() || ! $query->is_home() ) { return; } if ( '' !== $query->get( 'order' ) ) { $query->set( 'ignore_sticky_posts', true ); } } endif; add_action( 'pre_get_posts', 'benday_sort_includes_sticky' ); if ( ! function_exists( 'benday_sticky_only_fallback' ) ) : /** * Shows the latest post in a "sticky only" Query Loop when no post is sticky. * * Worth noticing (patterns/filters.php) lists sticky posts only. Without * this, it would be empty on a site with no sticky posts. Front end only: * the Editor still shows that loop empty. * * @since Benday 1.0 * * @param array $query Query vars built from the Query Loop settings. * @param WP_Block $block The Post Template block. * @return array Filtered query vars. */ function benday_sticky_only_fallback( $query, $block ) { if ( 'only' !== ( $block->context['query']['sticky'] ?? '' ) || get_option( 'sticky_posts' ) ) { return $query; } unset( $query['post__in'] ); $query['posts_per_page'] = 1; return $query; } endif; add_filter( 'query_loop_block_query_vars', 'benday_sticky_only_fallback', 10, 2 );