Changeset 12892 for sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php
- Timestamp:
- 09/17/2023 06:18:29 PM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php
r12012 r12892 7 7 public function __construct() { 8 8 // Add custom fields to user's profile. 9 add_action( 'bbp_user_edit_after_name', array( $this, 'add_custom_title_input' ) );10 add_action( 'bbp_user_edit_after', array( $this, 'add_options_section_header' ), 0 );11 add_action( 'bbp_user_edit_after', array( $this, 'add_auto_topic_subscription_checkbox' ) );9 add_action( 'bbp_user_edit_after_name', array( $this, 'add_custom_title_input' ) ); 10 add_action( 'bbp_user_edit_after', array( $this, 'add_options_section_header' ), 0 ); 11 add_action( 'bbp_user_edit_after', array( $this, 'add_auto_topic_subscription_checkbox' ) ); 12 12 13 13 // Save custom field values. 14 add_action( 'personal_options_update', array( $this, 'save_custom_fields' ), 10, 2 );15 add_action( 'edit_user_profile_update', array( $this, 'save_custom_fields' ), 10, 2 );14 add_action( 'personal_options_update', array( $this, 'save_custom_fields' ), 10, 2 ); 15 add_action( 'edit_user_profile_update', array( $this, 'save_custom_fields' ), 10, 2 ); 16 16 17 17 // Adjust display of user fields 18 add_filter( 'bbp_get_displayed_user_field', array( $this, 'modify_user_fields' ), 10, 3 );18 add_filter( 'bbp_get_displayed_user_field', array( $this, 'modify_user_fields' ), 10, 3 ); 19 19 20 20 // Custom user contact methods. 21 add_filter( 'user_contactmethods', array( $this, 'custom_contact_methods' ) );21 add_filter( 'user_contactmethods', array( $this, 'custom_contact_methods' ) ); 22 22 23 23 // Add "My Account" submenu items to admin bar for quick access. 24 add_action( 'admin_bar_menu', array( $this, 'add_my_account_submenu_items' ) );24 add_action( 'admin_bar_menu', array( $this, 'add_my_account_submenu_items' ) ); 25 25 26 26 // Only allow 3 published topics from a user in the first 24 hours. 27 add_action( 'bbp_new_topic_pre_insert', array( $this, 'limit_new_user_topics' ) );27 add_action( 'bbp_new_topic_pre_insert', array( $this, 'limit_new_user_topics' ) ); 28 28 29 29 // Add query vars and rewrite rules for user's topic and review queries. 30 add_filter( 'query_vars', array( $this, 'add_query_vars' ) );31 add_action( 'bbp_add_rewrite_rules', array( $this, 'add_rewrite_rules' ) );30 add_filter( 'query_vars', array( $this, 'add_query_vars' ) ); 31 add_action( 'bbp_add_rewrite_rules', array( $this, 'add_rewrite_rules' ) ); 32 32 33 33 // Don't allow attempting to set an email to one that is banned-from-use on WordPress.org. 34 add_action( 'bbp_post_request', array( $this, 'check_email_safe_for_use' ), 0 ); // bbPress is at 134 add_action( 'bbp_post_request', array( $this, 'check_email_safe_for_use' ), 0 ); // bbPress is at 1 35 35 36 36 // Parse user's topic and review queries. 37 add_action( 'parse_query', array( $this, 'parse_user_topics_query' ) ); 38 add_filter( 'posts_groupby', array( $this, 'parse_user_topics_posts_groupby' ), 10, 2 ); 39 add_filter( 'bbp_after_has_topics_parse_args', array( $this, 'parse_user_topics_query_args' ) ); 40 add_filter( 'bbp_topic_pagination', array( $this, 'parse_user_topics_pagination_args' ) ); 41 add_filter( 'bbp_replies_pagination', array( $this, 'parse_user_topics_pagination_args' ) ); 42 add_filter( 'bbp_before_title_parse_args', array( $this, 'parse_user_topics_title_args' ) ); 37 add_action( 'parse_query', array( $this, 'parse_user_topics_query' ) ); 38 add_filter( 'posts_groupby', array( $this, 'parse_user_topics_posts_groupby' ), 10, 2 ); 39 add_filter( 'bbp_after_has_topics_parse_args', array( $this, 'parse_user_topics_query_args' ) ); 40 add_filter( 'bbp_after_has_replies_parse_args', array( $this, 'parse_user_replies_query_args' ) ); 41 add_filter( 'bbp_topic_pagination', array( $this, 'parse_user_topics_pagination_args' ) ); 42 add_filter( 'bbp_replies_pagination', array( $this, 'parse_user_topics_pagination_args' ) ); 43 add_filter( 'bbp_before_title_parse_args', array( $this, 'parse_user_topics_title_args' ) ); 43 44 44 45 // Clear user's topics and reviews count cache. 45 add_action( 'bbp_new_topic', array( $this, 'clear_user_topics_count_cache' ) );46 add_action( 'bbp_spammed_topic', array( $this, 'clear_user_topics_count_cache' ) );47 add_action( 'bbp_unspammed_topic', array( $this, 'clear_user_topics_count_cache' ) );48 add_action( 'bbp_approved_topic', array( $this, 'clear_user_topics_count_cache' ) );49 add_action( 'bbp_unapproved_topic', array( $this, 'clear_user_topics_count_cache' ) );50 add_action( 'wporg_bbp_archived_topic', array( $this, 'clear_user_topics_count_cache' ) );51 add_action( 'wporg_bbp_unarchived_topic', array( $this, 'clear_user_topics_count_cache' ) );46 add_action( 'bbp_new_topic', array( $this, 'clear_user_topics_count_cache' ) ); 47 add_action( 'bbp_spammed_topic', array( $this, 'clear_user_topics_count_cache' ) ); 48 add_action( 'bbp_unspammed_topic', array( $this, 'clear_user_topics_count_cache' ) ); 49 add_action( 'bbp_approved_topic', array( $this, 'clear_user_topics_count_cache' ) ); 50 add_action( 'bbp_unapproved_topic', array( $this, 'clear_user_topics_count_cache' ) ); 51 add_action( 'wporg_bbp_archived_topic', array( $this, 'clear_user_topics_count_cache' ) ); 52 add_action( 'wporg_bbp_unarchived_topic', array( $this, 'clear_user_topics_count_cache' ) ); 52 53 } 53 54 … … 76 77 return; 77 78 } 78 79 79 80 $title = get_user_option( 'title', bbp_get_displayed_user_id() ); 80 81 ?> 81 82 83 84 82 <div> 83 <label for="title"><?php esc_html_e( 'Custom Title', 'wporg-forums' ); ?></label> 84 <input type="text" name="title" id="title" value="<?php echo esc_attr( $title ); ?>" class="regular-text" /> 85 </div> 85 86 <?php 86 87 } … … 102 103 $auto_topic_subscription = get_user_option( 'auto_topic_subscription', bbp_get_displayed_user_id() ); 103 104 ?> 104 105 106 107 105 <p> 106 <input name="auto_topic_subscription" id="auto_topic_subscription" type="checkbox" value="yes" <?php checked( $auto_topic_subscription ); ?> /> 107 <label for="auto_topic_subscription"><?php esc_html_e( 'Always notify me via email of follow-up posts in any topics I reply to', 'wporg-forums' ); ?></label> 108 </p> 108 109 <?php 109 110 } … … 132 133 } 133 134 return $value; 134 } 135 } 135 136 136 137 /** … … 257 258 258 259 /** 259 * Add query vars for user's "Reviews Written" and "Topics Replied To" views. 260 * Add query vars for user's "Reviews Written", 261 * "Topics Replied To", and "Reports Submitted" views. 260 262 * 261 263 * @param array $query_vars Query vars. … … 265 267 $query_vars[] = 'wporg_single_user_reviews'; 266 268 $query_vars[] = 'wporg_single_user_topics_replied_to'; 269 $query_vars[] = 'wporg_single_user_reported_topics'; 267 270 return $query_vars; 268 271 } 269 272 270 273 /** 271 * Add rewrite rules for user's "Reviews Written" and "Topics Replied To" views. 274 * Add rewrite rules for user's "Reviews Written", 275 * "Topics Replied To", and "Reports Submitted" views. 272 276 */ 273 277 public function add_rewrite_rules() { … … 276 280 $user_reviews_rule = bbp_get_user_slug() . '/([^/]+)/reviews/'; 277 281 $user_topics_replied_to_rule = bbp_get_user_slug() . '/([^/]+)/replied-to/'; 282 $user_reports_submitted = bbp_get_user_slug() . '/([^/]+)/reports/'; 278 283 279 284 $feed_id = 'feed'; … … 297 302 add_rewrite_rule( $user_topics_replied_to_rule . $paged_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_topics_replied_to=1&' . $paged_id . '=$matches[2]', $priority ); 298 303 add_rewrite_rule( $user_topics_replied_to_rule . $feed_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_topics_replied_to=1&' . $feed_id . '=$matches[2]', $priority ); 304 305 // Add users "Reports Submitted" page rewrite rules. 306 add_rewrite_rule( $user_reports_submitted . $base_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reported_topics=1', $priority ); 307 add_rewrite_rule( $user_reports_submitted . $paged_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reported_topics=1&' . $paged_id . '=$matches[2]', $priority ); 308 add_rewrite_rule( $user_reports_submitted . $feed_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reported_topics=1&' . $feed_id . '=$matches[2]', $priority ); 299 309 } 300 310 301 311 /** 302 312 * Verify that the a new email is valid for use. 303 * 313 * 304 314 * @param string $action The current action. 305 315 */ … … 332 342 333 343 /** 334 * Set WP_Query::bbp_is_single_user_profile to false on user's "Reviews Written" 335 * and "Topics Replied To" views.344 * Set WP_Query::bbp_is_single_user_profile to false on user's "Reviews Written", 345 * "Topics Replied To", and "Reports Submitted" views. 336 346 * 337 347 * @param WP_Query $query Current query object. … … 340 350 if ( 341 351 get_query_var( 'wporg_single_user_reviews' ) 342 ||352 || 343 353 get_query_var( 'wporg_single_user_topics_replied_to' ) 354 || 355 get_query_var( 'wporg_single_user_reported_topics' ) 344 356 ) { 345 357 $query->bbp_is_single_user_profile = false; … … 386 398 387 399 /** 388 * Set 'base' argument for pagination links on user's "Reviews Written" 389 * and "Topics Replied To" views. 400 * Set the arguments for user's "Reports Submitted" query. 401 * 402 * @param array $args WO_Query arguments. 403 * @return array Filtered query arguments. 404 */ 405 public function parse_user_replies_query_args( $args ) { 406 if ( get_query_var( 'wporg_single_user_reported_topics' ) ) { 407 $args['post_type'] = 'reported_topics'; 408 unset( $args['meta_key'] ); 409 unset( $args['meta_type'] ); 410 } 411 412 return $args; 413 } 414 415 /** 416 * Set 'base' argument for pagination links on user's "Reviews Written", 417 * "Topics Replied To", and "Reports Submitted" views. 390 418 * 391 419 * @param array $args Pagination arguments. … … 403 431 } 404 432 433 if ( get_query_var( 'wporg_single_user_reported_topics' ) ) { 434 $args['base'] = bbp_get_user_profile_url( bbp_get_displayed_user_id() ) . 'reports/'; 435 $args['base'] .= bbp_get_paged_slug() . '/%#%/'; 436 } 437 405 438 return $args; 406 439 } 407 440 408 441 /** 409 * Set title for user's "Reviews Written" and "Topics Replied To" views.442 * Set title for user's "Reviews Written", "Topics Replied To", and "Reports Submitted" views. 410 443 * 411 444 * @param array $title Title parts. … … 430 463 /* translators: user's display name */ 431 464 $title['format'] = __( 'Topics %s Has Replied To', 'wporg-forums' ); 465 } 466 } 467 468 if ( get_query_var( 'wporg_single_user_reported_topics' ) ) { 469 if ( bbp_is_user_home() ) { 470 $title['text'] = __( "Reports You've Submitted", 'wporg-forums' ); 471 } elseif ( bbp_get_user_id() ) { 472 $title['text'] = get_userdata( bbp_get_user_id() )->display_name; 473 /* translators: user's display name */ 474 $title['format'] = __( 'Reports %s Has Submitted', 'wporg-forums' ); 432 475 } 433 476 } … … 476 519 477 520 /** 521 * Return the raw database count of reports by a user. 522 * 523 * @global wpdb $wpdb WordPress database abstraction object. 524 * 525 * @param int $user_id User ID to get count for. 526 * @return int Raw DB count of reports. 527 */ 528 public function get_user_report_count( $user_id = 0 ) { 529 global $wpdb; 530 531 $user_id = bbp_get_user_id( $user_id ); 532 if ( empty( $user_id ) ) { 533 return 0; 534 } 535 536 if ( ! class_exists( 'WordPressdotorg\Forums\Plugin' ) ) { 537 return 0; 538 } 539 540 // Check cache. 541 $count = wp_cache_get( $user_id, 'user-report-count' ); 542 if ( false === $count ) { 543 $count = (int) $wpdb->get_var( $wpdb->prepare( 544 "SELECT COUNT(*) 545 FROM {$wpdb->posts} 546 WHERE post_type = 'reported_topics' 547 AND post_status IN ( 'publish', 'closed' ) 548 AND post_author = %d", 549 $user_id 550 ) ); 551 wp_cache_set( $user_id, $count, 'user-report-count' ); 552 } 553 554 return $count; 555 } 556 557 /** 478 558 * Return the raw database count of reviews by a user. 479 559 * … … 521 601 public function clear_user_topics_count_cache( $topic_id ) { 522 602 $post = get_post( $topic_id ); 523 603 524 604 if ( Plugin::REVIEWS_FORUM_ID != $post->post_parent ) { 525 605 wp_cache_delete( $post->post_author, 'user-topics-count' );
Note: See TracChangeset
for help on using the changeset viewer.