Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/02/2024 07:12:25 PM (2 years ago)
Author:
espellcaste
Message:

WPCS: Part VIII: miscellaneous fixes for some of the files of the core component.

Follow-up to [13883], [13886], [13887], [13888], [13891], [13892], [13893]

See #9164 and #7228

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/classes/class-bp-core-oembed-extension.php

    r13878 r13900  
    66 * @subpackage Core
    77 * @since 2.6.0
     8 *
     9 * @phpcs:disable PEAR.NamingConventions.ValidClassName.Invalid
    810 */
    911
     
    5456         *
    5557         * @since 2.6.0
    56          *
    57          * @return null
    5858         */
    5959        abstract protected function content();
     
    128128         * @param int $item_id The item ID to do checks for.
    129129         */
    130         protected function set_iframe_title( $item_id ) {}
     130        protected function set_iframe_title( $item_id ) {} // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
    131131
    132132        /**
     
    145145         *
    146146         * @since 2.6.0
     147         *
     148         * @return string
    147149         */
    148150        protected function set_permalink() {
     
    165167         *
    166168         * @since 2.6.0
     169         *
     170         * @return int
    167171         */
    168172        protected function get_item_id() {
     
    189193         */
    190194        protected function setup_hooks() {
    191                 add_action( 'rest_api_init',    array( $this, 'register_route' ) );
     195                add_action( 'rest_api_init', array( $this, 'register_route' ) );
    192196                add_action( 'bp_embed_content', array( $this, 'inject_content' ) );
    193197
    194198                add_filter( 'embed_template', array( $this, 'setup_template_parts' ) );
    195199                add_filter( 'post_embed_url', array( $this, 'filter_embed_url' ) );
    196                 add_filter( 'embed_html',     array( $this, 'filter_embed_html' ) );
     200                add_filter( 'embed_html', array( $this, 'filter_embed_html' ) );
    197201                add_filter( 'oembed_discovery_links', array( $this, 'add_oembed_discovery_links' ) );
    198202                add_filter( 'rest_pre_serve_request', array( $this, 'oembed_xml_request' ), 20, 4 );
     
    223227                                'default'           => $maxwidth,
    224228                                'sanitize_callback' => 'absint',
     229                        ),
     230                );
     231
     232                // Merge custom arguments here.
     233                $args = $args + (array) $this->set_route_args();
     234
     235                register_rest_route(
     236                        'oembed/1.0',
     237                        "/embed/{$this->slug_endpoint}",
     238                        array(
     239                                array(
     240                                        'methods'             => WP_REST_Server::READABLE,
     241                                        'callback'            => array( $this, 'get_item' ),
     242                                        'permission_callback' => '__return_true',
     243                                        'args'                => $args,
     244                                ),
    225245                        )
    226246                );
    227 
    228                 // Merge custom arguments here.
    229                 $args = $args + (array) $this->set_route_args();
    230 
    231                 register_rest_route( 'oembed/1.0', "/embed/{$this->slug_endpoint}", array(
    232                         array(
    233                                 'methods'             => WP_REST_Server::READABLE,
    234                                 'callback'            => array( $this, 'get_item' ),
    235                                 'permission_callback' => '__return_true',
    236                                 'args'                => $args
    237                         ),
    238                 ) );
    239247        }
    240248
     
    255263                // Set up some BP-specific embed template overrides.
    256264                add_action( 'get_template_part_embed', array( $this, 'content_buffer_start' ), -999, 2 );
    257                 add_action( 'get_footer',              array( $this, 'content_buffer_end' ), -999 );
     265                add_action( 'get_footer', array( $this, 'content_buffer_end' ), -999 );
    258266
    259267                // Return the original WP embed template.
     
    341349                }
    342350
    343                 add_filter( 'rest_url' , array( $this, 'filter_rest_url' ) );
     351                add_filter( 'rest_url', array( $this, 'filter_rest_url' ) );
    344352
    345353                $retval = '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( $permalink ) ) . '" />' . "\n";
     
    349357                }
    350358
    351                 remove_filter( 'rest_url' , array( $this, 'filter_rest_url' ) );
     359                remove_filter( 'rest_url', array( $this, 'filter_rest_url' ) );
    352360
    353361                return $retval;
     
    357365         * Fetch our oEmbed response data to return.
    358366         *
    359          * A simplified version of {@link get_oembed_response_data()}.
     367         * A simplified version of {@see get_oembed_response_data()}.
    360368         *
    361369         * @since 2.6.0
     
    382390
    383391                /** This filter is documented in /wp-includes/embed.php */
    384                 $min_max_width = apply_filters( 'oembed_min_max_width', array(
    385                         'min' => 200,
    386                         'max' => 600
    387                 ) );
     392                $min_max_width = apply_filters(
     393                        'oembed_min_max_width',
     394                        array(
     395                                'min' => 200,
     396                                'max' => 600,
     397                        )
     398                );
    388399
    389400                $width  = min( max( $min_max_width['min'], $width ), $min_max_width['max'] );
     
    396407                if ( 'video' === $data['type'] || 'rich' === $data['type'] ) {
    397408                        // Fake a WP post so we can use get_post_embed_html().
    398                         $post = new stdClass;
     409                        $post               = new stdClass();
    399410                        $post->post_content = $data['content'];
    400411                        $post->post_title   = $data['title'];
     
    430441                        // This is needed for various oEmbed response data filtering.
    431442                        if ( ! isset( buddypress()->{$this->slug_endpoint} ) || ! buddypress()->{$this->slug_endpoint} ) {
    432                                 buddypress()->{$this->slug_endpoint} = new stdClass;
     443                                buddypress()->{$this->slug_endpoint} = new stdClass();
    433444                        }
    434445                        buddypress()->{$this->slug_endpoint}->embedurl_in_progress = $url;
     
    569580                $custom_title = $this->set_iframe_title( $item_id );
    570581                if ( ! empty( $custom_title ) ) {
    571                         $title_pos = strpos( $retval, 'title=' ) + 7;
     582                        $title_pos     = strpos( $retval, 'title=' ) + 7;
    572583                        $title_end_pos = strpos( $retval, '"', $title_pos );
    573584
     
    587598                // @todo Maybe use KSES?
    588599                $fallback_html = $this->set_fallback_html( $item_id );
     600
     601                $embed_html = $fallback_html . $retval;
    589602
    590603                /**
     
    593606                 * @since 2.6.0
    594607                 *
    595                  * @var string $retval
     608                 * @param string $embed_html Current embed HTML.
    596609                 */
    597                 return apply_filters( "bp_{$this->slug_endpoint}_embed_html", $fallback_html . $retval );
     610                return apply_filters( "bp_{$this->slug_endpoint}_embed_html", $embed_html );
    598611        }
    599612
Note: See TracChangeset for help on using the changeset viewer.