Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update contact-form.php #553

Merged
merged 1 commit into from
Sep 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions includes/contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1115,8 +1115,10 @@ public function nonce_is_active() {
return (bool) apply_filters( 'wpcf7_verify_nonce', $is_active, $this );
}

/* Upgrade */

/**
* Upgrades this contact form properties.
*/
private function upgrade() {
$mail = $this->prop( 'mail' );

Expand All @@ -1140,8 +1142,12 @@ private function upgrade() {
$this->properties['messages'] = $messages;
}

/* Save */

/**
* Stores this contact form properties to the database.
*
* @return int The post ID on success. The value 0 on failure.
*/
public function save() {
$title = wp_slash( $this->title );
$props = wp_slash( $this->get_properties() );
Expand All @@ -1167,7 +1173,8 @@ public function save() {
if ( $post_id ) {
foreach ( $props as $prop => $value ) {
update_post_meta( $post_id, '_' . $prop,
wpcf7_normalize_newline_deep( $value ) );
wpcf7_normalize_newline_deep( $value )
);
}

if ( wpcf7_is_valid_locale( $this->locale ) ) {
Expand All @@ -1187,6 +1194,12 @@ public function save() {
return $post_id;
}


/**
* Makes a copy of this contact form.
*
* @return WPCF7_ContactForm New contact form object.
*/
public function copy() {
$new = new self;
$new->title = $this->title . '_copy';
Expand All @@ -1196,6 +1209,10 @@ public function copy() {
return apply_filters( 'wpcf7_copy', $new, $this );
}


/**
* Deletes this contact form.
*/
public function delete() {
if ( $this->initial() ) {
return;
Expand All @@ -1209,26 +1226,39 @@ public function delete() {
return false;
}


/**
* Returns a WordPress shortcode for this contact form.
*/
public function shortcode( $args = '' ) {
$args = wp_parse_args( $args, array(
'use_old_format' => false ) );
'use_old_format' => false
) );

$title = str_replace( array( '"', '[', ']' ), '', $this->title );

if ( $args['use_old_format'] ) {
$old_unit_id = (int) get_post_meta( $this->id, '_old_cf7_unit_id', true );

if ( $old_unit_id ) {
$shortcode = sprintf( '[contact-form %1$d "%2$s"]', $old_unit_id, $title );
$shortcode = sprintf(
'[contact-form %1$d "%2$s"]',
$old_unit_id,
$title
);
} else {
$shortcode = '';
}
} else {
$shortcode = sprintf( '[contact-form-7 id="%1$d" title="%2$s"]',
$this->id, $title );
$shortcode = sprintf(
'[contact-form-7 id="%1$d" title="%2$s"]',
$this->id,
$title
);
}

return apply_filters( 'wpcf7_contact_form_shortcode',
$shortcode, $args, $this );
$shortcode, $args, $this
);
}
}