Support

Home Forums Event Espresso Premium bulk action hook for admin event list page?

bulk action hook for admin event list page?

Posted: November 27, 2018 at 5:30 am


lhammond

November 27, 2018 at 5:30 am

Is there a way to add options to the bulk actions drop-down in the event listing of the admin area? I have a function that will update all the waitlist settings if I pass in an array of event ids, and I’d like to be able to call it from the bulk actions drop-down. It would also be handy for bulk updates of regsitration start dates and end dates, etc.

If we can hook in to add an option to the drop-down, what is the best way to show a few fields to enter the values desired for the given update? A pop-up window? Or can the bulk update have a multi-step process of screens?


lhammond

November 27, 2018 at 5:51 am

I tried the steps in this (https://wpengineer.com/2803/create-your-own-bulk-actions/), but it only shows my new bulk action on the list of Posts, not on my Events list. I’m guessing there’s a special filter for custom post types? Or I need to change the edit-posts screen ID to whatever one is relevant for events?


Tony

  • Support Staff

November 27, 2018 at 8:38 am

Is there a way to add options to the bulk actions drop-down in the event listing of the admin area?

Yes, you can.

The bulk dropdown options are unique for each ‘view’, the views are the links along the top of the table, ‘View all events’, ‘draft’, ‘trash’ and so on.

As the options relate to each view, they are also set on each of those views and they are passed through a filter to allow you to change them:

FHEE_list_table_views_{page_slug}

For your request that’s going to be FHEE_list_table_views_espresso_events

That is passed an array of arrays, each array is the view with the options for that view, for example, the default view is ‘all’ and that looks like:

'all' => array (4)
    'slug' => string (3) "all"
    'label' => string (15) "View All Events"
    'count' => integer 0
    'bulk_action' => array (1)
        'trash_events' => string (13) "Move to Trash"

So you can add options to the ‘bulk_action’ array using the above filter, however, each of those is also a route within the admin so you’ll also nee dot register your custom route if you do it this way. As you have the EE4 Everything license I recommend taking a look at one of our add-ons for an example of how to add a page route, the EE4 Attendee mover add-on has an example (search for ‘attendee_mover_page_routes’).

The filter you would use is likely FHEE__Extend_Events_Admin_Page__page_setup__page_routes.

It would also be handy for bulk updates of regsitration start dates and end dates, etc.

How so? Note that the dates within EE events are stored on the datetimes/tickets, so your going to need to update those rather than the event itself.

‘Registration start dates’ is a term from EE3 but I’m assuming this is aimed at EE4.

If we can hook in to add an option to the drop-down, what is the best way to show a few fields to enter the values desired for the given update? A pop-up window? Or can the bulk update have a multi-step process of screens?

The bulk option basically just calls a function so you can do any of the above if you prefer, but its not something we have an examples/snippets of.


lhammond

November 27, 2018 at 2:18 pm

So you can add options to the ‘bulk_action’ array using the above filter, however, each of those is also a route within the admin so you’ll also nee dot register your custom route if you do it this way.

I looked at the attendee mover routes and I am a bit confused about it. I see the line:

   add_filter(
            'FHEE__Extend_Registrations_Admin_Page__page_setup__page_routes',
            array('EED_Attendee_Mover', 'attendee_mover_page_routes'),
            10,
            2
        );

and I understand that, ‘attendee_mover_page_routes’ is the name of the callback function, but what must the first element of that array be? In this case, it matches the name of the class, but I’m not creating a new class, just adding the hooks into a custom plugin.

So I tried adding this to my custom plugin:

add_filter('FHEE__Extend_Events_Admin_Page__page_setup__page_routes', array('Compass Mods', 'compass_ee_page_routes'), 10, 2);

     // callback for FHEE__Extend_Events_Admin_Page__page_setup__page_routes
    function compass_ee_page_routes(array $page_routes, Events_Admin_Page $admin_page)
    {
        $req_data = $admin_page->get_request_data();
        $EVT_ID = ! empty($req_data['EVT_ID']) && ! is_array($req_data['EVT_ID'])
            ? $req_data['EVT_ID']
            : 0;
        $page_routes['create_waitlist'] = array(
            'func'       => array('Compass Mods', 'my_bulk_action_handler'),
            'EVT_ID'     => $EVT_ID,
        );
        return $page_routes;
    }

But adding that code makes the following error appear on the Events Admin List page:

An EE_Error exception was thrown!   code: EE_Admin_Page - _verify_routes - 816
"No page routes have been set for the Events admin page. Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly."

I did get the Create Waitlists option to show in the bulk dropdown using

add_filter( 'bulk_actions-toplevel_page_espresso_events', 'register_compass_bulk_actions' );
 
function register_compass_bulk_actions($bulk_actions) {
  $bulk_actions['create_waitlist'] = __( 'Create Waitlist', 'create_waitlist');
  return $bulk_actions;
}

But when I tried to submit the form so it would call my bulk action handler function, I got an EE exception about the page routes, too. Help?

How so? Note that the dates within EE events are stored on the datetimes/tickets, so your going to need to update those rather than the event itself.

‘Registration start dates’ is a term from EE3 but I’m assuming this is aimed at EE4.

Yes, I am in the process of upgrading from EE3 to EE4, sorry about the confusion with wording. We only have one ticket per event, so I would like a bulk action that updates the start or end dates for all tickets for all events. Since we have 100s of classes offered each quarter, if we decide to change our registration day, it is a pain to have to manually edit each one, hence the need for a bulk action.


Josh

  • Support Staff

November 27, 2018 at 2:43 pm

and I understand that, ‘attendee_mover_page_routes’ is the name of the callback function, but what must the first element of that array be? In this case, it matches the name of the class, but I’m not creating a new class, just adding the hooks into a custom plugin.

If you’re not creating a new class, then you just pass in the function name, like this:

add_filter(
'FHEE__Extend_Events_Admin_Page__page_setup__page_routes', 'compass_ee_page_routes', 
10, 
2
);

Similarly, in your compass_ee_page_routes function, you pass in the function name (since it’s not a method either) e.g.

'func' => 'my_bulk_action_handler',


Josh

  • Support Staff

November 27, 2018 at 2:54 pm

You’ll find more examples for using add_filter() in these WordPress developer resources:

https://developer.wordpress.org/reference/functions/add_filter/
https://pippinsplugins.com/a-quick-introduction-to-using-filters/

You must be logged in to reply to this support post. Sign In or Register for an Account

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: publish

Updated by  Josh 2 weeks, 1 day ago ago

Topic Tags

Tagged: 

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!