PluginProbe
TablePress – Tables in WordPress made easy / 2.1.7
TablePress – Tables in WordPress made easy v2.1.7
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 / views / view-options.php

view-options.php in TablePress – Tables in WordPress made easy 2.1.7, at views/view-options.php

225 lines 9.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Options View
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 * Plugin Options View class
16 *
17 * @package TablePress
18 * @subpackage Views
19 * @author Tobias Bäthge
20 * @since 1.0.0
21 */
22 class TablePress_Options_View extends TablePress_View {
23
24 /**
25 * Set up the view with data and do things that are specific for this view.
26 *
27 * @since 1.0.0
28 *
29 * @param string $action Action for this view.
30 * @param array $data Data for this view.
31 */
32 public function setup( $action, array $data ) {
33 if ( current_user_can( 'tablepress_edit_options' ) ) {
34 // Register the feature pointer "Custom CSS" textarea, before running `parent::setup();`. This is done here as the target HTML element does not exist for all users.
35 $this->wp_pointers[] = 'tp20_options_custom_css_css_variables';
36 }
37
38 parent::setup( $action, $data );
39
40 $this->admin_page->enqueue_script( 'options' );
41
42 $this->process_action_messages( array(
43 'success_save' => __( 'Options saved successfully.', 'tablepress' ),
44 'success_save_error_custom_css' => __( 'Options saved successfully, but &#8220;Custom CSS&#8221; was not saved to file.', 'tablepress' ),
45 'error_save' => __( 'Error: Options could not be saved.', 'tablepress' ),
46 ) );
47
48 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
49 if ( current_user_can( 'tablepress_edit_options' ) ) {
50 // Enqueue WordPress copy of CodeMirror, with CSS linting, etc., for the "Custom CSS" textarea, which is only shown to admins.
51 $codemirror_settings = wp_enqueue_code_editor( array( 'type' => 'text/css' ) );
52 if ( ! empty( $codemirror_settings ) ) {
53 // Load CSS adjustments for CodeMirror and the added vertical resizing.
54 $this->admin_page->enqueue_style( 'codemirror', array( 'code-editor' ) );
55 $this->admin_page->enqueue_script( 'codemirror' );
56 }
57
58 $this->add_meta_box( 'frontend-options', __( 'Frontend Options and Styling', 'tablepress' ), array( $this, 'postbox_frontend_options' ), 'normal' );
59 }
60 $this->add_meta_box( 'user-options', __( 'User Options', 'tablepress' ), array( $this, 'postbox_user_options' ), 'normal' );
61 $this->add_text_box( 'submit', array( $this, 'textbox_submit_button' ), 'submit' );
62 if ( current_user_can( 'deactivate_plugin', TABLEPRESS_BASENAME ) && current_user_can( 'tablepress_edit_options' ) && current_user_can( 'tablepress_delete_tables' ) && ! is_plugin_active_for_network( TABLEPRESS_BASENAME ) ) {
63 $this->add_text_box( 'uninstall-tablepress', array( $this, 'textbox_uninstall_tablepress' ), 'submit' );
64 }
65 }
66
67 /**
68 * Print the screen head text.
69 *
70 * @since 1.0.0
71 *
72 * @param array $data Data for this screen.
73 * @param array $box Information about the text box.
74 */
75 public function textbox_head( array $data, array $box ) {
76 ?>
77 <p>
78 <?php _e( 'TablePress has some options which affect the plugin&#8217;s behavior in different areas.', 'tablepress' ); ?>
79 </p>
80 <?php
81 }
82
83 /**
84 * Print the content of the "Frontend Options" post meta box.
85 *
86 * @since 1.0.0
87 *
88 * @param array $data Data for this screen.
89 * @param array $box Information about the meta box.
90 */
91 public function postbox_frontend_options( array $data, array $box ) {
92 ?>
93 <table class="tablepress-postbox-table fixed">
94 <tr>
95 <th class="column-1" scope="row"><label for="option-custom-css"><?php _e( 'Custom CSS', 'tablepress' ); ?></label>:</th>
96 <td class="column-2"><label for="option-use-custom-css"><input type="checkbox" id="option-use-custom-css" name="options[use_custom_css]" value="true"<?php checked( $data['frontend_options']['use_custom_css'] ); ?> /> <?php _e( 'Load this &#8220;Custom CSS&#8221; code to change the table styling:', 'tablepress' ); ?></label>
97 </td>
98 </tr>
99 <tr>
100 <td class="column-1"></td>
101 <td class="column-2">
102 <textarea name="options[custom_css]" id="option-custom-css" class="large-text" rows="8" autocomplete="off"><?php echo esc_textarea( $data['frontend_options']['custom_css'] ); ?></textarea>
103 <p class="description">
104 <?php
105 printf( __( '&#8220;Custom CSS&#8221; (<a href="%s">Cascading Style Sheets</a>) can be used to change the styling or layout of a table.', 'tablepress' ), 'https://www.htmldog.com/guides/css/beginner/' );
106 echo ' ';
107 printf( __( 'You can get styling examples from the <a href="%s">FAQ</a>.', 'tablepress' ), 'https://tablepress.org/faq/' );
108 echo ' ';
109 printf( __( 'Information on available CSS selectors can be found in the <a href="%s">Documentation</a>.', 'tablepress' ), 'https://tablepress.org/documentation/' );
110 echo ' ';
111 _e( 'Please note that invalid CSS code will be stripped, if it can not be corrected automatically.', 'tablepress' );
112 ?>
113 </p>
114 </td>
115 </tr>
116 </table>
117 <?php
118 }
119
120 /**
121 * Print the content of the "User Options" post meta box.
122 *
123 * @since 1.0.0
124 *
125 * @param array $data Data for this screen.
126 * @param array $box Information about the meta box.
127 */
128 public function postbox_user_options( array $data, array $box ) {
129 // Get list of current admin menu entries.
130 $entries = array();
131 foreach ( $GLOBALS['menu'] as $entry ) {
132 if ( false !== strpos( $entry[2], '.php' ) ) {
133 $entries[ $entry[2] ] = $entry[0];
134 }
135 }
136
137 // Remove <span> elements with notification bubbles (e.g. update or comment count).
138 if ( isset( $entries['plugins.php'] ) ) {
139 $entries['plugins.php'] = preg_replace( '/ <span.*span>/', '', $entries['plugins.php'] );
140 }
141 if ( isset( $entries['edit-comments.php'] ) ) {
142 $entries['edit-comments.php'] = preg_replace( '/ <span.*span>/', '', $entries['edit-comments.php'] );
143 }
144
145 // Add separator and generic positions.
146 $entries['-'] = '---';
147 $entries['top'] = __( 'Top-Level (top)', 'tablepress' );
148 $entries['middle'] = __( 'Top-Level (middle)', 'tablepress' );
149 $entries['bottom'] = __( 'Top-Level (bottom)', 'tablepress' );
150
151 $select_box = '<select id="option-admin-menu-parent-page" name="options[admin_menu_parent_page]">' . "\n";
152 foreach ( $entries as $page => $entry ) {
153 $select_box .= '<option' . selected( $page, $data['user_options']['parent_page'], false ) . disabled( $page, '-', false ) . ' value="' . $page . '">' . $entry . "</option>\n";
154 }
155 $select_box .= "</select>\n";
156 ?>
157 <table class="tablepress-postbox-table fixed">
158 <tr>
159 <th class="column-1" scope="row"><label for="option-admin-menu-parent-page"><?php _e( 'Admin menu entry', 'tablepress' ); ?>:</label></th>
160 <td class="column-2"><?php printf( __( 'TablePress shall be shown in this section of my admin menu: %s', 'tablepress' ), $select_box ); ?></td>
161 </tr>
162 </table>
163 <?php
164 }
165
166 /**
167 * Prints "Save Changes" button.
168 *
169 * @since 2.2.0
170 *
171 * @param array $data Data for this screen.
172 * @param array $box Information about the text box.
173 */
174 public function textbox_submit_button( array $data, array $box ) {
175 ?>
176 <p class="submit">
177 <input type="submit" id="tablepress-options-save-changes" class="button button-primary button-large button-save-changes" value="<?php esc_attr_e( 'Save Changes', 'tablepress' ); ?>" data-shortcut="<?php echo esc_attr( _x( '%1$sS', 'keyboard shortcut for Save Changes', 'tablepress' ) ); ?>" />
178 </p>
179 <?php
180 }
181
182 /**
183 * Print the content of the "Admin Options" post meta box.
184 *
185 * @since 1.0.0
186 *
187 * @param array $data Data for this screen.
188 * @param array $box Information about the text box.
189 */
190 public function textbox_uninstall_tablepress( array $data, array $box ) {
191 ?>
192 <h1 style="margin-top:40px;"><?php _e( 'Uninstall TablePress', 'tablepress' ); ?></h1>
193 <p>
194 <?php
195 echo __( 'Uninstalling <strong>will permanently delete</strong> all TablePress tables and options from the database.', 'tablepress' ) . '<br />'
196 . __( 'It is recommended that you create a backup of the tables (by exporting the tables in the JSON format), in case you later change your mind.', 'tablepress' ) . '<br />'
197 . __( 'You will manually need to remove the plugin&#8217;s files from the plugin folder afterwards.', 'tablepress' ) . '<br />'
198 . __( 'Be very careful with this and only click the button if you know what you are doing!', 'tablepress' );
199 ?>
200 </p>
201 <p><a href="<?php echo TablePress::url( array( 'action' => 'uninstall_tablepress' ), true, 'admin-post.php' ); ?>" id="uninstall-tablepress" class="button"><?php _e( 'Uninstall TablePress', 'tablepress' ); ?></a></p>
202 <?php
203 }
204
205 /**
206 * Sets the content for the WP feature pointer about the CSS Custom Variables on the "Options" screen.
207 *
208 * @since 2.0.0
209 */
210 public function wp_pointer_tp20_options_custom_css_css_variables() {
211 $content = '<h3>' . __( 'TablePress feature: Styling tables with CSS Custom Properties', 'tablepress' ) . '</h3>';
212 $content .= '<p>' . __( 'Did you know?', 'tablepress' ) . ' ' . __( 'To change the table colors, you can easily set new ones with CSS variables.', 'tablepress' ) . ' ' . sprintf( __( '<a href="%s">Read more in the TablePress FAQ.</a>', 'tablepress' ), 'https://tablepress.org/faq/' ) . '</p>';
213
214 $this->admin_page->print_wp_pointer_js(
215 'tp20_options_custom_css_css_variables',
216 '#option-custom-css + .CodeMirror',
217 array(
218 'content' => $content,
219 'position' => array( 'edge' => 'top', 'align' => 'center' ),
220 )
221 );
222 }
223
224 } // class TablePress_Options_View
225