Support » Plugin: Events Manager » Add event using EM_Event->save() has pending status

  • Resolved daymobrew


    I am using a cron job to run a php script to add events. My script resulted in events with Pending status.

    I have stripped back the script to add a single, hard coded event. This stil results in a Pending status. The event user is also ‘anon_submitter’ instead of the admin (I set author to ID 1).

    I am open to suggestions on how to sort this so that the events are Published. (Yes, I do not want to review them as they are added by my code and not an anonymous visitor).

    My code:

    $location_id = 75;
    $author_id = 1; # admin user.
    $event_start_date = '2017-01-31';
    $minute = date('i');  // Change the minute.
    $event_time = '20:'.$minute.':15';
    $event_end_date = $event_start_date;
    $event_start_time = $event_time;
    $event_end_time = $event_start_time;
    $EM_Event = new EM_Event();
    $EM_Event->event_name = 'EM Test';
                            //$EM_Event->event_slug = $slug;
    $EM_Event->post_content = '<p>This is the description of EM Test event.</p>';
    $EM_Event->event_owner = $author_id;
    $EM_Event->location_id = $location_id;
    $EM_Event->event_start_date = $event_start_date;
    $EM_Event->event_end_date = $event_end_date;
    $EM_Event->event_start_time = $event_start_time;
    $EM_Event->event_end_time = $event_end_time;
    $EM_Event->start = strtotime($EM_Event->event_start_date.' '.$EM_Event->event_start_time);
    $EM_Event->end = strtotime($EM_Event->event_end_date.' '.$EM_Event->event_end_time);
    // Disable saving during development.
    echo '<p>Event post ID: ', $EM_Event->post_id, '</p>';
    echo '<p>Event event ID: ', $EM_Event->event_id, '</p>';
Viewing 5 replies - 1 through 5 (of 5 total)
  • The events are added and the post_id and event_id increment as expected.

    My code is run as a standalone script (using: define(‘WP_USE_THEMES’, false);).
    So, as the user is not logged in, I think that the is_user_logged_in() check in the save() function is setting the event owner to the ‘dbem_events_anonymous_user’ setting. That user cannot publish events (for obvious reasons).

    Could I change the user after it is saved and publish it via my code?

    Plugin Support caimin_nwl


    NetWebLogic Support

    Do you have “Allow anonymous event submissions?” set to No under Events > Settings > General > Event Submission Forms? Setting that to Yes is probably the easiest solution.


    See screenshot of settings and resulting pending events with the specified user.

    Events Manager – Event Submission Settings

    Maybe I could add a filter for the ’em_event_save’ filter and change the owner and post status at that point.
    Or simply use wp_update_post() when save() returns.

    I added the following code after the $EM_Event->save() call:

    $args = array(
        'ID' => $EM_Event->post_id,
        'post_author' => $author_id,
        'post_status' => 'publish',
    wp_update_post( $args );

    It seems to have worked. I will investigate further tomorrow.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add event using EM_Event->save() has pending status’ is closed to new replies.