Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/27/2021 04:56:32 AM (5 years ago)
Author:
imath
Message:

Improve ways to disable BP RSS feeds

Returning false to the filter bp_activity_enable_feeds is completely disabling all RSS feeds and will now avoid the output of an empty link.

A second argument has been added to the filter to allow to disable a specific feed in particular, one of these feed identifiers:

  • 'sitewide',
  • 'personal',
  • 'friends',
  • 'mygroups',
  • 'mentions',
  • 'favorites'.

The BP Nouveau Template pack has also been improved to update the user's profile activity RSS feed links according to the context.

Props sippis

Fixes #8454

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/classes/class-bp-activity-feed.php

    r10487 r12907  
    8888         */
    8989        public function __construct( $args = array() ) {
    90 
    91                 /**
    92                  * Filters if BuddyPress should consider feeds enabled. If disabled, it will return early.
    93                  *
    94                  * @since 1.8.0
    95                  *
    96                  * @param bool true Default true aka feeds are enabled.
    97                  */
    98                 if ( false === (bool) apply_filters( 'bp_activity_enable_feeds', true ) ) {
     90                $feed_id = '';
     91
     92                if ( isset( $args['id'] ) ) {
     93                        $feed_id = sanitize_key( $args['id'] );
     94                }
     95
     96                if ( false === bp_activity_is_feed_enable( $feed_id ) ) {
    9997                        global $wp_query;
    10098
     
    102100                        $wp_query->is_feed = false;
    103101
    104                         return false;
    105                 }
    106 
    107                 // Setup data.
    108                 $this->data = wp_parse_args( $args, array(
    109                         // Internal identifier for the RSS feed - should be alphanumeric only.
    110                         'id'               => '',
    111 
    112                         // RSS title - should be plain-text.
    113                         'title'            => '',
    114 
    115                         // Relevant link for the RSS feed.
    116                         'link'             => '',
    117 
    118                         // RSS description - should be plain-text.
    119                         'description'      => '',
    120 
    121                         // Time-to-live - number of minutes to cache the data before an aggregator
    122                         // requests it again.  This is only acknowledged if the RSS client supports it
    123                         //
    124                         // See: http://www.rssboard.org/rss-profile#element-channel-ttl.
    125                         // See: http://www.kbcafe.com/rss/rssfeedstate.html#ttl.
    126                         'ttl'              => '30',
    127 
    128                         // Syndication module - similar to ttl, but not really supported by RSS
    129                         // clients
    130                         //
    131                         // See: http://web.resource.org/rss/1.0/modules/syndication/#description.
    132                         // See: http://www.kbcafe.com/rss/rssfeedstate.html#syndicationmodule.
    133                         'update_period'    => 'hourly',
    134                         'update_frequency' => 2,
    135 
    136                         // Number of items to display.
    137                         'max'              => 50,
    138 
    139                         // Activity arguments passed to bp_has_activities().
    140                         'activity_args'    => array()
    141                 ) );
    142 
    143                 /**
    144                  * Fires before the feed is setup so plugins can modify.
    145                  *
    146                  * @since 1.8.0
    147                  *
    148                  * @param BP_Activity_Feed $this Current instance of activity feed. Passed by reference.
    149                  */
    150                 do_action_ref_array( 'bp_activity_feed_prefetch', array( &$this ) );
    151 
    152                 // Setup class properties.
    153                 $this->setup_properties();
    154 
    155                 // Check if id is valid.
    156                 if ( empty( $this->id ) ) {
    157                         _doing_it_wrong( 'BP_Activity_Feed', __( "RSS feed 'id' must be defined", 'buddypress' ), 'BP 1.8' );
    158                         return false;
    159                 }
    160 
    161                 /**
    162                  * Fires after the feed is setup so plugins can modify.
    163                  *
    164                  * @since 1.8.0
    165                  *
    166                  * @param BP_Activity_Feed $this Current instance of activity feed. Passed by reference.
    167                  */
    168                 do_action_ref_array( 'bp_activity_feed_postfetch', array( &$this ) );
    169 
    170                 // Setup feed hooks.
    171                 $this->setup_hooks();
    172 
    173                 // Output the feed.
    174                 $this->output();
    175 
    176                 // Kill the rest of the output.
    177                 die();
     102                        $this->data = array(
     103                                'enabled' => false,
     104                        );
     105                } else {
     106                        // Setup data.
     107                        $this->data = wp_parse_args( $args, array(
     108                                // Internal identifier for the RSS feed - should be alphanumeric only.
     109                                'id'               => '',
     110
     111                                // RSS title - should be plain-text.
     112                                'title'            => '',
     113
     114                                // Relevant link for the RSS feed.
     115                                'link'             => '',
     116
     117                                // RSS description - should be plain-text.
     118                                'description'      => '',
     119
     120                                // Time-to-live - number of minutes to cache the data before an aggregator
     121                                // requests it again.  This is only acknowledged if the RSS client supports it
     122                                //
     123                                // See: http://www.rssboard.org/rss-profile#element-channel-ttl.
     124                                // See: http://www.kbcafe.com/rss/rssfeedstate.html#ttl.
     125                                'ttl'              => '30',
     126
     127                                // Syndication module - similar to ttl, but not really supported by RSS
     128                                // clients
     129                                //
     130                                // See: http://web.resource.org/rss/1.0/modules/syndication/#description.
     131                                // See: http://www.kbcafe.com/rss/rssfeedstate.html#syndicationmodule.
     132                                'update_period'    => 'hourly',
     133                                'update_frequency' => 2,
     134
     135                                // Number of items to display.
     136                                'max'              => 50,
     137
     138                                // Activity arguments passed to bp_has_activities().
     139                                'activity_args'    => array(),
     140
     141                                // The activity feed is enabled.
     142                                'enabled'          => false,
     143                        ) );
     144
     145                        /**
     146                         * Fires before the feed is setup so plugins can modify.
     147                         *
     148                         * @since 1.8.0
     149                         *
     150                         * @param BP_Activity_Feed $this Current instance of activity feed. Passed by reference.
     151                         */
     152                        do_action_ref_array( 'bp_activity_feed_prefetch', array( &$this ) );
     153
     154                        // Setup class properties.
     155                        $this->setup_properties();
     156
     157                        // Check if id is valid.
     158                        if ( empty( $this->id ) ) {
     159                                _doing_it_wrong( 'BP_Activity_Feed', __( "RSS feed 'id' must be defined", 'buddypress' ), 'BP 1.8' );
     160                                return false;
     161                        }
     162
     163                        /**
     164                         * Fires after the feed is setup so plugins can modify.
     165                         *
     166                         * @since 1.8.0
     167                         *
     168                         * @param BP_Activity_Feed $this Current instance of activity feed. Passed by reference.
     169                         */
     170                        do_action_ref_array( 'bp_activity_feed_postfetch', array( &$this ) );
     171
     172                        // Setup feed hooks.
     173                        $this->setup_hooks();
     174
     175                        // Output the feed.
     176                        $this->output();
     177
     178                        // Kill the rest of the output.
     179                        die();
     180                }
    178181        }
    179182
Note: See TracChangeset for help on using the changeset viewer.