コード例 #1
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);
}
コード例 #2
0
 function hocwp_widget_subscribe_ajax_callback()
 {
     $use_captcha = (bool) hocwp_get_method_value('use_captcha');
     $captcha_code = hocwp_get_method_value('captcha');
     $email = hocwp_get_method_value('email');
     $name = hocwp_get_method_value('name');
     $phone = hocwp_get_method_value('phone');
     $register = (bool) hocwp_get_method_value('register');
     $result = array('success' => false, 'message' => hocwp_build_message(hocwp_text_error_default(), 'danger'));
     $captcha_valid = true;
     if ($use_captcha) {
         $captcha = new HOCWP_Captcha();
         $captcha_valid = $captcha->check($captcha_code);
     }
     $re_verify = false;
     $query = hocwp_get_post_by_meta('subscriber_email', $email, array('post_type' => 'hocwp_subscriber'));
     if ($query->have_posts()) {
         $subscriber = array_shift($query->posts);
         $verified = hocwp_get_post_meta('subscriber_verified', $subscriber->ID);
         if (1 != $verified) {
             $re_verify = true;
         }
     }
     if ($captcha_valid) {
         if (is_email($email)) {
             $active_key = hocwp_generate_reset_key();
             $verify_link = hocwp_generate_verify_link($active_key);
             if ($re_verify) {
                 hocwp_send_mail_verify_email_subscription(hocwp_text_email_subject_verify_subscription(), $email, $verify_link);
                 $result['success'] = true;
                 $result['message'] = hocwp_build_message(hocwp_text_success_register_and_verify_email(), 'success');
             } else {
                 if ($query->have_posts() || $register && email_exists($email)) {
                     $result['message'] = hocwp_build_message(hocwp_text_error_email_exists(), 'danger');
                 } else {
                     $post_title = '';
                     if (!empty($name)) {
                         $post_title .= $name;
                     }
                     if (empty($post_title)) {
                         $post_title = $email;
                     } else {
                         $post_title .= ' - ' . $email;
                     }
                     $post_data = array('post_type' => 'hocwp_subscriber', 'post_title' => $post_title, 'post_status' => 'publish');
                     $post_id = hocwp_insert_post($post_data);
                     if (hocwp_id_number_valid($post_id)) {
                         update_post_meta($post_id, 'subscriber_name', $name);
                         update_post_meta($post_id, 'subscriber_email', $email);
                         update_post_meta($post_id, 'subscriber_phone', $phone);
                         update_post_meta($post_id, 'subscriber_verified', 0);
                         update_post_meta($post_id, 'subscriber_active_key', $active_key);
                         if ($register) {
                             $password = wp_generate_password();
                             $user_data = array('username' => $email, 'email' => $email, 'password' => $password);
                             $user_id = hocwp_add_user($user_data);
                             if (hocwp_id_number_valid($user_id)) {
                                 wp_send_new_user_notifications($user_id);
                                 update_post_meta($post_id, 'subscriber_user', $user_id);
                                 update_user_meta($user_id, 'subscriber_id', $post_id);
                             }
                         }
                         hocwp_send_mail_verify_email_subscription(hocwp_text_email_subject_verify_subscription(), $email, $verify_link);
                         $result['success'] = true;
                         $result['message'] = hocwp_build_message(hocwp_text_success_register_and_verify_email(), 'success');
                     }
                 }
             }
         } else {
             $result['message'] = hocwp_build_message(hocwp_text_error_email_not_valid(), 'danger');
         }
     } else {
         $result['message'] = hocwp_build_message(hocwp_text_error_captcha_not_valid(), 'danger');
     }
     wp_send_json($result);
 }
コード例 #3
0
ファイル: utils.php プロジェクト: skylarkcob/hocwp-projects
function hocwp_dashboard_widget_rss_cache($args = array())
{
    echo '<div class="rss-widget">';
    $url = '';
    if (is_string($args)) {
        $url = $args;
    } elseif (is_array($args) && isset($args['url'])) {
        $url = $args['url'];
    }
    if (!empty($url)) {
        $number = hocwp_get_value_by_key($args, 'number');
        $feed_args = array('url' => $url);
        if (hocwp_id_number_valid($number)) {
            $feed_args['number'] = $number;
        }
        $rss = hocwp_get_feed_items($feed_args);
        if (is_wp_error($rss)) {
            $error_code = $rss->get_error_code();
            if ('feed_down' === $error_code) {
                echo '<ul><li>' . $rss->get_error_message() . '</li></ul>';
            } else {
                if (is_admin() || current_user_can('manage_options')) {
                    echo '<p>' . sprintf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message()) . '</p>';
                }
            }
            return;
        }
        if (hocwp_array_has_value($rss)) {
            echo '<ul>';
            foreach ($rss as $item) {
                $li = new HOCWP_HTML('li');
                $a = new HOCWP_HTML('a');
                $a->set_href($item['permalink']);
                $a->set_text($item['title']);
                $a->set_attribute('target', '_blank');
                $li->set_text($a->build());
                $li->output();
            }
            echo '</ul>';
        }
    } else {
        echo hocwp_build_message(__('Please set a valid feed url for this widget!', 'hocwp-theme'), '');
    }
    echo '</div>';
}
コード例 #4
0
ファイル: login.php プロジェクト: skylarkcob/hocwp-projects
function hocwp_lostpassword_form($args = array())
{
    $defaults = hocwp_account_form_default_args();
    $args = wp_parse_args($args, $defaults);
    $data = hocwp_execute_lostpassword();
    $user_login = $data['user_login'];
    $error = $data['error'];
    $message = $data['message'];
    $redirect_to = hocwp_get_value_by_key($args, 'redirect_to', hocwp_get_method_value('redirect_to', 'get'));
    $logo = hocwp_get_value_by_key($args, 'logo', hocwp_get_login_logo_url());
    ?>
	<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($_POST['submit']) || isset($_POST['wp-submit'])) {
        if (isset($_REQUEST['error']) || $error) {
            $message = hocwp_build_message($message, 'danger');
            echo $message;
        } else {
            if (!empty($message) && !$error || isset($_POST['submit']) && !empty($message)) {
                $message = hocwp_build_message($message, 'success');
                echo $message;
            }
        }
    }
    ?>
		</div>
		<div class="module-body">
			<h4 class="form-title"><?php 
    _e('Reset password', 'hocwp-theme');
    ?>
</h4>

			<form name="lostpasswordform" id="lostpasswordform" action="<?php 
    echo esc_url(wp_lostpassword_url());
    ?>
"
			      method="post">
				<p>
					<label><?php 
    echo hocwp_get_value_by_key($args, 'label_username', __('Username or Email', 'hocwp-theme'));
    ?>
						<br>
						<input type="text" size="20" value="<?php 
    echo esc_attr($user_login);
    ?>
" class="input"
						       id="user_login" name="user_login"></label>
				</p>
				<input type="hidden" name="action" value="lostpassword">
				<input type="hidden" name="redirect_to" value="<?php 
    echo $redirect_to;
    ?>
">

				<p class="submit">
					<input type="submit" name="wp-submit" id="wp-submit" class="button-primary"
					       value="Get New Password" tabindex="100"></p>
			</form>
		</div>
		<div class="module-footer">
			<div class="text-center">
				<p class="form-nav">
					<a href="<?php 
    echo esc_url(wp_login_url());
    ?>
"><?php 
    echo hocwp_get_value_by_key($args, 'label_log_in', __('Login', 'hocwp-theme'));
    ?>
</a>
					<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 
}