Changeset 11921 for sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/includes/class-gp-translation-helpers.php
- Timestamp:
- 06/21/2022 02:15:05 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/includes/class-gp-translation-helpers.php
r11837 r11921 63 63 add_action( 'gp_pre_tmpl_load', array( $this, 'register_reject_feedback_js' ), 10, 2 ); 64 64 add_action( 'wp_ajax_reject_with_feedback', array( $this, 'reject_with_feedback' ) ); 65 add_action( 'wp_ajax_optout_discussion_notifications', array( $this, 'optout_discussion_notifications' ) ); 65 66 66 67 add_thickbox(); … … 160 161 161 162 $translation_helpers_settings = array( 162 'th_url' => gp_url_project( $args['project'], gp_url_join( $args['locale_slug'], $args['translation_set_slug'], '-get-translation-helpers' ) ), 163 'th_url' => gp_url_project( $args['project'], gp_url_join( $args['locale_slug'], $args['translation_set_slug'], '-get-translation-helpers' ) ), 164 'ajax_url' => admin_url( 'admin-ajax.php' ), 165 'nonce' => wp_create_nonce( 'gp_optin_optout' ), 163 166 ); 164 167 … … 395 398 396 399 // Post comment on discussion page for the first string 397 $ save_feedback= $this->insert_reject_comment( $reject_comment, $first_original_id, $reject_reason, $first_translation_id, $locale_slug, $_SERVER );400 $first_comment_id = $this->insert_reject_comment( $reject_comment, $first_original_id, $reject_reason, $first_translation_id, $locale_slug, $_SERVER ); 398 401 399 402 if ( ! empty( $original_id_array ) && ! empty( $translation_id_array ) ) { 400 403 // For other strings post link to the comment. 401 $reject_comment = get_comment_link( $ save_feedback);404 $reject_comment = get_comment_link( $first_comment_id ); 402 405 foreach ( $original_id_array as $index => $single_original_id ) { 403 $this->insert_reject_comment( $reject_comment, $single_original_id, $reject_reason, $translation_id_array[ $index ], $locale_slug, $_SERVER ); 404 } 406 $comment_id = $this->insert_reject_comment( $reject_comment, $single_original_id, $reject_reason, $translation_id_array[ $index ], $locale_slug, $_SERVER ); 407 $comment = get_comment( $comment_id ); 408 GP_Notifications::add_related_comment( $comment ); 409 } 410 } 411 412 if ( $first_comment_id ) { 413 $comment = get_comment( $first_comment_id ); 414 GP_Notifications::init( $comment, null, null ); 405 415 } 406 416 407 417 wp_send_json_success(); 418 } 419 420 /** 421 * Adds or removes metadata to a user, related with the opt-in/opt-out status in a discussion 422 * 423 * It receives thought Ajax this data: 424 * - nonce. 425 * - originalId. The id of the original string related with the discussion. 426 * - optType: 427 * - optout. Add the metadata, to opt-out from the notifications. 428 * - optin. Removes the metadata, to opt-in from the notifications. Default status. 429 * 430 * @since 0.0.2 431 * 432 * @return void 433 */ 434 public function optout_discussion_notifications() { 435 $nonce = sanitize_text_field( $_POST['data']['nonce'] ); 436 if ( ! wp_verify_nonce( $nonce, 'gp_optin_optout' ) ) { 437 wp_send_json_error( esc_html__( 'Invalid nonce.' ), 403 ); 438 } else { 439 $user_id = get_current_user_id(); 440 $original_id = sanitize_text_field( $_POST['data']['originalId'] ); 441 $opt_type = sanitize_text_field( $_POST['data']['optType'] ); 442 if ( 'optout' === $opt_type ) { 443 add_user_meta( $user_id, 'gp_opt_out', $original_id ); 444 } elseif ( 'optin' === $opt_type ) { 445 delete_user_meta( $user_id, 'gp_opt_out', $original_id ); 446 } 447 wp_send_json_success(); 448 } 408 449 } 409 450
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)