|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\WooCommerce; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Integrations\IntegrationHooks; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Integrations\WooCommerce\Controllers\Controller; |
|
7
|
|
|
use GeminiLabs\SiteReviews\Integrations\WooCommerce\Controllers\ExperimentsController; |
|
8
|
|
|
use GeminiLabs\SiteReviews\Integrations\WooCommerce\Controllers\ImportController; |
|
9
|
|
|
use GeminiLabs\SiteReviews\Integrations\WooCommerce\Controllers\IntegrationController; |
|
10
|
|
|
use GeminiLabs\SiteReviews\Integrations\WooCommerce\Controllers\MainController; |
|
11
|
|
|
use GeminiLabs\SiteReviews\Integrations\WooCommerce\Controllers\ProductController; |
|
12
|
|
|
use GeminiLabs\SiteReviews\Integrations\WooCommerce\Controllers\RestApiController; |
|
13
|
|
|
|
|
14
|
|
|
class Hooks extends IntegrationHooks |
|
15
|
|
|
{ |
|
16
|
|
|
public function run(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$this->hook(Controller::class, [ |
|
19
|
|
|
['declareHposCompatibility', 'before_woocommerce_init'], |
|
20
|
|
|
['filterOrphanedOptions', 'site-reviews/option/addon/woocommerce/enabled', 10, 3], |
|
21
|
|
|
['filterOrphanedOptions', 'site-reviews/option/addon/woocommerce/style', 10, 3], |
|
22
|
|
|
['filterOrphanedOptions', 'site-reviews/option/addon/woocommerce/summary', 10, 3], |
|
23
|
|
|
['filterOrphanedOptions', 'site-reviews/option/addon/woocommerce/reviews', 10, 3], |
|
24
|
|
|
['filterOrphanedOptions', 'site-reviews/option/addon/woocommerce/form', 10, 3], |
|
25
|
|
|
['filterOrphanedOptions', 'site-reviews/option/addon/woocommerce/sorting', 10, 3], |
|
26
|
|
|
['filterOrphanedOptions', 'site-reviews/option/addon/woocommerce/display_empty', 10, 3], |
|
27
|
|
|
['filterOrphanedOptions', 'site-reviews/option/addon/woocommerce/wp_comments', 10, 3], |
|
28
|
|
|
['filterSettings', 'site-reviews/settings'], |
|
29
|
|
|
['filterSettingsCallback', 'site-reviews/settings/sanitize', 10, 2], |
|
30
|
|
|
['filterSubsubsub', 'site-reviews/integration/subsubsub'], |
|
31
|
|
|
['renderNotice', 'admin_init'], |
|
32
|
|
|
['renderSettings', 'site-reviews/settings/woocommerce'], |
|
33
|
|
|
]); |
|
34
|
|
|
$this->hook(ImportController::class, [ |
|
35
|
|
|
['filterTools', 'site-reviews/tools/general'], |
|
36
|
|
|
['importProductReviewsAjax', 'site-reviews/route/ajax/import-product-reviews'], |
|
37
|
|
|
['migrateProductRatingsAjax', 'site-reviews/route/ajax/migrate-product-ratings'], |
|
38
|
|
|
]); |
|
39
|
|
|
if ($this->isEnabled()) { |
|
40
|
|
|
$this->runIfEnabled(); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function runIfEnabled(): void |
|
45
|
|
|
{ |
|
46
|
|
|
remove_action('comment_post', ['WC_Comments', 'add_comment_purchase_verification'], 10); |
|
47
|
|
|
remove_action('wp_update_comment_count', ['WC_Comments', 'clear_transients'], 10); |
|
48
|
|
|
remove_filter('comments_open', ['WC_Comments', 'comments_open'], 10); |
|
49
|
|
|
if ('yes' === $this->option('integrations.woocommerce.wp_comments')) { |
|
50
|
|
|
$this->hook(ExperimentsController::class, [ |
|
51
|
|
|
['filterProductCommentMeta', 'get_comment_metadata', 20, 4], |
|
52
|
|
|
['filterProductCommentsQuery', 'comments_pre_query', 20, 2], |
|
53
|
|
|
]); |
|
54
|
|
|
} |
|
55
|
|
|
$this->hook(IntegrationController::class, [ |
|
56
|
|
|
['filterDiviDynamicAssetsList', 'divi_frontend_assets_dynamic_assets_global_assets_list', 10, 2], |
|
57
|
|
|
]); |
|
58
|
|
|
$this->hook(MainController::class, [ |
|
59
|
|
|
['enqueueInlineAdminStyles', 'admin_enqueue_scripts', 20], |
|
60
|
|
|
['filterInlineStyles', 'site-reviews/enqueue/public/inline-styles', 20], |
|
61
|
|
|
['filterMenuPendingCount', 'woocommerce_product_reviews_pending_count'], |
|
62
|
|
|
['filterProductCommentStatus', 'get_default_comment_status', 10, 3], |
|
63
|
|
|
['filterProductSettings', 'woocommerce_get_settings_products', 10, 2], |
|
64
|
|
|
['filterPublicInlineScript', 'site-reviews/enqueue/public/inline-script/after'], |
|
65
|
|
|
['filterRankmathSchemaPreview', 'site-reviews/schema/generate', 10, 2], |
|
66
|
|
|
['filterRatingOption', 'option_woocommerce_enable_review_rating'], |
|
67
|
|
|
['filterRatingOption', 'option_woocommerce_review_rating_required'], |
|
68
|
|
|
['filterReviewAuthorTagValue', 'site-reviews/review/value/author', 10, 2], |
|
69
|
|
|
['filterReviewCallbackHasVerifiedOwner', 'site-reviews/review/call/hasVerifiedOwner'], |
|
70
|
|
|
['filterReviewCallbackProduct', 'site-reviews/review/call/product'], |
|
71
|
|
|
['redirectProductReviews', 'admin_init'], |
|
72
|
|
|
['registerElementorWidgets', 'elementor/widgets/register', 20], |
|
73
|
|
|
['registerWidgets', 'widgets_init', 20], |
|
74
|
|
|
['removeWoocommerceReviews', 'woocommerce_register_post_type_product'], |
|
75
|
|
|
['renderNotice', 'admin_notices'], |
|
76
|
|
|
['verifyProductOwner', 'site-reviews/review/created', 20], |
|
77
|
|
|
]); |
|
78
|
|
|
$this->hook(ProductController::class, [ |
|
79
|
|
|
['filterCommentsTemplate', 'comments_template', 50], |
|
80
|
|
|
['filterGetRatingHtml', 'woocommerce_product_get_rating_html', 20, 3], |
|
81
|
|
|
['filterGetStarRatingHtml', 'woocommerce_get_star_rating_html', 10, 3], |
|
82
|
|
|
['filterProductAverageRating', 'woocommerce_product_get_average_rating', 10, 2], |
|
83
|
|
|
['filterProductDataTabs', 'woocommerce_product_data_tabs'], |
|
84
|
|
|
['filterProductMetaQuery', 'woocommerce_product_query_meta_query', 20], |
|
85
|
|
|
['filterProductPostClauses', 'woocommerce_get_catalog_ordering_args', 20, 2], |
|
86
|
|
|
['filterProductRatingCounts', 'woocommerce_product_get_rating_counts', 10, 2], |
|
87
|
|
|
['filterProductReviewCount', 'woocommerce_product_get_review_count', 10, 2], |
|
88
|
|
|
['filterProductTabs', 'woocommerce_product_tabs', 50], |
|
89
|
|
|
['filterProductTaxQuery', 'woocommerce_product_query_tax_query', 20], |
|
90
|
|
|
['filterStructuredData', 'woocommerce_structured_data_product', 10, 2], |
|
91
|
|
|
['filterWidgetArgsTopRatedProducts', 'woocommerce_top_rated_products_widget_args'], |
|
92
|
|
|
['filterWoocommerceTemplate', 'wc_get_template', 20, 2], |
|
93
|
|
|
['modifyProductQuery', 'pre_get_posts'], |
|
94
|
|
|
['printInlineStyle', 'admin_head'], |
|
95
|
|
|
['registerMetaboxes', 'add_meta_boxes_product', 20], |
|
96
|
|
|
['renderBulkEditField', 'bulk_edit_custom_box', 10, 2], |
|
97
|
|
|
['renderLoopRating', 'site-reviews/woocommerce/render/loop/rating', 5], |
|
98
|
|
|
['renderProductDataPanel', 'woocommerce_product_data_panels'], |
|
99
|
|
|
['renderQuickEditField', 'quick_edit_custom_box', 5, 2], |
|
100
|
|
|
['renderSingleProductRating', 'site-reviews/woocommerce/render/single-product/rating', 5], |
|
101
|
|
|
['renderSingleProductReviews', 'site-reviews/woocommerce/render/single-product-reviews', 5], |
|
102
|
|
|
['updateProductData', 'woocommerce_admin_process_product_object'], |
|
103
|
|
|
['updateProductRatingCounts', 'site-reviews/ratings/count/post', 10, 2], |
|
104
|
|
|
]); |
|
105
|
|
|
$this->hook(RestApiController::class, [ |
|
106
|
|
|
['filterRestEndpoints', 'rest_endpoints'], |
|
107
|
|
|
['filterRestNamespaces', 'woocommerce_rest_api_get_rest_namespaces'], |
|
108
|
|
|
['filterRestPermissions', 'woocommerce_rest_check_permissions', 10, 4], |
|
109
|
|
|
['filterSqlJoin', 'site-reviews/query/sql/join', 10, 3], |
|
110
|
|
|
['filterSqlOrderBy', 'site-reviews/query/sql/order-by', 10, 3], |
|
111
|
|
|
]); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
protected function isEnabled(): bool |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->isInstalled() |
|
117
|
|
|
&& 'yes' === $this->option('integrations.woocommerce.enabled') |
|
118
|
|
|
&& 'yes' === get_option('woocommerce_enable_reviews', 'yes'); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
protected function isInstalled(): bool |
|
122
|
|
|
{ |
|
123
|
|
|
return class_exists('WooCommerce') |
|
124
|
|
|
&& function_exists('WC'); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|