ID, 'preloader_advert_option', true ));
?>
name="preloader-advert-option" value="yes">
name="preloader-advert-option" value="no">
' . __( 'only on selected posts and pages', 'AdvertLoader' ) . '' );
}
}
// Save the meta box's post metadata.
function preloader_advert_save_post_meta( $post_id ) {
// Verify the nonce before proceeding.
if ( !isset( $_POST['preloader_advert_option_nonce'] ) || !wp_verify_nonce( $_POST['preloader_advert_option_nonce'], basename( __FILE__ ) ) ){
return $post_id;
}
// Get the post type object.
$post_type = get_post_type_object( $post->post_type );
/*
// Check if the current user has permission to edit the post.
if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ){
var_dump("permission problem");
return $post_id;
}
*/
// Return if it's a post revision
if ( false !== wp_is_post_revision( $post_id ) ){
return $post_id;
}
// Get the posted data and sanitize it for use as an HTML class.
$new_meta_value = ( isset( $_POST['preloader-advert-option'] ) ? sanitize_html_class( $_POST['preloader-advert-option'] ) : '' );
// Get the meta key.
$meta_key = 'preloader_advert_option';
// Get the meta value of the custom field key.
$meta_value = get_post_meta( $post_id, $meta_key, true );
// If a new meta value was added and there was no previous value, add it.
if ( $new_meta_value && '' == $meta_value ){
add_post_meta( $post_id, $meta_key, $new_meta_value, true );
}
// If the new meta value does not match the old value, update it.
else if ( $new_meta_value && $new_meta_value != $meta_value ){
update_post_meta( $post_id, $meta_key, $new_meta_value );
}
// If there is no new meta value but an old value exists, delete it.
else if ( '' == $new_meta_value && $meta_value ){
delete_post_meta( $post_id, $meta_key, $meta_value );
}
}
// add the_content filter to replace content with preloader
add_filter('the_content', 'preloader_advert_add_to_content');
function preloader_advert_add_to_content($content = ''){
// get current post ID
$post_id = get_the_ID();
if ( !empty( $post_id ) ) {
// first get options from meta and preloader options
$show_preloader_for_specific_post = get_post_meta( $post_id, 'preloader_advert_option', true );
$show_preloader_basic_option = GetPreloaderOptions("preloader_show_on");
// Where to show preloader?
if((is_single($post_id) || is_page($post_id)) && GetPreloaderOptions("preloader_show_on_page_type")==='only_full_content'){
$preloader_HTML = generate_advert_preloader_HTML();
if($show_preloader_basic_option === 'selected_posts'){
if($show_preloader_for_specific_post === 'yes'){
// add preloader here
$content = $preloader_HTML.'