Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use make_spam_blog action in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
March 6, 2023
5 minutes read

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

    Below is the required parameter to use this hook:

  • $site_id : (int) Site ID.

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.

Access Premium WordPress Plugins

Contact Us

If you’re having any trouble using this hook or need customization, please contact us. We’re here to help!

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

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.