Search code examples
phpwordpressadvanced-custom-fieldscustom-post-type

Wordpress: how to overwrite specific update notice


So I've made it so that if u delete a member from my member custom post type that it doesn't go to trash and just permanently deletes it. the problem is I still get this message shown below:

enter image description here

how can I overrule the message in my functions.php

I know I can just /wp-admin/edit.php I can just comment out:

echo '<div id="message" class="updated notice is-dismissible"><p>' . join( ' ', $messages ) . '</p></div>';

but of course, this doesn't work permanently and breaks whenever u update.

So how do I get rid of the 1 post moved to the trash message?

UPDATE

the code to delete users from post type + Wordpress users I use is as follows:

add_action('trashed_post', 'on_delete_members');
function on_delete_members()
{
    $post = get_post();
    if ($post->post_type === 'members' ) {
        $email_address = get_post_meta($post->ID, 'email', true);
        $user = get_user_by('email', $email_address);

        $id = $user->ID;

        wp_delete_user($id);

        wp_delete_post($post->ID, true);
    }
}

Solution

  • Never change WordPress core files. Ever!

    You should use admin_notices hook to customize those messages in your custom post type:

    <?php
    function so60507901_sample_admin_notice__success() {
        ?>
        <div class="notice notice-success is-dismissible">
            <p><?php _e( 'Done!', 'sample-text-domain' ); ?></p>
        </div>
        <?php
    }
    add_action( 'admin_notices', 'so60507901_sample_admin_notice__success' );
    ?>
    

    Once your code is not complete, I can't create a full working example. So you need to adjust it to your needs.