Changeset 5757
- Timestamp:
- 08/06/2017 09:31:29 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php
r5737 r5757 4 4 5 5 class Hooks { 6 7 const SITE_URL_META = 'site_url'; 6 8 7 9 public function __construct() { … … 40 42 // Limit no-replies view to a certain number of days and hide resolved topics. 41 43 add_filter( 'bbp_register_view_no_replies', array( $this, 'limit_no_replies_view' ) ); 44 45 // Display extra topic fields after content. 46 add_action( 'bbp_theme_after_topic_content', array( $this, 'display_extra_topic_fields' ) ); 47 48 // Add extra topic fields after Title field in topic form. 49 add_action( 'bbp_theme_after_topic_form_title', array( $this, 'add_extra_topic_fields' ) ); 50 51 // Process extra topic fields. 52 add_action( 'bbp_new_topic', array( $this, 'handle_extra_topic_fields' ), 10, 2 ); 53 add_action( 'bbp_edit_topic', array( $this, 'handle_extra_topic_fields' ), 10, 2 ); 42 54 43 55 // Add extra reply actions before Submit button in reply form. … … 362 374 363 375 /** 376 * Display extra topic fields after content. 377 */ 378 public function display_extra_topic_fields() { 379 // Display site URL for logged-in users. 380 if ( is_user_logged_in() ) { 381 $site_url = get_post_meta( bbp_get_topic_id(), self::SITE_URL_META, true ); 382 383 printf( '<p>%1$s <a href="%2$s" rel="nofollow">%2$s</a></p>', 384 __( 'Site URL:', 'wporg-forums' ), 385 esc_url( $site_url ) 386 ); 387 } 388 } 389 390 /** 391 * Add extra topic fields after Title field in topic form. 392 */ 393 public function add_extra_topic_fields() { 394 $site_url = ( bbp_is_topic_edit() ) ? get_post_meta( bbp_get_topic_id(), self::SITE_URL_META, true ) : ''; 395 ?> 396 <p> 397 <label for="site_url"><?php _e( 'URL of the site or page you need help with:', 'wporg-forums' ) ?></label><br /> 398 <input type="text" id="site_url" value="<?php echo esc_attr( $site_url ); ?>" size="40" name="site_url" maxlength="100" /> 399 </p> 400 <?php 401 } 402 403 /** 404 * Process extra topic fields. 405 * 406 * @param int $topic_id Topic ID. 407 */ 408 public function handle_extra_topic_fields( $topic_id ) { 409 // Handle "URL of the site or page you need help with" field. 410 if ( isset( $_POST['site_url'] ) ) { 411 $site_url = esc_url_raw( apply_filters( 'pre_user_url', $_POST['site_url'] ) ); 412 413 $protocols = implode( '|', array( 'http', 'https' ) ); 414 if ( ! preg_match( '/^(' . $protocols . '):/is', $site_url ) ) { 415 $site_url = 'http://' . $site_url; 416 } 417 418 update_post_meta( $topic_id, self::SITE_URL_META, $site_url ); 419 } 420 } 421 422 /** 364 423 * Add extra reply actions before Submit button in reply form. 365 424 */ … … 401 460 */ 402 461 public function handle_extra_reply_actions( $reply_id, $topic_id ) { 403 // Handle "Reply and mark as resolved" checkbox 462 // Handle "Reply and mark as resolved" checkbox. 404 463 if ( isset( $_POST['bbp_reply_mark_resolved'] ) && 'yes' === $_POST['bbp_reply_mark_resolved'] ) { 405 464 if ( class_exists( 'WordPressdotorg\Forums\Topic_Resolution\Plugin' ) ) { … … 418 477 } 419 478 420 // Handle "Reply and close the topic" checkbox 479 // Handle "Reply and close the topic" checkbox. 421 480 if ( isset( $_POST['bbp_reply_close_topic'] ) && 'yes' === $_POST['bbp_reply_close_topic'] ) { 422 481 if ( current_user_can( 'moderate', $topic_id ) && bbp_is_topic_open( $topic_id ) ) {
Note: See TracChangeset
for help on using the changeset viewer.