Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
File Manager
/
wp-content
/
plugins
/
elementor
/
includes
/
managers
:
contact-form.php
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php class WPCF7_ContactForm { use WPCF7_SWV_SchemaHolder; const post_type = 'wpcf7_contact_form'; private static $found_items = 0; private static $current = null; private $id; private $name; private $title; private $locale; private $properties = array(); private $unit_tag; private $responses_count = 0; private $scanned_form_tags; private $shortcode_atts = array(); /** * Returns count of contact forms found by the previous retrieval. * * @return int Count of contact forms. */ public static function count() { return self::$found_items; } /** * Returns the contact form that is currently processed. * * @return WPCF7_ContactForm Current contact form object. */ public static function get_current() { return self::$current; } /** * Registers the post type for contact forms. */ public static function register_post_type() { register_post_type( self::post_type, array( 'labels' => array( 'name' => __( 'Contact Forms', 'contact-form-7' ), 'singular_name' => __( 'Contact Form', 'contact-form-7' ), ), 'rewrite' => false, 'query_var' => false, 'public' => false, 'capability_type' => 'page', 'capabilities' => array( 'edit_post' => 'wpcf7_edit_contact_form', 'read_post' => 'wpcf7_read_contact_form', 'delete_post' => 'wpcf7_delete_contact_form', 'edit_posts' => 'wpcf7_edit_contact_forms', 'edit_others_posts' => 'wpcf7_edit_contact_forms', 'publish_posts' => 'wpcf7_edit_contact_forms', 'read_private_posts' => 'wpcf7_edit_contact_forms', ), ) ); } /** * Retrieves contact form data that match given conditions. * * @param string|array $args Optional. Arguments to be passed to WP_Query. * @return array Array of WPCF7_ContactForm objects. */ public static function find( $args = '' ) { $defaults = array( 'post_status' => 'any', 'posts_per_page' => -1, 'offset' => 0, 'orderby' => 'ID', 'order' => 'ASC', ); $args = wp_parse_args( $args, $defaults ); $args['post_type'] = self::post_type; $q = new WP_Query(); $posts = $q->query( $args ); self::$found_items = $q->found_posts; $objs = array(); foreach ( (array) $posts as $post ) { $objs[] = new self( $post ); } return $objs; } /** * Returns a contact form data filled by default template contents. * * @param string|array $args Optional. Contact form options. * @return WPCF7_ContactForm A new contact form object. */ public static function get_template( $args = '' ) { $args = wp_parse_args( $args, array( 'locale' => '', 'title' => __( 'Untitled', 'contact-form-7' ), ) ); $locale = $args['locale']; $title = $args['title']; if ( ! $switched = wpcf7_load_textdomain( $locale ) ) { $locale = determine_locale(); } $contact_form = new self; $contact_form->title = $title; $contact_form->locale = $locale; $properties = $contact_form->get_properties(); foreach ( $properties as $key => $value ) { $default_template = WPCF7_ContactFormTemplate::get_default( $key ); if ( isset( $default_template ) ) { $properties[$key] = $default_template; } } $contact_form->properties = $properties; $contact_form = apply_filters( 'wpcf7_contact_form_default_pack', $contact_form, $args ); if ( $switched ) { wpcf7_load_textdomain(); } self::$current = $contact_form; return $contact_form; } /** * Returns an instance of WPCF7_ContactForm. * * @return WPCF7_ContactForm A new contact form object. */ public static function get_instance( $post ) { $post = get_post( $post ); if ( ! $post or self::post_type != get_post_type( $post ) ) { return false; } return self::$current = new self( $post ); } /** * Generates a "unit-tag" for the given contact form ID. * * @return string Unit-tag. */ private static function generate_unit_tag( $id = 0 ) { static $global_count = 0; $global_count += 1; if ( in_the_loop() ) { $unit_tag = sprintf( 'wpcf7-f%1$d-p%2$d-o%3$d', absint( $id ), get_the_ID(), $global_count ); } else { $unit_tag = sprintf( 'wpcf7-f%1$d-o%2$d', absint( $id ), $global_count ); } return $unit_tag; } /** * Constructor. */ private function __construct( $post = null ) { $post = get_post( $post ); if ( $post and self::post_type == get_post_type( $post ) ) { $this->id = $post->ID; $this->name = $post->post_name; $this->title = $post->post_title; $this->locale = get_post_meta( $post->ID, '_locale', true ); $this->construct_properties( $post ); $this->upgrade(); } else { $this->construct_properties(); } do_action( 'wpcf7_contact_form', $this ); } /** * Magic method for property overloading. */ public function __get( $name ) { $message = __( '<code>%1$s</code> property of a <code>WPCF7_ContactForm</code> object is <strong>no longer accessible</strong>. Use <code>%2$s</code> method instead.', 'contact-form-7' ); if ( 'id' == $name ) { if ( WP_DEBUG ) { trigger_error( sprintf( $message, 'id', 'id()' ), E_USER_DEPRECATED ); } return $this->id; } elseif ( 'title' == $name ) { if ( WP_DEBUG ) { trigger_error( sprintf( $message, 'title', 'title()' ), E_USER_DEPRECATED ); } return $this->title; } elseif ( $prop = $this->prop( $name ) ) { if ( WP_DEBUG ) { trigger_error( sprintf( $message, $name, 'prop(\'' . $name . '\')' ), E_USER_DEPRECATED ); } return $prop; } } /** * Returns true if this contact form is not yet saved to the database. */ public function initial() { return empty( $this->id ); } /** * Constructs contact form properties. This is called only once * from the constructor. */ private function construct_properties( $post = null ) { $builtin_properties = array( 'form' => '', 'mail' => array(), 'mail_2' => array(), 'messages' => array(), 'additional_settings' => '', ); $properties = apply_filters( 'wpcf7_pre_construct_contact_form_properties', $builtin_properties, $this ); // Filtering out properties with invalid name $properties = array_filter( $properties, function ( $key ) { $sanitized_key = sanitize_key( $key ); return $key === $sanitized_key; }, ARRAY_FILTER_USE_KEY ); foreach ( $properties as $name => $val ) { $prop = $this->retrieve_property( $name ); if ( isset( $prop ) ) { $properties[$name] = $prop; } } $this->properties = $properties; foreach ( $properties as $name => $val ) { $properties[$name] = apply_filters( "wpcf7_contact_form_property_{$name}", $val, $this ); } $this->properties = $properties; $properties = (array) apply_filters( 'wpcf7_contact_form_properties', $properties, $this ); $this->properties = $properties; } /** * Retrieves contact form property of the specified name from the database. * * @param string $name Property name. * @return array|string|null Property value. Null if property does not exist. */ private function retrieve_property( $name ) { $property = null; if ( ! $this->initial() ) { $post_id = $this->id; if ( metadata_exists( 'post', $post_id, '_' . $name ) ) { $property = get_post_meta( $post_id, '_' . $name, true ); } elseif ( metadata_exists( 'post', $post_id, $name ) ) { $property = get_post_meta( $post_id, $name, true ); } } return $property; } /** * Returns the value for the given property name. * * @param string $name Property name. * @return array|string|null Property value. Null if property does not exist. */ public function prop( $name ) { $props = $this->get_properties(); return isset( $props[$name] ) ? $props[$name] : null; } /** * Returns all the properties. * * @return array This contact form's properties. */ public function get_properties() { return (array) $this->properties; } /** * Updates properties. * * @param array $properties New properties. */ public function set_properties( $properties ) { $defaults = $this->get_properties(); $properties = wp_parse_args( $properties, $d