Remove interface for this PR (actions will be hooked up later);
persist actions given during creation through to the db
This commit is contained in:
parent
9f7ffa08a9
commit
677c205ad2
|
@ -37,7 +37,6 @@ class WC_Admin_Api_Init {
|
|||
public function init_classes() {
|
||||
// Interfaces.
|
||||
require_once dirname( __FILE__ ) . '/interfaces/class-wc-admin-reports-data-store-interface.php';
|
||||
require_once dirname( __FILE__ ) . '/interfaces/class-wc-admin-notes-data-store-interface.php';
|
||||
require_once dirname( __FILE__ ) . '/class-wc-admin-reports-query.php';
|
||||
|
||||
// Common date time code.
|
||||
|
|
|
@ -328,6 +328,14 @@ class WC_Admin_Note extends WC_Data {
|
|||
* @param string $content Note content.
|
||||
*/
|
||||
public function set_content( $content ) {
|
||||
$allowed_html = array(
|
||||
'br' => array(),
|
||||
'em' => array(),
|
||||
'strong' => array(),
|
||||
);
|
||||
|
||||
$content = wp_kses( $content, $allowed_html );
|
||||
|
||||
if ( empty( $content ) ) {
|
||||
$this->error( 'admin_note_invalid_data', __( 'The admin note content prop cannot be empty.', 'woocommerce' ) );
|
||||
}
|
||||
|
@ -426,32 +434,30 @@ class WC_Admin_Note extends WC_Data {
|
|||
* Add an action to the note
|
||||
*/
|
||||
public function add_action( $name, $label, $query ) {
|
||||
if ( 0 !== $this->get_id() ) {
|
||||
$name = wc_clean( $name );
|
||||
$label = wc_clean( $label );
|
||||
$query = wc_clean( $query );
|
||||
$name = wc_clean( $name );
|
||||
$label = wc_clean( $label );
|
||||
$query = wc_clean( $query );
|
||||
|
||||
if ( empty( $name ) ) {
|
||||
$this->error( 'admin_note_invalid_data', __( 'The admin note action name prop cannot be empty.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
if ( empty( $label ) ) {
|
||||
$this->error( 'admin_note_invalid_data', __( 'The admin note action label prop cannot be empty.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
if ( empty( $query ) ) {
|
||||
$this->error( 'admin_note_invalid_data', __( 'The admin note action query prop cannot be empty.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
$action = array(
|
||||
'name' => $name,
|
||||
'label' => $label,
|
||||
'query' => $query,
|
||||
);
|
||||
|
||||
$note_actions = $this->get_prop( 'actions', 'edit' );
|
||||
$note_actions[] = (object) $action;
|
||||
$this->set_prop( 'actions', $note_actions );
|
||||
if ( empty( $name ) ) {
|
||||
$this->error( 'admin_note_invalid_data', __( 'The admin note action name prop cannot be empty.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
if ( empty( $label ) ) {
|
||||
$this->error( 'admin_note_invalid_data', __( 'The admin note action label prop cannot be empty.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
if ( empty( $query ) ) {
|
||||
$this->error( 'admin_note_invalid_data', __( 'The admin note action query prop cannot be empty.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
$action = array(
|
||||
'name' => $name,
|
||||
'label' => $label,
|
||||
'query' => $query,
|
||||
);
|
||||
|
||||
$note_actions = $this->get_prop( 'actions', 'edit' );
|
||||
$note_actions[] = (object) $action;
|
||||
$this->set_prop( 'actions', $note_actions );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ defined( 'ABSPATH' ) || exit;
|
|||
/**
|
||||
* WC Admin Note Data Store (Custom Tables)
|
||||
*/
|
||||
class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Admin_Notes_Data_Store_Interface, WC_Object_Data_Store_Interface {
|
||||
class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Data_Store_Interface {
|
||||
/**
|
||||
* Method to create a new note in the database.
|
||||
*
|
||||
|
@ -42,7 +42,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Admin_Not
|
|||
$note_id = $wpdb->insert_id;
|
||||
$note->set_id( $note_id );
|
||||
$note->save_meta_data();
|
||||
// TODO $note->save_actions( $note );
|
||||
$this->save_actions( $note );
|
||||
$note->apply_changes();
|
||||
|
||||
do_action( 'woocommerce_new_note', $note_id );
|
||||
|
@ -122,7 +122,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Admin_Not
|
|||
}
|
||||
|
||||
$note->save_meta_data();
|
||||
// TODO $note->save_actions( $note );
|
||||
$this->save_actions( $note );
|
||||
$note->apply_changes();
|
||||
do_action( 'woocommerce_update_note', $note->get_id() );
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Admin_Not
|
|||
*/
|
||||
private function save_actions( &$note ) {
|
||||
$changed_props = array_keys( $note->get_changes() );
|
||||
if ( ! in_array( 'note_actions', $changed_props, true ) ) {
|
||||
if ( ! in_array( 'actions', $changed_props, true ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -194,26 +194,6 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Admin_Not
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a note as actioned
|
||||
*
|
||||
* @param WC_Admin_Note $note Note object.
|
||||
*/
|
||||
public function mark_note_as_actioned( &$note ) {
|
||||
$note->set_status( E_WC_ADMIN_NOTE_ACTIONED );
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a note for reminder
|
||||
*
|
||||
* @param WC_Admin_Note $note Note object.
|
||||
* @param int $days Number of days until reminder
|
||||
*/
|
||||
public function mark_note_for_reminder( &$note, $days = 3 ) {
|
||||
$when = current_time( 'timestamp', 1 ) + intval( $days ) * DAY_IN_SECONDS;
|
||||
$note->set_date_reminder( $when );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an ordered list of notes.
|
||||
*
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Admin (Dashboard) Notes Data Store Interface
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @package WooCommerce Admin/Interface
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce Admin (Dashboard) Notes data store interface.
|
||||
*
|
||||
* @since 3.5.0
|
||||
*/
|
||||
interface WC_Admin_Notes_Data_Store_Interface {
|
||||
|
||||
/**
|
||||
* Mark a note as actioned
|
||||
*
|
||||
* @param WC_Admin_Note $note Note object.
|
||||
*/
|
||||
public function mark_note_as_actioned( &$note );
|
||||
|
||||
/**
|
||||
* Mark a note for reminder
|
||||
*
|
||||
* @param WC_Admin_Note $note Note object.
|
||||
* @param int $days Number of days until reminder
|
||||
*/
|
||||
public function mark_note_for_reminder( &$note, $days = 3 );
|
||||
}
|
Loading…
Reference in New Issue