示例#1
0
function hocwp_login_get_captcha_field()
{
    ob_start();
    $args = array('before' => '<p>', 'after' => '</p>');
    hocwp_field_captcha($args);
    return ob_get_clean();
}
示例#2
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);
}
    public function widget($args, $instance)
    {
        $this->instance = $instance;
        $register = hocwp_get_value_by_key($instance, 'register', hocwp_get_value_by_key($this->args, 'register'));
        $button_text = hocwp_get_value_by_key($instance, 'button_text', hocwp_get_value_by_key($this->args, 'button_text'));
        $captcha = (bool) hocwp_get_value_by_key($instance, 'captcha', hocwp_get_value_by_key($this->args, 'captcha'));
        if ($captcha) {
            add_filter('hocwp_use_session', '__return_true');
        }
        $description = hocwp_get_value_by_key($instance, 'description', hocwp_get_value_by_key($this->args, 'description'));
        $desc_position = hocwp_get_value_by_key($instance, 'desc_position', hocwp_get_value_by_key($this->args, 'desc_position'));
        $fields = $this->get_value_fields($instance);
        $all_fields = explode(',', $fields);
        hocwp_widget_before($args, $instance);
        ob_start();
        ?>
		<form class="subscribe-form hocwp-subscribe-form" method="post"
		      data-captcha="<?php 
        echo hocwp_bool_to_int($captcha);
        ?>
"
		      data-register="<?php 
        echo hocwp_bool_to_int($register);
        ?>
">
			<?php 
        echo '<div class="messages"></div>';
        if (!empty($description) && 'before' == $desc_position) {
            echo '<p class="description">' . $description . '</p>';
        }
        foreach ($all_fields as $field_name) {
            $field = hocwp_get_value_by_key($this->args['fields'], $field_name);
            if (hocwp_array_has_value($field)) {
                $label = $this->get_value_field($instance, $field_name, 'label');
                $placeholder = $this->get_value_field($instance, $field_name, 'placeholder');
                $required = $this->get_value_field($instance, $field_name, 'required');
                $class = hocwp_sanitize_html_class($field_name);
                $field_args = array('id' => $this->get_field_id('subscribe_' . $field_name), 'name' => $this->get_field_name('subscribe_' . $field_name), 'value' => '', 'label' => $label, 'placeholder' => $placeholder, 'required' => $required, 'class' => 'form-control input-' . $class, 'before' => '<div class="form-group field-' . $class . '">', 'after' => '</div>');
                hocwp_field_input($field_args);
            }
        }
        if (!empty($description) && 'after' == $desc_position) {
            echo '<p class="description">' . $description . '</p>';
        }
        if ($captcha) {
            $captcha_label = hocwp_get_value_by_key($instance, 'captcha_label', hocwp_get_value_by_key($this->args, 'captcha_label'));
            $captcha_placeholder = hocwp_get_value_by_key($instance, 'captcha_placeholder', hocwp_get_value_by_key($this->args, 'captcha_placeholder'));
            $field_args = array('id' => $this->get_field_id('captcha'), 'name' => $this->get_field_name('captcha'), 'input_width' => '100%', 'class' => 'form-control', 'label' => $captcha_label, 'placeholder' => $captcha_placeholder, 'before' => '<div class="form-group field-captcha">', 'after' => '</div>');
            hocwp_field_captcha($field_args);
        }
        $field_args = array('type' => 'submit', 'name' => 'submit', 'value' => $button_text, 'class' => 'form-control', 'before' => '<div class="form-group field-submit">', 'after' => '</div>');
        hocwp_field_input($field_args);
        hocwp_loading_image(array('name' => 'icon-loading-long.gif'));
        ?>
		</form>
		<?php 
        $widget_html = ob_get_clean();
        $widget_html = apply_filters('hocwp_widget_subscribe_html', $widget_html, $args, $instance, $this);
        echo $widget_html;
        hocwp_widget_after($args, $instance);
    }
function hocwp_setup_theme_comment_form_submit_field($submit_field, $args)
{
    if (hocwp_use_comment_form_captcha() && !hocwp_use_comment_form_captcha_custom_position()) {
        $disable_captcha_user = hocwp_user_not_use_comment_form_captcha();
        if (!$disable_captcha_user || $disable_captcha_user && !is_user_logged_in()) {
            $submit_field = str_replace('form-submit', 'form-submit captcha-beside', $submit_field);
            ob_start();
            $args = array('before' => '<p class="captcha-group">', 'after' => '</p>', 'input_width' => 165);
            hocwp_field_captcha($args);
            $captcha_field = ob_get_clean();
            $submit_field .= $captcha_field;
        }
    }
    return $submit_field;
}