installed plugin Easy Digital Downloads
version 3.1.0.3
This commit is contained in:
@ -0,0 +1,223 @@
|
||||
<?php
|
||||
/**
|
||||
* Note Object
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Classes/Notes
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 3.0
|
||||
*/
|
||||
namespace EDD\Notes;
|
||||
|
||||
use EDD\Base_Object;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Note Class.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $object_id
|
||||
* @property string $object_type
|
||||
* @property int $user_id
|
||||
* @property string $content
|
||||
* @property string $date_created
|
||||
* @property string $date_modified
|
||||
*/
|
||||
class Note extends Base_Object {
|
||||
|
||||
/**
|
||||
* Note ID.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Object ID.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $object_id;
|
||||
|
||||
/**
|
||||
* Object Type.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $object_type;
|
||||
|
||||
/**
|
||||
* Note content.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $content;
|
||||
|
||||
/**
|
||||
* User ID.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $user_id;
|
||||
|
||||
/**
|
||||
* Date created.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $date_created;
|
||||
|
||||
/**
|
||||
* Comment ID.
|
||||
*
|
||||
* @since 3.0
|
||||
* @var int
|
||||
*/
|
||||
protected $comment_ID;
|
||||
|
||||
/**
|
||||
* ID of the post the comment is associated with.
|
||||
*
|
||||
* @since 3.0
|
||||
* @var int
|
||||
*/
|
||||
protected $comment_post_ID = 0;
|
||||
|
||||
/**
|
||||
* Comment author name.
|
||||
*
|
||||
* @since 3.0
|
||||
* @var string
|
||||
*/
|
||||
protected $comment_author = '';
|
||||
|
||||
/**
|
||||
* Comment author email address.
|
||||
*
|
||||
* @since 3.0
|
||||
* @var string
|
||||
*/
|
||||
protected $comment_author_email = '';
|
||||
|
||||
/**
|
||||
* Comment author URL.
|
||||
*
|
||||
* @since 3.0
|
||||
* @var string
|
||||
*/
|
||||
protected $comment_author_url = '';
|
||||
|
||||
/**
|
||||
* Comment author IP address (IPv4 format).
|
||||
*
|
||||
* @since 3.0
|
||||
* @var string
|
||||
*/
|
||||
protected $comment_author_IP = '';
|
||||
|
||||
/**
|
||||
* Comment date in YYYY-MM-DD HH:MM:SS format.
|
||||
*
|
||||
* @since 3.0
|
||||
* @var string
|
||||
*/
|
||||
protected $comment_date = '0000-00-00 00:00:00';
|
||||
|
||||
/**
|
||||
* Comment GMT date in YYYY-MM-DD HH::MM:SS format.
|
||||
*
|
||||
* @since 3.0
|
||||
* @var string
|
||||
*/
|
||||
protected $comment_date_gmt = '0000-00-00 00:00:00';
|
||||
|
||||
/**
|
||||
* Comment content.
|
||||
*
|
||||
* @since 3.0
|
||||
* @var string
|
||||
*/
|
||||
public $comment_content;
|
||||
|
||||
/**
|
||||
* Comment karma count.
|
||||
*
|
||||
* @since 3.0
|
||||
* @var int
|
||||
*/
|
||||
public $comment_karma = 0;
|
||||
|
||||
/**
|
||||
* Comment approval status.
|
||||
*
|
||||
* @since 3.0
|
||||
* @var string
|
||||
*/
|
||||
public $comment_approved = '1';
|
||||
|
||||
/**
|
||||
* Comment author HTTP user agent.
|
||||
*
|
||||
* @since 3.0
|
||||
* @var string
|
||||
*/
|
||||
public $comment_agent = '';
|
||||
|
||||
/**
|
||||
* Comment type.
|
||||
*
|
||||
* @since 3.0
|
||||
* @var string
|
||||
*/
|
||||
public $comment_type = '';
|
||||
|
||||
/**
|
||||
* Parent comment ID.
|
||||
*
|
||||
* @since 3.0
|
||||
* @var int
|
||||
*/
|
||||
public $comment_parent = 0;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
*
|
||||
* @param \object $note Note data from the database.
|
||||
*/
|
||||
public function __construct( $note = null ) {
|
||||
parent::__construct( $note );
|
||||
|
||||
if ( is_object( $note ) ) {
|
||||
/**
|
||||
* We fill object vars which have the same name as the object vars in WP_Comment for backwards compatibility
|
||||
* purposes.
|
||||
*/
|
||||
$this->comment_ID = absint( $this->id );
|
||||
$this->comment_post_ID = $this->object_id;
|
||||
$this->comment_type = $this->object_type;
|
||||
$this->comment_date = $this->date_created;
|
||||
$this->comment_date_gmt = $this->date_created;
|
||||
$this->comment_content = $this->content;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,188 @@
|
||||
<?php
|
||||
/**
|
||||
* Note Functions.
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Notes
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Add a note.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $data {
|
||||
* Array of note data. Default empty.
|
||||
*
|
||||
* The `date_created` and `date_modified` parameters do not need to be passed.
|
||||
* They will be automatically populated if empty.
|
||||
*
|
||||
* @type int $object_id Object ID that the note refers to. This would
|
||||
* be an ID that corresponds to the object type
|
||||
* specified. E.g. an object ID of 25 with object
|
||||
* type of `order` refers to order 25 in the
|
||||
* `edd_orders` table. Default empty.
|
||||
* @type string $object_type Object type that the note refers to.
|
||||
* E.g. `discount` or `order`. Default empty.
|
||||
* @type int $user_id ID of the current WordPress user logged in.
|
||||
* Default 0.
|
||||
* @type string $content Note content. Default empty.
|
||||
* @type string $date_created Optional. Automatically calculated on add/edit.
|
||||
* The date & time the note was inserted.
|
||||
* Format: YYYY-MM-DD HH:MM:SS. Default empty.
|
||||
* @type string $date_modified Optional. Automatically calculated on add/edit.
|
||||
* The date & time the note was last modified.
|
||||
* Format: YYYY-MM-DD HH:MM:SS. Default empty.
|
||||
* }
|
||||
* @return int|false ID of newly created note, false on error.
|
||||
*/
|
||||
function edd_add_note( $data = array() ) {
|
||||
|
||||
// An object ID and object type must be supplied for every note that is
|
||||
// inserted into the database.
|
||||
if ( empty( $data['object_id'] ) || empty( $data['object_type'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Instantiate a query object
|
||||
$notes = new EDD\Database\Queries\Note();
|
||||
|
||||
return $notes->add_item( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a note.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $note_id Note ID.
|
||||
* @return int|false `1` if the note was deleted successfully, false on error.
|
||||
*/
|
||||
function edd_delete_note( $note_id = 0 ) {
|
||||
$notes = new EDD\Database\Queries\Note();
|
||||
|
||||
return $notes->delete_item( $note_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a note.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $note_id Note ID.
|
||||
* @param array $data {
|
||||
* Array of note data. Default empty.
|
||||
*
|
||||
* @type int $object_id Object ID that the note refers to. This would
|
||||
* be an ID that corresponds to the object type
|
||||
* specified. E.g. an object ID of 25 with object
|
||||
* type of `order` refers to order 25 in the
|
||||
* `edd_orders` table. Default empty.
|
||||
* @type string $object_type Object type that the note refers to.
|
||||
* E.g. `discount` or `order`. Default empty.
|
||||
* @type int $user_id ID of the current WordPress user logged in.
|
||||
* Default 0.
|
||||
* @type string $content Note content. Default empty.
|
||||
* @type string $date_created Optional. Automatically calculated on add/edit.
|
||||
* The date & time the note was inserted.
|
||||
* Format: YYYY-MM-DD HH:MM:SS. Default empty.
|
||||
* @type string $date_modified Optional. Automatically calculated on add/edit.
|
||||
* The date & time the note was last modified.
|
||||
* Format: YYYY-MM-DD HH:MM:SS. Default empty.
|
||||
* }
|
||||
*
|
||||
* @return int|false Number of rows updated if successful, false otherwise.
|
||||
*/
|
||||
function edd_update_note( $note_id = 0, $data = array() ) {
|
||||
$notes = new EDD\Database\Queries\Note();
|
||||
|
||||
return $notes->update_item( $note_id, $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a note by ID.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $note_id Note ID.
|
||||
* @return EDD\Notes\Note Note object if successful, false otherwise.
|
||||
*/
|
||||
function edd_get_note( $note_id = 0 ) {
|
||||
$notes = new EDD\Database\Queries\Note();
|
||||
|
||||
// Return note
|
||||
return $notes->get_item( $note_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a note by a specific field value.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param string $field Database table field.
|
||||
* @param string $value Value of the row.
|
||||
*
|
||||
* @return EDD\Notes\Note Note object if successful, false otherwise.
|
||||
*/
|
||||
function edd_get_note_by( $field = '', $value = '' ) {
|
||||
$notes = new EDD\Database\Queries\Note();
|
||||
|
||||
// Return note
|
||||
return $notes->get_item_by( $field, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for notes.
|
||||
*
|
||||
* @see \EDD\Database\Queries\Note::__construct()
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $args Arguments. See `EDD\Database\Queries\Note` for
|
||||
* accepted arguments.
|
||||
* @return \EDD\Notes\Note[] Array of `Note` objects.
|
||||
*/
|
||||
function edd_get_notes( $args = array() ) {
|
||||
|
||||
// Parse args
|
||||
$r = wp_parse_args( $args, array(
|
||||
'number' => 30
|
||||
) );
|
||||
|
||||
// Instantiate a query object
|
||||
$notes = new EDD\Database\Queries\Note();
|
||||
|
||||
// Return notes
|
||||
return $notes->query( $r );
|
||||
}
|
||||
|
||||
/**
|
||||
* Count notes.
|
||||
*
|
||||
* @see \EDD\Database\Queries\Note::__construct()
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $args Arguments. See `EDD\Database\Queries\Note` for
|
||||
* accepted arguments.
|
||||
* @return int Number of notes returned based on query arguments passed.
|
||||
*/
|
||||
function edd_count_notes( $args = array() ) {
|
||||
|
||||
// Parse args
|
||||
$r = wp_parse_args( $args, array(
|
||||
'count' => true
|
||||
) );
|
||||
|
||||
// Query for count(s)
|
||||
$notes = new EDD\Database\Queries\Note( $r );
|
||||
|
||||
// Return count(s)
|
||||
return absint( $notes->found_items );
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Note Meta Functions
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Notes
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Add meta data field to a note.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $note_id Note ID.
|
||||
* @param string $meta_key Meta data name.
|
||||
* @param mixed $meta_value Meta data value. Must be serializable if non-scalar.
|
||||
* @param bool $unique Optional. Whether the same key should not be added. Default false.
|
||||
*
|
||||
* @return int|false Meta ID on success, false on failure.
|
||||
*/
|
||||
function edd_add_note_meta( $note_id, $meta_key, $meta_value, $unique = false ) {
|
||||
return add_metadata( 'edd_note', $note_id, $meta_key, $meta_value, $unique );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove meta data matching criteria from a note.
|
||||
*
|
||||
* You can match based on the key, or key and value. Removing based on key and value, will keep from removing duplicate
|
||||
* meta data with the same key. It also allows removing all meta data matching key, if needed.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $note_id Note ID.
|
||||
* @param string $meta_key Meta data name.
|
||||
* @param mixed $meta_value Optional. Meta data value. Must be serializable if non-scalar. Default empty.
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
function edd_delete_note_meta( $note_id, $meta_key, $meta_value = '' ) {
|
||||
return delete_metadata( 'edd_note', $note_id, $meta_key, $meta_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve note meta field for a note.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $note_id Note ID.
|
||||
* @param string $key Optional. The meta key to retrieve. By default, returns data for all keys. Default empty.
|
||||
* @param bool $single Optional, default is false. If true, return only the first value of the specified meta_key.
|
||||
* This parameter has no effect if meta_key is not specified.
|
||||
*
|
||||
* @return mixed Will be an array if $single is false. Will be value of meta data field if $single is true.
|
||||
*/
|
||||
function edd_get_note_meta( $note_id, $key = '', $single = false ) {
|
||||
return get_metadata( 'edd_note', $note_id, $key, $single );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update note meta field based on note ID.
|
||||
*
|
||||
* Use the $prev_value parameter to differentiate between meta fields with the
|
||||
* same key and note ID.
|
||||
*
|
||||
* If the meta field for the note does not exist, it will be added.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $note_id Note ID.
|
||||
* @param string $meta_key Meta data key.
|
||||
* @param mixed $meta_value Meta data value. Must be serializable if non-scalar.
|
||||
* @param mixed $prev_value Optional. Previous value to check before removing. Default empty.
|
||||
*
|
||||
* @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
|
||||
*/
|
||||
function edd_update_note_meta( $note_id, $meta_key, $meta_value, $prev_value = '' ) {
|
||||
return update_metadata( 'edd_note', $note_id, $meta_key, $meta_value, $prev_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete everything from note meta matching meta key.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param string $meta_key Key to search for when deleting.
|
||||
*
|
||||
* @return bool Whether the note meta key was deleted from the database.
|
||||
*/
|
||||
function edd_delete_note_meta_by_key( $meta_key ) {
|
||||
return delete_metadata( 'edd_note', null, $meta_key, '', true );
|
||||
}
|
Reference in New Issue
Block a user