Tribe__Events__Aggregator__Record__Abstract::prep_post_args( string $type, object $args, array $meta = array() )
Preps post arguments for create/save.
Contents
Parameters
- $type
-
(string) (Required) Type of record to create - manual or schedule.
- $args
-
(object) (Required) Post type args.
- $meta
-
(array) (Optional) Post meta.
Default value: array()
Return
(array)
Source
File: src/Tribe/Aggregator/Record/Abstract.php
public function prep_post_args( $type, $args, $meta = array() ) {
$post = array(
'post_title' => $this->generate_title( $type, $this->origin, $meta['frequency'], $args->parent ),
'post_type' => Tribe__Events__Aggregator__Records::$post_type,
'ping_status' => $type,
// The Mime Type needs to be on a %/% format to work on WordPress
'post_mime_type' => 'ea/' . $this->origin,
'post_date' => current_time( 'mysql' ),
'post_status' => Tribe__Events__Aggregator__Records::$status->draft,
'post_parent' => $args->parent,
'meta_input' => array(),
);
// prefix all keys
foreach ( $meta as $key => $value ) {
// skip arrays that are empty
if ( is_array( $value ) && empty( $value ) ) {
continue;
}
// trim scalars
if ( is_scalar( $value ) ) {
$value = trim( $value );
}
// if the value is null, let's avoid inserting it
if ( null === $value ) {
continue;
}
$post['meta_input'][ self::$meta_key_prefix . $key ] = $value;
}
$meta = (object) $meta;
if ( 'schedule' === $type ) {
$frequency = Tribe__Events__Aggregator__Cron::instance()->get_frequency( array( 'id' => $meta->frequency ) );
if ( ! $frequency ) {
return tribe_error( 'core:aggregator:invalid-record-frequency', $meta );
}
// Setup the post_content as the Frequency (makes it easy to fetch by frequency)
$post['post_content'] = $frequency->id;
}
return $post;
}