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

enhance: inconsistent format in email templates #1475

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function __construct() {
'submit_text' => __( 'Create Event', 'wp-user-frontend' ),
'edit_post_status' => 'publish',
'edit_redirect_to' => 'same',
'update_message' => __( 'Event has been updated successfully. <a target="_blank" href="%link%">View event</a>',
'update_message' => __( 'Event has been updated successfully. <a target="_blank" href="{link}">View event</a>',
'wp-user-frontend' ),
'edit_url' => '',
'update_text' => __( 'Update Event', 'wp-user-frontend' ),
Expand All @@ -192,28 +192,28 @@ public function __construct() {
'new_to' => get_option( 'admin_email' ),
'new_subject' => 'New event has been created',
'new_body' => 'Hi,
A new event has been created in your site %sitename% (%siteurl%).
A new event has been created in your site {sitename} ({siteurl}).

Here is the details:
Event Title: %post_title%
Description: %post_content%
Short Description: %post_excerpt%
Author: %author%
Post URL: %permalink%
Edit URL: %editlink%',
Event Title: {post_title}
Description: {post_content}
Short Description: {post_excerpt}
Author: {author}
Post URL: {permalink}
Edit URL: {editlink}',
'edit' => 'off',
'edit_to' => get_option( 'admin_email' ),
'edit_subject' => 'Post has been edited',
'edit_body' => 'Hi,
The event "%post_title%" has been updated.
The event "{post_title}" has been updated

Here is the details:
Event Title: %post_title%
Description: %post_content%
Short Description: %post_excerpt%
Author: %author%
Post URL: %permalink%
Edit URL: %editlink%',
Event Title: {post_title}
Description: {post_content}
Short Description: {post_excerpt}
Author: {author}
Post URL: {permalink}
Edit URL: {editlink}'
],
];
}
Expand Down
30 changes: 15 additions & 15 deletions includes/Admin/Forms/Post/Templates/Post_Form_Template_Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function __construct() {
],
'edit_post_status' => 'publish',
'edit_redirect_to' => 'same',
'update_message' => __( 'Post has been updated successfully. <a target="_blank" href="%link%">View post</a>', 'wp-user-frontend' ),
'update_message' => __( 'Post has been updated successfully. <a target="_blank" href="{link}">View post</a>', 'wp-user-frontend' ),
'edit_url' => '',
'update_text' => __( 'Update Post', 'wp-user-frontend' ),
'form_template' => 'post_form_template_post',
Expand All @@ -157,28 +157,28 @@ public function __construct() {
'new_to' => get_option( 'admin_email' ),
'new_subject' => 'New post has been created',
'new_body' => 'Hi,
A new post has been created in your site %sitename% (%siteurl%).
A new post has been created in your site {sitename} ({siteurl}).

Here is the details:
Post Title: %post_title%
Description: %post_content%
Short Description: %post_excerpt%
Author: %author%
Post URL: %permalink%
Edit URL: %editlink%',
Post Title: {post_title}
Description: {post_content}
Short Description: {post_excerpt}
Author: {author}
Post URL: {permalink}
Edit URL: {editlink}',
'edit' => 'off',
'edit_to' => get_option( 'admin_email' ),
'edit_subject' => 'Post has been edited',
'edit_body' => 'Hi,
The post "%post_title%" has been updated.
The post "{post_title}" has been updated

Here is the details:
Post Title: %post_title%
Description: %post_content%
Short Description: %post_excerpt%
Author: %author%
Post URL: %permalink%
Edit URL: %editlink%',
Post Title: {post_title}
Description: {post_content}
Short Description: {post_excerpt}
Author: {author}
Post URL: {permalink}
Edit URL: {editlink}'
],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function __construct() {
'submit_text' => 'Create Product',
'edit_post_status' => 'publish',
'edit_redirect_to' => 'same',
'update_message' => 'Product has been updated successfully. <a target="_blank" href="%link%">View Product</a>',
'update_message' => 'Product has been updated successfully. <a target="_blank" href="{link}">View Product</a>',
'edit_url' => '',
'update_text' => 'Update Product',
'form_template' => 'post_form_template_woocommerce',
Expand All @@ -199,28 +199,28 @@ public function __construct() {
'new_to' => get_option( 'admin_email' ),
'new_subject' => 'New product has been created',
'new_body' => 'Hi,
A new product has been created in your site %sitename% (%siteurl%).
A new product has been created in your site {sitename} ({siteurl}).

Here is the details:
Product Title: %post_title%
Description: %post_content%
Short Description: %post_excerpt%
Author: %author%
Post URL: %permalink%
Edit URL: %editlink%',
Product Title: {post_title}
Description: {post_content}
Short Description: {post_excerpt}
Author: {author}
Post URL: {permalink}
Edit URL: {editlink}',
'edit' => 'off',
'edit_to' => get_option( 'admin_email' ),
'edit_subject' => 'Product has been edited',
'edit_body' => 'Hi,
The product "%post_title%" has been updated.
The product "{post_title}" has been updated

Here is the details:
Product Title: %post_title%
Description: %post_content%
Short Description: %post_excerpt%
Author: %author%
Post URL: %permalink%
Edit URL: %editlink%',
Product Title: {post_title}
Description: {post_content}
Short Description: {post_excerpt}
Author: {author}
Post URL: {permalink}
Edit URL: {editlink}'
],
];
}
Expand Down
9 changes: 4 additions & 5 deletions includes/Admin/Upgrades.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Upgrades {
'2.9.2' => 'upgrades/upgrade-2.9.2.php',
'3.6.0' => 'upgrades/upgrade-3.6.0.php',
'4.0.4' => 'upgrades/upgrade-4.0.4.php',
'4.0.11' => 'upgrades/upgrade-4.0.11.php',
];

/**
Expand Down Expand Up @@ -53,7 +54,6 @@ public function get_version() {
* @return bool
*/
public function needs_update() {

// may be it's the first install
if ( ! $this->get_version() ) {
return false;
Expand Down Expand Up @@ -88,11 +88,10 @@ public function perform_updates() {
if ( file_exists( $path ) ) {
include_once $path;
}
update_option( 'wpuf_version', $version );
}
}

update_option( 'wpuf_version', WPUF_VERSION );
update_option( wpuf()->get_db_version_key(), WPUF_VERSION );
}

/**
Expand All @@ -118,8 +117,8 @@ public function show_upgrade_notice() {
);
?>
<div id="message" class="updated">
<p><?php printf( '<strong>%s</strong>', esc_attr__( 'WPUF Data Update Required', 'wp-user-frontend' ) ); ?></p>
<p class="submit"><a href="<?php echo esc_url( $link ); ?>" class="wpuf-update-btn button-primary"><?php esc_attr_e( 'Run the updater', 'wp-user-frontend' ); ?></a></p>
<p><?php printf( '<strong>%s</strong>', esc_html__( 'WPUF Data Update Required', 'wp-user-frontend' ) ); ?></p>
<p class="submit"><a href="<?php echo esc_url( $link ); ?>" class="wpuf-update-btn button-primary"><?php esc_html_e( 'Run the updater', 'wp-user-frontend' ); ?></a></p>
</div>

<script type="text/javascript">
Expand Down
28 changes: 14 additions & 14 deletions includes/Ajax/Frontend_Form_Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,18 +624,18 @@ public function prepare_mail_body( $content, $user_id, $post_id ) {
$post = get_post( $post_id );

$post_field_search = [
'%post_title%',
'%post_content%',
'%post_excerpt%',
'%tags%',
'%category%',
'%author%',
'%author_email%',
'%author_bio%',
'%sitename%',
'%siteurl%',
'%permalink%',
'%editlink%',
'{post_title}',
'{post_content}',
'{post_excerpt}',
'{tags}',
'{category}',
'{author}',
'{author_email}',
'{author_bio}',
'{sitename}',
'{siteurl}',
'{permalink}',
'{editlink}',
];

$home_url = sprintf( '<a href="%s">%s</a>', home_url(), home_url() );
Expand All @@ -658,14 +658,14 @@ public function prepare_mail_body( $content, $user_id, $post_id ) {
];

if ( class_exists( 'WooCommerce' ) ) {
$post_field_search[] = '%product_cat%';
$post_field_search[] = '{product_cat}';
$post_field_replace[] = get_the_term_list( $post_id, 'product_cat', '', ', ' );
}

$content = str_replace( $post_field_search, $post_field_replace, $content );

// custom fields
preg_match_all( '/%custom_([\w-]*)\b%/', $content, $matches );
preg_match_all( '/{custom_([\w-]*)\b}/', $content, $matches );
[ $search, $replace ] = $matches;

if ( $replace ) {
Expand Down
22 changes: 11 additions & 11 deletions includes/Free/Form_Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,17 @@
global $post;

$new_mail_body = "Hi Admin,\r\n";
$new_mail_body .= "A new post has been created in your site %sitename% (%siteurl%).\r\n\r\n";
$new_mail_body .= "A new post has been created in your site {sitename} ({siteurl}).\r\n\r\n";

$edit_mail_body = "Hi Admin,\r\n";
$edit_mail_body .= "The post \"%post_title%\" has been updated.\r\n\r\n";
$edit_mail_body .= "The post \"{post_title}\" has been updated.\r\n\r\n";

$mail_body = "Here is the details:\r\n";
$mail_body .= "Post Title: %post_title%\r\n";
$mail_body .= "Content: %post_content%\r\n";
$mail_body .= "Author: %author%\r\n";
$mail_body .= "Post URL: %permalink%\r\n";
$mail_body .= 'Edit URL: %editlink%';
$mail_body .= "Post Title: {post_title}\r\n";
$mail_body .= "Content: {post_content}\r\n";
$mail_body .= "Author: {author}\r\n";
$mail_body .= "Post URL: {permalink}\r\n";
$mail_body .= 'Edit URL: {editlink}';

$form_settings = wpuf_get_form_settings( $post->ID );

Expand Down Expand Up @@ -288,13 +288,13 @@

<h3><?php esc_html_e( 'You may use in to, subject & message:', 'wp-user-frontend' ); ?></h3>
<p>
<code>%post_title%</code>, <code>%post_content%</code>, <code>%post_excerpt%</code>, <code>%tags%</code>, <code>%category%</code>,
<code>{post_title}</code>, <code>{post_content}</code>, <code>{post_excerpt}</code>, <code>{tags}</code>, <code>{category}</code>,
<?php
if ( class_exists( 'WooCommerce' ) ) :
?>
<code>%product_cat%</code> <?php endif ?>,
<code>%author%</code>, <code>%author_email%</code>, <code>%author_bio%</code>, <code>%sitename%</code>, <code>%siteurl%</code>, <code>%permalink%</code>, <code>%editlink%</code>
<br><code>%custom_{NAME_OF_CUSTOM_FIELD}%</code> e.g: <code>%custom_website_url%</code> for <code>website_url</code> meta field
<code>{product_cat}</code> <?php endif ?>,
<code>{author}</code>, <code>{author_email}</code>, <code>{author_bio}</code>, <code>{sitename}</code>, <code>{siteurl}</code>, <code>{permalink}</code>, <code>{editlink}</code>
<br><code>{custom_{NAME_OF_CUSTOM_FIELD}}</code> e.g: <code>{custom_website_url}</code> for <code>website_url</code> meta field
</p>

<?php
Expand Down Expand Up @@ -432,7 +432,7 @@
<td>
<select disabled name="">
<?php
$pages = get_posts( [

Check failure on line 435 in includes/Free/Form_Element.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Opening parenthesis of a multi-line function call must be the last content on the line
'numberposts' => -1,
'post_type' => 'page',
]);
Expand Down
2 changes: 1 addition & 1 deletion includes/Frontend/Frontend_Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
return;
}

$post_id = isset( $_GET['pid'] ) ? intval( wp_unslash( $_GET['pid'] ) ) : 0;

Check warning on line 55 in includes/Frontend/Frontend_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.

Check warning on line 55 in includes/Frontend/Frontend_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.

if ( ! $post_id ) {
return '<div class="wpuf-info">' . __( 'Invalid post', 'wp-user-frontend' ) . '</div>';
Expand Down Expand Up @@ -107,7 +107,7 @@
$form = new Form( $form_id );

$this->form_fields = $form->get_fields();
// $form_settings = wpuf_get_form_settings( $form_id );

Check warning on line 110 in includes/Frontend/Frontend_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

This comment is 55% valid code; is this commented out code?
$this->form_settings = $form->get_settings();

$disable_pending_edit = wpuf_get_option( 'disable_pending_edit', 'wpuf_dashboard', 'on' );
Expand All @@ -121,11 +121,11 @@
return '<div class="wpuf-info">' . __( 'You\'re not allowed to edit this post.', 'wp-user-frontend' );
}

$msg = isset( $_GET['msg'] ) ? sanitize_text_field( wp_unslash( $_GET['msg'] ) ) : '';

Check warning on line 124 in includes/Frontend/Frontend_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.

Check warning on line 124 in includes/Frontend/Frontend_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.

if ( $msg === 'post_updated' ) {
echo wp_kses_post( '<div class="wpuf-success">' );
echo wp_kses_post( str_replace( '%link%', get_permalink( $post_id ), $this->form_settings['update_message'] ) );
echo wp_kses_post( str_replace( '{link}', get_permalink( $post_id ), $this->form_settings['update_message'] ) );
echo wp_kses_post( '</div>' );
}

Expand Down Expand Up @@ -165,7 +165,7 @@
public function draft_post() {
check_ajax_referer( 'wpuf_form_add' );
add_filter( 'wpuf_form_fields', [ $this, 'add_field_settings' ] );
@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );

Check warning on line 168 in includes/Frontend/Frontend_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Silencing errors is strongly discouraged. Use proper error checking instead. Found: @Header( 'Content-Type: application/json; charset=' ...

$form_id = isset( $_POST['form_id'] ) ? intval( wp_unslash( $_POST['form_id'] ) ) : 0;
$form = new Form( $form_id );
Expand All @@ -173,7 +173,7 @@
$this->form_fields = $form->get_fields();
$pay_per_post = $form->is_enabled_pay_per_post();

[ $post_vars, $taxonomy_vars, $meta_vars ] = $this->get_input_fields( $this->form_fields );

Check failure on line 176 in includes/Frontend/Frontend_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The shorthand list syntax "[]" to destructure arrays is not available in PHP 7.0 or earlier.

$entry_fields = $form->prepare_entries();
$allowed_tags = wp_kses_allowed_html( 'post' );
Expand Down Expand Up @@ -267,7 +267,7 @@

wpuf_clear_buffer();

echo json_encode(

Check warning on line 270 in includes/Frontend/Frontend_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

json_encode() is discouraged. Use wp_json_encode() instead.
[
'post_id' => $post_id,
'action' => isset( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '',
Expand Down Expand Up @@ -301,7 +301,7 @@
$this->form_fields = $form->get_fields();
$this->form_settings = $form->get_settings();
$this->generate_auth_link(); // Translate tag %login% %registration% to login registartion url
[ $user_can_post, $info ] = $form->is_submission_open( $form, $this->form_settings );

Check failure on line 304 in includes/Frontend/Frontend_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The shorthand list syntax "[]" to destructure arrays is not available in PHP 7.0 or earlier.
$info = apply_filters( 'wpuf_addpost_notice', $info, $id, $this->form_settings );
$user_can_post = apply_filters( 'wpuf_can_post', $user_can_post, $id, $this->form_settings );

Expand All @@ -322,7 +322,7 @@
* @since 2.5.8
*/
public function publish_guest_post() {
$post_msg = isset( $_GET['post_msg'] ) ? sanitize_text_field( wp_unslash( $_GET['post_msg'] ) ) : '';

Check warning on line 325 in includes/Frontend/Frontend_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.

Check warning on line 325 in includes/Frontend/Frontend_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.
$pid = isset( $_GET['p_id'] ) ? sanitize_text_field( wp_unslash( $_GET['p_id'] ) ) : '';
$fid = isset( $_GET['f_id'] ) ? sanitize_text_field( wp_unslash( $_GET['f_id'] ) ) : '';

Expand Down Expand Up @@ -425,10 +425,10 @@
public function get_edit_post_link( $url, $post_id ) {
if (
current_user_can( 'edit_post', $post_id )
&& ! current_user_can( 'administrator' )

Check failure on line 428 in includes/Frontend/Frontend_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Capabilities should be used instead of roles. Found "administrator" in function call to current_user_can()
&& ! current_user_can( 'editor' )

Check failure on line 429 in includes/Frontend/Frontend_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Capabilities should be used instead of roles. Found "editor" in function call to current_user_can()
&& ! current_user_can( 'author' )

Check failure on line 430 in includes/Frontend/Frontend_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Capabilities should be used instead of roles. Found "author" in function call to current_user_can()
&& ! current_user_can( 'contributor' )

Check failure on line 431 in includes/Frontend/Frontend_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Capabilities should be used instead of roles. Found "contributor" in function call to current_user_can()
) {
$post = get_post( $post_id );
$form_id = get_post_meta( $post_id, '_wpuf_form_id', true );
Expand Down
79 changes: 79 additions & 0 deletions includes/upgrades/upgrade-4.0.11.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

function wpuf_upgrade_4_0_11_migration() {
global $wpdb;

// get all the post meta from postmeta table where meta_key is 'wpuf_form_settings'
$form_settings = $wpdb->get_results( "SELECT * FROM {$wpdb->postmeta} WHERE meta_key = 'wpuf_form_settings'" );

if ( empty( $form_settings ) ) {
return;
}

$search = [
'%username%',
'%user_email%',
'%display_name%',
'%user_status%',
'%pending_users%',
'%approved_users%',
'%denied_users%',
'%sitename%',
'%post_title%',
'%post_content%',
'%post_excerpt%',
'%tags%',
'%category%',
'%author%',
'%author_email%',
'%author_bio%',
'%siteurl%',
'%permalink%',
'%editlink%',
'%link%',
];
$replace = [
'{username}',
'{user_email}',
'{display_name}',
'{user_status}',
'{pending_users}',
'{approved_users}',
'{denied_users}',
'{sitename}',
'{post_title}',
'{post_content}',
'{post_excerpt}',
'{tags}',
'{category}',
'{author}',
'{author_email}',
'{author_bio}',
'{siteurl}',
'{permalink}',
'{editlink}',
'{link}',
];

foreach ( $form_settings as $form_setting ) {
$unserilized = maybe_unserialize( $form_setting->meta_value );

if ( isset( $unserilized['notification']['new_body'] ) ) {
$new_body = $unserilized['notification']['new_body'];
$updated_new_body = str_replace( $search, $replace, $new_body );

$unserilized['notification']['new_body'] = $updated_new_body;
}

if ( isset( $unserilized['notification']['edit_body'] ) ) {
$edit_body = $unserilized['notification']['edit_body'];
$updated_edit_body = str_replace( $search, $replace, $edit_body );

$unserilized['notification']['edit_body'] = $updated_edit_body;
}

update_post_meta( $form_setting->post_id, 'wpuf_form_settings', $unserilized );
}
}

wpuf_upgrade_4_0_11_migration();
Loading
Loading