Advertisement
Guest User

Untitled

a guest
Jan 17th, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.40 KB | None | 0 0
  1. <?php
  2. /**
  3.  *
  4.  * Confirmation de lecture
  5.  *
  6.  */
  7.  
  8.  
  9. add_filter( 'rwmb_meta_boxes', 'confirmation_lecture_register_meta_boxes' );
  10.  
  11. function confirmation_lecture_register_meta_boxes( $meta_boxes ) {
  12.     $prefix = '';
  13.    
  14.     //global $post;                
  15.     //$post_id = $post->ID;
  16.  
  17.     //$ben = $GLOBALS['post']->ID;
  18.  
  19.     $ip_address = $_SERVER['SERVER_ADDR'];
  20.  
  21.     $meta_boxes[] = [
  22.         'title'      => esc_html__( 'Confirmation de lecture', 'text-domain' ),
  23.         'id'         => 'confirmation-lecture',
  24.         'fields'     => [
  25.             [
  26.                 'id'       => $prefix . 'signature',
  27.                 'type'     => 'text',
  28.                 'name'     => esc_html__( 'Signature', 'text-domain' ),
  29.                 'required' => 1,
  30.             ],
  31.             [
  32.                 'id'   => $prefix . 'check_lecture',
  33.                 'name' => esc_html__( '« Je confirme avoir lu le document »', 'text-domain' ),
  34.                 'type' => 'checkbox',
  35.                 'required' => 1,
  36.             ],
  37.             [
  38.                 'id'   => $prefix . 'testtest',
  39.                 'type' => 'text',
  40.                 'attributes' => array(
  41.                     'value' =>  $post_id, // Here is the value who's not working
  42.                 )
  43.             ],
  44.             array(
  45.                 'id'   => $prefix . 'hidden_postid',
  46.                 'type' => 'hidden',
  47.                 'attributes' => array(
  48.                     'value' =>  $post_id, // I tried both types text and hidden
  49.                 )
  50.             ),
  51.             array(
  52.                 'id'   => $prefix . 'ip_adrress',
  53.                 'type' => 'hidden',
  54.                 'attributes' => array(
  55.                     'value' =>  $ip_address, // this value works well
  56.                 )
  57.             ),
  58.             array(
  59.                 'id' => 'date_signature',
  60.                 'type' => 'hidden',
  61.                 'attributes' => array(
  62.                     'value' => date('d/m/Y'), // this value works well
  63.                 )
  64.             ),
  65.         ],
  66.         'validation' => array(
  67.             'messages' => array(
  68.                 'signature' => array(
  69.                     'required'   => 'Vous devez signer.',
  70.                 ),
  71.                 'check_lecture' => array(
  72.                     'required'   => 'Vous devez confirmer la lecture.',
  73.                 ),
  74.             ),
  75.         ),
  76.     ];
  77.  
  78.     return $meta_boxes;
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement