<?php
/**
 * Plugin Name:     SOLARWARE Dealer Search Tool
 * Plugin URI:      http://innovedesigns.com/
 * Description:     Able to create dealer with fields (Dealer Name, Information, Store Location) by entering postcode.
 * Version:         1.0.0
 * Author:          esstat17
 * Author URI:      http://innovedesigns.com/
 * Text Domain:     dst-txt
 *
 *
 * @package         DST
 * @author          esstat17
 * @copyright       Copyright (c) 2016 
 *
 * @todo Replace only if your creating your own Plugin
 * @todo replace Plugin Name
 * @todo replace Plugin URI
 * @todo replace Description
 * @todo replace Version
 * @todo replace Text Domain
 * @todo replace Author
 * @todo replace Author URI
 *
 * @todo Dealer_Search_Tool - Find all and replace text
 * @todo DST - Find all and replace text
 * @todo dst - Find all and replace text
 * @todo DEALER_SEARCH_TOOL - Find all and replace text
 *
 *
 * IMPORTANT! Ensure that you make the following amendments
 * before releasing your extension:
 *
 * Copyright 2016 (email : esstat17 at GMAIL.com)
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2, as
 * published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

// Exit if accessed directly
if( !defined( 'ABSPATH' ) ) exit;

/**
 * The core plugin class.
 *
 * This is used to define internationalization, admin-specific hooks, and
 * public-facing site hooks.
 *
 * Also maintains the unique identifier of this plugin as well as the current
 * version of the plugin.
 *
 * @since      1.0.0
 * @package    Dealer_Search_Tool
 * @subpackage Dealer_Search_Tool/includes
 */
if( !class_exists( 'Dealer_Search_Tool' ) ) {

    /**
     * Main Dealer_Search_Tool class
     *
     * @since       1.0.0
     */
    class Dealer_Search_Tool {

        /**
         * @var         object $instance self assigning 
         * @since       1.0.0
         */
        private static $instance; // 

        /**
         * HTML Element Helper Object.
         *
         * @var object
         * @since 1.0.0
         */
        public $html;

        /**
         * Relational DB SELECT query using Native WP DB System.
         *
         * @var object
         * @since 1.0.0
         */
        public $db;

        /**
         * The unique identifier of this plugin.
         *
         * @since    1.0.0
         * @access   protected
         * @var      string    $plugin_name    The string used to uniquely identify this plugin.
         */
        private $plugin_name;

        /**
         * The Class Constructor
         */

        public function __construct() {
            $this->plugin_name = 'note-for-posts'; // @todo replace it with your plugin name
            $this->setup_constants();
            $this->includes();    
            do_action( 'dst_hooks' ); // This function invokes all functions attached to `ywp_hooks` action hook 
        }

        /**
         * Get active instance
         *
         * @access      public
         * @since       1.0.0
         * @return      object self::$instance The one true NoteForPost
         */
        public static function instance() {
            if( !self::$instance ) {
                self::$instance = new self(); // // assigning the new NoteForPost Class Instance
                self::$instance->db = new DST_DB_Query();
                self::$instance->html = new DST_Friendly_HTML();
            }
            return self::$instance;
        }

        /**
         * Define constant if not already set.
         *
         * @param  string $name
         * @param  string|bool $value
         */
        private function define( $name, $value ) {
            if ( ! defined( $name ) ) {
                define( $name, $value );
            }
        }

        /**
         * Setup plugin constants
         *
         * @access      private
         * @since       1.0.0
         * @return      void
         */
        private function setup_constants() {
            // Plugin version
            $this->define( 'DEALER_SEARCH_TOOL_VER', '1.0.0' );
            // Plugin path
            $this->define( 'DEALER_SEARCH_TOOL_DIR', plugin_dir_path( __FILE__ ) );
            // Plugin URL
            $this->define( 'DEALER_SEARCH_TOOL_URL', plugin_dir_url( __FILE__ ) );
        }
        
        /**
         * Run action and filter hooks
         *
         * @access      private
         * @since       1.0.0
         * @return      void
         *
         * @todo        The hooks listed in this section are a guideline, and
         *              may or may not be relevant to your particular plugin.
         *              Please remove any unnecessary lines, and refer to the
         *              WordPress codex documentation for additional
         *              information on the included hooks.
         *
         *              This method should be used to add any filters or actions
         *              that are necessary to the core of your extension only.
         *              Hooks that are relevant to meta boxes, widgets and
         *              the like can be placed in their respective files.
         * 
         * @see Add Action Hook at https://developer.wordpress.org/reference/functions/add_action/
         * @see Add Filter Hook at https://developer.wordpress.org/reference/functions/add_filter/
         */

        /**
         * Include necessary files
         *
         * @access      private
         * @since       1.0.0
         * @return      void
         */
        private function includes() {

            /**
             * @todo    Make Sure to only include the file(s) you need
             *
             */

            // DB Relational Query for Post Type and Post Meta
            require_once DEALER_SEARCH_TOOL_DIR . 'includes/class-relational-db-query.php';

            // Friendly HTML Output Class
            require_once DEALER_SEARCH_TOOL_DIR . 'includes/class-friendly-html.php';

   
            // Register Custom Post Type
            require_once DEALER_SEARCH_TOOL_DIR . 'includes/custom-post-type.php';

             // Register Custom Post Type
            require_once DEALER_SEARCH_TOOL_DIR . 'includes/the-content-filter.php';

            // Custom Widget with Options
            // require_once DEALER_SEARCH_TOOL_DIR . 'includes/widget-register.php';

            // Register Custom Taxonomy for Custom Post Type
            // require_once DEALER_SEARCH_TOOL_DIR . 'includes/taxonomy-tags.php';

            // Load Text Domain
            // require_once DEALER_SEARCH_TOOL_DIR . 'includes/text-domain.php';


            // Short Code Functions
            require_once DEALER_SEARCH_TOOL_DIR . 'includes/shortcodes.php';
                
            // WP AJAX Request
            require_once DEALER_SEARCH_TOOL_DIR . 'includes/wp-ajax-action.php';

            // Frontend Includes
            if ( !is_admin() ) {

                // Enqueue Scripts in the Public
               //  require_once DEALER_SEARCH_TOOL_DIR . 'includes/enqueue-scripts.php';  

                // Inline Footer Scripts in the Public
               // require_once DEALER_SEARCH_TOOL_DIR . 'includes/wp-footer-scripts.php';           
            }

            // Admin Includes
            if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {

                // Manage Custom Columns
                // require_once DEALER_SEARCH_TOOL_DIR . 'includes/admin/manage-columns.php';

                // Enqueue Scripts in the Admin
                require_once DEALER_SEARCH_TOOL_DIR . 'includes/admin/admin-enqueue-scripts.php';

                // Footer scripts in the Admin
                // require_once DEALER_SEARCH_TOOL_DIR . 'includes/admin/admin-footer-options.php';

                // Register Custom Meta Box for Custom Post Type
                require_once DEALER_SEARCH_TOOL_DIR . 'includes/admin/metabox-save-post.php';

                // Manage Custom Columns
                // require_once DEALER_SEARCH_TOOL_DIR . 'includes/admin/manage-columns.php';
              
                // Sub Menu for Settings 
                require_once DEALER_SEARCH_TOOL_DIR . 'includes/admin/sub-menu-options.php';
                
             }
        }


        /**
         * The name of the plugin used to uniquely identify it within the context of
         * WordPress and to define internationalization functionality.
         *
         * @since     1.0.0
         * @return    string    The name of the plugin.
         */
        public function get_plugin_name() {
            return $this->plugin_name;
        }


    }
} // End if class_exists check

/**
 * Permalinks Fix for Post Type
 * To get permalinks to work when you activate the plugin use the following example, 
 * paying attention to how my_cpt_init is called in the register_activation_hook callback:
 */

function dst_rewrite_flush() {
    require_once DEALER_SEARCH_TOOL_DIR . 'includes/custom-post-type.php';
    dst_custom_post_type();

    // ATTENTION: This is *only* done during plugin activation hook in this example!
    // You should *NEVER EVER* do this on every page load!!
    flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'dst_rewrite_flush' );

/**
 * Wrapping the Class Instance into Function
 */
function DST() {
    return Dealer_Search_Tool::instance();
}
// Run the Plugin Instance
DST();



