So I’m trying to apply a filter to a variable that I have in a class and its not doing anything. I’ve added the variable in another class thats on a separate file and it works there, but when using it on this one it doesn’t. Here is how I created it and how I’m calling it. Thanks for the help
class WPFrontendForm{
public function __construct($labels = true, $display_required = true){
add_filter( 'wpfrontendform_required_fields', array($this, 'wpfrontend_required') );
}
// Create filter for required fields.
public function wpfrontend_required(){
$rfields = array();
foreach ($this->fields as $field => $value) {
if( $value['required'] == true ){
$rfields[] .= $value['id'];
}
}
return $rfields;
}
And I call it inside of my other class here:
class WPFrontendProcess {
public function validate_form(){
$required = apply_filters( 'wpfrontendform_required_fields', $required );
}
Second parameter for apply_filters should be function name.
Hope this helps.