How to write a plugin that “listens” every time, an edit occurs?

  1. Use the “save_post” action hook, which is triggered every time a post or page is created or updated. In the function called by the hook, you can check the post content for new iframes, and if found, replace the src attributes of iframe elements before they are saved to the database.

  2. Use the “the_content” filter hook, which allows you to modify the post content before it is displayed on the frontend. In the function called by the filter, you can replace the src attributes of all iframe elements on the website with a custom string.

  3. To limit the plugin functionality to certain post types, you can check the post type before making the replacement in both the “save_post” and “the_content” functions.

  4. Once the plugin is ready, activate it in the WordPress backend and it will start listening for post and pages changes and replacing the iframe src attributes as per your custom string.