Some add_action() statements that i see now and then are provided with an array in which the first argument is $this, and the second one, the function.
As far as i know, $this stands as the current instance in POO, but what about in this particular case? Let's say for the sake of example that we have a newsletter system that registers your email adress, except if it still exists in the database.
<?php
public function save_email()
{
if (isset($_POST['zero_newsletter_email']) && !empty($_POST['zero_newsletter_email'])) {
global $wpdb;
$email = $_POST['zero_newsletter_email'];
$row = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}zero_newsletter_email WHERE email = '$email'");
if (is_null($row)) {
$wpdb->insert("{$wpdb->prefix}zero_newsletter_email", array('email' => $email));
}
}
}
Now we need to declare it as an available action. why should we need an array like this one?
add_action('wp_loaded', array($this, 'save_email'));
And why couldn't we simply do as followed?
add_action('wp_loaded','save_email');