PluginProbe ʕ •ᴥ•ʔ
YITH WooCommerce Wishlist / 4.0.1
YITH WooCommerce Wishlist v4.0.1
trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.17 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.18 3.0.19 3.0.2 3.0.20 3.0.21 3.0.22 3.0.23 3.0.25 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.10.0 3.11.0 3.12.0 3.13.0 3.14.0 3.15.0 3.16.0 3.17.0 3.18.0 3.19.0 3.2.0 3.20.0 3.21.0 3.22.0 3.23.0 3.24.0 3.25.0 3.26.0 3.27.0 3.28.0 3.29.0 3.3.0 3.30.0 3.31.0 3.32.0 3.33.0 3.34.0 3.35.0 3.36.0 3.37.0 3.38.0 3.4.0 3.5.0 3.6.0 3.7.0 3.8.0 3.9.0 4.0.0 4.0.1 4.1.0 4.10.0 4.10.1 4.10.2 4.11.0 4.12.0 4.13.0 4.14.0 4.15.0 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.8.0 4.9.0
yith-woocommerce-wishlist / includes / class-yith-wcwl-shortcode.php
yith-woocommerce-wishlist / includes Last commit date
abstracts 1 year ago admin 1 year ago data-stores 1 year ago legacy 1 year ago rest-api 1 year ago traits 1 year ago widgets 2 years ago abstract-yith-wcwl-db.php 1 year ago class-yith-wcwl-add-to-wishlist-button.php 1 year ago class-yith-wcwl-ajax-handler.php 1 year ago class-yith-wcwl-autoloader.php 1 year ago class-yith-wcwl-cron.php 1 year ago class-yith-wcwl-exception.php 1 year ago class-yith-wcwl-form-handler.php 1 year ago class-yith-wcwl-frontend.php 1 year ago class-yith-wcwl-install.php 1 year ago class-yith-wcwl-privacy.php 1 year ago class-yith-wcwl-rendering-method-frontend-handler.php 1 year ago class-yith-wcwl-session.php 1 year ago class-yith-wcwl-shortcode.php 1 year ago class-yith-wcwl-wishlist-factory.php 1 year ago class-yith-wcwl-wishlist-item.php 1 year ago class-yith-wcwl-wishlist.php 1 year ago class-yith-wcwl-wishlists.php 1 year ago class-yith-wcwl.php 1 year ago functions-yith-wcwl-update.php 1 year ago functions-yith-wcwl.php 1 year ago
class-yith-wcwl-shortcode.php
645 lines
1 <?php
2 /**
3 * Shortcodes class
4 *
5 * @package YITH\Wishlist\Classes
6 * @author YITH <plugins@yithemes.com>
7 * @version 3.0.0
8 */
9
10 if ( ! defined( 'YITH_WCWL' ) ) {
11 exit;
12 } // Exit if accessed directly
13
14 if ( ! class_exists( 'YITH_WCWL_Shortcode' ) ) {
15 /**
16 * YITH WCWL Shortcodes
17 *
18 * @since 1.0.0
19 */
20 class YITH_WCWL_Shortcode {
21 use YITH_WCWL_Rendering_Method_Access_Trait;
22
23 /**
24 * Init shortcodes available for the plugin
25 *
26 * @return void
27 */
28 public static function init() {
29 // register shortcodes.
30 add_shortcode( 'yith_wcwl_wishlist', array( 'YITH_WCWL_Shortcode', 'wishlist' ) );
31 add_shortcode( 'yith_wcwl_add_to_wishlist', array( 'YITH_WCWL_Shortcode', 'add_to_wishlist' ) );
32
33 // register gutenberg blocks.
34 add_action( 'init', array( 'YITH_WCWL_Shortcode', 'register_gutenberg_blocks' ) );
35 add_action( 'yith_plugin_fw_gutenberg_before_do_shortcode', array( 'YITH_WCWL_Shortcode', 'fix_for_gutenberg_blocks' ), 10, 1 );
36
37 // register elementor widgets.
38 add_action( 'init', array( 'YITH_WCWL_Shortcode', 'init_elementor_widgets' ) );
39 }
40
41 /* === GUTENBERG BLOCKS === */
42
43 /**
44 * Register available gutenberg blocks
45 *
46 * @return void
47 */
48 public static function register_gutenberg_blocks() {
49 self::register_gutenberg_scripts();
50 YITH_WCWL_Add_To_Wishlist_Button::get_class()::maybe_register_scripts();
51 $blocks = array(
52 'yith-wcwl-add-to-wishlist' => array(
53 'style' => self::is_php_templates_mode() ? 'yith-wcwl-main' : 'yith-wcwl-add-to-wishlist',
54 'script' => self::is_php_templates_mode() ? 'jquery-yith-wcwl' : array( 'yith-wcwl-add-to-wishlist', 'yith-wcwl-add-to-wishlist-gutenberg' ),
55 'title' => _x( 'YITH Add to wishlist', '[gutenberg]: block name', 'yith-woocommerce-wishlist' ),
56 'description' => _x( 'Shows Add to wishlist button', '[gutenberg]: block description', 'yith-woocommerce-wishlist' ),
57 'shortcode_name' => 'yith_wcwl_add_to_wishlist',
58 'attributes' => array(
59 'product_id' => array(
60 'type' => 'text',
61 'label' => __( 'ID of the product to add to the wishlist (leave empty to use the global product)', 'yith-woocommerce-wishlist' ),
62 'default' => '',
63 ),
64 'wishlist_url' => array(
65 'type' => 'text',
66 'label' => __( 'URL of the wishlist page (leave empty to use the default settings)', 'yith-woocommerce-wishlist' ),
67 'default' => '',
68 ),
69 'label' => array(
70 'type' => 'text',
71 'label' => __( 'Button label (leave empty to use the default settings)', 'yith-woocommerce-wishlist' ),
72 'default' => '',
73 ),
74 'browse_wishlist_text' => array(
75 'type' => 'text',
76 'label' => __( '"Browse wishlist" label (leave empty to use the default settings)', 'yith-woocommerce-wishlist' ),
77 'default' => '',
78 ),
79 'already_in_wishslist_text' => array(
80 'type' => 'text',
81 'label' => __( '"Product already in wishlist" label (leave empty to use the default settings)', 'yith-woocommerce-wishlist' ),
82 'default' => '',
83 ),
84 'product_added_text' => array(
85 'type' => 'text',
86 'label' => __( '"Product added to wishlist" label (leave empty to use the default settings)', 'yith-woocommerce-wishlist' ),
87 'default' => '',
88 ),
89 'icon' => array(
90 'type' => 'text',
91 'label' => __( 'Icon for the button (use any FontAwesome valid class, or leave empty to use the default settings)', 'yith-woocommerce-wishlist' ),
92 'default' => '',
93 ),
94 'link_classes' => array(
95 'type' => 'text',
96 'label' => __( 'Additional CSS classes for the button (leave empty to use the default settings)', 'yith-woocommerce-wishlist' ),
97 'default' => '',
98 ),
99 ),
100 ),
101 'yith-wcwl-wishlist' => array(
102 'style' => 'yith-wcwl-main',
103 'script' => 'jquery-yith-wcwl',
104 'title' => _x( 'YITH Wishlist', '[gutenberg]: block name', 'yith-woocommerce-wishlist' ),
105 'description' => _x( 'Shows a list of products in wishlist', '[gutenberg]: block description', 'yith-woocommerce-wishlist' ),
106 'shortcode_name' => 'yith_wcwl_wishlist',
107 'attributes' => array(
108 'pagination' => array(
109 'type' => 'select',
110 'label' => __( 'Choose whether to paginate items in the wishlist or show them all', 'yith-woocommerce-wishlist' ),
111 'default' => 'no',
112 'options' => array(
113 'yes' => __( 'Paginate', 'yith-woocommerce-wishlist' ),
114 'no' => __( 'Do not paginate', 'yith-woocommerce-wishlist' ),
115 ),
116 ),
117 'per_page' => array(
118 'type' => 'number',
119 'label' => __( 'Number of items to show per page', 'yith-woocommerce-wishlist' ),
120 'default' => '5',
121 ),
122 'wishlist_id' => array(
123 'type' => 'text',
124 'label' => __( 'ID of the wishlist to show (e.g. K6EOWXB888ZD)', 'yith-woocommerce-wishlist' ),
125 'default' => '',
126 ),
127 ),
128 ),
129 );
130
131 yith_plugin_fw_gutenberg_add_blocks( $blocks );
132 }
133
134 /**
135 * Register gutenberg scripts
136 */
137 public static function register_gutenberg_scripts() {
138 $prefix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'unminified/' : '';
139 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
140
141 wp_register_script( 'yith-wcwl-add-to-wishlist-gutenberg', YITH_WCWL_ASSETS_JS_URL . $prefix . 'add-to-wishlist-gutenberg' . $suffix . '.js', 'jquery', YITH_WCWL_VERSION, true );
142 }
143
144 /**
145 * Fix preview of Gutenberg blocks at backend
146 *
147 * @param string $shortcode Shortcode to render.
148 * @return void
149 */
150 public static function fix_for_gutenberg_blocks( $shortcode ) {
151 if ( strpos( $shortcode, '[yith_wcwl_add_to_wishlist' ) !== false ) {
152 if ( strpos( $shortcode, 'product_id=""' ) !== false ) {
153 $products = wc_get_products(
154 array(
155 'type' => 'simple',
156 'limit' => 1,
157 )
158 );
159
160 if ( ! empty( $products ) ) {
161 global $product;
162 $product = array_shift( $products );
163 }
164 }
165 }
166 }
167
168 /* === ELEMENTOR WIDGETS === */
169
170 /**
171 * Register custom widgets for Elementor
172 *
173 * @return void
174 */
175 public static function init_elementor_widgets() {
176 // check if elementor is active.
177 if ( ! defined( 'ELEMENTOR_VERSION' ) ) {
178 return;
179 }
180
181 // include widgets.
182 include_once YITH_WCWL_INC . 'widgets/elementor/class-yith-wcwl-elementor-add-to-wishlist.php';
183 include_once YITH_WCWL_INC . 'widgets/elementor/class-yith-wcwl-elementor-wishlist.php';
184
185 $register_widget_hook = version_compare( ELEMENTOR_VERSION, '3.5.0', '>=' ) ? 'elementor/widgets/register' : 'elementor/widgets/widgets_registered';
186
187 // register widgets.
188 add_action( $register_widget_hook, array( 'YITH_WCWL_Shortcode', 'register_elementor_widgets' ) );
189 }
190
191 /**
192 * Register Elementor Widgets
193 *
194 * @return void
195 */
196 public static function register_elementor_widgets() {
197 $widgets_manager = \Elementor\Plugin::instance()->widgets_manager;
198
199 if ( is_callable( array( $widgets_manager, 'register' ) ) ) {
200 $widgets_manager->register( new YITH_WCWL_Elementor_Add_To_Wishlist() );
201 $widgets_manager->register( new YITH_WCWL_Elementor_Wishlist() );
202 } else {
203 $widgets_manager->register_widget_type( new YITH_WCWL_Elementor_Add_To_Wishlist() );
204 $widgets_manager->register_widget_type( new YITH_WCWL_Elementor_Wishlist() );
205 }
206 }
207
208 /* === SHORTCODES == */
209
210 /**
211 * Print the wishlist HTML.
212 *
213 * @param array $atts Array of attributes for the shortcode.
214 * @param string $content Shortcode content (none expected).
215 * @return string Rendered shortcode
216 *
217 * @since 1.0.0
218 */
219 public static function wishlist( $atts, $content = null ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
220 global $yith_wcwl_is_wishlist, $yith_wcwl_wishlist_token;
221
222 $atts = shortcode_atts(
223 array(
224 'per_page' => 5,
225 'current_page' => 1,
226 'pagination' => 'no',
227 'wishlist_id' => get_query_var( 'wishlist_id', false ),
228 'action_params' => get_query_var( YITH_WCWL()->wishlist_param, false ),
229 'no_interactions' => 'no',
230 'layout' => '',
231 ),
232 $atts
233 );
234
235 /**
236 * Extracted variables:
237 *
238 * @var $per_page int
239 * @var $current_page int
240 * @var $pagination string
241 * @var $wishlist_id int
242 * @var $action_params array
243 * @var $no_interactions string
244 * @var $layout string
245 */
246 extract( $atts ); // phpcs:ignore
247
248 // retrieve options from query string.
249 /**
250 * APPLY_FILTERS: yith_wcwl_current_wishlist_view_params
251 *
252 * Filter the array of parameters to see the current wishlist.
253 *
254 * @param array $params Array of parameters
255 *
256 * @return array
257 */
258 $action_params = explode( '/', apply_filters( 'yith_wcwl_current_wishlist_view_params', $action_params ) );
259 $action = ( isset( $action_params[ 0 ] ) ) ? $action_params[ 0 ] : 'view';
260
261 // retrieve options from db.
262 $default_wishlist_title = get_option( 'yith_wcwl_wishlist_title', __( 'My wishlist', 'yith-woocommerce-wishlist' ) );
263 $show_price = 'yes' === get_option( 'yith_wcwl_price_show' );
264 $show_stock = 'yes' === get_option( 'yith_wcwl_stock_show' );
265 $show_date_added = 'yes' === get_option( 'yith_wcwl_show_dateadded' );
266 $show_add_to_cart = 'yes' === get_option( 'yith_wcwl_add_to_cart_show' );
267 $show_remove_product = 'yes' === get_option( 'yith_wcwl_show_remove', 'yes' );
268 $show_variation = 'yes' === get_option( 'yith_wcwl_variation_show' );
269 $repeat_remove_button = 'yes' === get_option( 'yith_wcwl_repeat_remove_button' );
270 $add_to_cart_label = get_option( 'yith_wcwl_add_to_cart_text', __( 'Add to cart', 'yith-woocommerce-wishlist' ) );
271 $price_excluding_tax = 'excl' === get_option( 'woocommerce_tax_display_cart' );
272 $ajax_loading = 'yes' === get_option( 'yith_wcwl_ajax_enable', 'no' );
273
274 // icons.
275 $icon = get_option( 'yith_wcwl_add_to_wishlist_icon' );
276
277 if ( 'custom' === $icon ) {
278 $custom_icon = get_option( 'yith_wcwl_add_to_wishlist_custom_icon' );
279
280 /**
281 * APPLY_FILTERS: yith_wcwl_custom_icon_alt
282 *
283 * Filter the alternative text for the heading icon in the widget.
284 *
285 * @param string $text Alternative text
286 *
287 * @return string
288 */
289 $custom_icon_alt = apply_filters( 'yith_wcwl_custom_icon_alt', '' );
290
291 /**
292 * APPLY_FILTERS: yith_wcwl_custom_width
293 *
294 * Filter the width for the heading icon in the widget.
295 *
296 * @param string $width Icon width
297 *
298 * @return string
299 */
300 $custom_icon_width = apply_filters( 'yith_wcwl_custom_width', '32' );
301
302 $heading_icon = '<img src="' . esc_url( $custom_icon ) . '" alt="' . esc_attr( $custom_icon_alt ) . '" width="' . esc_attr( $custom_icon_width ) . '" />';
303 } else {
304 $heading_icon = ! empty( $icon ) ? '<i class="fa ' . esc_attr( $icon ) . '"></i>' : '';
305 }
306
307 // init params needed to load correct template.
308 $template_part = 'view';
309 $no_interactions = 'yes' === $no_interactions;
310 $additional_params = array(
311 // wishlist data.
312 'wishlist' => false,
313 'is_default' => true, // @deprecated since 3.0.7
314 'is_custom_list' => false,
315 'wishlist_token' => '',
316 'wishlist_id' => false,
317 'is_private' => false,
318
319 // wishlist items.
320 'count' => 0,
321 'wishlist_items' => array(),
322
323 // page data.
324 'page_title' => $default_wishlist_title,
325 'default_wishlsit_title' => $default_wishlist_title,
326 'current_page' => $current_page,
327 'page_links' => false,
328 'layout' => $layout,
329
330 // user data.
331 'is_user_logged_in' => is_user_logged_in(),
332 'is_user_owner' => true,
333 'can_user_edit_title' => false,
334
335 // view data.
336 'no_interactions' => $no_interactions,
337 'show_price' => $show_price,
338 'show_dateadded' => $show_date_added,
339 'show_stock_status' => $show_stock,
340 'show_add_to_cart' => $show_add_to_cart && ! $no_interactions,
341 'show_remove_product' => $show_remove_product && ! $no_interactions,
342 'add_to_cart_text' => $add_to_cart_label,
343 'show_ask_estimate_button' => false,
344 'ask_estimate_url' => '',
345 'price_excl_tax' => $price_excluding_tax,
346 'show_cb' => false,
347 'show_quantity' => false,
348 'show_variation' => $show_variation,
349 'show_price_variations' => false,
350 'show_update' => false,
351 'enable_drag_n_drop' => false,
352 'enable_add_all_to_cart' => false,
353 'move_to_another_wishlist' => false,
354 'repeat_remove_button' => $repeat_remove_button && ! $no_interactions,
355 'show_last_column' => $show_date_added || ( $show_add_to_cart && ! $no_interactions ) || ( $repeat_remove_button && ! $no_interactions ),
356
357 // wishlist icon.
358 'heading_icon' => $heading_icon,
359
360 // share data.
361 'share_enabled' => false,
362
363 // template data.
364 'template_part' => $template_part,
365 'additional_info' => false,
366 'available_multi_wishlist' => false,
367 'users_wishlists' => array(),
368 'form_action' => esc_url( YITH_WCWL()->get_wishlist_url( 'view' ) ),
369 );
370
371 $wishlist = YITH_WCWL_Wishlist_Factory::get_current_wishlist( $atts );
372
373 if ( $wishlist && $wishlist->current_user_can( 'view' ) ) {
374 // set global wishlist token.
375 $yith_wcwl_wishlist_token = $wishlist->get_token();
376
377 // retrieve wishlist params.
378 $is_user_owner = $wishlist->is_current_user_owner();
379 $count = $wishlist->count_items();
380 $offset = 0;
381
382 // sets current page, number of pages and element offset.
383 $queried_page = get_query_var( 'paged' );
384 $current_page = max( 1, $queried_page ? $queried_page : $current_page );
385
386 // sets variables for pagination, if shortcode atts is set to yes.
387 if ( 'yes' === $pagination && ! $no_interactions && $count > 1 ) {
388 $pages = ceil( $count / $per_page );
389
390 if ( $current_page > $pages ) {
391 $current_page = $pages;
392 }
393
394 $offset = ( $current_page - 1 ) * $per_page;
395
396 if ( $pages > 1 ) {
397 $page_links = paginate_links(
398 array(
399 'base' => esc_url( add_query_arg( array( 'paged' => '%#%' ), $wishlist->get_url() ) ),
400 'format' => '?paged=%#%',
401 'current' => $current_page,
402 'total' => $pages,
403 'show_all' => true,
404 )
405 );
406 }
407 } else {
408 $per_page = 0;
409 }
410
411 // retrieve items to print.
412 $wishlist_items = $wishlist->get_items( $per_page, $offset );
413
414 // retrieve wishlist information.
415 $is_default = $wishlist->get_is_default();
416 $wishlist_token = $wishlist->get_token();
417 $wishlist_title = $wishlist->get_formatted_name();
418
419 $additional_params = wp_parse_args(
420 array(
421 // wishlist items.
422 'count' => $count,
423 'wishlist_items' => $wishlist_items,
424
425 // wishlist data.
426 'wishlist' => $wishlist,
427 'is_default' => $is_default,
428 'is_custom_list' => $is_user_owner && ! $no_interactions, // @deprecated since 3.0.7
429 'wishlist_token' => $wishlist_token,
430 'wishlist_id' => $wishlist->get_id(),
431 'is_private' => $wishlist->has_privacy( 'private' ),
432 'ajax_loading' => $ajax_loading,
433
434 // page data.
435 'page_title' => $wishlist_title,
436 'current_page' => $current_page,
437 'page_links' => isset( $page_links ) && ! $no_interactions ? $page_links : false,
438
439 // user data.
440 'is_user_owner' => $is_user_owner,
441 'can_user_edit_title' => $wishlist->current_user_can( 'update_wishlist' ) && ! $no_interactions,
442
443 // view data.
444 'show_remove_product' => $show_remove_product && $wishlist->current_user_can( 'remove_from_wishlist' ) && ! $no_interactions,
445 'repeat_remove_button' => $repeat_remove_button && $wishlist->current_user_can( 'remove_from_wishlist' ) && ! $no_interactions,
446
447 // template data.
448 'form_action' => $wishlist->get_url(),
449 ),
450 $additional_params
451 );
452
453 // share options.
454 $enable_share = 'yes' === get_option( 'yith_wcwl_enable_share' ) && ! $wishlist->has_privacy( 'private' );
455 $share_facebook_enabled = 'yes' === get_option( 'yith_wcwl_share_fb' );
456 $share_twitter_enabled = 'yes' === get_option( 'yith_wcwl_share_twitter' );
457 $share_pinterest_enabled = 'yes' === get_option( 'yith_wcwl_share_pinterest' );
458 $share_email_enabled = 'yes' === get_option( 'yith_wcwl_share_email' );
459 $share_whatsapp_enabled = 'yes' === get_option( 'yith_wcwl_share_whatsapp' );
460 $share_url_enabled = 'yes' === get_option( 'yith_wcwl_share_url' );
461
462 // we want spaces to be encoded as + instead of %20, so we use urlencode instead of rawurlencode.
463 // phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
464 if ( ! $no_interactions && $enable_share && ( $share_facebook_enabled || $share_twitter_enabled || $share_pinterest_enabled || $share_email_enabled || $share_whatsapp_enabled || $share_url_enabled ) ) {
465 /**
466 * APPLY_FILTERS: yith_wcwl_socials_share_title
467 *
468 * Filter the title to share the wishlist on the different socials.
469 *
470 * @param string $share_title Share title
471 *
472 * @return string
473 */
474 $share_title = apply_filters( 'yith_wcwl_socials_share_title', __( 'Share on:', 'yith-woocommerce-wishlist' ) );
475
476 /**
477 * APPLY_FILTERS: yith_wcwl_shortcode_share_link_url
478 *
479 * Filter the wishlist URL to share.
480 *
481 * @param string $share_link_url Share link URL
482 * @param YITH_WCWL_Wishlist $wishlist Wishlist object
483 *
484 * @return string
485 */
486 $share_link_url = apply_filters( 'yith_wcwl_shortcode_share_link_url', $wishlist->get_url(), $wishlist );
487
488 /**
489 * APPLY_FILTERS: yith_wcwl_share_title
490 *
491 * Filter the title to share the wishlist.
492 *
493 * @param string $share_title Share title
494 * @param YITH_WCWL_Wishlist $wishlist Wishlist object
495 *
496 * @return string
497 */
498 $share_link_title = apply_filters( 'yith_wcwl_share_title', urlencode( get_option( 'yith_wcwl_socials_title' ) ), $wishlist );
499 $share_summary = urlencode( str_replace( '%wishlist_url%', $share_link_url, get_option( 'yith_wcwl_socials_text' ) ) );
500
501 $share_atts = array(
502 'share_facebook_enabled' => $share_facebook_enabled,
503 'share_twitter_enabled' => $share_twitter_enabled,
504 'share_pinterest_enabled' => $share_pinterest_enabled,
505 'share_email_enabled' => $share_email_enabled,
506 'share_whatsapp_enabled' => $share_whatsapp_enabled,
507 'share_url_enabled' => $share_url_enabled,
508 'share_title' => $share_title,
509 'share_link_url' => $share_link_url,
510 'share_link_title' => $share_link_title,
511 );
512
513 $social_buttons = array(
514 'fb' => array(
515 'name' => 'facebook',
516 'alt_text' => __( 'Share on Facebook', 'yith-woocommerce-wishlist' ),
517 'enabled' => $share_facebook_enabled,
518 ),
519 'tw' => array(
520 'name' => 'twitter',
521 'alt_text' => __( 'Tweet on Twitter (X)', 'yith-woocommerce-wishlist' ),
522 'icon' => 'x-twitter',
523 'enabled' => $share_twitter_enabled,
524 ),
525 'pr' => array(
526 'name' => 'pinterest',
527 'alt_text' => __( 'Pin on Pinterest', 'yith-woocommerce-wishlist' ),
528 'enabled' => $share_pinterest_enabled,
529 ),
530 'em' => array(
531 'name' => 'email',
532 'alt_text' => __( 'Share via email', 'yith-woocommerce-wishlist' ),
533 'icon' => 'envelope',
534 'enabled' => $share_email_enabled,
535 ),
536 'wa' => array(
537 'name' => 'whatsapp',
538 'alt_text' => __( 'Share on WhatsApp', 'yith-woocommerce-wishlist' ),
539 'enabled' => $share_whatsapp_enabled,
540 ),
541 );
542
543 foreach ( $social_buttons as $social_id => $social_button ) {
544 if ( $social_button[ 'enabled' ] ) {
545 $share_button_icon = get_option( 'yith_wcwl_' . $social_id . '_button_icon', 'default' );
546 if ('none' === $share_button_icon) {
547 $share_atts[ 'share_' . $social_button[ 'name' ] . '_icon' ] = '';
548 }else{
549 $share_button_custom_icon = get_option( 'yith_wcwl_' . $social_id . '_button_custom_icon' );
550 if ( 'custom' === $share_button_icon && $share_button_custom_icon ) {
551 $share_atts[ 'share_' . $social_button[ 'name' ] . '_icon' ] = "<img src='$share_button_custom_icon' alt='{$social_button[ 'alt_text' ]}'/>";
552 } else {
553 $share_atts[ 'share_' . $social_button[ 'name' ] . '_icon' ] = yith_wcwl_get_icon( $social_button[ 'icon' ] ?? $social_button[ 'name' ] );
554 }
555 }
556 }
557 }
558
559 if ( $share_twitter_enabled ) {
560 $share_atts[ 'share_twitter_summary' ] = urlencode( str_replace( '%wishlist_url%', '', get_option( 'yith_wcwl_socials_text' ) ) );
561 }
562
563 if ( $share_pinterest_enabled ) {
564 $share_atts[ 'share_summary' ] = $share_summary;
565 $share_atts[ 'share_image_url' ] = urlencode( get_option( 'yith_wcwl_socials_image_url' ) );
566 }
567
568 if ( $share_whatsapp_enabled ) {
569 if ( wp_is_mobile() ) {
570 $share_atts[ 'share_whatsapp_url' ] = 'whatsapp://send?text=' . $share_link_title . ' - ' . urlencode( $share_link_url );
571 } else {
572 $share_atts[ 'share_whatsapp_url' ] = 'https://web.whatsapp.com/send?text=' . $share_link_title . ' - ' . urlencode( $share_link_url );
573 }
574 }
575
576 $additional_params[ 'share_enabled' ] = true;
577 $additional_params[ 'share_atts' ] = $share_atts;
578 }
579 // phpcs:enable WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
580 }
581
582 // filter params.
583
584 /**
585 * APPLY_FILTERS: yith_wcwl_wishlist_params
586 *
587 * Filter the array with the paramters in the wishlist page.
588 *
589 * @param array $additional_params Wishlist parameters
590 * @param string $action Action
591 * @param array $action_params Action parameters
592 * @param string $pagination Use pagination or not
593 * @param int $per_page Number of items per page
594 * @param array $atts Array of attributes
595 *
596 * @return array
597 */
598 $additional_params = apply_filters( 'yith_wcwl_wishlist_params', $additional_params, $action, $action_params, $pagination, $per_page, $atts );
599
600 $atts = array_merge(
601 $atts,
602 $additional_params
603 );
604
605 $atts[ 'fragment_options' ] = YITH_WCWL_Frontend()->format_fragment_options( $atts, 'wishlist' );
606
607 // apply filters for add to cart buttons.
608 YITH_WCWL_Frontend()->alter_add_to_cart_button();
609
610 // sets that we're in the wishlist template.
611 $yith_wcwl_is_wishlist = true;
612
613 $template = yith_wcwl_get_template( 'wishlist.php', $atts, true );
614
615 // we're not in wishlist template anymore.
616 $yith_wcwl_is_wishlist = false;
617 $yith_wcwl_wishlist_token = null;
618
619 // remove filters for add to cart buttons.
620 YITH_WCWL_Frontend()->restore_add_to_cart_button();
621
622 // enqueue scripts.
623 YITH_WCWL_Frontend()->enqueue_scripts();
624
625 return apply_filters( 'yith_wcwl_wishlisth_html', $template, array(), true );
626 }
627
628 /**
629 * Return "Add to Wishlist" button.
630 *
631 * @param array $atts Array of parameters for the shortcode.
632 *
633 * @return string Template of the shortcode.
634 *
635 * @since 1.0.0
636 */
637 public static function add_to_wishlist( $atts ) {
638 $button = YITH_WCWL_Add_To_Wishlist_Button::get( $atts );
639 return $button->render( true );
640 }
641 }
642 }
643
644 YITH_WCWL_Shortcode::init();
645