hook = $hook;
$this->schedule = $schedule;
$this->interval = $interval;
$this->args = $args;
$this->next_call = $next_call;
$this->protected = $is_protected;
$this->paused = $paused;
// phpcs:ignore
$this->hash = substr( md5( $this->hook . $this->schedule . serialize( $this->args ) ), 0, 8 );
}
/**
* Magic method
*
* @param string $property Schedule property.
* @return mixed property value
*/
public function __get( $property ) {
return $this->$property;
}
/**
* Gets implementation code for event
*
* @return string
*/
public function get_implementation() {
$arguments = array();
foreach ( $this->args as $n => $arg ) {
$arguments[] = '$arg' . (string) $n;
}
$arguments = empty( $arguments ) ? '' : ' ' . implode( ', ', $arguments ) . ' ';
$hook_escaped = esc_html( $this->hook );
$function_name = esc_html( 'cron_' . $this->hook . '_' . $this->hash );
$arguments_escaped = esc_html( $arguments );
$imp = '';
$imp .= 'function ' . $function_name . '(' . $arguments_escaped . ') {
';
$imp .= ' // do stuff
';
$imp .= '}
';
$imp .= '
';
$args_count = is_array( $this->args ) ? count( $this->args ) : 0;
$imp .= "add_action( '" . $hook_escaped . "', '" . $function_name . "', 10, " . $args_count . ' );';
return $imp;
}
/**
* Gets the nonce hash for event action
*
* @param string $action action name.
* @return string nonce hash
*/
public function nonce( $action = '' ) {
return esc_attr( wp_create_nonce( 'acm/event/' . $action . '/' . $this->hash ) );
}
}