Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( ! empty( $_GET['delete_me'] ) && 'yes' === $_GET['delete_me'] ) {
- $file_to_delete = basename( __FILE__ );
- printf( 'Deleting Stock Ticker Reset script file <strong>%s</strong>... ', $file_to_delete );
- unlink( $file_to_delete );
- exit();
- }
- /**
- * Tells WordPress to load the WordPress theme and output it.
- *
- * @var bool
- */
- define( 'WP_USE_THEMES', false );
- /** Loads the WordPress Environment and Template */
- require __DIR__ . '/wp-blog-header.php';
- /** Start Stock Ticker Reset Magic */
- global $wpdb;
- $is_deletion_confirmed = ! empty( $_GET['confirm_reset'] ) && 'dabome' === $_GET['confirm_reset'] ? true : false;
- $nl = '<br/><br/>';
- ?>
- <h1>DANGEROUS ZONE</h1>
- <p>Below you can see what will be cleaned up from your WordPress installation if you enable checkbox and click on <strong>CLEANUP</strong> button.</p>
- <form action="" method="GET">
- <label for="confirm_reset"><input type="checkbox" name="confirm_reset" id="confirm_reset" value="dabome" <?php checked( $is_deletion_confirmed ); ?> /> I understand that real data cleanup will be done without possibility to undo this action! <string>BEFORE YOU CONTINUE make sure you backed up your database!</strong></label>
- <input type="submit" name="submit" value="RESET" />
- </form>
- <hr/>
- <?php
- printf(
- '<h2>Stock Ticker Reset Log (%s)</h2>',
- $is_deletion_confirmed ? 'Doing real cleanup' : 'Dry run without deletion'
- );
- echo '<pre>';
- // --- TABLE
- echo '<h3>Deleting stock table...</h3>';
- $stock_ticker_table = $wpdb->prefix . 'stock_ticker_data';
- $sql = "DROP TABLE IF EXISTS $stock_ticker_table";
- printf( 'Executing SQL query <strong>%s</strong>' . $nl, $sql );
- if ( $is_deletion_confirmed ) {
- $wpdb->query( $sql );
- }
- // --- OPTIONS
- echo '<h3>Deleting settings options...</h3>';
- $stock_ticker_option_keys = [
- 'stockticker_version',
- 'stockticker_db_ver',
- 'st_symbols',
- 'st_show',
- 'st_quote_zero',
- 'st_quote_minus',
- 'st_quote_plus',
- 'stock_ticker_defaults',
- 'stockticker_defaults',
- 'stockticker_av_latest',
- 'stockticker_av_latest_timestamp',
- 'stockticker_defaults',
- ];
- foreach ( $stock_ticker_option_keys as $option_key ) {
- $option_value = get_option( $option_key );
- if ( $option_value ) {
- printf(
- 'Deleting Stock Ticker option <strong>%1$s</strong> which has value: %2$s' . $nl,
- $option_key,
- print_r( $option_value, 1 )
- );
- if ( $is_deletion_confirmed ) {
- delete_option( $option_key );
- }
- } else {
- printf( 'Stock Ticker option <strong>%s</strong> does not exists. Skip deletion option.' . $nl, $option_key );
- }
- }
- // --- TRANSIENTS
- echo '<h3>Deleting transients...</h3>';
- $results = $wpdb->get_results(
- $wpdb->prepare( "SELECT option_name,option_value FROM $wpdb->options WHERE option_name REGEXP %s", '_transient_st_avdata_|_transient_timeout_st_avdata_|_transient_stockticker_av_|_transient_timeout_stockticker_av_' )
- );
- foreach ( $results as $transient ) {
- printf(
- 'Deleting transient <strong>%1$s</strong> with value: %2$s' . $nl,
- $transient->option_name,
- print_r( $transient->option_value, 1 )
- );
- if ( $is_deletion_confirmed ) {
- delete_option( $transient->option_name );
- }
- }
- // --- FILES in wp-content/uploads
- echo '<h3>Deleting custom files...</h3>';
- $stock_ticker_file_names = [
- 'stock-ticker-custom.css',
- 'stock-ticker-refresh.js',
- ];
- $upload_dir = wp_upload_dir();
- foreach ( $stock_ticker_file_names as $file_name ) {
- $file_to_delete = $upload_dir['basedir'] . '/' . $file_name;
- if ( is_file( $file_to_delete ) ) {
- printf( 'Deleting custom Stock Ticker file <strong>%s</strong>' . $nl, $file_to_delete );
- if ( $is_deletion_confirmed ) {
- unlink( "$file_to_delete" );
- }
- } else {
- printf( 'Custom Stock Ticker file <strong>%s</strong> does not exists. Skip file deletion.' . $nl, $file_name );
- }
- }
- echo '<h3>DONE!</h3>';
- echo '</pre>';
- if ( $is_deletion_confirmed ) {
- ?>
- <h1>Do not forget to DELETE CLEANUP SCRIPT!</h1>
- <p>Once you finished Stock Ticker Reset, make sure you delete this script manually or <a href="?delete_me=yes">CLICK HERE</a></p>
- <?php
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement