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() ) ); ?>

settings->get_option( 'headers_footers_mode' ); $button_disabled = ! $this->can_edit && ! $headers_footers_mode ? 'disabled' : ''; ?>

get_submenu_toggle(); ?>
settings_submenu ) { return; } ?>
get_checkbox_toggle( true, 'headers_footers_mode' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
register_editor( 'ihaf_insert_header' ); $editor->register_editor( 'ihaf_insert_footer' ); if ( $this->body_supported() ) { $editor->register_editor( 'ihaf_insert_body' ); } $editor->init_editor(); } /** * If the form is submitted attempt to save the values. * * @return void */ public function submit_listener() { if ( ! isset( $_REQUEST[ $this->nonce_name ] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST[ $this->nonce_name ] ), $this->action ) ) { // Nonce is missing, so we're not even going to try. return; } if ( $this->can_edit && isset( $_REQUEST['ihaf_insert_header'] ) && isset( $_REQUEST['ihaf_insert_footer'] ) ) { // If they are not allowed to edit the page these should not be processed but we still allow them to save to disable the simple mode. update_option( 'ihaf_insert_header', $_REQUEST['ihaf_insert_header'] ); update_option( 'ihaf_insert_footer', $_REQUEST['ihaf_insert_footer'] ); update_option( 'ihaf_insert_body', isset( $_REQUEST['ihaf_insert_body'] ) ? $_REQUEST['ihaf_insert_body'] : '' ); // Clear the cache. if ( apply_filters( 'wpcode_clear_cache_on_global_save', true ) ) { wpcode_clear_all_plugins_page_cache( 'global' ); } } if ( wpcode()->settings->get_option( 'headers_footers_mode' ) && ! isset( $_REQUEST['headers_footers_mode'] ) ) { wpcode()->settings->update_option( 'headers_footers_mode', false ); wp_safe_redirect( add_query_arg( array( 'page' => $this->page_slug, 'message' => 2, ), admin_url( 'admin.php' ) ) ); exit; } $this->set_success_message( __( 'Settings Saved. Please don\'t forget to clear the site cache if you are using a cache plugin, so that the changes will be reflected for all users.', 'insert-headers-and-footers' ) ); } /** * Use a different base url when the headers_footers_mode is enabled. * * @return string */ public function get_page_action_url() { $url = parent::get_page_action_url(); if ( ! wpcode()->settings->get_option( 'headers_footers_mode' ) ) { return $url; } return str_replace( 'admin.php', 'options-general.php', $url ); } /** * Add the revisions box. * * @return void */ public function revisions_box() { $html = $this->code_revisions_list_with_notice( esc_html__( 'Code Revisions is a Pro Feature', 'insert-headers-and-footers' ), sprintf( '

%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' ) ); } }