Project

General

Profile

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

Boone Gorges, 2023-02-16 03:13 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
	if ( 1 == $doc_settings ) {
23
		$doc_settings = get_post_meta( $doc_id, '_bp_docs_settings_bak', true );
24
	}
25

    
26
	//update_post_meta( $doc_id, '_bp_docs_settings_bak', $doc_settings );
27

    
28
	if ( ! $doc_settings ) {
29
		$doc_settings = $default_settings;
30
	} else {
31
		$doc_settings['edit'] = 'creator';
32
	}
33

    
34
	update_post_meta( $doc_id, 'bp_docs_settings', $doc_settings );
35
}
(2-2/2)