Skip to content

Commit 5f6efca

Browse files
Merge pull request #546 from Codeinwp/development
Add support for Dataset schema Horizontal Axis formatting should apply to tooltips
2 parents ec168af + a70b0f8 commit 5f6efca

File tree

10 files changed

+110
-11
lines changed

10 files changed

+110
-11
lines changed

classes/Visualizer/Gutenberg/Block.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function enqueue_gutenberg_scripts() {
8787
if ( Visualizer_Module::is_pro() ) {
8888
$type = 'pro';
8989
if ( apply_filters( 'visualizer_is_business', false ) ) {
90-
$type = 'developer';
90+
$type = 'business';
9191
}
9292
}
9393

@@ -156,6 +156,9 @@ public function register_rest_endpoints() {
156156
'sanitize_callback' => 'absint',
157157
),
158158
),
159+
'permission_callback' => function () {
160+
return current_user_can( 'edit_posts' );
161+
},
159162
)
160163
);
161164

@@ -170,6 +173,9 @@ public function register_rest_endpoints() {
170173
'sanitize_callback' => 'esc_url_raw',
171174
),
172175
),
176+
'permission_callback' => function () {
177+
return current_user_can( 'edit_posts' );
178+
},
173179
)
174180
);
175181

@@ -184,6 +190,9 @@ public function register_rest_endpoints() {
184190
'sanitize_callback' => 'sanitize_text_field',
185191
),
186192
),
193+
'permission_callback' => function () {
194+
return current_user_can( 'edit_posts' );
195+
},
187196
)
188197
);
189198
}
@@ -249,15 +258,20 @@ public function update_chart_data( $data ) {
249258

250259
if ( $data['id'] && ! is_wp_error( $data['id'] ) ) {
251260

252-
update_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_TYPE, $data['visualizer-chart-type'] );
253-
update_post_meta( $data['id'], Visualizer_Plugin::CF_SOURCE, $data['visualizer-source'] );
261+
$chart_type = sanitize_text_field( $data['visualizer-chart-type'] );
262+
$source_type = sanitize_text_field( $data['visualizer-source'] );
263+
264+
update_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_TYPE, $chart_type );
265+
update_post_meta( $data['id'], Visualizer_Plugin::CF_SOURCE, $source_type );
254266
update_post_meta( $data['id'], Visualizer_Plugin::CF_DEFAULT_DATA, $data['visualizer-default-data'] );
255267
update_post_meta( $data['id'], Visualizer_Plugin::CF_SERIES, $data['visualizer-series'] );
256268
update_post_meta( $data['id'], Visualizer_Plugin::CF_SETTINGS, $data['visualizer-settings'] );
257269

258270
if ( $data['visualizer-chart-url'] && $data['visualizer-chart-schedule'] ) {
259-
update_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_URL, $data['visualizer-chart-url'] );
260-
apply_filters( 'visualizer_pro_chart_schedule', $data['id'], $data['visualizer-chart-url'], $data['visualizer-chart-schedule'] );
271+
$chart_url = esc_url_raw( $data['visualizer-chart-url'] );
272+
$chart_schedule = intval( $data['visualizer-chart-schedule'] );
273+
update_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_URL, $chart_url );
274+
apply_filters( 'visualizer_pro_chart_schedule', $data['id'], $chart_url, $chart_schedule );
261275
} else {
262276
delete_post_meta( $data['id'], Visualizer_Plugin::CF_CHART_URL );
263277
apply_filters( 'visualizer_pro_remove_schedule', $data['id'] );
@@ -268,7 +282,8 @@ public function update_chart_data( $data ) {
268282
}
269283

270284
if ( $data['visualizer-chart-url'] ) {
271-
$content['source'] = $data['visualizer-chart-url'];
285+
$chart_url = esc_url_raw( $data['visualizer-chart-url'] );
286+
$content['source'] = $chart_url;
272287
$content['data'] = $this->format_chart_data( $data['visualizer-data'], $data['visualizer-series'] );
273288
} else {
274289
$content = $this->format_chart_data( $data['visualizer-data'], $data['visualizer-series'] );

classes/Visualizer/Module/Frontend.php

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,55 @@ public function renderChart( $atts ) {
344344
}
345345

346346
// return placeholder div
347-
return $actions_div . '<div id="' . $id . '"' . $class . '></div>';
347+
return $actions_div . '<div id="' . $id . '"' . $class . '></div>' . $this->addSchema( $chart->ID );
348+
}
349+
350+
/**
351+
* Adds the schema corresponding to the dataset.
352+
*
353+
* @since 3.3.2
354+
*
355+
* @access private
356+
*/
357+
private function addSchema( $id ) {
358+
$settings = get_post_meta( $id, Visualizer_Plugin::CF_SETTINGS, true );
359+
$title = '';
360+
if ( isset( $settings['title'] ) && ! empty( $settings['title'] ) ) {
361+
$title = $settings['title'];
362+
if ( is_array( $title ) ) {
363+
$title = $settings['title']['text'];
364+
}
365+
}
366+
$title = apply_filters( 'visualizer_schema_name', $title, $id );
367+
if ( empty( $title ) ) {
368+
return '';
369+
}
370+
371+
$desc = '';
372+
if ( isset( $settings['description'] ) && ! empty( $settings['description'] ) ) {
373+
$desc = $settings['description'];
374+
}
375+
$desc = apply_filters( 'visualizer_schema_description', $desc, $id );
376+
// descriptions below 50 chars are not allowed.
377+
if ( empty( $desc ) || strlen( $desc ) < 50 ) {
378+
return '';
379+
}
380+
381+
$schema = apply_filters(
382+
'visualizer_schema',
383+
'{
384+
"@context":"https://schema.org/",
385+
"@type":"Dataset",
386+
"name":"' . esc_html( $title ) . '",
387+
"description":"' . esc_html( $desc ) . '"
388+
}',
389+
$id
390+
);
391+
392+
if ( empty( $schema ) ) {
393+
return '';
394+
}
395+
396+
return '<script type="application/ld+json">' . $schema . '</script>';
348397
}
349398
}

classes/Visualizer/Plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
class Visualizer_Plugin {
2929

3030
const NAME = 'visualizer';
31-
const VERSION = '3.3.1';
31+
const VERSION = '3.3.2';
3232

3333
// custom post types
3434
const CPT_VISUALIZER = 'visualizer';

classes/Visualizer/Render/Sidebar/ChartJS.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ protected function _renderChartTitleSettings() {
161161
'#000'
162162
);
163163

164+
echo '<div class="viz-section-delimiter"></div>';
165+
166+
self::_renderTextAreaItem(
167+
esc_html__( 'Chart Description', 'visualizer' ),
168+
'description',
169+
$this->description,
170+
sprintf( esc_html__( 'Description to display in the structured data schema as explained %1$shere%2$s', 'visualizer' ), '<a href="https://developers.google.com/search/docs/data-types/dataset#dataset" target="_blank">', '</a>' )
171+
);
172+
164173
}
165174

166175
/**

classes/Visualizer/Render/Sidebar/Graph.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ protected function _renderChartTitleSettings() {
122122
$this->_positions,
123123
esc_html__( 'Determines where to place the axis titles, compared to the chart area.', 'visualizer' )
124124
);
125+
126+
echo '<div class="viz-section-delimiter"></div>';
127+
128+
self::_renderTextAreaItem(
129+
esc_html__( 'Chart Description', 'visualizer' ),
130+
'description',
131+
$this->description,
132+
sprintf( esc_html__( 'Description to display in the structured data schema as explained %1$shere%2$s', 'visualizer' ), '<a href="https://developers.google.com/search/docs/data-types/dataset#dataset" target="_blank">', '</a>' )
133+
);
134+
125135
}
126136

127137
/**

classes/Visualizer/Render/Sidebar/Type/DataTable/DataTable.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ protected function _renderGeneralSettings() {
136136
$this->title,
137137
esc_html__( 'Text to display in the back-end admin area.', 'visualizer' )
138138
);
139+
140+
echo '<div class="viz-section-delimiter"></div>';
141+
142+
self::_renderTextAreaItem(
143+
esc_html__( 'Chart Description', 'visualizer' ),
144+
'description',
145+
$this->description,
146+
sprintf( esc_html__( 'Description to display in the structured data schema as explained %1$shere%2$s', 'visualizer' ), '<a href="https://developers.google.com/search/docs/data-types/dataset#dataset" target="_blank">', '</a>' )
147+
);
148+
139149
self::_renderSectionEnd();
140150
self::_renderGroupEnd();
141151
}

css/media.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Version: 3.3.1
2+
Version: 3.3.2
33
*/
44
#visualizer-library-view {
55
padding: 30px 10px 10px 30px;

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Plugin Name: Visualizer: Tables and Charts Manager for WordPress
55
Plugin URI: https://themeisle.com/plugins/visualizer-charts-and-graphs-lite/
66
Description: A simple, easy to use and quite powerful tool to create, manage and embed interactive charts into your WordPress posts and pages. The plugin uses Google Visualization API to render charts, which supports cross-browser compatibility (adopting VML for older IE versions) and cross-platform portability to iOS and new Android releases.
7-
Version: 3.3.1
7+
Version: 3.3.2
88
Author: Themeisle
99
Author URI: http://themeisle.com
1010
License: GPL v2.0 or later

js/render-google.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ var __visualizer_chart_images = [];
214214
} else if (chart.type === 'pie' && settings.format && settings.format !== '') {
215215
format_data(id, table, 'number', settings.format, 1);
216216
}
217+
218+
219+
if(settings.hAxis) {
220+
format_data(id, table, series[0].type, settings.hAxis.format, 0);
221+
}
222+
217223
override(settings);
218224

219225
gv.events.addListener(render, 'ready', function () {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "visualizer",
3-
"version": "3.3.1",
3+
"version": "3.3.2",
44
"description": "Visualizer Lite",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)