Skip to content

Commit

Permalink
When posting activity items, use 'hide_sitewide' correctly
Browse files Browse the repository at this point in the history
The value of 'hide_sitewide' when posting activity was previously handled by
the group integration piece. This obviously doesn't work for non-group-
affiliated Docs. In the case of those Docs, hide_sitewide should be true
whenever the 'read' setting for the Doc is something other than 'anyone'.
  • Loading branch information
boonebgorges committed Dec 19, 2012
1 parent 0773c4f commit 67bfd88
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions includes/component.php
Expand Up @@ -562,6 +562,8 @@ function post_comment_activity( $comment_id ) {
// Set the type, to be used in activity filtering
$type = 'bp_doc_comment';

$hide_sitewide = bp_docs_hide_sitewide_for_doc( $doc_id );

$args = array(
'user_id' => $commenter_id,
'action' => $action,
Expand All @@ -572,7 +574,7 @@ function post_comment_activity( $comment_id ) {
'item_id' => $item, // Set to the group/user/etc id, for better consistency with other BP components
'secondary_item_id' => $comment_id, // The id of the doc itself. Note: limitations in the BP activity API mean I don't get to store the doc_id, but at least it can be abstracted from the comment_id
'recorded_time' => bp_core_current_time(),
'hide_sitewide' => apply_filters( 'bp_docs_hide_sitewide', false, $comment, $doc, $item, $component ) // Filtered to allow plugins and integration pieces to dictate
'hide_sitewide' => apply_filters( 'bp_docs_hide_sitewide', $hide_sitewide, $comment, $doc, $item, $component ) // Filtered to allow plugins and integration pieces to dictate
);

do_action( 'bp_docs_before_comment_activity_save', $args );
Expand Down Expand Up @@ -730,6 +732,8 @@ function post_activity( $query ) {

$action = apply_filters( 'bp_docs_activity_action', $action, $user_link, $doc_link, $query->is_new_doc, $query );

$hide_sitewide = bp_docs_hide_sitewide_for_doc( $doc_id );

// Get a canonical name for the component. This is a nightmare because of the way
// the current component and root slug relate in BP 1.3+
$component = bp_current_component();
Expand All @@ -754,7 +758,7 @@ function post_activity( $query ) {
'item_id' => $query->item_id, // Set to the group/user/etc id, for better consistency with other BP components
'secondary_item_id' => $doc_id, // The id of the doc itself
'recorded_time' => bp_core_current_time(),
'hide_sitewide' => apply_filters( 'bp_docs_hide_sitewide', false, false, $doc, $item, $component ) // Filtered to allow plugins and integration pieces to dictate
'hide_sitewide' => apply_filters( 'bp_docs_hide_sitewide', $hide_sitewide, false, $doc, $item, $component ) // Filtered to allow plugins and integration pieces to dictate
);

do_action( 'bp_docs_before_activity_save', $args );
Expand Down
23 changes: 23 additions & 0 deletions includes/functions.php
Expand Up @@ -610,3 +610,26 @@ function bp_docs_update_doc_access( $doc_id, $access_setting = 'anyone' ) {

}

/**
* Should 'hide_sitewide' be true for activity items associated with this Doc?
*
* We generalize: mark the activity items as 'hide_sitewide' whenever the
* 'read' setting is something other than 'anyone'.
*
* Note that this gets overridden by the filter in integration-groups.php in
* the case of group-associated Docs.
*
* @since 1.2.8
* @param int $doc_id
* @return bool $hide_sitewide
*/
function bp_docs_hide_sitewide_for_doc( $doc_id ) {
if ( ! $doc_id ) {
return false;
}

$settings = get_post_meta( $doc_id, 'bp_docs_settings', true );
$hide_sitewide = empty( $settings['read'] ) || 'anyone' != $settings['read'];

return apply_filters( 'bp_docs_hide_sitewide_for_doc', $hide_sitewide, $doc_id );
}
1 change: 1 addition & 0 deletions readme.txt
Expand Up @@ -38,6 +38,7 @@ This plugin is in active development. For feature requests and bug reports, visi
= 1.2.8 =
* Fixes problem with group associations and privacy levels of new docs
* Improves access protection in WP searches and elsewhere
* Sets hide_sitewide more carefully when posting Doc activity items

= 1.2.7 =
* Updates German translation
Expand Down

0 comments on commit 67bfd88

Please sign in to comment.