0

This alert shows when you click Delete Permanently on a media (attachment) item.

My Goal: I want to change the text of the alert if the current user has a certain custom meta value. Also, changing wordpress core is not an acceptable answer because updates would wipe my code.

I see this message's text is set in 2 places:

1 - wp-includes/script-loader.php (the wp_default_scripts() function)

2 - wp-includes/media.php (the wp_enqueue_media() function)

Here is the relevant code from script-loader.php for your convenience:

did_action( 'init' ) && $scripts->localize( 'common', 'commonL10n', array( 'warnDelete' => __( "You are about to permanently delete these items from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete." ), 'dismiss' => __( 'Dismiss this notice.' ), 'collapseMenu' => __( 'Collapse Main menu' ), 'expandMenu' => __( 'Expand Main menu' ), ));

I tried preventing the alert and adding my own via jquery, but this is not a good solution. Can I re-localize the "common" script myself with my message as the warnDelete maybe? Any ideas would be much appreciated.

1

You could use the gettext filter. See the examples here https://codex.wordpress.org/Plugin_API/Filter_Reference/gettext. In your filter you will add code to check

  1. IF it's the exact text you want to change
  2. then if the users meta value is what you are looking for

the return the revised text.

Else return the passed text unchanged.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.