Guest User

Untitled

a guest
Nov 27th, 2019
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.75 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: widgets
  4. Version: 1.0
  5. Plugin URI:
  6. Description: Create widgets
  7. Author: RBS
  8. Author URI:  
  9. License: GPLv2 or later
  10. License URI: http://www.opensource.org/licenses/gpl-license.php
  11. */
  12.  
  13.  
  14.  
  15. //Uson una CPT llamada 'curso-ingles-basico'
  16.  
  17. add_action( 'add_meta_boxes', 'rb_mp3tables_register_meta_boxes' );
  18. function rb_mp3tables_register_meta_boxes(){
  19.  
  20.   add_meta_box( 'rb_mp3tables_1', 'Mp3 Tables', 'rb_mp3tables_1_display', 'curso-ingles-basico', 'advanced', 'high');
  21.  
  22.   add_meta_box( 'rb_podcastfields_id1', 'Podcast Fields', 'rb_podcastfields_id1_display', 'curso-ingles-basico','side', 'high' );
  23.  
  24. }
  25.  
  26. // METABOX1
  27.  
  28. // Añadimos los campos de formulario a nuestro meta box
  29. function rb_mp3tables_1_display( $post ){
  30.   $post_id = $post->ID;
  31.   //obtenemos los metadata de este post
  32.   $rb_mp3tables_metadata = get_post_meta( $post_id, '_rb_mp3tables_folder', true );
  33. ?>
  34. <!-- text -->
  35. <p>
  36.   <label for="rb_mp3tables_folder">Folder:</label>
  37.   <input type="text" name="rb_mp3tables_folder" id="rb_mp3tables_folder" value="<?php if( isset( $rb_mp3tables_metadata ) ) echo $rb_mp3tables_metadata; ?>">
  38. </p>
  39.  
  40. <?php
  41. }
  42.  
  43. // METABOX2 - Busca los post ID del CPT 'podcast' que está generado por Simple Seriously Podcasting
  44.  
  45. // Añadimos los campos de formulario a nuestro meta box
  46. function rb_podcastfields_id1_display($post){
  47.   $post_id = $post->ID;
  48.   $rb_podcast_enabled = get_post_meta( $post_id, '_rb_podcast_enabled', true );
  49.   $rb_podcast_episode = get_post_meta( $post_id, '_rb_podcast_episode', true );
  50.   ?>
  51.   <p>
  52.     <label for="rb_podcast_enabled">
  53.     <input type="checkbox" name="rb_podcast_enabled" id="rb_podcast_enabled" value="yes" <?php if( isset( $rb_podcast_enabled ) ) checked($rb_podcast_enabled, 'yes'); ?>>
  54.     Podcast Enabled?</label>
  55.   </p>
  56.   <?php
  57.     $args = array( 'posts_per_page' => 100,
  58.                     'offset' => 0,
  59.                     'category' => '',
  60.                     'category_name' => '',
  61.                     'orderby' => 'date',
  62.                     'order' => 'desc',
  63.                     'post_type' => 'podcast',
  64.                     'post_parent' => '',
  65.                     'post_status' => 'publish',
  66.                     'suppress_filters' => true );
  67.  
  68.     $my_query = new WP_Query( $args );
  69.   ?>
  70.     <p>
  71.       <label for="rb_podcast_episode">Podcast Episode</label>
  72.       <select name="rb_podcast_episode" id="rb_podcast_episode">
  73.         <option value="">-- Choose Podcast</option>
  74.         <?php
  75.         if ($my_query->have_posts()) : while( $my_query->have_posts() ): $my_query->the_post();  ?>
  76.  
  77.           <option value ="<?php the_ID(); ?>" <?php if( isset( $rb_podcast_episode ) ) selected($rb_podcast_episode,  get_the_ID() ); ?>>  <?php   the_title(); ?>  </option>
  78.         <?php endwhile; wp_reset_postdata(); endif; ?>
  79.       </select>
  80.     </p>
  81.   <?php      
  82. }
  83.  
  84. // Guardamos los meta datos
  85. add_action( 'save_post', 'rb_mp3tables_save_meta' );
  86.  
  87. function rb_mp3tables_save_meta( $post_id ){
  88.  
  89.   // comprobamos si hay datos en el campo del formulario
  90.   if( isset($_POST['rb_mp3tables_folder']) && ($_POST['rb_mp3tables_folder'] != '') ):
  91.     // añadirlo o modificar el metadata
  92.     update_post_meta( $post_id, '_rb_mp3tables_folder', $_POST['rb_mp3tables_folder'] );
  93.   endif;
  94.  
  95.   // comprobamos si hay datos en el campo del formulario
  96.   if( isset($_POST['rb_podcast_enabled']) && ($_POST['rb_podcast_enabled'] !='')):
  97.       // añadirlo o modificar el metadata
  98.     update_post_meta( $post_id, '_rb_podcast_enabled', $_POST['rb_podcast_enabled'] );
  99.   endif;
  100.  
  101.   if( isset($_POST['rb_podcast_episode']) && ($_POST['rb_podcast_episode'] !='')):
  102.       // añadirlo o modificar el metadata
  103.     update_post_meta( $post_id, '_rb_podcast_episode', $_POST['rb_podcast_episode'] );
  104.   endif;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment