Some customizations

This topic contains 8 replies, has 3 voices, and was last updated by  Stephen Harris 7 years, 3 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #25108

    Hi,
    I’ve just buy the FES plugin and I’ve been playing with it. It works good but I need to do some customization.<br />
    Please can you tell me if there is any way to achieve that:

    1 – I want to asign the First Name to the Event name automatically whithout adding the Event title field in the form

    2 – I want to assign the Email to an specific custom field

    3 – I don’t want the users to choose the category. All the new events submited by the FES form will be assigned to only one specific category

    Just let me know if there is a hook or where to change the code or just point me in the right direction.

    Thank you very much

    aswebmedia
    #25115

    Yes it is possible:

    add_filter( 'eventorganiser_fes_submit_event', function( $event, $form ) {
         $name  = $form->get_element( 'name' );   
         $fname = $name ? $name->get_value( 'fname' ) : '';
         $event['post_title'] = $fname;
    
         $event['event-taxonomy']['event_category'] = array( 123 ); //change to desired term ID
         return $event;
    }, 10, 2 );
    
    add_action( 'eventorganiser_fes_submitted_event', function( $event_id, $event, $form ) {
         $email = $form->get_element( 'email' );
         $email = $email ? sanitize_email( $email->get_value() ) : '';
         update_post_meta( $event_id, 'my_key', $email );
    }, 10, 3 );
    
    • This reply was modified 7 years, 4 months ago by  Stephen Harris. Reason: Corrected bug in first callback
    Stephen Harris
    #25124

    Hi!

    Thanks for the response.

    There is a problem in the first hook. Even getting rid of the code inside the function I get an error:
    Warning: array_merge(): Argument #1 is not an array in ..../plugins/event-organiser/includes/event.php on line 194

    Warning: array_intersect_key(): Argument #1 is not an array in /plugins/event-organiser/includes/event.php on line 215

    Fatal error: Unsupported operand types in plugins/event-organiser/includes/event.php on line 215

    Second hook works fine.. so now, I am able to assign the Email to an specific custom field.

    Let me know if there is a solution.

    Thanks

    aswebmedia
    #25126

    My apologies, the first hook is a filter, so it needs to return the filtered variable ($event). I’ve made that correction.

    The second hook is an action, not a filter. The callback was mistakenly attached using add_filter rather than add_action – but this doesn’t actually matter.

    Stephen Harris
    #25130

    No worries ,

    Works like a charm now!

    Just a small thing:
    $event[‘event-taxonomy’][‘event_category’] should be $event[‘event-taxonomy’][‘event-category’]

    dash instead of underscore.

    Also I used the slug term instead of the ID and works.

    Thanks for your help.

    aswebmedia
    #25602

    Hi Stephen,
    thanks for this code!

    This filter assigns all frontend submission forms to one category, right? Is it possible to choose which form is assigned to which category?
    form 1 –> category 1
    form 2 –> category 2

    Thanks and best regards

    Oliver Flueckiger
    #25618

    Hi Oliver,

    Yes, the callbacks are passed a form instance ($form). You can use $form->id or $form->get('name') to identify the name and set the value of the category ID appropriately.

    Stephen Harris
    #25632

    Thanks, Stephen.
    Unfortunately, I can’t find eventorganiser_fes_submit_event in the documentation and I’m a beginner…
    Do you mind to write the whole snippet for me? Thank you!

    Oliver Flueckiger
    #25642

    Try:

    add_filter( 'eventorganiser_fes_submit_event', function( $event, $form ) {
         switch ( $form->id ) {
             case 12: 
                   $category_id = 34; //If form ID is 12, set to category 34
                   break;
             case 56:
                   $category_id = 78;//If form ID is 56, set to category 78
                   break;
             default:
                   $category_id = 9; //for any other forms set to category 9
                   break;
         }    
         $event['event-taxonomy']['event_category'] = array( $category_id ); //change to desired term ID
         return $event;
    }, 10, 2 );
    

    Simply replace the form IDs and the category IDs as required..

    Stephen Harris
Viewing 9 posts - 1 through 9 (of 9 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.