query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE meta_key IN ( %s, %s, %s, %s, %s, %s, %s )", $meta_keys[0], $meta_keys[1], $meta_keys[2], $meta_keys[3], $meta_keys[4], $meta_keys[5], $meta_keys[6] ) ); $transient_like = $wpdb->esc_like( '_transient_flipwebp_' ) . '%'; $timeout_like = $wpdb->esc_like( '_transient_timeout_flipwebp_' ) . '%'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Uninstall cleanup has no higher-level API. $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", $transient_like, $timeout_like ) ); flipwebp_uninstall_delete_tmp(); } /** * Delete the temporary working directory and nothing outside it. * * @return void */ function flipwebp_uninstall_delete_tmp() { $uploads = wp_upload_dir(); if ( ! empty( $uploads['error'] ) || empty( $uploads['basedir'] ) ) { return; } $root = wp_normalize_path( trailingslashit( $uploads['basedir'] ) . 'flipwebp-tmp' ); $real = realpath( $root ); $base = realpath( $uploads['basedir'] ); if ( false === $real || false === $base ) { return; } $real = wp_normalize_path( $real ); $base = trailingslashit( wp_normalize_path( $base ) ); $real_cmp = $real; $base_cmp = $base; if ( 'Windows' === PHP_OS_FAMILY ) { $real_cmp = strtolower( $real_cmp ); $base_cmp = strtolower( $base_cmp ); } if ( 0 !== strpos( trailingslashit( $real_cmp ), $base_cmp ) || 'flipwebp-tmp' !== strtolower( wp_basename( $real ) ) ) { return; } flipwebp_uninstall_delete_tree( $real, trailingslashit( $real ) ); } /** * Recursively delete a directory that is confirmed to sit inside the tmp root. * * @param string $dir Absolute directory path. * @param string $tmp_root Absolute tmp root with a trailing slash. * @return void */ function flipwebp_uninstall_delete_tree( $dir, $tmp_root ) { $dir = wp_normalize_path( (string) $dir ); $dir_cmp = $dir; $root_cmp = $tmp_root; if ( 'Windows' === PHP_OS_FAMILY ) { $dir_cmp = strtolower( $dir_cmp ); $root_cmp = strtolower( $root_cmp ); } if ( 0 !== strpos( trailingslashit( $dir_cmp ), $root_cmp ) ) { return; } $items = scandir( $dir ); if ( ! is_array( $items ) ) { return; } foreach ( $items as $item ) { if ( '.' === $item || '..' === $item ) { continue; } $path = $dir . '/' . $item; if ( is_dir( $path ) && ! is_link( $path ) ) { flipwebp_uninstall_delete_tree( $path, $tmp_root ); continue; } if ( is_file( $path ) && ! is_link( $path ) ) { wp_delete_file( $path ); } } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir -- Local plugin temp directory, already constrained to uploads/flipwebp-tmp. rmdir( $dir ); } if ( is_multisite() ) { $flipwebp_site_ids = get_sites( array( 'fields' => 'ids', 'number' => 0, ) ); foreach ( $flipwebp_site_ids as $flipwebp_site_id ) { switch_to_blog( (int) $flipwebp_site_id ); flipwebp_uninstall_current_site(); restore_current_blog(); } } else { flipwebp_uninstall_current_site(); }