Last active
February 21, 2022 18:58
-
-
Save dcavins/d846e87c5a1cf44bca4133a332800f51 to your computer and use it in GitHub Desktop.
Find all BP Docs that have perrmissive read settings ("anyone") and change them to "loggedin" or "group-members".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Ignore folder association temporarily. | |
remove_filter( 'bp_docs_tax_query', 'bp_docs_folder_tax_query', 10, 2 ); | |
$doc_args = array( | |
// 'folder' => , | |
'posts_per_page' => 50, | |
'paged' => 1, // increment this to work through the docs. | |
); | |
if ( bp_docs_has_docs( $doc_args ) ) : | |
?> | |
<ul> | |
<?php while ( bp_docs_has_docs() ) : bp_docs_the_doc(); ?> | |
<li> | |
<?php get_the_title() ? the_title() : the_ID(); ?> | |
<br/> | |
<?php | |
?> | |
Settings: | |
<?php | |
$doc_id = get_the_ID(); | |
$is_group_associated = false; | |
if ( function_exists( 'bp_docs_get_associated_group_id' ) && bp_docs_get_associated_group_id( $doc_id ) ) { | |
$is_group_associated = true; | |
} | |
$min_setting = ( $is_group_associated ) ? "group-members" : "loggedin"; | |
$settings = bp_docs_get_doc_settings( $doc_id ); | |
$must_update = false; | |
foreach ( $settings as $cap => $value ) { | |
if ( 'anyone' === $value ) { | |
$settings[ $cap ] = $min_setting; | |
$must_update = true; | |
} | |
} | |
if ( $must_update ) { | |
echo "updating doc: " . $doc_id; | |
$author_id = get_the_author_meta( 'ID' ); | |
bp_docs_save_doc_access_settings( $doc_id, $author_id, $settings ); | |
} else { | |
echo "NOT updating doc: " . $doc_id; | |
} | |
?> | |
</li> | |
<?php endwhile; ?> | |
</ul> | |
<?php | |
endif; | |
add_filter( 'bp_docs_tax_query', 'bp_docs_folder_tax_query', 10, 2 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment