Guest User

Untitled

a guest
Dec 13th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Register Metabox
  5. */
  6. function themeplate_register_metabox() {
  7. add_meta_box(
  8. 'post-settings',
  9. 'Post Settings',
  10. 'themeplate_post_settings_metabox',
  11. 'post',
  12. 'side',
  13. 'high'
  14. );
  15. }
  16.  
  17. add_action( 'admin_init', 'themeplate_register_metabox' );
  18.  
  19. /*
  20. * Post Settings Metabox
  21. */
  22. function themeplate_post_settings_metabox( $post ) {
  23. // wp security check
  24. wp_nonce_field( 'post_meta_nonce_', 'post_nonce_' );
  25. $sportlight_post= get_post_meta($post->ID, 'sportlight_on', true);
  26. ?>
  27. <div class="metabox-section">
  28. <p>
  29. <label for="sportlight_on">
  30. <input type="checkbox" name="sportlight_on" id="sportlight_on" value="on" <?php if ('on' == $sportlight_post) echo 'checked="checked"'; ?>>
  31. <b><?php echo esc_html__( 'SPOTLIGHT ON', 'themeplate' ) ?></b></label>
  32. </p>
  33. </div>
  34. <?php
  35. }
  36.  
  37.  
  38. function themeplate_save_postmeta( $post_id ) {
  39. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
  40. return;
  41. }
  42. if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
  43. return;
  44. }
  45. if ( 'post' !== get_post_type( $post_id ) ) {
  46. return;
  47. }
  48. // security check
  49. if ( ! isset( $_POST['post_nonce_'] ) ) {
  50. return;
  51. }
  52. if ( ! wp_verify_nonce( $_POST['post_nonce_'], 'post_meta_nonce_' ) ) {
  53. return;
  54. }
  55. update_post_meta( $post_id, 'sportlight_on', empty( $_POST['sportlight_on'] ) ? '' : $_POST['sportlight_on'] );
  56.  
  57.  
  58. }
  59. add_action( 'save_post', 'themeplate_save_postmeta' );
Add Comment
Please, Sign In to add comment