PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 1.5.3
Visualizer – Tables & Charts Manager with Built-in AI Generator v1.5.3
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
← All changes | classes/Visualizer/Module.php +145 -546 3.1.01.5.3 View file →
@@ -1,546 +1,145 @@
1 -<?php
2 -
3 -// +----------------------------------------------------------------------+
4 -// | Copyright 2013 Madpixels (email : visualizer@madpixels.net) |
5 -// +----------------------------------------------------------------------+
6 -// | This program is free software; you can redistribute it and/or modify |
7 -// | it under the terms of the GNU General Public License, version 2, as |
8 -// | published by the Free Software Foundation. |
9 -// | |
10 -// | This program is distributed in the hope that it will be useful, |
11 -// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 -// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 -// | GNU General Public License for more details. |
14 -// | |
15 -// | You should have received a copy of the GNU General Public License |
16 -// | along with this program; if not, write to the Free Software |
17 -// | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
18 -// | MA 02110-1301 USA |
19 -// +----------------------------------------------------------------------+
20 -// | Author: Eugene Manuilov <eugene@manuilov.org> |
21 -// +----------------------------------------------------------------------+
22 -/**
23 - * Base class for all modules. Implements routine methods required by all modules.
24 - *
25 - * @category Visualizer
26 - * @package Module
27 - *
28 - * @since 1.0.0
29 - */
30 -class Visualizer_Module {
31 -
32 - /**
33 - * The instance of wpdb class.
34 - *
35 - * @since 1.0.0
36 - *
37 - * @access protected
38 - * @var wpdb
39 - */
40 - protected $_wpdb = null;
41 -
42 - /**
43 - * The plugin instance.
44 - *
45 - * @since 1.0.0
46 - *
47 - * @access protected
48 - * @var Visualizer_Plugin
49 - */
50 - protected $_plugin = null;
51 -
52 - /**
53 - * Constructor.
54 - *
55 - * @since 1.0.0
56 - * @global wpdb $wpdb Current database connection.
57 - *
58 - * @access public
59 - * @param Visualizer_Plugin $plugin The instance of the plugin.
60 - */
61 - public function __construct( Visualizer_Plugin $plugin ) {
62 - global $wpdb;
63 -
64 - $this->_wpdb = $wpdb;
65 - $this->_plugin = $plugin;
66 -
67 - $this->_addFilter( Visualizer_Plugin::FILTER_UNDO_REVISIONS, 'undoRevisions', 10, 2 );
68 - $this->_addFilter( Visualizer_Plugin::FILTER_HANDLE_REVISIONS, 'handleExistingRevisions', 10, 2 );
69 -
70 - }
71 -
72 - /**
73 - * Registers an action hook.
74 - *
75 - * @since 1.0.0
76 - * @uses add_action() To register action hook.
77 - *
78 - * @access protected
79 - * @param string $tag The name of the action to which the $method is hooked.
80 - * @param string $method The name of the method to be called.
81 - * @param bool $methodClass The root of the method.
82 - * @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
83 - * @param int $accepted_args optional. The number of arguments the function accept (default 1).
84 - * @return Visualizer_Module
85 - */
86 - protected function _addAction( $tag, $method, $methodClass = null, $priority = 10, $accepted_args = 1 ) {
87 - add_action( $tag, array( $methodClass ? $methodClass : $this, $method ), $priority, $accepted_args );
88 - return $this;
89 - }
90 -
91 - /**
92 - * Registers AJAX action hook.
93 - *
94 - * @since 1.0.0
95 - *
96 - * @access public
97 - * @param string $tag The name of the AJAX action to which the $method is hooked.
98 - * @param string $method Optional. The name of the method to be called. If the name of the method is not provided, tag name will be used as method name.
99 - * @param bool $methodClass The root of the method.
100 - * @param boolean $private Optional. Determines if we should register hook for logged in users.
101 - * @param boolean $public Optional. Determines if we should register hook for not logged in users.
102 - * @return Visualizer_Module
103 - */
104 - protected function _addAjaxAction( $tag, $method = '', $methodClass = null, $private = true, $public = false ) {
105 - if ( $private ) {
106 - $this->_addAction( 'wp_ajax_' . $tag, $method, $methodClass );
107 - }
108 -
109 - if ( $public ) {
110 - $this->_addAction( 'wp_ajax_nopriv_' . $tag, $method, $methodClass );
111 - }
112 -
113 - return $this;
114 - }
115 -
116 - /**
117 - * Registers a filter hook.
118 - *
119 - * @since 1.0.0
120 - * @uses add_filter() To register filter hook.
121 - *
122 - * @access protected
123 - * @param string $tag The name of the filter to hook the $method to.
124 - * @param type $method The name of the method to be called when the filter is applied.
125 - * @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
126 - * @param int $accepted_args optional. The number of arguments the function accept (default 1).
127 - * @return Visualizer_Module
128 - */
129 - protected function _addFilter( $tag, $method, $priority = 10, $accepted_args = 1 ) {
130 - add_filter( $tag, array( $this, $method ), $priority, $accepted_args );
131 - return $this;
132 - }
133 -
134 - /**
135 - * Registers a hook for shortcode tag.
136 - *
137 - * @since 1.0.0
138 - * @uses add_shortcode() To register shortcode hook.
139 - *
140 - * @access protected
141 - * @param string $tag Shortcode tag to be searched in post content.
142 - * @param string $method Hook to run when shortcode is found.
143 - * @return Visualizer_Module
144 - */
145 - protected function _addShortcode( $tag, $method ) {
146 - add_shortcode( $tag, array( $this, $method ) );
147 - return $this;
148 - }
149 -
150 - /**
151 - * Extracts the data for a chart and prepares it for the given type.
152 - *
153 - * @access public
154 - * @param int $chart_id The chart id.
155 - * @param string $type The exported type.
156 - */
157 - public function _getDataAs( $chart_id, $type ) {
158 - $final = null;
159 - $success = false;
160 - if ( $chart_id ) {
161 - $chart = get_post( $chart_id );
162 - $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
163 - }
164 - if ( $success ) {
165 - $settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true );
166 - $rows = array();
167 - $series = get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true );
168 - $data = unserialize( $chart->post_content );
169 - if ( ! empty( $series ) ) {
170 - $row = array();
171 - foreach ( $series as $array ) {
172 - $row[] = $array['label'];
173 - }
174 - $rows[] = $row;
175 - $row = array();
176 - foreach ( $series as $array ) {
177 - $row[] = $array['type'];
178 - }
179 - $rows[] = $row;
180 - }
181 - if ( ! empty( $data ) ) {
182 - foreach ( $data as $array ) {
183 - // ignore strings
184 - if ( ! is_array( $array ) ) {
185 - continue;
186 - }
187 - // if this is an array of arrays...
188 - if ( is_array( $array[0] ) ) {
189 - foreach ( $array as $arr ) {
190 - $rows[] = $arr;
191 - }
192 - } else {
193 - // just an array
194 - $rows[] = $array;
195 - }
196 - }
197 - }
198 -
199 - $filename = isset( $settings['title'] ) && ! empty( $settings['title'] ) ? $settings['title'] : 'visualizer#' . $chart_id;
200 -
201 - switch ( $type ) {
202 - case 'csv':
203 - $final = $this->_getCSV( $rows, $filename );
204 - break;
205 - case 'xls':
206 - $final = $this->_getExcel( $rows, $filename );
207 - break;
208 - case 'print':
209 - $final = $this->_getHTML( $rows );
210 - break;
211 - }
212 - }
213 - return $final;
214 - }
215 -
216 - /**
217 - * Prepares a CSV.
218 - *
219 - * @access private
220 - * @param array $rows The array of data.
221 - * @param string $filename The name of the file to use.
222 - */
223 - private function _getCSV( $rows, $filename ) {
224 - $filename .= '.csv';
225 -
226 - $fp = tmpfile();
227 - // support for MS Excel
228 - fprintf( $fp, $bom = ( chr( 0xEF ) . chr( 0xBB ) . chr( 0xBF ) ) );
229 - foreach ( $rows as $row ) {
230 - fputcsv( $fp, $row );
231 - }
232 - rewind( $fp );
233 - $csv = '';
234 - while ( ( $array = fgetcsv( $fp ) ) !== false ) {
235 - if ( strlen( $csv ) > 0 ) {
236 - $csv .= PHP_EOL;
237 - }
238 - $csv .= implode( ',', $array );
239 - }
240 - fclose( $fp );
241 -
242 - return array(
243 - 'csv' => $csv,
244 - 'name' => $filename,
245 - );
246 - }
247 -
248 - /**
249 - * Prepares an Excel file.
250 - *
251 - * @access private
252 - * @param array $rows The array of data.
253 - * @param string $filename The name of the file to use.
254 - */
255 - private function _getExcel( $rows, $filename ) {
256 - // PHPExcel does not like sheet names longer than 31 characters.
257 - $chart = substr( $filename, 0, 30 );
258 - $filename .= '.xlsx';
259 -
260 - $xlsData = '';
261 - if ( class_exists( 'PHPExcel' ) ) {
262 - $doc = new PHPExcel();
263 - $doc->getActiveSheet()->fromArray( $rows, null, 'A1' );
264 - $doc->getActiveSheet()->setTitle( sanitize_title( $chart ) );
265 - $doc = apply_filters( 'visualizer_excel_doc', $doc );
266 - $writer = PHPExcel_IOFactory::createWriter( $doc, 'Excel2007' );
267 - ob_start();
268 - $writer->save( 'php://output' );
269 - $xlsData = ob_get_contents();
270 - ob_end_clean();
271 - } else {
272 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Class PHPExcel does not exist!', 'error', __FILE__, __LINE__ );
273 - error_log( 'Class PHPExcel does not exist!' );
274 - }
275 - return array(
276 - 'csv' => 'data:application/vnd.ms-excel;base64,' . base64_encode( $xlsData ),
277 - 'name' => $filename,
278 - );
279 - }
280 -
281 - /**
282 - * Prepares an HTML table.
283 - *
284 - * @access private
285 - * @param array $rows The array of data.
286 - */
287 - private function _getHTML( $rows ) {
288 - $css = '
289 - table.visualizer-print {
290 - border-collapse: collapse;
291 - }
292 - table.visualizer-print, table.visualizer-print th, table.visualizer-print td {
293 - border: 1px solid #000;
294 - }
295 - ';
296 - $html = '';
297 - $html .= '
298 - <html>
299 - <head>
300 - <style>
301 - ' . apply_filters( 'visualizer_print_css', $css ) . '
302 - </style>
303 - </head>
304 - <body>';
305 -
306 - $table = '<table class="visualizer-print">';
307 - $index = 0;
308 - foreach ( $rows as $row ) {
309 - $table .= '<tr>';
310 - foreach ( $row as $col ) {
311 - if ( $index === 0 ) {
312 - $table .= '<th>' . $col . '</th>';
313 - } else {
314 - $table .= '<td>' . $col . '</td>';
315 - }
316 - }
317 - $table .= '</tr>';
318 - $index++;
319 - }
320 - $table .= '</table>';
321 -
322 - $html .= apply_filters( 'visualizer_print_table', $table ) . '
323 - </body>
324 - </html>';
325 - return array(
326 - 'csv' => $html,
327 - );
328 - }
329 -
330 - /**
331 - * Undo revisions for the chart, and if necessary, restore the earliest version.
332 - *
333 - * @return bool If any revisions were found.
334 - */
335 - public final function undoRevisions( $chart_id, $restore = false ) {
336 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'undoRevisions for %d with%s restore', $chart_id, ( $restore ? '' : 'out' ) ), 'debug', __FILE__, __LINE__ );
337 -
338 - $revisions = wp_get_post_revisions( $chart_id, array( 'order' => 'ASC' ) );
339 - if ( count( $revisions ) > 1 ) {
340 - $revision_ids = array_keys( $revisions );
341 -
342 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'found %d revisions = %s', count( $revisions ), print_r( $revision_ids, true ) ), 'debug', __FILE__, __LINE__ );
343 -
344 - // when we restore, a new revision is likely to be created. so, let's disable revisions for the time being.
345 - add_filter( 'wp_revisions_to_keep', '__return_false' );
346 -
347 - if ( $restore ) {
348 - // restore to the oldest one i.e. the first one.
349 - wp_restore_post_revision( array_shift( $revision_ids ) );
350 - }
351 -
352 - // delete all revisions.
353 - foreach ( $revision_ids as $id ) {
354 - wp_delete_post_revision( $id );
355 - }
356 -
357 - return true;
358 - }
359 - return false;
360 - }
361 -
362 - /**
363 - * If existing revisions exist for the chart, restore the earliest version and then create a new revision to initiate editing.
364 - */
365 - public final function handleExistingRevisions( $chart_id, $chart ) {
366 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'handleExistingRevisions for %d', $chart_id ), 'debug', __FILE__, __LINE__ );
367 -
368 - // undo revisions.
369 - $revisions_found = $this->undoRevisions( $chart_id, true );
370 -
371 - // create revision for the edit action.
372 - wp_save_post_revision( $chart_id );
373 -
374 - if ( $revisions_found ) {
375 - // fetch chart data again in case it was updated by an earlier revision.
376 - $chart = get_post( $chart_id );
377 - }
378 - return $chart;
379 - }
380 -
381 - /**
382 - * Returns the language of the locale.
383 - *
384 - * @access protected
385 - */
386 - protected function get_language() {
387 - $locale = get_locale();
388 - if ( empty( $locale ) ) {
389 - return '';
390 - }
391 - $array = explode( '_', $locale );
392 - if ( count( $array ) < 2 ) {
393 - return '';
394 - }
395 - return reset( $array );
396 - }
397 -
398 - /**
399 - * Gets/creates the JS where user-specific customizations can be/have been added.
400 - */
401 - protected function get_user_customization_js() {
402 - // use this as the JS file in case we are not able to create the file in uploads.
403 - $default = VISUALIZER_ABSURL . 'js/customization.js';
404 -
405 - $uploads = wp_get_upload_dir();
406 - $specific = $uploads['baseurl'] . '/visualizer/customization.js';
407 -
408 - // for testing on user sites (before we send them the correctly customized file).
409 - if ( VISUALIZER_TEST_JS_CUSTOMIZATION ) {
410 - return $default;
411 - }
412 -
413 - require_once( ABSPATH . 'wp-admin/includes/file.php' );
414 - WP_Filesystem();
415 - global $wp_filesystem;
416 -
417 - $dir = $wp_filesystem->wp_content_dir() . 'uploads/visualizer';
418 - $file = $wp_filesystem->wp_content_dir() . 'uploads/visualizer/customization.js';
419 -
420 - if ( $wp_filesystem->is_readable( $file ) ) {
421 - return $specific;
422 - }
423 -
424 - if ( $wp_filesystem->exists( $file ) && ! $wp_filesystem->is_readable( $file ) ) {
425 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to read file %s', $file ), 'error', __FILE__, __LINE__ );
426 - return $default;
427 - }
428 -
429 - if ( ! $wp_filesystem->exists( $dir ) ) {
430 - if ( ( $done = $wp_filesystem->mkdir( $dir ) ) === false ) {
431 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ );
432 - return $default;
433 - }
434 - }
435 -
436 - // if file does not exist, copy.
437 - if ( ! $wp_filesystem->exists( $file ) ) {
438 - $src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' );
439 - if ( ( $done = $wp_filesystem->copy( $src, $file ) ) === false ) {
440 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ );
441 - return $default;
442 - }
443 - }
444 -
445 - return $specific;
446 - }
447 -
448 - /**
449 - * Load the class for the given chart's chart type so that its assets can be loaded.
450 - */
451 - protected function load_chart_type( $chart_id ) {
452 - $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
453 - $name = 'Visualizer_Render_Sidebar_Type_' . ucwords( $type );
454 - $class = null;
455 - if ( class_exists( $name ) || true === apply_filters( 'visualizer_load_chart', false, $name ) ) {
456 - $class = new $name;
457 - }
458 -
459 - if ( is_null( $class ) && VISUALIZER_PRO ) {
460 - // lets see if this type exists in pro. New Lite(3.1.0+) & old Pro(1.8.0-).
461 - $class = apply_filters( 'visualizer_pro_chart_type_sidebar', null, array( 'type' => $type, 'settings' => get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ) ) );
462 - }
463 -
464 - return is_null( $class ) ? null : $class->getLibrary();
465 - }
466 -
467 - /**
468 - * Generates the inline CSS to apply to the chart and adds these classes to the settings.
469 - *
470 - * @access public
471 - * @param int $id The id of the chart.
472 - * @param array $settings The settings of the chart.
473 - */
474 - protected function get_inline_custom_css( $id, $settings ) {
475 - $css = '';
476 -
477 - $arguments = array( '', $settings );
478 - if ( ! isset( $settings['customcss'] ) ) {
479 - return $arguments;
480 - }
481 -
482 - $classes = array();
483 - $css = '<style type="text/css" name="visualizer-custom-css" id="customcss-' . $id . '">';
484 - foreach ( $settings['customcss'] as $name => $element ) {
485 - $attributes = array();
486 - foreach ( $element as $property => $value ) {
487 - $attributes[] = $this->handle_css_property( $property, $value );
488 - }
489 - $class_name = $id . $name;
490 - $properties = implode( '; ', array_filter( $attributes ) );
491 - if ( ! empty( $properties ) ) {
492 - $css .= '.' . $class_name . ' {' . $properties . ' !important;}';
493 - $classes[ $name ] = $class_name;
494 - }
495 - }
496 - $css .= '</style>';
497 -
498 - $settings['cssClassNames'] = $classes;
499 -
500 - $arguments = array( $css, $settings );
501 - apply_filters_ref_array( 'visualizer_inline_css', array( &$arguments ) );
502 -
503 - return $arguments;
504 - }
505 -
506 - /**
507 - * Handles CSS properties that might need special syntax.
508 - *
509 - * @access private
510 - * @param string $property The name of the css property.
511 - * @param string $value The value of the css property.
512 - */
513 - private function handle_css_property( $property, $value ) {
514 - if ( empty( $property ) || empty( $value ) ) {
515 - return '';
516 - }
517 -
518 - switch ( $property ) {
519 - case 'transform':
520 - $value = 'rotate(' . $value . 'deg)';
521 - break;
522 - }
523 - return $property . ': ' . $value;
524 - }
525 -
526 - /**
527 - * Determines if charts have been created of the particular chart type.
528 - */
529 - protected static function hasChartType( $type ) {
530 - $args = array(
531 - 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
532 - 'fields' => 'ids',
533 - 'post_status' => 'publish',
534 - 'meta_query' => array(
535 - array(
536 - 'key' => Visualizer_Plugin::CF_CHART_TYPE,
537 - 'value' => $type,
538 - ),
539 - ),
540 - );
541 -
542 - $q = new WP_Query( $args );
543 - return $q->found_posts > 0;
544 - }
545 -
546 -}
1 +<?php
2 +
3 +// +----------------------------------------------------------------------+
4 +// | Copyright 2013 Madpixels (email : visualizer@madpixels.net) |
5 +// +----------------------------------------------------------------------+
6 +// | This program is free software; you can redistribute it and/or modify |
7 +// | it under the terms of the GNU General Public License, version 2, as |
8 +// | published by the Free Software Foundation. |
9 +// | |
10 +// | This program is distributed in the hope that it will be useful, |
11 +// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 +// | GNU General Public License for more details. |
14 +// | |
15 +// | You should have received a copy of the GNU General Public License |
16 +// | along with this program; if not, write to the Free Software |
17 +// | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
18 +// | MA 02110-1301 USA |
19 +// +----------------------------------------------------------------------+
20 +// | Author: Eugene Manuilov <eugene@manuilov.org> |
21 +// +----------------------------------------------------------------------+
22 +
23 +/**
24 + * Base class for all modules. Implements routine methods required by all modules.
25 + *
26 + * @category Visualizer
27 + * @package Module
28 + *
29 + * @since 1.0.0
30 + */
31 +class Visualizer_Module {
32 +
33 + /**
34 + * The instance of wpdb class.
35 + *
36 + * @since 1.0.0
37 + *
38 + * @access protected
39 + * @var wpdb
40 + */
41 + protected $_wpdb = null;
42 +
43 + /**
44 + * The plugin instance.
45 + *
46 + * @since 1.0.0
47 + *
48 + * @access protected
49 + * @var Visualizer_Plugin
50 + */
51 + protected $_plugin = null;
52 +
53 + /**
54 + * Constructor.
55 + *
56 + * @since 1.0.0
57 + * @global wpdb $wpdb Current database connection.
58 + *
59 + * @access public
60 + * @param Visualizer_Plugin $plugin The instance of the plugin.
61 + */
62 + public function __construct( Visualizer_Plugin $plugin ) {
63 + global $wpdb;
64 +
65 + $this->_wpdb = $wpdb;
66 + $this->_plugin = $plugin;
67 + }
68 +
69 + /**
70 + * Registers an action hook.
71 + *
72 + * @since 1.0.0
73 + * @uses add_action() To register action hook.
74 + *
75 + * @access protected
76 + * @param string $tag The name of the action to which the $method is hooked.
77 + * @param string $method The name of the method to be called.
78 + * @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
79 + * @param int $accepted_args optional. The number of arguments the function accept (default 1).
80 + * @return Visualizer_Module
81 + */
82 + protected function _addAction( $tag, $method, $methodClass=NULL, $priority = 10, $accepted_args = 1 ) {
83 + add_action( $tag, array( $methodClass ? $methodClass : $this, $method ), $priority, $accepted_args );
84 + return $this;
85 + }
86 +
87 + /**
88 + * Registers AJAX action hook.
89 + *
90 + * @since 1.0.0
91 + *
92 + * @access public
93 + * @param string $tag The name of the AJAX action to which the $method is hooked.
94 + * @param string $method Optional. The name of the method to be called. If the name of the method is not provided, tag name will be used as method name.
95 + * @param boolean $private Optional. Determines if we should register hook for logged in users.
96 + * @param boolean $public Optional. Determines if we should register hook for not logged in users.
97 + * @return Visualizer_Module
98 + */
99 + protected function _addAjaxAction( $tag, $method = '', $methodClass=NULL, $private = true, $public = false ) {
100 + if ( $private ) {
101 + $this->_addAction( 'wp_ajax_' . $tag, $method, $methodClass );
102 + }
103 +
104 + if ( $public ) {
105 + $this->_addAction( 'wp_ajax_nopriv_' . $tag, $method, $methodClass );
106 + }
107 +
108 + return $this;
109 + }
110 +
111 + /**
112 + * Registers a filter hook.
113 + *
114 + * @since 1.0.0
115 + * @uses add_filter() To register filter hook.
116 + *
117 + * @access protected
118 + * @param string $tag The name of the filter to hook the $method to.
119 + * @param type $method The name of the method to be called when the filter is applied.
120 + * @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
121 + * @param int $accepted_args optional. The number of arguments the function accept (default 1).
122 + * @return Visualizer_Module
123 + */
124 + protected function _addFilter( $tag, $method, $priority = 10, $accepted_args = 1 ) {
125 + add_filter( $tag, array( $this, $method ), $priority, $accepted_args );
126 + return $this;
127 + }
128 +
129 + /**
130 + * Registers a hook for shortcode tag.
131 + *
132 + * @since 1.0.0
133 + * @uses add_shortcode() To register shortcode hook.
134 + *
135 + * @access protected
136 + * @param string $tag Shortcode tag to be searched in post content.
137 + * @param string $method Hook to run when shortcode is found.
138 + * @return Visualizer_Module
139 + */
140 + protected function _addShortcode( $tag, $method ) {
141 + add_shortcode( $tag, array( $this, $method ) );
142 + return $this;
143 + }
144 +
145 +}