Skip to:
Content

BuddyPress.org

Changeset 10152


Ignore:
Timestamp:
09/29/2015 10:03:53 PM (5 years ago)
Author:
imath
Message:

Allow Administrators to disable/enable the Cover Image Feature from the BuddyPress settings (Administration screen)

  • Create two new options for targeted components (xProfile & Groups)
  • Generate two new setting fields into the components setting sections as soon as the feature is active. By default, the two new checkboxes are enabled.
  • Introduce two new functions to check if the Administrator disallowed cover image uploads for Users (bp_disable_cover_image_uploads()) and Groups (bp_disable_group_cover_image_uploads()).
  • Edit the bp_is_active() function to take in account the particularity of the xProfile component. See below for a detailled explanation.
  • Introduce a new conditional tag to check if the current page is the profile "change-cover-image" screen.

The bp_is_active() function first checks into the "bp-active-components" database option to see if the component is active. In this option the xProfile component is keyed "xprofile". But the component global holding the extended BP_Component class is keyed "profile" and features are inside a property of this component global. So to be able to check if a feature attached to the xProfile component is active, we needed to edit this function changing the component key from "xprofile" to "profile". As a result, the xProfile filter to deactivate/activate the cover image is bp_is_profile_cover_image_active. For the Groups component, the filter is bp_is_groups_cover_image_active.

Props mercime, r-a-y

See #6570

Location:
trunk/src/bp-core
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/admin/bp-core-admin-settings.php

    r10108 r10152  
    160160}
    161161
     162/**
     163 * Allow members to upload cover images field.
     164 *
     165 * @since 2.4.0
     166 */
     167function bp_admin_setting_callback_cover_image_uploads() {
     168?>
     169    <input id="bp-disable-cover-image-uploads" name="bp-disable-cover-image-uploads" type="checkbox" value="1" <?php checked( ! bp_disable_cover_image_uploads() ); ?> />
     170    <label for="bp-disable-cover-image-uploads"><?php _e( 'Allow registered members to upload cover images', 'buddypress' ); ?></label>
     171<?php
     172}
     173
    162174/** Groups Section ************************************************************/
    163175
     
    195207    <input id="bp-disable-group-avatar-uploads" name="bp-disable-group-avatar-uploads" type="checkbox" value="1" <?php checked( ! bp_disable_group_avatar_uploads() ); ?> />
    196208    <label for="bp-disable-group-avatar-uploads"><?php _e( 'Allow customizable avatars for groups', 'buddypress' ); ?></label>
     209<?php
     210}
     211
     212/**
     213 * 'Enable group cover images' field markup.
     214 *
     215 * @since 2.4.0
     216 */
     217function bp_admin_setting_callback_group_cover_image_uploads() {
     218?>
     219    <input id="bp-disable-group-cover-image-uploads" name="bp-disable-group-cover-image-uploads" type="checkbox" value="1" <?php checked( ! bp_disable_group_cover_image_uploads() ); ?> />
     220    <label for="bp-disable-group-cover-image-uploads"><?php _e( 'Allow customizable cover images for groups', 'buddypress' ); ?></label>
    197221<?php
    198222}
     
    300324            'bp-disable-account-deletion',
    301325            'bp-disable-avatar-uploads',
     326            'bp-disable-cover-image-uploads',
    302327            'bp-disable-group-avatar-uploads',
     328            'bp-disable-group-cover-image-uploads',
    303329            'bp_disable_blogforum_comments',
    304330            'bp-disable-profile-sync',
  • trunk/src/bp-core/bp-core-admin.php

    r10108 r10152  
    339339            add_settings_section( 'bp_xprofile', _x( 'Profile Settings', 'BuddyPress setting tab', 'buddypress' ), 'bp_admin_setting_callback_xprofile_section', 'buddypress' );
    340340
     341            // Avatars
    341342            add_settings_field( 'bp-disable-avatar-uploads', __( 'Profile Photo Uploads', 'buddypress' ), 'bp_admin_setting_callback_avatar_uploads', 'buddypress', 'bp_xprofile' );
    342343            register_setting( 'buddypress', 'bp-disable-avatar-uploads', 'intval' );
     344
     345            // Cover images
     346            if ( bp_is_active( 'xprofile', 'cover_image' ) ) {
     347                add_settings_field( 'bp-disable-cover-image-uploads', __( 'Cover Image Uploads', 'buddypress' ), 'bp_admin_setting_callback_cover_image_uploads', 'buddypress', 'bp_xprofile' );
     348                register_setting( 'buddypress', 'bp-disable-cover-image-uploads', 'intval' );
     349            }
    343350
    344351            // Profile sync setting
     
    361368            add_settings_field( 'bp-disable-group-avatar-uploads', __( 'Group Photo Uploads', 'buddypress' ), 'bp_admin_setting_callback_group_avatar_uploads', 'buddypress', 'bp_groups' );
    362369            register_setting( 'buddypress', 'bp-disable-group-avatar-uploads', 'intval' );
     370
     371            // Allow group cover images.
     372            if ( bp_is_active( 'groups', 'cover_image' ) ) {
     373                add_settings_field( 'bp-disable-group-cover-image-uploads', __( 'Group Cover Image Uploads', 'buddypress' ), 'bp_admin_setting_callback_group_cover_image_uploads', 'buddypress', 'bp_groups' );
     374                register_setting( 'buddypress', 'bp-disable-group-cover-image-uploads', 'intval' );
     375            }
    363376        }
    364377
  • trunk/src/bp-core/bp-core-options.php

    r10108 r10152  
    2424        /** Components ********************************************************/
    2525
    26         'bp-deactivated-components'       => array(),
     26        'bp-deactivated-components'            => array(),
    2727
    2828        /** bbPress ***********************************************************/
    2929
    3030        // Legacy bbPress config location
    31         'bb-config-location'              => ABSPATH . 'bb-config.php',
     31        'bb-config-location'                   => ABSPATH . 'bb-config.php',
    3232
    3333        /** XProfile **********************************************************/
    3434
    3535        // Base profile groups name
    36         'bp-xprofile-base-group-name'     => 'Base',
     36        'bp-xprofile-base-group-name'          => 'Base',
    3737
    3838        // Base fullname field name
    39         'bp-xprofile-fullname-field-name' => 'Name',
     39        'bp-xprofile-fullname-field-name'      => 'Name',
    4040
    4141        /** Blogs *************************************************************/
    4242
    4343        // Used to decide if blogs need indexing
    44         'bp-blogs-first-install'          => false,
     44        'bp-blogs-first-install'               => false,
    4545
    4646        /** Settings **********************************************************/
    4747
    4848        // Disable the WP to BP profile sync
    49         'bp-disable-profile-sync'         => false,
     49        'bp-disable-profile-sync'              => false,
    5050
    5151        // Hide the Toolbar for logged out users
    52         'hide-loggedout-adminbar'         => false,
     52        'hide-loggedout-adminbar'              => false,
    5353
    5454        // Avatar uploads
    55         'bp-disable-avatar-uploads'       => false,
     55        'bp-disable-avatar-uploads'            => false,
     56
     57        // Cover image uploads
     58        'bp-disable-cover-image-uploads'       => false,
    5659
    5760        // Group Profile Photos
    58         'bp-disable-group-avatar-uploads' => false,
     61        'bp-disable-group-avatar-uploads'      => false,
     62
     63        // Group Cover image uploads
     64        'bp-disable-group-cover-image-uploads' => false,
    5965
    6066        // Allow users to delete their own accounts
    61         'bp-disable-account-deletion'     => false,
     67        'bp-disable-account-deletion'          => false,
    6268
    6369        // Allow comments on blog and forum activity items
    64         'bp-disable-blogforum-comments'   => true,
     70        'bp-disable-blogforum-comments'        => true,
    6571
    6672        // The ID for the current theme package.
    67         '_bp_theme_package_id'            => 'legacy',
     73        '_bp_theme_package_id'                 => 'legacy',
    6874
    6975        /** Groups ************************************************************/
     
    7278
    7379        // Restrict group creation to super admins
    74         'bp_restrict_group_creation'      => false,
     80        'bp_restrict_group_creation'           => false,
    7581
    7682        /** Akismet ***********************************************************/
    7783
    7884        // Users from all sites can post
    79         '_bp_enable_akismet'              => true,
     85        '_bp_enable_akismet'                   => true,
    8086
    8187        /** Activity HeartBeat ************************************************/
    8288
    8389        // HeartBeat is on to refresh activities
    84         '_bp_enable_heartbeat_refresh'    => true,
     90        '_bp_enable_heartbeat_refresh'         => true,
    8591
    8692        /** BuddyBar **********************************************************/
    8793
    8894        // Force the BuddyBar
    89         '_bp_force_buddybar'              => false,
     95        '_bp_force_buddybar'                   => false,
    9096
    9197        /** Legacy theme *********************************************/
    9298
    9399        // Whether to register the bp-default themes directory
    94         '_bp_retain_bp_default'           => false,
     100        '_bp_retain_bp_default'                => false,
    95101
    96102        /** Widgets **************************************************/
     
    597603
    598604/**
     605 * Are members able to upload their own cover images?
     606 *
     607 * @since 2.4.0
     608 *
     609 * @uses bp_get_option() To get the cover image uploads option.
     610 *
     611 * @param bool $default Optional. Fallback value if not found in the database.
     612 *                      Default: false.
     613 *
     614 * @return bool True if cover image uploads are disabled, otherwise false.
     615 */
     616function bp_disable_cover_image_uploads( $default = false ) {
     617
     618    /**
     619     * Filters whether or not members are able to upload their own cover images.
     620     *
     621     * @since 2.4.0
     622     *
     623     * @param bool $value Whether or not members are able to upload their own cover images.
     624     */
     625    return (bool) apply_filters( 'bp_disable_cover_image_uploads', (bool) bp_get_option( 'bp-disable-cover-image-uploads', $default ) );
     626}
     627
     628/**
    599629 * Are group avatars disabled?
    600630 *
     
    629659     */
    630660    return (bool) apply_filters( 'bp_disable_group_avatar_uploads', $disabled, $default );
     661}
     662
     663/**
     664 * Are group cover images disabled?
     665 *
     666 * @since 2.4.0
     667 *
     668 * @uses bp_get_option() To get the group cover image uploads option.
     669 *
     670 * @param bool $default Optional. Fallback value if not found in the database.
     671 *                      Default: false.
     672 *
     673 * @return bool True if group cover image uploads are disabled, otherwise false.
     674 */
     675function bp_disable_group_cover_image_uploads( $default = false ) {
     676
     677    /**
     678     * Filters whether or not members are able to upload group cover images.
     679     *
     680     * @since 2.4.0
     681     *
     682     * @param bool $value Whether or not members are able to upload thier groups cover images.
     683     */
     684    return (bool) apply_filters( 'bp_disable_group_cover_image_uploads', (bool) bp_get_option( 'bp-disable-group-cover-image-uploads', $default ) );
    631685}
    632686
  • trunk/src/bp-core/bp-core-template.php

    r10109 r10152  
    19351935        // Is feature active?
    19361936        if ( ! empty( $feature ) ) {
     1937            // The xProfile component is specific
     1938            if ( 'xprofile' === $component ) {
     1939                $component = 'profile';
     1940            }
     1941
    19371942            if ( empty( buddypress()->$component->features ) || false === in_array( $feature, buddypress()->$component->features, true ) ) {
    19381943                $retval = false;
     
    22452250function bp_is_user_change_avatar() {
    22462251    return (bool) ( bp_is_profile_component() && bp_is_current_action( 'change-avatar' ) );
     2252}
     2253
     2254/**
     2255 * Is the current page the a user's change cover image profile page?
     2256 *
     2257 * Eg http://example.com/members/joe/profile/change-cover-image/ (or a subpage thereof).
     2258 *
     2259 * @since  2.4.0
     2260 *
     2261 * @return True if the current page is a user's profile edit cover image page.
     2262 */
     2263function bp_is_user_change_cover_image() {
     2264    return (bool) ( bp_is_profile_component() && bp_is_current_action( 'change-cover-image' ) );
    22472265}
    22482266
Note: See TracChangeset for help on using the changeset viewer.