PluginProbe
TablePress – Tables in WordPress made easy / 1.14
TablePress – Tables in WordPress made easy v1.14
3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 2.4.4 All 44 releases
tablepress / classes / class-admin-page-helper.php

class-admin-page-helper.php in TablePress – Tables in WordPress made easy 1.14, at classes/class-admin-page-helper.php

130 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Page Helper Class for TablePress with functions needed in the admin area
4 *
5 * @package TablePress
6 * @subpackage Views
7 * @author Tobias Bäthge
8 * @since 1.0.0
9 */
10
11 // Prohibit direct script loading.
12 defined( 'ABSPATH' ) || die( 'No direct script access allowed!' );
13
14 /**
15 * Admin Page class
16 * @package TablePress
17 * @subpackage Views
18 * @author Tobias Bäthge
19 * @since 1.0.0
20 */
21 class TablePress_Admin_Page {
22
23 /**
24 * Enqueue a CSS file.
25 *
26 * @since 1.0.0
27 *
28 * @param string $name Name of the CSS file, without extension.
29 * @param array $dependencies Optional. List of names of CSS stylesheets that this stylesheet depends on, and which need to be included before this one.
30 */
31 public function enqueue_style( $name, array $dependencies = array() ) {
32 $suffix = SCRIPT_DEBUG ? '' : '.min';
33 $css_file = "admin/css/{$name}{$suffix}.css";
34 $css_url = plugins_url( $css_file, TABLEPRESS__FILE__ );
35 wp_enqueue_style( "tablepress-{$name}", $css_url, $dependencies, TablePress::version );
36 }
37
38 /**
39 * Enqueue a JavaScript file, possibly with dependencies and extra information.
40 *
41 * @since 1.0.0
42 *
43 * @param string $name Name of the JS file, without extension.
44 * @param array $dependencies Optional. List of names of JS scripts that this script depends on, and which need to be included before this one.
45 * @param array $localize_script Optional. An array with strings that gets transformed into a JS object and is added to the page before the script is included.
46 * @param bool $force_minified Optional. Always load the minified version, regardless of SCRIPT_DEBUG constant value.
47 */
48 public function enqueue_script( $name, array $dependencies = array(), array $localize_script = array(), $force_minified = false ) {
49 $suffix = ( ! $force_minified && SCRIPT_DEBUG ) ? '' : '.min';
50 $js_file = "admin/js/{$name}{$suffix}.js";
51 $js_url = plugins_url( $js_file, TABLEPRESS__FILE__ );
52 wp_enqueue_script( "tablepress-{$name}", $js_url, $dependencies, TablePress::version, true );
53 if ( ! empty( $localize_script ) ) {
54 foreach ( $localize_script as $var_name => $var_data ) {
55 wp_localize_script( "tablepress-{$name}", "tablepress_{$var_name}", $var_data );
56 }
57 }
58 }
59
60 /**
61 * Register a filter hook on the admin footer.
62 *
63 * @since 1.0.0
64 */
65 public function add_admin_footer_text() {
66 // Show admin footer message (only on TablePress admin screens).
67 add_filter( 'admin_footer_text', array( $this, '_admin_footer_text' ) );
68 }
69
70 /**
71 * Add a TablePress "Thank You" message to the admin footer content.
72 *
73 * @since 1.0.0
74 *
75 * @param string $content Current admin footer content.
76 * @return string New admin footer content.
77 */
78 public function _admin_footer_text( $content ) {
79 $content .= ' &bull; ' . sprintf( __( 'Thank you for using <a href="%s">TablePress</a>.', 'tablepress' ), 'https://tablepress.org/' );
80 $content .= ' ' . sprintf( __( 'Support the plugin with your <a href="%s">donation</a>!', 'tablepress' ), 'https://tablepress.org/donate/' );
81 return $content;
82 }
83
84 /**
85 * Print the JavaScript code for a WP feature pointer.
86 *
87 * @since 1.0.0
88 *
89 * @param string $pointer_id The pointer ID.
90 * @param string $selector The HTML elements, on which the pointer should be attached.
91 * @param array $args Arguments to be passed to the pointer JS (see wp-pointer.js).
92 */
93 public function print_wp_pointer_js( $pointer_id, $selector, array $args ) {
94 if ( empty( $pointer_id ) || empty( $selector ) || empty( $args['content'] ) ) {
95 return;
96 }
97 ?>
98 <script type="text/javascript">
99 ( function( $ ) {
100 var options = <?php echo wp_json_encode( $args, TABLEPRESS_JSON_OPTIONS ); ?>, setup;
101
102 if ( ! options ) {
103 return;
104 }
105
106 options = $.extend( options, {
107 close: function() {
108 $.post( ajaxurl, {
109 pointer: '<?php echo $pointer_id; ?>',
110 action: 'dismiss-wp-pointer'
111 } );
112 }
113 } );
114
115 setup = function() {
116 $( '<?php echo $selector; ?>' ).pointer( options ).pointer( 'open' );
117 };
118
119 if ( options.position && options.position.defer_loading ) {
120 $( window ).on( 'load.wp-pointers', setup );
121 } else {
122 $( setup );
123 }
124 } )( jQuery );
125 </script>
126 <?php
127 }
128
129 } // class TablePress_Admin_Page
130