Files
apache
wp-content
mu-plugins
plugins
activitypub
audioigniter
authldap
companion-auto-update
easy-digital-downloads
assets
includes
adjustments
admin
api
blocks
cart
checkout
compat
currency
customers
database
downloads
emails
extensions
gateways
libraries
logs
models
notes
class-note.php
functions.php
meta.php
orders
payments
reports
traits
users
utils
EDD_SL_Plugin_Updater.php
actions.php
ajax-functions.php
class-base-object.php
class-component.php
class-easy-digital-downloads.php
class-edd-cache-helper.php
class-edd-cli.php
class-edd-cron.php
class-edd-customer-query.php
class-edd-customer.php
class-edd-db-customer-meta.php
class-edd-db-customers.php
class-edd-db.php
class-edd-discount.php
class-edd-download.php
class-edd-fees.php
class-edd-html-elements.php
class-edd-license-handler.php
class-edd-logging.php
class-edd-register-meta.php
class-edd-requirements-check.php
class-edd-roles.php
class-edd-session.php
class-edd-stats.php
class-stats.php
class-structured-data.php
class-utilities.php
compat-functions.php
component-functions.php
country-functions.php
customer-functions.php
date-functions.php
deprecated-functions.php
deprecated-hooks.php
discount-functions.php
download-functions.php
error-tracking.php
formatting.php
install.php
interface-edd-exception.php
mime-types.php
misc-functions.php
plugin-compatibility.php
post-types.php
privacy-functions.php
process-download.php
process-purchase.php
query-filters.php
refund-functions.php
scripts.php
shortcodes.php
tax-functions.php
template-actions.php
template-functions.php
theme-compatibility.php
user-functions.php
widgets.php
languages
src
templates
vendor
easy-digital-downloads.php
license.txt
readme.txt
uninstall.php
gitium
gp-premium
jetpack-protect
menu-icons
simple-local-avatars
smtp-mailer
two-factor
w3-total-cache
wp-piwik
wp-webauthn
index.php
themes
w3tc-config
index.php
.dbsetup
.gitignore
htaccess
php.ini
laipower/wp-content/plugins/easy-digital-downloads/includes/notes/functions.php

189 lines
5.7 KiB
PHP

<?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 );
}