prefix . 'ostew_log'; /* * Export the audit trail before dropping it. * * Failure here must never stop the uninstall, so every step is guarded and the * drop below runs either way. */ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $ostew_rows = $wpdb->get_results( "SELECT * FROM {$ostew_workflow_table} ORDER BY id ASC", ARRAY_A ); if ( ! empty( $ostew_rows ) && function_exists( 'wp_upload_dir' ) ) { $ostew_uploads = wp_upload_dir(); if ( empty( $ostew_uploads['error'] ) && ! empty( $ostew_uploads['basedir'] ) ) { $ostew_dir = trailingslashit( $ostew_uploads['basedir'] ) . 'ost-editorial-workflow'; wp_mkdir_p( $ostew_dir ); $ostew_columns = array( 'id', 'post_id', 'from_status', 'to_status', 'action', 'user_id', 'note', 'created_at' ); array_unshift( $ostew_rows, array_combine( $ostew_columns, $ostew_columns ) ); $ostew_csv = ''; foreach ( $ostew_rows as $ostew_row ) { $ostew_fields = array(); foreach ( $ostew_columns as $ostew_column ) { $ostew_value = isset( $ostew_row[ $ostew_column ] ) ? (string) $ostew_row[ $ostew_column ] : ''; $ostew_fields[] = '"' . str_replace( '"', '""', $ostew_value ) . '"'; } $ostew_csv .= implode( ',', $ostew_fields ) . "\r\n"; } if ( '' !== $ostew_csv ) { $ostew_file = $ostew_dir . '/audit-export-' . gmdate( 'Y-m-d-His' ) . '.csv'; global $wp_filesystem; if ( ! $wp_filesystem ) { require_once ABSPATH . 'wp-admin/includes/file.php'; WP_Filesystem(); } if ( $wp_filesystem ) { $wp_filesystem->put_contents( $ostew_file, $ostew_csv, FS_CHMOD_FILE ); } } } } // Drop the audit table. $wpdb->query( "DROP TABLE IF EXISTS {$ostew_workflow_table}" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared // Remove options. delete_option( 'ostew_workflows' ); delete_option( 'ostew_settings' ); delete_option( 'ostew_db_version' ); delete_option( 'ostew_known_statuses' ); delete_option( 'ostew_pending_scan' ); // Remove the per-user dismissal of the stranded-content warning. delete_metadata( 'user', 0, '_ostew_orphans_dismissed', '', true ); // Remove per-post workflow meta (written by the transition + escalation engine). delete_post_meta_by_key( '_ostew_status_since' ); delete_post_meta_by_key( '_ostew_escalation_count' ); delete_post_meta_by_key( '_ostew_last_escalated' );