hooks(); } /** * Load the translatable strings. * * @return void */ public function load_strings() { $this->title = __( 'WPCode Page Scripts', 'insert-headers-and-footers' ); $this->tabs = array( 'header' => __( 'Header', 'insert-headers-and-footers' ), 'footer' => __( 'Footer', 'insert-headers-and-footers' ), ); $body_supported = function_exists( 'wp_body_open' ) && version_compare( get_bloginfo( 'version' ), '5.2', '>=' ); if ( $body_supported ) { $this->tabs['body'] = __( 'Body', 'insert-headers-and-footers' ); } $this->tabs['code'] = __( 'Custom Code Snippet', 'insert-headers-and-footers' ); $this->tabs['revisions'] = __( 'Revisions', 'insert-headers-and-footers' ); } /** * Add hooks. * * @return void */ public function hooks() { add_action( 'admin_init', array( $this, 'load_strings' ) ); add_action( 'add_meta_boxes', array( $this, 'register_metabox' ) ); add_action( 'admin_head', array( $this, 'close_metabox_for_current_screen' ) ); } /** * Make sure the metabox is closed by default. * * @return void */ public function close_metabox_for_current_screen() { // Close the metabox by default. $screen = get_current_screen(); if ( ! isset( $screen->id ) ) { return; } if ( apply_filters( 'wpcode_metabox_scripts_force_collapse', true, $screen ) ) { add_filter( 'get_user_option_closedpostboxes_' . $screen->id, array( $this, 'add_metabox_to_user_closed', ) ); } } /** * Add our metabox id to the array of closed metaboxes when the page loads. * * @param mixed $closed The array of closed metaboxes. * * @return array */ public function add_metabox_to_user_closed( $closed ) { // Make sure it's an array. if ( ! is_array( $closed ) ) { $closed = array(); } $closed[] = $this->id; return $closed; } /** * Use `add_meta_box` to register the metabox for this class. * * @param string $post_type The post type of the screen where metaboxes are loaded. * * @return void */ public function register_metabox( $post_type ) { // Don't show the metabox to users who aren't allowed to manage snippets. if ( ! current_user_can( 'wpcode_edit_html_snippets' ) ) { return; } if ( wpcode()->settings->get_option( 'headers_footers_mode' ) ) { // Don't load the metabox when headers & footers mode is enabled. return; } $post_type_details = get_post_type_object( $post_type ); // Add metabox only on public post types. if ( empty( $post_type_details->public ) ) { return; } add_meta_box( $this->id, $this->title, array( $this, 'output_metabox_content', ), $post_type, 'normal', apply_filters( 'wpcode_post_metabox_priority', 'default' ) ); } /** * Metabox content output callback. * * @param WP_Post $post The post object. * * @return void */ public function output_metabox_content( $post ) { $this->metabox_start(); echo '