apply_filters from within a Class (WordPress) -
i'm writing plugin makes use of wp_mail function. want change from: address. wp provides filters - wp_mail_from_name , wp_mail_from - i'm not sure how call them within class.
if place them outside of function there's parse error (unexpected t_string, expecting t_function).
if place them within function nothing seems happen
class myplugin { public function setfromname($fromname) { apply_filters( 'wp_mail_from_name', $fromname ); $this->fromname = $fromname; } public function setfromemail($fromemail) { apply_filters( 'wp_mail_from', $fromemail ); $this->fromemail = $fromemail; } } how possible affect these filters within class?
in wordpress filters must have call back, can not use variable.
class myplugin { public function myplugin { add_filter( 'wp_mail_from_name', array($this, 'filter_mail_from_name')); add_filter( 'wp_mail_from', array($this, 'filter_mail_from')); } function filter_mail_from_name( $from_name ) { // $from_name comes wordpress, default $from_name // must modify $from_name within function before returning return $from_name; } function filter_mail_from( $from_email ) { // $from_email comes wordpress, default $from_name // must modify $from_email within function before returning return $from_email; } }
Comments
Post a Comment