Changeset 2793155
- Timestamp:
- 10/02/2022 10:41:20 PM (3 years ago)
- Location:
- dco-comment-attachment
- Files:
-
- 15 added
- 6 edited
-
tags/2.4.0 (added)
-
tags/2.4.0/assets (added)
-
tags/2.4.0/assets/dco-comment-attachment-admin.css (added)
-
tags/2.4.0/assets/dco-comment-attachment-admin.js (added)
-
tags/2.4.0/assets/dco-comment-attachment.css (added)
-
tags/2.4.0/assets/dco-comment-attachment.js (added)
-
tags/2.4.0/dco-comment-attachment.php (added)
-
tags/2.4.0/includes (added)
-
tags/2.4.0/includes/back-compat.php (added)
-
tags/2.4.0/includes/class-dco-ca-admin.php (added)
-
tags/2.4.0/includes/class-dco-ca-base.php (added)
-
tags/2.4.0/includes/class-dco-ca-settings.php (added)
-
tags/2.4.0/includes/class-dco-ca.php (added)
-
tags/2.4.0/includes/functions.php (added)
-
tags/2.4.0/readme.txt (added)
-
trunk/assets/dco-comment-attachment-admin.js (modified) (1 diff)
-
trunk/dco-comment-attachment.php (modified) (2 diffs)
-
trunk/includes/class-dco-ca-admin.php (modified) (4 diffs)
-
trunk/includes/class-dco-ca-base.php (modified) (2 diffs)
-
trunk/includes/class-dco-ca.php (modified) (6 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dco-comment-attachment/trunk/assets/dco-comment-attachment-admin.js
r2636964 r2793155 54 54 } 55 55 ); 56 57 // Only for DCO_CA_Admin::show_bulk_action_message() 58 if ( $( '#the-comment-list' ).length ) { 59 const $referer = $( '[name="_wp_http_referer"]' ); 60 const params = new URLSearchParams( $referer.val() ); 61 params.delete( 'deletedattachment' ); 62 $referer.val( decodeURIComponent( params.toString() ) ); 63 } 56 64 57 65 $( '#dco-comment-attachment' ).on( -
dco-comment-attachment/trunk/dco-comment-attachment.php
r2642680 r2793155 13 13 * Plugin URI: https://denisco.pro/dco-comment-attachment/ 14 14 * Description: Allows your visitors to attach files with their comments 15 * Version: 2. 3.115 * Version: 2.4.0 16 16 * Author: Denis Yanchevskiy 17 17 * Author URI: https://denisco.pro … … 25 25 define( 'DCO_CA_PATH', plugin_dir_path( __FILE__ ) ); 26 26 define( 'DCO_CA_BASENAME', plugin_basename( __FILE__ ) ); 27 define( 'DCO_CA_VERSION', '2. 3.1' );27 define( 'DCO_CA_VERSION', '2.4.0' ); 28 28 29 29 require_once DCO_CA_PATH . 'includes/functions.php'; -
dco-comment-attachment/trunk/includes/class-dco-ca-admin.php
r2642679 r2793155 40 40 41 41 add_filter( 'comment_row_actions', array( $this, 'add_comment_action_links' ), 10, 2 ); 42 add_action( 'admin_action_deleteattachment', array( $this, 'delete_attachment_action' ) ); 42 add_action( 'admin_action_deletecommentattachment', array( $this, 'delete_attachment_action' ) ); 43 add_filter( 'bulk_actions-edit-comments', array( $this, 'add_comments_bulk_actions' ) ); 44 add_action( 'admin_action_deleteattachment', array( $this, 'delete_attachment_bulk_action' ) ); 45 add_filter( 'ngettext', array( $this, 'show_bulk_action_message' ), 10, 5 ); 46 add_filter( 'removable_query_args', array( $this, 'add_removable_query_args' ) ); 43 47 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 44 48 add_action( 'wp_ajax_delete_attachment', array( $this, 'delete_attachment_ajax' ) ); … … 71 75 72 76 $del_attach_nonce = esc_html( '_wpnonce=' . $nonce ); 73 $url = esc_url( "comment.php?c=$comment_id&action=delete attachment&$del_attach_nonce" );74 75 $title = esc_html__( 'Delete Attachment', 'dco-comment-attachment' );76 $actions['delete attachment'] = "<a href='$url' class='dco-del-attachment' data-id='$comment_id' data-nonce='$nonce'>$title</a>";77 $url = esc_url( "comment.php?c=$comment_id&action=deletecommentattachment&$del_attach_nonce" ); 78 79 $title = esc_html__( 'Delete Attachment', 'dco-comment-attachment' ); 80 $actions['deletecommentattachment'] = "<a href='$url' class='dco-del-attachment' data-id='$comment_id' data-nonce='$nonce'>$title</a>"; 77 81 } 78 82 … … 119 123 wp_safe_redirect( $redir ); 120 124 exit(); 125 } 126 127 /** 128 * Adds additional bulk actions. 129 * 130 * @since 2.4.0 131 * 132 * @param array $actions An array of the available bulk actions. 133 * @return array An array with standard bulk actions 134 * and attachment bulk actions. 135 */ 136 public function add_comments_bulk_actions( $actions ) { 137 $actions['deleteattachment'] = __( 'Delete Attachment', 'dco-comment-attachment' ); 138 139 return $actions; 140 } 141 142 /** 143 * Handles a bulk action to delete comment attachments on the comments page. 144 * 145 * @since 2.4.0 146 */ 147 public function delete_attachment_bulk_action() { 148 check_admin_referer( 'bulk-comments' ); 149 150 if ( isset( $_REQUEST['delete_comments'] ) && is_array( $_REQUEST['delete_comments'] ) ) { 151 $comment_ids = array_map( 'absint', $_REQUEST['delete_comments'] ); 152 } else { 153 return; 154 } 155 156 $redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids', 'deletedattachment' ), wp_get_referer() ); 157 158 wp_defer_comment_counting( true ); 159 160 $count = 0; 161 foreach ( $comment_ids as $comment_id ) { 162 if ( ! current_user_can( 'edit_comment', $comment_id ) ) { 163 continue; 164 } 165 166 $comment = get_comment( $comment_id ); 167 if ( ! $comment ) { 168 continue; 169 } 170 171 $delete = $this->get_option( 'delete_attachment_action' ); 172 if ( $this->delete_attachment( $comment_id, $delete ) ) { 173 $count ++; 174 } 175 } 176 177 wp_defer_comment_counting( false ); 178 179 $redirect_to = add_query_arg( 'deletedattachment', $count, $redirect_to ); 180 181 // @see DCO_CA_Admin::show_bulk_action_message() for details. 182 $redirect_to = add_query_arg( 'approved', $count, $redirect_to ); 183 184 wp_safe_redirect( $redirect_to ); 185 exit; 186 } 187 188 /** 189 * Shows bulk action updated message. 190 * 191 * @since 2.4.0 192 * 193 * @param string $translation Translated text. 194 * @param string $single The text to be used if the number is singular. 195 * @param string $plural The text to be used if the number is plural. 196 * @param string $number The number to compare against to use either the singular or plural form. 197 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 198 * 199 * @return string Filtered translated text. 200 */ 201 public function show_bulk_action_message( $translation, $single, $plural, $number, $domain ) { 202 /** 203 * There is no hook in WordPress to add updated message for custom comments bulk action. 204 * So we override the approval message if attachment deletion was triggered. 205 */ 206 // phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized 207 if ( ! isset( $_REQUEST['deletedattachment'] ) || ! $_REQUEST['deletedattachment'] ) { 208 return $translation; 209 } 210 // phpcs:enable 211 212 if ( '%s comment approved.' === $single && '%s comments approved.' === $plural && 'default' === $domain ) { 213 /* translators: %s: Number of comments. */ 214 $translation = sprintf( _n( 'Attachments deleted from %s comment.', 'Attachments deleted from %s comments.', $number, 'dco-comment-attachment' ), $number ); 215 } 216 217 return $translation; 218 } 219 220 /** 221 * Adds single-use URL parameters. 222 * 223 * @since 2.4.0 224 * 225 * @param array $removable_query_args An array of query variable names to remove from the URL. 226 * @return array An array of query variable names to remove from the URL. 227 */ 228 public function add_removable_query_args( $removable_query_args ) { 229 $removable_query_args[] = 'deletedattachment'; 230 231 return $removable_query_args; 121 232 } 122 233 … … 272 383 273 384 $attachment_id = isset( $_POST['dco_attachment_id'] ) ? array_map( 'intval', $_POST['dco_attachment_id'] ) : array(); 385 386 // We need to delete the last empty element, because it's used 387 // as a placeholder in the attachments edit form. 388 // @see DCO_CA_Admin::render_attachment_metabox. 389 array_pop( $attachment_id ); 390 274 391 if ( $attachment_id ) { 275 // We need to delete the last empty element, because it's used276 // as a placeholder in the attachments edit form.277 // @see DCO_CA_Admin::render_attachment_metabox.278 array_pop( $attachment_id );279 280 392 $this->assign_attachment( $comment_id, $attachment_id ); 281 393 } else { -
dco-comment-attachment/trunk/includes/class-dco-ca-base.php
r2642679 r2793155 68 68 * 69 69 * @param int $comment_id Optional. The comment ID. 70 * @return int| string The assigned attachment IDon success,71 * empty string on failure.70 * @return int|array|string The assigned attachment ID(s) on success, 71 * empty string on failure. 72 72 */ 73 73 public function get_attachment_id( $comment_id = 0 ) { … … 114 114 * @since 1.0.0 115 115 * 116 * @param int $comment_id The comment ID.117 * @param int $attachment_id The attachment ID.116 * @param int $comment_id The comment ID. 117 * @param int|array $attachment_id The attachment ID(s). 118 118 * @return int|bool Meta ID on success, false on failure. 119 119 */ -
dco-comment-attachment/trunk/includes/class-dco-ca.php
r2642679 r2793155 72 72 add_filter( 'comment_text', array( $this, 'autoembed_links' ), 5 ); 73 73 } 74 75 add_shortcode( 'dco_ca', array( $this, 'dco_ca_shortcode' ) ); 74 76 } 75 77 … … 530 532 } 531 533 532 $this->assign_attachment( $comment_id, $ids ); 534 if ( $ids ) { 535 $this->assign_attachment( $comment_id, $ids ); 536 } 533 537 534 538 $_FILES[ $field_name ] = $attachments; … … 570 574 } 571 575 572 $attachment_id = (array) $this->get_attachment_id( $comment->comment_ID ); 576 $attachment_id = $this->get_attachment_id( $comment->comment_ID ); 577 $attachment_content = $this->generate_attachment_markup( $attachment_id ); 578 579 return $comment_text . $attachment_content; 580 } 581 582 /** 583 * Generates an attachment markup. 584 * 585 * @since 2.4.0 586 * 587 * @param int|array $attachment_id The attachment ID(s). 588 * @return string The attachment HTML markup. 589 */ 590 public function generate_attachment_markup( $attachment_id ) { 591 if ( ! is_array( $attachment_id ) ) { 592 $attachment_id = (array) $attachment_id; 593 } 594 573 595 if ( count( $attachment_id ) > 1 ) { 574 596 $this->enable_gallery_image_size(); 575 597 $attachments_content = array(); 576 598 foreach ( $attachment_id as $attach_id ) { 599 // Check that the attachment exists. 600 if ( ! wp_get_attachment_url( $attach_id ) ) { 601 continue; 602 } 603 577 604 $type = $this->get_embed_type( $attach_id ); 578 605 $key = "{$type}_{$attach_id}"; … … 582 609 583 610 if ( $this->get_option( 'combine_images' ) || is_admin() ) { 584 // combine only images.611 // Combine only images. 585 612 $not_images = array(); 586 613 foreach ( $attachments_content as $key => $content ) { … … 603 630 } 604 631 605 return $ comment_text . $attachment_content;632 return $attachment_content; 606 633 } 607 634 … … 634 661 635 662 return $response; 663 } 664 665 /** 666 * The dco_ca shortcode handler. 667 * 668 * @since 2.4.0 669 * 670 * @param array $atts { 671 * An array of shortcode attributes. 672 * 673 * @type int $post_id Optional. The post ID. Default current post ID. 674 * @type string $type Optional. Attachment types separated by comma. 675 * Accepts: all, image, video, audio, misc. 676 * Default: all. 677 * } 678 */ 679 public function dco_ca_shortcode( $atts ) { 680 $atts = shortcode_atts( 681 array( 682 'post_id' => get_the_ID(), 683 'type' => 'all', 684 ), 685 $atts, 686 'dco_ca' 687 ); 688 689 $comments = get_comments( 690 array( 691 'post_id' => $atts['post_id'], 692 'meta_key' => 'attachment_id', 693 'status' => 'approve', 694 ) 695 ); 696 697 $ids = array(); 698 foreach ( $comments as $comment ) { 699 $attachment_id = (array) $this->get_attachment_id( $comment->comment_ID ); 700 if ( 'all' === $atts['type'] ) { 701 $ids = array_merge( $ids, $attachment_id ); 702 } else { 703 $types = array_map( 'trim', explode( ',', $atts['type'] ) ); 704 foreach ( $attachment_id as $attach_id ) { 705 $type = $this->get_embed_type( $attach_id ); 706 if ( in_array( $type, $types, true ) ) { 707 $ids[] = $attach_id; 708 } 709 } 710 } 711 } 712 713 return '<div class="dco-attachments-list">' . $this->generate_attachment_markup( $ids ) . '</div>'; 636 714 } 637 715 -
dco-comment-attachment/trunk/readme.txt
r2642679 r2793155 3 3 Tags: comment, comment attachment, attachment, image, video 4 4 Requires at least: 4.6 5 Tested up to: 5.85 Tested up to: 6.0 6 6 Requires PHP: 5.6 7 Stable tag: 2. 3.17 Stable tag: 2.4.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 33 33 You can also: 34 34 35 * Add, replace or delete an attachment from a comment on Edit Comment screen.35 * Add, replace or delete an attachment from a comment on the Edit Comment screen. 36 36 * Attach an unlimited number of attachments to the comment in the admin panel. 37 * Delete an attachment on Comments screen. 37 * Delete an attachment from a specific comment or bulk delete attachments from comments on the Comments screen. 38 * Display attachments attached to comments to the current post (or a specific post) with the `[dco_ca]` shortcode. You can also filter by type. See [FAQ](#faq) for details. 38 39 39 40 Attachments are uploaded to the WordPress Media Library and deleted along with the comment (if this is set in the settings). … … 60 61 Feel free to create [a new topic](https://wordpress.org/support/plugin/dco-comment-attachment/) on support forum if you need integration with another plugin. 61 62 63 = How to use the [dco_ca] shortcode? = 64 65 Without attributes specified, the `[dco_ca]` shortcode will display all attachments attached to current post. 66 67 You can filter attachments using the `type` attribute. By default it is `all`. Also supported: `image`, `video`, `audio` and `misc`. 68 You can specify one value `[dco_ca type="image"]` or multiple values, separated by commas `[dco_ca type="video,audio"]`. 69 70 You can also display attachments from the comments of another post using the `post_id` attribute. 71 For example, `[dco_ca post_id="45"]`, where `45` is the ID of the specific post. 72 73 You can also combine these attributes. For example, `[dco_ca post_id="45" type="image"]` will display all images attached to comments to the post with ID 45. 74 62 75 == Changelog == 76 77 = 2.4.0 = 78 * Added bulk delete attachments action on the Comments screen. 79 * Added the `[dco_ca]` shortcode for display attachments attached to comments (see FAQ for details). 80 * Fixed bug: now if there is no attachment, the empty array is not saved to the database. 63 81 64 82 = 2.3.1 =
Note: See TracChangeset
for help on using the changeset viewer.