Advertisement
Guest User

Untitled

a guest
Sep 27th, 2020
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.93 KB | None | 0 0
  1. <?php
  2.  
  3. if ( !defined( 'ABSPATH' ) ) {
  4.     exit;
  5. }
  6.  
  7. function my_whatsapp_assets() {
  8.     $current_screen = get_current_screen();
  9.  
  10.     if ( !is_object($current_screen) || 'my_page_my_whatsapp' !== $current_screen->base ) return;
  11.     if ( wp_doing_ajax() ) return;
  12.  
  13.     wp_enqueue_script( 'jquery-mask', MY_URI . 'assets/js/jquery.mask.min.js', array( 'wp-color-picker' ), my_VERSION );
  14. }
  15.  
  16. add_action( 'admin_enqueue_scripts', 'my_whatsapp_assets' );
  17.  
  18. function my_view_whatsapp() {
  19.     if(isset($_POST['submit']) && !wp_verify_nonce($_POST['my_agency_whatsapp_form'], 'my_agency')) {
  20.         echo '<div class="notice notice-error"><p>Falha na verificação!</p></div>';
  21.         exit;
  22.     }
  23.  
  24.     // Save form submition
  25.     if (isset($_POST['submit'])) {
  26.         update_option( 'my_whatsapp_enable', sanitize_text_field($_POST['my_whatsapp_enable']) );
  27.         update_option( 'my_whatsapp_phone', sanitize_text_field($_POST['my_whatsapp_phone']) );
  28.         update_option( 'my_whatsapp_text', sanitize_text_field($_POST['my_whatsapp_text']) );
  29.         update_option( 'my_whatsapp_message', sanitize_text_field($_POST['my_whatsapp_message']) );
  30.  
  31.         echo '<div class="notice notice-success is-dismissible"><p>As configurações foram salvas com sucesso!</p></div>';
  32.     }
  33.        
  34.     ?>
  35.  
  36.     <form method="POST">
  37.         <?php wp_nonce_field( 'my_agency', 'my_agency_whatsapp_form' ); ?>
  38.  
  39.         <table class="form-table" role="presentation">
  40.             <tbody>
  41.                 <!-- Ativar módulo -->
  42.                 <tr>
  43.                     <th scope="row"><label>Ativar o módulo Whatsapp</label></th>
  44.                     <td>
  45.                         <input name="my_whatsapp_enable" type="checkbox" value="1" <?php if (get_option('my_whatsapp_enable') == true) echo "checked"; ?> />
  46.                         <p class="description">Marque essa opção para ativar o módulo whatsapp.</p>
  47.                     </td>
  48.                 </tr>
  49.                
  50.         <!-- Número do telefone -->
  51.                 <tr>
  52.                     <th scope="row"><label>Número do telefone</label></th>
  53.                     <td>
  54.                         <input
  55.                             type="text"
  56.                             class="regular-text my_mask_phone"
  57.                             name="my_whatsapp_phone"
  58.                             value="<?php echo get_option('my_whatsapp_phone'); ?>"
  59.                             placeholder="(48) 9.9988-7766"
  60.                         />
  61.                     </td>
  62.                 </tr>
  63.  
  64.                 <!-- Texto do botão -->
  65.                 <tr>
  66.                     <th scope="row"><label>Texto do botão</label></th>
  67.                     <td>
  68.                         <input
  69.                             type="text"
  70.                             class="regular-text"
  71.                             name="my_whatsapp_text"
  72.                             value="<?php echo get_option('my_whatsapp_text'); ?>"
  73.                             placeholder="Precisa de ajuda?"
  74.                         />
  75.                     </td>
  76.                 </tr>
  77.  
  78.                 <!-- Mensagem -->
  79.                 <tr>
  80.                     <th scope="row"><label>Mensagem</label></th>
  81.                     <td>
  82.                         <textarea name="my_whatsapp_message" class="regular-text" maxlength="180" rows="4" placeholder="Olá, estou entrando em contato através do site"><?php echo get_option('my_whatsapp_message'); ?></textarea>
  83.                     </td>
  84.                 </tr>
  85.             </tbody>
  86.         </table>
  87.  
  88.         <p class="submit">
  89.             <input type="submit" name="submit" id="submit" class="button button-primary" value="Salvar alterações">
  90.         </p>
  91.     </form>
  92.     <?php
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement