settings->get_option( 'headers_footers_mode' ) ) { $this->settings_submenu = true; } $this->page_title = __( 'Header & Footer', 'insert-headers-and-footers' ); parent::__construct(); add_action( 'wpcode_admin_page_content_wpcode-headers-footers', array( $this, 'revisions_box' ), 260 ); } /** * Add the submenu page. * * @return void */ public function add_page() { if ( $this->settings_submenu ) { add_options_page( $this->menu_title, $this->page_title, 'wpcode_edit_snippets', $this->page_slug, array( wpcode()->admin_page_loader, 'admin_menu_page', ) ); return; } parent::add_page(); } /** * Register hook on admin init just for this page. * * @return void */ public function page_hooks() { $this->can_edit = current_user_can( 'unfiltered_html', 'wpcode-editor' ); add_action( 'admin_init', array( $this, 'submit_listener' ) ); $this->process_message(); } /** * Process messages specific to this page. * * @return void */ public function process_message() { // phpcs:disable WordPress.Security.NonceVerification if ( ! isset( $_GET['message'] ) ) { return; } $messages = array( 1 => __( 'Headers & Footers mode activated. Use the toggle next to the Save Changes button to disable it at any time.', 'insert-headers-and-footers' ), 2 => __( 'Headers & Footers mode deactivated, if you wish to switch back please use the option on the settings page.', 'insert-headers-and-footers' ), ); $message = absint( $_GET['message'] ); // phpcs:enable WordPress.Security.NonceVerification if ( ! isset( $messages[ $message ] ) ) { return; } $this->set_success_message( $messages[ $message ] ); } /** * Wrap this page in a form tag. * * @return void */ public function output() { if ( ! $this->can_edit ) { $this->set_error_message( __( 'Sorry, you only have read-only access to this page. Ask your administrator for assistance editing.', 'insert-headers-and-footers' ) ); $headers_footers_mode = wpcode()->settings->get_option( 'headers_footers_mode' ); // If in headers & footers mode allow them to update to disable the simple mode. if ( ! $headers_footers_mode ) { // If the user can't edit the values just don't load form at all. parent::output(); return; } } ?>
` tag */ esc_html__( 'These scripts will be printed in the %s section.', 'insert-headers-and-footers' ), '<head>
'
);
$body_desc = sprintf(
/* translators: %s: The `` tag */
esc_html__( 'These scripts will be printed just below the opening %s tag.', 'insert-headers-and-footers' ),
'<body>
'
);
$footer_desc = sprintf(
/* translators: %s: The `` tag */
esc_html__( 'These scripts will be printed above the closing %s tag.', 'insert-headers-and-footers' ),
'</body>
'
);
$this->textarea_field( 'header', __( 'Header', 'insert-headers-and-footers' ), $header_desc );
if ( $this->body_supported() ) {
$this->textarea_field( 'body', __( 'Body', 'insert-headers-and-footers' ), $body_desc );
}
$this->textarea_field( 'footer', __( 'Footer', 'insert-headers-and-footers' ), $footer_desc );
wp_nonce_field( $this->action, $this->nonce_name );
}
/**
* Check if the website supports wp_body_open.
*
* @return bool
*/
public function body_supported() {
return function_exists( 'wp_body_open' ) && version_compare( get_bloginfo( 'version' ), '5.2', '>=' );
}
/**
* Standard output for a code input field.
*
* @param string $option The option name as stored in the DB.
* @param string $title The title of the input (also used as label).
* @param string $desc The description that shows up under the field.
*
* @return void
*/
public function textarea_field( $option, $title, $desc ) {
$value = wp_unslash( $this->get_option( $option ) );
?>
array() ) ); ?>
%s
', esc_html__( 'Upgrade to WPCode Pro today and start tracking revisions and see exactly who, when and which changes were made to global Headers & Footers scripts.', 'insert-headers-and-footers' ) ), array( 'text' => esc_html__( 'Upgrade to Pro and Unlock Revisions', 'insert-headers-and-footers' ), 'url' => wpcode_utm_url( 'https://wpcode.com/lite/', 'headers-footers', 'revisions', 'upgrade-to-pro' ), ), array( 'text' => esc_html__( 'Learn more about all the features', 'insert-headers-and-footers' ), 'url' => wpcode_utm_url( 'https://wpcode.com/lite/', 'headers-footers', 'revisions', 'features' ), ) ); $this->metabox( __( 'Code Revisions', 'insert-headers-and-footers' ), $html, __( 'Easily switch back to a previous version of your global scripts.', 'insert-headers-and-footers' ) ); } }