Skip to content

Instantly share code, notes, and snippets.

@unsalkorkmaz
Last active November 11, 2019 11:13
Show Gist options
  • Save unsalkorkmaz/6edb5bf45889ae43564fc0f02e19cb32 to your computer and use it in GitHub Desktop.
Save unsalkorkmaz/6edb5bf45889ae43564fc0f02e19cb32 to your computer and use it in GitHub Desktop.
[firmasite showcase for editors] #firmasite #wordpress
<?php
add_action( 'admin_head', 'firmasite_js_showcase_for_editors',9 );
// add jquery function to admin head to save
function firmasite_js_showcase_for_editors(){
remove_action( 'admin_head', 'firmasite_js_showcase_posts_add_jquery_to_head' );
if ( current_user_can("edit_pages") ){ ?>
<script type="text/javascript" language="javascript">
jQuery(document).ready(function(){
// when the checkbox is clicked save the meta option for this post
jQuery('.showcase_posts_star').click(function() {
var selected = 'yes';
if ( jQuery(this).hasClass( 'selected' ) ){
jQuery(this).removeClass( 'selected' );
selected = 'no';
} else { jQuery(this).addClass( 'selected' ); }
// get id
var postID = jQuery(this).attr('data-id');
var jsshowcasenonce = jQuery(this).attr('data-nonce');
jQuery.post( ajaxurl, 'action=jsshowcase_posts&post='+postID+'&jsshowcase-nonce='+jsshowcasenonce+'&firmasite_showcase='+selected );
});
});
</script> <?php
}
}
add_action( 'admin_head', 'firmasite_js_promotionbar_for_editors',9 );
// add jquery function to admin head to save
function firmasite_js_promotionbar_for_editors(){
remove_action( 'admin_head', 'firmasite_js_promotionbar_posts_add_jquery_to_head' );
if ( current_user_can("edit_pages") ){ ?>
<script type="text/javascript" language="javascript">
jQuery(document).ready(function(){
// when the checkbox is clicked save the meta option for this post
jQuery('.promotionbar_posts_star').click(function() {
var selected = 'yes';
if ( jQuery(this).hasClass( 'selected' ) ){
jQuery(this).removeClass( 'selected' );
selected = 'no';
} else { jQuery(this).addClass( 'selected' ); }
// get id
var postID = jQuery(this).attr('data-id');
var jspromotionbarnonce = jQuery(this).attr('data-nonce');
jQuery.post( ajaxurl, 'action=jspromotionbar_posts&post='+postID+'&jspromotionbar-nonce='+jspromotionbarnonce+'&firmasite_promotionbar='+selected );
});
});
</script> <?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment