This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
So, you’re diving into WordPress hooks and stumbled upon the make_spam_blog action. Great choice! This hook is triggered when the ‘spam’ status is added to a site. To get started, you’ll need to register it using add_action
. You can place this code in the functions.php
file of your activated theme or, better yet, in a custom WordPress Plugin. WePlugins always recommend creating custom plugins to ensure nothing breaks when you update your WordPress theme.
Let’s walk through how to use this hook with some live examples.
Parameters
- $site_id : (int) Site ID.
Below is the required parameter to use this hook:
Live Example #1: Basic Implementation
This example demonstrates a simple function that executes when the make_spam_blog
action is triggered.
function weplugins_execute_on_make_spam_blog_event($site_id) { // Your custom code here error_log("Site ID " . $site_id . " has been marked as spam."); } // Add the action add_action("make_spam_blog", "weplugins_execute_on_make_spam_blog_event", 10, 1);
Live Example #2: Sending an Email Notification
In this example, we’ll send an email notification whenever a site is marked as spam.
function weplugins_notify_admin_on_spam_blog($site_id) { $admin_email = get_option('admin_email'); $subject = "Site Marked as Spam"; $message = "Site with ID " . $site_id . " has been marked as spam."; wp_mail($admin_email, $subject, $message); } // Add the action add_action("make_spam_blog", "weplugins_notify_admin_on_spam_blog", 10, 1);
Live Example #3: Removing the Action
Sometimes, you may need to remove a registered hook. Here’s how you can do that.
function weplugins_remove_spam_blog_action() { remove_action("make_spam_blog", "weplugins_execute_on_make_spam_blog_event", 10, 1); } // Call this function where you need to remove the action weplugins_remove_spam_blog_action();
Make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.
Contact Us
If you’re having any trouble using this hook or need customization, please contact us. We’re here to help!
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.