/module.php ('uninstall'). Data of other plugins, * including the original SalesGen Store Info options (storeinfo_*), is never touched. * * @package CPODKit */ defined( 'WP_UNINSTALL_PLUGIN' ) || exit; // The other edition (free cPOD Kit or cPOD Kit Pro) is still installed and uses the same data. // Only the Pro build ships cpod-kit-pro.php. $cpod_other = file_exists( __DIR__ . '/cpod-kit-pro.php' ) ? '/cpod-kit/cpod-kit.php' : '/cpod-kit-pro/cpod-kit-pro.php'; if ( file_exists( WP_PLUGIN_DIR . $cpod_other ) ) { return; } $cpod_settings = get_option( 'cpod_settings', array() ); if ( ! is_array( $cpod_settings ) || empty( $cpod_settings['uninstall'] ) || 'delete' !== $cpod_settings['uninstall'] ) { return; } $cpod_data = array( 'post_types' => array(), 'post_meta' => array(), 'user_meta' => array(), 'options' => array( 'cpod_settings', 'cpod_modules', 'cpod_version' ), 'transients' => array(), 'taxonomies' => array(), ); foreach ( glob( __DIR__ . '/modules/*/module.php' ) as $cpod_file ) { $cpod_module = include $cpod_file; if ( ! is_array( $cpod_module ) || empty( $cpod_module['uninstall'] ) ) { continue; } foreach ( $cpod_data as $cpod_key => $cpod_list ) { if ( ! empty( $cpod_module['uninstall'][ $cpod_key ] ) ) { $cpod_data[ $cpod_key ] = array_merge( $cpod_list, (array) $cpod_module['uninstall'][ $cpod_key ] ); } } } if ( $cpod_data['post_types'] ) { $cpod_ids = get_posts( array( 'post_type' => array_unique( $cpod_data['post_types'] ), 'post_status' => array_keys( get_post_stati() ), // 'any' would skip trash and auto-drafts. 'posts_per_page' => -1, 'fields' => 'ids', // get_posts() already skips query filters. ) ); foreach ( $cpod_ids as $cpod_id ) { wp_delete_post( $cpod_id, true ); } } // Extra cleanup steps shipped by an edition (core/uninstall-*.php, e.g. in cPOD Kit Pro). foreach ( glob( __DIR__ . '/core/uninstall-*.php' ) as $cpod_file ) { include $cpod_file; } foreach ( array_unique( $cpod_data['post_meta'] ) as $cpod_meta ) { delete_post_meta_by_key( $cpod_meta ); } foreach ( array_unique( $cpod_data['user_meta'] ) as $cpod_meta ) { delete_metadata( 'user', 0, $cpod_meta, '', true ); } foreach ( array_unique( $cpod_data['options'] ) as $cpod_option ) { delete_option( $cpod_option ); } foreach ( array_unique( $cpod_data['transients'] ) as $cpod_transient ) { delete_transient( $cpod_transient ); } // Taxonomies of the plugin (Print style): its terms and their links to products. Other taxonomies are not touched. foreach ( array_unique( $cpod_data['taxonomies'] ) as $cpod_taxonomy ) { if ( ! taxonomy_exists( $cpod_taxonomy ) ) { register_taxonomy( $cpod_taxonomy, array( 'product' ), array( 'public' => false ) ); } $cpod_terms = get_terms( array( 'taxonomy' => $cpod_taxonomy, 'hide_empty' => false, 'fields' => 'ids', ) ); foreach ( is_wp_error( $cpod_terms ) ? array() : $cpod_terms as $cpod_term ) { wp_delete_term( (int) $cpod_term, $cpod_taxonomy ); } } // Printify caches and import steps (cPOD Kit Pro): names hold a hash or ids, so by prefix. global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- one-time cleanup on uninstall. $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", $wpdb->esc_like( '_transient_cpod_pfy_' ) . '%', $wpdb->esc_like( '_transient_timeout_cpod_pfy_' ) . '%' ) ); // Daily Printify base cost update (cPOD Kit Pro). wp_clear_scheduled_hook( 'cpod_pfy_sync' ); // Linking Printify products to profiles, price and stock of variations (cPOD Kit Pro). foreach ( array( 'cpod_pfy_link', 'cpod_pp_variations_product', 'cpod_pp_variations_profile', 'cpod_pp_auto_terms_batch', 'cpod_print_style_sync' ) as $cpod_hook ) { if ( function_exists( 'as_unschedule_all_actions' ) ) { as_unschedule_all_actions( $cpod_hook ); } wp_unschedule_hook( $cpod_hook ); }