Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Global Featured Posts
- Description: WordPress plugin for setting site-wide featured posts
- Author: Flavio Li Volsi
- Version: 1.0
- */
- /**
- * Backend page for setup
- */
- class wp_global_posts_page
- {
- function __construct()
- {
- add_action( 'admin_menu', array( $this, 'admin_menu' ) );
- }
- function admin_menu()
- {
- add_management_page( 'Global Featured Posts', 'Global Featured Posts', 'edit_posts', 'global_featured_posts', array( $this, 'settings_page' ) );
- }
- function settings_page()
- {
- if ( isset( $_POST["globalPostsSubmit"] ) ) {
- for ($i=0;$i<6;$i++) {
- update_option( "global_post_".$i, json_encode( array( 'img' => $_POST['gp_'.$i.'_img'], 'title' => $_POST['gp_'.$i.'_title'], 'url' => $_POST['gp_'.$i.'_url'] ) ) );
- }
- }
- wp_enqueue_media();
- ?>
- <script type="text/javascript">
- jQuery(document).on('click', '.insert-media', function(event) {
- var id = jQuery(this).data("id");
- console.log(id);
- wp.media.editor.send.attachment = function(props, attachment) {
- jQuery('#gp_'+id+'_img').val(attachment.url);
- }
- });
- </script>
- <div class="wrap">
- <h2>Global Featured Posts</h2>
- <form method="POST">
- <?php for ($i=0;$i<6;$i++) { ?>
- <?php $current = json_decode( get_option( "global_post_".$i ), true ); ?>
- <p>Image:</p>
- <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>
- <p>Link to:</p>
- <p><input type="text" name="gp_<?php echo $i; ?>_url" placeholder="URL" value="<?php echo $current['url'] ?>"></p>
- <p>Title:</p>
- <p><input type="text" name="gp_<?php echo $i; ?>_title" placeholder="Title" value="<?php echo $current['title'] ?>"></p>
- <p><input type="submit" name="globalPostsSubmit" class="button" value="Save"></p>
- <hr>
- <?php } ?>
- </form>
- </div>
- <?php
- }
- }
- new wp_global_posts_page;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement