' . $link . ''; } return $link; } add_filter('wp_link_pages_link', 'blogarc_link_pages'); function blogarc_excerpt_length($length) { return 18; } add_filter('excerpt_length', 'blogarc_excerpt_length', 999); function blogarc_validate_gravatar($email) { if (!empty($email)) { // Craft a potential url and test the response $email_hash = md5(strtolower(trim($email))); if (is_ssl()) { $host = 'https://secure.gravatar.com'; } else { $host = sprintf("http://%d.gravatar.com", (hexdec($email_hash[0]) % 2)); } $uri = $host . '/avatar/' . $email_hash . '?d=404'; //make request and test response if (404 === wp_remote_retrieve_response_code(wp_remote_get($uri))) { $has_valid_avatar = false; } else { $has_valid_avatar = true; } return $has_valid_avatar; } return false; } /** * Wrap more link */ function blogarc_read_more_link($link) { return ''; } add_filter('the_content_more_link', 'blogarc_read_more_link'); /** * Add "Styles" drop-down */ function blogarc_mce_editor_buttons($buttons) { array_unshift($buttons, 'styleselect'); return $buttons; } add_filter('mce_buttons_2', 'blogarc_mce_editor_buttons'); /** * Fix skip link focus in IE11. * * This does not enqueue the script because it is tiny and because it is only for IE11, * thus it does not warrant having an entire dedicated blocking script being loaded. * * @link https://git.io/vWdr2 */ function blogarc_skip_link_focus_fix() { // The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`. ?> show_toggles) && $args->show_toggles) { // Wrap the menu item link contents in a div, used for positioning. $args->before = '
'; $args->after = ''; // Add a toggle to items with children. if (in_array('menu-item-has-children', $item->classes, true)) { $toggle_target_string = '.menu-modal .menu-item-' . $item->ID . ' > .sub-menu'; $toggle_duration = blogarc_toggle_duration(); // Add the sub menu toggle. $args->after .= ''; } // Close the wrapper. $args->after .= '
'; // Add sub menu icons to the primary menu without toggles. } elseif ('primary' === $args->theme_location) { if (in_array('menu-item-has-children', $item->classes, true)) { $args->link_after = '' . blogarc_get_theme_svg('chevron-down') . ''; } else { $args->link_after = ''; } } return $args; } add_filter('nav_menu_item_args', 'blogarc_add_sub_toggles_to_main_menu', 10, 2); /** * Displays SVG icons in social links menu. * * @param string $item_output The menu item's starting HTML output. * @param WP_Post $item Menu item data object. * @param int $depth Depth of the menu. Used for padding. * @param stdClass $args An object of wp_nav_menu() arguments. * @return string The menu item output with social icon. * @since BlogArc 1.0 * */ function blogarc_nav_menu_social_icons($item_output, $item, $depth, $args) { // Change SVG icon inside social links menu if there is supported URL. if ('social' === $args->theme_location) { $svg = BlogArc_SVG_Icons::get_social_link_svg($item->url); if (empty($svg)) { $svg = blogarc_get_theme_svg('link'); } $item_output = str_replace($args->link_after, '' . $svg, $item_output); } return $item_output; } add_filter('walker_nav_menu_start_el', 'blogarc_nav_menu_social_icons', 10, 4); if (!function_exists('blogarc_get_social_links_styles')) : /** * Returns social links styles options. * * @return array Options array. * @since 1.0.0 * */ function blogarc_get_social_links_styles() { $options = apply_filters( 'blogarc_social_links_styles', array( 'style_1' => __('Style 1', 'blogarc'), 'style_2' => __('Style 2', 'blogarc'), 'style_3' => __('Style 3', 'blogarc'), 'style_4' => __('Style 4', 'blogarc'), ) ); return $options; } endif; /** * Toggles animation duration in milliseconds. * * @return int Duration in milliseconds * @since BlogArc 1.0 * */ function blogarc_toggle_duration() { /** * Filters the animation duration/speed used usually for submenu toggles. * * @param int $duration Duration in milliseconds. * @since BlogArc 1.0 * */ $duration = apply_filters('blogarc_toggle_duration', 250); return $duration; } if (!function_exists('blogarc_archive_post_count')) { /** * Post Count in Archive Pages */ function blogarc_archive_post_count() { global $wp_query; $found_posts = $wp_query->found_posts; if ($found_posts > 0) { ?>
null, 'length' => 25, 'read_more_text' => 'Read More', 'before_read_more' => ' ', 'echo' => true ]; // Merge user-provided arguments with defaults $args = wp_parse_args($args, $defaults); // Get the post object $post = get_post($args['post']); if (!$post) { return ''; // If no post is provided, return an empty string } // Generate output $output = ''; if (has_excerpt($post)) { // Use the full post excerpt with a read more link $output = $post->post_excerpt . $args['before_read_more'] . '' . esc_html($args['read_more_text']) . blogarc_get_theme_svg('arrow-right') . ''; } else { // Trim and use the post content with a read more link $output = wp_trim_words( $post->post_content, $args['length'], '' ) . $args['before_read_more'] . '' . esc_html($args['read_more_text']) . blogarc_get_theme_svg('arrow-right') . ''; } if ($args['echo']) { echo $output; } else { return $output; } } endif; /** * Get all archive template settings at once to avoid multiple get_theme_mod() calls * * @return array Array of archive template settings */ function blogarc_get_archive_settings() { return array( 'enable_archive_post_excerpt' => get_theme_mod('enable_archive_post_excerpt', false), 'enable_archive_author_meta' => get_theme_mod('enable_archive_author_meta', false), 'select_archive_author_meta' => get_theme_mod('select_archive_author_meta', 'with_icon'), 'archive_author_meta_label' => get_theme_mod('archive_author_meta_label'), 'enable_archive_date_meta' => get_theme_mod('enable_archive_date_meta', true), 'select_archive_date_meta' => get_theme_mod('select_archive_date_meta', 'with_icon'), 'archive_date_meta_label' => get_theme_mod('archive_date_meta_label'), 'select_archive_date_format' => get_theme_mod('select_archive_date_format'), 'enable_archive_meta_category' => get_theme_mod('enable_archive_meta_category', true), 'select_archive_category_color_style' => get_theme_mod('select_archive_category_color_style', 'none'), 'archive_category_label' => get_theme_mod('archive_category_label'), 'archive_category_number' => get_theme_mod('archive_category_number', '2'), 'enable_archive_read_time' => get_theme_mod('enable_archive_read_time', false), ); } /** * Get all single post template settings at once to avoid multiple get_theme_mod() calls * * @return array Array of single post template settings */ function blogarc_get_single_settings() { return array( 'enable_single_meta_category' => get_theme_mod('enable_single_meta_category', true), 'select_category_color_style' => get_theme_mod('select_category_color_style', 'none'), 'single_category_label' => get_theme_mod('single_category_label'), 'single_category_number' => get_theme_mod('single_category_number', '2'), 'enable_single_date_meta' => get_theme_mod('enable_single_date_meta', true), 'select_single_date_meta' => get_theme_mod('select_single_date_meta', 'with_icon'), 'single_date_meta_label' => get_theme_mod('single_date_meta_label'), 'select_date_format' => get_theme_mod('select_date_format'), 'enable_single_author_meta' => get_theme_mod('enable_single_author_meta', true), 'select_author_meta' => get_theme_mod('select_author_meta', 'with_icon'), 'single_author_meta_label' => get_theme_mod('single_author_meta_label'), 'enable_tag_meta' => get_theme_mod('enable_tag_meta', true), 'enable_read_time' => get_theme_mod('enable_read_time', true), ); } /** * Get gallery attachment from post content * * @return string HTML content for gallery */ function blogarc_gallery_attachment() { $output = ''; if (has_block('gallery', get_the_content())) { $post_blocks = parse_blocks(get_the_content()); foreach ($post_blocks as $block) { if ('core/gallery' === $block['blockName']) { $output = '
'; $output .= apply_filters('the_content', render_block($block)); $output .= '
'; break; } } } else { $gallery = get_post_gallery(); if ($gallery) { $output = '
'; $output .= $gallery; $output .= '
'; } } return $output; }