Automattic\WooCommerce\Admin\Notes
DataStore::read()
Method to read a note.
Method of the class: DataStore{}
Hooks from the method
Return
null
. Nothing (null).
Usage
$DataStore = new DataStore(); $DataStore->read( $note );
- $note(Note) (required) (passed by reference — &)
- Admin note.
DataStore::read() DataStore::read code WC 9.8.2
public function read( &$note ) { global $wpdb; $note->set_defaults(); $note_row = false; $note_id = $note->get_id(); if ( 0 !== $note_id || '0' !== $note_id ) { $note_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wc_admin_notes WHERE note_id = %d LIMIT 1", $note->get_id() ) ); } if ( 0 === $note->get_id() || '0' === $note->get_id() ) { $this->read_actions( $note ); $note->set_object_read( true ); /** * Fires when an admin note is loaded. * * @param int $note_id Note ID. */ do_action( 'woocommerce_note_loaded', $note ); } elseif ( $note_row ) { $note->set_name( $note_row->name ); $note->set_type( $note_row->type ); $note->set_locale( $note_row->locale ); $note->set_title( $note_row->title ); $note->set_content( $note_row->content ); // The default for 'content_value' used to be an array, so there might be rows with invalid data! $content_data = json_decode( $note_row->content_data ); if ( ! $content_data ) { $content_data = new \stdClass(); } elseif ( is_array( $content_data ) ) { $content_data = (object) $content_data; } $note->set_content_data( $content_data ); $note->set_status( $note_row->status ); $note->set_source( $note_row->source ); $note->set_date_created( $note_row->date_created ); $note->set_date_reminder( $note_row->date_reminder ); $note->set_is_snoozable( (bool) $note_row->is_snoozable ); $note->set_is_deleted( (bool) $note_row->is_deleted ); isset( $note_row->is_read ) && $note->set_is_read( (bool) $note_row->is_read ); $note->set_layout( $note_row->layout ); $note->set_image( $note_row->image ); $this->read_actions( $note ); $note->set_object_read( true ); /** * Fires when an admin note is loaded. * * @param int $note_id Note ID. */ do_action( 'woocommerce_note_loaded', $note ); } else { throw new \Exception( __( 'Invalid admin note', 'woocommerce' ) ); } }