true );
$post_types = get_post_types( $args );
// Bail if we're not using the old Page Header meta box
if ( 'generate_page_header' !== get_post_type() && '' == $stored_meta['_meta-generate-page-header-content'][0] && '' == $stored_meta['_meta-generate-page-header-image'][0] && '' == $stored_meta['_meta-generate-page-header-image-id'][0] ) {
if ( ! defined( 'GENERATE_LAYOUT_META_BOX' ) ) {
foreach ( $post_types as $type ) {
if ( 'attachment' !== $type ) {
add_meta_box(
'generate_select_page_header_meta_box',
__( 'Page Header', 'gp-premium' ),
'generate_do_select_page_header_meta_box',
$type,
'normal',
'high'
);
}
}
}
if ( ! apply_filters( 'generate_page_header_legacy_metabox', false ) ) {
return;
}
}
array_push( $post_types, 'generate_page_header' );
foreach ($post_types as $type) {
if ( 'attachment' !== $type ) {
add_meta_box(
'generate_page_header_meta_box',
__( 'Page Header', 'gp-premium' ),
'show_generate_page_header_meta_box',
$type,
'normal',
'high'
);
}
}
}
}
if ( ! function_exists( 'generate_page_header_metabox_enqueue' ) ) {
add_action( 'admin_enqueue_scripts', 'generate_page_header_metabox_enqueue' );
/**
* Add our metabox scripts
*/
function generate_page_header_metabox_enqueue( $hook ) {
// I prefer to enqueue the styles only on pages that are using the metaboxes
if ( in_array( $hook, array( "post.php", "post-new.php" ) ) ) {
$args = array( 'public' => true );
$post_types = get_post_types( $args );
$screen = get_current_screen();
$post_type = $screen->id;
if ( in_array( $post_type, (array) $post_types ) || 'generate_page_header' == get_post_type() ){
wp_enqueue_media();
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker-alpha', plugin_dir_url( __FILE__ ) . 'js/wp-color-picker-alpha.min.js', array( 'wp-color-picker' ), GENERATE_PAGE_HEADER_VERSION );
wp_localize_script(
'wp-color-picker-alpha',
'gpSectionsColorPickerL10n',
array(
'defaultLabel' => __( 'Color value', 'gp-premium' ),
'pick' => __( 'Select Color', 'gp-premium' ),
'defaultString' => __( 'Default', 'gp-premium' ),
'defaultAriaLabel' => __( 'Select default color', 'gp-premium' ),
'clear' => __( 'Clear', 'gp-premium' ),
'clearAriaLabel' => __( 'Clear color', 'gp-premium' ),
)
);
wp_enqueue_style( 'generate-page-header-metabox', plugin_dir_url( __FILE__ ) . 'css/metabox.css', array(), GENERATE_PAGE_HEADER_VERSION );
wp_enqueue_script( 'generate-lc-switch', plugin_dir_url( __FILE__ ) . 'js/lc_switch.js', array( 'jquery' ), GENERATE_PAGE_HEADER_VERSION, false );
wp_enqueue_script( 'generate-page-header-metabox', plugin_dir_url( __FILE__ ) . 'js/metabox.js', array( 'jquery','generate-lc-switch', 'wp-color-picker' ), GENERATE_PAGE_HEADER_VERSION, false );
if ( function_exists( 'wp_add_inline_script' ) && function_exists( 'generate_get_default_color_palettes' ) ) {
// Grab our palette array and turn it into JS
$palettes = json_encode( generate_get_default_color_palettes() );
// Add our custom palettes
// json_encode takes care of escaping
wp_add_inline_script( 'wp-color-picker', 'jQuery.wp.wpColorPicker.prototype.options.palettes = ' . $palettes . ';' );
}
}
}
}
}
/**
* Build our Select Page Header meta box.
*
* @since 1.4
*/
function generate_do_select_page_header_meta_box( $post ) {
wp_nonce_field( basename( __FILE__ ), 'generate_page_header_nonce' );
$stored_meta = get_post_meta( $post->ID );
$stored_meta['_generate-select-page-header'][0] = ( isset( $stored_meta['_generate-select-page-header'][0] ) ) ? $stored_meta['_generate-select-page-header'][0] : '';
$page_headers = get_posts(array(
'posts_per_page' => -1,
'orderby' => 'title',
'post_type' => 'generate_page_header',
));
if ( count( $page_headers ) > 0 ) :
?>
create one?', 'gp-premium' ),
esc_url( admin_url( 'post-new.php?post_type=generate_page_header' ) )
);
?>
%1$s
',
__( 'Content is required for the below settings to work.', 'gp-premium' ),
'' !== generate_page_header_get_post_meta( get_the_ID(), '_meta-generate-page-header-content', true ) ? 'style="display:none"' : ''
);
if ( '' !== generate_page_header_get_post_meta( get_the_ID(), '_meta-generate-page-header-content', true ) ) {
?>
>
featured image.', 'gp-premium' ); ?>
'FILTER_CONTENT',
'_meta-generate-page-header-image' => 'FILTER_SANITIZE_URL',
'_meta-generate-page-header-image-id' => 'FILTER_SANITIZE_NUMBER_INT',
'_meta-generate-page-header-image-link' => 'FILTER_SANITIZE_URL',
'_meta-generate-page-header-enable-image-crop' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-image-crop' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-image-width' => 'FILTER_SANITIZE_NUMBER_INT',
'_meta-generate-page-header-image-height' => 'FILTER_SANITIZE_NUMBER_INT',
'_meta-generate-page-header-image-background-type' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-inner-container' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-image-background-alignment' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-image-background-spacing' => 'FILTER_SANITIZE_NUMBER_INT',
'_meta-generate-page-header-image-background-spacing-unit' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-left-right-padding' => 'FILTER_SANITIZE_NUMBER_INT',
'_meta-generate-page-header-left-right-padding-unit' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-image-background-color' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-image-background-text-color' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-image-background-link-color' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-image-background-link-color-hover' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-navigation-background' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-navigation-text' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-navigation-background-hover' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-navigation-text-hover' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-navigation-background-current' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-navigation-text-current' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-site-title' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-site-tagline' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-video' => 'FILTER_SANITIZE_URL',
'_meta-generate-page-header-video-ogv' => 'FILTER_SANITIZE_URL',
'_meta-generate-page-header-video-webm' => 'FILTER_SANITIZE_URL',
'_meta-generate-page-header-video-overlay' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-content-autop' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-content-padding' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-image-background' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-full-screen' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-vertical-center' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-image-background-fixed' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-image-background-overlay' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-combine' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-absolute-position' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-transparent-navigation' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-add-to-excerpt' => 'FILTER_SANITIZE_STRING',
'_meta-generate-page-header-logo' => 'FILTER_SANITIZE_URL',
'_meta-generate-page-header-logo-id' => 'FILTER_SANITIZE_NUMBER_INT',
'_meta-generate-page-header-navigation-logo' => 'FILTER_SANITIZE_URL',
'_meta-generate-page-header-navigation-logo-id' => 'FILTER_SANITIZE_NUMBER_INT',
);
if ( ! defined( 'GENERATE_LAYOUT_META_BOX' ) ) {
$options[ '_generate-select-page-header' ] = 'FILTER_SANITIZE_NUMBER_INT';
}
foreach ( $options as $key => $sanitize ) {
if ( 'FILTER_SANITIZE_STRING' == $sanitize ) {
$value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_STRING );
} elseif ( 'FILTER_SANITIZE_URL' == $sanitize ) {
$value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_URL );
} elseif ( 'FILTER_SANITIZE_NUMBER_INT' == $sanitize ) {
$value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_NUMBER_INT );
} elseif ( 'FILTER_CONTENT' == $sanitize && isset( $_POST[ $key ] ) ) {
if ( current_user_can( 'unfiltered_html' ) ) {
$value = $_POST[ $key ];
} else {
$value = wp_kses_post( $_POST[ $key ] );
}
} else {
$value = filter_input( INPUT_POST, $key, FILTER_DEFAULT );
}
if ( $value ) {
update_post_meta( $post_id, $key, $value );
} else {
delete_post_meta( $post_id, $key );
}
}
}
}
add_action( 'add_meta_boxes', 'generate_page_header_tags_add_meta_box' );
/**
* Add our Template Tags meta box.
*
* @param WP_Post $post Current post object.
*
* @since 1.4
*/
function generate_page_header_tags_add_meta_box( $post ) {
add_meta_box( 'generate_page_header_tags', __( 'Template Tags', 'gp-premium' ), 'generate_page_header_tags_do_meta_box', 'generate_page_header', 'side', 'low' );
}
/**
* Meta box display callback.
*
* @param WP_Post $post Current post object.
*
* @since 1.4
*/
function generate_page_header_tags_do_meta_box( $post ) {
?>