__construct();}
/**
* PHP 5 Constructor
*/
function __construct() {
$name = dirname(plugin_basename(__FILE__));
//Language Setup
load_plugin_textdomain('simplemodal-login', false, "$name/I18n/");
//"Constants" setup
$this->pluginurl = WP_PLUGIN_URL . "/$name/";
$this->pluginpath = WP_PLUGIN_DIR . "/$name/";
//Initialize the options
$this->get_options();
//Actions
add_action('admin_menu', array(&$this, 'admin_menu_link'));
if (!is_admin()) {
add_filter('login_redirect', array(&$this, 'login_redirect'), 5, 3);
add_filter('register', array(&$this, 'register'));
add_filter('loginout', array(&$this, 'login_loginout'));
add_action('wp_footer', array($this, 'login_footer'));
add_action('wp_print_styles', array(&$this, 'login_css'));
add_action('wp_print_scripts', array(&$this, 'login_js'));
}
}
/**
* @desc Adds the options subpanel
*/
function admin_menu_link() {
add_options_page('SimpleModal Login', 'SimpleModal Login', 'manage_options', basename(__FILE__), array(&$this, 'admin_options_page'));
add_filter('plugin_action_links_' . plugin_basename(__FILE__), array(&$this, 'filter_plugin_actions'), 10, 2 );
}
/**
* @desc Adds settings/options page
*/
function admin_options_page() {
if (isset($_POST['simplemodal_login_save'])) {
check_admin_referer($this->nonce);
$this->options['theme'] = $_POST['theme'];
$this->options['shortcut'] = (isset($_POST['shortcut']) && $_POST['shortcut'] === 'on') ? true : false;
$this->options['registration'] = (isset($_POST['registration']) && $_POST['registration'] === 'on') ? true : false;
$this->options['reset'] = (isset($_POST['reset']) && $_POST['reset'] === 'on') ? true : false;
$this->save_admin_options();
echo '
' . __('Success! Your changes were successfully saved!', 'simplemodal-login') . '
';
}
?>
SimpleModal Login vversion; ?>
simplemodal-login plugin directory: css/THEME.css and js/THEME.js. Replace THEME with the name you would like to use. I suggest using one of the existing themes as a template.', 'simplemodal-login'); ?>
WordPress Forum'); ?>
optionsName)) {
// default options for a clean install
$options = array(
'shortcut' => true,
'theme' => 'default',
'version' => $this->version,
'registration' => $this->users_can_register,
'reset' => true
);
update_option($this->optionsName, $options);
}
else {
// check for upgrades
if (isset($options['version'])) {
if ($options['version'] < $this->version) {
// post v1.0 upgrade logic goes here
}
}
else {
// pre v1.0 updates
if (isset($options['admin'])) {
unset($options['admin']);
$options['shortcut'] = true;
$options['version'] = $this->version;
$options['registration'] = $this->users_can_register;
$options['reset'] = true;
update_option($this->optionsName, $options);
}
}
}
return $options;
}
/**
* @desc Adds the Settings link to the plugin activate/deactivate page
* @return string
*/
function filter_plugin_actions($links, $file) {
$settings_link = '' . __('Settings', 'simplemodal-login') . '';
array_unshift($links, $settings_link); // before other links
return $links;
}
/**
* @desc Retrieves the plugin options from the database.
*/
function get_options() {
$options = $this->check_options();
$this->options = $options;
}
/**
* @desc Determines if request is an AJAX call
* @return boolean
*/
function is_ajax() {
return isset($_SERVER['HTTP_X_REQUESTED_WITH'])
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
}
/**
* @desc Checks to see if the given plugin is active.
* @return boolean
*/
function is_plugin_active($plugin) {
return in_array($plugin, (array) get_option('active_plugins', array()));
}
/**
* @desc Enqueue's the CSS for the specified theme.
*/
function login_css() {
$style = sprintf('%s.css', $this->options['theme']);
wp_enqueue_style('simplemodal-login', $this->pluginurl . "css/$style", false, $this->version, 'screen');
if (false !== @file_exists(TEMPLATEPATH . "simplemodal-login-$style")) {
wp_enqueue_style('simplemodal-login-form', get_template_directory_uri() . $style, false, $this->version, 'screen');
}
}
/**
* @desc Builds the login, registration, and password reset form HTML.
* Calls filters for each form, then echo's the output.
*/
function login_footer() {
$output = '';
$login_form = $this->login_form();
$output .= apply_filters('simplemodal_login_form', $login_form);
if ($this->users_can_register && $this->options['registration']) {
$registration_form = $this->registration_form();
$output .= apply_filters('simplemodal_registration_form', $registration_form);
}
if ($this->options['reset']) {
$reset_form = $this->reset_form();
$output .= apply_filters('simplemodal_reset_form', $reset_form);
}
$output .= '
';
echo $output;
}
/**
* @desc Builds the login form HTML.
* If using the simplemodal_login_form filter, copy and modify this code
* into your function.
* @return string
*/
function login_form() {
$output = sprintf('
';
return $output;
}
/**
* @desc Responsible for loading the necessary scripts and localizing JavaScript messages
*/
function login_js() {
global $wp_scripts;
if (isset($wp_scripts->registered['jquery-simplemodal'])
&& version_compare($wp_scripts->registered['jquery-simplemodal']->ver, $this->simplemodalVersion) === -1) {
wp_deregister_script('jquery-simplemodal'); // remove older versions
}
wp_enqueue_script('jquery-simplemodal', $this->pluginurl . 'js/jquery.simplemodal.js', array('jquery'), $this->simplemodalVersion, true);
$script = sprintf('js/%s.js', $this->options['theme']);
wp_enqueue_script('simplemodal-login', $this->pluginurl . $script, null, $this->version, true);
wp_localize_script('simplemodal-login', 'SimpleModalLoginL10n', array(
'shortcut' => $this->options['shortcut'] ? 'true' : 'false',
'logged_in' => is_user_logged_in() ? 'true' : 'false',
'admin_url' => get_admin_url(),
'empty_username' => __('ERROR: The username field is empty.', 'simplemodal-login'),
'empty_password' => __('ERROR: The password field is empty.', 'simplemodal-login'),
'empty_email' => __('ERROR: The email field is empty.', 'simplemodal-login'),
'empty_all' => __('ERROR: All fields are required.', 'simplemodal-login')
));
}
/**
* @desc loginout filter that adds the simplemodal-login class to the "Log In" link
* @return string
*/
function login_loginout($link) {
if (!is_user_logged_in()) {
$link = str_replace('href=', 'class="simplemodal-login" href=', $link);
}
return $link;
}
/**
* @desc login_redirect filter that determines where to redirect the user.
* Supports Peter's Login Redirect plugin, if enabled.
* @return string
*/
function login_redirect($redirect_to, $req_redirect_to, $user) {
if (!isset($user->user_login) || !$this->is_ajax()) {
return $redirect_to;
}
if ($this->is_plugin_active('peters-login-redirect/wplogin_redirect.php')
&& function_exists('redirect_to_front_page')) {
$redirect_to = redirect_to_front_page($redirect_to, $req_redirect_to, $user);
}
echo "$redirect_to
";
exit();
}
/**
* @desc register filter that adds the simplemodal-register class to the "Register" link
* @return string
*/
function register($link) {
if ($this->users_can_register && $this->options['registration']) {
if (!is_user_logged_in()) {
$link = str_replace('href=', 'class="simplemodal-register" href=', $link);
}
}
return $link;
}
/**
* @desc Builds the registration form HTML.
* If using the simplemodal_registration_form filter, copy and modify this code
* into your function.
* @return string
*/
function registration_form() {
$output = sprintf('
';
return $output;
}
/**
* @desc Builds the reset password form HTML.
* If using the simplemodal_reset_form filter, copy and modify this code
* into your function.
* @return string
*/
function reset_form() {
$output = sprintf('
';
return $output;
}
/**
* Saves the admin options to the database.
*/
function save_admin_options(){
return update_option($this->optionsName, $this->options);
}
}
}
// instantiate the class
if (class_exists('SimpleModalLogin')) {
$simplemodal_login = new SimpleModalLogin();
$simplemodal_login->users_can_register = get_option('users_can_register') ? true : false;
}
/*
* The format of this plugin is based on the following plugin template:
* http://pressography.com/plugins/wordpress-plugin-template/
*/
?>