Background
1 year ago
Blocks
1 year ago
GlobalElements
1 year ago
Layout
1 year ago
Separators
11 months ago
StyleManager
1 month ago
Styles
1 year ago
Activation.php
1 year ago
Backup.php
1 year ago
CustomizerImporter.php
11 months ago
Deactivation.php
1 year ago
EditInKubioCustomizerPanel.php
1 year ago
Element.php
1 year ago
ElementBase.php
4 years ago
Importer.php
1 month ago
InnerBlocks.php
1 year ago
KubioFrontPageRevertNotice.php
9 months ago
LodashBasic.php
1 year ago
Registry.php
1 year ago
ThirdPartyPluginAssetLoaderInEditor.php
3 months ago
Utils.php
20 hours ago
Deactivation.php
60 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kubio\Core; |
| 4 | |
| 5 | use Kubio\Flags; |
| 6 | |
| 7 | class Deactivation { |
| 8 | |
| 9 | private static $instance = null; |
| 10 | |
| 11 | public static function load() { |
| 12 | if ( ! self::$instance ) { |
| 13 | self::$instance = new self(); |
| 14 | } |
| 15 | |
| 16 | return self::$instance; |
| 17 | } |
| 18 | |
| 19 | public function __construct() { |
| 20 | add_action( 'kubio/plugin_deactivated', array( $this, 'deactivate' ) ); |
| 21 | } |
| 22 | |
| 23 | public function deactivate() { |
| 24 | |
| 25 | $active_plugins = get_option( 'active_plugins', array() ); |
| 26 | |
| 27 | $current_plugin_file = trim( str_replace( wp_normalize_path( WP_PLUGIN_DIR ), '', wp_normalize_path( KUBIO_ENTRY_FILE ) ), '/' ); |
| 28 | $active_plugins = array_diff( $active_plugins, array( $current_plugin_file ) ); |
| 29 | |
| 30 | // if another kubio plugin is still active ( pro or free version ) skip backup |
| 31 | foreach ( $active_plugins as $active_plugin ) { |
| 32 | if ( strpos( $active_plugin, 'kubio/' ) === 0 || strpos( $active_plugin, 'kubio-pro/' ) === 0 ) { |
| 33 | return; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | $identifier = uniqid( 'bkp-deactivation-' ); |
| 38 | $backup = new Backup(); |
| 39 | $result = $backup->backupSiteStructureAndStyle( $identifier ); |
| 40 | |
| 41 | // stop deactivating block templates is the backup fails |
| 42 | if ( is_wp_error( $result ) ) { |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | $template = get_stylesheet(); |
| 47 | Flags::setSetting( "deactivation_backup_key.{$template}", $identifier ); |
| 48 | $this->deleteBlockTemplates( 'wp_template' ); |
| 49 | $this->deleteBlockTemplates( 'wp_template_part' ); |
| 50 | } |
| 51 | |
| 52 | private function deleteBlockTemplates( $post_type = 'wp_template' ) { |
| 53 | $entities = get_block_templates( array(), $post_type ); |
| 54 | |
| 55 | foreach ( $entities as $entity ) { |
| 56 | wp_delete_post( $entity->wp_id, true ); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 |