add_shortcode(); $this->table = 'md_metas';// '". $wpdb->prefix ."allinmenu'; $this->version = '1.1.3'; register_activation_hook(__FILE__, array( $this, 'activate' )); //$this->add_scripts(); //$this->add_styles(); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); //add_action( 'plugins_loaded', array( $this, 'init' ), 10 ); add_action( 'wp_footer', array( $this, 'wp_footer') ); // Add Settings js if ( isset( $_GET['page'] ) && $_GET['page'] == 'all-in-settings' ){ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); } add_action( 'wp_ajax_load_panel_category', array( $this, 'load_panel_category') ); add_action( 'wp_ajax_nopriv_load_panel_category',array( $this, 'load_panel_category') ); add_action( 'wp_ajax_load_panel_post_tag', array( $this, 'load_panel_category') ); add_action( 'wp_ajax_nopriv_load_panel_post_tag',array( $this, 'load_panel_category') ); add_action( 'wp_ajax_load_panel_post', array( $this, 'load_panel_post') ); add_action( 'wp_ajax_nopriv_load_panel_post', array( $this, 'load_panel_post') ); add_action( 'wp_ajax_load_panel_youtube', array( $this, 'load_panel_youtube') ); add_action( 'wp_ajax_nopriv_load_panel_youtube',array( $this, 'load_panel_youtube') ); add_action( 'wp_ajax_load_panel_custom', array( $this, 'load_panel_custom') ); add_action( 'wp_ajax_nopriv_load_panel_custom', array( $this, 'load_panel_custom') ); add_action( 'after_setup_theme', array( $this, 'theme_setup') ); } /**** * Create the table in db to store the menu values * We will create one table to avoid inner joins * */ public function activate(){ global $wpdb; // create the database table if( $wpdb->get_var("show tables like '".$this->table ."'") == null) { require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); $sql = "CREATE TABLE `".$this->table."` ( `md_id` bigint(20) NOT NULL AUTO_INCREMENT, `md_ref` bigint(20) NOT NULL, `md_name` varchar(255), `md_values` text, `md_type` tinyint, PRIMARY KEY (`md_id`), UNIQUE KEY `md_id` (`md_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; dbDelta($sql); $sql = "INSERT INTO `".$this->table."` VALUES ('1', '0', 'Home','{\"type\":\"static\",\"title\":\"Home\",\"values\":{}}','1'), ('2', '0', 'Search','{\"type\":\"search\",\"title\":\"Search\",\"values\":{}}','1')"; dbDelta($sql); } } public function theme_setup(){ add_image_size( 'medium_fixed', 300, 300, true ); // 300 pixels wide (and unlimited height) } /** * Add the menu dash shortcode */ public function add_shortcode() { add_shortcode( 'menu_dash', array( $this, 'do_shortcode' ) ); } /** * Do the shortcode when called in theme */ public function do_shortcode( $atts ){ $atts = shortcode_atts( array( 'id' => '0', ), $atts, 'menu_dash' ); $items = $this->get_menu( $atts['id'] ); // If menu doesn't exists $items will be false so nothing will happen if ( $items ){ $this->export_html( $items ); } } /** * Enqueue scripts and styles */ public function enqueue_scripts(){ wp_enqueue_script( 'all_in_js', plugins_url( 'js/all-in.js', __FILE__ ), array('jquery'), null, true ); wp_localize_script( 'all_in_js', 'Ajax', array( 'url' => admin_url('admin-ajax.php') ) ); //wp_enqueue_script( 'scrollbarjs', plugins_url('js/jquery.mCustomScrollbar.min.js', __FILE__), array('jquery'), true ); //wp_enqueue_script( 'mousewheeljs', plugins_url('js/jquery.mousewheel.min.js', __FILE__), array('jquery'), true ); //jquery.mCustomScrollbar.min wp_enqueue_style( 'all_in_css', plugins_url( 'css/all-in.css', __FILE__ ) ); //wp_enqueue_style( 'scrollbarcss', plugins_url( 'css/jquery.mCustomScrollbar.min.css', __FILE__ ) ); } /** * Enqueue scripts and styles in admin settings page */ public function admin_enqueue_scripts(){ wp_enqueue_script( 'tmpljs', plugins_url( 'js/jquery.tmpl.min.js', __FILE__ ) ,array('jquery'), $this->version, true ); wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_script( 'jquery-ui-draggable' ); wp_enqueue_script( 'jquery-ui-droppable' ); wp_enqueue_script( 'jquery-ui-accordion' ); wp_enqueue_script( 'jquery-ui-tabs'); wp_enqueue_script( 'touch_punch', plugins_url( 'js/jquery.ui.touch-punch.min.js', __FILE__ ) ,array('jquery-ui-tabs'), $this->version, true ); wp_enqueue_media(); wp_enqueue_style( 'all_in_settings_css', plugins_url( 'css/all-in-settings.css', __FILE__ ), null, $this->version ); wp_enqueue_script( 'all_in_settings_js', plugins_url( 'js/all-in-settings.js', __FILE__ ), array('jquery'), $this->version, true ); wp_localize_script( 'all_in_settings_js', 'Ajax', array( 'url' => admin_url('admin-ajax.php') ) ); } /** * With the wp_footer function we print the all the necessary script templates * in the footer of every page */ public function wp_footer(){ //$this->export_html_scripts(); } /** * Get the items of the selected menu */ private function get_items( $atts ){ $taxonomies = array( $atts['term'], ); $args = array( 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => $atts['parent'], 'hierarchical' => true, 'child_of' => 0,//$atts['parent'], 'get' => '', 'name__like' => '', 'description__like' => '', 'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' ); $items = get_terms( $taxonomies, $args ); //var_dump( $items ); return $items; } /** * Decode stored values */ public static function decode_values( $items ){ // DECODE VALUES if ( is_array( $items ) ){ foreach ( $items as &$item ){ $item = json_decode( $item ); } } return $items; } /** * Constructing the menu html to be rendered */ private function export_html( $items ){ // Get the stored settings $settings = get_option('allin_settings'); // Checking if cache exists and is not older than the user defined $cache = $this->check_cache( $items->md_id, $settings ); // If cache is false then we must create a new file if ( $cache === false ){ // Check if is sticky or not $sticky = ( isset( $items->md_values->sticky ) && intval($items->md_values->sticky) == 'checked' ) ? 'sticky' : ''; // Get the color theme $color = isset( $items->md_values->color ) ? $items->md_values->color : 'light'; $html = '
'; $html .= '
'.__( 'Menu', 'allinmenu').'
'; // Print the main menu items $this->export_html_main( $items, $html ); $html .= '
'; if ( $settings['enable'] === 'true' ){ $this->create_cache( $html, $items->md_id ); } } else{ $html = file_get_contents( $cache ); } echo $html; } /** * Export html