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 +105 -69 1.9.2 → 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,44 +27,43 @@
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' ) );
39 - $this->admin_page->enqueue_script( 'codemirror', array( 'jquery-core', 'jquery-ui-resizable' ), array(
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-core' ), array(
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 - 'success_save' => __( 'Options saved successfully.', 'tablepress' ),
53 - 'success_save_error_custom_css' => __( 'Options saved successfully, but &#8220;Custom CSS&#8221; was not saved to file.', 'tablepress' ),
54 - 'error_save' => __( 'Error: Options could not be saved.', 'tablepress' ),
55 - 'success_import_wp_table_reloaded' => __( 'The WP-Table Reloaded &#8220;Custom CSS&#8221; was imported successfully.', 'tablepress' ),
44 + 'success_save' => __( 'Options saved successfully.', 'tablepress' ),
45 + 'success_save_error_custom_css' => __( 'Options saved successfully, but &#8220;Custom CSS&#8221; was not saved to file.', 'tablepress' ),
46 + 'error_save' => __( 'Error: Options could not be saved.', 'tablepress' ),
56 47 ) );
57 48
58 49 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
59 50 if ( current_user_can( 'tablepress_edit_options' ) ) {
60 - $this->add_meta_box( 'frontend-options', __( 'Frontend Options', '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' );
61 64 }
62 65 $this->add_meta_box( 'user-options', __( 'User Options', 'tablepress' ), array( $this, 'postbox_user_options' ), 'normal' );
63 - $this->data['submit_button_caption'] = __( 'Save Changes', 'tablepress' );
64 66 $this->add_text_box( 'submit', array( $this, 'textbox_submit_button' ), 'submit' );
65 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 ) ) {
66 68 $this->add_text_box( 'uninstall-tablepress', array( $this, 'textbox_uninstall_tablepress' ), 'submit' );
67 69 }
@@ -67,53 +69,75 @@
67 69 }
68 70 }
69 71
70 72 /**
71 - * Print the screen head text.
73 + * Prints the screen head text.
72 74 *
73 75 * @since 1.0.0
74 76 *
75 - * @param array $data Data for this screen.
76 - * @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.
77 79 */
78 - public function textbox_head( array $data, array $box ) {
80 + public function textbox_head( array $data, array $box ): void {
79 81 ?>
80 82 <p>
81 - <?php _e( 'TablePress has several options which affect the plugin&#8217;s behavior in different areas.', 'tablepress' ); ?>
83 + <?php _e( 'TablePress has some options which affect the plugin&#8217;s behavior in different areas.', 'tablepress' ); ?>
82 84 </p>
83 - <p>
85 + <?php
86 + }
87 +
88 + /**
89 + * Prints the content of the "Default Style Customizer Screen" post meta box.
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>
84 116 <?php
85 - if ( current_user_can( 'tablepress_edit_options' ) ) {
86 - _e( 'Frontend Options influence the styling of tables in pages, posts, or text widgets, by defining which CSS code shall be loaded.', 'tablepress' );
87 - echo '<br />';
88 - }
89 - _e( 'In the User Options, every TablePress user can choose the position of the plugin in his WordPress admin menu.', 'tablepress' );
90 - ?>
91 - </p>
92 - <?php
117 + endif;
93 118 }
94 119
95 120 /**
96 - * Print the content of the "Frontend Options" post meta box.
121 + * Prints the content of the "Frontend Options" post meta box.
97 122 *
98 123 * @since 1.0.0
99 124 *
100 - * @param array $data Data for this screen.
101 - * @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.
102 127 */
103 - public function postbox_frontend_options( array $data, array $box ) {
104 -?>
128 + public function postbox_frontend_options( array $data, array $box ): void {
129 + ?>
105 130 <table class="tablepress-postbox-table fixed">
106 -<tbody>
107 131 <tr>
108 132 <th class="column-1" scope="row"><label for="option-custom-css"><?php _e( 'Custom CSS', 'tablepress' ); ?></label>:</th>
109 - <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 these &#8220;Custom CSS&#8221; commands to influence 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>
110 134 </td>
111 135 </tr>
112 136 <tr>
113 137 <td class="column-1"></td>
114 138 <td class="column-2">
115 - <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>
116 140 <p class="description">
117 141 <?php
118 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/' );
119 143 echo ' ';
@@ -118,9 +142,9 @@
118 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/' );
119 143 echo ' ';
120 144 printf( __( 'You can get styling examples from the <a href="%s">FAQ</a>.', 'tablepress' ), 'https://tablepress.org/faq/' );
121 145 echo ' ';
122 - printf( __( 'Information on available CSS selectors can be found in the <a href="%s">documentation</a>.', 'tablepress' ), 'https://tablepress.org/documentation/' );
146 + printf( __( 'Information on available CSS selectors can be found in the <a href="%s">Documentation</a>.', 'tablepress' ), 'https://tablepress.org/documentation/' );
123 147 echo ' ';
124 148 _e( 'Please note that invalid CSS code will be stripped, if it can not be corrected automatically.', 'tablepress' );
125 149 ?>
126 150 </p>
@@ -125,30 +149,25 @@
125 149 ?>
126 150 </p>
127 151 </td>
128 152 </tr>
129 -</tbody>
130 153 </table>
131 -<?php
154 + <?php
132 155 }
133 156
134 157 /**
135 - * Print the content of the "User Options" post meta box.
158 + * Prints the content of the "User Options" post meta box.
136 159 *
137 160 * @since 1.0.0
138 161 *
139 - * @param array $data Data for this screen.
140 - * @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.
141 164 */
142 - public function postbox_user_options( array $data, array $box ) {
143 - ?>
144 -<table class="tablepress-postbox-table fixed">
145 -<tbody>
146 - <?php
165 + public function postbox_user_options( array $data, array $box ): void {
147 166 // Get list of current admin menu entries.
148 167 $entries = array();
149 168 foreach ( $GLOBALS['menu'] as $entry ) {
150 - if ( false !== strpos( $entry[2], '.php' ) ) {
169 + if ( str_contains( $entry[2], '.php' ) ) {
151 170 $entries[ $entry[2] ] = $entry[0];
152 171 }
153 172 }
154 173
@@ -171,37 +190,54 @@
171 190 $select_box .= '<option' . selected( $page, $data['user_options']['parent_page'], false ) . disabled( $page, '-', false ) . ' value="' . $page . '">' . $entry . "</option>\n";
172 191 }
173 192 $select_box .= "</select>\n";
174 193 ?>
194 +<table class="tablepress-postbox-table fixed">
175 195 <tr>
176 196 <th class="column-1" scope="row"><label for="option-admin-menu-parent-page"><?php _e( 'Admin menu entry', 'tablepress' ); ?>:</label></th>
177 197 <td class="column-2"><?php printf( __( 'TablePress shall be shown in this section of my admin menu: %s', 'tablepress' ), $select_box ); ?></td>
178 198 </tr>
179 -</tbody>
180 199 </table>
181 -<?php
200 + <?php
182 201 }
183 202
184 203 /**
185 - * Print the content of the "Admin Options" post meta box.
204 + * Prints "Save Changes" button.
186 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 + *
187 223 * @since 1.0.0
188 224 *
189 - * @param array $data Data for this screen.
190 - * @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.
191 227 */
192 - public function textbox_uninstall_tablepress( array $data, array $box ) {
228 + public function textbox_uninstall_tablepress( array $data, array $box ): void {
193 229 ?>
194 230 <h1 style="margin-top:40px;"><?php _e( 'Uninstall TablePress', 'tablepress' ); ?></h1>
195 231 <p>
196 232 <?php
197 - echo __( 'Uninstalling <strong>will permanently delete</strong> all TablePress tables and options from the database.', 'tablepress' ) . '<br />'
198 - . __( '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 />'
199 - . __( '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>'
200 236 . __( 'Be very careful with this and only click the button if you know what you are doing!', 'tablepress' );
201 237 ?>
202 238 </p>
203 - <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>
204 240 <?php
205 241 }
206 242
207 243 } // class TablePress_Options_View