' . __('Update now!', 'nextend-facebook-connect') . '');
}
}
public static function noticeUpdatePro() {
if (is_admin() && current_user_can('manage_options')) {
$file = 'nextend-social-login-pro/nextend-social-login-pro.php';
Notices::addError(sprintf(__('Please update %1$s to version %2$s or newer.', 'nextend-facebook-connect'), "Nextend Social Login Pro Addon", self::$nslPROMinVersion) . ' ' . __('Update now!', 'nextend-facebook-connect') . '');
}
}
/** @var NextendSocialLoginSettings */
public static $settings;
private static $styles = array(
'fullwidth' => array(
'container' => 'nsl-container-block-fullwidth',
'align' => array()
),
'default' => array(
'container' => 'nsl-container-block',
'align' => array(
'left',
'right',
'center',
)
),
'icon' => array(
'container' => 'nsl-container-inline',
'align' => array(
'left',
'right',
'center',
)
),
'grid' => array(
'container' => 'nsl-container-grid',
'align' => array(
'left',
'right',
'center',
'space-around',
'space-between',
)
)
);
public static $providersPath;
/**
* @var NextendSocialProviderDummy[]
*/
public static $providers = array();
/**
* @var NextendSocialProvider[]
*/
public static $allowedProviders = array();
/**
* @var NextendSocialProvider[]
*/
public static $enabledProviders = array();
private static $ordering = array();
private static $loginHeadAdded = false;
private static $loginMainButtonsAdded = false;
public static $counter = 1;
public static $WPLoginCurrentView = '';
public static $WPLoginCurrentFlow = 'login';
private static $allowedPostStates = array(
'classic-editor-plugin',
'elementor'
);
public static function init() {
add_action('plugins_loaded', 'NextendSocialLogin::plugins_loaded');
register_activation_hook(NSL_PATH_FILE, 'NextendSocialLogin::install');
add_action('delete_user', 'NextendSocialLogin::delete_user');
self::$settings = new NextendSocialLoginSettings('nextend_social_login', array(
'enabled' => array(),
'register-flow-page' => '',
'proxy-page' => '',
'ordering' => array(
'facebook',
'google',
'twitter'
),
'licenses' => array(),
'terms_show' => 0,
'terms' => __('By clicking Register, you accept our Privacy Policy', 'nextend-facebook-connect'),
'store_name' => 1,
'store_email' => 1,
'avatar_store' => 1,
'store_access_token' => 1,
'redirect_prevent_external' => 0,
'redirect' => '',
'redirect_reg' => '',
'default_redirect' => '',
'default_redirect_reg' => '',
'blacklisted_urls' => '',
'redirect_overlay' => 'overlay-with-spinner-and-message',
'target' => 'prefer-popup',
'allow_register' => -1,
'allow_unlink' => 1,
'show_login_form' => 'show',
'login_form_button_align' => 'left',
'show_registration_form' => 'show',
'login_form_button_style' => 'default',
'login_form_layout' => 'below',
'show_embedded_login_form' => 'show',
'embedded_login_form_button_align' => 'left',
'embedded_login_form_button_style' => 'default',
'embedded_login_form_layout' => 'below',
'custom_actions' => '',
'custom_actions_button_style' => 'default',
'custom_actions_button_layout' => 'default',
'custom_actions_button_align' => 'left',
'comment_login_button' => 'show',
'comment_button_align' => 'left',
'comment_button_style' => 'default',
'buddypress_register_button' => 'bp_before_account_details_fields',
'buddypress_register_button_align' => 'left',
'buddypress_register_button_style' => 'default',
'buddypress_register_form_layout' => 'default',
'buddypress_login' => 'show',
'buddypress_login_form_layout' => 'default',
'buddypress_login_button_style' => 'default',
'buddypress_sidebar_login' => 'show',
'woocommerce_login' => 'after',
'woocommerce_login_form_layout' => 'default',
'woocommerce_register' => 'after',
'woocommerce_register_form_layout' => 'default',
'woocommerce_billing' => 'before',
'woocommerce_billing_form_layout' => 'default',
'woocoommerce_form_button_style' => 'default',
'woocoommerce_form_button_align' => 'left',
'woocommerce_account_details' => 'before',
'woocommerce_cfw' => 'show',
'woocommerce_cfw_layout' => 'below',
'memberpress_login' => 'before',
'memberpress_form_button_align' => 'left',
'memberpress_login_form_button_style' => 'default',
'memberpress_login_form_layout' => 'below-separator',
'memberpress_signup' => 'before',
'memberpress_signup_form_button_style' => 'default',
'memberpress_signup_form_layout' => 'below-separator',
'memberpress_account_details' => 'after',
'registration_notification_notify' => '0',
'debug' => '0',
'show_linked_providers' => '0',
'login_restriction' => '0',
'avatars_in_all_media' => '0',
'custom_register_label' => '0',
'review_state' => -1,
'woocommerce_dismissed' => 0,
'woocoommerce_registration_email_template' => 'woocommerce',
'userpro_show_login_form' => 'show',
'userpro_show_register_form' => 'show',
'userpro_login_form_button_style' => 'default',
'userpro_login_form_layout' => 'below',
'userpro_register_form_button_style' => 'default',
'userpro_register_form_layout' => 'below',
'userpro_form_button_align' => 'left',
'ultimatemember_login' => 'after',
'ultimatemember_login_form_button_style' => 'default',
'ultimatemember_login_form_layout' => 'below-separator',
'ultimatemember_register' => 'after',
'ultimatemember_register_form_button_style' => 'default',
'ultimatemember_register_form_layout' => 'below-separator',
'ultimatemember_account_details' => 'after',
'ultimatemember_form_button_align' => 'left',
'edd_login' => 'after',
'edd_login_form_button_style' => 'default',
'edd_login_form_layout' => 'default',
'edd_register' => 'after',
'edd_register_form_button_style' => 'default',
'edd_register_form_layout' => 'default',
'edd_checkout' => 'form_after',
'edd_checkout_form_button_style' => 'default',
'edd_checkout_form_layout' => 'default',
'edd_form_button_align' => 'left',
'admin_bar_roles' => array(),
));
add_action('itsec_initialized', 'NextendSocialLogin::disable_better_wp_security_block_long_urls', -1);
add_action('bp_loaded', 'NextendSocialLogin::buddypress_loaded');
}
public static function plugins_loaded() {
NextendSocialLoginAdmin::init();
$lastVersion = get_option('nsl-version');
if ($lastVersion != self::$version) {
NextendSocialLogin::install();
if (empty($lastVersion) || version_compare($lastVersion, '3.0.14', '<=')) {
$old_license_status = NextendSocialLogin::$settings->get('license_key_ok');
if ($old_license_status) {
$domain = NextendSocialLogin::$settings->get('authorized_domain');
if (empty($domain)) {
$domain = self::getDomain();
}
NextendSocialLogin::$settings->set('licenses', array(
array(
'license_key' => NextendSocialLogin::$settings->get('license_key'),
'domain' => $domain
)
));
}
}
update_option('nsl-version', self::$version, true);
wp_redirect(set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']));
exit;
} else if (isset($_REQUEST['repairnsl']) && current_user_can('manage_options') && check_admin_referer('repairnsl')) {
self::install();
wp_redirect(admin_url('admin.php?page=nextend-social-login'));
exit;
}
do_action('nsl_start');
load_plugin_textdomain('nextend-facebook-connect', false, basename(dirname(__FILE__)) . '/languages/');
Notices::init();
self::$providersPath = NSL_PATH . '/providers/';
$providers = array_diff(scandir(self::$providersPath), array(
'..',
'.'
));
foreach ($providers as $provider) {
if (file_exists(self::$providersPath . $provider . '/' . $provider . '.php')) {
require_once(self::$providersPath . $provider . '/' . $provider . '.php');
}
}
do_action('nsl_add_providers');
self::$ordering = array_flip(self::$settings->get('ordering'));
uksort(self::$providers, 'NextendSocialLogin::sortProviders');
uksort(self::$allowedProviders, 'NextendSocialLogin::sortProviders');
uksort(self::$enabledProviders, 'NextendSocialLogin::sortProviders');
do_action('nsl_providers_loaded');
if (NextendSocialLogin::$settings->get('allow_register') != 1) {
add_filter('nsl_is_register_allowed', 'NextendSocialLogin::is_register_allowed');
}
add_action('login_form_login', 'NextendSocialLogin::login_form_login');
/**
* We need smaller priority, as some plugins like Ultimate Member may trigger a redirect before us.
*/
add_action('login_form_register', 'NextendSocialLogin::login_form_register', 9);
add_action('login_form_link', 'NextendSocialLogin::login_form_link');
add_action('bp_core_screen_signup', 'NextendSocialLogin::bp_login_form_register');
add_action('login_form_unlink', 'NextendSocialLogin::login_form_unlink');
add_action('template_redirect', 'NextendSocialLogin::alternate_login_page_template_redirect');
add_action('parse_request', 'NextendSocialLogin::editProfileRedirect');
//check if DOM is ready
add_action('wp_print_scripts', 'NextendSocialLogin::nslDOMReady');
if (count(self::$enabledProviders) > 0) {
if (self::$settings->get('show_login_form') == 'hide') {
add_action('login_form_login', 'NextendSocialLogin::removeLoginFormAssets');
} else {
add_action('login_form', 'NextendSocialLogin::addLoginFormButtons');
}
if (NextendSocialLogin::$settings->get('show_registration_form') == 'hide') {
add_action('login_form_register', 'NextendSocialLogin::removeLoginFormAssets');
} else {
add_action('register_form', 'NextendSocialLogin::addRegisterFormButtons');
}
if (NextendSocialLogin::$settings->get('show_embedded_login_form') != 'hide') {
add_filter('login_form_bottom', 'NextendSocialLogin::filterAddEmbeddedLoginFormButtons');
}
//some themes trigger both the bp_sidebar_login_form action and the login_form action.
switch (NextendSocialLogin::$settings->get('buddypress_sidebar_login')) {
case 'show':
add_action('bp_sidebar_login_form', 'NextendSocialLogin::addLoginButtons');
break;
}
add_action('profile_personal_options', 'NextendSocialLogin::addLinkAndUnlinkButtons');
/*
* Shopkeeper theme fix. Remove normal login form hooks while WooCommerce registration/login form rendering
*/
add_action('woocommerce_login_form_start', 'NextendSocialLogin::remove_action_login_form_buttons');
add_action('woocommerce_login_form_end', 'NextendSocialLogin::add_action_login_form_buttons');
add_action('woocommerce_register_form_start', 'NextendSocialLogin::remove_action_login_form_buttons');
add_action('woocommerce_register_form_end', 'NextendSocialLogin::add_action_login_form_buttons');
/* End of fix */
add_action('wp_head', 'NextendSocialLogin::styles', 100);
/*
*
* We need to call in our styles on the AMP pages using this action, since:
* -the "AMP" plugin does not call wp_head in Reader mode.
* -the "AMP for WP" plugin does not call wp_head in AMP view at all.
* -AMP plugins only allow adding custom CSS in the unique ';
}
}
public static function stylesWithoutTag() {
$stylesheet = self::get_template_part('style.css');
if (!empty($stylesheet) && file_exists($stylesheet)) {
echo file_get_contents($stylesheet);
}
}
public static function nslDOMReady() {
echo '';
}
public static function loginHead() {
self::styles();
$template = self::get_template_part('login/' . sanitize_file_name(self::$settings->get('login_form_layout')) . '.php');
if (!empty($template) && file_exists($template)) {
require($template);
}
self::$loginHeadAdded = true;
}
public static function scripts() {
static $once = null;
if ($once === null) {
$scripts = NSL_PATH . '/js/nsl.js';
if (file_exists($scripts)) {
$localizedStrings = array(
'redirect_overlay_title' => __('Hold On', 'nextend-facebook-connect'),
'redirect_overlay_text' => __('You are being redirected to another page,
it may take a few seconds.', 'nextend-facebook-connect')
);
echo '';
}
$once = true;
}
}
public static function install() {
/** @var $wpdb WPDB */ global $wpdb;
$table_name = $wpdb->prefix . "social_users";
$charset_collate = $wpdb->get_charset_collate();
$lastVersion = get_option('nsl-version');
/*
* We should run these codes only if our database table already exists.
*/
if ($wpdb->get_var("SHOW TABLES LIKE '" . $table_name . "'") === $table_name) {
/**
* In 3.0.27 we added a new column to the social_users table as autoincrement and primary key.
* This causes an SQL error for the dbDelta() function so we need to add it beforehand.
*/
if (version_compare($lastVersion, '3.0.26', '<=')) {
$row = $wpdb->get_results("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" . DB_NAME . "' AND TABLE_NAME = '" . $table_name . "' AND COLUMN_NAME = 'social_users_id';");
if (!$row) {
$alterQuery = "ALTER TABLE " . $table_name . " ADD `social_users_id` int NOT NULL AUTO_INCREMENT PRIMARY KEY;";
$wpdb->query($alterQuery);
}
}
if (version_compare($lastVersion, '3.0.27', '<=')) {
/*
* In version 3.0.21 we started storing the register_date, login_date and link_date with '0000-00-00 00:00:00' as default value.
* That value returned an invalid value error on databases where 'sql_mode' has 'NO_ZERO_DATE, NO_ZERO_IN_DATE' modes, so it prevented us from modifying our database structure.
*/
$row = $wpdb->get_results("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" . DB_NAME . "' AND TABLE_NAME = '" . $table_name . "' AND COLUMN_NAME = 'register_date';");
if (!empty($row)) {
$alterQuery = "ALTER TABLE " . $table_name . " CHANGE `register_date` `register_date` datetime DEFAULT NULL, CHANGE `login_date` `login_date` datetime DEFAULT NULL, CHANGE `link_date` `link_date` datetime DEFAULT NULL;";
$result = $wpdb->query($alterQuery);
if ($result) {
$wpdb->update($table_name, array('register_date' => NULL,), array(
'register_date' => '0000-00-00 00:00:00'
));
$wpdb->update($table_name, array('login_date' => NULL,), array(
'login_date' => '0000-00-00 00:00:00'
));
$wpdb->update($table_name, array('link_date' => NULL,), array(
'link_date' => '0000-00-00 00:00:00'
));
}
}
}
}
$sql = "CREATE TABLE " . $table_name . " (
`social_users_id` int NOT NULL AUTO_INCREMENT,
`ID` int NOT NULL,
`type` varchar(20) NOT NULL,
`identifier` varchar(100) NOT NULL,
`register_date` datetime default NULL,
`login_date` datetime default NULL,
`link_date` datetime default NULL,
PRIMARY KEY (social_users_id),
KEY `ID` (`ID`,`type`),
KEY `identifier` (`identifier`)
) " . $charset_collate . ";";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
public static function sortProviders($a, $b) {
if (isset(self::$ordering[$a]) && isset(self::$ordering[$b])) {
if (self::$ordering[$a] < self::$ordering[$b]) {
return -1;
}
return 1;
}
if (isset(self::$ordering[$a])) {
return -1;
}
return 1;
}
/**
* @param $provider NextendSocialProviderDummy
*/
public static function addProvider($provider) {
if (in_array($provider->getId(), self::$settings->get('enabled'))) {
if ($provider->isTested() && $provider->enable()) {
self::$enabledProviders[$provider->getId()] = $provider;
}
}
self::$providers[$provider->getId()] = $provider;
if ($provider instanceof NextendSocialProvider) {
self::$allowedProviders[$provider->getId()] = $provider;
}
}
public static function enableProvider($providerID) {
if (isset(self::$providers[$providerID])) {
$enabled = self::$settings->get('enabled');
$enabled[] = self::$providers[$providerID]->getId();
$enabled = array_unique($enabled);
self::$settings->update(array(
'enabled' => $enabled
));
}
}
public static function disableProvider($providerID) {
if (isset(self::$providers[$providerID])) {
$enabled = array_diff(self::$settings->get('enabled'), array(self::$providers[$providerID]->getId()));
self::$settings->update(array(
'enabled' => $enabled
));
}
}
public static function isProviderEnabled($providerID) {
return isset(self::$enabledProviders[$providerID]);
}
public static function alternate_login_page_template_redirect() {
$isAlternatePage = ((self::getProxyPage() !== false && (is_page(self::getProxyPage()) || get_permalink() === get_permalink(self::getProxyPage()))) || (self::getRegisterFlowPage() !== false && (is_page(self::getRegisterFlowPage()) || get_permalink() === get_permalink(self::getRegisterFlowPage()))));
if ($isAlternatePage) {
nocache_headers();
if (!empty($_REQUEST['loginSocial']) || (isset($_GET['interim_login']) && $_GET['interim_login'] === 'nsl')) {
$action = isset($_GET['action']) ? $_GET['action'] : 'login';
if (!in_array($action, array(
'login',
'register',
'link',
'unlink'
))) {
$action = 'login';
}
switch ($action) {
case 'login':
NextendSocialLogin::login_form_login();
break;
case 'register':
NextendSocialLogin::login_form_register();
break;
case 'link':
NextendSocialLogin::login_form_link();
break;
case 'unlink':
NextendSocialLogin::login_form_unlink();
break;
}
} else {
if (!is_front_page() && !is_home()) {
if (Notices::hasErrors()) {
wp_redirect(NextendSocialLogin::enableNoticeForUrl(home_url()));
exit;
}
wp_redirect(home_url());
exit;
}
}
}
}
public static function login_form_login() {
self::$WPLoginCurrentView = 'login';
self::login_init();
}
public static function login_form_register() {
self::$WPLoginCurrentView = 'register';
self::login_init();
}
public static function bp_login_form_register() {
self::$WPLoginCurrentView = 'register-bp';
self::login_init();
}
public static function login_form_link() {
self::$WPLoginCurrentView = 'link';
self::login_init();
}
public static function login_form_unlink() {
self::$WPLoginCurrentView = 'unlink';
self::login_init();
}
public static function login_init() {
add_filter('wp_login_errors', 'NextendSocialLogin::wp_login_errors');
if (isset($_GET['interim_login']) && $_GET['interim_login'] === 'nsl' && is_user_logged_in()) {
self::onInterimLoginSuccess();
}
if (isset($_REQUEST['loginFacebook']) && $_REQUEST['loginFacebook'] == '1') {
$_REQUEST['loginSocial'] = 'facebook';
}
if (isset($_REQUEST['loginGoogle']) && $_REQUEST['loginGoogle'] == '1') {
$_REQUEST['loginSocial'] = 'google';
}
if (isset($_REQUEST['loginTwitter']) && $_REQUEST['loginTwitter'] == '1') {
$_REQUEST['loginTwitter'] = 'twitter';
}
if (isset($_REQUEST['loginSocial']) && is_string($_REQUEST['loginSocial']) && isset(self::$providers[$_REQUEST['loginSocial']]) && (self::$providers[$_REQUEST['loginSocial']]->isEnabled() || self::$providers[$_REQUEST['loginSocial']]->isTest())) {
nocache_headers();
self::$providers[$_REQUEST['loginSocial']]->connect();
}
}
private static function onInterimLoginSuccess() {
require_once(NSL_PATH . '/admin/interim.php');
}
public static function wp_login_errors($errors) {
if (empty($errors)) {
$errors = new WP_Error();
}
$errorMessages = Notices::getErrors();
if ($errorMessages !== false) {
foreach ($errorMessages as $errorMessage) {
$errors->add('error', $errorMessage);
}
}
return $errors;
}
public static function editProfileRedirect() {
global $wp;
if (isset($wp->query_vars['editProfileRedirect'])) {
if (function_exists('bp_loggedin_user_domain')) {
header('LOCATION: ' . bp_loggedin_user_domain() . 'profile/edit/group/1/');
} else {
header('LOCATION: ' . self_admin_url('profile.php'));
}
exit;
}
}
public static function filterAddEmbeddedLoginFormButtons($ret) {
return $ret . self::getEmbeddedLoginForm();
}
private static function getEmbeddedLoginForm($labelType = 'login') {
ob_start();
self::styles();
$index = self::$counter++;
$containerID = 'nsl-custom-login-form-' . $index;
echo '