Basdower

descarga.php

Dec 10th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.57 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Descargas MetaBox
  4. Plugin URI: http://basdower.com
  5. Description: Descargas MetaBox agregara un campo de texto para su descarga.
  6. Version: 1.0
  7. Author: Basdower
  8. Author URI: http://basdower.com
  9. License: GPL2
  10. */
  11.  
  12. function link_get_meta( $value ) {
  13.     global $post;
  14.  
  15.     $field = get_post_meta( $post->ID, $value, true );
  16.     if ( ! empty( $field ) ) {
  17.         return is_array( $field ) ? stripslashes_deep( $field ) : stripslashes( wp_kses_decode_entities( $field ) );
  18.     } else {
  19.         return false;
  20.     }
  21. }
  22. function link_add_meta_box() {
  23.     add_meta_box(
  24.         'link-link',
  25.         __( 'Descarga', 'link' ),
  26.         'link_html',
  27.         'post',
  28.         'normal',
  29.         'default'
  30.     );
  31. }
  32. add_action( 'add_meta_boxes', 'link_add_meta_box' );
  33. function link_html( $post) {
  34.     wp_nonce_field( '_link_nonce', 'link_nonce' ); ?>
  35.     <table class="form-table">
  36.         <tr>
  37.             <th style="width:10%"><label for="link_by_basdower">Link</label></th>
  38.             <td><input type="text" name="link_by_basdower" id="link_by_basdower" value="<?php echo link_get_meta( 'link_by_basdower' ); ?>" size="30" style="width:97%"> Ingresa el enlace de tu descarga</td>
  39.         </tr>
  40.     </table>
  41. <?php
  42. }
  43. function link_save( $post_id ) {
  44.     if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
  45.     if ( ! isset( $_POST['link_nonce'] ) || ! wp_verify_nonce( $_POST['link_nonce'], '_link_nonce' ) ) return;
  46.     if ( ! current_user_can( 'edit_post', $post_id ) ) return;
  47.  
  48.     if ( isset( $_POST['link_by_basdower'] ) )
  49.         update_post_meta( $post_id, 'link_by_basdower', esc_attr( $_POST['link_by_basdower'] ) );
  50. }
  51. add_action( 'save_post', 'link_save' );
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment