V3007.php
1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace AC\Plugin\Update;
use AC\Plugin\Update;
use AC\Plugin\Version;
class V3007 extends Update {
public function __construct() {
parent::__construct( new Version( '3.0.7' ) );
}
public function apply_update(): void
{
$this->update_roles_column();
}
/**
* Change the roles columns to the author column
*/
private function update_roles_column() {
global $wpdb;
$sql = "
SELECT *
FROM {$wpdb->options}
WHERE option_name LIKE 'cpac_options_%'
";
$results = $wpdb->get_results( $sql );
if ( ! is_array( $results ) ) {
return;
}
foreach ( $results as $row ) {
$options = maybe_unserialize( $row->option_value );
$update = false;
if ( ! is_array( $options ) ) {
continue;
}
foreach ( $options as $k => $v ) {
if ( ! is_array( $v ) || empty( $v['type'] ) || $v['type'] !== 'column-roles' ) {
continue;
}
$v['type'] = 'column-author_name';
$v['display_author_as'] = 'roles';
$v['edit'] = 'off';
$options[ $k ] = $v;
$update = true;
}
if ( $update ) {
update_option( $row->option_name, $options, false );
}
}
}
}