| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * bbPress Common AJAX Functions. | |
| 4 | + * bbPress Common AJAX Functions | |
| 5 | 5 | * |
| 6 | 6 | * Common AJAX functions are ones that are used to setup and/or use during |
| 7 | 7 | * bbPress specific, theme-side AJAX requests. |
| 8 | 8 | * |
| @@ -13,9 +13,9 @@ | ||
| 13 | 13 | // Exit if accessed directly |
| 14 | 14 | defined( 'ABSPATH' ) || exit; |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * Output the URL to use for theme-side bbPress AJAX requests. | |
| 17 | + * Output the URL to use for theme-side bbPress AJAX requests | |
| 18 | 18 | * |
| 19 | 19 | * @since 2.3.0 bbPress (r4543) |
| 20 | 20 | */ |
| 21 | 21 | function bbp_ajax_url() { |
| @@ -20,42 +20,34 @@ | ||
| 20 | 20 | */ |
| 21 | 21 | function bbp_ajax_url() { |
| 22 | 22 | echo esc_url( bbp_get_ajax_url() ); |
| 23 | 23 | } |
| 24 | - | |
| 25 | -/** | |
| 26 | - * Return the URL to use for theme-side bbPress AJAX requests. | |
| 27 | - * | |
| 28 | - * @since 2.3.0 bbPress (r4543) | |
| 29 | - * | |
| 30 | - * @global WP $wp | |
| 31 | - * @return string | |
| 32 | - */ | |
| 33 | -function bbp_get_ajax_url() { | |
| 34 | - global $wp; | |
| 35 | - | |
| 36 | - $ssl = bbp_get_url_scheme(); | |
| 37 | - $url = trailingslashit( $wp->request ); | |
| 38 | - $base_url = home_url( $url, $ssl ); | |
| 39 | - $ajaxurl = add_query_arg( array( 'bbp-ajax' => 'true' ), $base_url ); | |
| 40 | - | |
| 41 | 24 | /** |
| 42 | - * Filters the URL used for theme-side bbPress AJAX requests. | |
| 25 | + * Return the URL to use for theme-side bbPress AJAX requests | |
| 43 | 26 | * |
| 44 | 27 | * @since 2.3.0 bbPress (r4543) |
| 45 | 28 | * |
| 46 | - * @param string $ajaxurl The URL for bbPress AJAX requests. | |
| 47 | - * @return string The filtered URL for bbPress AJAX requests. | |
| 29 | + * @global WP $wp | |
| 30 | + * @return string | |
| 48 | 31 | */ |
| 49 | - return apply_filters( 'bbp_get_ajax_url', $ajaxurl ); | |
| 50 | -} | |
| 32 | + function bbp_get_ajax_url() { | |
| 33 | + global $wp; | |
| 51 | 34 | |
| 35 | + $ssl = bbp_get_url_scheme(); | |
| 36 | + $url = trailingslashit( $wp->request ); | |
| 37 | + $base_url = home_url( $url, $ssl ); | |
| 38 | + $ajaxurl = add_query_arg( array( 'bbp-ajax' => 'true' ), $base_url ); | |
| 39 | + | |
| 40 | + // Filter & return | |
| 41 | + return apply_filters( 'bbp_get_ajax_url', $ajaxurl ); | |
| 42 | + } | |
| 43 | + | |
| 52 | 44 | /** |
| 53 | 45 | * Is this a bbPress AJAX request? |
| 54 | 46 | * |
| 55 | 47 | * @since 2.3.0 bbPress (r4543) |
| 56 | 48 | * |
| 57 | - * @return bool Looking for bbp-ajax. | |
| 49 | + * @return bool Looking for bbp-ajax | |
| 58 | 50 | */ |
| 59 | 51 | function bbp_is_ajax() { |
| 60 | 52 | return (bool) ( ( isset( $_GET['bbp-ajax'] ) || isset( $_POST['bbp-ajax'] ) ) && ! empty( $_REQUEST['action'] ) ); |
| 61 | 53 | } |
| @@ -68,11 +60,11 @@ | ||
| 68 | 60 | * theme-side bbPress-only AJAX requests. |
| 69 | 61 | * |
| 70 | 62 | * @since 2.3.0 bbPress (r4543) |
| 71 | 63 | * |
| 72 | - * @param string $action Sanitized action from bbp_post_request/bbp_get_request. | |
| 64 | + * @param string $action Sanitized action from bbp_post_request/bbp_get_request | |
| 73 | 65 | * |
| 74 | - * @return If not a bbPress AJAX request. | |
| 66 | + * @return If not a bbPress AJAX request | |
| 75 | 67 | */ |
| 76 | 68 | function bbp_do_ajax( $action = '' ) { |
| 77 | 69 | |
| 78 | 70 | // Bail if not a bbPress specific AJAX request |
| @@ -111,9 +103,9 @@ | ||
| 111 | 103 | wp_die( '0' ); |
| 112 | 104 | } |
| 113 | 105 | |
| 114 | 106 | /** |
| 115 | - * Send headers for AJAX specific requests. | |
| 107 | + * Send headers for AJAX specific requests | |
| 116 | 108 | * |
| 117 | 109 | * This was abstracted from bbp_do_ajax() for use in custom theme-side AJAX |
| 118 | 110 | * implementations. |
| 119 | 111 | * |
| @@ -121,10 +113,10 @@ | ||
| 121 | 113 | */ |
| 122 | 114 | function bbp_ajax_headers() { |
| 123 | 115 | |
| 124 | 116 | // Set the header content type |
| 125 | - header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) ); | |
| 126 | - header( 'X-Robots-Tag: noindex' ); | |
| 117 | + @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) ); | |
| 118 | + @header( 'X-Robots-Tag: noindex' ); | |
| 127 | 119 | |
| 128 | 120 | // Disable content sniffing in browsers that support it |
| 129 | 121 | send_nosniff_header(); |
| 130 | 122 | |
| @@ -132,9 +124,9 @@ | ||
| 132 | 124 | nocache_headers(); |
| 133 | 125 | } |
| 134 | 126 | |
| 135 | 127 | /** |
| 136 | - * Helper method to return JSON response for bbPress AJAX calls. | |
| 128 | + * Helper method to return JSON response for bbPress AJAX calls | |
| 137 | 129 | * |
| 138 | 130 | * @since 2.3.0 bbPress (r4542) |
| 139 | 131 | * |
| 140 | 132 | * @param bool $success |
| @@ -160,8 +152,8 @@ | ||
| 160 | 152 | $response = array_merge( $response, $extras ); |
| 161 | 153 | } |
| 162 | 154 | |
| 163 | 155 | // Send back the JSON |
| 164 | - header( 'Content-type: application/json' ); | |
| 156 | + @header( 'Content-type: application/json' ); | |
| 165 | 157 | echo json_encode( $response ); |
| 166 | 158 | die(); |
| 167 | 159 | } |