Skip to content

Commit 3505079

Browse files
support actions only when WP >= 4.7
1 parent 32f02f7 commit 3505079

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

classes/Visualizer/Module/Frontend.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public function enqueueScripts() {
169169
* @param array $atts The array of shortcode attributes.
170170
*/
171171
public function renderChart( $atts ) {
172+
global $wp_version;
172173
$atts = shortcode_atts(
173174
array(
174175
'id' => false, // chart id
@@ -239,7 +240,7 @@ public function renderChart( $atts ) {
239240
'visualizer-render', 'visualizer', array(
240241
'charts' => $this->_charts,
241242
'map_api_key' => get_option( 'visualizer-map-api-key' ),
242-
'rest_url' => rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ),
243+
'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
243244
'i10n' => array(
244245
'copied' => __( 'Copied!', 'visualizer' ),
245246
),

classes/Visualizer/Render/Sidebar.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,24 @@ protected function _renderAdvancedSettings() {
192192
* @access protected
193193
*/
194194
protected function _renderActionSettings() {
195+
global $wp_version;
196+
$disable_actions = version_compare( $wp_version, '4.7.0', '<' );
195197
self::_renderSectionStart( esc_html__( 'Actions', 'visualizer' ), false );
196198
self::_renderCheckboxItem(
197199
esc_html__( 'Print', 'visualizer' ),
198200
'actions[]',
199201
isset( $this->actions ) && in_array( 'print', $this->actions ) ? true : false,
200202
'print',
201-
esc_html__( 'To enable printing the data.', 'visualizer' )
203+
$disable_actions ? '<span class="viz-section-error">' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '</span>' : esc_html__( 'To enable printing the data.', 'visualizer' ),
204+
$disable_actions
202205
);
203206
self::_renderCheckboxItem(
204207
esc_html__( 'CSV', 'visualizer' ),
205208
'actions[]',
206209
isset( $this->actions ) && in_array( 'csv;application/csv', $this->actions ) ? true : false,
207210
'csv;application/csv',
208-
esc_html__( 'To enable downloading the data as a CSV.', 'visualizer' )
211+
$disable_actions ? '<span class="viz-section-error">' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '</span>' : esc_html__( 'To enable downloading the data as a CSV.', 'visualizer' ),
212+
$disable_actions
209213
);
210214

211215
$disabled = ! ( class_exists( 'PHPExcel' ) && extension_loaded( 'zip' ) && extension_loaded( 'xml' ) && version_compare( PHP_VERSION, '5.2.0', '>' ) );
@@ -214,15 +218,16 @@ protected function _renderActionSettings() {
214218
'actions[]',
215219
isset( $this->actions ) && in_array( 'xls;application/vnd.ms-excel', $this->actions ) ? true : false,
216220
'xls;application/vnd.ms-excel',
217-
$disabled ? '<span class="viz-section-error">' . esc_html__( 'Enable the ZIP and XML extensions to use this setting.', 'visualizer' ) . '</span>' : esc_html__( 'To enable downloading the data as an Excel spreadsheet.', 'visualizer' ),
218-
$disabled
221+
$disable_actions ? '<span class="viz-section-error">' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '</span>' : ( $disabled ? '<span class="viz-section-error">' . esc_html__( 'Enable the ZIP and XML extensions to use this setting.', 'visualizer' ) . '</span>' : esc_html__( 'To enable downloading the data as an Excel spreadsheet.', 'visualizer' ) ),
222+
$disable_actions || $disabled
219223
);
220224
self::_renderCheckboxItem(
221225
esc_html__( 'Copy', 'visualizer' ),
222226
'actions[]',
223227
isset( $this->actions ) && in_array( 'copy', $this->actions ) ? true : false,
224228
'copy',
225-
esc_html__( 'To enable copying the data to the clipboard.', 'visualizer' )
229+
$disable_actions ? '<span class="viz-section-error">' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '</span>' : esc_html__( 'To enable copying the data to the clipboard.', 'visualizer' ),
230+
$disable_actions
226231
);
227232
self::_renderSectionEnd();
228233
}

0 commit comments

Comments
 (0)