PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.1.2
ShopBuilder – WooCommerce Builder For Elementor v2.1.2
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Controllers / Hooks / ActionHooks.php

ActionHooks.php in ShopBuilder – WooCommerce Builder For Elementor 2.1.2, at app/Controllers/Hooks/ActionHooks.php

210 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main ActionHooks class.
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Controllers\Hooks;
9
10 use RadiusTheme\SB\Helpers\Fns;
11 use RadiusTheme\SB\Models\GeneralList;
12 use RadiusTheme\SB\Helpers\BuilderFns;
13 use RadiusTheme\SB\Models\TemplateSettings;
14 use RadiusTheme\SB\Elementor\Render\WCRender;
15
16 defined( 'ABSPATH' ) || exit();
17
18 /**
19 * Main ActionHooks class.
20 */
21 class ActionHooks {
22 /**
23 * Init Hooks.
24 *
25 * @return void
26 */
27 public static function init_hooks() {
28 add_action( 'wp_head', [ __CLASS__, 'og_metatags_for_sharing' ], 1 );
29 add_action( 'woocommerce_share', [ __CLASS__, 'shopbuilder_share' ], 20 );
30 add_action( 'rtsb/wcqv/product/summary', [ __CLASS__, 'shopbuilder_share' ], 40 );
31 add_action( 'rtsb/shop/product/image', [ __CLASS__, 'render_image' ], 10, 2 );
32
33 add_action(
34 'admin_init',
35 function () {
36 remove_post_type_support( BuilderFns::$post_type_tb, 'revisions' );
37 }
38 );
39 add_action( 'deleted_post', [ __CLASS__, 'deleted_post' ], 10, 2 );
40 add_action( 'rtsb/elements/render/before_query', [ __CLASS__, 'modify_wc_query_args' ] );
41 add_action( 'rtsb/elements/render/after_query', [ __CLASS__, 'reset_wc_query_args' ] );
42 }
43 /**
44 * Meta tags for social sharing.
45 *
46 * @return void
47 */
48 public static function deleted_post( $post_id, $post ) {
49 if ( BuilderFns::$post_type_tb !== $post->post_type ) {
50 return;
51 }
52 $options = BuilderFns::option_name_for_specific_product_set_default( $post_id );
53
54 if ( TemplateSettings::instance()->get_option( $options ) ) {
55 TemplateSettings::instance()->delete_option( $options );
56 }
57
58 $template_options = BuilderFns::option_name_by_template_id( $post_id );
59 if ( TemplateSettings::instance()->get_option( $template_options ) ) {
60 TemplateSettings::instance()->delete_option( $template_options );
61 }
62
63 $archive_options = BuilderFns::archive_option_name_by_template_id( $post_id );
64 if ( TemplateSettings::instance()->get_option( $archive_options ) ) {
65 TemplateSettings::instance()->delete_option( $archive_options );
66 }
67
68 $category_options = BuilderFns::option_name_for_specific_category_set_default( $post_id );
69 if ( TemplateSettings::instance()->get_option( $category_options ) ) {
70 TemplateSettings::instance()->delete_option( $category_options );
71 }
72
73 $selected_category_options = BuilderFns::archive_option_name_by_template_id( $post_id );
74 if ( TemplateSettings::instance()->get_option( $selected_category_options ) ) {
75 TemplateSettings::instance()->delete_option( $selected_category_options );
76 }
77
78 global $wpdb;
79 // Prepare and execute the SQL query.
80 $sql = $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d", BuilderFns::$view_template_for_products_meta, $post_id );
81 $wpdb->query( $sql );
82
83 // Prepare and execute the SQL query.
84 $sql = $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE meta_key = %s AND meta_value = %d", BuilderFns::$view_template_for_archive_meta, $post_id );
85 $wpdb->query( $sql );
86
87 }
88 /**
89 * Meta tags for social sharing.
90 *
91 * @return void
92 */
93 public static function shopbuilder_share() {
94 $generalList = GeneralList::instance()->get_data();
95
96 if (
97 empty( $generalList['social_share']['share_platforms_to_product_page'] ) ||
98 'on' !== $generalList['social_share']['share_platforms_to_product_page'] ||
99 empty( $generalList['social_share']['share_platforms'] )
100 ) {
101 return;
102 }
103
104 $share_platforms = [];
105
106 foreach ( $generalList['social_share']['share_platforms'] as $value ) {
107 $share_platforms[ $value ] = [
108 'share_items' => $value,
109 'share_text' => ucwords( $value ),
110 ];
111 }
112
113 $settings['share_platforms'] = $share_platforms;
114 $settings['layout'] = ! empty( $generalList['social_share']['share_icon_layout'] ) ? $generalList['social_share']['share_icon_layout'] : 1;
115 $settings['show_share_icon'] = 1;
116
117 // TODO:: Implement Later ! empty( $generalList['social_share']['share_icon_show_to_product_page'] ) && 'on' === $generalList['social_share']['share_icon_show_to_product_page'];
118 Fns::print_html( WCRender::instance()->social_share_view( 'elementor/general/social-share', $settings ), true );
119 }
120
121 /**
122 * Meta tags for social sharing.
123 *
124 * @return void
125 */
126 public static function og_metatags_for_sharing() {
127 global $post;
128
129 if ( ! isset( $post ) ) {
130 return;
131 }
132
133 if ( ! is_singular( 'product' ) ) {
134 return;
135 }
136
137 Fns::print_html( '<meta property="og:url" content="' . get_the_permalink() . '" />', true );
138 Fns::print_html( '<meta property="og:type" content="article" />', true );
139 Fns::print_html( '<meta property="og:title" content="' . $post->post_title . '" />', true );
140 Fns::print_html( '<meta property="og:description" content="' . wp_trim_words( $post->post_content, 150 ) . '" />' );
141
142 $attachment = get_the_post_thumbnail_url();
143
144 if ( ! empty( $attachment ) ) {
145 Fns::print_html( '<meta property="og:image" content="' . $attachment . '" />', true );
146 }
147
148 Fns::print_html( '<meta property="og:site_name" content="' . get_bloginfo( 'name' ) . '" />', true );
149 Fns::print_html( '<meta name="twitter:card" content="summary" />', true );
150 }
151
152 /**
153 * Render image.
154 *
155 * @param array $args Image args.
156 * @param array $settings Settings array.
157 *
158 * @return void
159 */
160 public static function render_image( $args, $settings ) {
161 if ( $args['image_link'] ) {
162 $aria_label = esc_attr(
163 /* translators: Product Name */
164 sprintf( __( 'Image link for Product: %s', 'shopbuilder' ), $args['title'] )
165 );
166 ?>
167 <figure>
168 <a class="woocommerce-LoopProduct-link rtsb-img-link" href="<?php echo esc_url( $args['p_link'] ); ?>" aria-label="<?php echo esc_attr( $aria_label ); ?>">
169 <?php
170 Fns::get_product_image( $args['img_html'], $args['hover_img_html'] );
171 ?>
172 </a>
173 </figure>
174 <?php
175 } else {
176 echo '<figure class="rtsb-img-link">';
177 Fns::get_product_image( $args['img_html'], $args['hover_img_html'] );
178 echo '</figure>';
179 }
180 }
181
182 /**
183 * Modify WooCommerce query arguments for product retrieval.
184 *
185 * @param array $settings The settings array.
186 *
187 * @return void
188 */
189 public static function modify_wc_query_args( $settings ) {
190 if ( ( isset( $settings['tax_relation'] ) && 'OR' === $settings['tax_relation'] ) ||
191 ( isset( $settings['relation'] ) && 'OR' === $settings['relation'] ) ) {
192 add_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args' ], 10, 2 );
193 }
194 }
195
196 /**
197 * Reset WooCommerce query arguments for product retrieval.
198 *
199 * @param array $settings The settings array.
200 *
201 * @return void
202 */
203 public static function reset_wc_query_args( $settings ) {
204 if ( ( isset( $settings['tax_relation'] ) && 'OR' === $settings['tax_relation'] ) ||
205 ( isset( $settings['relation'] ) && 'OR' === $settings['relation'] ) ) {
206 remove_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args' ] );
207 }
208 }
209 }
210