PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 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 All 45 releases
← All changes | views/view-options.php +97 -51 1.14 → 3.4 View file →
@@ -7,13 +7,16 @@
7 7 * @author Tobias Bäthge
8 8 * @since 1.0.0
9 9 */
10 10
11 +declare(strict_types=1);
12 +
11 13 // Prohibit direct script loading.
12 14 defined( 'ABSPATH' ) || die( 'No direct script access allowed!' );
13 15
14 16 /**
15 17 * Plugin Options View class
18 + *
16 19 * @package TablePress
17 20 * @subpackage Views
18 21 * @author Tobias Bäthge
19 22 * @since 1.0.0
@@ -24,31 +27,20 @@
24 27 * Set up the view with data and do things that are specific for this view.
25 28 *
26 29 * @since 1.0.0
27 30 *
28 - * @param string $action Action for this view.
29 - * @param array $data Data for this view.
31 + * @param string $action Action for this view.
32 + * @param array<string, mixed> $data Data for this view.
30 33 */
31 - public function setup( $action, array $data ) {
34 + #[\Override]
35 + public function setup( /* string */ $action, array $data ) /* : void */ {
36 + // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited.
37 +
32 38 parent::setup( $action, $data );
33 39
34 - // Enqueue WordPress copy of CodeMirror, with CSS linting, etc.
35 - $codemirror_settings = wp_enqueue_code_editor( array( 'type' => 'text/css' ) );
36 - if ( ! empty( $codemirror_settings ) ) {
37 - // Load CSS adjustments for CodeMirror and the added vertical resizing.
38 - $this->admin_page->enqueue_style( 'codemirror', array( 'code-editor' ) ); // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
39 - $this->admin_page->enqueue_script( 'codemirror', array( 'jquery', 'jquery-ui-resizable' ), array( // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
40 - 'codemirror_settings' => $codemirror_settings,
41 - ) );
42 - }
40 + TablePress::enqueue_script( 'common', array( 'jquery-core', 'postbox' ) );
41 + TablePress::enqueue_script( 'options' );
43 42
44 - $this->admin_page->enqueue_script( 'options', array( 'jquery' ), array( // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
45 - 'strings' => array(
46 - 'uninstall_warning_1' => __( 'Do you really want to uninstall TablePress and delete ALL data?', 'tablepress' ),
47 - 'uninstall_warning_2' => __( 'Are you really sure?', 'tablepress' ),
48 - ),
49 - ) );
50 -
51 43 $this->process_action_messages( array(
52 44 'success_save' => __( 'Options saved successfully.', 'tablepress' ),
53 45 'success_save_error_custom_css' => __( 'Options saved successfully, but &#8220;Custom CSS&#8221; was not saved to file.', 'tablepress' ),
54 46 'error_save' => __( 'Error: Options could not be saved.', 'tablepress' ),
@@ -55,12 +47,23 @@
55 47 ) );
56 48
57 49 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
58 50 if ( current_user_can( 'tablepress_edit_options' ) ) {
59 - $this->add_meta_box( 'frontend-options', __( 'Frontend Options and Styling', 'tablepress' ), array( $this, 'postbox_frontend_options' ), 'normal' );
51 + // Enqueue WordPress copy of CodeMirror, with CSS linting, etc., for the "Custom CSS" textarea, which is only shown to admins.
52 + $codemirror_settings = wp_enqueue_code_editor( array( 'type' => 'text/css' ) );
53 + if ( ! empty( $codemirror_settings ) ) {
54 + // Load CSS adjustments for CodeMirror and the added vertical resizing.
55 + TablePress::enqueue_style( 'codemirror', array( 'code-editor' ) );
56 + TablePress::enqueue_script( 'codemirror' );
57 + }
58 +
59 + if ( ! TABLEPRESS_IS_PLAYGROUND_PREVIEW ) {
60 + /* translators: %s: Premium badge HTML or empty string */
61 + $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' );
62 + }
63 + $this->add_meta_box( 'frontend-options', __( 'Custom Styling', 'tablepress' ), array( $this, 'postbox_frontend_options' ), 'normal' );
60 64 }
61 65 $this->add_meta_box( 'user-options', __( 'User Options', 'tablepress' ), array( $this, 'postbox_user_options' ), 'normal' );
62 - $this->data['submit_button_caption'] = __( 'Save Changes', 'tablepress' );
63 66 $this->add_text_box( 'submit', array( $this, 'textbox_submit_button' ), 'submit' );
64 67 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 ) ) {
65 68 $this->add_text_box( 'uninstall-tablepress', array( $this, 'textbox_uninstall_tablepress' ), 'submit' );
66 69 }
@@ -66,16 +69,16 @@
66 69 }
67 70 }
68 71
69 72 /**
70 - * Print the screen head text.
73 + * Prints the screen head text.
71 74 *
72 75 * @since 1.0.0
73 76 *
74 - * @param array $data Data for this screen.
75 - * @param array $box Information about the text box.
77 + * @param array<string, mixed> $data Data for this screen.
78 + * @param array<string, mixed> $box Information about the text box.
76 79 */
77 - public function textbox_head( array $data, array $box ) {
80 + public function textbox_head( array $data, array $box ): void {
78 81 ?>
79 82 <p>
80 83 <?php _e( 'TablePress has some options which affect the plugin&#8217;s behavior in different areas.', 'tablepress' ); ?>
81 84 </p>
@@ -82,28 +85,59 @@
82 85 <?php
83 86 }
84 87
85 88 /**
86 - * Print the content of the "Frontend Options" post meta box.
89 + * Prints the content of the "Default Style Customizer Screen" post meta box.
87 90 *
91 + * @since 2.2.0
92 + *
93 + * @param array<string, mixed> $data Data for this screen.
94 + * @param array<string, mixed> $box Information about the meta box.
95 + */
96 + public function postbox_default_style_customizer_screen( array $data, array $box ): void {
97 + if ( tb_tp_fs()->is_free_plan() ) :
98 + ?>
99 + <div style="display:flex;max-width:800px;gap:20px;font-size:14px;">
100 + <div>
101 + <p style="font-size:14px;">
102 + <strong><?php _e( 'Did you know?', 'tablepress' ); ?></strong>
103 + <?php _e( 'The TablePress premium versions come with a table default style customizer!', 'tablepress' ); ?>
104 + <?php _e( 'Choose from multiple style variations or define your own color scheme in an easy-to-use visual tool!', 'tablepress' ); ?>
105 + <strong><?php _e( 'Change your tables’ default style without touching CSS code!', 'tablepress' ); ?></strong>
106 + </p>
107 + <div class="buttons" style="text-align:center;">
108 + <a href="https://tablepress.org/modules/default-style-customizer/?utm_source=plugin&utm_medium=textlink&utm_content=options-screen" class="tablepress-button">
109 + <span><?php _e( 'Find out more', 'tablepress' ); ?></span>
110 + <span class="dashicons dashicons-arrow-right-alt"></span>
111 + </a>
112 + </div>
113 + </div>
114 + <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>
115 + </div>
116 + <?php
117 + endif;
118 + }
119 +
120 + /**
121 + * Prints the content of the "Frontend Options" post meta box.
122 + *
88 123 * @since 1.0.0
89 124 *
90 - * @param array $data Data for this screen.
91 - * @param array $box Information about the meta box.
125 + * @param array<string, mixed> $data Data for this screen.
126 + * @param array<string, mixed> $box Information about the meta box.
92 127 */
93 - public function postbox_frontend_options( array $data, array $box ) {
128 + public function postbox_frontend_options( array $data, array $box ): void {
94 129 ?>
95 130 <table class="tablepress-postbox-table fixed">
96 -<tbody>
97 131 <tr>
98 132 <th class="column-1" scope="row"><label for="option-custom-css"><?php _e( 'Custom CSS', 'tablepress' ); ?></label>:</th>
99 - <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>
133 + <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>
100 134 </td>
101 135 </tr>
102 136 <tr>
103 137 <td class="column-1"></td>
104 138 <td class="column-2">
105 - <textarea name="options[custom_css]" id="option-custom-css" class="large-text" rows="8"><?php echo esc_textarea( $data['frontend_options']['custom_css'] ); ?></textarea>
139 + <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>
106 140 <p class="description">
107 141 <?php
108 142 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/' );
109 143 echo ' ';
@@ -115,30 +149,25 @@
115 149 ?>
116 150 </p>
117 151 </td>
118 152 </tr>
119 -</tbody>
120 153 </table>
121 154 <?php
122 155 }
123 156
124 157 /**
125 - * Print the content of the "User Options" post meta box.
158 + * Prints the content of the "User Options" post meta box.
126 159 *
127 160 * @since 1.0.0
128 161 *
129 - * @param array $data Data for this screen.
130 - * @param array $box Information about the meta box.
162 + * @param array<string, mixed> $data Data for this screen.
163 + * @param array<string, mixed> $box Information about the meta box.
131 164 */
132 - public function postbox_user_options( array $data, array $box ) {
133 - ?>
134 -<table class="tablepress-postbox-table fixed">
135 -<tbody>
136 - <?php
165 + public function postbox_user_options( array $data, array $box ): void {
137 166 // Get list of current admin menu entries.
138 167 $entries = array();
139 168 foreach ( $GLOBALS['menu'] as $entry ) {
140 - if ( false !== strpos( $entry[2], '.php' ) ) {
169 + if ( str_contains( $entry[2], '.php' ) ) {
141 170 $entries[ $entry[2] ] = $entry[0];
142 171 }
143 172 }
144 173
@@ -161,37 +190,54 @@
161 190 $select_box .= '<option' . selected( $page, $data['user_options']['parent_page'], false ) . disabled( $page, '-', false ) . ' value="' . $page . '">' . $entry . "</option>\n";
162 191 }
163 192 $select_box .= "</select>\n";
164 193 ?>
194 +<table class="tablepress-postbox-table fixed">
165 195 <tr>
166 196 <th class="column-1" scope="row"><label for="option-admin-menu-parent-page"><?php _e( 'Admin menu entry', 'tablepress' ); ?>:</label></th>
167 197 <td class="column-2"><?php printf( __( 'TablePress shall be shown in this section of my admin menu: %s', 'tablepress' ), $select_box ); ?></td>
168 198 </tr>
169 -</tbody>
170 199 </table>
171 200 <?php
172 201 }
173 202
174 203 /**
175 - * Print the content of the "Admin Options" post meta box.
204 + * Prints "Save Changes" button.
176 205 *
206 + * @since 2.2.0
207 + *
208 + * @param array<string, mixed> $data Data for this screen.
209 + * @param array<string, mixed> $box Information about the text box.
210 + */
211 + #[\Override]
212 + public function textbox_submit_button( array $data, array $box ): void {
213 + ?>
214 + <p class="submit">
215 + <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' ) ); ?>">
216 + </p>
217 + <?php
218 + }
219 +
220 + /**
221 + * Prints the content of the "Admin Options" post meta box.
222 + *
177 223 * @since 1.0.0
178 224 *
179 - * @param array $data Data for this screen.
180 - * @param array $box Information about the text box.
225 + * @param array<string, mixed> $data Data for this screen.
226 + * @param array<string, mixed> $box Information about the text box.
181 227 */
182 - public function textbox_uninstall_tablepress( array $data, array $box ) {
228 + public function textbox_uninstall_tablepress( array $data, array $box ): void {
183 229 ?>
184 230 <h1 style="margin-top:40px;"><?php _e( 'Uninstall TablePress', 'tablepress' ); ?></h1>
185 231 <p>
186 232 <?php
187 - echo __( 'Uninstalling <strong>will permanently delete</strong> all TablePress tables and options from the database.', 'tablepress' ) . '<br />'
188 - . __( '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 />'
189 - . __( 'You will manually need to remove the plugin&#8217;s files from the plugin folder afterwards.', 'tablepress' ) . '<br />'
233 + echo __( 'Uninstalling <strong>will permanently delete</strong> all TablePress tables and options from the database.', 'tablepress' ) . '<br>'
234 + . __( '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>'
235 + . __( 'You will manually need to remove the plugin&#8217;s files from the plugin folder afterwards.', 'tablepress' ) . '<br>'
190 236 . __( 'Be very careful with this and only click the button if you know what you are doing!', 'tablepress' );
191 237 ?>
192 238 </p>
193 - <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>
239 + <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>
194 240 <?php
195 241 }
196 242
197 243 } // class TablePress_Options_View