Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter( 'wp_insert_post_data', 'wpas_custom_status_change_notification', 10, 2 );
- /**
- * Check if the ticket status has changed and, if so, maybe send an e-mail notification if the new status required one.
- *
- * @since 3.0.0
- *
- * @param array $data Post data
- * @param array $postarr Original post data
- *
- * @return array Modified post data for insertion
- */
- function wpas_custom_status_change_notification( $data, $postarr ) {
- // Make sure we only work on tickets and not other post types
- if ( ! isset( $data['post_type'] ) || 'ticket' !== $data['post_type'] ) {
- return $data;
- }
- // We're not interested in tickets being trashed
- if ( 'trash' === $data['post_status'] ) {
- return $data;
- }
- // Not interested in auto-drafts either
- if ( 'auto-draft' === $data['post_status'] ) {
- return $data;
- }
- global $current_user;
- // Make sure the current user has the capability to edit a ticket
- if ( ! user_can( $current_user->ID, 'edit_ticket' ) ) {
- return $data;
- }
- // Get the registered custom status
- $status = wpas_get_post_status();
- // Make sure the new status is a registered one
- if ( array_key_exists( $_POST['post_status_override'], $status ) ) {
- // We only want to send the notification if the status has changed and if a new reply is being posted
- if ( $postarr['original_post_status'] !== $_POST['post_status_override'] && isset( $_POST['wpas_post_parent'] ) ) {
- switch ( $_POST['post_status_override'] ) {
- case 'status1':
- // Do something when the new status is "status1"
- break;
- case 'status2':
- // Do something when the new status is "status2"
- break;
- }
- // If you want to perform the same action whatever the new status then remove the entire switch() block and add your action here
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement