How to pre-populate fields in Add New Event screen?

WordPress Event Management, Calendars & Registration Forums General Question How to pre-populate fields in Add New Event screen?

This topic contains 7 replies, has 2 voices, and was last updated by  John 11 years, 7 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #5318

    I’ve written the better part of an admin plugin that handles specific kinds of recurring events. I want the users to be able to push a button to add events to the calendar through Event Organizer’s Add New Event screen. But since there’s no use in their entering data twice, I’d like to pre-populate the fields for them. Is there any way I can do this?

    I see an action hook eventorganiser_event_settings_imexport, but it has no documentation. Might that be the key?

    John
    #5327

    That hook is for the settings import/export admin page…

    Can you explain your use case – you can already make an event reoccur (and description, title, categories, venue etc are shared across all dates). If you want each date to be a separate event but, say, still share the description – then you can create an event occurring on those dates and then break each occurrence.

    What kind of information do you want to be pre-filled – there are hooks for when an event is updated/inserted – and I’ll be adding more to filter the array returned by http://wp-event-organiser.com/documentation/function/eo_get_event_schedule/ – that might help..

    Stephen Harris
    #5339

    Thanks for your reply, Stephen. My plugin is for church events. The user enters the events in this plugin and it displays the usual schedule on the webpage (shortcodes, widgets) in a particular way and also in the root directory as XML in a standardized format.

    Your plugin’s recurrence ability is one reason I’d like to use your interface for actually putting the event(s) on the calendar. Not to mention that your interface has more flexibility (like excluding days from recurrence). I’m trying to make my plugin as convenient as possible, so I’d like the user to be able to transfer the events from my plugin to yours with just a button push, instead of reentering them. (Or maybe they can enter a start and end date for recurrence, or else the number of times for recurrence.)

    (I’d like to be able to set all the parameters listed for eo_get_event_schedule. The fields in my plugin are Title; Type; Description; Day(s) of week; Monthly flag; if set, then which week(s) of the month (haven’t gotten to day of month yet); Start time; End time– you seem to handle all these already.)

    Btw have you ever considered adding a group ID for recurrence events that come from the same “parent” (for lack of a better word) event? It would help keep track of them in case they needed to be altered or deleted later.

    I would appreciate your help.

    John
    #5340

    I just found this post:
    How to add category to: ‘wp-admin/post-new.php’?. Also found that this works to pre-set the event title: http://example.com/wp/wp-admin/post-new.php?post_type=event&post_title=Hello.

    Using _GET parameters would be convenient! Are the parameters already set up in Event Organizer? If not, should I hook into 'wp_insert_post' or is there a comparable hook for events?

    John
    #5354

    I don’t think the $_GET parameters will work, but you can use the eventorganiser_get_event_schedule filter (make sure you’re on 1.8.5). If you check that you are on the ‘new post’ screen (via get_current_screen()) and then over-ride it with the defaults.

    Also, the ‘group ID’ is essentially the post ID as one event (post) can have multiple dates. (Or do you mean occurrences which have been broken from a recurring event?).


    On a side note, I’d be interested to find out more about how you’re intending to use the plug-in (sounds like you’re developing something like an add-on?). I’ve noticed a lot of my users are church based (and hopefully soon, my own 🙂 ) – so I’d love to find out if there would be any useful church-focussed features that could comprise an add-on (or if there is already an add-on for EO). Feel free to shoot me an e-mail.

    Stephen Harris
    #5379

    Thanks for the hook, Stephen!

    The $_GET superglobal is still defined by the time the filter runs, so I was actually able to pass the information through the URL’s query string. Works pretty nicely for weekly events.

    But now I’m wondering about monthly events. The docs for eo_insert_event read

    schedule_meta =>
    [...]
    BYDAY=ND. N= 1|2|3|4|-1 (first, second, third, fourth, last). D is day of week SU|MO|TU|WE|TH|FR|SA. E.g. BYDAY=2TU (repeat on second tuesday)

    Is it only possible to have one monthly day in a given event? If not, it doesn’t seem to be reflected in the Add New Event interface. But then, the Show Dates calendar allows days to be toggled on and off–not sure what effect that has.

    The way my plugin works for monthly events is that if the “monthly?” checkbox is toggled on, a week-of-month series of checkboxes opens (1st, 2nd, 3rd, 4th, 5th*, last), but the day of the week checkboxes stay put. That way a user could have an event for the 2nd & 3rd Tuesdays, and the 2nd & 3rd Thursdays of each month.

    *Yes, a Toastmasters group I was part of scheduled a special event on the 5th week of the month, whenever it occurred, because it messed up the rhythm of the biweekly schedule.

    John
    #5380

    Oops! I spoke too fast. The correct parameters were showing in the event meta-box, but hitting “Publish” gives this error

    Event dates were not saved.
    Start date not provided.

    And it resets the meta-box data to the defaults for new events.

    (I’m sorry: start date WAS provided.)

    John
    #5518

    My code works. Here it is:

    add_filter('eventorganiser_get_event_schedule', 'parev_meta_xfer', 10, 2);

    function parev_meta_xfer($event_details, $post_id) {

    if ( !isset($_GET) || count($_GET) === 1 ) return $event_details;

    if ( isset($_GET['schedule']) ) {
    $a = strtolower( $_GET['schedule'] );
    if ($a === 'monthly' || $a === 'weekly' )
    $event_details['schedule'] = $a;
    else $event_details['schedule'] = 'weekly';
    }

    if ( isset($_GET['start']) ) {
    $hm = explode(":", $_GET['start'] );
    date_time_set($event_details['start'], $hm[0], $hm[1]);

    if ( isset($_GET['end']) ) {
      $hm = explode(":", $_GET['end'] );
      date_time_set($event_details['end'], $hm[0], $hm[1]);
    }
    else { // if end not given, add an hour to start
      $end = $event_details['start'];
      date_add( $end, DateInterval::createFromDateString('1 hour') );
      $event_details['end'] = $end;
    }
    

    }

    // set up the events for over the next three months
    date_add( $event_details['schedule_last'], DateInterval::createFromDateString('3 months') );

    if ( isset($_GET['dow']) ) {
    $dow_array = convert2eoDays( explode(',',$_GET['dow']) );
    $event_details['schedule_meta'] = $dow_array;
    }

    return $event_details;
    }

    (Ancillary function convert2eoDays() just converts my abbrevs for days of week (viz., Su, M, T, W, Th, F, Sa) to yours (viz., SU,MO,TU,WE,TH,FR,SA).)

    Example URL with query string:

    http://example.com/wp-admin/post-new.php?post_type=event&post_title=Bible%20Study&content=We%20meet%20in%20the%20conference%20room.&excerpt=We%20meet%20in%20the%20conference%20room.&post_cat=meeting&schedule=weekly&dow=M&start=18:30&end=20:00

    for

    Bible Study (Meeting)
    M, 6:30 pm to 8:00 pm
    We meet in the conference room.

    The problem I was having is that if, after transferring the data to wp-admin/post-new.php?post_type=event, where it is properly populated, one then immediately hits Publish, WP apparently thinks the event has no start date and gives the errors I recorded above. BUT things work fine once one checks the box for “This is a reoccurring event. Check to edit this event and its reoccurrences.” (Perhaps the word you’re looking for at the end is “recurrences.”)

    For some reason that checkbox isn’t checked by default, as would seem to be the intention in your code. On line 79 of event-organiser/event-organiser-edit.php, you have

    .' <input type="checkbox" id="HWSEvent_rec" name="eo_input[AlterRe]" value="yes">';

    when I think instead of value="yes" you probably want checked. Fwiw I forget this “checked” all the time myself and actually had to look it up just now. 🙂

    So anyway, if you make that teensy correction to the plugin, there’ll be no hitch in passing the event specs through the URL’s query string.

    Well, except for the categories, which I’m still working on…

    P.S. The math CAPTCHA at the end doesn’t work right all of the time.

    John
Viewing 8 posts - 1 through 8 (of 8 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.