| 1 |
<?php |
| 2 |
|
| 3 |
namespace ReviewX\Form; |
| 4 |
|
| 5 |
use ReviewX\CPT\CptHelper; |
| 6 |
use ReviewX\Utilities\Auth\Client; |
| 7 |
class ReviewForm |
| 8 |
{ |
| 9 |
protected $cptHelper; |
| 10 |
public function __construct() |
| 11 |
{ |
| 12 |
$this->cptHelper = new CptHelper(); |
| 13 |
} |
| 14 |
public static function post_type_support() |
| 15 |
{ |
| 16 |
if (Client::getSync()) { |
| 17 |
// Retrieve settings |
| 18 |
$enabled_post_types = (new self())->cptHelper->enabledCPT(); |
| 19 |
// Dynamically add comment support for enabled post types |
| 20 |
foreach ($enabled_post_types as $post_type) { |
| 21 |
if (post_type_exists($post_type)) { |
| 22 |
add_post_type_support($post_type, 'comments'); |
| 23 |
} |
| 24 |
} |
| 25 |
} |
| 26 |
} |
| 27 |
public static function comments_template_init($default) |
| 28 |
{ |
| 29 |
if (Client::getSync()) { |
| 30 |
// Retrieve settings |
| 31 |
$enabled_post_types = (new self())->cptHelper->enabledCPT(); |
| 32 |
// Check if the current post type is enabled |
| 33 |
if (is_singular($enabled_post_types)) { |
| 34 |
// Exclude WooCommerce account page |
| 35 |
if (\class_exists('WooCommerce') && is_account_page()) { |
| 36 |
// Do nothing on WooCommerce front-end user dashboard |
| 37 |
} else { |
| 38 |
// Invoke custom handler |
| 39 |
if (\class_exists('ReviewX\\Handlers\\CommentBoxHandle')) { |
| 40 |
(new \ReviewX\Handlers\CommentBoxHandle())->__invoke(); |
| 41 |
} |
| 42 |
// Load custom template if it exists |
| 43 |
$custom_template = \dirname(__FILE__) . '/widget.php'; |
| 44 |
if (\file_exists($custom_template)) { |
| 45 |
return $custom_template; |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
// Fallback to default template |
| 50 |
return $default; |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
|