-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbip-pages-deactivation.php
62 lines (49 loc) · 1.51 KB
/
bip-pages-deactivation.php
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
<?php
namespace BipPages;
// turn all bip pages to regular pages
function convert_page_types() {
$converted = 0;
$bip_pages = get_pages( ['post_type' => 'bip'] );
$total = count( $bip_pages );
foreach ( $bip_pages as $page ) {
if ( post_exists( $page->post_title, '', '', 'page' ) ) {
// rename first
wp_update_post( array(
'ID' => $page->ID,
'post_status' => 'draft'
));
}
$res = set_post_type( $page->ID, 'page');
$converted += $res;
}
return $converted;
}
function remove_widgets() {
$active_widgets = get_option( 'sidebars_widgets', array() );
foreach ( $active_widgets as $key => $val ) {
if ( !is_array( $val ) ) {
continue;
}
$widget_ids = array_flip( $val );
foreach ( $widget_ids as $widget => $id ) {
if ( strpos( $widget, 'bip-logo-' ) === 0 ) {
unset( $active_widgets[$key][$id] );
}
}
}
update_option( 'sidebars_widgets', $active_widgets );
delete_option( 'widget_bip-logo' );
}
add_action( 'admin_notices', __NAMESPACE__ . '\deactivation_notice' );
function deactivation_notice(){
if( get_transient( 'bip-pages-deactivation-msg' ) ){
?>
<div class="updated notice is-dismissible">
<p>
<?= esc_html__( 'BIP Pages plugin has been deactivated. Your BIP pages have been converted to standard pages (or drafts in case of a conflicting page title)', 'bip-pages' ) ?>
</p>
</div>
<?php
delete_transient( 'bip-pages-deactivation-msg' );
}
}