PluginProbe
TablePress – Tables in WordPress made easy / 3.3
TablePress – Tables in WordPress made easy v3.3
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 3.3, at views/view-options.php

242 lines 10.6 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<string, mixed> $data Data for this view.
31 */
32 #[\Override]
33 public function setup( /* string */ $action, array $data ) /* : void */ {
34 // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited.
35
36 parent::setup( $action, $data );
37
38 TablePress::enqueue_script( 'common', array( 'jquery-core', 'postbox' ) );
39 TablePress::enqueue_script( 'options' );
40
41 $this->process_action_messages( array(
42 'success_save' => __( 'Options saved successfully.', 'tablepress' ),
43 'success_save_error_custom_css' => __( 'Options saved successfully, but &#8220;Custom CSS&#8221; was not saved to file.', 'tablepress' ),
44 'error_save' => __( 'Error: Options could not be saved.', 'tablepress' ),
45 ) );
46
47 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
48 if ( current_user_can( 'tablepress_edit_options' ) ) {
49 // Enqueue WordPress copy of CodeMirror, with CSS linting, etc., for the "Custom CSS" textarea, which is only shown to admins.
50 $codemirror_settings = wp_enqueue_code_editor( array( 'type' => 'text/css' ) );
51 if ( ! empty( $codemirror_settings ) ) {
52 // Load CSS adjustments for CodeMirror and the added vertical resizing.
53 TablePress::enqueue_style( 'codemirror', array( 'code-editor' ) );
54 TablePress::enqueue_script( 'codemirror' );
55 }
56
57 if ( ! TABLEPRESS_IS_PLAYGROUND_PREVIEW ) {
58 /* translators: %s: Premium badge HTML or empty string */
59 $this->add_meta_box( 'default-style', sprintf( __( 'Default Styling %s', 'tablepress' ), tb_tp_fs()->is_free_plan() ? '<span class="pill-label">' . __( 'Premium', 'tablepress' ) . '</span>' : '' ), array( $this, 'postbox_default_style_customizer_screen' ), 'normal' );
60 }
61 $this->add_meta_box( 'frontend-options', __( 'Custom Styling', 'tablepress' ), array( $this, 'postbox_frontend_options' ), 'normal' );
62 }
63 $this->add_meta_box( 'user-options', __( 'User Options', 'tablepress' ), array( $this, 'postbox_user_options' ), 'normal' );
64 $this->add_text_box( 'submit', array( $this, 'textbox_submit_button' ), 'submit' );
65 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 ) ) {
66 $this->add_text_box( 'uninstall-tablepress', array( $this, 'textbox_uninstall_tablepress' ), 'submit' );
67 }
68 }
69
70 /**
71 * Prints the screen head text.
72 *
73 * @since 1.0.0
74 *
75 * @param array<string, mixed> $data Data for this screen.
76 * @param array<string, mixed> $box Information about the text box.
77 */
78 public function textbox_head( array $data, array $box ): void {
79 ?>
80 <p>
81 <?php _e( 'TablePress has some options which affect the plugin&#8217;s behavior in different areas.', 'tablepress' ); ?>
82 </p>
83 <?php
84 }
85
86 /**
87 * Prints the content of the "Default Style Customizer Screen" post meta box.
88 *
89 * @since 2.2.0
90 *
91 * @param array<string, mixed> $data Data for this screen.
92 * @param array<string, mixed> $box Information about the meta box.
93 */
94 public function postbox_default_style_customizer_screen( array $data, array $box ): void {
95 if ( tb_tp_fs()->is_free_plan() ) :
96 ?>
97 <div style="display:flex;max-width:800px;gap:20px;font-size:14px;">
98 <div>
99 <p style="font-size:14px;">
100 <strong><?php _e( 'Did you know?', 'tablepress' ); ?></strong>
101 <?php _e( 'The TablePress premium versions come with a table default style customizer!', 'tablepress' ); ?>
102 <?php _e( 'Choose from multiple style variations or define your own color scheme in an easy-to-use visual tool!', 'tablepress' ); ?>
103 <strong><?php _e( 'Change your tables’ default style without touching CSS code!', 'tablepress' ); ?></strong>
104 </p>
105 <div class="buttons" style="text-align:center;">
106 <a href="https://tablepress.org/modules/default-style-customizer/?utm_source=plugin&utm_medium=textlink&utm_content=options-screen" class="tablepress-button">
107 <span><?php _e( 'Find out more', 'tablepress' ); ?></span>
108 <span class="dashicons dashicons-arrow-right-alt"></span>
109 </a>
110 </div>
111 </div>
112 <a href="https://tablepress.org/modules/default-style-customizer/?utm_source=plugin&utm_medium=textlink&utm_content=options-screen"><img src="<?php echo esc_url( plugins_url( 'admin/img/default-style-customizer.png', TABLEPRESS__FILE__ ) ); ?>" width="305" height="172" alt="<?php esc_attr_e( 'Screenshot of the Default Style Customizer that is part of the TablePress premium versions.', 'tablepress' ); ?>"></a>
113 </div>
114 <?php
115 endif;
116 }
117
118 /**
119 * Prints the content of the "Frontend Options" post meta box.
120 *
121 * @since 1.0.0
122 *
123 * @param array<string, mixed> $data Data for this screen.
124 * @param array<string, mixed> $box Information about the meta box.
125 */
126 public function postbox_frontend_options( array $data, array $box ): void {
127 ?>
128 <table class="tablepress-postbox-table fixed">
129 <tr>
130 <th class="column-1" scope="row"><label for="option-custom-css"><?php _e( 'Custom CSS', 'tablepress' ); ?></label>:</th>
131 <td class="column-2"><label><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>
132 </td>
133 </tr>
134 <tr>
135 <td class="column-1"></td>
136 <td class="column-2">
137 <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>
138 <p class="description">
139 <?php
140 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/' );
141 echo ' ';
142 printf( __( 'You can get styling examples from the <a href="%s">FAQ</a>.', 'tablepress' ), 'https://tablepress.org/faq/' );
143 echo ' ';
144 printf( __( 'Information on available CSS selectors can be found in the <a href="%s">Documentation</a>.', 'tablepress' ), 'https://tablepress.org/documentation/' );
145 echo ' ';
146 _e( 'Please note that invalid CSS code will be stripped, if it can not be corrected automatically.', 'tablepress' );
147 ?>
148 </p>
149 </td>
150 </tr>
151 </table>
152 <?php
153 }
154
155 /**
156 * Prints the content of the "User Options" post meta box.
157 *
158 * @since 1.0.0
159 *
160 * @param array<string, mixed> $data Data for this screen.
161 * @param array<string, mixed> $box Information about the meta box.
162 */
163 public function postbox_user_options( array $data, array $box ): void {
164 // Get list of current admin menu entries.
165 $entries = array();
166 foreach ( $GLOBALS['menu'] as $entry ) {
167 if ( str_contains( $entry[2], '.php' ) ) {
168 $entries[ $entry[2] ] = $entry[0];
169 }
170 }
171
172 // Remove <span> elements with notification bubbles (e.g. update or comment count).
173 if ( isset( $entries['plugins.php'] ) ) {
174 $entries['plugins.php'] = preg_replace( '/ <span.*span>/', '', $entries['plugins.php'] );
175 }
176 if ( isset( $entries['edit-comments.php'] ) ) {
177 $entries['edit-comments.php'] = preg_replace( '/ <span.*span>/', '', $entries['edit-comments.php'] );
178 }
179
180 // Add separator and generic positions.
181 $entries['-'] = '---';
182 $entries['top'] = __( 'Top-Level (top)', 'tablepress' );
183 $entries['middle'] = __( 'Top-Level (middle)', 'tablepress' );
184 $entries['bottom'] = __( 'Top-Level (bottom)', 'tablepress' );
185
186 $select_box = '<select id="option-admin-menu-parent-page" name="options[admin_menu_parent_page]">' . "\n";
187 foreach ( $entries as $page => $entry ) {
188 $select_box .= '<option' . selected( $page, $data['user_options']['parent_page'], false ) . disabled( $page, '-', false ) . ' value="' . $page . '">' . $entry . "</option>\n";
189 }
190 $select_box .= "</select>\n";
191 ?>
192 <table class="tablepress-postbox-table fixed">
193 <tr>
194 <th class="column-1" scope="row"><label for="option-admin-menu-parent-page"><?php _e( 'Admin menu entry', 'tablepress' ); ?>:</label></th>
195 <td class="column-2"><?php printf( __( 'TablePress shall be shown in this section of my admin menu: %s', 'tablepress' ), $select_box ); ?></td>
196 </tr>
197 </table>
198 <?php
199 }
200
201 /**
202 * Prints "Save Changes" button.
203 *
204 * @since 2.2.0
205 *
206 * @param array<string, mixed> $data Data for this screen.
207 * @param array<string, mixed> $box Information about the text box.
208 */
209 #[\Override]
210 public function textbox_submit_button( array $data, array $box ): void {
211 ?>
212 <p class="submit">
213 <input type="submit" id="tablepress-options-save-changes" class="components-button is-primary 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' ) ); ?>">
214 </p>
215 <?php
216 }
217
218 /**
219 * Prints the content of the "Admin Options" post meta box.
220 *
221 * @since 1.0.0
222 *
223 * @param array<string, mixed> $data Data for this screen.
224 * @param array<string, mixed> $box Information about the text box.
225 */
226 public function textbox_uninstall_tablepress( array $data, array $box ): void {
227 ?>
228 <h1 style="margin-top:40px;"><?php _e( 'Uninstall TablePress', 'tablepress' ); ?></h1>
229 <p>
230 <?php
231 echo __( 'Uninstalling <strong>will permanently delete</strong> all TablePress tables and options from the database.', 'tablepress' ) . '<br>'
232 . __( '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>'
233 . __( 'You will manually need to remove the plugin&#8217;s files from the plugin folder afterwards.', 'tablepress' ) . '<br>'
234 . __( 'Be very careful with this and only click the button if you know what you are doing!', 'tablepress' );
235 ?>
236 </p>
237 <p><a href="<?php echo TablePress::url( array( 'action' => 'uninstall_tablepress' ), true, 'admin-post.php' ); ?>" id="uninstall-tablepress" class="components-button is-secondary is-destructive"><?php _e( 'Uninstall TablePress', 'tablepress' ); ?></a></p>
238 <?php
239 }
240
241 } // class TablePress_Options_View
242