Admin::SLUG . '-privacy', 'saved' => 1, ], admin_url( 'admin.php' ) ) ); exit; } /** * One-off maintenance actions: anonymize existing data or purge old entries. */ public function handle_action() { if ( ! current_user_can( Admin::CAPABILITY ) ) { wp_die( esc_html__( 'Permission denied.', 'phemightforms' ) ); } check_admin_referer( 'phemightforms_privacy_action' ); global $wpdb; $table = Install::entries_table(); $action = isset( $_POST['privacy_action'] ) ? sanitize_key( wp_unslash( $_POST['privacy_action'] ) ) : ''; $done = ''; if ( 'anonymize' === $action ) { $wpdb->query( "UPDATE {$table} SET ip_address = '', user_agent = ''" ); // phpcs:ignore WordPress.DB $done = 'anonymized'; } elseif ( 'purge_old' === $action ) { $days = (int) Plugin::get_option( 'entry_retention_days', 0 ); if ( $days > 0 ) { $cutoff = gmdate( 'Y-m-d H:i:s', time() - ( $days * DAY_IN_SECONDS ) ); $wpdb->query( $wpdb->prepare( "DELETE FROM {$table} WHERE created_at < %s", $cutoff ) ); // phpcs:ignore WordPress.DB $done = 'purged'; } else { $done = 'noretention'; } } wp_safe_redirect( add_query_arg( [ 'page' => Admin::SLUG . '-privacy', 'done' => $done, ], admin_url( 'admin.php' ) ) ); exit; } /** * Render the Privacy Compliance page. */ public static function render_page() { if ( ! current_user_can( Admin::CAPABILITY ) ) { wp_die( esc_html__( 'Permission denied.', 'phemightforms' ) ); } global $wpdb; $table = Install::entries_table(); $total = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$table}" ); // phpcs:ignore WordPress.DB $with_ip = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$table} WHERE ip_address <> ''" ); // phpcs:ignore WordPress.DB $oldest = $wpdb->get_var( "SELECT MIN(created_at) FROM {$table}" ); // phpcs:ignore WordPress.DB $settings = get_option( 'phemightforms_settings', [] ); $get = static function ( $key, $default = '' ) use ( $settings ) { return isset( $settings[ $key ] ) ? $settings[ $key ] : $default; }; $retention = (int) $get( 'entry_retention_days', 0 ); $done = isset( $_GET['done'] ) ? sanitize_key( wp_unslash( $_GET['done'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended // GDPR export/delete tool messages (form posts back to this page). $tool_message = ''; if ( isset( $_POST['phf_gdpr_action'] ) && check_admin_referer( 'phemightforms_gdpr' ) ) { $email = isset( $_POST['phf_gdpr_email'] ) ? sanitize_email( wp_unslash( $_POST['phf_gdpr_email'] ) ) : ''; $action = sanitize_key( wp_unslash( $_POST['phf_gdpr_action'] ) ); if ( ! is_email( $email ) ) { $tool_message = 'error:' . __( 'Please enter a valid email address.', 'phemightforms' ); } elseif ( 'delete' === $action ) { $count = self::delete_by_email( $email ); $tool_message = 'success:' . sprintf( /* translators: %d: number of entries removed. */ __( 'Removed %d entries containing that email.', 'phemightforms' ), $count ); } } ?>

0 ? esc_html( sprintf( /* translators: %d: days */ __( '%d days', 'phemightforms' ), $retention ) ) : esc_html__( 'Off', 'phemightforms' ); ?>

' . esc_html__( 'Export Personal Data', 'phemightforms' ) . '', '' . esc_html__( 'Erase Personal Data', 'phemightforms' ) . '' ); ?>

esc_like( $email ) . '%'; $rows = (array) $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$table} WHERE fields LIKE %s", $like ) ); // phpcs:ignore WordPress.DB $count = 0; foreach ( $rows as $row ) { $wpdb->delete( $table, [ 'id' => $row->id ], [ '%d' ] ); // phpcs:ignore WordPress.DB $count++; } return $count; } }