to be deleted. * * @return bool */ public function delete_by_id( int $id ): bool { global $wpdb; if ( ! $wpdb->delete( $this->get_table(), array( 'url_id' => $id ) ) ) { return false; } unset( $this->cache ); return true; } /** * Delete the entirev approved directory list. * * @return bool */ public function delete_all(): bool { global $wpdb; if ( ! $wpdb->query( "DELETE FROM {$this->get_table()}" ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared return false; } unset( $this->cache ); return true; } /** * Enable the approved directory identitied by the supplied ID. * * @param int $id The ID of the rule to be deleted. * * @return bool */ public function enable_by_id( int $id ): bool { global $wpdb; $table = $this->get_table(); if ( ! $wpdb->update( $table, array( 'enabled' => 1 ), array( 'url_id' => $id ) ) ) { return false; } unset( $this->cache ); return true; } /** * Disable the approved directory identitied by the supplied ID. * * @param int $id The ID of the rule to be deleted. * * @return bool */ public function disable_by_id( int $id ): bool { global $wpdb; if ( ! $wpdb->update( $this->get_table(), array( 'enabled' => 0 ), array( 'url_id' => $id ) ) ) { return false; } unset( $this->cache ); return true; } /** * Enables all Approved Download Directory rules in a single operation. * * @return bool */ public function enable_all(): bool { global $wpdb; if ( ! $wpdb->query( "UPDATE {$this->get_table()} SET enabled = 1" ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared return false; } unset( $this->cache ); return true; } /** * Disables all Approved Download Directory rules in a single operation. * * @return bool */ public function disable_all(): bool { global $wpdb; // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared if ( ! $wpdb->query( "UPDATE {$this->get_table()} SET enabled = 0" ) ) { return false; } unset( $this->cache ); return true; } /** * Indicates the number of approved directories that are enabled (or disabled, if optional * param $enabled is set to false). * * @param bool $enabled Controls whether enabled or disabled directory rules are counted. * * @return int */ public function count( bool $enabled = true ): int { global $wpdb; $table = $this->get_table(); return (int) $wpdb->get_var( $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared "SELECT COUNT(*) FROM {$table} WHERE enabled = %d", $enabled ? 1 : 0 ) ); } }