table = 'md_metas';// '". $wpdb->prefix ."allinmenu'; // Set the serialize variable; $this->deprecated_php = version_compare("5.4.0", phpversion()) >= 0 ? true : false ; add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'wp_ajax_allin_save_settings', array( $this, 'save_settings') ); add_action( 'wp_ajax_allin_search_posts', array( $this, 'search_posts' ) ); add_action( 'wp_ajax_allin_save_options', array( $this, 'save_options' ) ); add_action( 'wp_ajax_allin_flush_cache', array( $this, 'flush_cache' ) ); add_action( 'wp_ajax_md_add_menu', array( $this, 'add_menu') ); add_action( 'wp_ajax_md_get_menus', array( $this, 'get_menus') ); add_action( 'wp_ajax_md_add_component', array( $this, 'add_component') ); add_action( 'wp_ajax_md_delete_component', array( $this, 'delete_component') ); add_action( 'wp_ajax_md_update_component', array( $this, 'update_component') ); add_action( 'wp_ajax_md_get_components', array( $this, 'get_components') ); add_action( 'wp_ajax_md_update_menu', array( $this, 'update_menu') ); add_action( 'wp_ajax_md_get_items', array( $this, 'get_items') ); } //RENAME TABLE `md_metas` TO `$wpdb->prefix .allinmenu`; /**** * ADMINISTRATION PAGE * This page contains all the function to create and edit menus and tabs */ public function admin_menu () { add_menu_page( 'All-In-Menu Settings', 'All-In-Menu Settings', 'manage_options', 'all-in-settings', array( $this, 'all_in_settings'), plugins_url( 'images/page_icon.jpg', __FILE__ ) ); } /**** * START RENDER SETTINGS HTML */ public function all_in_settings () { // Load the stored settings $html = '
'; // The main menu of the setting page $this->settings_side_menu( $html ); // General Settings for Menu Dashboard $this->general_settings( $html ); // Export the tab for menus management $this->manage_menus( $html ); // Export the tab for tabs (components) management $this->manage_components( $html ); // The popup editor $this->edit_popup( $html ); // Add the html indicators ( Loader + Message box ); $this->html_indicators( $html ); // The script templates used in the administration page $html .= $this->script_templates(); $html .= '
'; // Echos the HTML from the previous functionality. // This is the UNIQUE echo in the page echo $html; } /**** * MAIN MENU OF THE SETTING PAGE * Contains the main menu of the settings page shown as left sidebar * asychronous altering the interface between the following states: * GENERAL : Settings about the plugin * MENUS : Menus management (create, edit, delete) * TABS : The tabs are the menu components. At least one tab must be created * in order to connect it one already created menu. */ protected function settings_side_menu( &$html ){ $html .= ' '; } /**** * GENERAL SETTING * This function contains the html for the general settings. These are: * */ protected function general_settings( &$html ){ // Get already submitted options $settings = get_option('allin_settings'); $html .= '

General Settings

Settings for all menus

'; $html .= '
'; // Enable cache checkbox $enabled = $settings['enable'] == 'true' ? 'checked="checked"' : ''; $html .= '
'; // Expiry cache select option $expiry = $settings['expiry']; $expiry_values = array( '3600' => '1 hour', '7200' => '2 hours', '21600' => '6 hours', '86400' => '1 day', '172800' => '2 days', '604800' => '1 week', '315360000' => 'never (until flush cache)', ); $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; } /**** * MENUS MANAGEMENT * This function has three main parts. * - Add new menu * - Available tabs (components) * - Menus List */ protected function manage_menus( &$html ){ $html .= '
'; $html .= '

Menus

Create and manipulate menus

'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; } /**** * TABS (COMPONENTS) MANAGEMENT * The tabs (components) are parts of a menu. One menu can have one or more tabs * and a tab can be part of more than one menu. One menu is a unordered list () * and a tab is one list item (
  • ). There are several tab types that the user can * create and this can be done in the following interface. */ protected function manage_components( &$html ){ $html .= '

    Tabs (Components)

    Create Tabs for your menus

    '; $html .= '
    '; $html .= '
    '; // The container hosting each component submission form $html .= '
    '; // Create the placeholders $html .= '
    '; $html .= $this->placeholder_toolbar(); $html .= '
    '; // Show the already submitted components $html .= '
    '; $html .= '
    '; // END OF div.md_settings_inside $html .= '
    '; } /**** * POPUP EDITOR HTML * This function returns the html for the editor popup editor * Editor popup is an empty div with a submit button filled with * the appropriate form template (and values) for editing */ protected function edit_popup( &$html ){ $html .= '
    Edit values
    '; } /**** * HTML INDICATORS * The function ontains and export two empty divs. * The first one is the md_loader div which is an full page overlay visible * when ajax requests are in progress and the second is the message indicator is * a position absolute div, visible when a message to the user must be shown. */ protected function html_indicators( &$html ){ $html .= '
    '; } /**** * RETURNS THE TERMS OF A TAXONOMY * This function returns an array from the get_terms() wordpress function */ protected function get_taxonomy( $type ){ $taxonomies = array( $type, ); $args = array( 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => 0, 'hierarchical' => true, 'child_of' => '',//$atts['parent'], 'get' => '', 'name__like' => '', 'description__like' => '', 'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' ); $items = get_terms( $taxonomies, $args ); return $items; } /**** * THE TOOLBAR IN THE CUSTOM MENU TAB SECTION * This function contains the html with the tools available in the creation * of the custom menu tab (Tabs Section). */ protected function placeholder_toolbar(){ $html = '
    '; $html .= '
    '; return $html; } /**** * CREATE A SELECT HTML TAG * The function accepts three parameters and creates a select html tag: * The first one is an array containing the total * */ protected function create_term_select_tag( $terms, $name, $data = array() ){ foreach ( $data as $k => &$d ){ $d = 'data-'.$k.'="'.$d.'"'; } $html = '
    '; return $html; } /**** * CREATE AN INPUT HTML TAG * The function accepts three parameters and creates an input html tag: * The first one is the type of input produced input tag (e.x. hidden). The second * is the name attribute of the tag and the third the data-values attributes. * The following parameters for example: * $type = 'text'; * $data = array( * 'need' => 'required', * 'id' => 27, * ); * create_input_tag( $type, 'the_selected_name', $data ) * will create the following input tag: * */ protected function create_input_tag( $type, $name, $data = array(), $label = '', $class = '', $placeholder = '' ){ // Looping the $data array converting values to data-key="value" format foreach ( $data as $k => &$d ){ $d = 'data-'.$k.'="'.$d.'"'; } // Create a unique id for the input $id = $type .'_'. $name .'_'. rand( 1, 99999999); // Generate the html with the input tag $html = ''; // If label is set then add the