Exemplo n.º 1
0
 public static function init()
 {
     //Load LWA options
     self::$data = get_option('lwa_data');
     //Remember the current user, in case there is a logout
     self::$current_user = wp_get_current_user();
     //Get Templates from theme and default by checking for folders - we assume a template works if a folder exists!
     //Note that duplicate template names are overwritten in this order of precedence (highest to lowest) - Child Theme > Parent Theme > Plugin Defaults
     //First are the defaults in the plugin directory
     self::find_templates(path_join(WP_PLUGIN_DIR, basename(dirname(__FILE__)) . "/widget/"));
     //Now, the parent theme (if exists)
     if (get_stylesheet_directory() != get_template_directory()) {
         self::find_templates(get_template_directory() . '/plugins/login-with-ajax/');
     }
     //Finally, the child theme
     self::find_templates(get_stylesheet_directory() . '/plugins/login-with-ajax/');
     //Generate URLs for login, remember, and register
     self::$url_login = self::template_link(site_url('wp-login.php', 'login_post'));
     self::$url_register = self::template_link(self::getRegisterLink());
     self::$url_remember = self::template_link(site_url('wp-login.php?action=lostpassword', 'login_post'));
     //Make decision on what to display
     if (!empty($_REQUEST["lwa"])) {
         //AJAX Request
         self::ajax();
     } elseif (isset($_REQUEST["login-with-ajax-widget"])) {
         //Widget Request via AJAX
         $instance = !empty($_REQUEST["template"]) ? array('template' => $_REQUEST["template"]) : array();
         $instance['profile_link'] = !empty($_REQUEST["lwa_profile_link"]) ? $_REQUEST['lwa_profile_link'] : 0;
         self::widget($instance);
         exit;
     } else {
         //Enqueue scripts - Only one script enqueued here.... theme JS takes priority, then default JS
         if (!is_admin()) {
             $js_url = defined('WP_DEBUG') && WP_DEBUG ? 'login-with-ajax.source.js' : 'login-with-ajax.js';
             wp_enqueue_script("login-with-ajax", self::locate_template_url($js_url), array('jquery'));
             wp_enqueue_style("login-with-ajax", self::locate_template_url('widget.css'));
         }
         //Add logout/in redirection
         add_action('wp_logout', 'LoginWithAjax::logoutRedirect');
         add_action('logout_url', 'LoginWithAjax::logoutUrl');
         add_action('login_redirect', 'LoginWithAjax::loginRedirect', 1, 3);
         add_shortcode('login-with-ajax', 'LoginWithAjax::shortcode');
         add_shortcode('lwa', 'LoginWithAjax::shortcode');
     }
 }