installed plugin Easy Digital Downloads version 3.1.0.3

This commit is contained in:
2022-11-27 15:03:07 +00:00
committed by Gitium
parent 555673545b
commit c5dce2cec6
1200 changed files with 238970 additions and 0 deletions

View File

@ -0,0 +1,132 @@
<?php
/**
* Notes Actions
*
* @package EDD
* @subpackage Admin/Discounts
* @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 via AJAX.
*
* @since 3.0
*/
function edd_admin_ajax_add_note() {
// Check AJAX referrer
check_ajax_referer( 'edd_note', 'nonce' );
// Bail if user cannot delete notes
if ( ! current_user_can( 'edit_shop_payments' ) ) {
wp_die( -1 );
}
// Get object ID
$object_id = ! empty( $_POST['object_id'] )
? absint( $_POST['object_id'] )
: 0;
// Get object type
$object_type = ! empty( $_POST['object_type'] )
? sanitize_key( $_POST['object_type'] )
: '';
// Bail if no object
if ( empty( $object_id ) || empty( $object_type ) ) {
wp_die( -1 );
}
// Get note contents (maybe sanitize)
$note = ! empty( $_POST['note'] )
? trim( wp_kses( stripslashes_deep( $_POST['note'] ), edd_get_allowed_tags() ) )
: '';
// Bail if no note
if ( empty( $note ) ) {
wp_die( -1 );
}
// Add the note
$note_id = edd_add_note( array(
'object_id' => $object_id,
'object_type' => $object_type,
'content' => $note,
'user_id' => get_current_user_id()
) );
$x = new WP_Ajax_Response();
$x->add(
array(
'what' => 'edd_note_html',
'data' => edd_admin_get_note_html( $note_id, $object_id ),
)
);
$x->send();
}
add_action( 'wp_ajax_edd_add_note', 'edd_admin_ajax_add_note' );
/**
* Delete a note.
*
* @since 3.0
*
* @param array $data Data from $_GET.
*/
function edd_admin_delete_note( $data = array() ) {
// Bail if missing any data
if ( empty( $data['_wpnonce'] ) || empty( $data['note_id'] ) ) {
return;
}
// Bail if nonce fails
if ( ! wp_verify_nonce( $data['_wpnonce'], 'edd_delete_note_' . $data['note_id'] ) ) {
return;
}
// Try to delete
edd_delete_note( $data['note_id'] );
edd_redirect( edd_get_note_delete_redirect_url() );
}
add_action( 'edd_delete_note', 'edd_admin_delete_note' );
/**
* Delete a discount note via AJAX.
*
* @since 3.0
*/
function edd_admin_ajax_delete_note() {
// Check AJAX referrer
check_ajax_referer( 'edd_note', 'nonce' );
// Bail if user cannot delete notes
if ( ! current_user_can( 'manage_shop_settings' ) ) {
wp_die( -1 );
}
// Get note ID
$note_id = ! empty( $_POST['note_id'] )
? absint( $_POST['note_id'] )
: 0;
// Bail if no note
if ( empty( $note_id ) ) {
wp_die( -1 );
}
// Delete note
if ( edd_delete_note( $note_id ) ) {
wp_die( 1 );
}
wp_die( 0 );
}
add_action( 'wp_ajax_edd_delete_note', 'edd_admin_ajax_delete_note' );

View File

@ -0,0 +1,223 @@
<?php
/**
* Notes Functions
*
* @package EDD
* @subpackage Admin/Discounts
* @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;
/**
* Get the HTML used to output all of the notes for a single object
*
* @since 3.0
*
* @param array $notes
* @return string
*/
function edd_admin_get_notes_html( $notes = array() ) {
// Whether to show or hide the "No notes" default text
$no_notes_display = ! empty( $notes )
? ' style="display:none;"'
: '';
// Start a buffer
ob_start(); ?>
<div id="edd-notes" class="edd-notes">
<?php
// Output notes
foreach ( $notes as $note ) {
echo edd_admin_get_note_html( $note );
}
?>
<p class="edd-no-notes"<?php echo $no_notes_display; ?>>
<?php _e( 'No notes.', 'easy-digital-downloads' ); ?>
</p>
</div>
<?php
// Return the current buffer
return ob_get_clean();
}
/**
* Get the HTML used to output a single note, from an array of notes
*
* @since 3.0
* @param int $note_id
*
* @return string
*/
function edd_admin_get_note_html( $note_id = 0 ) {
/** @var $note EDD\Notes\Note For IDE type-hinting purposes. */
// Get the note
$note = is_numeric( $note_id )
? edd_get_note( $note_id )
: $note_id;
// No note, so bail
if ( empty( $note ) ) {
return;
}
// User
$user_id = $note->user_id;
$author = edd_get_bot_name();
if ( ! empty( $user_id ) ) {
/* translators: user ID */
$author = sprintf( __( 'User ID #%s', 'easy-digital-downloads' ), $user_id );
$user_object = get_userdata( $user_id );
if ( $user_object ) {
$author = ! empty( $user_object->display_name ) ? $user_object->display_name : $user_object->user_login;
}
}
// URL to delete note
$delete_note_url = wp_nonce_url( add_query_arg( array(
'edd-action' => 'delete_note',
'note_id' => absint( $note->id ),
) ), 'edd_delete_note_' . absint( $note->id ) );
// Start a buffer
ob_start();
?>
<div class="edd-note" id="edd-note-<?php echo esc_attr( $note->id ); ?>">
<div class="edd-note__header">
<strong class="edd-note-author"><?php echo esc_html( $author ); ?></strong>
<time datetime="<?php echo esc_attr( EDD()->utils->date( $note->date_created, null, true )->toDateTimeString() ); ?>"><?php echo edd_date_i18n( $note->date_created, 'datetime' ); ?></time>
<a href="<?php echo esc_url( $delete_note_url ); ?>#edd-notes" class="edd-delete-note" data-note-id="<?php echo esc_attr( $note->id ); ?>" data-object-id="<?php echo esc_attr( $note->object_id ); ?>" data-object-type="<?php echo esc_attr( $note->object_type ); ?>">
<?php echo esc_html_x( '&times;', 'Delete note', 'easy-digital-downloads' ); ?>
</a>
</div>
<?php echo wpautop( make_clickable( $note->content ) ); ?>
</div>
<?php
// Return the current buffer
return ob_get_clean();
}
/**
* Get the HTML used to add a note to an object ID and type
*
* @since 3.0
*
* @param int $object_id
* @param string $object_type
*
* @return string
*/
function edd_admin_get_new_note_form( $object_id = 0, $object_type = '' ) {
if ( ! current_user_can( 'edit_shop_payments' ) ) {
return '';
}
// Start a buffer
ob_start();?>
<div class="edd-add-note">
<div class="edd-form-group">
<label class="edd-form-group__label screen-reader-text" for="edd-note">
<?php esc_html_e( 'Note', 'easy-digital-downloads' ); ?>
</label>
<div id="edd-form-group__control">
<textarea name="edd-note" id="edd-note" class="edd-form-group__input"></textarea>
</div>
</div>
<div class="edd-form-group">
<button type="button" id="edd-add-note" class="edd-note-submit button button-secondary left" data-object-id="<?php echo esc_attr( $object_id ); ?>" data-object-type="<?php echo esc_attr( $object_type ); ?>">
<?php _e( 'Add Note', 'easy-digital-downloads' ); ?>
</button>
<span class="spinner"></span>
</div>
<?php wp_nonce_field( 'edd_note', 'edd_note_nonce' ); ?>
</div>
<?php
// Return the current buffer
return ob_get_clean();
}
/**
* Return the URL to redirect to after deleting a note
*
* For now, this is always the current URL, because we aren't ever sure where
* notes are being used. Maybe this will need a filter or something, someday.
*
* @since 3.0
*
* @return string
*/
function edd_get_note_delete_redirect_url() {
// HTTP or HTTPS
$scheme = is_ssl()
? 'https'
: 'http';
// Return the concatenated URL
return "{$scheme}://{$_SERVER[HTTP_HOST]}{$_SERVER[REQUEST_URI]}";
}
/**
* Return the HTML used to paginate through notes.
*
* @since 3.0
* @param array $args
*/
function edd_admin_get_notes_pagination( $args = array() ) {
// Parse args
$r = wp_parse_args( $args, array(
'total' => 0,
'pag_arg' => 'paged',
'base' => '%_%',
'show_all' => true,
'prev_text' => is_rtl() ? '&rarr;' : '&larr;',
'next_text' => is_rtl() ? '&larr;' : '&rarr;',
'add_fragment' => ''
) );
// Maximum notes per page
$per_page = apply_filters( 'edd_notes_per_page', 20 );
$r['total'] = ceil( $r['total'] / $per_page );
$r['format'] = "?{$r['pag_arg']}=%#%";
// Don't allow pagination beyond the boundaries
$r['current'] = ! empty( $_GET[ $r['pag_arg'] ] ) && is_numeric( $_GET[ $r['pag_arg'] ] )
? absint( $_GET[ $r['pag_arg'] ] )
: 1;
// Start a buffer
ob_start(); ?>
<div class="edd-note-pagination">
<?php echo paginate_links( $r ); ?>
</div>
<?php
// Return the current buffer
return ob_get_clean();
}