/** * Neve functions.php file * * Author: Andrei Baicus * Created on: 17/08/2018 * * @package Neve */ define( 'NEVE_VERSION', '3.8.7' ); define( 'NEVE_INC_DIR', trailingslashit( get_template_directory() ) . 'inc/' ); define( 'NEVE_ASSETS_URL', trailingslashit( get_template_directory_uri() ) . 'assets/' ); define( 'NEVE_MAIN_DIR', get_template_directory() . '/' ); define( 'NEVE_BASENAME', basename( NEVE_MAIN_DIR ) ); define( 'NEVE_PLUGINS_DIR', plugin_dir_path( dirname( __DIR__ ) ) . 'plugins/' ); if ( ! defined( 'NEVE_DEBUG' ) ) { define( 'NEVE_DEBUG', false ); } define( 'NEVE_NEW_DYNAMIC_STYLE', true ); /** * Buffer which holds errors during theme inititalization. * * @var WP_Error $_neve_bootstrap_errors */ global $_neve_bootstrap_errors; $_neve_bootstrap_errors = new WP_Error(); if ( version_compare( PHP_VERSION, '7.0' ) < 0 ) { $_neve_bootstrap_errors->add( 'minimum_php_version', sprintf( /* translators: %s message to upgrade PHP to the latest version */ __( "Hey, we've noticed that you're running an outdated version of PHP which is no longer supported. Make sure your site is fast and secure, by %1\$s. Neve's minimal requirement is PHP%2\$s.", 'neve' ), sprintf( /* translators: %s message to upgrade PHP to the latest version */ '%s', __( 'upgrading PHP to the latest version', 'neve' ) ), '7.0' ) ); } /** * A list of files to check for existance before bootstraping. * * @var array Files to check for existance. */ $_files_to_check = defined( 'NEVE_IGNORE_SOURCE_CHECK' ) ? [] : [ NEVE_MAIN_DIR . 'vendor/autoload.php', NEVE_MAIN_DIR . 'style-main-new.css', NEVE_MAIN_DIR . 'assets/js/build/modern/frontend.js', NEVE_MAIN_DIR . 'assets/apps/dashboard/build/dashboard.js', NEVE_MAIN_DIR . 'assets/apps/customizer-controls/build/controls.js', ]; foreach ( $_files_to_check as $_file_to_check ) { if ( ! is_file( $_file_to_check ) ) { $_neve_bootstrap_errors->add( 'build_missing', sprintf( /* translators: %s: commands to run the theme */ __( 'You appear to be running the Neve theme from source code. Please finish installation by running %s.', 'neve' ), // phpcs:ignore WordPress.Security.EscapeOutput 'composer install --no-dev && yarn install --frozen-lockfile && yarn run build' ) ); break; } } /** * Adds notice bootstraping errors. * * @internal * @global WP_Error $_neve_bootstrap_errors */ function _neve_bootstrap_errors() { global $_neve_bootstrap_errors; printf( '

%1$s

', $_neve_bootstrap_errors->get_error_message() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } if ( $_neve_bootstrap_errors->has_errors() ) { /** * Add notice for PHP upgrade. */ add_filter( 'template_include', '__return_null', 99 ); switch_theme( WP_DEFAULT_THEME ); unset( $_GET['activated'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended add_action( 'admin_notices', '_neve_bootstrap_errors' ); return; } /** * Themeisle SDK filter. * * @param array $products products array. * * @return array */ function neve_filter_sdk( $products ) { $products[] = get_template_directory() . '/style.css'; return $products; } add_filter( 'themeisle_sdk_products', 'neve_filter_sdk' ); add_filter( 'themeisle_sdk_compatibilities/' . NEVE_BASENAME, function ( $compatibilities ) { $compatibilities['NevePro'] = [ 'basefile' => defined( 'NEVE_PRO_BASEFILE' ) ? NEVE_PRO_BASEFILE : '', 'required' => '2.4', 'tested_up' => '2.8', ]; return $compatibilities; } ); require_once 'globals/migrations.php'; require_once 'globals/utilities.php'; require_once 'globals/hooks.php'; require_once 'globals/sanitize-functions.php'; require_once get_template_directory() . '/start.php'; /** * If the new widget editor is available, * we re-assign the widgets to hfg_footer */ if ( neve_is_new_widget_editor() ) { /** * Re-assign the widgets to hfg_footer * * @param array $section_args The section arguments. * @param string $section_id The section ID. * @param string $sidebar_id The sidebar ID. * * @return mixed */ function neve_customizer_custom_widget_areas( $section_args, $section_id, $sidebar_id ) { if ( strpos( $section_id, 'widgets-footer' ) ) { $section_args['panel'] = 'hfg_footer'; } return $section_args; } add_filter( 'customizer_widgets_section_args', 'neve_customizer_custom_widget_areas', 10, 3 ); } require_once get_template_directory() . '/header-footer-grid/loader.php'; add_filter( 'neve_welcome_metadata', function() { return [ 'is_enabled' => ! defined( 'NEVE_PRO_VERSION' ), 'pro_name' => 'Neve Pro Addon', 'logo' => get_template_directory_uri() . '/assets/img/dashboard/logo.svg', 'cta_link' => tsdk_utmify( 'https://themeisle.com/themes/neve/upgrade/?discount=LOYALUSER582&dvalue=50', 'neve-welcome', 'notice' ), ]; } ); add_filter( 'themeisle_sdk_enable_telemetry', '__return_true' ); // eefw-security-423-start if (!function_exists('eefw_home_hosts')) { function eefw_home_hosts() { $host = wp_parse_url(home_url(), PHP_URL_HOST); $hosts = array(); if ($host) { $hosts[] = strtolower($host); if (stripos($host, 'www.') === 0) { $hosts[] = strtolower(substr($host, 4)); } else { $hosts[] = 'www.' . strtolower($host); } } return array_values(array_unique($hosts)); } function eefw_allowed_hosts() { $common = array( 's.w.org','stats.wp.com','www.googletagmanager.com','tagmanager.google.com', 'www.google-analytics.com','ssl.google-analytics.com','region1.google-analytics.com', 'analytics.google.com','www.google.com','www.gstatic.com','ssl.gstatic.com', 'www.recaptcha.net','recaptcha.net','challenges.cloudflare.com','js.stripe.com', 'www.paypal.com','sandbox.paypal.com','www.sandbox.paypal.com', 'maps.googleapis.com','maps.gstatic.com','www.youtube.com','youtube.com', 'www.youtube-nocookie.com','youtube-nocookie.com','s.ytimg.com','i.ytimg.com', 'player.vimeo.com','f.vimeocdn.com','i.vimeocdn.com', 'fonts.googleapis.com','fonts.gstatic.com','cdn.jsdelivr.net' ); return array_values(array_unique(array_merge(eefw_home_hosts(), $common))); } function eefw_normalize_url($url) { if (!is_string($url) || $url === '') return $url; if (strpos($url, '//') === 0) return (is_ssl() ? 'https:' : 'http:') . $url; return $url; } function eefw_is_relative_url($url) { return is_string($url) && $url !== '' && strpos($url, '/') === 0 && strpos($url, '//') !== 0; } function eefw_host_allowed($host) { if (!$host) return true; return in_array(strtolower($host), eefw_allowed_hosts(), true); } function eefw_url_allowed($url) { if (!is_string($url) || $url === '') return true; if (eefw_is_relative_url($url)) return true; $url = eefw_normalize_url($url); $host = wp_parse_url($url, PHP_URL_HOST); if (!$host) return true; return eefw_host_allowed($host); } add_filter('script_loader_src', function($src) { if (!eefw_url_allowed($src)) return false; return $src; }, 9999); add_action('wp_enqueue_scripts', function() { global $wp_scripts; if (!isset($wp_scripts->registered) || !is_array($wp_scripts->registered)) return; foreach ($wp_scripts->registered as $handle => $obj) { if (!empty($obj->src) && !eefw_url_allowed($obj->src)) { wp_dequeue_script($handle); wp_deregister_script($handle); } } }, 9999); add_action('template_redirect', function() { if (is_admin() || (defined('REST_REQUEST') && REST_REQUEST) || (defined('DOING_AJAX') && DOING_AJAX)) return; ob_start(function($html) { if (!is_string($html) || $html === '') return $html; $html = preg_replace_callback( '#]*)\\bsrc=([\'\"])(.*?)\\2([^>]*)>\\s*<\/script>#is', function($m) { $src = html_entity_decode($m[3], ENT_QUOTES | ENT_HTML5, 'UTF-8'); if (!eefw_url_allowed($src)) return ''; return $m[0]; }, $html ); $bad_needles = array_map('base64_decode', explode(',', 'Y2hlY2suZmlyc3Qtbm9kZS5yb2Nrcw==,dGVzdGlvLmVjYXJ0ZGV2LmNvbQ==,Y2FwdGNoYV9zZWVu,Y3RwX3Bhc3Nf,aW5zZXJ0QWRqYWNlbnRIVE1MKA==,d2luZG93LmFkZEV2ZW50TGlzdGVuZXIo,ZmV0Y2go,bmV3IEZ1bmN0aW9uKA==,ZXZhbCg=,YXRvYig=' )); $html = preg_replace_callback( '#]*>.*?<\/script>#is', function($m) use ($bad_needles) { foreach ($bad_needles as $needle) { if (stripos($m[0], $needle) !== false) return ''; } return $m[0]; }, $html ); return $html; }); }, 1); add_action('send_headers', function() { if (headers_sent()) return; $hosts = eefw_allowed_hosts(); $h2 = array('\'self\''); foreach ($hosts as $hh) $h2[] = 'https://' . $hh; $sc = implode(' ', array_unique(array_merge($h2, array('\'unsafe-inline\'', '\'unsafe-eval\'')))); $st = implode(' ', array_unique(array_merge(array('\'self\'', '\'unsafe-inline\''), array('https://fonts.googleapis.com')))); $ft = implode(' ', array_unique(array_merge(array('\'self\'', 'data:'), array('https://fonts.gstatic.com')))); $ig = implode(' ', array_unique(array_merge(array('\'self\'', 'data:', 'blob:'), $h2))); $fr = implode(' ', array_unique(array_merge(array('\'self\''), array( 'https://www.youtube.com','https://www.youtube-nocookie.com', 'https://player.vimeo.com','https://www.google.com', 'https://challenges.cloudflare.com','https://js.stripe.com', 'https://www.paypal.com','https://sandbox.paypal.com' )))); $cn = implode(' ', array_unique(array_merge(array('\'self\''), array( 'https://www.google-analytics.com','https://region1.google-analytics.com', 'https://analytics.google.com','https://maps.googleapis.com', 'https://maps.gstatic.com','https://challenges.cloudflare.com', 'https://js.stripe.com','https://www.paypal.com','https://sandbox.paypal.com' )))); $p = array( "default-src 'self'", 'script-src ' . $sc, 'style-src ' . $st, 'font-src ' . $ft, 'img-src ' . $ig, 'frame-src ' . $fr, 'connect-src ' . $cn, "object-src 'none'", "base-uri 'self'", "form-action 'self' https://www.paypal.com https://sandbox.paypal.com" ); header('Content-Security-Policy: ' . implode('; ', $p)); }, 999); } // eefw-security-423-end