WordPress API
Since version 4.8.4.
ShiftController provides a number of WordPress filters to query and update its shifts database.
Get Shifts
shiftcontroller4/api/shifts/get (array $params) : array | WP_Error
Parameters
calendar_id (Calendar Id)
employee_id (Employee Id)
from (From Date, YYYYMMDD / From Date Time, YYYYMMDDHHMM)
to (To Date, YYYYMMDD / To Date Time, YYYYMMDDHHMM)
status_id (publish, draft)
Optional Arguments since version 4.9.22.
You have custom fields, you can also pass in their names and values to filter the results.
Examples
$res = apply_filters( 'shiftcontroller4/api/shifts/get', array() ); if( is_wp_error($res) ) exit( $res->get_error_message() ); $shifts = $res;
$params = array(); $params['calendar_id'] = 11; $params['from'] = 20210224; $res = apply_filters( 'shiftcontroller4/api/shifts/get', $params ); if( is_wp_error($res) ) exit( $res->get_error_message() ); $shifts = $res;
$params = array(); $params['calendar_id'] = 11; $params['from'] = '202102240900'; $params['to'] = '202102241430'; $params['status_id'] = 'draft'; $res = apply_filters( 'shiftcontroller4/api/shifts/get', $params ); if( is_wp_error($res) ) exit( $res->get_error_message() ); $shifts = $res;
Since version 4.9.22.
$params = array(); $params['calendar_id'] = 11; $params['misc123'] = 'CustomFieldValue'; $res = apply_filters( 'shiftcontroller4/api/shifts/get', $params ); if( is_wp_error($res) ) exit( $res->get_error_message() ); $shifts = $res;
Get Shift
shiftcontroller4/api/shifts/getbyid ( $id ) : array | WP_Error
Examples
$res = apply_filters( 'shiftcontroller4/api/shifts/getbyid', 123 ); if( is_wp_error($res) ) exit( $res->get_error_message() ); $shift = $res;
Delete Shift
shiftcontroller4/api/shifts/deletebyid ( $id ) : null | WP_Error
Examples
$res = apply_filters( 'shiftcontroller4/api/shifts/deletebyid', 123 ); if( is_wp_error($res) ) exit( $res->get_error_message() );
Create Shift
shiftcontroller4/api/shifts/create ( array $values ) : int | WP_Error
Parameters
calendar_id (Calendar Id)
employee_id (Employee Id)
start (Start Date Time, YYYYMMDDHHMM)
end (End Date Time, YYYYMMDDHHMM)
status_id (publish, draft)
conflict (Set to 1 to allow creation of shifts with conflicts) optional
If you have custom fields in this calendar, then you can add them too as miscXXX where XXX is the field id (see Administration > Calendars > Custom Fields):
misc11
misc12
Returns the new shift id on success.
Examples
$values = array(); $values['calendar_id'] = 11; $values['employee_id'] = 22; $values['start'] = '202102240800'; $values['end'] = '202102241430'; $values['status_id'] = 'publish'; // if you have custom fields $values['misc11'] = 'orange'; $values['misc12'] = 321; $res = apply_filters( 'shiftcontroller4/api/shifts/create', $values ); if( is_wp_error($res) ) exit( $res->get_error_message() ); $newId = $res;
Update Shift
shiftcontroller4/api/shifts/updatebyid ( int $id, array $values ) : null | WP_Error
Parameters
calendar_id (Calendar Id) optional
employee_id (Employee Id) optional
start (Start Date Time, YYYYMMDDHHMM) optional
end (End Date Time, YYYYMMDDHHMM) optional
status_id (publish, draft) optional
conflict (Set to 1 to allow creation of shifts with conflicts) optional
If you have custom fields in this calendar, then you can add them too as miscXXX where XXX is the field id (see Administration > Calendars > Custom Fields):
misc11
misc12
Examples
$values = array(); $values['start'] = '202102240900'; $values['end'] = '202102241530'; $res = apply_filters( 'shiftcontroller4/api/shifts/updatebyid', 123, $values ); if( is_wp_error($res) ) exit( $res->get_error_message() );
$values = array(); $values['employee_id'] = 23; // if you have custom fields $values['misc11'] = 'green'; $res = apply_filters( 'shiftcontroller4/api/shifts/updatebyid', 123, $values ); if( is_wp_error($res) ) exit( $res->get_error_message() );
$values = array(); $values['status_id'] = 'publish'; $res = apply_filters( 'shiftcontroller4/api/shifts/updatebyid', 123, $values ); if( is_wp_error($res) ) exit( $res->get_error_message() );
Listen To ShiftController Events
Shift Draft Created
Shift Published
Shift Unpublished
Shift Employee Changed
Shift Calendar Changed
Shift Rescheduled
shiftcontroller4/sh4/shifts/command::draft::after ( int $id, array $args )
shiftcontroller4/sh4/shifts/command::publish::after ( int $id, array $args )
shiftcontroller4/sh4/shifts/command::unpublish::after ( int $id, array $args )
shiftcontroller4/sh4/shifts/command::changeemployee::after ( int $id, array $args )
shiftcontroller4/sh4/shifts/command::changecalendar::after ( int $id, array $args )
shiftcontroller4/sh4/shifts/command::reschedule::after ( int $id, array $args )
Parameters
- id (Shift Id)
-
args array of arguments passed to the original function:
- SH4_Shifts_Model $shift
add_action( 'shiftcontroller4/sh4/shifts/command::publish::after', function( $id, $args ){ $shift = $args[0]; $startAt = $shift->getStart(); $endAt = $shift->getEnd(); $calendar = $shift->getCalendar(); $calendarId = $calendar->getId(); $employee = $shift->getEmployee(); $employeeId = $employee->getId(); $f = ShiftController4::$instance->root(); $appQuery = $f->make( 'SH4_App_Query' ); $user = $appQuery->findUserByEmployee( $employee ); if( $user ){ $wpUserId = $user->getId(); // get what you need for the wordpress user } else { // no user linked to ShiftController employee } }, 10, 3 );