Support » Plugin: Events Manager » [Plugin: Events Manager] How to make an event attribute required

Viewing 6 replies - 1 through 6 (of 6 total)
  • not atm, however you can modify template at /templates/forms/event/attributes.php

    using templates –

    Well, as it seems there is no easy way to do it, I have finally modified a couple of files. In case of others interest, here it is what I have done:

    1) Let’s assume you have created an event attribute through EM settings. Let’s call it “attribute1”.

    2) Open classes/em-event.php.

    3) Add the following line below Field names area (around line 60). This will declare the attribute as a property for event class.

    var $event_attribute1;

    4) Add the following line inside get_post() function (around line 320). You will find a similar line for “event_name”. Just put them together. This will request the value provided in the public form.

    $this->event_attribute1 = !empty($_POST['em_attributes']['attribute1'] ) ? wp_kses($_POST['em_attributes']['attribute1'], array()):'';

    5) Add the following code inside validate() function (around line 450). As mentioned, you will find a similar piece of code for “event_name”. This will check if the value is non-empty.

    if( empty($this->event_attribute1) ){
    	$validate_post = false;
    	$this->add_error( __('attribute1').__(" is required.", "dbem") );

    6) Open templates/forms/event-editor.php.

    7) Add the following code beside the input field in the event attributes section (around line 165). This will place the asterisk sign, showing to the user it is a required field.

    <?php echo $name == 'attribute1' ? $required : ''; ?>

    8) You’re done.

    I feel this might not be the better way of achivieng this goal, so I will listen to your suggestions.


    thanks for updating;

    Plugin Author Marcus


    it’s a long explanation, but as you said there’s a better way.

    In fact, it’s not that complicated, you need to hook into the em_event_get_post and em_event_validate filters, which passes $result and $EM_Event.

    You can probably acheive the same result doing that and replace $this with $EM_Event in your changes

    Thank you, Marcus. Although I’m not so WP expert when talking about “hooking” and so on, I would like to leave my code as clean as possible, so I will try your suggestion.

    Plugin Author Marcus


    this is the best place to start then –

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Events Manager] How to make an event attribute required’ is closed to new replies.