Project

General

Profile

Bug #17651 » non-group-doc-settings-17651.php

Boone Gorges, 2023-02-16 01:37 PM

 
1
<?php
2

    
3
global $wpdb;
4

    
5
$doc_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'bp_doc'" );
6

    
7
$default_settings = [
8
	'read'          => 'anyone',
9
	'edit'          => 'creator',
10
	'read_comments' => 'anyone',
11
	'post_comments' => 'loggedin',
12
	'view_history'  => 'anyone',
13
];
14

    
15
foreach ( $doc_ids as $doc_id ) {
16
	$associated_group_id = bp_docs_get_associated_group_id( $doc_id );
17
	if ( $associated_group_id ) {
18
		continue;
19
	}
20

    
21
	$doc_settings = get_post_meta( $doc_id, 'bp_docs_settings', true );
22

    
23
	update_post_meta( $doc_id, '_bp_docs_settings_bak', $doc_settings );
24

    
25
	if ( ! $doc_settings ) {
26
		$doc_settings = $default_settings;
27
	} else {
28
		$doc_settings['edit'] = 'creator';
29
	}
30

    
31
	update_post_meta( $doc_id, 'bp_docs_settings', true );
32
}
(1-1/2)