/** * Parses the return values from vcita connection * @since 0.1.0 */ function ls_parse_vcita_callback() { $success = $_GET['success']; $uid = $_GET['uid']; $first_name = $_GET['first_name']; $last_name = $_GET['last_name']; $title = $_GET['title']; $confirmation_token = $_GET['confirmation_token']; $confirmed = $_GET['confirmed']; $engage_delay = $_GET['engage_delay']; $implementation_key = $_GET['implementation_key']; $email = $_GET['email']; ls_set_settings(array('vcita_connected' => true, 'vcita_params' => array('success' => $success, 'uid' => $uid, 'first_name' => $first_name, 'last_name' => $last_name, 'title' => $title, 'confirmation_token' => $confirmation_token, 'confirmed' => $confirmed, 'engage_delay' => $engage_delay, 'implementation_key' => $implementation_key, 'email' => $email))); $ls_helpers = $this->ls_helpers; // Replace curly brace tags inside of html code // $ls_helpers->ls_replace_default_tags(); $redirect_url = $ls_helpers->get_plugin_path(); ?> <script type="text/javascript"> window.location = "<?php echo $redirect_url; ?> "; </script> <?php }
/** * Parses the return values from vcita connection * @since 0.1.0 */ function ls_parse_vcita_callback() { $success = sanitize_text_field($_GET['success']); $uid = sanitize_text_field($_GET['uid']); $first_name = sanitize_text_field($_GET['first_name']); $last_name = sanitize_text_field($_GET['last_name']); $title = sanitize_text_field($_GET['title']); $confirmation_token = sanitize_text_field($_GET['confirmation_token']); $confirmed = sanitize_text_field($_GET['confirmed']); $engage_delay = sanitize_text_field($_GET['engage_delay']); $implementation_key = sanitize_text_field($_GET['implementation_key']); $email = sanitize_email($_GET['email']); ls_set_settings(array('vcita_connected' => true, 'vcita_params' => array('success' => $success, 'uid' => $uid, 'first_name' => $first_name, 'last_name' => $last_name, 'title' => $title, 'confirmation_token' => $confirmation_token, 'confirmed' => $confirmed, 'engage_delay' => $engage_delay, 'implementation_key' => $implementation_key, 'email' => $email))); $redirect_url = $ls_helpers->get_plugin_path(); ?> <script type="text/javascript"> window.location = "<?php echo $redirect_url; ?> "; </script> <?php }
/** * Create Settings Page * @since 0.1.0 */ function ls_settings_setup() { $ls_helpers = $this->ls_helpers; // Setup small link on wordpress plugins page that directs user to settings page add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); /* Add settings menu page */ $settings_page = add_menu_page('LiveSite Pack', 'LiveSite', 'manage_options', 'live-site', array($this, 'ls_settings_page'), plugin_dir_url(__FILE__) . 'images/vcita-icon.png', '2.3489'); $os = $ls_helpers->get_os(); // For popular os (unix) if ($os != 'win32') { define('LS_SLASH', '/'); } else { define('LS_SLASH', '\\'); } // If settings don't exist in db set them up from defaults if (!ls_get_settings()) { ls_init_default_settings(); } // Check if vcita is not connected // If old connection details are in place use them if (!ls_is_vcita_connected()) { $old_plugin_db_key = $ls_helpers->get_old_plugin_db_key(); // Get old plugin connection details $old_connection_options = get_option($old_plugin_db_key); // Setup connection details if ($old_connection_options) { ls_parse_old_plugin_params($old_connection_options); // Flag plugin as upgraded plugin so we know not to auto install module pages ls_set_settings(array('plugin_upgraded' => true)); $vcita_params = ls_get_vcita_params(); // Set value of active engage widget to the same value as the old plugin if (isset($vcita_params['engage_active'])) { ls_set_module_data('livesite_widget', array('show_livesite' => $vcita_params['engage_active'])); } $redirect_url = $ls_helpers->get_plugin_path(); wp_redirect($redirect_url); exit; } } // Only show modules and settings if we're connected to vcita if (ls_is_vcita_connected()) { require_once 'system/settings_page.php'; require_once 'system/backoffice_page.php'; $this->init_modules(); $main_module = ls_get_main_module(); $settings = ls_get_settings(); // For a one time redirect after vcita connect if (!$settings['plugin_initially_activated']) { // Set plugin as already activated, this only allows it to happen once when we connect to vcita ls_set_settings(array('plugin_initially_activated' => true)); // Get main module data $module_data = ls_get_module_data($main_module); // Redirect to main module page $plugin_page_url = $ls_helpers->get_plugin_page_url($module_data['slug']); wp_redirect($plugin_page_url); exit; } } /* Vars */ $page_hook_id = $this->setings_page_id(); /* Do stuff in settings page, such as adding scripts, etc. */ if (!empty($settings_page)) { /* Load the JavaScript needed for the settings screen. */ add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); add_action('admin_enqueue_scripts', array($this, 'enqueue_styles')); } }
/** * Remove custom page when user deletes page through wordpress and not through plugin * @since 0.1.0 */ function remove_custom_page($page_id) { $module_data = $this->module_data; $module_name = $this->module_name; if ($page_id == $module_data['custom_page_id']) { ls_set_settings(array('modules' => array($module_name => array('custom_page_id' => false)))); } return true; }
/** * Settings * Activates module using ajax call * @since 0.1.0 */ function ls_update_livesite_status() { $nonce = $_POST['nonce']; $status = false; // check to see if the submitted nonce matches with the // generated nonce we created earlier if (!wp_verify_nonce($nonce, 'module-page')) { die('Unauthorized attempt'); } // If you need to pass in extra information $show_livesite = $_POST['show_livesite']; if (isset($show_livesite)) { ls_set_settings(array('modules' => array('livesite_widget' => array('show_livesite' => filter_var($show_livesite, FILTER_VALIDATE_BOOLEAN))))); } $status = true; header("Content-Type: application/json"); echo json_encode($status); exit; }
/** * Settings * Setup user connection based on old plugin params for when we upgrade the old plugin * @param: $params{Array} * @since 0.1.0 */ function ls_parse_old_plugin_params($params) { ls_set_settings(array('vcita_connected' => true, 'vcita_params' => array('success' => 1, 'uid' => $params['uid'], 'first_name' => $params['first_name'], 'last_name' => $params['last_name'], 'title' => $params['title'], 'confirmation_token' => $params['confirmation_token'], 'confirmed' => $params['confirmed'], 'engage_delay' => 5, 'implementation_key' => $params['implementation_key'], 'email' => $params['email'], 'engage_active' => filter_var($params['engage_active'], FILTER_VALIDATE_BOOLEAN)))); delete_option('vcita_paypal_payment_button'); }
/** * Utility: Helper * Create a custom page for the given module once per plugin init * * @param: $module_name{String}, * @return: String * @since 0.1.0 */ function generate_custom_page_once($module_name = false) { if ($module_name) { $module_data = ls_get_module_data($module_name); // Get custom page id returns false if does not exist $custom_page_id = $module_data['custom_page_id']; $custom_page_previously_created = $module_data['custom_page_previously_created']; // If custom page id does not exist and was not previously created if (!$custom_page_id && !$custom_page_previously_created) { // Get random content method knows how to handle single string and array $custom_page_content = $this->get_random_page_content($module_data['custom_page_content']); // Add the modules custom page $page_id = $this->add_wp_page($module_data['custom_page_title'], $custom_page_content); // Only if page was added define the new page id in the plugins settings if ($page_id) { ls_set_settings(array('modules' => array($module_name => array('custom_page_id' => $page_id, 'custom_page_previously_created' => true)))); } } return $custom_page_previously_created; } }