Initial public release of BreznFlow, an n8n workflow renderer for WordPress. Fully PHPCS-compliant (WordPress Coding Standards), security-hardened, and ready for WordPress.org plugin review. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
55 lines
1.2 KiB
PHP
55 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* Tracks shortcode render counts per workflow.
|
|
*
|
|
* @package BreznFlow
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
namespace BreznFlow\Features;
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Tracks and retrieves view counts for workflow posts.
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
class ViewCounter {
|
|
/**
|
|
* Registers the view counter hooks.
|
|
*
|
|
* @since 1.0.0
|
|
* @return void
|
|
*/
|
|
public function register(): void {
|
|
// View counting is triggered from Shortcode::render() directly.
|
|
// This class provides the static increment/get methods.
|
|
}
|
|
|
|
/**
|
|
* Increments the view count for a workflow post.
|
|
*
|
|
* @param int $post_id Workflow post ID.
|
|
*/
|
|
public static function increment( int $post_id ): void {
|
|
$settings = get_option( 'breznflow_settings', array() );
|
|
if ( isset( $settings['view_counting'] ) && ! $settings['view_counting'] ) {
|
|
return;
|
|
}
|
|
$current = (int) get_post_meta( $post_id, '_breznflow_view_count', true );
|
|
update_post_meta( $post_id, '_breznflow_view_count', $current + 1 );
|
|
}
|
|
|
|
/**
|
|
* Gets the view count for a workflow post.
|
|
*
|
|
* @param int $post_id Workflow post ID.
|
|
* @return int View count.
|
|
*/
|
|
public static function get( int $post_id ): int {
|
|
return (int) get_post_meta( $post_id, '_breznflow_view_count', true );
|
|
}
|
|
}
|