Well let’s compare the hook to one that is working:
add_action( 'admin_init', array( $this, 'page_init' ) );
add_action( 'publish_pelicula', 'post_published_notification', 10, 2 );
page_init()
and post_published_notification()
are both methods of the MySettingsPage
class, but you’ve set the action callbacks for each of them differently.
The second argument for add_action()
is a callback. It tells WordPress/PHP which function to run when the action is fired. For an action to call a class method, you need to pass an array:
A method of an instantiated object is passed as an array containing an
object at index 0 and the method name at index 1.
Since you’re running add_action
inside a class, the object in question is $this
, and the method name is post_published_notification
. You’ve done this correctly for page_init
, so you just need to do that same for post_published_notification
:
add_action( 'publish_pelicula', array( $this, 'post_published_notification' ), 10, 2 );