1, 'type__in' => array('broadcast_email', 'broadcast_notice'), ); $query['meta_query'] = array( array( 'key' => $column, 'value' => $value, ), ); $results = \WP_Ultimo\Models\Broadcast::query($query); return ! empty($results) ? array_pop($results) : false; } /** * Gets a broadcast on the ID. * * @since 2.0.0 * * @param integer $broadcast_id ID of the broadcast to retrieve. * @return \WP_Ultimo\Models\Broadcast|false */ function wu_get_broadcast($broadcast_id) { return \WP_Ultimo\Models\Broadcast::get_by_id($broadcast_id); } /** * Gets a broadcast on the ID. * * @since 2.0.0 * * @param integer $broadcast_id ID of the broadcast to retrieve. * @param string $type Target type (customers or products). * @return array All targets, based on the type, from a specific broadcast. */ function wu_get_broadcast_targets($broadcast_id, $type) { $object = \WP_Ultimo\Models\Broadcast::get_by_id($broadcast_id); $targets = $object->get_message_targets(); if (is_array($targets[ $type ])) { return $targets[ $type ]; } elseif (is_string($targets[ $type ])) { return explode(',', $targets[ $type ]); } return array(); } /** * Creates a new broadcast. * * Check the wp_parse_args below to see what parameters are necessary. * * @since 2.0.0 * * @param array $broadcast_data Broadcast attributes. * @return \WP_Error|\WP_Ultimo\Models\Broadcast */ function wu_create_broadcast($broadcast_data) { $broadcast_data = wp_parse_args( $broadcast_data, array( 'type' => 'broadcast_notice', 'notice_type' => 'success', 'date_created' => wu_get_current_time('mysql', true), 'date_modified' => wu_get_current_time('mysql', true), 'migrated_from_id' => 0, 'skip_validation' => false, 'message_targets' => array( 'customers' => array(), 'products' => array(), ), ) ); $broadcast = new Broadcast($broadcast_data); $saved = $broadcast->save(); return is_wp_error($saved) ? $saved : $broadcast; }