Support » Plugin: Events Manager » Validate event on creation / modifying and provide error message.

  • Resolved userrebo

    (@userrebo)


    I hooked into em_event_save to check whether my taxonomies are valid or not.
    But if I return false, the event is saved anyway and no error appears.
    I also wonder why em_event_validate (or $EM_Event->validate()) isn’t called, which would make more sense.
    What do I miss?

    Code:

    
    add_filter('em_event_save','em_event_filter_event_save', 1, 2);
    function em_event_filter_event_save($result, $EM_Event)
    {
        $condition = true;  // Some condition for invalid taxonomy 
    
        if ($condition) {
            $EM_Event->add_error('Some error message');
            return false;
        }
        return $result;
    }
    
    • This topic was modified 1 month ago by  userrebo.
    • This topic was modified 1 month ago by  userrebo.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Patrick Buntsma

    (@duisterdenhaag)

    Its not called because you are not calling it.

    Use;
    add_filter(‘em_event_validate_meta’, ‘function_name’, 10, 2)

    userrebo

    (@userrebo)

    Thanks a lot for your fast answer! Worked perfectly:

    
    add_filter('em_event_validate_meta','em_taxonomies_event_validate_meta', 1, 2);
    function em_taxonomies_event_validate_meta($result, $EM_Event){
        // Do validation stuff
        return count($EM_Event->errors) == 0;
    }
    

    You mean it’s not called by the plugin, just like em_event_save?! I only thought the equivalent of em_event_save is em_event_validate, which is not exactly the case here.
    However it works now as it should! Thanks!

    • This reply was modified 1 month ago by  userrebo.
    • This reply was modified 1 month ago by  userrebo.
    Patrick Buntsma

    (@duisterdenhaag)

    It is called, but separately. First validate and if that does not fail, save.
    Two different functions.

    It is a custom function (because of the notices that are outputted.

    The WP save only requires proper sanitation, not validation.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.