PluginProbe ʕ •ᴥ•ʔ
Meta for WooCommerce / 1.11.3
Meta for WooCommerce v1.11.3
3.7.1 trunk 1.10.0 1.10.1 1.10.2 1.11.0 1.11.1 1.11.2 1.11.3 1.11.4 1.9.11 1.9.12 1.9.13 1.9.14 1.9.15 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.4.0 2.4.1 2.5.0 2.5.1 2.6.0 2.6.1 2.6.10 2.6.11 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.18 2.6.19 2.6.2 2.6.20 2.6.21 2.6.22 2.6.23 2.6.24 2.6.25 2.6.26 2.6.27 2.6.28 2.6.29 2.6.3 2.6.30 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.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.24 3.0.25 3.0.26 3.0.27 3.0.28 3.0.29 3.0.3 3.0.30 3.0.31 3.0.32 3.0.33 3.0.34 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.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.4.0 3.4.1 3.4.10 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.10 3.5.11 3.5.12 3.5.13 3.5.14 3.5.15 3.5.16 3.5.17 3.5.18 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.3 3.7.0
facebook-for-woocommerce / includes / fbwpml.php
facebook-for-woocommerce / includes Last commit date
Integrations 6 years ago Products 6 years ago Utilities 6 years ago test 6 years ago AJAX.php 6 years ago Admin.php 6 years ago Lifecycle.php 6 years ago Products.php 6 years ago fbasync.php 6 years ago fbbackground.php 6 years ago fbgraph.php 6 years ago fbinfobanner.php 6 years ago fbproduct.php 6 years ago fbproductfeed.php 6 years ago fbutils.php 6 years ago fbwpml.php 6 years ago
fbwpml.php
164 lines
1 <?php
2 /**
3 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
4 *
5 * This source code is licensed under the license found in the
6 * LICENSE file in the root directory of this source tree.
7 *
8 * @package FacebookCommerce
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 if ( ! class_exists( 'WC_Facebook_WPML_Injector' ) ) :
16
17 class FB_WPML_Language_Status {
18 const VISIBLE = 1;
19 const HIDDEN = 2;
20 const NOT_SYNCED = 0;
21 }
22
23 class WC_Facebook_WPML_Injector {
24 public static $settings = null;
25 public static $default_lang = null;
26 const OPTION = 'fb_wmpl_language_visibility';
27
28
29 /**
30 * Constructor for WC_Facebook_WPML_Injector class.
31 */
32 public function __construct() {
33
34 self::$settings = get_option( self::OPTION );
35 self::$default_lang = apply_filters( 'wpml_default_language', null );
36
37 if ( is_admin() ) {
38 add_action( 'icl_menu_footer', [ $this, 'wpml_support' ] );
39 add_action( 'icl_ajx_custom_call', [ $this, 'wpml_ajax_support' ], 10, 2 );
40 }
41 }
42
43
44 public static function should_hide( $wp_id ) {
45 $product_lang = apply_filters( 'wpml_post_language_details', null, $wp_id );
46 $settings = self::$settings;
47 if ( $product_lang && isset( $product_lang['language_code'] ) ) {
48 $product_lang = $product_lang['language_code'];
49 }
50
51 // Option doesn't exist : Backwards Compatibility
52 if ( ! $settings ) {
53 return ( $product_lang && self::$default_lang !== $product_lang );
54 }
55 // Hide products from non-active languages.
56 if ( ! isset( $settings[ $product_lang ] ) ) {
57 return true;
58 }
59 return $settings[ $product_lang ] !== FB_WPML_Language_Status::VISIBLE;
60 }
61
62 public function wpml_ajax_support( $call, $REQUEST ) {
63 global $sitepress;
64 if ( isset( $REQUEST['icl_ajx_action'] ) ) {
65 $call = $REQUEST['icl_ajx_action'];
66 }
67 if ( $call === 'icl_fb_woo' ) {
68 $active_languages = array_keys( $sitepress->get_active_languages() );
69 $settings = array();
70 foreach ( $active_languages as $lang ) {
71 $settings[ $lang ] = $REQUEST[ $lang ] === 'on' ?
72 FB_WPML_Language_Status::VISIBLE : FB_WPML_Language_Status::HIDDEN;
73 }
74
75 update_option( 'fb_wmpl_language_visibility', $settings, false );
76 self::$settings = $settings;
77 }
78 }
79
80
81 /**
82 * Prints the content for Facebook Visibility section.
83 *
84 * The section is shown at the bottom of the WPML > Languages settings page.
85 */
86 public function wpml_support() {
87 /** @var object $sitepress */
88 global $sitepress;
89
90 // there is no nonce to check here and the value of $_GET['page] is being compared against a known and safe string
91 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
92 if ( isset( $_GET['page'] ) && false !== strpos( esc_url_raw( wp_unslash( $_GET['page'] ) ), 'languages.php' ) ) {
93
94 /** @var array $active_languages */
95 $active_languages = $sitepress->get_active_languages();
96 $settings = get_option( self::OPTION );
97
98 // Default setting is only show default lang.
99 if ( ! $settings ) {
100
101 $settings = array_fill_keys(
102 array_keys( $active_languages ),
103 FB_WPML_Language_Status::HIDDEN
104 );
105
106 if ( self::$default_lang ) {
107 $settings[ self::$default_lang ] = FB_WPML_Language_Status::VISIBLE;
108 }
109 }
110
111 ?>
112 <div id="lang-sec-fb" class="wpml-section wpml-section-languages">
113 <div class="wpml-section-header">
114 <h3><?php esc_html_e( 'Facebook Visibility', 'facebook-for-woocommerce' ); ?></h3>
115 </div>
116 <div class="wpml-section-content">
117 <?php esc_html_e( 'WooCommerce Products with languages that are selected here will be visible to customers who see your Facebook Shop.', 'facebook-for-woocommerce' ); ?>
118
119 <div class="wpml-section-content-inner">
120 <form id="icl_fb_woo" name="icl_fb_woo" action="">
121
122 <?php foreach ( $settings as $language => $set ) : ?>
123
124 <p>
125 <label>
126 <input type="checkbox" id="icl_fb_woo_chk" name="<?php echo esc_attr( $language ); ?>" <?php checked( $set, FB_WPML_Language_Status::VISIBLE ); ?>>
127 <?php echo isset( $active_languages[ $language ]['native_name'] ) ? esc_html( $active_languages[ $language ]['native_name'] ) : esc_html( $language ); ?>
128 </label>
129 </p>
130
131 <?php endforeach; ?>
132
133 <?php // TODO: restore success message removed in e7f290f when FBE 2.0 changes are available {WV 2020-04-27} ?>
134 <p class="icl_ajx_response_fb" id="icl_ajx_response_fb" hidden="true"><?php esc_html_e( "Saved. An automated sync from Facebook will run every hour to update the catalog with any changes you've made.", 'facebook-for-woocommerce' ); ?></p>
135
136 <p class="buttons-wrap">
137 <input
138 class="button button-primary"
139 name="save"
140 value="<?php esc_attr_e( 'Save', 'sitepress' ); ?>"
141 type="submit"
142 />
143 </p>
144 </form>
145 <script type="text/javascript">
146 addLoadEvent( function() {
147 jQuery( '#icl_fb_woo' ).submit( iclSaveForm );
148 jQuery( '#icl_fb_woo' ).submit( function() {
149 jQuery( '#icl_ajx_response_fb' ).show();
150 } );
151 } );
152 </script>
153 </div>
154 </div>
155 </div>
156 <?php
157 }
158 }
159
160
161 }
162
163 endif;
164