<?php
	if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
	define("THEME_NAME", 'gadgetine');
	define("THEME_FULL_NAME", 'Gadgetine');


	// THEME PATHS
	define("THEME_FUNCTIONS_PATH",TEMPLATEPATH."/functions/");
	define("THEME_INCLUDES_PATH",TEMPLATEPATH."/includes/");
	define("THEME_SCRIPTS_PATH",TEMPLATEPATH."/js/");
	define("THEME_AWEBER_PATH", THEME_FUNCTIONS_PATH."aweber_api/");
	define("THEME_ADMIN_INCLUDES_PATH", THEME_INCLUDES_PATH."admin/");
	define("THEME_WIDGETS_PATH", THEME_INCLUDES_PATH."widgets/");

	//POST TYPES
	if (!defined('OT_POST_GALLERY')) {
		define("OT_POST_GALLERY","gallery");
	}
	if (!defined('OT_POST_PORTFOLIO')) {
		define("OT_POST_PORTFOLIO","portfolio");
	}

	define("THEME_FUNCTIONS", "functions/");
	define("THEME_INCLUDES", "includes/");
	define("THEME_SLIDERS", THEME_INCLUDES."sliders/");
	define("THEME_LOOP", THEME_INCLUDES."loop/");
	define("THEME_SINGLE", THEME_INCLUDES."single/");
	define("THEME_ADMIN_INCLUDES", THEME_INCLUDES."admin/");
	define("THEME_CACHE", "cache/");
	define("THEME_SCRIPTS", "js/");
	define("THEME_CSS", "css/");

	define("THEME_URL", get_template_directory_uri());

	define("THEME_CSS_URL",THEME_URL."/css/");
	define("THEME_CSS_ADMIN_URL",THEME_URL."/css/admin/");
	define("THEME_JS_URL",THEME_URL."/js/");
	define("THEME_JS_ADMIN_URL",THEME_URL."/js/admin/");
	define("THEME_IMAGE_URL",THEME_URL."/images/");
	define("THEME_IMAGE_CPANEL_URL",THEME_IMAGE_URL."/control-panel-images/");
	define("THEME_IMAGE_MTHEMES_URL",THEME_IMAGE_URL."/more-themes-images/");
	define("THEME_FUNCTIONS_URL",THEME_URL."/functions/");

	define("THEME_ADMIN_URL",THEME_URL."/includes/admin/");
	define("THEME_HOME_BLOCKS", THEME_INCLUDES."home-blocks/");
	define("THEME_HOME_BLOCK_ROWS", THEME_HOME_BLOCKS."rows/");


	require_once(THEME_FUNCTIONS_PATH."tax-meta-class/tax-meta-class.php");
	require_once(THEME_INCLUDES_PATH."theme-config.php");
	require_once(THEME_FUNCTIONS_PATH."init.php");
	require_once(THEME_WIDGETS_PATH."init.php");




	//remove visual composer notifier
	if(function_exists('vc_set_as_theme')) {
		vc_set_as_theme($notifier = false);
	}

	//woocomerce
	remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
	remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
	add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10);
	add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10);

	function my_theme_wrapper_start() {
	  echo '<section id="main">';
	}

	function my_theme_wrapper_end() {
	  echo '</section>';
	}
	
	add_theme_support( 'woocommerce' );

	$shopCount = 12; 
	if($shopCount) {
		add_filter( 'loop_shop_per_page', create_function( '$cols', 'return '.$shopCount.';' ), 20 );
	}

	if ( ot_is_woocommerce_activated() == true && version_compare( WOOCOMMERCE_VERSION, "2.1" ) >= 0 ) {
		add_filter( 'woocommerce_enqueue_styles', '__return_false' );
	} else {
		define( 'WOOCOMMERCE_USE_CSS', false );
	}

	//remove layserslider notifier
	$GLOBALS['lsAutoUpdateBox'] = false;

//function no_rows_found_function($query) 
//	{

	//	if (!is_admin()) 
	//	{
			/*if(is_category())
			{
				$query->set( 'no_found_rows', true );
			}else
			{
				$query->set( 'no_found_rows', true );
			}*/
	//		$query->set( 'no_found_rows', true );
	//	}
//	}

//	add_action('pre_get_posts','no_rows_found_function');
	
//	add_filter('posts_orderby', 'custom_order');

//	function custom_order()
//	{
//		$orderby = 'ID desc';
//		return $orderby;
//	}

if ( ! function_exists( 'wpartisan_set_no_found_rows' ) ) :
 
    /**
     * Sets the 'no_found_rows' param to true.
     *
     * In the WP_Query class this stops the use of SQL_CALC_FOUND_ROWS in the
     * MySql query it generates. It's slow so we're going to replace it with
     * a COUNT(*) instead.
     *
     * @param  WP_Query $wp_query The WP_Query instance. Passed by reference.
     * @return void
     */
    function wpartisan_set_no_found_rows( \WP_Query $wp_query ) {
        $wp_query->set( 'no_found_rows', true );
    }
endif;
add_filter( 'pre_get_posts', 'wpartisan_set_no_found_rows', 10, 1 );
 
if ( ! function_exists( 'wpartisan_set_found_posts' ) ) :
 
    /**
     * Workout the pagination values.
     *
     * Uses the query parts to run a custom count(*) query against the database
     * then constructs and sets the pagination results for this wp_query.
     *
     * @param array    $clauses  Array of clauses that make up the SQL query.
     * @param WP_Query $wp_query The WP_Query instance. Passed by reference.
     * @return array
     */
    function wpartisan_set_found_posts( $clauses, \WP_Query $wp_query ) {
 
        // Don't proceed if it's a singular page.
        if ( $wp_query->is_singular()  ) {
            return $clauses;
        }
 
        global $wpdb;
 
        // Check if they're set.
        $where = isset( $clauses[ 'where' ] ) ? $clauses[ 'where' ] : '';
        $join = isset( $clauses[ 'join' ] ) ? $clauses[ 'join' ] : '';
        $distinct = isset( $clauses[ 'distinct' ] ) ? $clauses[ 'distinct' ] : '';
 
        // Construct and run the query. Set the result as the 'found_posts'
        // param on the main query we want to run.
        $wp_query->found_posts = $wpdb->get_var( "SELECT $distinct COUNT($wpdb->posts.ID) FROM {$wpdb->posts} $join WHERE 1=1 $where" );
 
        // Work out how many posts per page there should be.
        $posts_per_page = ( ! empty( $wp_query->query_vars['posts_per_page'] ) ? absint( $wp_query->query_vars['posts_per_page'] ) : absint( get_option( 'posts_per_page' ) ) );
 
        // Set the max_num_pages.
        $wp_query->max_num_pages = ceil( $wp_query->found_posts / $posts_per_page );
 
        // Return the $clauses so the main query can run.
        return $clauses;
    }
endif;
add_filter( 'posts_clauses', 'wpartisan_set_found_posts', 10, 2 );
add_filter('posts_orderby', 'custom_order');

	function custom_order(){
		$orderby = 'ID desc';
		return $orderby;
	}
?>