: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
class WPCF7_ContactForm {
use WPCF7_SWV_SchemaHolder;
const post_type = 'wpcf7_contact_form';
private static $found_items = 0;
private static $current = null;
private $properties = array();
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|null Current contact form object. Null if unset.
public static function get_current() {
* Registers the post type for contact forms.
public static function register_post_type() {
register_post_type( self::post_type, array(
'name' => __( 'Contact Forms', 'contact-form-7' ),
'singular_name' => __( 'Contact Form', 'contact-form-7' ),
'capability_type' => 'page',
'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 = '' ) {
$args = wp_parse_args( $args, $defaults );
$args['post_type'] = self::post_type;
$posts = $q->query( $args );
self::$found_items = $q->found_posts;
foreach ( (array) $posts as $post ) {
$objs[] = new self( $post );
* Returns a contact form data filled by default template contents.
* @param string|array $options Optional. Contact form options.
* @return WPCF7_ContactForm A new contact form object.
public static function get_template( $options = '' ) {
$options = wp_parse_args( $options, array(
'title' => __( 'Untitled', 'contact-form-7' ),
if ( ! isset( $options['locale'] ) ) {
$options['locale'] = determine_locale();
$callback = static function ( $options ) {
$contact_form = new self;
$contact_form->title = $options['title'];
$contact_form->locale = $options['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 = wpcf7_switch_locale(
self::$current = apply_filters( 'wpcf7_contact_form_default_pack',
* Creates a WPCF7_ContactForm object and sets it as the current instance.
* @param WPCF7_ContactForm|WP_Post|int $post Object or post ID.
* @return WPCF7_ContactForm|null Contact form object. Null if unset.
public static function get_instance( $post ) {
if ( $post instanceof self ) {
} elseif ( ! empty( $post ) ) {
$post = get_post( $post );
if ( isset( $post ) and self::post_type === get_post_type( $post ) ) {
$contact_form = new self( $post );
return self::$current = $contact_form;
* 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;
$unit_tag = sprintf( 'wpcf7-f%1$d-p%2$d-o%3$d',
$unit_tag = sprintf( 'wpcf7-f%1$d-o%2$d',
private function __construct( $post = null ) {
$post = get_post( $post );
and self::post_type === get_post_type( $post ) ) {
$this->name = $post->post_name;
$this->title = $post->post_title;
$this->locale = get_post_meta( $post->ID, '_locale', true );
$this->hash = get_post_meta( $post->ID, '_hash', true );
$this->construct_properties( $post );
$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' );
sprintf( $message, 'id', 'id()' ),
} elseif ( 'title' == $name ) {
sprintf( $message, 'title', 'title()' ),
} elseif ( $prop = $this->prop( $name ) ) {
sprintf( $message, $name, 'prop(\'' . $name . '\')' ),
* 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
private function construct_properties( $post = null ) {
$builtin_properties = array(
'additional_settings' => '',
$properties = apply_filters(
'wpcf7_pre_construct_contact_form_properties',
$builtin_properties, $this
// Filtering out properties with invalid name
$properties = array_filter(
static function ( $key ) {
$sanitized_key = sanitize_key( $key );
return $key === $sanitized_key;
foreach ( $properties as $name => $val ) {
$prop = $this->retrieve_property( $name );
$properties[$name] = $prop;
$this->properties = $properties;
foreach ( $properties as $name => $val ) {
$properties[$name] = apply_filters(
"wpcf7_contact_form_property_{$name}",
$this->properties = $properties;
$properties = (array) apply_filters(
'wpcf7_contact_form_properties',
$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 ) {
if ( ! $this->initial() ) {
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 );
* 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;
* @param array $properties New properties.
public function set_properties( $properties ) {
$defaults = $this->get_properties();
$properties = wp_parse_args( $properties, $defaults );
$properties = array_intersect_key( $properties, $defaults );
$this->properties = $properties;
* Returns ID of this contact form.
* Returns unit-tag for this contact form.
* @return string Unit-tag.
public function unit_tag() {
* Returns name (slug) of this contact form.
* Returns title of this contact form.
public function title() {
* Set a title for this contact form.
* @param string $title Title.
public function set_title( $title ) {
$title = strip_tags( $title );
$title = __( 'Untitled', 'contact-form-7' );
* Returns the locale code of this contact form.
* @return string Locale code. Empty string if no valid locale is set.
public function locale() {
if ( wpcf7_is_valid_locale( $this->locale ) ) {
* Sets a locale for this contact form.
* @param string $locale Locale code.
public function set_locale( $locale ) {
$locale = trim( $locale );
if ( wpcf7_is_valid_locale( $locale ) ) {
* Retrieves the random hash string tied to this contact form.
* @param int $length Length of hash string.
* @return string Hash string unique to this contact form.
public function hash( $length = 7 ) {
return substr( $this->hash, 0, absint( $length ) );
* Returns the specified shortcode attribute value.
* @param string $name Shortcode attribute name.
* @return string|null Attribute value. Null if the attribute does not exist.
public function shortcode_attr( $name ) {
if ( isset( $this->shortcode_atts[$name] ) ) {
return (string) $this->shortcode_atts[$name];