PluginProbe
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More / 2.1.0
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More v2.1.0
2.3.0 2.2.0 2.1.1 2.1.0 2.0.0 1.10.0 1.9.1 1.9.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 All 59 releases
storeengine / includes / hooks.php

hooks.php in StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More 2.1.0, at includes/hooks.php

148 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace StoreEngine;
4
5 use stdClass;
6 use StoreEngine\Classes\FrontendRequestHandler;
7 use StoreEngine\Compatibility\Elementor;
8 use StoreEngine\Hooks\Integration;
9 use StoreEngine\hooks\Kses;
10 use StoreEngine\hooks\Payment;
11 use StoreEngine\Hooks\PermissionsAndCapabilities;
12 use StoreEngine\Utils\Formatting;
13 use StoreEngine\Utils\Geolocation;
14 use StoreEngine\Utils\Helper;
15 use WP_Post;
16
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 class Hooks {
22
23 public static function init() {
24 PermissionsAndCapabilities::init();
25 Formatting::init_hooks();
26 Kses::init();
27 Payment::init();
28 Hooks\Price::init();
29 Integration::init();
30 Hooks\AfterPurchase::init();
31
32 // Compatibility with external plugins
33 Elementor::init();
34
35 /**
36 * @see \WC_Comments::exclude_order_comments()
37 * @see \WC_Comments::exclude_order_comments_from_feed_where()
38 */
39 add_filter( 'comments_clauses', [ __CLASS__, 'exclude_order_comments' ] );
40 add_filter( 'comment_feed_where', [ __CLASS__, 'exclude_order_comments_from_feed_where' ] );
41
42 FrontendRequestHandler::init();
43
44 add_filter( 'storeengine/template/get_content', [ __CLASS__, 'remove_empty_spaces' ], -10, 2 );
45 add_filter( 'do_shortcode_tag', [ __CLASS__, 'remove_empty_spaces' ], -10, 2 );
46
47 add_action( 'save_post', [ __CLASS__, 'save_post' ], 10, 2 );
48 add_action( 'delete_post', [ __CLASS__, 'delete_post' ], 10, 2 );
49
50 add_filter( 'storeengine_settings', [ __CLASS__, 'set_maxmind_database_path' ] );
51 add_filter( 'storeengine/api/settings', [ __CLASS__, 'set_maxmind_database_path' ] );
52 add_filter( 'storeengine/geolocation/geo-locate-ip', [ Geolocation::class, 'maxmind_locate_ip' ], 10, 2 );
53
54 self::handle_cache_last_changed();
55 }
56
57 /**
58 * @param stdClass $settings
59 *
60 * @return stdClass
61 */
62 public static function set_maxmind_database_path( stdClass $settings ): stdClass {
63 $settings->maxmind_db_path = Geolocation::get_maxmind_db_path();
64
65 return $settings;
66 }
67
68 /**
69 * @return void
70 * @see update_metadata()
71 * @see delete_metadata()
72 * @see add_metadata()
73 */
74 protected static function handle_cache_last_changed() {
75 $cache_groups = [
76 'payment_token' => 'storeengine_payment_tokenmeta',
77 'order_item' => 'storeengine_order_item_meta',
78 'order' => 'storeengine_orders_meta',
79 ];
80
81 foreach ( $cache_groups as $meta_type => $cache_group ) {
82 add_action( "added_{$meta_type}_meta", fn() => wp_cache_set_last_changed( $cache_group ) );
83 add_action( "updated_{$meta_type}_meta", fn() => wp_cache_set_last_changed( $cache_group ) );
84 add_action( "deleted_{$meta_type}_meta", fn() => wp_cache_set_last_changed( $cache_group ) );
85 }
86 }
87
88 /**
89 * Exclude order comments from queries and RSS.
90 *
91 * This code should exclude shop_order comments from queries. Some queries (like the recent comments widget on the dashboard) are hardcoded.
92 * and are not filtered, however, the code current_user_can( 'read_post', $comment->comment_post_ID ) should keep them safe since only admin and.
93 * shop managers can view orders anyway.
94 *
95 * The frontend view order pages get around this filter by using remove_filter('comments_clauses', array( 'WC_Comments' ,'exclude_order_comments'), 10, 1 );
96 *
97 * @param array $clauses A compacted array of comment query clauses.
98 *
99 * @return array
100 */
101 public static function exclude_order_comments( array $clauses ): array {
102 $clauses['where'] .= ( $clauses['where'] ? ' AND ' : '' ) . " comment_type != 'order_note' ";
103
104 return $clauses;
105 }
106
107 public static function include_order_comments( array $clauses ): array {
108 $clauses['where'] .= ( $clauses['where'] ? ' AND ' : '' ) . " comment_type = 'order_note' AND comment_agent = 'StoreEngine' ";
109
110 return $clauses;
111 }
112
113 /**
114 * Exclude order comments from queries and RSS.
115 *
116 * @param string $where The WHERE clause of the query.
117 *
118 * @return string
119 */
120 public static function exclude_order_comments_from_feed_where( string $where ): string {
121 return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'order_note' ";
122 }
123
124 /**
125 * Cleanup empty extra whitespaces.
126 *
127 * @param mixed|string $content
128 * @param string $tag
129 *
130 * @return mixed|string
131 */
132 public static function remove_empty_spaces( $content, string $tag ) {
133 if ( ! Helper::is_fse_theme() || ( ! str_starts_with( $tag, 'storeengine_' ) && ! str_starts_with( $tag, 'academy_' ) ) ) {
134 return $content;
135 }
136
137 return Formatting::clean_html_whitespaces( (string) $content );
138 }
139
140 public static function save_post( $post_id, WP_Post $post ) {
141 wp_cache_set( 'storeengine:get_page_by_title:' . sanitize_title( $post->post_title ), absint( $post_id ), $post->post_type );
142 }
143
144 public static function delete_post( $post_id, WP_Post $post ) {
145 wp_cache_delete( 'storeengine:get_page_by_title:' . sanitize_title( $post->post_title ), $post->post_type );
146 }
147 }
148