PHP Class Grunion_Contact_Form_Plugin, jetpack

Show file Open project: automattic/jetpack Class Usage Examples

Public Properties

Property Type Description
$current_widget_id The Widget ID of the widget currently being processed. Used to build the unique contact-form ID for forms embedded in widgets.
$using_contact_form_field

Public Methods

Method Description
__construct ( )
add_shortcode ( ) * Adds our contact-form shortcode The "child" contact-field shortcode is enabled as needed by the contact-form shortcode handler
ajax_request ( )
akismet_submit ( string $as, array $form ) Submit a feedback as either spam or ham
allow_feedback_rest_api_type ( $post_types ) Add to REST API post type whitelist
daily_akismet_meta_cleanup ( ) Runs daily to clean up spam detection metadata after 15 days. Keeps your DB squeaky clean.
download_feedback_as_csv ( ) download as a csv a contact form or all of them in a csv file
esc_csv ( string $field ) : string Escape a string to be used in a CSV context
export_form ( ) Prints the menu
get_export_data_for_posts ( array $post_ids ) : array Prepares feedback post data for CSV export.
get_ip_address ( )
get_parsed_field_contents_of_post ( integer $post_id ) : array Get parsed feedback post fields.
get_post_content_for_csv_export ( integer $post_id ) : string Fetch post content for a post and extract just the comment.
get_post_meta_for_csv_export ( integer $post_id ) : mixed Get _feedback_extra_fields field from post meta data.
init ( )
insert_feedback_filter ( array $data, array $postarr ) : array Ensure the post author is always zero for contact-form feedbacks Attached to wp_insert_post_data
is_spam_akismet ( boolean $is_spam, array $form = [] ) : boolean | WP_Error Submit contact-form data to Akismet to check for spam.
map_parsed_field_contents_of_post_to_field_names ( array $parsed_post_content ) : array Properly maps fields that are missing from the post meta data to names, that are similar to those of the post meta.
parse_fields_from_content ( $post_id )
prepare_for_akismet ( array $form ) : array Populate an array with all values necessary to submit a NEW contact-form feedback to Akismet.
process_form_submission ( ) Handles all contact-form POST submissions
replace_tokens_with_input ( string $subject, array $field_values ) : string Replaces tokens like {city} or {City} (case insensitive) with the value of an input field of that name
sanitize_value ( $value )
strip_tags ( mixed $data_with_tags ) : mixed Strips HTML tags from input. Output is NOT HTML safe.
tokenize_label ( $label )
track_current_widget ( array $widget ) Tracks the widget currently being processed.
unread_count ( object $screen ) Display the count of new feedback entries received. It's reset when user visits the Feedback screen.
widget_atts ( string $text ) : string Adds a "widget" attribute to every contact-form embedded in a text widget.
widget_shortcode_hack ( string $text ) : string For sites where text widgets are not processed for shortcodes, we add this hack to process just our shortcode Attached to widget_text

Protected Methods

Method Description
get_feedbacks_as_options ( ) : string Returns a string of HTML
get_field_names ( array | integer $posts ) : array Get the names of all the form's fields
make_csv_row_from_feedback ( integer $post_id, array $fields ) : String Creates a valid csv row from a post id

Method Details

__construct() public method

public __construct ( )

add_shortcode() public method

* Adds our contact-form shortcode The "child" contact-field shortcode is enabled as needed by the contact-form shortcode handler
public add_shortcode ( )

ajax_request() public method

public ajax_request ( )

akismet_submit() public method

Submit a feedback as either spam or ham
public akismet_submit ( string $as, array $form )
$as string Either 'spam' or 'ham'.
$form array the contact-form data

allow_feedback_rest_api_type() public method

Add to REST API post type whitelist
public allow_feedback_rest_api_type ( $post_types )

daily_akismet_meta_cleanup() public method

Runs daily to clean up spam detection metadata after 15 days. Keeps your DB squeaky clean.

download_feedback_as_csv() public method

download as a csv a contact form or all of them in a csv file

esc_csv() public method

Malicious input can inject formulas into CSV files, opening up the possibility for phishing attacks and disclosure of sensitive information. Additionally, Excel exposes the ability to launch arbitrary commands through the DDE protocol.
See also: http://www.contextis.com/resources/blog/comma-separated-vulnerabilities/
public esc_csv ( string $field ) : string
$field string
return string

export_form() public method

Prints the menu
public export_form ( )

get_export_data_for_posts() public method

Prepares feedback post data for CSV export.
public get_export_data_for_posts ( array $post_ids ) : array
$post_ids array Post IDs to fetch the data for. These need to be Feedback posts.
return array

get_feedbacks_as_options() protected method

Returns a string of HTML
protected get_feedbacks_as_options ( ) : string
return string a string of HTML

get_field_names() protected method

Get the names of all the form's fields
Deprecation: As this is no longer necessary as of the CSV export rewrite. - 2015-12-29
protected get_field_names ( array | integer $posts ) : array
$posts array | integer the post we want the fields of
return array the array of fields

get_ip_address() public static method

public static get_ip_address ( )

get_parsed_field_contents_of_post() public method

Get parsed feedback post fields.
public get_parsed_field_contents_of_post ( integer $post_id ) : array
$post_id integer Id of the post to fetch parsed contents for.
return array

get_post_content_for_csv_export() public method

Fetch post content for a post and extract just the comment.
public get_post_content_for_csv_export ( integer $post_id ) : string
$post_id integer The post id to fetch the content for.
return string Trimmed post comment.

get_post_meta_for_csv_export() public method

Get _feedback_extra_fields field from post meta data.
public get_post_meta_for_csv_export ( integer $post_id ) : mixed
$post_id integer Id of the post to fetch meta data for.
return mixed

init() static public method

static public init ( )

insert_feedback_filter() public method

Ensure the post author is always zero for contact-form feedbacks Attached to wp_insert_post_data
See also: Grunion_Contact_Form::process_submission()
public insert_feedback_filter ( array $data, array $postarr ) : array
$data array the data to insert
$postarr array the data sent to wp_insert_post()
return array The filtered $data to insert

is_spam_akismet() public method

If you're accepting a new item via $_POST, run it Grunion_Contact_Form_Plugin::prepare_for_akismet() first Attached to jetpack_contact_form_is_spam
public is_spam_akismet ( boolean $is_spam, array $form = [] ) : boolean | WP_Error
$is_spam boolean
$form array
return boolean | WP_Error TRUE => spam, FALSE => not spam, WP_Error => stop processing entirely

make_csv_row_from_feedback() protected static method

Creates a valid csv row from a post id
Deprecation: This is no longer needed, as of the CSV export rewrite.
protected static make_csv_row_from_feedback ( integer $post_id, array $fields ) : String
$post_id integer The id of the post
$fields array An array containing the names of all the fields of the csv
return String The csv row

map_parsed_field_contents_of_post_to_field_names() public method

Properly maps fields that are missing from the post meta data to names, that are similar to those of the post meta.
See also: parse_fields_from_content for how the input data is generated.
public map_parsed_field_contents_of_post_to_field_names ( array $parsed_post_content ) : array
$parsed_post_content array Parsed post content
return array Mapped fields.

parse_fields_from_content() public static method

public static parse_fields_from_content ( $post_id )

prepare_for_akismet() public method

Note that this includes the current user_ip etc, so this should only be called when accepting a new item via $_POST
public prepare_for_akismet ( array $form ) : array
$form array Contact form feedback array
return array feedback array with additional data ready for submission to Akismet

process_form_submission() public method

Conditionally attached to template_redirect

replace_tokens_with_input() public method

Replaces tokens like {city} or {City} (case insensitive) with the value of an input field of that name
public replace_tokens_with_input ( string $subject, array $field_values ) : string
$subject string
$field_values array Array with field label => field value associations
return string The filtered $subject with the tokens replaced

sanitize_value() static public method

static public sanitize_value ( $value )

strip_tags() public static method

Strips HTML tags from input. Output is NOT HTML safe.
public static strip_tags ( mixed $data_with_tags ) : mixed
$data_with_tags mixed
return mixed

tokenize_label() static public method

static public tokenize_label ( $label )

track_current_widget() public method

Attached to dynamic_sidebar
public track_current_widget ( array $widget )
$widget array The widget data

unread_count() public method

Display the count of new feedback entries received. It's reset when user visits the Feedback screen.
Since: 4.1.0
public unread_count ( object $screen )
$screen object Information about the current screen.

widget_atts() public method

Used to tell the difference between post-embedded contact-forms and widget-embedded contact-forms Attached to widget_text
public widget_atts ( string $text ) : string
$text string The widget text
return string The filtered widget text

widget_shortcode_hack() public method

For sites where text widgets are not processed for shortcodes, we add this hack to process just our shortcode Attached to widget_text
public widget_shortcode_hack ( string $text ) : string
$text string The widget text
return string The contact-form filtered widget text

Property Details

$current_widget_id public property

The Widget ID of the widget currently being processed. Used to build the unique contact-form ID for forms embedded in widgets.
public $current_widget_id

$using_contact_form_field static public property

static public $using_contact_form_field