Skip to:
Content
Pages
Categories
Search
Top
Bottom

Make user status update button available only to admin


  • Tom
    Participant

    @jeffreeeeey

    OK Here’s what I’m trying to do:

    In a member profile, a users status should be publicly viewable.

    The only people who should be able to update a users status is Admin.

    Even registered members shouldn’t be allowed to update their status.

    Also this part: “18 hours, 1 minute ago” I want to edit so that the same text displays all the time. I want to change it to: “To xxxxxx. T&C’s [Hyperlink] apply”.

    Can anyone tell me how I’d go about doing this?

    I don’t see the relative ‘if’ tags in profile/index.php that allow logged in users to edit their status, so started looking elsewhere.

    The only place I see something that maybe what I need to edit is-

    /buddypress/bp-status/bp-status-templatetags.php

    Here’s what’s there:

    <?php

    function bp_the_status( $args = false ) {
    /***
    * To support updating your status without JS, we can display the update form when the GET var "status" is set
    * to "new".
    */
    if ( 'new' == $_GET['status'] && is_user_logged_in() ) {
    locate_template( array( 'status/post-form.php' ), true );
    } else {
    if ( 'clear' == $_GET['status'] && is_user_logged_in() )
    bp_status_clear_status();

    echo bp_get_the_status( $args );
    }
    }
    function bp_get_the_status( $args = false ) {
    global $bp;

    $defaults = array(
    'user_id' => $bp->displayed_user->id,
    'clear_button_text' => __( 'Clear', 'buddypress' ),
    'new_button_text' => __( 'Update Your Status', 'buddypress' ),
    'no_anchor' => false
    );

    $r = wp_parse_args( $args, $defaults );
    extract( $r, EXTR_SKIP );

    if ( !$user_id )
    $user_id = $bp->displayed_user->id;

    $status = apply_filters( 'bp_status_from_usermeta', get_usermeta( $user_id, 'bp_status' ) );

    if ( empty($status) )
    return bp_get_update_status_button( 'text=' . $new_button_text );

    $time_since = sprintf( __( '%s ago', 'buddypress' ), bp_core_time_since( $status['recorded_time'] ) );
    $content = apply_filters( 'the_status_content', $status['content'] );

    if ( !(int)$no_anchor && $user_id == $bp->loggedin_user->id )
    $content = '<a href="' . bp_core_get_user_domain( $user_id ) . '?status=new" id="status-new-status">' . $content . '</a>';

    $content .= ' <span class="time-since">' . $time_since . '</span>';
    $content .= ' ' . bp_get_clear_status_button( 'text=' . $clear_button_text );

    return apply_filters( 'bp_get_the_status', $content );
    }

    function bp_update_status_button( $args = false ) {
    echo bp_get_update_status_button( $args );
    }
    function bp_get_update_status_button( $args = false ) {
    global $bp;

    $defaults = array(
    'user_id' => false,
    'text' => __( 'Update Your Status', 'buddypress' )
    );

    $r = wp_parse_args( $args, $defaults );
    extract( $r, EXTR_SKIP );

    if ( !$user_id )
    $user_id = $bp->displayed_user->id;

    if ( $user_id != $bp->loggedin_user->id )
    return false;

    return apply_filters( 'bp_get_update_status_button', '<div class="generic-button"><a href="' . bp_core_get_user_domain( $user_id ) . '?status=new" id="status-new-status">' . $text . '</a></div>' );
    }

    function bp_clear_status_button( $args = false ) {
    echo bp_get_clear_status_button( $args );
    }
    function bp_get_clear_status_button( $args = false ) {
    global $bp;

    $defaults = array(
    'user_id' => false,
    'text' => __( 'Clear', 'buddypress' )
    );

    $r = wp_parse_args( $args, $defaults );
    extract( $r, EXTR_SKIP );

    if ( !$user_id )
    $user_id = $bp->displayed_user->id;

    if ( $user_id != $bp->loggedin_user->id )
    return false;

    return apply_filters( 'bp_get_clear_status_button', '<a href="' . bp_core_get_user_domain( $user_id ) . '?status=clear" id="status-clear-status">' . $text . '</a>' );
    }

    function bp_status_form_action( $user_id = false ) {
    global $bp;

    if ( !$user_id )
    $user_id = $bp->loggedin_user->id;

    echo apply_filters( 'bp_status_form_action', bp_core_get_user_domain( $user_id ) . BP_STATUS_SLUG . '/add' );
    }

    function bp_the_status_css_class() {
    echo bp_get_the_status_css_class();
    }
    function bp_get_the_status_css_class() {
    return ( bp_loggedin_user_id() == bp_displayed_user_id() ) ? 'status-editable' : 'status-display';
    }

    ?>

    Can anyone help, or even tell me if I’m looking in the correct place?

Viewing 4 replies - 1 through 4 (of 4 total)

  • Tom
    Participant

    @jeffreeeeey

    and to be more clear.. I only need to worry about the display on member profiles as I don’t have the activity feed turned on across the site.


    Boone Gorges
    Keymaster

    @boonebgorges

    Untested, but the following should work.

    1) Copy all those functions above to a plugin file/functions.php/bp-custom.php

    2) Add a unique prefix to each function, so as to avoid PHP errors. Eg jeff_bp_update_status_button, etc.

    3) In jeff_get_update_status_button and jeff_get_clear_status_button, add the following:

    if ( !is_site_admin )
    return false;

    You can put it right after the line that reads global $bp;.

    4) In jeff_bp_the_status, change all references to the original functions (like bp_update_status_button) to your new functions (jeff_bp_update_status_button).

    5) In the template file that handles profile status ([child-theme-path]/profile/profile-header.php – copy the same file over from the parent theme if it doesn’t exist yet), change

    bp_the_status()

    to

    jeff_bp_the_status()


    Tom
    Participant

    @jeffreeeeey

    Jesus not as simple as I thought lol.

    Many thanks Boone for your time, once again. :@)


    Boone Gorges
    Keymaster

    @boonebgorges

    No problem.

    You could just hack the core files to reflect the change in step (3). But it’s good to avoid such hacks when you can; thus the long process outlined above :)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Make user status update button available only to admin’ is closed to new replies.
Skip to toolbar