| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Options/Save Custom CSS Credentials Form 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/Save Custom CSS Credentials Form View class |
| 16 |
* |
| 17 |
* @package TablePress |
| 18 |
* @subpackage Views |
| 19 |
* @author Tobias Bäthge |
| 20 |
* @since 1.0.0 |
| 21 |
*/ |
| 22 |
class TablePress_Options_Custom_CSS_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 |
// Set action manually here, to get correct page title and nav bar entries. |
| 37 |
$this->action = 'options'; |
| 38 |
$this->data = $data; |
| 39 |
|
| 40 |
// Set page title. |
| 41 |
/* translators: %1$s: Page title, %2$s: Plugin name */ |
| 42 |
$GLOBALS['title'] = sprintf( __( '%1$s ‹ %2$s', 'tablepress' ), $this->data['view_actions'][ $this->action ]['page_title'], 'TablePress' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 43 |
|
| 44 |
$this->add_header_message( '<strong>' . __( 'Attention: Further action is required to save the changes to your “Custom CSS”!', 'tablepress' ) . '</strong>', 'is-success' ); |
| 45 |
|
| 46 |
// Admin page helpers, like script/style loading, could be moved to view. |
| 47 |
$this->admin_page = TablePress::load_class( 'TablePress_Admin_Page', 'class-admin-page-helper.php', 'classes' ); |
| 48 |
$this->admin_page->enqueue_style( 'common', array( 'wp-components' ) ); |
| 49 |
|
| 50 |
$this->admin_page->add_admin_footer_text(); |
| 51 |
|
| 52 |
$this->add_text_box( 'explanation-text', array( $this, 'textbox_explanation_text' ), 'normal' ); |
| 53 |
$this->add_text_box( 'credentials-form', array( $this, 'textbox_credentials_form' ), 'normal' ); |
| 54 |
$this->add_text_box( 'proceed-no-file-saving', array( $this, 'textbox_proceed_no_file_saving' ), 'submit' ); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Render the current view (in this view: without form tag). |
| 59 |
* |
| 60 |
* @since 1.0.0 |
| 61 |
*/ |
| 62 |
#[\Override] |
| 63 |
public function render(): void { |
| 64 |
?> |
| 65 |
<div id="tablepress-page" class="wrap"> |
| 66 |
<?php |
| 67 |
$this->print_nav_tab_menu(); |
| 68 |
?> |
| 69 |
<div id="tablepress-body"> |
| 70 |
<hr class="wp-header-end"> |
| 71 |
<?php |
| 72 |
// Print all header messages. |
| 73 |
foreach ( $this->header_messages as $message ) { |
| 74 |
echo $message; |
| 75 |
} |
| 76 |
|
| 77 |
$this->do_text_boxes( 'header' ); |
| 78 |
?> |
| 79 |
<div id="poststuff"> |
| 80 |
<div id="post-body" class="metabox-holder columns-<?php echo ( isset( $GLOBALS['screen_layout_columns'] ) && ( 2 === $GLOBALS['screen_layout_columns'] ) ) ? '2' : '1'; ?>"> |
| 81 |
<div id="postbox-container-2" class="postbox-container"> |
| 82 |
<?php |
| 83 |
$this->do_text_boxes( 'normal' ); |
| 84 |
$this->do_meta_boxes( 'normal' ); |
| 85 |
|
| 86 |
$this->do_text_boxes( 'additional' ); |
| 87 |
$this->do_meta_boxes( 'additional' ); |
| 88 |
|
| 89 |
// Print all submit buttons. |
| 90 |
$this->do_text_boxes( 'submit' ); |
| 91 |
?> |
| 92 |
</div> |
| 93 |
<div id="postbox-container-1" class="postbox-container"> |
| 94 |
<?php |
| 95 |
// Print all boxes in the sidebar. |
| 96 |
$this->do_text_boxes( 'side' ); |
| 97 |
$this->do_meta_boxes( 'side' ); |
| 98 |
?> |
| 99 |
</div> |
| 100 |
</div> |
| 101 |
<br class="clear"> |
| 102 |
</div> |
| 103 |
</div> |
| 104 |
</div> |
| 105 |
<?php |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Print the content of the "Explanation" text box. |
| 110 |
* |
| 111 |
* @since 1.0.0 |
| 112 |
* |
| 113 |
* @param array<string, mixed> $data Data for this screen. |
| 114 |
* @param array<string, mixed> $box Information about the text box. |
| 115 |
*/ |
| 116 |
public function textbox_explanation_text( array $data, array $box ): void { |
| 117 |
?> |
| 118 |
<p> |
| 119 |
<?php _e( 'Due to the configuration of your server, TablePress was not able to automatically save your “Custom CSS” to a file.', 'tablepress' ); ?> |
| 120 |
<?php |
| 121 |
/* translators: %s: Connection information form label */ |
| 122 |
printf( __( 'To try again with the same method that you use for updating plugins or themes, please fill out the “%s” form below.', 'tablepress' ), __( 'Connection Information', 'default' ) ); |
| 123 |
?> |
| 124 |
</p> |
| 125 |
<?php |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* Print the content of the "Credentials" text box. |
| 130 |
* |
| 131 |
* @since 1.0.0 |
| 132 |
* |
| 133 |
* @param array<string, mixed> $data Data for this screen. |
| 134 |
* @param array<string, mixed> $box Information about the text box. |
| 135 |
*/ |
| 136 |
public function textbox_credentials_form( array $data, array $box ): void { |
| 137 |
echo $data['credentials_form']; |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Print the content of the "Cancel Saving" text box. |
| 142 |
* |
| 143 |
* @since 1.0.0 |
| 144 |
* |
| 145 |
* @param array<string, mixed> $data Data for this screen. |
| 146 |
* @param array<string, mixed> $box Information about the text box. |
| 147 |
*/ |
| 148 |
public function textbox_proceed_no_file_saving( array $data, array $box ): void { |
| 149 |
?> |
| 150 |
<h2><?php _e( 'Proceed without saving a file', 'tablepress' ); ?></h2> |
| 151 |
<p> |
| 152 |
<?php _e( 'To proceed without trying to save the “Custom CSS” to a file, click the button below.', 'tablepress' ); ?> |
| 153 |
<?php _e( 'Your “Custom CSS” will then be loaded inline.', 'tablepress' ); ?> |
| 154 |
</p><p> |
| 155 |
<a href="<?php echo TablePress::url( array( 'action' => 'options', 'message' => 'success_save_error_custom_css' ) ); ?>" class="components-button is-secondary"><?php _e( 'Proceed without saving “Custom CSS” to a file', 'tablepress' ); ?></a> |
| 156 |
</p> |
| 157 |
<?php |
| 158 |
} |
| 159 |
|
| 160 |
} // class TablePress_Options_Custom_CSS_View |
| 161 |
|