Example #1
0
function hocwp_send_mail_verify_email_subscription($subject, $to_email, $verify_link)
{
    $message = '<p>You received this message because someone requested an email subscription for ' . $to_email . ' to %SITE_NAME%.  If you did not make this request, please ignore the rest of this message.</p>';
    $message = hocwp_replace_text_placeholder($message);
    $message .= '<br>';
    $message .= '<p>Please click here to verify your email: ' . $verify_link . '</p>';
    hocwp_send_html_mail($to_email, $subject, $message);
}
Example #2
0
function hocwp_notification_posts_ajax_callback()
{
    $lists = get_option('hocwp_notification_posts');
    $lists = hocwp_to_array($lists);
    if (hocwp_array_has_value($lists)) {
        $query = hocwp_get_post_by_meta('subscriber_verified', 1, array('post_type' => 'hocwp_subscriber'));
        if ($query->have_posts()) {
            $subscribers = $query->posts;
            $date = hocwp_get_current_date();
            $transient_name = hocwp_build_transient_name('hocwp_notification_posts_table_%s', $date);
            if (false === ($table_content = get_transient($transient_name))) {
                $table = new HOCWP_HTML('table');
                $table->set_attribute('align', 'center');
                $table->set_attribute('width', '100%');
                $table->set_attribute('cellspacing', 0);
                $table->set_attribute('border', 0);
                $table->set_attribute('cellpadding', 0);
                $table->set_attribute('bgcolor', '#ffffff');
                $table_content = '';
                foreach ($lists as $post_id) {
                    $obj = get_post($post_id);
                    $post_type = get_post_type_object($obj->post_type);
                    if (!is_object($post_type) || !$post_type->public) {
                        continue;
                    }
                    $notified = (bool) hocwp_get_post_meta('hocwp_notification_posts_sent', $post_id);
                    if ($notified) {
                        continue;
                    }
                    $inner_table = $table;
                    $tbody = new HOCWP_HTML('tbody');
                    $tr = new HOCWP_HTML('tr');
                    $td = new HOCWP_HTML('td');
                    $td->set_attribute('style', 'font-size:1px;line-height:1px');
                    $tr->set_text($td);
                    $tr2 = new HOCWP_HTML('tr');
                    $td2 = new HOCWP_HTML('td');
                    $td2->set_attribute('style', 'border-bottom:2px dotted #808285;padding-bottom:12px');
                    $a = new HOCWP_HTML('a');
                    $a->set_attribute('target', '_blank');
                    $a->set_href(get_permalink($obj));
                    $a->set_attribute('style', 'font-family: Helvetica,arial,sans-serif; font-size: 20px; color: rgb(22, 63, 144); text-align: left; font-weight: 500; text-decoration: none; line-height: 27px;');
                    $a->set_text(get_the_title($obj));
                    $p = new HOCWP_HTML('p');
                    $excerpt = get_the_excerpt($obj);
                    if (empty($excerpt)) {
                        $excerpt = $obj->post_content;
                        $excerpt = strip_tags($excerpt);
                        $excerpt = apply_filters('excerpt_length', $excerpt, 150);
                    }
                    $p->set_text($excerpt);
                    $td2->set_text($a->build() . $p->build());
                    $tr2->set_text($td2);
                    $tbody->set_text($tr->build() . $tr2->build());
                    $inner_table->set_text($tbody);
                    $table_content .= $inner_table->build();
                    update_post_meta($post_id, 'hocwp_notification_posts_sent', 1);
                }
                if (!empty($table_content)) {
                    $tbody = new HOCWP_HTML('tbody');
                    $tr = new HOCWP_HTML('tr');
                    $td = new HOCWP_HTML('td');
                    $td->set_text($table_content);
                    $tr->set_text($td);
                    $tbody->set_text($tr);
                    $table->set_text($tbody);
                    $table_content = $table->build();
                }
            }
            if (!empty($table_content)) {
                foreach ($subscribers as $subscriber) {
                    $email = hocwp_get_post_meta('subscriber_email', $subscriber->ID);
                    if (is_email($email)) {
                        $transient_name = 'hocwp_notification_posts_to_user_' . md5($email);
                        $transient_name = hocwp_build_transient_name($transient_name . '_%s', $table_content);
                        if (false === get_transient($transient_name)) {
                            $subject = '[' . get_bloginfo('name') . '] New content updated on ' . hocwp_get_current_date(hocwp_get_date_format());
                            $message = $table_content;
                            $message = hocwp_mail_unsubscribe_link_footer($message, $email);
                            $sent = hocwp_send_html_mail($email, $subject, $message);
                            if ($sent) {
                                set_transient($transient_name, 1, DAY_IN_SECONDS);
                            }
                        }
                    }
                }
            }
        }
    }
    exit;
}
Example #3
0
function hocwp_shortcode_support_form_callback($atts = array(), $content = null)
{
    $defaults = array('style' => '', 'name' => 'full_name,email,phone,message', 'label' => array(__('Full name', 'hocwp-theme'), __('Email', 'hocwp-theme'), __('Phone', 'hocwp-theme'), __('Message', 'hocwp-theme')), 'type' => 'text,email,text,textarea', 'placehoder' => '', 'captcha' => false, 'admin_email' => hocwp_get_admin_email());
    $attributes = shortcode_atts($defaults, $atts);
    $name = hocwp_get_value_by_key($attributes, 'name');
    $names = explode(',', $name);
    if (hocwp_array_has_value($names)) {
        $show_form = true;
        $label = hocwp_get_value_by_key($attributes, 'label');
        if (!is_array($label)) {
            $label = explode(',', $label);
            $label = array_map('trim', $label);
        }
        $type = hocwp_get_value_by_key($attributes, 'type');
        $type = explode(',', $type);
        $type = array_map('trim', $type);
        $placeholder = hocwp_get_value_by_key($attributes, 'placeholder');
        if (!empty($placeholder)) {
            $placeholder = explode(',', $placeholder);
            $placeholder = array_map('trim', $placeholder);
        }
        $captcha = hocwp_get_value_by_key($attributes, 'captcha');
        $names = array_map('trim', $names);
        $html = hocwp_shortcode_before('support-form', $attributes);
        if (isset($_POST['submit'])) {
            if (hocwp_check_nonce('hocwp_support_form')) {
                if (hocwp_check_captcha()) {
                    $body = '';
                    foreach ($names as $index => $name) {
                        if (empty($name)) {
                            continue;
                        }
                        if ('name' == $name) {
                            $name = 'full_name';
                        }
                        $field_type = isset($type[$index]) ? $type[$index] : 'text';
                        $field_label = isset($label[$index]) ? $label[$index] : '';
                        $field_placeholder = isset($placeholder[$index]) ? $placeholder[$index] : '';
                        $row = isset($_POST[$name]) ? $_POST[$name] : '';
                        if (!empty($field_label)) {
                            $last_char = hocwp_get_last_char($field_label);
                            if (':' != $last_char) {
                                $field_label .= ':';
                            }
                            $row = $field_label . ' ' . $row;
                        }
                        if (!empty($row)) {
                            $body .= wpautop($row);
                        }
                    }
                    if (empty($body)) {
                        $html .= hocwp_build_message(__('You must fill all required fields.', 'hocwp-theme'), 'danger');
                    } else {
                        $full_name = __('Guest', 'hocwp-theme');
                        if (isset($_POST['full_name'])) {
                            $full_name = $_POST['full_name'];
                        }
                        $subject = sprintf(__('[%1$s] Contact message from %2$s', 'hocwp-theme'), get_bloginfo('name'), $full_name);
                        $admin_email = hocwp_get_value_by_key($attributes, 'admin_email');
                        if (!is_email($admin_email)) {
                            $admin_email = hocwp_get_admin_email();
                        }
                        $sent = hocwp_send_html_mail($admin_email, $subject, $body);
                        if ($sent) {
                            $show_form = false;
                            $html .= hocwp_build_message(__('Your message has been sent, we will reply to you as soon as possible.', 'hocwp-theme'), 'success');
                        } else {
                            $html .= hocwp_build_message(__('There was an error occurred, please try again or contact administrators.', 'hocwp-theme'), 'danger');
                        }
                    }
                } else {
                    $html .= hocwp_build_message(__('Captcha code is not valid.', 'hocwp-theme'), 'danger');
                }
            }
        }
        if ($show_form) {
            ob_start();
            ?>
			<form class="hocwp-support-form" action="" method="post">
				<?php 
            foreach ($names as $index => $name) {
                if (empty($name)) {
                    continue;
                }
                if ('name' == $name) {
                    $name = 'full_name';
                }
                $field_type = isset($type[$index]) ? $type[$index] : 'text';
                $field_label = isset($label[$index]) ? $label[$index] : '';
                $field_placeholder = isset($placeholder[$index]) ? $placeholder[$index] : '';
                ?>
					<div class="form-group form-row">
						<div class="row">
							<div class="col-sm-2">
								<label for="<?php 
                echo esc_attr($name);
                ?>
"><?php 
                echo $field_label;
                ?>
</label>
							</div>
							<div class="col-sm-10">
								<?php 
                $value = isset($_POST[$name]) ? $_POST[$name] : '';
                switch ($field_type) {
                    case 'longtext':
                    case 'textarea':
                        ?>
										<textarea id="<?php 
                        echo esc_attr($name);
                        ?>
"
										          name="<?php 
                        echo esc_attr($name);
                        ?>
"
										          class="form-control"
										          placeholder="<?php 
                        echo esc_attr($field_placeholder);
                        ?>
"><?php 
                        echo $value;
                        ?>
</textarea>
										<?php 
                        break;
                    default:
                        $input_type = 'text';
                        if ('email' == $field_type) {
                            $input_type = 'email';
                        }
                        ?>
										<input id="<?php 
                        echo esc_attr($name);
                        ?>
"
										       placeholder="<?php 
                        echo esc_attr($field_placeholder);
                        ?>
"
										       value="<?php 
                        echo esc_attr($value);
                        ?>
"
										       name="<?php 
                        echo esc_attr($name);
                        ?>
"
										       type="<?php 
                        echo esc_attr($input_type);
                        ?>
">
										<?php 
                }
                ?>
							</div>
						</div>
					</div>
					<?php 
            }
            if ($captcha) {
                echo '<div class="form-group form-row"><div class="row"><div class="col-sm-2"></div><div class="col-sm-10">';
                hocwp_field_captcha(array('input_width' => 180));
                echo '</div></div></div>';
            }
            ?>
				<div class="form-hidden-fields">
					<?php 
            hocwp_nonce('hocwp_support_form');
            ?>
				</div>
				<div class="form-group form-row">
					<div class="row">
						<div class="col-sm-2"></div>
						<div class="col-sm-10">
							<input type="submit" name="submit" class="btn btn-warning"
							       value="<?php 
            _e('Send', 'hocwp-theme');
            ?>
">
						</div>
					</div>
				</div>
			</form>
			<?php 
            $html .= ob_get_clean();
        }
        $html .= hocwp_shortcode_after();
    }
    return apply_filters('hocwp_shortcode_support_form', $html, $attributes, $content);
}
Example #4
0
function hocwp_execute_lostpassword()
{
    $http_post = 'POST' == $_SERVER['REQUEST_METHOD'];
    $user = null;
    $user_login = '';
    $user_id = '';
    $user_email = '';
    $error = false;
    $message = __('There was an error occurred, please try again.', 'hocwp-theme');
    $redirect = hocwp_get_value_by_key($_REQUEST, 'redirect_to');
    $redirect_to = apply_filters('lostpassword_redirect', $redirect);
    if (is_user_logged_in()) {
        if (empty($redirect_to)) {
            $redirect_to = home_url('/');
        }
        wp_redirect($redirect_to);
        exit;
    }
    $transient = '';
    $captcha = hocwp_get_method_value('captcha');
    if ($http_post) {
        $action = hocwp_get_method_value('action');
        if ('lostpassword' === $action || 'retrievepassword' === $action) {
            $user_login = hocwp_get_method_value('user_login');
            $transient_name = hocwp_build_transient_name('hocwp_lostpassword_user_%s', $user_login);
            if ((isset($_POST['submit']) || isset($_POST['wp-submit'])) && false === ($transient = get_transient($transient_name))) {
                if (empty($user_login)) {
                    $error = true;
                    $message = __('Please enter your account name or email address.', 'hocwp-theme');
                } else {
                    if (isset($_POST['captcha'])) {
                        $capt = new HOCWP_Captcha();
                        if (!$capt->check($captcha)) {
                            $error = true;
                            $message = __('The security code is incorrect.', 'hocwp-theme');
                        }
                    }
                    if (!$error) {
                        $user = hocwp_return_user($user_login);
                        if (!is_a($user, 'WP_User')) {
                            $error = true;
                            $message = __('Username or email is not exists.', 'hocwp-theme');
                        } else {
                            $user_login = $user->user_login;
                            $user_id = $user->ID;
                            $user_email = $user->user_email;
                        }
                    }
                }
                if (!$error && is_a($user, 'WP_User')) {
                    $key = get_password_reset_key($user);
                    if (is_wp_error($key)) {
                        $error = true;
                        $message = __('There was an error occurred, please try again or contact the administrator.', 'hocwp-theme');
                    } else {
                        $message = wpautop(__('Someone has requested a password reset for the following account:', 'hocwp-theme'));
                        $message .= wpautop(network_home_url('/'));
                        $message .= wpautop(sprintf(__('Username: %s', 'hocwp-theme'), $user_login));
                        $message .= wpautop(__('If this was a mistake, just ignore this email and nothing will happen.', 'hocwp-theme'));
                        $message .= wpautop(__('To reset your password, visit the following address:', 'hocwp-theme'));
                        $message .= wpautop(network_site_url("wp-login.php?action=rp&key={$key}&login=" . rawurlencode($user_login), 'login'));
                        if (is_multisite()) {
                            $blogname = $GLOBALS['current_site']->site_name;
                        } else {
                            $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
                        }
                        $title = sprintf(__('[%s] Password Reset'), $blogname);
                        $title = apply_filters('retrieve_password_title', $title, $user_login, $user);
                        $message = apply_filters('retrieve_password_message', $message, $key, $user_login, $user);
                        if (!is_email($user_email)) {
                            $user_email = $user->user_email;
                        }
                        if ($message && !hocwp_send_html_mail($user_email, wp_specialchars_decode($title), $message)) {
                            $error = true;
                            $message = __('The email could not be sent. Possible reason: your host may have disabled the mail() function.', 'hocwp-theme');
                        } else {
                            $error = false;
                            $message = __('Password recovery information has been sent, please check your mailbox.', 'hocwp-theme');
                            set_transient($transient_name, $user_id, 15 * MINUTE_IN_SECONDS);
                        }
                    }
                }
            } else {
                if (hocwp_id_number_valid($transient)) {
                    $error = false;
                    $message = __('Password recovery information has been sent, please check your mailbox.', 'hocwp-theme');
                }
            }
        }
    }
    $result = array('user_id' => $user_id, 'user_email' => $user_email, 'user_login' => $user_login, 'captcha' => $captcha, 'error' => $error, 'message' => $message, 'redirect_to' => $redirect_to, 'transient' => $transient);
    return $result;
}