ActionScheduler_wpPostStore::get_schedule_from_post_meta
Read a scheduled action's schedule from post meta without instantiating unexpected classes.
Using get_post_meta() would run the stored blob through maybe_unserialize(), instantiating whatever classes it names before we can vet them. Instead we read the raw serialized value and hand it to ActionScheduler_ScheduleDeserializer, which only instantiates a valid schedule (and its vetted supporting classes). @see https://github.com/woocommerce/action-scheduler/issues/1318
Метод класса: ActionScheduler_wpPostStore{}
Хуков нет.
Возвращает
mixed. The schedule object, false if unusable, or the raw meta value when it is not a serialized object (left for validate_schedule() to reject, as before).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_schedule_from_post_meta( $post_id );
- $post_id(int) (обязательный)
- Post ID of the scheduled action.
Код ActionScheduler_wpPostStore::get_schedule_from_post_meta() ActionScheduler wpPostStore::get schedule from post meta WC 11.2.1
protected function get_schedule_from_post_meta( $post_id ) {
global $wpdb;
// Direct, uncached query is intentional: we need the raw serialized value before the meta API
// runs it through maybe_unserialize(), so we bypass get_post_meta() and its cache here.
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$raw = $wpdb->get_var(
$wpdb->prepare(
"SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = %s ORDER BY meta_id ASC LIMIT 1",
$post_id,
self::SCHEDULE_META_KEY
)
);
if ( null === $raw ) {
return false;
}
// Schedule objects are stored serialized by the meta API. A non-serialized value cannot be a
// schedule object, so there is nothing to protect against — return it as-is for validation.
if ( ! is_serialized( $raw ) ) {
return $raw;
}
return ActionScheduler_ScheduleDeserializer::unserialize( $raw );
}