Пример #1
0
    function __construct($attributes, $content = null)
    {
        global $post;
        // Set up the default subject and recipient for this form
        $default_to = '';
        $default_subject = "[" . get_option('blogname') . "]";
        if (!empty($attributes['widget']) && $attributes['widget']) {
            $default_to .= get_option('admin_email');
            $attributes['id'] = 'widget-' . $attributes['widget'];
            $default_subject = sprintf(_x('%1$s Sidebar', '%1$s = blog name', 'jetpack'), $default_subject);
        } else {
            if ($post) {
                $attributes['id'] = $post->ID;
                $default_subject = sprintf(_x('%1$s %2$s', '%1$s = blog name, %2$s = post title', 'jetpack'), $default_subject, Grunion_Contact_Form_Plugin::strip_tags($post->post_title));
                $post_author = get_userdata($post->post_author);
                $default_to .= $post_author->user_email;
            }
        }
        // Keep reference to $this for parsing form fields
        self::$current_form = $this;
        $this->defaults = array('to' => $default_to, 'subject' => $default_subject, 'show_subject' => 'no', 'widget' => 0, 'id' => null, 'submit_button_text' => __('Submit »', 'jetpack'));
        $attributes = shortcode_atts($this->defaults, $attributes, 'contact-form');
        // We only enable the contact-field shortcode temporarily while processing the contact-form shortcode
        Grunion_Contact_Form_Plugin::$using_contact_form_field = true;
        parent::__construct($attributes, $content);
        // There were no fields in the contact form. The form was probably just [contact-form /]. Build a default form.
        if (empty($this->fields)) {
            // same as the original Grunion v1 form
            $default_form = '
				[contact-field label="' . __('Name', 'jetpack') . '" type="name"  required="true" /]
				[contact-field label="' . __('Email', 'jetpack') . '" type="email" required="true" /]
				[contact-field label="' . __('Website', 'jetpack') . '" type="url" /]';
            if ('yes' == strtolower($this->get_attribute('show_subject'))) {
                $default_form .= '
					[contact-field label="' . __('Subject', 'jetpack') . '" type="subject" /]';
            }
            $default_form .= '
				[contact-field label="' . __('Message', 'jetpack') . '" type="textarea" /]';
            $this->parse_content($default_form);
            // Store the shortcode
            $this->store_shortcode($default_form, $attributes);
        } else {
            // Store the shortcode
            $this->store_shortcode($content, $attributes);
        }
        // $this->body and $this->fields have been setup.  We no longer need the contact-field shortcode.
        Grunion_Contact_Form_Plugin::$using_contact_form_field = false;
    }