<?php if (!function_exists('add_filter')) { exit; } global $hocwp_tos_tabs; $parent_slug = 'hocwp_theme_option'; $option = new HOCWP_Option(__('Login settings', 'hocwp-theme'), 'hocwp_user_login'); $option->set_parent_slug($parent_slug); $option->set_use_style_and_script(true); $option->set_use_media_upload(true); $args = array('id' => 'logo', 'title' => __('Logo', 'hocwp-theme'), 'field_callback' => 'hocwp_field_media_upload'); $option->add_field($args); $args = array('id' => 'login_with_email', 'title' => __('Login With Email', 'hocwp-theme'), 'label' => __('Allow user to login with registered email address?', 'hocwp-theme'), 'field_callback' => 'hocwp_field_input_checkbox'); $option->add_field($args); $args = array('id' => 'users_can_register', 'title' => __('Membership', 'hocwp-theme'), 'label' => __('Anyone can register', 'hocwp-theme'), 'field_callback' => 'hocwp_field_input_checkbox', 'value' => hocwp_users_can_register()); $option->add_field($args); $args = array('id' => 'button_style', 'title' => __('Button Style', 'hocwp-theme'), 'field_callback' => 'hocwp_field_select', 'field_args' => array('options' => hocwp_bootstrap_color_select_options()), 'default' => 'warning'); $option->add_field($args); $args = array('id' => 'security', 'title' => __('Security', 'hocwp-theme'), 'description' => __('Help your site safe online.', 'hocwp-theme')); $option->add_section($args); $args = array('id' => 'use_captcha', 'title' => __('Captcha', 'hocwp-theme'), 'label' => __('Protect your site against bots by using captcha', 'hocwp-theme'), 'field_callback' => 'hocwp_field_input_checkbox', 'section' => 'security'); $option->add_field($args); $args = array('id' => 'social_login', 'title' => __('Social Login', 'hocwp-theme'), 'description' => __('Allow user to login with social account.', 'hocwp-theme')); $option->add_section($args); $args = array('id' => 'login_with_facebook', 'title' => __('Facebook', 'hocwp-theme'), 'label' => __('Check here to allow user connects with Facebook account.', 'hocwp-theme'), 'field_callback' => 'hocwp_field_input_checkbox', 'section' => 'social_login'); $option->add_field($args); $args = array('id' => 'login_with_google', 'title' => __('Google', 'hocwp-theme'), 'label' => __('Check here to allow user connects with Google account.', 'hocwp-theme'), 'field_callback' => 'hocwp_field_input_checkbox', 'section' => 'social_login'); $option->add_field($args); $option->add_option_tab($hocwp_tos_tabs); $option->set_page_header_callback('hocwp_theme_option_form_before');
function hocwp_setup_theme_wp_hook() { if (is_404()) { $redirect_404 = (bool) hocwp_option_get_value('reading', 'redirect_404'); $post_type = hocwp_get_method_value('post_type', 'get'); $p = hocwp_get_method_value('p', 'get'); if ($redirect_404 || !empty($post_type) && hocwp_id_number_valid($p)) { hocwp_redirect_home(); } } else { if (is_singular()) { $post_status = get_post_status(); if ('future' == $post_status && !current_user_can('manage_options')) { hocwp_redirect_home(); } $trending = hocwp_theme_get_reading_options('trending'); if ((bool) $trending) { do_action('hocwp_add_trending_post', get_the_ID(), 'view'); } } if (is_user_logged_in()) { if (is_page_template('page-templates/register.php') || is_page_template('page-templates/login.php')) { wp_redirect(get_edit_profile_url()); exit; } } else { if (is_page_template('page-templates/register.php')) { if (hocwp_users_can_register()) { hocwp_execute_register(); } else { $page = hocwp_get_page_by_template('page-templates/login.php'); if (is_a($page, 'WP_Post')) { wp_redirect(get_permalink($page)); exit; } hocwp_redirect_home(); } } else { if (hocwp_is_login_page()) { $page = hocwp_get_pages_by_template('page-templates/login.php', array('output' => 'object')); if (is_a($page, 'WP_Post')) { wp_redirect(get_permalink($page)); exit; } } elseif (is_page_template('page-templates/favorite-posts.php')) { wp_redirect(wp_login_url()); exit; } } } } $enlarge_thumbnail = (bool) hocwp_theme_get_reading_options('enlarge_thumbnail'); if ($enlarge_thumbnail) { add_filter('hocwp_enlarge_post_thumbnail_on_mobile', '__return_true'); } $action = hocwp_get_method_value('action', 'get'); switch ($action) { case 'verify_subscription': $key = hocwp_get_method_value('key', 'get'); if (!empty($key)) { $args = array('post_type' => 'hocwp_subscriber', 'posts_per_page' => 1); $query = hocwp_get_post_by_meta('subscriber_active_key', $key, $args); if ($query->have_posts()) { $obj = array_shift($query->posts); update_post_meta($obj->ID, 'subscriber_verified', 1); $name = hocwp_get_post_meta('subscriber_name', $obj->ID); $email = hocwp_get_post_meta('subscriber_email', $obj->ID); $args = array('email' => $email, 'name' => $name); hocwp_add_to_newsletter_list($args); } else { hocwp_redirect_home(); } } break; } }
function hocwp_login_form($args = array()) { if (is_user_logged_in()) { return; } $action = hocwp_get_method_value('action', 'get'); if ('register' == $action) { hocwp_register_form($args); return; } if ('lostpassword' == $action) { hocwp_lostpassword_form($args); return; } $defaults = hocwp_account_form_default_args(); $args = wp_parse_args($args, $defaults); $placeholder = (bool) hocwp_get_value_by_key($args, 'placeholder', false); $args['echo'] = false; $form = wp_login_form($args); if ($placeholder) { $form = str_replace('name="log"', 'name="log" placeholder="' . $args['placeholder_username'] . '"', $form); $form = str_replace('name="pwd"', 'name="pwd" placeholder="' . $args['placeholder_password'] . '"', $form); } $logo = hocwp_get_value_by_key($args, 'logo', hocwp_get_login_logo_url()); $hide_form = (bool) hocwp_get_value_by_key($args, 'hide_form'); ?> <div class="hocwp-login-box module"> <div class="module-header text-center"> <?php if (!empty($logo)) { $a = new HOCWP_HTML('a'); $a->set_href(home_url('/')); $a->set_class('logo'); $img = new HOCWP_HTML('img'); $img->set_image_alt(''); $img->set_image_src($logo); $a->set_text($img->build()); $a->output(); } $slogan = new HOCWP_HTML('p'); $slogan->set_class('slogan'); $slogan->set_text(sprintf($args['slogan'], hocwp_get_root_domain_name(home_url('/')))); $slogan->output(); if (isset($_REQUEST['error'])) { echo '<p class="alert alert-danger">' . __('There was an error occurred, please try again.', 'hocwp-theme') . '</p>'; } ?> </div> <div class="module-body"> <h4 class="form-title"><?php _e('Login', 'hocwp-theme'); ?> </h4> <?php if ($hide_form) { $login_form_top = apply_filters('login_form_top', '', $args); $login_form_middle = apply_filters('login_form_middle', '', $args); $login_form_bottom = apply_filters('login_form_bottom', '', $args); $form = $login_form_top . $login_form_middle . $login_form_bottom; $form = hocwp_wrap_tag($form, 'form', 'login-form hocwp-login-form'); echo $form; } else { echo $form; } ?> </div> <div class="module-footer"> <div class="text-center"> <p class="form-nav"> <?php $mails = array('confirm', 'newpass'); if (!isset($_GET['checkemail']) || !in_array($_GET['checkemail'], $mails)) { if (hocwp_users_can_register()) { $registration_url = sprintf('<a href="%s">%s</a>', esc_url(wp_registration_url()), $args['text_register_link']); echo apply_filters('register', $registration_url) . '<span class="sep">|</span>'; } } ?> <a href="<?php echo esc_url(wp_lostpassword_url()); ?> " title="<?php echo $args['title_lostpassword_link']; ?> "><?php echo $args['text_lostpassword_link']; ?> </a> </p> </div> </div> </div> <?php }