-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BIP type pages will now be converted to standard pages on deactivation (
- Loading branch information
1 parent
b86927d
commit a1e86cc
Showing
3 changed files
with
98 additions
and
33 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?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() { | ||
// remove widget data | ||
delete_option( 'widget_bip-logo' ); | ||
$active_widgets = get_option( 'sidebars_widgets' ); | ||
|
||
foreach ( $active_widgets as $key => $val ) { | ||
if ( empty( $val ) || !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 ); | ||
} | ||
|
||
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' ); | ||
} | ||
} |
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