@@ -21,13 +21,13 @@ discard block |
||
21 | 21 | * Contructor |
22 | 22 | */ |
23 | 23 | public function __construct() { |
24 | - add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 5 ); |
|
25 | - add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses_allowed_html' ), 10, 2 ); |
|
26 | - add_shortcode( 'lsx_sharing_buttons', array( $this, 'sharing_buttons_shortcode' ) ); |
|
24 | + add_action('wp_enqueue_scripts', array($this, 'assets'), 5); |
|
25 | + add_filter('wp_kses_allowed_html', array($this, 'wp_kses_allowed_html'), 10, 2); |
|
26 | + add_shortcode('lsx_sharing_buttons', array($this, 'sharing_buttons_shortcode')); |
|
27 | 27 | // Storefront (storefront_loop_post, storefront_single_post). |
28 | - add_action( 'storefront_post_content_before', array( $this, 'sharing_buttons_template' ), 20 ); |
|
28 | + add_action('storefront_post_content_before', array($this, 'sharing_buttons_template'), 20); |
|
29 | 29 | // WooCommerce. |
30 | - add_action( 'woocommerce_share', array( $this, 'sharing_buttons_template' ) ); |
|
30 | + add_action('woocommerce_share', array($this, 'sharing_buttons_template')); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public static function get_instance() { |
41 | 41 | // If the single instance hasn't been set, set it now. |
42 | - if ( null == self::$instance ) { |
|
42 | + if (null == self::$instance) { |
|
43 | 43 | self::$instance = new self(); |
44 | 44 | } |
45 | 45 | return self::$instance; |
@@ -49,14 +49,14 @@ discard block |
||
49 | 49 | * Enques the assets. |
50 | 50 | */ |
51 | 51 | public function assets() { |
52 | - if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) { |
|
52 | + if (defined('WP_DEBUG') && true === WP_DEBUG) { |
|
53 | 53 | $min = ''; |
54 | 54 | } else { |
55 | 55 | $min = '.min'; |
56 | 56 | } |
57 | 57 | /* Remove assets completely if all sharing options are off */ |
58 | 58 | |
59 | - if ( \lsx\sharing\includes\functions\is_disabled() ) { |
|
59 | + if (\lsx\sharing\includes\functions\is_disabled()) { |
|
60 | 60 | return ''; |
61 | 61 | } |
62 | 62 | |
@@ -64,67 +64,67 @@ discard block |
||
64 | 64 | $post_type = get_post_type(); |
65 | 65 | |
66 | 66 | /* Only show the assets if the post type sharing option is on */ |
67 | - if ( ! \lsx\sharing\includes\functions\is_pt_disabled( $post_type ) ) { |
|
67 | + if ( ! \lsx\sharing\includes\functions\is_pt_disabled($post_type)) { |
|
68 | 68 | |
69 | - wp_enqueue_script( 'lsx-sharing', LSX_SHARING_URL . 'assets/js/lsx-sharing' . $min . '.js', array( 'jquery' ), LSX_SHARING_VER, true ); |
|
69 | + wp_enqueue_script('lsx-sharing', LSX_SHARING_URL . 'assets/js/lsx-sharing' . $min . '.js', array('jquery'), LSX_SHARING_VER, true); |
|
70 | 70 | |
71 | - $params = apply_filters( 'lsx_sharing_js_params', array( |
|
72 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
71 | + $params = apply_filters('lsx_sharing_js_params', array( |
|
72 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
73 | 73 | )); |
74 | 74 | |
75 | - wp_localize_script( 'lsx-sharing', 'lsx_sharing_params', $params ); |
|
75 | + wp_localize_script('lsx-sharing', 'lsx_sharing_params', $params); |
|
76 | 76 | |
77 | - wp_enqueue_style( 'lsx-sharing', LSX_SHARING_URL . 'assets/css/lsx-sharing.css', array(), LSX_SHARING_VER ); |
|
78 | - wp_style_add_data( 'lsx-sharing', 'rtl', 'replace' ); |
|
77 | + wp_enqueue_style('lsx-sharing', LSX_SHARING_URL . 'assets/css/lsx-sharing.css', array(), LSX_SHARING_VER); |
|
78 | + wp_style_add_data('lsx-sharing', 'rtl', 'replace'); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * Display/return sharing buttons. |
84 | 84 | */ |
85 | - public function sharing_buttons( $buttons = array( 'facebook', 'twitter', 'pinterest' ), $echo = false, $post_id = false ) { |
|
85 | + public function sharing_buttons($buttons = array('facebook', 'twitter', 'pinterest'), $echo = false, $post_id = false) { |
|
86 | 86 | $sharing_content = ''; |
87 | 87 | |
88 | - if ( ( is_preview() || is_admin() ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
88 | + if ((is_preview() || is_admin()) && ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
89 | 89 | return ''; |
90 | 90 | } |
91 | 91 | |
92 | 92 | //Set our variables |
93 | 93 | global $post; |
94 | 94 | $share_post = $post; |
95 | - if ( false !== $post_id ) { |
|
96 | - $share_post = get_post( $post_id ); |
|
97 | - $post_type = get_post_type( $post_id ); |
|
95 | + if (false !== $post_id) { |
|
96 | + $share_post = get_post($post_id); |
|
97 | + $post_type = get_post_type($post_id); |
|
98 | 98 | } else { |
99 | 99 | $post_type = get_post_type(); |
100 | 100 | } |
101 | 101 | |
102 | - if ( \lsx\sharing\includes\functions\is_disabled() || \lsx\sharing\includes\functions\is_pt_disabled( $post_type ) ) { |
|
102 | + if (\lsx\sharing\includes\functions\is_disabled() || \lsx\sharing\includes\functions\is_pt_disabled($post_type)) { |
|
103 | 103 | return ''; |
104 | 104 | } |
105 | 105 | |
106 | - if ( ( is_array( $buttons ) && count( $buttons ) > 0 ) ) { |
|
106 | + if ((is_array($buttons) && count($buttons) > 0)) { |
|
107 | 107 | $sharing_content .= '<div class="lsx-sharing-content"><p>'; |
108 | 108 | |
109 | - $sharing_text = \lsx\sharing\includes\functions\get_sharing_text( $post_type ); |
|
110 | - if ( '' !== $sharing_text ) { |
|
109 | + $sharing_text = \lsx\sharing\includes\functions\get_sharing_text($post_type); |
|
110 | + if ('' !== $sharing_text) { |
|
111 | 111 | $sharing_content .= '<span class="lsx-sharing-label">' . $sharing_text . '</span>'; |
112 | 112 | } |
113 | 113 | |
114 | - foreach ( $buttons as $id => $button ) { |
|
115 | - $button_obj = new \lsx\sharing\classes\frontend\Button( $button, $this->options, $post_type ); |
|
114 | + foreach ($buttons as $id => $button) { |
|
115 | + $button_obj = new \lsx\sharing\classes\frontend\Button($button, $this->options, $post_type); |
|
116 | 116 | |
117 | - if ( ! empty( $button_obj ) ) { |
|
118 | - $url = $button_obj->get_link( $share_post ); |
|
117 | + if ( ! empty($button_obj)) { |
|
118 | + $url = $button_obj->get_link($share_post); |
|
119 | 119 | |
120 | - if ( ! empty( $url ) ) { |
|
121 | - if ( 'email' === $button ) { |
|
122 | - if ( ! isset( $this->options['display'] ) || empty( $this->options['display']['sharing_email_form_id'] ) ) { |
|
120 | + if ( ! empty($url)) { |
|
121 | + if ('email' === $button) { |
|
122 | + if ( ! isset($this->options['display']) || empty($this->options['display']['sharing_email_form_id'])) { |
|
123 | 123 | continue; |
124 | 124 | } |
125 | - $sharing_content .= '<span class="lsx-sharing-button lsx-sharing-button-' . esc_attr( $button ) . '"><a href="#lsx-sharing-email" data-toggle="modal" data-link="' . esc_url( $url ) . '"><span class="fa" aria-hidden="true"></span></a></span>'; |
|
125 | + $sharing_content .= '<span class="lsx-sharing-button lsx-sharing-button-' . esc_attr($button) . '"><a href="#lsx-sharing-email" data-toggle="modal" data-link="' . esc_url($url) . '"><span class="fa" aria-hidden="true"></span></a></span>'; |
|
126 | 126 | } else { |
127 | - $sharing_content .= '<span class="lsx-sharing-button lsx-sharing-button-' . esc_attr( $button ) . '"><a href="' . esc_url( $url ) . '" target="_blank" rel="noopener noreferrer"><span class="fa" aria-hidden="true"></span></a></span>'; |
|
127 | + $sharing_content .= '<span class="lsx-sharing-button lsx-sharing-button-' . esc_attr($button) . '"><a href="' . esc_url($url) . '" target="_blank" rel="noopener noreferrer"><span class="fa" aria-hidden="true"></span></a></span>'; |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | } |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | $sharing_content .= '</p></div>'; |
133 | 133 | } |
134 | 134 | |
135 | - if ( $echo ) { |
|
136 | - echo wp_kses_post( $sharing_content ); |
|
135 | + if ($echo) { |
|
136 | + echo wp_kses_post($sharing_content); |
|
137 | 137 | } else { |
138 | 138 | return $sharing_content; |
139 | 139 | } |
@@ -142,20 +142,20 @@ discard block |
||
142 | 142 | /** |
143 | 143 | * Sharing buttons shortcode. |
144 | 144 | */ |
145 | - public function sharing_buttons_shortcode( $atts ) { |
|
146 | - $atts = shortcode_atts( array( |
|
145 | + public function sharing_buttons_shortcode($atts) { |
|
146 | + $atts = shortcode_atts(array( |
|
147 | 147 | 'buttons' => '', |
148 | - ), $atts, 'lsx_sharing_buttons' ); |
|
148 | + ), $atts, 'lsx_sharing_buttons'); |
|
149 | 149 | |
150 | - if ( empty( $atts['buttons'] ) ) { |
|
150 | + if (empty($atts['buttons'])) { |
|
151 | 151 | return ''; |
152 | 152 | } |
153 | 153 | |
154 | - $no_whitespaces = preg_replace( '/\s*,\s*/', ',', filter_var( $atts['buttons'], FILTER_SANITIZE_STRING ) ); |
|
155 | - $buttons = explode( ',', $no_whitespaces ); |
|
154 | + $no_whitespaces = preg_replace('/\s*,\s*/', ',', filter_var($atts['buttons'], FILTER_SANITIZE_STRING)); |
|
155 | + $buttons = explode(',', $no_whitespaces); |
|
156 | 156 | |
157 | - if ( is_array( $buttons ) && count( $buttons ) > 0 ) { |
|
158 | - return $this->sharing_buttons( $buttons ); |
|
157 | + if (is_array($buttons) && count($buttons) > 0) { |
|
158 | + return $this->sharing_buttons($buttons); |
|
159 | 159 | } |
160 | 160 | } |
161 | 161 | |
@@ -163,13 +163,13 @@ discard block |
||
163 | 163 | * Display buttons (template hook). |
164 | 164 | */ |
165 | 165 | public function sharing_buttons_template() { |
166 | - echo wp_kses_post( $this->sharing_buttons() ); |
|
166 | + echo wp_kses_post($this->sharing_buttons()); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
170 | 170 | * Allow data params for Bootstrap modal. |
171 | 171 | */ |
172 | - public function wp_kses_allowed_html( $allowedtags, $context ) { |
|
172 | + public function wp_kses_allowed_html($allowedtags, $context) { |
|
173 | 173 | $allowedtags['a']['data-toggle'] = true; |
174 | 174 | $allowedtags['a']['data-link'] = true; |
175 | 175 | return $allowedtags; |
@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | * Contructor |
38 | 38 | */ |
39 | 39 | public function __construct() { |
40 | - add_filter( 'cmb2_enqueue_css', array( $this, 'disable_cmb2_styles' ), 1, 1 ); |
|
41 | - add_action( 'cmb2_before_form', array( $this, 'generate_navigation' ), 10, 4 ); |
|
42 | - add_action( 'cmb2_before_title_field_row', array( $this, 'output_tab_open_div' ), 10, 1 ); |
|
43 | - add_action( 'cmb2_after_tab_closing_field_row', array( $this, 'output_tab_closing_div' ), 10, 1 ); |
|
44 | - add_action( 'cmb2_render_tab_closing', array( $this, 'cmb2_render_callback_for_tab_closing' ), 10, 5 ); |
|
45 | - add_filter( 'cmb2_sanitize_tab_closing', array( $this, 'cmb2_sanitize_tab_closing_callback' ), 10, 2 ); |
|
46 | - add_action( 'cmb2_after_form', array( $this, 'navigation_js' ), 10, 4 ); |
|
47 | - add_filter( 'cmb2_options_page_redirect_url', array( $this, 'add_tab_argument' ), 10, 1 ); |
|
40 | + add_filter('cmb2_enqueue_css', array($this, 'disable_cmb2_styles'), 1, 1); |
|
41 | + add_action('cmb2_before_form', array($this, 'generate_navigation'), 10, 4); |
|
42 | + add_action('cmb2_before_title_field_row', array($this, 'output_tab_open_div'), 10, 1); |
|
43 | + add_action('cmb2_after_tab_closing_field_row', array($this, 'output_tab_closing_div'), 10, 1); |
|
44 | + add_action('cmb2_render_tab_closing', array($this, 'cmb2_render_callback_for_tab_closing'), 10, 5); |
|
45 | + add_filter('cmb2_sanitize_tab_closing', array($this, 'cmb2_sanitize_tab_closing_callback'), 10, 2); |
|
46 | + add_action('cmb2_after_form', array($this, 'navigation_js'), 10, 4); |
|
47 | + add_filter('cmb2_options_page_redirect_url', array($this, 'add_tab_argument'), 10, 1); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public static function get_instance() { |
58 | 58 | // If the single instance hasn't been set, set it now. |
59 | - if ( null == self::$instance ) { |
|
59 | + if (null == self::$instance) { |
|
60 | 60 | self::$instance = new self(); |
61 | 61 | } |
62 | 62 | return self::$instance; |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @return bool $enabled Whether to enable (enqueue) styles. |
69 | 69 | */ |
70 | - public function disable_cmb2_styles( $enabled ) { |
|
71 | - if ( is_admin() ) { |
|
70 | + public function disable_cmb2_styles($enabled) { |
|
71 | + if (is_admin()) { |
|
72 | 72 | $current_screen = get_current_screen(); |
73 | - if ( is_object( $current_screen ) && 'settings_page_lsx-sharing-settings' === $current_screen->id ) { |
|
73 | + if (is_object($current_screen) && 'settings_page_lsx-sharing-settings' === $current_screen->id) { |
|
74 | 74 | $enabled = false; |
75 | 75 | } |
76 | 76 | } |
@@ -86,14 +86,14 @@ discard block |
||
86 | 86 | * @param object $cmb2_obj |
87 | 87 | * @return void |
88 | 88 | */ |
89 | - public function generate_navigation( $cmb_id, $object_id, $object_type, $cmb2_obj ) { |
|
90 | - if ( 'lsx_sharing_settings' === $cmb_id && 'lsx-sharing-settings' === $object_id && 'options-page' === $object_type ) { |
|
89 | + public function generate_navigation($cmb_id, $object_id, $object_type, $cmb2_obj) { |
|
90 | + if ('lsx_sharing_settings' === $cmb_id && 'lsx-sharing-settings' === $object_id && 'options-page' === $object_type) { |
|
91 | 91 | $this->navigation = array(); |
92 | 92 | $this->is_options_page = true; |
93 | - if ( isset( $cmb2_obj->meta_box['fields'] ) && ! empty( $cmb2_obj->meta_box['fields'] ) ) { |
|
94 | - foreach ( $cmb2_obj->meta_box['fields'] as $field_index => $field ) { |
|
95 | - if ( 'title' === $field['type'] ) { |
|
96 | - $this->navigation[ $field_index ] = $field['name']; |
|
93 | + if (isset($cmb2_obj->meta_box['fields']) && ! empty($cmb2_obj->meta_box['fields'])) { |
|
94 | + foreach ($cmb2_obj->meta_box['fields'] as $field_index => $field) { |
|
95 | + if ('title' === $field['type']) { |
|
96 | + $this->navigation[$field_index] = $field['name']; |
|
97 | 97 | } |
98 | 98 | } |
99 | 99 | } |
@@ -107,32 +107,32 @@ discard block |
||
107 | 107 | * @return void |
108 | 108 | */ |
109 | 109 | public function output_navigation() { |
110 | - if ( ! empty( $this->navigation ) ) { |
|
110 | + if ( ! empty($this->navigation)) { |
|
111 | 111 | ?> |
112 | 112 | <div class="wp-filter hide-if-no-js"> |
113 | 113 | <ul class="filter-links"> |
114 | 114 | <?php |
115 | 115 | $first_tab = true; |
116 | - $total = count( $this->navigation ); |
|
116 | + $total = count($this->navigation); |
|
117 | 117 | $count = 0; |
118 | 118 | $separator = ' |'; |
119 | 119 | $selected_tab = ''; |
120 | - if ( isset( $_GET['cmb_tab'] ) && '' !== $_GET['cmb_tab'] ) { |
|
121 | - $selected_tab = sanitize_text_field( $_GET['cmb_tab'] ); |
|
120 | + if (isset($_GET['cmb_tab']) && '' !== $_GET['cmb_tab']) { |
|
121 | + $selected_tab = sanitize_text_field($_GET['cmb_tab']); |
|
122 | 122 | $selected_tab = 'settings_' . $selected_tab; |
123 | 123 | } |
124 | - foreach ( $this->navigation as $key => $label ) { |
|
124 | + foreach ($this->navigation as $key => $label) { |
|
125 | 125 | $count++; |
126 | 126 | $current_css = ''; |
127 | - if ( ( true === $first_tab && '' === $selected_tab ) || $key === $selected_tab ) { |
|
127 | + if ((true === $first_tab && '' === $selected_tab) || $key === $selected_tab) { |
|
128 | 128 | $first_tab = false; |
129 | 129 | $current_css = 'current'; |
130 | 130 | } |
131 | - if ( $count === $total ) { |
|
131 | + if ($count === $total) { |
|
132 | 132 | $separator = ''; |
133 | 133 | } |
134 | 134 | ?> |
135 | - <li><a href="#" class="<?php echo esc_attr( $current_css ); ?>" data-sort="<?php echo esc_attr( $key ); ?>_tab"><?php echo esc_attr( $label ); ?></a><?php echo esc_attr( $separator ); ?></li> |
|
135 | + <li><a href="#" class="<?php echo esc_attr($current_css); ?>" data-sort="<?php echo esc_attr($key); ?>_tab"><?php echo esc_attr($label); ?></a><?php echo esc_attr($separator); ?></li> |
|
136 | 136 | <?php |
137 | 137 | } |
138 | 138 | ?> |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | * @param object $field CMB2_Field(); |
149 | 149 | * @return void |
150 | 150 | */ |
151 | - public function output_tab_open_div( $field ) { |
|
152 | - if ( true === $this->is_options_page && isset( $field->args['type'] ) && 'title' === $field->args['type'] ) { |
|
151 | + public function output_tab_open_div($field) { |
|
152 | + if (true === $this->is_options_page && isset($field->args['type']) && 'title' === $field->args['type']) { |
|
153 | 153 | ?> |
154 | - <div id="<?php echo esc_attr( $field->args['id'] ); ?>_tab" class="tab tab-nav hidden"> |
|
154 | + <div id="<?php echo esc_attr($field->args['id']); ?>_tab" class="tab tab-nav hidden"> |
|
155 | 155 | <?php |
156 | 156 | } |
157 | 157 | } |
@@ -162,19 +162,19 @@ discard block |
||
162 | 162 | * @param object $field CMB2_Field(); |
163 | 163 | * @return void |
164 | 164 | */ |
165 | - public function output_tab_closing_div( $field ) { |
|
166 | - if ( true === $this->is_options_page && isset( $field->args['type'] ) && 'tab_closing' === $field->args['type'] ) { |
|
165 | + public function output_tab_closing_div($field) { |
|
166 | + if (true === $this->is_options_page && isset($field->args['type']) && 'tab_closing' === $field->args['type']) { |
|
167 | 167 | ?> |
168 | 168 | </div> |
169 | 169 | <?php |
170 | 170 | } |
171 | 171 | } |
172 | 172 | |
173 | - public function cmb2_render_callback_for_tab_closing( $field, $escaped_value, $object_id, $object_type, $field_type_object ) { |
|
173 | + public function cmb2_render_callback_for_tab_closing($field, $escaped_value, $object_id, $object_type, $field_type_object) { |
|
174 | 174 | return; |
175 | 175 | } |
176 | 176 | |
177 | - public function cmb2_sanitize_tab_closing_callback( $override_value, $value ) { |
|
177 | + public function cmb2_sanitize_tab_closing_callback($override_value, $value) { |
|
178 | 178 | return ''; |
179 | 179 | } |
180 | 180 | |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | * @param string $object_type |
187 | 187 | * @return void |
188 | 188 | */ |
189 | - public function navigation_js( $cmb_id, $object_id, $object_type ) { |
|
190 | - if ( 'lsx_sharing_settings' === $cmb_id && 'lsx-sharing-settings' === $object_id && 'options-page' === $object_type ) { |
|
189 | + public function navigation_js($cmb_id, $object_id, $object_type) { |
|
190 | + if ('lsx_sharing_settings' === $cmb_id && 'lsx-sharing-settings' === $object_id && 'options-page' === $object_type) { |
|
191 | 191 | ?> |
192 | 192 | <script> |
193 | 193 | var LSX_SHARING_CMB2 = Object.create( null ); |
@@ -224,14 +224,14 @@ discard block |
||
224 | 224 | * @param string $url |
225 | 225 | * @return void |
226 | 226 | */ |
227 | - public function add_tab_argument( $url ) { |
|
228 | - if ( isset( $_POST['cmb_tab'] ) && '' !== $_POST['cmb_tab'] ) { // @codingStandardsIgnoreLine |
|
229 | - $tab_selection = sanitize_text_field( $_POST['cmb_tab'] ); // @codingStandardsIgnoreLine |
|
230 | - $tab_selection = str_replace( array( 'settings_', '_tab' ), '', $tab_selection ); // @codingStandardsIgnoreLine |
|
231 | - if ( 'single' !== $tab_selection ) { |
|
232 | - $url = add_query_arg( 'cmb_tab', $tab_selection, $url ); |
|
227 | + public function add_tab_argument($url) { |
|
228 | + if (isset($_POST['cmb_tab']) && '' !== $_POST['cmb_tab']) { // @codingStandardsIgnoreLine |
|
229 | + $tab_selection = sanitize_text_field($_POST['cmb_tab']); // @codingStandardsIgnoreLine |
|
230 | + $tab_selection = str_replace(array('settings_', '_tab'), '', $tab_selection); // @codingStandardsIgnoreLine |
|
231 | + if ('single' !== $tab_selection) { |
|
232 | + $url = add_query_arg('cmb_tab', $tab_selection, $url); |
|
233 | 233 | } else { |
234 | - $url = remove_query_arg( 'cmb_tab', $url ); |
|
234 | + $url = remove_query_arg('cmb_tab', $url); |
|
235 | 235 | } |
236 | 236 | } |
237 | 237 | return $url; |