Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. Plugin Name: Global Featured Posts
  5. Description: WordPress plugin for setting site-wide featured posts
  6. Author: Flavio Li Volsi
  7. Version: 1.0
  8. */
  9.  
  10. /**
  11. * Backend page for setup
  12. */
  13. class wp_global_posts_page
  14. {
  15.  
  16. function __construct()
  17. {
  18. add_action( 'admin_menu', array( $this, 'admin_menu' ) );
  19. }
  20.  
  21. function admin_menu()
  22. {
  23. add_management_page( 'Global Featured Posts', 'Global Featured Posts', 'edit_posts', 'global_featured_posts', array( $this, 'settings_page' ) );
  24. }
  25.  
  26. function settings_page()
  27. {
  28. if ( isset( $_POST["globalPostsSubmit"] ) ) {
  29. for ($i=0;$i<6;$i++) {
  30. update_option( "global_post_".$i, json_encode( array( 'img' => $_POST['gp_'.$i.'_img'], 'title' => $_POST['gp_'.$i.'_title'], 'url' => $_POST['gp_'.$i.'_url'] ) ) );
  31. }
  32. }
  33.  
  34. wp_enqueue_media();
  35. ?>
  36. <script type="text/javascript">
  37. jQuery(document).on('click', '.insert-media', function(event) {
  38. var id = jQuery(this).data("id");
  39. console.log(id);
  40. wp.media.editor.send.attachment = function(props, attachment) {
  41. jQuery('#gp_'+id+'_img').val(attachment.url);
  42. }
  43. });
  44. </script>
  45. <div class="wrap">
  46. <h2>Global Featured Posts</h2>
  47. <form method="POST">
  48. <?php for ($i=0;$i<6;$i++) { ?>
  49. <?php $current = json_decode( get_option( "global_post_".$i ), true ); ?>
  50. <p>Image:</p>
  51. <p><input type="text" id="gp_<?php echo $i; ?>_img" name="gp_<?php echo $i; ?>_img" placeholder="Image" value="<?php echo $current['img']; ?>"> <button class="button insert-media" data-id="<?php echo $i; ?>">Upload</button></p>
  52. <p>Link to:</p>
  53. <p><input type="text" name="gp_<?php echo $i; ?>_url" placeholder="URL" value="<?php echo $current['url'] ?>"></p>
  54. <p>Title:</p>
  55. <p><input type="text" name="gp_<?php echo $i; ?>_title" placeholder="Title" value="<?php echo $current['title'] ?>"></p>
  56. <p><input type="submit" name="globalPostsSubmit" class="button" value="Save"></p>
  57. <hr>
  58. <?php } ?>
  59. </form>
  60. </div>
  61. <?php
  62. }
  63.  
  64. }
  65. new wp_global_posts_page;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement