Skip to content

Commit

Permalink
enhance: inconsistent format in email templates
Browse files Browse the repository at this point in the history
  • Loading branch information
sapayth committed Aug 22, 2024
1 parent 60b2b68 commit 6a112c5
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 139 deletions.
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 @@ -195,25 +195,25 @@ public function __construct() {
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
28 changes: 14 additions & 14 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 @@ -160,25 +160,25 @@ public function __construct() {
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 @@ -202,25 +202,25 @@ public function __construct() {
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
24 changes: 12 additions & 12 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 Down
20 changes: 10 additions & 10 deletions includes/Free/Form_Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ public static function add_post_notification_content() {
$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 @@ public static function add_post_notification_content() {

<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
2 changes: 1 addition & 1 deletion includes/Frontend/Frontend_Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function edit_post_shortcode( $atts ) {

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
81 changes: 81 additions & 0 deletions includes/upgrades/upgrade-4.0.11.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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}',
];

// error_log( print_r( $form_settings, true ) );

Check warning on line 58 in includes/upgrades/upgrade-4.0.11.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

This comment is 54% valid code; is this commented out code?

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']['email_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

0 comments on commit 6a112c5

Please sign in to comment.