installed plugin Easy Digital Downloads
version 3.1.0.3
This commit is contained in:
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* Logs API - API Request Log Object.
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Logs
|
||||
* @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\Logs;
|
||||
|
||||
use EDD\Base_Object;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* API Request Log Class.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property string $api_key
|
||||
* @property string $token
|
||||
* @property string $version
|
||||
* @property string $request
|
||||
* @property string $error
|
||||
* @property string $ip
|
||||
* @property string $time
|
||||
* @property string $date_created
|
||||
* @property string $date_modified
|
||||
*/
|
||||
class Api_Request_Log extends Base_Object {
|
||||
|
||||
/**
|
||||
* API request log ID.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* User ID.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $user_id;
|
||||
|
||||
/**
|
||||
* API key.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $api_key;
|
||||
|
||||
/**
|
||||
* API token.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
* API version.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $version;
|
||||
|
||||
/**
|
||||
* API request.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Request errors.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $error;
|
||||
|
||||
/**
|
||||
* IP.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $ip;
|
||||
|
||||
/**
|
||||
* Speed of the API request.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var float
|
||||
*/
|
||||
protected $time;
|
||||
|
||||
/**
|
||||
* Date log was created.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $date_created;
|
||||
|
||||
/**
|
||||
* Date modified.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $date_modified;
|
||||
}
|
@ -0,0 +1,207 @@
|
||||
<?php
|
||||
/**
|
||||
* API Request Log Functions.
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Logs
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
use EDD\Logs\Api_Request_Log;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
|
||||
/**
|
||||
* Add an API request log.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $data {
|
||||
* Array of API request log 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 $user_id WordPress user ID of the authenticated user
|
||||
* making the API request. Default 0.
|
||||
* @type string $api_key User's API key. Default empty.
|
||||
* @type string $token User's API token. Default empty.
|
||||
* @type string $version API version used. Default empty.
|
||||
* @type string $request API request query. Default empty.
|
||||
* @type string $error Error(s), if any when making the API request.
|
||||
* Default empty.
|
||||
* @type string $ip IP address of the client making the API
|
||||
* request. Default empty.
|
||||
* @type string $time Time it took for API request to complete. Default empty.
|
||||
* @type string $date_created Optional. Automatically calculated on add/edit.
|
||||
* The date & time the API request log 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 API request log was last
|
||||
* modified. Format: YYYY-MM-DD HH:MM:SS. Default empty.
|
||||
* }
|
||||
* @return int|false ID of inserted API request log, false on error.
|
||||
*/
|
||||
function edd_add_api_request_log( $data = array() ) {
|
||||
|
||||
// A request is required for every API request log that is inserted into
|
||||
// the database.
|
||||
if ( empty( $data['request'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow the ability to disable an API Request Log from being inserted.
|
||||
*
|
||||
* @since 3.1
|
||||
*
|
||||
* @param bool $should_record_log If this API reqeust should be logged.
|
||||
* @param array $data The data to be logged.
|
||||
*/
|
||||
$should_record_log = apply_filters( 'edd_should_log_api_request', true, $data );
|
||||
|
||||
if ( false === $should_record_log ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Instantiate a query object.
|
||||
$api_request_logs = new EDD\Database\Queries\Log_Api_Request();
|
||||
|
||||
return $api_request_logs->add_item( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an API request log.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $api_request_log_id API request log ID.
|
||||
* @return int|false `1` if the adjustment was deleted successfully, false on error.
|
||||
*/
|
||||
function edd_delete_api_request_log( $api_request_log_id = 0 ) {
|
||||
$api_request_logs = new EDD\Database\Queries\Log_Api_Request();
|
||||
|
||||
return $api_request_logs->delete_item( $api_request_log_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an API request log.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $api_request_log_id API request log ID.
|
||||
* @param array $data {
|
||||
* Array of API request log data. Default empty.
|
||||
*
|
||||
* @type int $user_id WordPress user ID of the authenticated user
|
||||
* making the API request. Default 0.
|
||||
* @type string $api_key User's API key. Default empty.
|
||||
* @type string $token User's API token. Default empty.
|
||||
* @type string $version API version used. Default empty.
|
||||
* @type string $request API request query. Default empty.
|
||||
* @type string $error Error(s), if any when making the API request.
|
||||
* Default empty.
|
||||
* @type string $ip IP address of the client making the API
|
||||
* request. Default empty.
|
||||
* @type string $time Time it took for API request to complete. Default empty.
|
||||
* @type string $date_created Optional. Automatically calculated on add/edit.
|
||||
* The date & time the API request log 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 API request log 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_api_request_log( $api_request_log_id = 0, $data = array() ) {
|
||||
$api_request_logs = new EDD\Database\Queries\Log_Api_Request();
|
||||
|
||||
return $api_request_logs->update_item( $api_request_log_id, $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an API request log by ID.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $api_request_log_id API request log ID.
|
||||
* @return Api_Request_Log|false Api_Request_Log object if successful, false otherwise.
|
||||
*/
|
||||
function edd_get_api_request_log( $api_request_log_id = 0 ) {
|
||||
$api_request_logs = new EDD\Database\Queries\Log_Api_Request();
|
||||
|
||||
// Return API Request Log.
|
||||
return $api_request_logs->get_item( $api_request_log_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an API request log by a specific field value.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param string $field Database table field.
|
||||
* @param string $value Value of the row.
|
||||
*
|
||||
* @return Api_Request_Log|false Api_Request_Log object if successful, false otherwise.
|
||||
*/
|
||||
function edd_get_api_request_log_by( $field = '', $value = '' ) {
|
||||
$api_request_logs = new EDD\Database\Queries\Log_Api_Request();
|
||||
|
||||
// Return API Request Log.
|
||||
return $api_request_logs->get_item_by( $field, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for API request logs.
|
||||
*
|
||||
* @see \EDD\Database\Queries\Log_Api_Request::__construct()
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $args Arguments. See `EDD\Database\Queries\Log_Api_Request` for
|
||||
* accepted arguments.
|
||||
* @return Api_Request_Log[] Array of `Api_Request_Log` objects.
|
||||
*/
|
||||
function edd_get_api_request_logs( $args = array() ) {
|
||||
|
||||
// Parse args
|
||||
$r = wp_parse_args( $args, array(
|
||||
'number' => 30
|
||||
) );
|
||||
|
||||
// Instantiate a query object
|
||||
$api_request_logs = new EDD\Database\Queries\Log_Api_Request();
|
||||
|
||||
// Return logs
|
||||
return $api_request_logs->query( $r );
|
||||
}
|
||||
|
||||
/**
|
||||
* Count API request logs.
|
||||
*
|
||||
* @see \EDD\Database\Queries\Log_Api_Request::__construct()
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $args Arguments. See `EDD\Database\Queries\Log_Api_Request` for
|
||||
* accepted arguments.
|
||||
* @return int Number of API request logs returned based on query arguments passed.
|
||||
*/
|
||||
function edd_count_api_request_logs( $args = array() ) {
|
||||
|
||||
// Parse args
|
||||
$r = wp_parse_args( $args, array(
|
||||
'count' => true
|
||||
) );
|
||||
|
||||
// Query for count(s)
|
||||
$api_request_logs = new EDD\Database\Queries\Log_Api_Request( $r );
|
||||
|
||||
// Return count(s)
|
||||
return absint( $api_request_logs->found_items );
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* API Request Log Meta Functions
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Logs
|
||||
* @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 an api request log.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $api_request_log_id Log 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_api_request_log_meta( $api_request_log_id, $meta_key, $meta_value, $unique = false ) {
|
||||
return add_metadata( 'edd_logs_api_request', $api_request_log_id, $meta_key, $meta_value, $unique );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove meta data matching criteria from a log.
|
||||
*
|
||||
* 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 $api_request_log_id Log 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_api_request_log_meta( $api_request_log_id, $meta_key, $meta_value = '' ) {
|
||||
return delete_metadata( 'edd_logs_api_request', $api_request_log_id, $meta_key, $meta_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve log meta field for a log.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $api_request_log_id Log 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_api_request_log_meta( $api_request_log_id, $key = '', $single = false ) {
|
||||
return get_metadata( 'edd_logs_api_request', $api_request_log_id, $key, $single );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update api request log meta field based on api request log ID.
|
||||
*
|
||||
* Use the $prev_value parameter to differentiate between meta fields with the
|
||||
* same key and log ID.
|
||||
*
|
||||
* If the meta field for the log does not exist, it will be added.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $api_request_log_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_api_request_log_meta( $api_request_log_id, $meta_key, $meta_value, $prev_value = '' ) {
|
||||
return update_metadata( 'edd_logs_api_request', $api_request_log_id, $meta_key, $meta_value, $prev_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete everything from log meta matching meta key.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param string $meta_key Key to search for when deleting.
|
||||
*
|
||||
* @return bool Whether the log meta key was deleted from the database.
|
||||
*/
|
||||
function edd_delete_api_request_log_meta_by_key( $meta_key ) {
|
||||
return delete_metadata( 'edd_logs_api_request', null, $meta_key, '', true );
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* Logs API - File Download Log Object.
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Logs
|
||||
* @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\Logs;
|
||||
|
||||
use EDD\Base_Object;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* EDD_File_Download_Log Class.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $product_id
|
||||
* @property int $file_id
|
||||
* @property int $order_id
|
||||
* @property int $price_id
|
||||
* @property int $customer_id
|
||||
* @property string $ip
|
||||
* @property string $user_agent
|
||||
* @property string $date_created
|
||||
* @property string $date_modified
|
||||
*/
|
||||
class File_Download_Log extends Base_Object {
|
||||
|
||||
/**
|
||||
* File download log ID.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Product ID.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $product_id;
|
||||
|
||||
/**
|
||||
* File ID.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $file_id;
|
||||
|
||||
/**
|
||||
* Order ID.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $order_id;
|
||||
|
||||
/**
|
||||
* Price ID.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $price_id;
|
||||
|
||||
/**
|
||||
* Customer ID.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $customer_id;
|
||||
|
||||
/**
|
||||
* IP.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $ip;
|
||||
|
||||
/**
|
||||
* User Agent.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $user_agent;
|
||||
|
||||
/**
|
||||
* Date created.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $date_created;
|
||||
|
||||
/**
|
||||
* Date modified.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $date_modified;
|
||||
}
|
@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/**
|
||||
* File Download Log Functions.
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Logs
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
use EDD\Logs\File_Download_Log;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Add a file download log.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $data {
|
||||
* Array of file download log 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 $product_id
|
||||
* @type int $file_id File ID corresponding to the URL used
|
||||
* to download the file. Default 0.
|
||||
* @type int $order_id Order ID corresponding to the URL used
|
||||
* to download the file. Default 0.
|
||||
* @type int $price_id Price ID of the download for which the file
|
||||
* is being downloaded. Default 0.
|
||||
* @type int $customer_id ID of the customer downloading the file.
|
||||
* Default 0.
|
||||
* @type string $ip IP address of the client downloading the file.
|
||||
* Default empty.
|
||||
* @type string $user_agent User agent of the client downloading the file.
|
||||
* Default empty.
|
||||
* @type string $date_created Optional. Automatically calculated on add/edit.
|
||||
* The date & time the file download log 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 file download log was last modified.
|
||||
* Format: YYYY-MM-DD HH:MM:SS. Default empty.
|
||||
* }
|
||||
* @return int|false ID of newly created log, false on error.
|
||||
*/
|
||||
function edd_add_file_download_log( $data = array() ) {
|
||||
|
||||
// A product ID and an order ID must be supplied for every log that is
|
||||
// inserted into the database.
|
||||
if ( empty( $data['product_id'] ) || empty( $data['order_id'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow the ability to disable a File Download Log being inserted.
|
||||
*
|
||||
* @since 3.1
|
||||
*
|
||||
* @param bool $should_record_log If this file download should be logged.
|
||||
* @param array $data The data to be logged.
|
||||
*/
|
||||
$should_record_log = apply_filters( 'edd_should_log_file_download', true, $data );
|
||||
|
||||
if ( false === $should_record_log ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$file_download_logs = new EDD\Database\Queries\Log_File_Download();
|
||||
|
||||
return $file_download_logs->add_item( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a file download log.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $file_download_log_id File download log ID.
|
||||
* @return int|false `1` if the adjustment was deleted successfully, false on error.
|
||||
*/
|
||||
function edd_delete_file_download_log( $file_download_log_id = 0 ) {
|
||||
$file_download_logs = new EDD\Database\Queries\Log_File_Download();
|
||||
|
||||
return $file_download_logs->delete_item( $file_download_log_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a file download log.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $file_download_log_id File download log ID.
|
||||
* @param array $data {
|
||||
* Array of file download log data. Default empty.
|
||||
*
|
||||
* @type int $product_id
|
||||
* @type int $file_id File ID corresponding to the URL used
|
||||
* to download the file. Default 0.
|
||||
* @type int $order_id Order ID corresponding to the URL used
|
||||
* to download the file. Default 0.
|
||||
* @type int $price_id Price ID of the download for which the file
|
||||
* is being downloaded. Default 0.
|
||||
* @type int $customer_id ID of the customer downloading the file.
|
||||
* Default 0.
|
||||
* @type string $ip IP address of the client downloading the file.
|
||||
* Default empty.
|
||||
* @type string $user_agent User agent of the client downloading the file.
|
||||
* Default empty.
|
||||
* @type string $date_created Optional. Automatically calculated on add/edit.
|
||||
* The date & time the file download log 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 file download log 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_file_download_log( $file_download_log_id = 0, $data = array() ) {
|
||||
$file_download_logs = new EDD\Database\Queries\Log_File_Download();
|
||||
|
||||
return $file_download_logs->update_item( $file_download_log_id, $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a file download log by ID.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $file_download_log_id Log ID.
|
||||
* @return File_Download_Log|false Log object if successful, false otherwise.
|
||||
*/
|
||||
function edd_get_file_download_log( $file_download_log_id = 0 ) {
|
||||
$file_download_logs = new EDD\Database\Queries\Log_File_Download();
|
||||
|
||||
// Return file download log
|
||||
return $file_download_logs->get_item( $file_download_log_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a file download log by field and value.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param string $field Database table field.
|
||||
* @param string $value Value of the row.
|
||||
*
|
||||
* @return File_Download_Log|false Log object if successful, false otherwise.
|
||||
*/
|
||||
function edd_get_file_download_log_by( $field = '', $value = '' ) {
|
||||
$file_download_logs = new EDD\Database\Queries\Log_File_Download();
|
||||
|
||||
// Return file download log
|
||||
return $file_download_logs->get_item_by( $field, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for file download logs.
|
||||
*
|
||||
* @see \EDD\Database\Queries\Log_File_Download::__construct()
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $args Arguments. See `EDD\Database\Queries\Log_File_Download`
|
||||
* for accepted arguments.
|
||||
* @return File_Download_Log[] Array of `File_Download_Log` objects.
|
||||
*/
|
||||
function edd_get_file_download_logs( $args = array() ) {
|
||||
|
||||
// Parse args
|
||||
$r = wp_parse_args( $args, array(
|
||||
'number' => 30
|
||||
) );
|
||||
|
||||
// Instantiate a query object
|
||||
$file_download_logs = new EDD\Database\Queries\Log_File_Download();
|
||||
|
||||
// Return file download logs
|
||||
return $file_download_logs->query( $r );
|
||||
}
|
||||
|
||||
/**
|
||||
* Count file download logs.
|
||||
*
|
||||
* @see \EDD\Database\Queries\Log_File_Download::__construct()
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $args Arguments. See `EDD\Database\Queries\Log_File_Download`
|
||||
* for accepted arguments.
|
||||
* @return int Number of file download logs returned based on query arguments passed.
|
||||
*/
|
||||
function edd_count_file_download_logs( $args = array() ) {
|
||||
|
||||
// Parse args
|
||||
$r = wp_parse_args( $args, array(
|
||||
'count' => true
|
||||
) );
|
||||
|
||||
// Query for count(s)
|
||||
$file_download_logs = new EDD\Database\Queries\Log_File_Download( $r );
|
||||
|
||||
// Return count(s)
|
||||
return absint( $file_download_logs->found_items );
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* File Download Log Meta Functions
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Logs
|
||||
* @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 file download log.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $file_download_log_id Log 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_file_download_log_meta( $file_download_log_id, $meta_key, $meta_value, $unique = false ) {
|
||||
return add_metadata( 'edd_logs_file_download', $file_download_log_id, $meta_key, $meta_value, $unique );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove meta data matching criteria from a log.
|
||||
*
|
||||
* 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 $file_download_log_id Log 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_file_download_log_meta( $file_download_log_id, $meta_key, $meta_value = '' ) {
|
||||
return delete_metadata( 'edd_logs_file_download', $file_download_log_id, $meta_key, $meta_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve log meta field for a log.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $file_download_log_id Log 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_file_download_log_meta( $file_download_log_id, $key = '', $single = false ) {
|
||||
return get_metadata( 'edd_logs_file_download', $file_download_log_id, $key, $single );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update file download log meta field based on file download log ID.
|
||||
*
|
||||
* Use the $prev_value parameter to differentiate between meta fields with the
|
||||
* same key and log ID.
|
||||
*
|
||||
* If the meta field for the log does not exist, it will be added.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $file_download_log_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_file_download_log_meta( $file_download_log_id, $meta_key, $meta_value, $prev_value = '' ) {
|
||||
return update_metadata( 'edd_logs_file_download', $file_download_log_id, $meta_key, $meta_value, $prev_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete everything from log meta matching meta key.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param string $meta_key Key to search for when deleting.
|
||||
*
|
||||
* @return bool Whether the log meta key was deleted from the database.
|
||||
*/
|
||||
function edd_delete_file_download_log_meta_by_key( $meta_key ) {
|
||||
return delete_metadata( 'edd_logs_file_download', null, $meta_key, '', true );
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* Logs API - Log Object
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Logs
|
||||
* @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\Logs;
|
||||
|
||||
use EDD\Base_Object;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Log Class.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $object_id
|
||||
* @property string $object_type
|
||||
* @property int $user_id
|
||||
* @property string $type
|
||||
* @property string $title
|
||||
* @property string $content
|
||||
* @property string $date_created
|
||||
* @property string $date_modified
|
||||
*/
|
||||
class Log extends Base_Object {
|
||||
|
||||
/**
|
||||
* Log 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;
|
||||
|
||||
/**
|
||||
* User ID.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $user_id;
|
||||
|
||||
/**
|
||||
* Log type.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Log title.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Log content.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $content;
|
||||
|
||||
/**
|
||||
* Date log was created.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $date_created;
|
||||
|
||||
/**
|
||||
* Date log was last modified.
|
||||
*
|
||||
* @since 3.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $date_modified;
|
||||
}
|
@ -0,0 +1,228 @@
|
||||
<?php
|
||||
/**
|
||||
* Log Functions.
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Logs
|
||||
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
use EDD\Logs\Log;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Add a log.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $data {
|
||||
* Array of log 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 log 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 log 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 $type Log type. Default empty.
|
||||
* @type string $title Log title. Default empty.
|
||||
* @type string $content Log content. Default empty.
|
||||
* @type string $date_created Optional. Automatically calculated on add/edit.
|
||||
* The date & time the log 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 log was last modified.
|
||||
* Format: YYYY-MM-DD HH:MM:SS. Default empty.
|
||||
* }
|
||||
* @return int|false ID of newly created log, false on error.
|
||||
*/
|
||||
function edd_add_log( $data = array() ) {
|
||||
|
||||
// An object type must be supplied for every log that is
|
||||
// inserted into the database.
|
||||
if ( empty( $data['object_type'] ) ) {
|
||||
// Verify that we do have an object_type before checking it further.
|
||||
if ( array_key_exists( 'object_type', $data ) && is_null( $data['object_type'] ) ) {
|
||||
// If the object_id is not empty but the object_type is null, fail this log attempt.
|
||||
if ( ! empty( $data['object_id'] ) ) {
|
||||
return false;
|
||||
}
|
||||
// The object_type is not null, and it is empty. No log will take place.
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$object_type_for_filter = ! empty( $data['object_type'] ) ? $data['object_type'] : 'generic';
|
||||
/**
|
||||
* Allow the ability to disable a generic log entry by object_type.
|
||||
*
|
||||
* Based on the object type, allows developers to disable the insertion of a log.
|
||||
*
|
||||
* Example:
|
||||
* add_filter( 'edd_should_log_gateway_error', '__return_false' )
|
||||
*
|
||||
* You can find a list of the logs object types in the edd_logs table.
|
||||
*
|
||||
* @since 3.1
|
||||
*
|
||||
* @param bool $should_record_log If this log should be inserted
|
||||
* @param array $data The data to be logged.
|
||||
*/
|
||||
$should_record_log = apply_filters( "edd_should_log_{$object_type_for_filter}", true, $data );
|
||||
|
||||
if ( false === $should_record_log ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Instantiate a query object.
|
||||
$logs = new EDD\Database\Queries\Log();
|
||||
|
||||
return $logs->add_item( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a log.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $log_id Log ID.
|
||||
* @return int|false `1` if the adjustment was deleted successfully, false on error.
|
||||
*/
|
||||
function edd_delete_log( $log_id = 0 ) {
|
||||
$logs = new EDD\Database\Queries\Log();
|
||||
|
||||
return $logs->delete_item( $log_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a log.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $log_id Log ID.
|
||||
* @param array $data {
|
||||
* Array of log data. Default empty.
|
||||
*
|
||||
* @type int $object_id Object ID that the log 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 log 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 $type Log type. Default empty.
|
||||
* @type string $title Log title. Default empty.
|
||||
* @type string $content Log content. Default empty.
|
||||
* @type string $date_created Optional. Automatically calculated on add/edit.
|
||||
* The date & time the log 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 log 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_log( $log_id = 0, $data = array() ) {
|
||||
$logs = new EDD\Database\Queries\Log();
|
||||
|
||||
return $logs->update_item( $log_id, $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a log by ID.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $log_id Log ID.
|
||||
* @return Log|false Log object if successful, false otherwise.
|
||||
*/
|
||||
function edd_get_log( $log_id = 0 ) {
|
||||
$logs = new EDD\Database\Queries\Log();
|
||||
|
||||
// Return log
|
||||
return $logs->get_item( $log_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a log by a specific field value.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param string $field Database table field.
|
||||
* @param string $value Value of the row.
|
||||
*
|
||||
* @return Log|false Log object if successful, false otherwise.
|
||||
*/
|
||||
function edd_get_log_by( $field = '', $value = '' ) {
|
||||
$logs = new EDD\Database\Queries\Log();
|
||||
|
||||
// Return log
|
||||
return $logs->get_item_by( $field, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for logs.
|
||||
*
|
||||
* @see \EDD\Database\Queries\Log::__construct()
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $args Arguments. See `EDD\Database\Queries\Log` for
|
||||
* accepted arguments.
|
||||
* @return Log[] Array of `Log` objects.
|
||||
*/
|
||||
function edd_get_logs( $args = array() ) {
|
||||
|
||||
// Parse args
|
||||
$r = wp_parse_args( $args, array(
|
||||
'number' => 30
|
||||
) );
|
||||
|
||||
// Instantiate a query object
|
||||
$logs = new EDD\Database\Queries\Log();
|
||||
|
||||
// Return logs
|
||||
return $logs->query( $r );
|
||||
}
|
||||
|
||||
/**
|
||||
* Count logs.
|
||||
*
|
||||
* @see \EDD\Database\Queries\Log::__construct()
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $args Arguments. See `EDD\Database\Queries\Log` for
|
||||
* accepted arguments.
|
||||
* @return int Number of logs returned based on query arguments passed.
|
||||
*/
|
||||
function edd_count_logs( $args = array() ) {
|
||||
|
||||
// Parse args.
|
||||
$r = wp_parse_args(
|
||||
$args,
|
||||
array(
|
||||
'count' => true,
|
||||
)
|
||||
);
|
||||
|
||||
// Query for count(s).
|
||||
$logs = new EDD\Database\Queries\Log( $r );
|
||||
|
||||
// Return the number of logs found in the query.
|
||||
return absint( $logs->found_items );
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Log Meta Functions
|
||||
*
|
||||
* @package EDD
|
||||
* @subpackage Logs
|
||||
* @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 log.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $log_id Log 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_log_meta( $log_id, $meta_key, $meta_value, $unique = false ) {
|
||||
return add_metadata( 'edd_log', $log_id, $meta_key, $meta_value, $unique );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove meta data matching criteria from a log.
|
||||
*
|
||||
* 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 $log_id Log 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_log_meta( $log_id, $meta_key, $meta_value = '' ) {
|
||||
return delete_metadata( 'edd_log', $log_id, $meta_key, $meta_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve log meta field for a log.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $log_id Log 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_log_meta( $log_id, $key = '', $single = false ) {
|
||||
return get_metadata( 'edd_log', $log_id, $key, $single );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update log meta field based on log ID.
|
||||
*
|
||||
* Use the $prev_value parameter to differentiate between meta fields with the
|
||||
* same key and log ID.
|
||||
*
|
||||
* If the meta field for the log does not exist, it will be added.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param int $log_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_log_meta( $log_id, $meta_key, $meta_value, $prev_value = '' ) {
|
||||
return update_metadata( 'edd_log', $log_id, $meta_key, $meta_value, $prev_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete everything from log meta matching meta key.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param string $meta_key Key to search for when deleting.
|
||||
*
|
||||
* @return bool Whether the log meta key was deleted from the database.
|
||||
*/
|
||||
function edd_delete_log_meta_by_key( $meta_key ) {
|
||||
return delete_metadata( 'edd_log', null, $meta_key, '', true );
|
||||
}
|
Reference in New Issue
Block a user