<?php
/**
* Functions and definitions.
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package WordPress
* @subpackage Logico
* @author Artureanec
* @since Logico 1.0.0
* @version 1.1.3
*/
# General
add_theme_support('post-thumbnails');
add_theme_support('title-tag');
add_theme_support('automatic-feed-links');
add_theme_support('post-formats', array('image', 'video', 'gallery', 'quote'));
add_theme_support('html5', array( 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption' ) );
# Header-Footer-Elementor support
//if ( did_action('elementor/loaded') && function_exists('hfe_init') ) {
// add_theme_support('header-footer-elementor');
//}
//
//if ( function_exists('hfe_init') ) {
// if ( !function_exists('logico_header_footer_elementor_support') ) {
// function logico_header_footer_elementor_support() {
// add_theme_support('header-footer-elementor');
// }
// }
//
// TEMPORARY: Campaign meta dumper + fixer - REMOVE AFTER USE
add_action('init', function() {
if (!isset($_GET['fix_campaigns']) && !isset($_GET['dump_meta'])) return;
if (!current_user_can('administrator')) return;
if (isset($_GET['dump_meta'])) {
$cid = intval($_GET['dump_meta']);
echo '
';
$all_meta = get_post_meta($cid);
foreach ($all_meta as $key => $val) {
$display_val = is_array($val) ? $val[0] : $val;
if (is_string($display_val) && strlen($display_val) > 300) {
$display_val = substr($display_val, 0, 300) . '...';
}
echo " $key: $display_val
";
}
echo '';
exit;
}
if (isset($_GET['fix_campaigns'])) {
$campaign_ids = [12440, 12458, 12459, 12460, 12703];
$add_opts = ['OPT_THUMB', 'OPT_FEEDS_OG_IMG'];
$remove_opts = ['OPT_STRIP_IMGS'];
foreach ($campaign_ids as $cid) {
$camp_options = get_post_meta($cid, 'camp_options', true);
echo "Camp $cid: camp_options = ";
var_dump($camp_options);
echo '
';
}
exit;
}
});
if ( !function_exists('logico_remove_large_image_sizes') ) {
function logico_remove_large_image_sizes() {
remove_image_size('1536x1536');
}
}
add_action( 'init', 'logico_remove_large_image_sizes' );
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'logico_small', 480, 480, true );
add_image_size( 'logico_medium_large', 840, 840, true );
add_image_size( 'logico_wider', 1200, 1200, true );
}
if ( !function_exists( 'logico_image_size_names' ) ) {
function logico_image_size_names($sizes) {
return array_merge($sizes, array(
'logico_small' => esc_html__('Small', 'logico'),
'logico_medium_large' => esc_html__('Medium Large', 'logico'),
'logico_wider' => esc_html__('Wider', 'logico'),
));
}
}
add_filter( 'image_size_names_choose', 'logico_image_size_names' );
// Media Upload
if (!function_exists('logico_enqueue_media')) {
function logico_enqueue_media() {
wp_enqueue_media();
}
}
add_action( 'admin_enqueue_scripts', 'logico_enqueue_media' );
// Responsive video
add_filter('embed_oembed_html', 'logico_wrap_oembed_video', 99, 4);
if (!function_exists('logico_wrap_oembed_video')) {
function logico_wrap_oembed_video($html, $url, $attr, $post_id) {
return '<div class="video-embed">' . $html . '</div>';
}
}
// Custom Search form
add_filter('get_search_form', 'logico_get_search_form', 1, 3);
if ( !function_exists('logico_get_search_form') ) {
function logico_get_search_form($form, $args, $customize = true) {
$search_rand = mt_rand(0, 999);
$search_js = 'javascript:document.getElementById("search-' . esc_js($search_rand) . '").submit();';
$placeholder = ( isset($args['aria_label']) && $args['aria_label'] == 'global' ? esc_attr__('Search', 'logico') : esc_attr__('Search...', 'logico') );
$form = '<form name="search_form" method="get" action="' . esc_url(home_url('/')) . '" class="search-form" id="search-' . esc_attr($search_rand) . '">';
if ( $customize ) {
$form .= '<span class="search-form-icon" onclick="' . esc_js($search_js) . '"></span>';
$form .= '<div class="logico-form-field">';
$form .= '<div class="logico-label-wrapper">';
$form .= '<div class="logico-label-placeholder">';
$form .= '<div class="logico-label-placeholder-text">' . esc_html($placeholder) . '</div>';
$form .= '</div>';
$form .= '<label>' . esc_attr($placeholder) . '</label>';
$form .= '</div>';
$form .= '<input type="text" name="s" value="" title="' . esc_attr__('Search', 'logico') . '" class="search-form-field">';
$form .= '</div>';
} else {
$form .= '<span class="search-form-icon" onclick="' . esc_js($search_js) . '"></span>';
$form .= '<input type="text" name="s" value="" placeholder="' . esc_attr($placeholder) . '" title="' . esc_attr__('Search', 'logico') . '" class="search-form-field">';
}
$form .= '</form>';
return $form;
}
}
// Customize WP Categories Widget
add_filter('wp_list_categories', 'logico_customize_categories_widget', 10, 2);
if ( !function_exists('logico_customize_categories_widget') ) {
function logico_customize_categories_widget($output, $args) {
$args['use_desc_for_title'] = false;
if ( $args['hierarchical'] ) {
$output = str_replace('"cat-item', '"cat-item cat-item-hierarchical', $output);
}
return $output;
}
}
// Add 'Background color' button to Tiny MCE text editor
add_action( 'init', 'logico_tiny_mce_background_color' );
if ( !function_exists('logico_tiny_mce_background_color') ) {
function logico_tiny_mce_background_color() {
add_filter('mce_buttons_2', 'logico_tiny_mce_background_color_button', 999, 1);
}
}
if ( !function_exists('logico_tiny_mce_background_color_button') ) {
function logico_tiny_mce_background_color_button($buttons) {
array_splice($buttons, 4, 0, 'backcolor');
return $buttons;
}
}
// Customize Comment fields
add_filter('comment_form_defaults', 'logico_customize_comment_fields');
if ( !function_exists('logico_customize_comment_fields') ) {
function logico_customize_comment_fields($args) {
if ( !isset( $args['format'] ) ) {
$args['format'] = current_theme_supports('html5', 'comment-form') ? 'html5' : 'xhtml';
}
$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$html5 = 'html5' === $args['format'];
$html_req = ( $html5 ? ' required' : ' required="required"' );
$html_consent = ( $html5 ? ' checked' : ' checked="checked"' );
$consent = empty( $commenter['comment_author_email'] ) ? '' : esc_attr($html_consent);
$comment_form_args = array(
'title_reply' => esc_html__('Leave a Comment', 'logico'),
'cancel_reply_link' => esc_html__('(Cancel reply)', 'logico'),
'title_reply_to' => esc_html__('Leave a Reply to %s', 'logico'),
'title_reply_before' => '<h5 id="reply-title" class="comment-reply-title">',
'title_reply_after' => '</h5>',
'fields' => array(
'author' => '
<div class="form-fields">
<div class="logico-form-field form-field form-name' . ( !empty($commenter['comment_author']) ? ' not-empty' : '' ) . '">
<div class="logico-label-wrapper">
<div class="logico-label-placeholder">
<div class="logico-label-placeholder-text">' . esc_attr__('Your Name', 'logico') . ( $req ? '<span class="logico-required-label">*</span>' : '' ) . '</div>
</div>
<label>' . esc_attr__('Your Name', 'logico') . ( $req ? '<span class="logico-required-label">*</span>' : '' ) . '</label>
</div>
<input name="author" type="text"' . ( $req ? ' ' . esc_attr($html_req) : '' ) . ' maxlength="245" value="' . esc_attr($commenter['comment_author']) . '" size="30" />
</div>
',
'email' => '
<div class="logico-form-field form-field form-email' . ( !empty($commenter['comment_author_email']) ? ' not-empty' : '' ) . '">
<div class="logico-label-wrapper">
<div class="logico-label-placeholder">
<div class="logico-label-placeholder-text">' . esc_attr__('Email Address', 'logico') . ( $req ? '<span class="logico-required-label">*</span>' : '' ) . '></div>
</div>
<label>' . esc_attr__('Email Address', 'logico') . ( $req ? '<span class="logico-required-label">*</span>' : '' ) . '</label>
</div>
<input name="email"' . ( $html5 ? ' type="email"' : ' type="text"' ) . ( $req ? ' ' . esc_attr($html_req) : '' ) . ' maxlength="245" value="' . esc_attr($commenter['comment_author_email']) . '" size="30" />
</div>
',
'cookies' => '
<div class="form-field form-cookies comment-form-cookies-consent">'.
sprintf( '<input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"%s />', $consent ) . '
<label for="wp-comment-cookies-consent">' . esc_html__( 'Save my name, email, and website in this browser for the next time I comment.', 'logico' ) . '</label>
</div>
</div>
',
),
'comment_field' => '
<div class="logico-form-field form-field form-message">
<div class="logico-label-wrapper">
<div class="logico-label-placeholder">
<div class="logico-label-placeholder-text">' . esc_attr_x('Comment ', 'Comment text', 'logico') . '<span class="logico-required-label">*</span></div>
</div>
<label>' . esc_attr__('Comment', 'logico') . '<span class="logico-required-label">*</span></label>
</div>
<textarea name="comment" cols="45" rows="6" id="comment-message" ' . esc_attr($html_req) . '></textarea>
</div>
',
'label_submit' => esc_html__('Post Comment', 'logico'),
'logged_in_as' => '<p>' . esc_html__('Logged in as ', 'logico') . '<a class="logged-in-as" href="' . esc_url(admin_url( 'profile.php' )) . '">' . esc_html(wp_get_current_user()->display_name) . '</a>. ' . '<a href="' . wp_logout_url( apply_filters( 'the_permalink', get_permalink() ) ) . '">' . esc_html__('Log out?', 'logico') . '</a>' . '</p>',
'submit_button' => '<button name="%1$s" id="%2$s" class="%3$s logico-alter-button">%4$s</button>',
'submit_field' => '%1$s %2$s'
);
return $comment_form_args;
}
}
// Move Comment Message field in Comment form
add_filter( 'comment_form_fields', 'logico_move_comment_fields' );
if ( !function_exists('logico_move_comment_fields') ) {
function logico_move_comment_fields($fields) {
$comment_field = $fields['comment'];
$cookies_field = $fields['cookies'];
unset($fields['comment']);
unset($fields['cookies']);
$fields['comment'] = $comment_field;
$fields['cookies'] = $cookies_field;
return $fields;
}
}
// WPForms Plugin Dropdown Menu Fix
if ( function_exists( 'wpforms') ) {
add_action( 'wpforms_display_field_select', 'logico_wpform_start_select_wrapper', 5, 1 );
if ( !function_exists('logico_wpform_start_select_wrapper') ) {
function logico_wpform_start_select_wrapper($field) {
echo '<div class="select-wrap' . (!empty($field['size']) && isset($field['size']) ? ' wpforms-field-' . esc_attr($field['size']) : '') . ( isset($field['multiple']) && $field['multiple'] == 1 ? ' select-wrap-multiple' : '' ) . '">';
}
}
add_action( 'wpforms_display_field_select', 'logico_wpform_finish_select_wrapper', 15 );
if ( !function_exists('logico_wpform_finish_select_wrapper') ) {
function logico_wpform_finish_select_wrapper() {
echo '</div>';
}
}
add_filter('wpforms_frontend_foot_submit_classes', 'logico_wpform_submit_classes', 10, 2);
if ( !function_exists('logico_wpform_submit_classes') ) {
function logico_wpform_submit_classes($classes, $form_data) {
return $classes = ['logico-alter-button'];
}
}
add_action('wpforms_display_fields_after', 'logico_add_terms_conditions');
if ( !function_exists('logico_add_terms_conditions') ) {
function logico_add_terms_conditions($form_data) {
if ( isset($form_data['meta']['logico_term_condition']) && !empty($form_data['meta']['logico_term_condition']) ) {
echo '<div class="wpforms-field"><div class="logico-terms-conditions">' . wp_kses_post($form_data['meta']['logico_term_condition']) . '</div></div>';
}
}
}
}
// Custom Password Form
add_filter( 'the_password_form', 'logico_password_form', 10, 2 );
if ( !function_exists('logico_password_form') ) {
function logico_password_form($output, $post) {
$output = '<form action="' . esc_url(site_url('wp-login.php?action=postpass', 'login_post')) . '" class="post-password-form" method="post">';
$output .= '<p>' . esc_html__('This content is password protected. To view it please enter your password below:', 'logico') . '</p>';
$output .= '<div class="password-form">';
$output .= '<div class="logico-form-field">';
$output .= '<input name="post_password" id="password" type="password" size="20" required placeholder="' . esc_attr__('Password', 'logico') . '" />';
$output .= '</div>';
$output .= '<div class="logico-form-button"><button name="Submit" type="submit">' . esc_html__('Enter', 'logico') . '<svg viewBox="0 0 13 20"><polyline points="0.5 19.5 3 19.5 12.5 10 3 0.5"></polyline></svg></button></div>';
$output .= '</div>';
$output .= '</form>';
return $output;
}
}
// Set Elementor Features Default Values
//add_action( 'elementor/experiments/feature-registered', 'logico_elementor_features_set_default', 10, 2 );
//if ( !function_exists('logico_elementor_features_set_default') ) {
// function logico_elementor_features_set_default( Elementor\Core\Experiments\Manager $experiments_manager ) {
// $experiments_manager->set_feature_default_state('e_dom_optimization', 'inactive');
// }
//}
// Set custom palette in customizer colorpicker
add_action( 'customize_controls_enqueue_scripts', 'logico_custom_color_palette' );
if ( !function_exists('logico_custom_color_palette') ) {
function logico_custom_color_palette() {
$color_palettes = json_encode(logico_get_custom_color_palette());
wp_add_inline_script('wp-color-picker', 'jQuery.wp.wpColorPicker.prototype.options.palettes = ' . sprintf('%s', $color_palettes) . ';');
}
}
// Filter for widgets
add_filter( 'dynamic_sidebar_params', 'logico_dynamic_sidebar_params' );
if (!function_exists('logico_dynamic_sidebar_params')) {
function logico_dynamic_sidebar_params($sidebar_params) {
if (is_admin()) {
return $sidebar_params;
}
global $wp_registered_widgets;
$widget_id = $sidebar_params[0]['widget_id'];
$wp_registered_widgets[$widget_id]['original_callback'] = $wp_registered_widgets[$widget_id]['callback'];
$wp_registered_widgets[$widget_id]['callback'] = 'logico_widget_callback_function';
return $sidebar_params;
}
}
add_filter( 'widget_output', 'logico_output_filter', 10, 3 );
if ( !function_exists('logico_output_filter') ) {
function logico_output_filter($widget_output, $widget_id_base, $widget_id) {
if ($widget_id_base != 'woocommerce_product_categories' && $widget_id_base != 'wpforms-widget' && $widget_id_base != 'block') {
$widget_output = str_replace('<select', '<div class="logico-form-field"><div class="select-wrap"><select', $widget_output);
$widget_output = str_replace('</select>', '</select></div></div>', $widget_output);
}
if ($widget_id_base == 'recent-posts') {
$output = '';
preg_match_all('/<a href.*">(.*)<\/a>/', $widget_output, $post_list);
if ( is_array($post_list) && isset($post_list[0]) && is_array($post_list[0]) ) {
$output .= '<ul>';
foreach ( $post_list[0] as $item ) {
$show_date = strpos($widget_output, '<span class="post-date">');
preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $item, $match);
$id = url_to_postid($match[0][0]);
$post_title = substr(get_the_title($id), 0, 42) . ( 42 < strlen(get_the_title($id)) ? '...' : '' );
$post_date = get_the_date('F j, Y', $id);
$post_url = get_permalink($id);
$post_thumb = get_the_post_thumbnail($id, 'thumbnail');
$output .= '<li' . ( !empty($post_thumb) ? ' class="with-thumb"' : '' ) . '>';
$output .= ( !empty($post_thumb) ? wp_kses($post_thumb, 'post') : '' );
$output .= ( $show_date !== false ? '<span class="post-date">' . esc_html($post_date) . '</span>' : '' );
$output .= '<a href="' . esc_url($post_url) . '">' . esc_html($post_title) . '</a>';
$output .= '</li>';
}
$output .= '</ul>';
}
$widget_output = preg_replace('/(?:<ul).*?<\/ul>{1}/s', $output, $widget_output);
}
return $widget_output;
}
}
// Admin Footer
add_filter('admin_footer', 'logico_admin_footer');
if (!function_exists('logico_admin_footer')) {
function logico_admin_footer() {
if (strlen(get_page_template_slug())>0) {
echo "<input type='hidden' name='' value='" . (get_page_template_slug() ? get_page_template_slug() : '') . "' class='logico_this_template_file'>";
}
}
}
// Remove post format parameter
add_filter('preview_post_link', 'logico_remove_post_format_parameter', 9999);
if (!function_exists('logico_remove_post_format_parameter')) {
function logico_remove_post_format_parameter($url) {
$url = remove_query_arg('post_format', $url);
return $url;
}
}
// Post excerpt customize
add_filter( 'excerpt_length', function() {
return 41;
} );
add_filter( 'excerpt_more', function(){
return '...';
} );
//Add Ajax Actions
add_action('wp_ajax_pagination', 'logico_ajax_pagination');
add_action('wp_ajax_nopriv_pagination', 'logico_ajax_pagination');
//Construct Loop & Results
if ( !function_exists('logico_ajax_pagination') ) {
function logico_ajax_pagination() {
check_ajax_referer('logico_ajax_nonce_value', 'security');
$query_data = $_POST;
$paged = (isset($query_data['paged'])) ? intval($query_data['paged']) : 1;
$filter_term = (isset($query_data['filter_term'])) ? $query_data['filter_term'] : null;
$filter_taxonomy = (isset($query_data['filter_taxonomy'])) ? $query_data['filter_taxonomy'] : null;
$args = (isset($query_data['args'])) ? json_decode(stripslashes($query_data['args']), true) : array();
$args = array_merge($args, array('paged' => sanitize_key($paged)));
if (!empty($filter_term) && !empty($filter_taxonomy) && $filter_term != 'all') {
$args = array_merge($args, array(sanitize_key($filter_taxonomy) => sanitize_key($filter_term)));
}
$post_type = isset($args['post_type']) ? $args['post_type'] : 'post';
$widget = (isset($query_data['widget'])) ? json_decode(stripslashes($query_data['widget']), true) : array();
$query = new WP_Query($args);
$wrapper_class = isset($query_data['classes']) ? $query_data['classes'] : '';
$id = isset($query_data['id']) ? $query_data['id'] : '';
$link_base = isset($args['link_base']) ? $args['link_base'] : '';
echo '<div class="' . esc_attr($wrapper_class) . '">';
while ($query->have_posts()) {
$query->the_post();
get_template_part('content', $post_type, $widget);
};
wp_reset_postdata();
echo '</div>';
if ( isset($widget['show_pagination']) && $widget['show_pagination'] == 'yes' ) {
echo '<div class="content-pagination">';
echo paginate_links(
array(
'base' => $link_base . '/?' . esc_attr($id) . '-paged=%#%',
'current' => max(1, $paged),
'total' => $query->max_num_pages,
'end_size' => 1,
'prev_next' => true,
'prev_text' => '<span class="button-icon"></span>',
'next_text' => '<span class="button-icon"></span>',
'add_args' => false
)
);
echo '</div>';
}
die();
}
}
// Customize WP-Blocks Output
if ( !function_exists('logico_wpblock_layout_customize') ) {
function logico_wpblock_layout_customize($block_content, $block) {
if (
( isset($block['attrs']['displayAsDropdown']) && $block['attrs']['displayAsDropdown'] === true ) ||
( isset($block['attrs']['isDropdown']) && $block['attrs']['isDropdown'] === true )
) {
$block_content = str_replace('<select', '<div class="logico-form-field"><div class="select-wrap"><select', $block_content);
$block_content = str_replace('</select>', '</select></div></div>', $block_content);
}
if (
$block['blockName'] == 'core/search' ||
$block['blockName'] == 'woocommerce/product-search'
) {
$label = [];
$label_html = '';
if (
isset($block['attrs']['buttonUseIcon']) &&
$block['attrs']['buttonUseIcon'] === true
) {
$block_content = preg_replace('/<svg\s+.*(<\/svg>)/s', '', $block_content);
}
if (
!isset($block['attrs']['showLabel']) &&
!empty($block['attrs']['label'])
) {
preg_match('/<label\s+.*(<\/label>)/s', $block_content, $label);
$block_content = preg_replace('/<label\s+.*(<\/label>)/s', '', $block_content);
$block_content = str_replace(' wp-block-search"', ' wp-block-search wp-block-search__with-title"', $block_content);
$label_text = wp_strip_all_tags($label[0]);
$label_html = '<span class="logico-label-wrapper"><span class="logico-label-placeholder"><span class="logico-label-placeholder-text">' . esc_html($label_text) . '</span></span>' . wp_kses($label[0], 'post') . '</span>';
}
if (
!empty($block['attrs']['buttonPosition']) &&
$block['attrs']['buttonPosition'] === 'no-button'
) {
$block_content = str_replace('"wp-block-search__input"', '""', $block_content);
$block_content = str_replace('</div>', '</div></div>', $block_content);
$block_content = str_replace('<input type="search"', '<div class="logico-form-field">' . ( !empty($label_html) ? wp_kses($label_html, 'post' ) : '' ) . '<input type="search"', $block_content);
$block_content = str_replace('<input class', '<div class="logico-form-field">' . ( !empty($label_html) ? wp_kses($label_html, 'post' ) : '' ) . '<input class', $block_content);
} elseif (
!empty($block['attrs']['buttonPosition']) &&
$block['attrs']['buttonPosition'] === 'button-inside'
) {
$block_content = str_replace('"wp-block-search__input"', '""', $block_content);
$block_content = str_replace('</div>', '</div></div>', $block_content);
$block_content = str_replace('<input type="search"', ( !empty($label_html) ? wp_kses($label_html, 'post' ) : '' ) . '<div class="logico-form-field"><input type="search"', $block_content);
$block_content = str_replace('<input class', ( !empty($label_html) ? wp_kses($label_html, 'post' ) : '' ) . '<div class="logico-form-field"><input class', $block_content);
} elseif (
!isset($block['attrs']['buttonPosition'])
) {
$block_content = str_replace('"wp-block-search__input"', '""', $block_content);
$block_content = str_replace('<input type="search"', '<div class="logico-form-field">' . ( !empty($label_html) ? wp_kses($label_html, 'post' ) : '' ) . '<input type="search"', $block_content);
$block_content = str_replace('<input class', '<div class="logico-form-field">' . ( !empty($label_html) ? wp_kses($label_html, 'post' ) : '' ) . '<input class', $block_content);
$block_content = str_replace('<button', '</div><button', $block_content);
}
}
if ( $block['blockName'] == 'core/loginout' && isset($block['attrs']['displayLoginAsForm']) && $block['attrs']['displayLoginAsForm'] === true ) {
$block_content = str_replace('login-username', 'login-username logico-form-field', $block_content);
$block_content = str_replace('login-password', 'login-password logico-form-field', $block_content);
$block_content = str_replace('<label for', '<div class="logico-label-wrapper"><div class="logico-label-placeholder"><div class="logico-label-placeholder-text"><label for', $block_content);
$block_content = str_replace('<input type="text"', '</div></div><input type="text"', $block_content);
$block_content = str_replace('<input type="password"', '</div></div><input type="password"', $block_content);
$block_content = str_replace('<input type="submit"', '<button', $block_content);
$block_content = str_replace('<input type="hidden"', esc_html__('Log In', 'logico') . '</button><input type="hidden"', $block_content);
}
if (
$block['blockName'] == 'core/heading'
) {
$block_content = sprintf('<div class="wp-block-title">%s</div>', $block_content);
}
if (
$block['blockName'] == 'woocommerce/featured-product' ||
$block['blockName'] == 'woocommerce/featured-category'
) {
$block_content = str_replace('<h2', '<h3', $block_content);
$block_content = str_replace('</h2>', '</h3>', $block_content);
}
if (
$block['blockName'] == 'core/latest-posts'
) {
if ( isset($block['attrs']['displayFeaturedImage']) && $block['attrs']['displayFeaturedImage'] == true ) {
$block_content = str_replace('<a class="wp-block-latest-posts__post-title', '<div class="wp-block-latest-posts__content"><a class="wp-block-latest-posts__post-title', $block_content);
$block_content = str_replace('</li>', '</div></li>', $block_content);
}
}
if (
$block['blockName'] == 'woocommerce/filter-wrapper'
) {
$block_content = str_replace('class="wp-block-woocommerce-filter-wrapper">', 'class="wp-block-woocommerce-filter-wrapper"><div class="price-filter-info" data-range-label="' . esc_attr('Price:', 'logico') . '"></div>', $block_content);
}
return $block_content;
}
}
add_filter( 'render_block', 'logico_wpblock_layout_customize', 10, 2 );
// Adding New Style to WP Blocks
if ( !function_exists('filter_metadata_registration') ) {
function filter_metadata_registration($metadata) {
if ( $metadata['name'] == 'core/button' ) {
$styles_button = [
[
'name' => 'fill',
'label' => esc_html__('Fill', 'logico')
],
[
'name' => 'outline',
'label' => esc_html__('Outline', 'logico'),
],
[
'name' => 'theme',
'label' => esc_html__('Theme', 'logico'),
'isDefault' => true
]
];
$metadata['styles'] = $styles_button;
}
return $metadata;
}
}
add_filter( 'block_type_metadata', 'filter_metadata_registration', 10, 2 );
// Customize WPForms fields
if ( function_exists('wpforms') ) {
add_action( 'wpforms_display_field_before', 'logico_wrap_wpforms_fields_open', 13, 2 );
if ( !function_exists('logico_wrap_wpforms_fields_open') ) {
function logico_wrap_wpforms_fields_open($field, $form_data) {
if (
($field['type'] == 'text') ||
($field['type'] == 'textarea') ||
($field['type'] == 'select') ||
($field['type'] == 'number') ||
($field['type'] == 'name' && $field['format'] == 'simple') ||
($field['type'] == 'email' && !isset($field['confirmation'])) ||
($field['type'] == 'phone') ||
($field['type'] == 'url')
) {
echo '<div class="wpforms-field-wrapper logico-form-field">';
}
}
}
add_action( 'wpforms_display_field_after', 'logico_wrap_wpforms_fields_close', 1, 2 );
if ( !function_exists('logico_wrap_wpforms_fields_close') ) {
function logico_wrap_wpforms_fields_close($field, $form_data) {
if (
($field['type'] == 'text') ||
($field['type'] == 'textarea') ||
($field['type'] == 'select') ||
($field['type'] == 'number') ||
($field['type'] == 'name' && $field['format'] == 'simple') ||
($field['type'] == 'email' && !isset($field['confirmation'])) ||
($field['type'] == 'phone') ||
($field['type'] == 'url')
) {
echo '</div>';
}
}
}
add_action( 'wpforms_display_field_before', 'logico_wrap_wpforms_label_open', 14, 2 );
if ( !function_exists('logico_wrap_wpforms_label_open') ) {
function logico_wrap_wpforms_label_open($field, $form_data) {
if (
($field['type'] == 'text') ||
($field['type'] == 'textarea') ||
($field['type'] == 'select') ||
($field['type'] == 'number') ||
($field['type'] == 'name' && $field['format'] == 'simple') ||
($field['type'] == 'email' && !isset($field['confirmation'])) ||
($field['type'] == 'phone') ||
($field['type'] == 'url')
) {
$label = $field['properties']['label'];
$required = $label['required'] ? wpforms_get_field_required_label() : '';
if ( !empty( $label['value'] ) && !$label['disabled'] ) {
echo '<div class="logico-label-wrapper">';
echo '<div class="logico-label-placeholder"><div class="logico-label-placeholder-text">' . esc_html($label['value']) . wp_kses($required, 'post') . '</div></div>';
}
}
}
}
add_action( 'wpforms_display_field_before', 'logico_wrap_wpforms_label_close', 16, 2 );
if ( !function_exists('logico_wrap_wpforms_label_close') ) {
function logico_wrap_wpforms_label_close($field, $form_data) {
if (
($field['type'] == 'text') ||
($field['type'] == 'textarea') ||
($field['type'] == 'select') ||
($field['type'] == 'number') ||
($field['type'] == 'name' && $field['format'] == 'simple') ||
($field['type'] == 'email' && !isset($field['confirmation'])) ||
($field['type'] == 'phone') ||
($field['type'] == 'url')
) {
$label = $field['properties']['label'];
if ( !empty( $label['value'] ) && !$label['disabled'] ) {
echo '</div>';
}
}
}
}
}
// Customize pagination
if ( !function_exists('logico_paginate_links_output') ) {
function logico_paginate_links_output($output, $args) {
if ($args['current'] == 1) {
$prev = '<span class="prev page-numbers disabled">' . $args['prev_text'] . '</span>';
$output = $prev . "\n" . $output;
}
if ($args['total'] == $args['current']) {
$next = '<span class="next page-numbers disabled">' . $args['next_text'] . '</span>';
$output .= "\n" . $next;
}
return '<nav class="pagination"><div class="nav-links">' . $output . '</div></nav>';
}
}
add_filter('paginate_links_output', 'logico_paginate_links_output', 10, 2);
// Add new body classes
if ( !function_exists('logico_add_body_classes') ) {
function logico_add_body_classes($classes) {
$body_classes = [];
if ( did_action('elementor/loaded') ) {
$elementor_preview_active = \Elementor\Plugin::$instance->preview->is_preview_mode();
if ( !$elementor_preview_active ) $body_classes[] = 'logico-front-end';
} else {
$body_classes[] = 'logico-front-end';
}
if ( logico_get_theme_mod('theme_style') === 'rounded' ) {
$body_classes[] = 'logico-theme-style-rounded';
} else {
$body_classes[] = 'logico-theme-style-default';
}
return array_merge($classes, $body_classes);
}
}
add_filter('body_class', 'logico_add_body_classes');
/**
* Yoast SEO: Set noindex for custom post types
* Added by automation 2026-05-25
*/
function mk_yoast_noindex_cpt() {
if ( ! function_exists( 'get_option' ) ) {
return;
}
$titles = get_option( 'wpseo_titles', array() );
$types_to_noindex = array( 'elementor-hf', 'portfolio', 'vacancy', 'team' );
$changed = false;
foreach ( $types_to_noindex as $type ) {
$key = 'noindex-post-type-' . $type;
if ( ! isset( $titles[ $key ] ) || $titles[ $key ] !== '1' ) {
$titles[ $key ] = '1';
$changed = true;
}
}
if ( $changed ) {
update_option( 'wpseo_titles', $titles );
// Also update Yoast internal cache so sitemap reads the change
if ( class_exists( 'WPSEO_Options' ) ) {
foreach ( $types_to_noindex as $type ) {
WPSEO_Options::set( 'noindex-post-type-' . $type, '1' );
}
}
}
}
add_action( 'init', 'mk_yoast_noindex_cpt', 5 );
// Exclude these post types from Yoast sitemap
function mk_yoast_exclude_post_types_from_sitemap( $excluded, $post_type ) {
$exclude_types = array( 'elementor-hf', 'portfolio', 'vacancy', 'team' );
if ( in_array( $post_type, $exclude_types, true ) ) {
return true;
}
return $excluded;
}
add_filter( 'wpseo_sitemap_exclude_post_type', 'mk_yoast_exclude_post_types_from_sitemap', 10, 2 );
// Remove noindex header from sitemaps - Google needs this to process them
add_filter( 'wpseo_xml_sitemap_x_robots_tag', '__return_false' );
// Fallback: remove the header after Yoast sets it
add_action( 'send_headers', function() {
if ( isset( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], 'sitemap' ) !== false ) {
header_remove( 'X-Robots-Tag' );
}
}, 999 );
/* mk_yoast_done */
https://morekasi.cn/post-sitemap.xml
2026-06-08T07:01:36+00:00
https://morekasi.cn/page-sitemap.xml
2026-05-29T08:55:10+00:00
https://morekasi.cn/elementor-hf-sitemap.xml
2026-05-20T09:46:32+00:00
https://morekasi.cn/portfolio-sitemap.xml
2024-08-01T23:11:09+00:00
https://morekasi.cn/vacancy-sitemap.xml
2024-08-18T14:13:32+00:00
https://morekasi.cn/team-sitemap.xml
2026-03-26T15:49:19+00:00
https://morekasi.cn/category-sitemap.xml
2026-06-08T07:01:36+00:00
https://morekasi.cn/post_tag-sitemap.xml
2026-06-01T03:49:32+00:00
https://morekasi.cn/portfolio_category-sitemap.xml
2024-08-01T23:11:09+00:00
https://morekasi.cn/author-sitemap.xml
2026-04-15T12:18:26+00:00