Last active
August 29, 2015 14:10
-
-
Save zzramesses/365918805cf5f937e976 to your computer and use it in GitHub Desktop.
WPATX Metadata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// display the top local, top unique and key varietals metaboxes in the admin area | |
public static function local_meta_box_display( $post, $metabox ) { | |
$prefix = $metabox['args']['name']; | |
$child_regions = hmc_get_child_regions(); | |
$current_regions = array(); | |
if ( get_the_terms( $post->ID, 'local_highlights' ) ) { | |
$current_regions = wp_list_pluck( get_the_terms( $post->ID, 'local_highlights' ), 'name' ); | |
} | |
echo '<input type="hidden" name="prefix[]" value ="'. esc_attr( $prefix ) .'"/>'; | |
// Add an nonce field so we can check for it later. | |
wp_nonce_field( 'local_highlights_box', 'local_highlights_box_nonce' ); | |
foreach ( $child_regions as $key => $value ) { | |
// Remove any '-fr' or other language codes added to values is removed | |
$clean_key = HMC_Regionalization::strip_lang_code( $key ); ?> | |
<input type="checkbox" name="<?php echo esc_attr( $prefix . 'local_highlights[]' ); ?>" value="<?php echo esc_attr( $prefix . $key ); ?>" <?php checked( true, in_array( $prefix . $clean_key, $current_regions ) ); ?>/> | |
<label for="local-highlight-<?php echo esc_attr( $key ); ?> "> | |
<?php echo esc_html( $value ); ?> | |
</label> | |
</br> | |
<?php } | |
} | |
// Save the term to the taxonomy when the post is saved. | |
public static function save_local_highlights_meta_box( $post_id ) { | |
// Check if our nonce is set. | |
if ( ! isset( $_POST['local_highlights_box_nonce'] ) ) | |
return $post_id; | |
$nonce = $_POST['local_highlights_box_nonce']; | |
// Verify that the nonce is valid. | |
if ( ! wp_verify_nonce( $nonce, 'local_highlights_box' ) ) | |
return $post_id; | |
// If this is an autosave, our form has not been submitted, | |
// so we don't want to do anything. | |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) | |
return $post_id; | |
// Check the user's permissions. | |
if ( 'page' == $_POST['post_type'] ) { | |
if ( ! current_user_can( 'edit_page', $post_id ) ) | |
return $post_id; | |
} else { | |
if ( ! current_user_can( 'edit_post', $post_id ) ) | |
return $post_id; | |
} | |
// Sanitize the user input. | |
$prefixes = $_POST['prefix']; | |
$local_highlights = array(); | |
foreach($prefixes as $prefix) { | |
if ( isset( $_POST[$prefix .'local_highlights'] ) ) { | |
$local_highlights = array_merge( $local_highlights, $_POST[$prefix .'local_highlights'] ); | |
} | |
} | |
// Update the product highlight terms. | |
wp_set_object_terms($post_id, $local_highlights, 'local_highlights'); | |
} | |
// Save the term to the taxonomy when the post is saved. | |
public static function save_local_highlights_meta_box( $post_id ) { | |
// Check if our nonce is set. | |
if ( ! isset( $_POST['local_highlights_box_nonce'] ) ) | |
return $post_id; | |
$nonce = $_POST['local_highlights_box_nonce']; | |
// Verify that the nonce is valid. | |
if ( ! wp_verify_nonce( $nonce, 'local_highlights_box' ) ) | |
return $post_id; | |
// If this is an autosave, our form has not been submitted, | |
// so we don't want to do anything. | |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) | |
return $post_id; | |
// Check the user's permissions. | |
if ( 'page' == $_POST['post_type'] ) { | |
if ( ! current_user_can( 'edit_page', $post_id ) ) | |
return $post_id; | |
} else { | |
if ( ! current_user_can( 'edit_post', $post_id ) ) | |
return $post_id; | |
} | |
// Sanitize the user input. | |
$prefixes = $_POST['prefix']; | |
$local_highlights = array(); | |
foreach($prefixes as $prefix) { | |
if ( isset( $_POST[$prefix .'local_highlights'] ) ) { | |
$local_highlights = array_merge( $local_highlights, $_POST[$prefix .'local_highlights'] ); | |
} | |
} | |
// Update the product highlight terms. | |
wp_set_object_terms($post_id, $local_highlights, 'local_highlights'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AMCN\Core\Post_Meta\Images; | |
/** | |
* Load various actions for this post meta | |
* | |
* @since 0.1.0 | |
* | |
* @return void. | |
*/ | |
function load() { | |
add_action( 'add_meta_boxes', __NAMESPACE__ . '\show_images_store' ); | |
add_action( 'save_post', __NAMESPACE__ . '\show_images_update' ); | |
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\admin_scripts' ); | |
} | |
/** | |
* Create Meta box for the show images meta | |
* | |
* @since 0.1.0 | |
* | |
* @return void. | |
*/ | |
function show_images_store() { | |
add_meta_box( | |
'show-images', | |
__( 'Show Images', 'amcn' ), | |
__NAMESPACE__ . '\show_images_display', | |
'amcn_show', | |
'advanced' | |
); | |
} | |
/** | |
* Callback func for show images meta box. | |
* | |
* @since 0.1.0 | |
* | |
* @param object $post post object | |
* | |
*/ | |
function show_images_display( $post ) { | |
// Add an nonce field so we can check for it later. | |
wp_nonce_field( 'show_media_metabox', 'show_media_metabox_nonce' ); | |
$show_stored_meta = get_post_meta( $post->ID ); ?> | |
<p> | |
<h4><label for="show-masthead"><?php _e( 'Show Masthead' , 'amcn' );?></label></h4> | |
<input type="text" name="show_masthead" id="show-masthead" value="<?php if ( isset ( $show_stored_meta['show_masthead'] ) ){ echo $show_stored_meta['show_masthead'][0]; } ?>" /> | |
<input type="button" id="show-masthead-button" class="button" value="Choose or Upload an Image" /> | |
</p> | |
<?php if ( isset ( $show_stored_meta['show_masthead'] ) ){ | |
echo '<div class="image-preview">'; | |
echo '<p><img src="' . $show_stored_meta['show_masthead'][0] . '" width="150"/></p>'; | |
echo '<button class="remove-image">'. __( 'Remove Image' , 'amctv' ) .'</button>'; | |
echo '</div>'; | |
} ?> | |
<p> | |
<h4><label for="show-logo"><?php _e( 'Show Logo' , 'amcn' );?></label></h4> | |
<input type="text" name="show_logo" id="show-logo" value="<?php if ( isset ( $show_stored_meta['show_logo'] ) ){ echo $show_stored_meta['show_logo'][0]; } ?>" /> | |
<input type="button" id="show-logo-button" class="button" value="Choose or Upload an Image" /> | |
</p> | |
<?php if ( isset ( $show_stored_meta['show_logo'] ) ){ | |
echo '<div class="image-preview">'; | |
echo '<p><img src="' . $show_stored_meta['show_logo'][0] . '" width="150"/></p>'; | |
echo '<button class="remove-image">'. __( 'Remove Image' , 'amctv' ) .'</button>'; | |
echo '</div>'; | |
} ?> | |
<p> | |
<h4><label for="show-poster"><?php _e( 'Show Poster' , 'amcn' );?></label></h4> | |
<input type="text" name="show_poster" id="show-poster" value="<?php if ( isset ( $show_stored_meta['show_poster'] ) ){ echo $show_stored_meta['show_poster'][0]; } ?>" /> | |
<input type="button" id="show-poster-button" class="button" value="Choose or Upload an Image" /> | |
</p> | |
<?php if ( isset ( $show_stored_meta['show_poster'] ) ){ | |
echo '<div class="image-preview">'; | |
echo '<p><img src="' . $show_stored_meta['show_poster'][0] . '" width="150"/></p>'; | |
echo '<button class="remove-image">'. __( 'Remove Image' , 'amctv' ) .'</button>'; | |
echo '</div>'; | |
} ?> | |
<p> | |
<h4><label for="small-tout"><?php _e( 'Small Tout Image' , 'amcn' );?></label></h4> | |
<input type="text" name="small_tout" id="small-tout" value="<?php if ( isset ( $show_stored_meta['small_tout'] ) ){ echo $show_stored_meta['small_tout'][0]; } ?>" /> | |
<input type="button" id="small-tout-button" class="button" value="Choose or Upload an Image" /> | |
</p> | |
<?php if ( isset ( $show_stored_meta['small_tout'] ) ){ | |
echo '<div class="image-preview">'; | |
echo '<p><img src="' . $show_stored_meta['small_tout'][0] . '" width="150"/></p>'; | |
echo '<button class="remove-image">'. __( 'Remove Image' , 'amctv' ) .'</button>'; | |
echo '</div>'; | |
} ?> | |
<p> | |
<h4><label for="large-tout"><?php _e( 'Large Tout Image' , 'amcn' );?></label></h4> | |
<input type="text" name="large_tout" id="large-tout" value="<?php if ( isset ( $show_stored_meta['large_tout'] ) ){ echo $show_stored_meta['large_tout'][0]; } ?>" /> | |
<input type="button" id="large-tout-button" class="button" value="Choose or Upload an Image" /> | |
</p> | |
<?php if ( isset ( $show_stored_meta['large_tout'] ) ){ | |
echo '<div class="image-preview">'; | |
echo '<p><img src="' . $show_stored_meta['large_tout'][0] . '" width="150"/></p>'; | |
echo '<button class="remove-image">'. __( 'Remove Image' , 'amctv' ) .'</button>'; | |
echo '</div>'; | |
} ?> | |
<?php | |
} | |
/** | |
* Save the meta when the post is saved. | |
* | |
* @since 0.1.0 | |
* | |
* @param int $post_id The ID of the post being saved. | |
*/ | |
function show_images_update( $post_id ) { | |
// Check if our nonce is set. | |
if ( ! isset( $_POST['show_media_metabox_nonce'] ) ) | |
return $post_id; | |
$nonce = $_POST['show_media_metabox_nonce']; | |
// Verify that the nonce is valid. | |
if ( ! wp_verify_nonce( $nonce, 'show_media_metabox' ) ) | |
return $post_id; | |
// If this is an autosave, our form has not been submitted, so we don't want to do anything. | |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) | |
return $post_id; | |
// Check the user's permissions. | |
if ( ! current_user_can( 'edit_post', $post_id ) ) { | |
return $post_id; | |
} | |
// Checks for input and sanitizes/saves if needed | |
if( isset( $_POST[ 'show_logo' ] ) ) { | |
update_post_meta( $post_id, 'show_logo', $_POST[ 'show_logo' ] ); | |
} | |
if( isset( $_POST[ 'small_show_poster' ] ) ) { | |
update_post_meta( $post_id, 'small_show_poster', $_POST[ 'small_show_poster' ] ); | |
} | |
if( isset( $_POST[ 'large_show_poster' ] ) ) { | |
update_post_meta( $post_id, 'large_show_poster', $_POST[ 'large_show_poster' ] ); | |
} | |
if( isset( $_POST[ 'small_tout' ] ) ) { | |
update_post_meta( $post_id, 'small_tout', $_POST[ 'small_tout' ] ); | |
} | |
if( isset( $_POST[ 'large_tout' ] ) ) { | |
update_post_meta( $post_id, 'large_tout', $_POST[ 'large_tout' ] ); | |
} | |
} | |
/** | |
* Gets and array of post types that pertain to social repeater meta | |
* | |
* @since 0.1.0 | |
* | |
* @return array An array of post type slugs. | |
*/ | |
function get_post_types() { | |
return apply_filters( 'amcn_show_images', array() ); | |
} | |
/** | |
* admin_scripts function | |
* | |
* @since 0.1.0 | |
* @return void | |
*/ | |
function admin_scripts() { | |
global $typenow; | |
if( 'amcn_show' === $typenow ) { | |
wp_enqueue_script( 'show-image-upload', AMCN_ASSETS . '/js/src/show-image-upload.js', array( 'jquery' ) ); | |
} | |
} | |
//getting show poster | |
<?php $show_poster = get_post_meta( $menu_item->object_id, 'show_poster', true ); ?> | |
// getting show tout | |
<?php echo esc_url( get_post_meta( absint( $footer_posts['left'] ) , 'large_tout' , true ) ) ;?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment