diff --git a/src/Api/ClientFactory.php b/src/Api/ClientFactory.php index 34f37e7..693630b 100644 --- a/src/Api/ClientFactory.php +++ b/src/Api/ClientFactory.php @@ -113,13 +113,7 @@ public function testConnection(): array { $workspace->isSeatLive() ); - if ( ! $workspace->isSeatLive() ) { - $result = array( - 'ok' => false, - 'message' => __( 'This workspace has no active Verifycate plan. Activate a plan before issuing certificates.', 'verifycate' ), - 'total' => 0, - ); - } elseif ( ! $workspace->canWriteCertificates() ) { + if ( ! $workspace->canWriteCertificates() ) { $result = array( 'ok' => false, 'message' => __( 'This API key can read certificates but cannot issue them. Create a key with the certificates:write scope and reconnect.', 'verifycate' ), @@ -195,7 +189,7 @@ private function describeApiError( ApiException $exception ): string { } if ( $exception->isPaymentRequired() ) { - return __( 'This workspace needs an active Verifycate plan before certificates can be issued.', 'verifycate' ); + return __( 'This workspace needs more credits before certificates can be issued, or the action uses a Pro feature.', 'verifycate' ); } if ( $exception->isForbidden() ) { diff --git a/src/Frontend/Wallet.php b/src/Frontend/Wallet.php index 1775975..00b09a6 100644 --- a/src/Frontend/Wallet.php +++ b/src/Frontend/Wallet.php @@ -115,8 +115,6 @@ public function assets(): void { array(), $version ); - - wp_enqueue_style( 'verifycate-wallet' ); } /** @@ -168,6 +166,8 @@ public function renderBlock( array $attributes ): string { * @return string */ public function render( array $args ): string { + wp_enqueue_style( 'verifycate-wallet' ); + $title = isset( $args['title'] ) && '' !== (string) $args['title'] ? (string) $args['title'] : __( 'My certificates', 'verifycate' ); $empty_text = isset( $args['empty_text'] ) && '' !== (string) $args['empty_text'] ? (string) $args['empty_text'] : __( 'No certificates yet.', 'verifycate' ); $limit = isset( $args['limit'] ) ? max( 1, min( 50, (int) $args['limit'] ) ) : 20; diff --git a/src/Install.php b/src/Install.php index cb9f97f..c18e703 100644 --- a/src/Install.php +++ b/src/Install.php @@ -152,11 +152,11 @@ private static function migrateMappingTriggers(): void { $table = $wpdb->prefix . 'verifycate_mappings'; - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared - $wpdb->query( "UPDATE {$table} SET event = 'course_completed' WHERE event = ''" ); + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $wpdb->query( $wpdb->prepare( "UPDATE %i SET event = 'course_completed' WHERE event = ''", $table ) ); - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared - $index = $wpdb->get_results( "SHOW INDEX FROM {$table} WHERE Key_name = 'mapping'", ARRAY_A ); + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $index = $wpdb->get_results( $wpdb->prepare( 'SHOW INDEX FROM %i WHERE Key_name = %s', $table, 'mapping' ), ARRAY_A ); $keys = array(); foreach ( is_array( $index ) ? $index : array() as $row ) { @@ -172,12 +172,12 @@ private static function migrateMappingTriggers(): void { } if ( $keys !== array() ) { - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared - $wpdb->query( "ALTER TABLE {$table} DROP INDEX mapping" ); + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange + $wpdb->query( $wpdb->prepare( 'ALTER TABLE %i DROP INDEX mapping', $table ) ); } - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared - $wpdb->query( "ALTER TABLE {$table} ADD UNIQUE KEY mapping (integration,event,trigger_id,course_id,certificate_id)" ); + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange + $wpdb->query( $wpdb->prepare( 'ALTER TABLE %i ADD UNIQUE KEY mapping (integration,event,trigger_id,course_id,certificate_id)', $table ) ); } /** diff --git a/src/Integrations/LearnPress.php b/src/Integrations/LearnPress.php index bdc3d7c..18a3e15 100644 --- a/src/Integrations/LearnPress.php +++ b/src/Integrations/LearnPress.php @@ -88,8 +88,10 @@ private function getTriggerItems( string $post_type, int $limit ): array { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $rows = $wpdb->get_results( $wpdb->prepare( - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table names are built from $wpdb->prefix, values are prepared. - "SELECT p.ID, p.post_title, s.section_course_id AS course_id FROM {$wpdb->posts} p INNER JOIN {$items} si ON si.item_id = p.ID INNER JOIN {$sections} s ON s.section_id = si.section_id WHERE p.post_type = %s AND p.post_status = 'publish' GROUP BY p.ID, p.post_title, s.section_course_id ORDER BY s.section_course_id, p.post_title LIMIT %d", + "SELECT p.ID, p.post_title, s.section_course_id AS course_id FROM %i p INNER JOIN %i si ON si.item_id = p.ID INNER JOIN %i s ON s.section_id = si.section_id WHERE p.post_type = %s AND p.post_status = 'publish' GROUP BY p.ID, p.post_title, s.section_course_id ORDER BY s.section_course_id, p.post_title LIMIT %d", + $wpdb->posts, + $items, + $sections, $post_type, max( 1, min( 1000, $limit ) ) ), diff --git a/src/Issuance/MappingRepository.php b/src/Issuance/MappingRepository.php index a771787..b8ae327 100644 --- a/src/Issuance/MappingRepository.php +++ b/src/Issuance/MappingRepository.php @@ -39,17 +39,15 @@ public function all( bool $enabled_only = false ): array { global $wpdb; $table = $this->table(); - $sql = "SELECT * FROM {$table}"; if ( $enabled_only ) { - $sql .= ' WHERE enabled = 1'; + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $rows = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %i WHERE enabled = 1 ORDER BY id DESC', $table ), ARRAY_A ); + } else { + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $rows = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %i ORDER BY id DESC', $table ), ARRAY_A ); } - $sql .= ' ORDER BY id DESC'; - - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared - $rows = $wpdb->get_results( $sql, ARRAY_A ); - return $this->hydrate( is_array( $rows ) ? $rows : array() ); } @@ -75,13 +73,18 @@ public function paginate( int $page = 1, int $per_page = 20, string $search = '' list( $where, $params ) = $this->searchClause( $search ); $order_sql = $this->orderClause( $orderby, $order ); - $sql = "SELECT m.* FROM {$table} m LEFT JOIN {$posts} p ON p.ID = m.course_id {$where} {$order_sql} LIMIT %d OFFSET %d"; - $params[] = $per_page; - $params[] = $offset; - $prepared = $wpdb->prepare( $sql, $params ); + $params = array_merge( array( $table, $posts ), $params, array( $per_page, $offset ) ); - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared - $rows = $wpdb->get_results( $prepared, ARRAY_A ); + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + // phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter -- WHERE clause is static; values use placeholders. + $rows = $wpdb->get_results( + // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- Search placeholders are built dynamically. + $wpdb->prepare( + "SELECT m.* FROM %i m LEFT JOIN %i p ON p.ID = m.course_id {$where} {$order_sql} LIMIT %d OFFSET %d", + $params + ), + ARRAY_A + ); return $this->hydrate( is_array( $rows ) ? $rows : array() ); } @@ -96,8 +99,8 @@ public function find( int $id ): ?Mapping { global $wpdb; $table = $this->table(); - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared - $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$table} WHERE id = %d", $id ), ARRAY_A ); + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $row = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM %i WHERE id = %d', $table, $id ), ARRAY_A ); return is_array( $row ) ? Mapping::fromRow( $row ) : null; } @@ -206,10 +209,11 @@ public function matching( string $integration, int $course_id, string $event, in global $wpdb; $table = $this->table(); - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $rows = $wpdb->get_results( $wpdb->prepare( - "SELECT * FROM {$table} WHERE enabled = 1 AND integration = %s AND (course_id = 0 OR course_id = %d) AND event = %s AND (trigger_id = 0 OR trigger_id = %d) ORDER BY course_id DESC, trigger_id DESC, id ASC", + 'SELECT * FROM %i WHERE enabled = 1 AND integration = %s AND (course_id = 0 OR course_id = %d) AND event = %s AND (trigger_id = 0 OR trigger_id = %d) ORDER BY course_id DESC, trigger_id DESC, id ASC', + $table, $integration, $course_id, $event, @@ -235,14 +239,17 @@ public function count( string $search = '' ): int { list( $where, $params ) = $this->searchClause( $search ); - $sql = "SELECT COUNT(*) FROM {$table} m LEFT JOIN {$posts} p ON p.ID = m.course_id {$where}"; - - if ( $params !== array() ) { - $sql = $wpdb->prepare( $sql, $params ); - } + $args = array_merge( array( $table, $posts ), $params ); - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared - return (int) $wpdb->get_var( $sql ); + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + // phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter -- WHERE clause is static; values use placeholders. + return (int) $wpdb->get_var( + // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- Search placeholders are built dynamically. + $wpdb->prepare( + "SELECT COUNT(*) FROM %i m LEFT JOIN %i p ON p.ID = m.course_id {$where}", + $args + ) + ); } /** diff --git a/src/Issuance/Queue.php b/src/Issuance/Queue.php index 4ecd47f..56dfbbc 100644 --- a/src/Issuance/Queue.php +++ b/src/Issuance/Queue.php @@ -134,18 +134,20 @@ public function claim( int $limit = 10 ): array { $now = current_time( 'mysql', true ); $stale = gmdate( 'Y-m-d H:i:s', time() - self::LOCK_TIMEOUT ); - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $wpdb->query( $wpdb->prepare( - "UPDATE {$table} SET status = 'pending', locked_at = NULL WHERE status = 'processing' AND locked_at < %s", + 'UPDATE %i SET status = \'pending\', locked_at = NULL WHERE status = \'processing\' AND locked_at < %s', + $table, $stale ) ); - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $ids = $wpdb->get_col( $wpdb->prepare( - "SELECT id FROM {$table} WHERE status = 'pending' AND available_at <= %s ORDER BY id ASC LIMIT %d", + 'SELECT id FROM %i WHERE status = \'pending\' AND available_at <= %s ORDER BY id ASC LIMIT %d', + $table, $now, $limit ) @@ -154,10 +156,11 @@ public function claim( int $limit = 10 ): array { $jobs = array(); foreach ( is_array( $ids ) ? $ids : array() as $id ) { - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $updated = $wpdb->query( $wpdb->prepare( - "UPDATE {$table} SET status = 'processing', locked_at = %s, attempts = attempts + 1, updated_at = %s WHERE id = %d AND status = 'pending'", + 'UPDATE %i SET status = \'processing\', locked_at = %s, attempts = attempts + 1, updated_at = %s WHERE id = %d AND status = \'pending\'', + $table, $now, $now, (int) $id @@ -168,9 +171,9 @@ public function claim( int $limit = 10 ): array { continue; } - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $row = $wpdb->get_row( - $wpdb->prepare( "SELECT * FROM {$table} WHERE id = %d", (int) $id ), + $wpdb->prepare( 'SELECT * FROM %i WHERE id = %d', $table, (int) $id ), ARRAY_A ); @@ -228,8 +231,8 @@ public function fail( int $id, string $error, bool $retryable, ?int $retry_after global $wpdb; $table = $this->table(); - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared - $attempts = (int) $wpdb->get_var( $wpdb->prepare( "SELECT attempts FROM {$table} WHERE id = %d", $id ) ); + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $attempts = (int) $wpdb->get_var( $wpdb->prepare( 'SELECT attempts FROM %i WHERE id = %d', $table, $id ) ); if ( $retryable && $attempts < self::MAX_ATTEMPTS ) { $delay = self::retryDelay( $attempts, $retry_after ); @@ -291,10 +294,11 @@ public function retryFailed(): int { $table = $this->table(); $now = current_time( 'mysql', true ); - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $updated = $wpdb->query( $wpdb->prepare( - "UPDATE {$table} SET status = 'pending', attempts = 0, available_at = %s, locked_at = NULL, updated_at = %s WHERE status = 'failed'", + 'UPDATE %i SET status = \'pending\', attempts = 0, available_at = %s, locked_at = NULL, updated_at = %s WHERE status = \'failed\'', + $table, $now, $now ) @@ -319,10 +323,11 @@ public function retry( int $id ): bool { $table = $this->table(); $now = current_time( 'mysql', true ); - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $updated = $wpdb->query( $wpdb->prepare( - "UPDATE {$table} SET status = 'pending', attempts = 0, available_at = %s, locked_at = NULL, last_error = NULL, updated_at = %s WHERE id = %d", + 'UPDATE %i SET status = \'pending\', attempts = 0, available_at = %s, locked_at = NULL, last_error = NULL, updated_at = %s WHERE id = %d', + $table, $now, $now, $id @@ -348,8 +353,8 @@ public function counts(): array { $table = $this->table(); $rows = $wpdb->get_results( - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared - "SELECT status, COUNT(*) AS total FROM {$table} GROUP BY status", + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $wpdb->prepare( 'SELECT status, COUNT(*) AS total FROM %i GROUP BY status', $table ), ARRAY_A ); @@ -382,9 +387,9 @@ public function recent( int $limit = 50 ): array { $table = $this->table(); $limit = max( 1, min( 200, $limit ) ); - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $rows = $wpdb->get_results( - $wpdb->prepare( "SELECT * FROM {$table} ORDER BY id DESC LIMIT %d", $limit ), + $wpdb->prepare( 'SELECT * FROM %i ORDER BY id DESC LIMIT %d', $table, $limit ), ARRAY_A ); @@ -428,10 +433,11 @@ public function purgeOld( int $days = 30 ): int { $table = $this->table(); $cutoff = gmdate( 'Y-m-d H:i:s', time() - ( max( 1, $days ) * DAY_IN_SECONDS ) ); - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $deleted = $wpdb->query( $wpdb->prepare( - "DELETE FROM {$table} WHERE status IN ('done','failed') AND updated_at < %s", + 'DELETE FROM %i WHERE status IN (\'done\',\'failed\') AND updated_at < %s', + $table, $cutoff ) ); @@ -455,12 +461,13 @@ private function countByStatus( string $dedupe_key, array $statuses ): int { $table = $this->table(); $placeholders = implode( ',', array_fill( 0, count( $statuses ), '%s' ) ); - $args = array_merge( array( $dedupe_key ), $statuses ); + $args = array_merge( array( $table, $dedupe_key ), $statuses ); - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $count = $wpdb->get_var( + // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- Status placeholders are built dynamically. $wpdb->prepare( - "SELECT COUNT(*) FROM {$table} WHERE dedupe_key = %s AND status IN ({$placeholders})", + "SELECT COUNT(*) FROM %i WHERE dedupe_key = %s AND status IN ({$placeholders})", $args ) ); diff --git a/src/Issuance/Worker.php b/src/Issuance/Worker.php index 0d8a2fe..edb0775 100644 --- a/src/Issuance/Worker.php +++ b/src/Issuance/Worker.php @@ -312,7 +312,7 @@ private function describeApiError( ApiException $exception ): string { $detail = $exception->getDetail(); if ( $exception->isPaymentRequired() ) { - return __( 'The workspace needs an active plan before certificates can be issued.', 'verifycate' ); + return __( 'The workspace needs more credits before certificates can be issued.', 'verifycate' ); } if ( $exception->isUnauthorized() ) { diff --git a/src/Support/Logger.php b/src/Support/Logger.php index 8bfbc7c..6ae80a4 100644 --- a/src/Support/Logger.php +++ b/src/Support/Logger.php @@ -107,15 +107,15 @@ public static function recent( int $limit = 200, string $level = '' ): array { $table = $wpdb->prefix . 'verifycate_logs'; if ( '' !== $level ) { - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $rows = $wpdb->get_results( - $wpdb->prepare( "SELECT * FROM {$table} WHERE level = %s ORDER BY id DESC LIMIT %d", $level, $limit ), + $wpdb->prepare( 'SELECT * FROM %i WHERE level = %s ORDER BY id DESC LIMIT %d', $table, $level, $limit ), ARRAY_A ); } else { - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $rows = $wpdb->get_results( - $wpdb->prepare( "SELECT * FROM {$table} ORDER BY id DESC LIMIT %d", $limit ), + $wpdb->prepare( 'SELECT * FROM %i ORDER BY id DESC LIMIT %d', $table, $limit ), ARRAY_A ); } @@ -133,8 +133,8 @@ public static function count(): int { $table = $wpdb->prefix . 'verifycate_logs'; - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared - return (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$table}" ); + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM %i', $table ) ); } /** @@ -146,8 +146,8 @@ public static function clear(): void { global $wpdb; $table = $wpdb->prefix . 'verifycate_logs'; - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared - $wpdb->query( "DELETE FROM {$table}" ); + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $wpdb->query( $wpdb->prepare( 'DELETE FROM %i', $table ) ); } /** @@ -161,7 +161,7 @@ private static function prune(): void { $table = $wpdb->prefix . 'verifycate_logs'; $cutoff = gmdate( 'Y-m-d H:i:s', time() - ( self::RETENTION_DAYS * DAY_IN_SECONDS ) ); - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared - $wpdb->query( $wpdb->prepare( "DELETE FROM {$table} WHERE created_at < %s", $cutoff ) ); + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching + $wpdb->query( $wpdb->prepare( 'DELETE FROM %i WHERE created_at < %s', $table, $cutoff ) ); } } diff --git a/src/Support/Settings.php b/src/Support/Settings.php index d8010cd..56a828b 100644 --- a/src/Support/Settings.php +++ b/src/Support/Settings.php @@ -182,7 +182,7 @@ public function canWriteCertificates(): bool { * @return bool */ public function isReadyToIssue(): bool { - return $this->isConnected() && $this->isSeatLive() && $this->canWriteCertificates(); + return $this->isConnected() && $this->canWriteCertificates(); } /** @@ -195,10 +195,6 @@ public function connectionIssue(): string { return ''; } - if ( ! $this->isSeatLive() ) { - return __( 'This workspace has no active Verifycate plan. Activate a plan before issuing certificates.', 'verifycate' ); - } - if ( ! $this->canWriteCertificates() ) { return __( 'This API key can read certificates but cannot issue them. Create a key with the certificates:write scope and reconnect.', 'verifycate' ); } diff --git a/tests/unit/SettingsTest.php b/tests/unit/SettingsTest.php index d41d77b..5da3b9b 100644 --- a/tests/unit/SettingsTest.php +++ b/tests/unit/SettingsTest.php @@ -194,4 +194,23 @@ public function test_read_only_key_is_not_ready(): void { $this->assertFalse( $settings->isReadyToIssue() ); $this->assertNotSame( '', $settings->connectionIssue() ); } + + /** + * API access does not depend on a Pro seat. + */ + public function test_unseated_workspace_can_still_issue(): void { + Functions\expect( 'update_option' )->once(); + + $settings = new Settings( array( 'api_key' => Crypto::encrypt( 'vc_key' ) ) ); + $settings->setResolvedWorkspace( + 'acme', + array( 'certificates:read', 'certificates:write' ), + false, + false + ); + + $this->assertFalse( $settings->isSeatLive() ); + $this->assertTrue( $settings->isReadyToIssue() ); + $this->assertSame( '', $settings->connectionIssue() ); + } } diff --git a/uninstall.php b/uninstall.php index 3afa8a6..3070f02 100644 --- a/uninstall.php +++ b/uninstall.php @@ -41,8 +41,8 @@ foreach ( array( 'mappings', 'jobs', 'logs' ) as $verifycate_table ) { $verifycate_name = $wpdb->prefix . 'verifycate_' . $verifycate_table; - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared - $wpdb->query( "DROP TABLE IF EXISTS `{$verifycate_name}`" ); + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange + $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $verifycate_name ) ); } }; diff --git a/verifycate.php b/verifycate.php index 6b47b74..45dfad5 100644 --- a/verifycate.php +++ b/verifycate.php @@ -74,14 +74,6 @@ static function ( string $class_name ): void { return; } -add_action( - 'plugins_loaded', - static function (): void { - load_plugin_textdomain( 'verifycate', false, dirname( VERIFYCATE_BASENAME ) . '/languages' ); - }, - 1 -); - add_action( 'plugins_loaded', static function (): void {