*/ class Ae_Connect_Admin { /** * The options name to be used in this plugin * * @since 1.0.0 * @access public * @var string $option_name Option name of this plugin */ public $option_name = 'ae_connect'; /** * The ID of this plugin. * * @since 1.0.0 * @access public * @var string $plugin_name The ID of this plugin. */ public $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $sections Plugin's admin sections */ private $sections; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $sections Plugin's admin fields */ private $fields; private $AE_Notices; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ public function __construct($plugin_name, $version) { include_once 'class-ae-connect-fields.php'; include_once 'class-ae-connect-sections.php'; include_once 'class-ae-connect-initialize.php'; include_once 'ae_notices.php'; $this->plugin_name = $plugin_name; $this->version = $version; $AE_Connect_Sections = new AE_Connect_Sections($this); $AE_Connect_Fields = new AE_Connect_Fields($this); $this->sections = $AE_Connect_Sections->sections; $this->fields = $AE_Connect_Fields->get_fields(); $this->AE_Notices = new AE_Notices(); } /** * called via Ajax */ public function initialize_ae() { $api_key = get_option("{$this->option_name}_api_key"); if($api_key) { $Init = new Initialize(); $Init->ae_connect_init_with_api_key($api_key); } else { echo 'api key not set'; } wp_die(); } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { /** * * An instance of this class should be passed to the run() function * defined in Ae_Connect_Loader as all of the hooks are defined * in that particular class. * * The Ae_Connect_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/ae-connect-admin.css', array(), time(), 'all'); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts() { /** * * An instance of this class should be passed to the run() function * defined in Ae_Connect_Loader as all of the hooks are defined * in that particular class. * * The Ae_Connect_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_script($this->plugin_name."_scgenerator", plugin_dir_url(__FILE__) . 'js/ae-connect-shortcode-generator.js', array('jquery'), $this->version, false); wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/ae-connect-admin.js', array('jquery'), $this->version, false); wp_localize_script($this->plugin_name, 'ajax_object', array('ajax_url' => admin_url('admin-ajax.php'), 'ajaxnonce' => wp_create_nonce('ajax_post_validation'))); } /** * render the ae_connect plugin menu * */ public function ae_connect_plugin_menu() { // Add the main plugin menu Link $page_title = __('AE Connect Settings', 'ae-connect'); $menu_title = __('AE Connect Settings', 'ae-connect'); $capability = 'manage_options'; $menu_slug = $this->plugin_name; $function = array($this, 'display_options_page'); $icon_url = ''; $position = 15; add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); // If the AE Framework has been properly initialized then load the subpages if (get_option('ae_connect_initialization') === 'OK') { // add Social Registration submenu page: add_submenu_page( $this->plugin_name, __('General', 'ae-connect'), __('General', 'ae-connect'), 'manage_options', $this->plugin_name . '-general-settings', array($this, 'display_general_page') ); add_submenu_page( $this->plugin_name, __('Popup Styling', 'ae-connect'), __('Popup Styling', 'ae-connect'), 'manage_options', $this->plugin_name . '-popup-settings', array($this, 'display_popup_page') ); add_submenu_page( $this->plugin_name, __('Performance', 'ae-connect'), __('Performance', 'ae-connect'), 'manage_options', $this->plugin_name . '-performance', array($this, 'display_performance_page') ); add_submenu_page( $this->plugin_name, __('Shortcode Generator', 'ae-connect'), __('Shortcode Generator', 'ae-connect'), 'manage_options', $this->plugin_name . '-shortcode-generator', array($this, 'display_shortcode_generator_page') ); add_submenu_page( $this->plugin_name, __('Shortcode Help', 'ae-connect'), __('Shortcode Help', 'ae-connect'), 'manage_options', $this->plugin_name . '-shortcode-help', array($this, 'display_shortcode_help_page') ); } } public function display_options_page() { include_once 'partials/ae-connect-admin-display.php'; } public function display_general_page() { include_once 'partials/ae-connect-admin-general-display.php'; } public function display_popup_page() { include_once 'partials/ae-connect-admin-popup-display.php'; } public function display_performance_page() { include_once 'partials/ae-connect-admin-performance-display.php'; } public function display_shortcode_generator_page() { include_once 'partials/shortcode-generator/ae-connect-admin-shortcode-generator.php'; } public function display_shortcode_help_page() { include_once 'partials/ae-connect-admin-shortcode-help.php'; } /** * Render all of the settings for the AE Connect Admin * Action is loaded in the class-ae-connect.php file * @return null */ public function ae_connect_register_all_settings() { // Register sections foreach ($this->sections as $sub_sections) { $this->render_sections($sub_sections); } // Register fields foreach ($this->fields as $sub_fields) { $this->render_fields($sub_fields); } } /** * A function which renders a list of sections * @param array $sections a list of sections * @return null */ public function render_sections($sections) { foreach ($sections as $section) { $id = $section['id']; $title = $section['title']; $callback = $section['callback']; $page = $section['page']; add_settings_section($id, $title, $callback, $page); } } /** * A function which renders a list of fields * @param array $fields a list of fields * @return null */ public function render_fields($fields) { foreach ($fields as $field) { $id = $field['id']; $title = $field['title']; $callback = $field['callback']; $page = $field['page']; //happens to be the same as the $options_group $section = $field['section']; $args = $field['args']; add_settings_field($id, $title, $callback, $page, $section, $args); register_setting($page, $this->option_name . $args['label'], array($this, $args['sanitize'])); } register_setting('ae-connect-general-opt-ins', 'ae-connect-general-opt-ins', array($this, 'sanitize_opt_ins')); } /** * A generic callback to display section content * @return null */ public function ae_connect_display_generic_section() { echo ''; } public function ae_connect_display_socials_section() { // echo // "
// Note: If you just finished creating a social application visit the AE Connect Settings page and press 'Save Changes'. Presto: Your new social app will appear on this page. //
"; echo " "; } public function ae_connect_display_email_options_section() { echo "Note: If you check \"Site Requires Verified Email Before Login\" then you must also check \"Send Email Verification During Registration\". Otherwise, it is expected that you have the developer skills to handle sending verification emails manually, through aeJS or other methods.
"; } public function ae_connect_button($args) { $label = $args['label']; $onclickFunction = $args['onclick']; $onclick = isset($onclickFunction) ? "onclick='{$onclickFunction};'" : ""; $btn = "{$label}"; echo $btn; } public function ae_connect_cb($args) { $label = $args['label']; $cb_checked = get_option($this->option_name . $label); $input_tag = $input_tag = 'option_name . $label . '"' . ' > '; // Check for default value // A field will only have a default value if it is TRUE by default // or FALSE and aeJS is True by default if (!$cb_checked && array_key_exists('default', $args)) { $default = $args['default']; if ($default == "on") { $input_tag = 'option_name . $label . '"' . "checked" . ' > '; } // Set default value in the DB update_option($this->option_name . $label, $default); } if ($cb_checked == "on") { $input_tag = 'option_name . $label . '"' . "checked" . ' > '; update_option($this->option_name . $label, $cb_checked); } elseif ($cb_checked === '') { $input_tag = 'option_name . $label . '"' . ' > '; update_option($this->option_name . $label, $cb_checked); } echo $input_tag; } // Render generic sections' text field public function ae_connect_text_field($args) { $label = $args['label']; $size = $args['size']; $txt = get_option($this->option_name . $label) ? get_option($this->option_name . $label) : ''; $default_value = ''; $placeholder = ''; // if the user input is blank, fill with the default if there exists one. if (array_key_exists('placeholder_txt', $args) && empty($txt)) { $placeholder = $args['placeholder_txt']; } if (array_key_exists('default', $args) && empty($txt)) { $default_value = $args['default']; $txt = $default_value; } echo 'option_name . $label . '"' . ' value="' . htmlentities($txt, ENT_QUOTES, 'UTF-8') . '"' . ' > '; // if this field has a label for the input