2018-09-20 23:56:35 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2018-09-21 23:44:04 +00:00
|
|
|
* Handles storage and retrieval of admin notes
|
2018-09-20 23:56:35 +00:00
|
|
|
*
|
2018-09-26 23:35:01 +00:00
|
|
|
* @package WooCommerce Admin/Classes
|
2018-09-20 23:56:35 +00:00
|
|
|
*/
|
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Admin Notes class.
|
|
|
|
*/
|
|
|
|
class WC_Admin_Notes {
|
|
|
|
/**
|
|
|
|
* Get notes from the database.
|
|
|
|
*
|
|
|
|
* @param string $context Getting notes for what context. Valid values: view, edit.
|
|
|
|
* @return array Array of arrays.
|
|
|
|
*/
|
|
|
|
public static function get_notes( $context = 'admin' ) {
|
2018-09-24 19:19:57 +00:00
|
|
|
$data_store = WC_Data_Store::load( 'admin-note' );
|
2018-09-21 23:44:04 +00:00
|
|
|
$raw_notes = $data_store->get_notes();
|
|
|
|
$notes = array();
|
|
|
|
foreach ( (array) $raw_notes as $raw_note ) {
|
|
|
|
$note = new WC_Admin_Note( $raw_note );
|
|
|
|
$note_id = $note->get_id();
|
|
|
|
$notes[ $note_id ] = $note->get_data();
|
|
|
|
$notes[ $note_id ]['name'] = $note->get_name( $context );
|
|
|
|
$notes[ $note_id ]['type'] = $note->get_type( $context );
|
|
|
|
$notes[ $note_id ]['locale'] = $note->get_locale( $context );
|
|
|
|
$notes[ $note_id ]['title'] = $note->get_title( $context );
|
|
|
|
$notes[ $note_id ]['content'] = $note->get_content( $context );
|
|
|
|
$notes[ $note_id ]['icon'] = $note->get_icon( $context );
|
|
|
|
$notes[ $note_id ]['content_data'] = $note->get_content_data( $context );
|
|
|
|
$notes[ $note_id ]['status'] = $note->get_status( $context );
|
|
|
|
$notes[ $note_id ]['source'] = $note->get_source( $context );
|
|
|
|
$notes[ $note_id ]['date_created'] = $note->get_date_created( $context );
|
|
|
|
$notes[ $note_id ]['date_reminder'] = $note->get_date_reminder( $context );
|
|
|
|
$notes[ $note_id ]['actions'] = $note->get_actions( $context );
|
2018-09-20 23:56:35 +00:00
|
|
|
}
|
2018-09-21 23:44:04 +00:00
|
|
|
return $notes;
|
2018-09-20 23:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-21 23:44:04 +00:00
|
|
|
* Get admin note using it's ID
|
2018-09-20 23:56:35 +00:00
|
|
|
*
|
2018-09-21 23:44:04 +00:00
|
|
|
* @param int $note_id Note ID.
|
|
|
|
* @return WC_Admin_Note|bool
|
2018-09-20 23:56:35 +00:00
|
|
|
*/
|
2018-09-21 23:44:04 +00:00
|
|
|
public static function get_note( $note_id ) {
|
|
|
|
if ( false !== $note_id ) {
|
|
|
|
try {
|
|
|
|
return new WC_Admin_Note( $note_id );
|
|
|
|
} catch ( Exception $e ) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-20 23:56:35 +00:00
|
|
|
}
|
2018-09-21 23:44:04 +00:00
|
|
|
return false;
|
2018-09-20 23:56:35 +00:00
|
|
|
}
|
|
|
|
}
|