function hocwp_setup_theme_social_login_script() { if (!is_user_logged_in()) { if (is_page_template('page-templates/register.php') || is_page_template('page-templates/login.php') || is_page_template('page-templates/account.php') || hocwp_is_login_page()) { $login_settings = get_option('hocwp_user_login'); if ((bool) hocwp_get_value_by_key($login_settings, 'login_with_facebook')) { hocwp_facebook_login_script(); } if ((bool) hocwp_get_value_by_key($login_settings, 'login_with_google')) { hocwp_google_login_script(); } } } }
function hocwp_setup_theme_more_user_profile($user) { $user_id = $user->ID; ?> <h3><?php _e('Social Accounts', 'hocwp-theme'); ?> </h3> <table class="form-table"> <tr> <th><label for="facebook">Facebook</label></th> <td> <?php $facebook = get_the_author_meta('facebook', $user_id); $input = new HOCWP_HTML('input'); $input->set_attribute('name', 'facebook'); if (empty($facebook)) { $input->set_attribute('type', 'button'); $input->set_text(__('Connect with Facebook account', 'hocwp-theme')); $input->set_class('button button-secondary hide-if-no-js hocwp-connect-facebook facebook'); $input->set_attribute('onclick', 'hocwp_facebook_login();'); } else { $facebook_data = get_the_author_meta('facebook_data', $user_id); $avatar = hocwp_get_value_by_key($facebook_data, array('picture', 'data', 'url')); $email = hocwp_get_value_by_key($facebook_data, 'email'); if (!empty($avatar)) { $img = new HOCWP_HTML('img'); $img->set_image_alt(''); $img->set_image_src($avatar); } $input->set_attribute('type', 'text'); $input->set_attribute('readonly', 'readonly'); $input->set_attribute('value', $facebook . ' - ' . $email); $input->set_class('regular-text hocwp-disconnect-social facebook'); $input->set_attribute('data-user-id', $user_id); $input->set_attribute('data-social', 'facebook'); } if (empty($facebook) && 'profile.php' == $GLOBALS['pagenow']) { $input->output(); if (empty($facebook)) { hocwp_facebook_login_script(array('connect' => true)); } } else { if (!empty($facebook)) { $input->output(); } else { _e('You can only connect to social account on profile page.', 'hocwp-theme'); } } ?> </td> </tr> <tr> <th><label for="google">Google</label></th> <td> <?php $social = 'google'; $social_id = get_the_author_meta($social, $user_id); $input = new HOCWP_HTML('input'); $input->set_attribute('name', $social); if (empty($social_id)) { $input->set_attribute('type', 'button'); $input->set_text(__('Connect with Google account', 'hocwp-theme')); $input->set_class('button button-secondary hide-if-no-js hocwp-connect-' . $social . ' ' . $social); $input->set_attribute('onclick', 'hocwp_google_login();'); } else { $facebook_data = get_the_author_meta($social . '_data', $user_id); $avatar = hocwp_get_value_by_key($facebook_data, array('picture', 'data', 'url')); $email = hocwp_get_value_by_key($facebook_data, array('emails', 0, 'value')); if (!empty($avatar)) { $img = new HOCWP_HTML('img'); $img->set_image_alt(''); $img->set_image_src($avatar); } $input->set_attribute('type', 'text'); $input->set_attribute('readonly', 'readonly'); $input->set_attribute('value', $social_id . ' - ' . $email); $input->set_class('regular-text hocwp-disconnect-social ' . $social); $input->set_attribute('data-user-id', $user_id); $input->set_attribute('data-social', $social); } if (empty($social_id) && 'profile.php' == $GLOBALS['pagenow']) { $input->output(); if (empty($social_id)) { hocwp_google_login_script(array('connect' => true)); } } else { if (!empty($social_id)) { $input->output(); } else { _e('You can only connect to social account on profile page.', 'hocwp-theme'); } } ?> </td> </tr> </table> <?php }