register(); } catch ( \Throwable $e ) { self::log( $e ); } } } /** * Activation: the queue table, and its event if rows were left from before. * * @return void */ public static function activate() { Queue::install(); Queue::reschedule(); } /** * Deactivation: stop the retry event. The connection, routes and queue are kept. * * @return void */ public static function deactivate() { wp_clear_scheduled_hook( Queue::HOOK ); } /** * Remove everything this plugin stored on the current site (uninstall.php calls it per site): * ask LaunchList to remove the site (best effort), drop the queue table, delete every * `launchlist_` option and transient, and clear the event. * * @return void */ public static function uninstall_site() { global $wpdb; $credentials = Connection::credentials(); $transients = array( Forms::TRANSIENT, Relay::HOLD, 'launchlist_queue_lock' ); foreach ( Routes::all() as $route ) { $transients[] = Relay::FORM_HOLD . $route['form']; } // A copy never removes the connection of the site it was copied from. if ( null !== $credentials && ! Connection::is_copy() ) { Client::signed( 'DELETE', '/wordpress/site', null, Client::RELAY_TIMEOUT, $credentials ); } Queue::drop(); // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- One-off cleanup; each option is then deleted through the API so caches stay right. $names = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s", $wpdb->esc_like( 'launchlist_' ) . '%', $wpdb->esc_like( '_transient_launchlist_' ) . '%', $wpdb->esc_like( '_transient_timeout_launchlist_' ) . '%' ) ); foreach ( is_array( $names ) ? $names : array() as $name ) { if ( 0 === strpos( $name, '_transient_timeout_' ) ) { continue; } if ( 0 === strpos( $name, '_transient_' ) ) { delete_transient( substr( $name, strlen( '_transient_' ) ) ); } else { delete_option( $name ); } } // Transients kept in a persistent object cache are not in the options table. foreach ( $transients as $transient ) { delete_transient( $transient ); } } /** * Log an error while debugging. * * @param \Throwable $error The error. * @return void */ private static function log( $error ) { if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { error_log( 'LaunchList: ' . $error->getMessage() ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log } } }