/** * Constructor Method. */ public function __construct() { // This plugin depends on the base plugin being installed. It can't do anything without it. if ($this->_dependency_check()) { // Set some useful options and stuff $this->core = agora_core_framework::get_instance(); $this->input = new agora_input_framework($this->core); $this->plugin_basename = plugin_basename(__FILE__); $this->plugin_dir = dirname(__FILE__); $this->plugin_admin_page = 'agora-middleware-authentication'; $this->config_name = 'agora-middleware-auth-config'; $this->file_protection = new agora_file_access(); // Load the base config from file $base_config = parse_ini_file(dirname(__FILE__) . '/default_config.ini'); // Default options are kept in the default_config.ini $this->config = $this->core->wp->get_option($this->config_name, $base_config); // Set up dependencies $this->core->user = new agora_middleware_user($this->core); $this->pubcodes = new agora_pubcode_authentication(include_once dirname(__FILE__) . '/config/authcode_config.php'); $this->core->authentication = $this->pubcodes; $this->core->security = new agora_login_security($this->core->mw, $this->config['rate_limiting']); // Add the theme folder from this plugin to the view framework. // Ideally the templates should be copied to the sites actual theme folder $this->core->view->set_template_path(dirname(__FILE__) . '/theme'); $this->core->view->set_template_path($this->plugin_dir . '/views'); // Wordpress API Hooks $this->_wordpress_hooks(); } }
/** * Constructor */ public function __construct($config = null) { $this->field_structure = $config['field_structure']; $this->auth_types = $config['auth_types']; $this->auth_type_locations = $config['auth_type_locations']; $this->plugin_dir = dirname(__FILE__) . '/..'; $this->core = agora_core_framework::get_instance(); add_filter('agora_middleware_check_permission', array($this, 'check_permission'), $this->priority, 2); add_action('agora_authentication_disable_cache', array($this, 'disable_cache')); add_filter('agora_get_login_url', array($this, 'get_login_url'), 0, 1); }
/** * @param $authcode Accepts an stdClass or an Integer * If stdClass it assumes Wordpress taxonomy properties and adds those properties to the object * If integer, it fetches the term from the database and initialises itself with the term data. */ function __construct($authcode = null) { $this->core = agora_core_framework::get_instance(); if ($authcode == null) { return; } elseif (is_array($authcode) or is_object($authcode)) { foreach ($authcode as $key => $value) { $this->{$key} = $value; } $this->get_type(); $this->get_advantage_code(); $this->get_rules(); } else { $x = get_term_by('id', $authcode, 'pubcode'); $this->__construct($x); } }
/** * Do the actual conversions. */ function convert() { add_action('pre_user_query', array($this, 're_parse_query')); global $wpdb; // We only want subscribers with "@agora-middleware.com" in their email addresses. This gives us only // unconverted users, allows restarting without any other logic, and prevents overwriting data. $users = new WP_User_Query(array('orderby' => 'ID', 'search' => '*@agora-middleware.com', 'search_columns' => array('user_email'), 'meta_query' => '')); $core = agora_core_framework::get_instance(); $errors = array(); $i = 0; foreach ($users->get_results() as $user) { echo "--------------------------------------------------\n"; echo "USER ID: "; print_r($user->ID); echo " -- LOGIN: "******"\n"; if ((int) $user->user_login == 0) { echo '*** User ID not numeric, probably not old MW plugin user.'; continue; } // Original Middleware if ($user->user_login != $user->user_nicename) { if (strpos($user->user_email, '@agora-middleware.com') !== false) { $query = $wpdb->prepare("UPDATE wp_users SET user_email = %s WHERE user_login = %s", str_replace('@agora-middleware.com', '@agora-middleware-PROCESSED.com', $user->user_email), $user->user_login); $wpdb->query($query); } echo 'Login and nicename missmatch for user ID: ' . $user->ID . "\n"; continue; } // Verify that the email address needs conversion. Anthing that's not '@agora-middleware.com' should be skipped. // (And yes, the user query shouldn't even pull them is. This is insurance.) if ($user->user_email != $user->user_login . '@agora-middleware.com') { echo "Email was did not contain '@agora-middleware.com' for user ID: " . $user->ID . "\n"; continue; } $update_user_name = $core->mw->get_customer_by_id($user->data->user_login); $update_customer_name = $core->mw->get_customer_address_by_id($user->data->user_login); // We got valid results form MW2, so process if (!is_wp_error($update_customer_name) && !is_wp_error($update_user_name)) { // WordPress likes lowercase user names, so we will force that. $new_user_login = strtolower($update_user_name[0]->id->userName); // Make sure username is valid. if (!validate_username($new_user_login)) { if (strpos($user->user_email, '@agora-middleware.com') !== false) { $query = $wpdb->prepare("UPDATE wp_users SET user_email = %s WHERE user_login = %s", str_replace('@agora-middleware.com', '@agora-middleware-INVALID_USER_NAME.com', $user->user_email), $user->user_login); //$wpdb->query( $query ); } echo 'New username is invalid: ' . $user->ID . " -- NEW USER LOGIN: {$new_user_login}\n"; continue; } // Make sure username isn't a duplicate. if (username_exists($new_user_login)) { if (strpos($user->user_email, '@agora-middleware.com') !== false) { $query = $wpdb->prepare("UPDATE wp_users SET user_email = %s WHERE user_login = %s", str_replace('@agora-middleware.com', '@agora-middleware-DUPE_USER_NAME.com', $user->user_email), $user->user_login); $wpdb->query($query); } echo 'New username is a duplicate: ' . $user->ID . "NEW USER LOGIN: {$new_user_login}\n"; continue; } $customer_number = $update_customer_name[0]->id->customerNumber; // Do not overwrite display name if set differently than login (MW ID) $new_display_name = $user->display_name; if ($user->display_name == $user->user_login) { $new_display_name = trim($update_customer_name[0]->firstName) . " " . $update_customer_name[0]->lastName[0] . '.'; } // user_nicename needs to be sanitized first, since it's used in $new_user_nicename = sanitize_title($new_user_login); // Get the email. $new_user_email = $update_customer_name[0]->emailAddress->emailAddress; if ($new_user_email == '') { $new_user_email = str_replace('@agora-middleware.com', '@agora-middleware-UPDATED.com', $user->user_email); } $query = $wpdb->prepare("UPDATE wp_users SET user_login = %s, display_name = %s, user_nicename = %s, user_email = %s WHERE user_login = %s", $new_user_login, $new_display_name, $new_user_nicename, $new_user_email, $customer_number); $wpdb->query($query); echo 'UPDATED TO: ' . $new_user_login . "\n"; // Clear some caches, just in case. wp_cache_delete($user->ID, 'users'); wp_cache_delete($user->user_login, 'userlogins'); wp_cache_delete(sanitize_user($new_user_login), 'userlogins'); // There was a problem. Note the error. } else { echo "ERROR INFORMATION: \n"; echo "update_user_name: \n"; print_r($update_user_name); echo "update_customer_name: \n"; print_r($update_customer_name); $query = $wpdb->prepare("UPDATE wp_users SET user_email = %s WHERE user_login = %s", str_replace('@agora-middleware.com', '@agora-middleware-ERROR.com', $user->user_email), $user->user_login); $wpdb->query($query); } } }
/** * Constructor */ function __construct() { parent::__construct('agora_login_widget', __('Middleware Login Widget'), array('description' => __('Use this widget to place a login box in your sidebars'))); $this->core = agora_core_framework::get_instance(); }