Advertisement
Guest User

functions.php

a guest
Mar 25th, 2019
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.40 KB | None | 0 0
  1.     /*-----------------------------------------------------
  2.      *   Función de wordpress para administrar las opciones del tema
  3.      *----------------------------------------------------*/   
  4.  
  5.     function theme_settings_page()
  6.     {
  7.     ?>
  8.         <div class="wrap">
  9.         <h1>Theme Panel</h1>
  10.         <form method="post" action="options.php" enctype="multipart/form-data">
  11.             <?php
  12.                 settings_fields("section");
  13.                 do_settings_sections("theme-options");      
  14.                 submit_button();
  15.             ?>
  16.         </form>
  17.         </div>
  18.     <?php      
  19.     }
  20.  
  21.     function add_theme_menu_item()
  22.     {
  23.         add_menu_page("Theme Panel", "Theme Panel", "manage_options", "theme-panel", "theme_settings_page", null, 99);
  24.     }
  25.  
  26.     add_action("admin_menu", "add_theme_menu_item");   
  27.  
  28.     /*-----------------------------------------------------
  29.      *   Función de wordpress para mostrar que opciones
  30.      del tema se van a administrar
  31.      *----------------------------------------------------*/
  32.  
  33.     function display_search_header()
  34.     {
  35.         ?>
  36.             <input type="checkbox" name="theme_layout" value="1" <?php checked(1, get_option('theme_layout'), true); ?> /> Si
  37.         <?php
  38.     }    
  39.  
  40.     function display_facebook_element()
  41.     {
  42.         ?>
  43.             <input type="text" name="facebook_url" id="facebook_url" value="<?php echo get_option('facebook_url'); ?>" style="width: 50%;" />
  44.         <?php
  45.     }
  46.  
  47.     function display_twitter_element()
  48.     {
  49.         ?>
  50.             <input type="text" name="twitter_url" id="twitter_url" value="<?php echo get_option('twitter_url'); ?>" style="width: 50%;" />
  51.         <?php
  52.     }
  53.  
  54.     function display_google_plus_element()
  55.     {
  56.         ?>
  57.             <input type="text" name="google_plus_url" id="google_plus_url" value="<?php echo get_option('google_plus_url'); ?>" style="width: 50%;" />
  58.         <?php
  59.     }
  60.  
  61.     function display_youtube_element()
  62.     {
  63.         ?>
  64.             <input type="text" name="youtube_url" id="youtube_url" value="<?php echo get_option('youtube_url'); ?>" style="width: 50%;" />
  65.         <?php
  66.     }
  67.  
  68.     function display_pinterest_element()
  69.     {
  70.         ?>
  71.             <input type="text" name="pinterest_url" id="pinterest_url" value="<?php echo get_option('pinterest_url'); ?>" style="width: 50%;" />
  72.         <?php
  73.     }
  74.     function display_instagram_element()
  75.     {
  76.         ?>
  77.             <input type="text" name="instagram_url" id="instagram_url" value="<?php echo get_option('instagram_url'); ?>" style="width: 50%;" />
  78.         <?php
  79.     }      
  80.     function display_linkedin_element()
  81.     {
  82.         ?>
  83.             <input type="text" name="linkedin_url" id="linkedin_url" value="<?php echo get_option('linkedin_url'); ?>" style="width: 50%;" />          
  84.         <?php
  85.     }
  86.  
  87.     function display_phone_whatsapp()
  88.     {
  89.         ?>
  90.             <input type="text" name="phone_ws" id="phone_ws" value="<?php echo get_option('phone_ws'); ?>" style="width: 50%;" />          
  91.         <?php      
  92.     }
  93.     function display_link_customize()
  94.     {
  95.         ?>
  96.             <input type="text" name="customize_url_ws" id="customize_url_ws" value="<?php echo get_option('customize_url_ws'); ?>" style="width: 50%;" />          
  97.         <?php      
  98.     }
  99.     function display_email_element()
  100.     {
  101.         ?>
  102.             <input type="text" name="email_url" id="email_url" value="<?php echo get_option('email_url'); ?>" style="width: 50%;" />           
  103.         <?php
  104.     }      
  105.  
  106.     /*-----------------------------------------------------
  107.      *   Función de wordpress para administrar los derechos
  108.          de autor y administrar el logo en el pie de pagina
  109.      *----------------------------------------------------*/
  110.  
  111.     function display_copyright_element()
  112.     {
  113.         ?>
  114.             <input type="text" name="copyright_text" id="copyright_text" value="<?php echo get_option('copyright_text'); ?>" style="width: 50%;" />
  115.         <?php
  116.  
  117.     }
  118.  
  119.     function logo_setting()
  120.     {  
  121.         $options = get_option('plugin_options');
  122.  
  123.         if($options=="")
  124.         {
  125.             echo "";
  126.         }
  127.         else
  128.         {
  129.     ?>
  130.         <p><img src="<?php echo $options['logo']; ?>" alt="Logo" /></p>
  131.     <?php
  132.         }
  133.     ?>
  134.         <input type="file" name="logo" />
  135.     <?php
  136.     }
  137.  
  138.     function display_theme_panel_fields()
  139.     {
  140.        
  141.  
  142.         add_settings_field("theme_layout", "Desea desactivar el buscador del header ?", "display_search_header", "theme-options", "section");
  143.  
  144.         add_settings_field("facebook_url", "Facebook Profile Url", "display_facebook_element", "theme-options", "section");    
  145.         add_settings_field("twitter_url", "Twitter Profile Url", "display_twitter_element", "theme-options", "section");
  146.         add_settings_field("google_plus_url", "Google Plus Profile Url", "display_google_plus_element", "theme-options", "section");
  147.         add_settings_field("youtube_url", "Youtube Channel Url", "display_youtube_element", "theme-options", "section");
  148.         add_settings_field("instagram_url", "Instagram Account", "display_instagram_element", "theme-options", "section");         
  149.         add_settings_field("pinterest_url", "Pinterest Profile Url", "display_pinterest_element", "theme-options", "section");
  150.         add_settings_field("linkedin_url", "Linkedin Profile Url", "display_linkedin_element", "theme-options", "section");
  151.         add_settings_field("email_url", "E-mail de la empresa", "display_email_element", "theme-options", "section");
  152.         add_settings_field("phone_ws", "Whatsapp number", "display_phone_whatsapp", "theme-options", "section");
  153.         add_settings_field("customize_url_ws", "Enlace de whatsapp", "display_link_customize", "theme-options", "section");
  154.  
  155.         add_settings_field("copyright_text", "Copyright Text", "display_copyright_element", "theme-options", "section");
  156.  
  157.         // add settings filed with callback test_logo_display.
  158.         add_settings_field('logo', 'Logo:', 'logo_setting', "theme-options", 'section'); // LOGO
  159.        
  160.         add_settings_section("section", "Cabecera y Footer Social Media", null, "theme-options");
  161.         register_setting("section", "theme_layout");
  162.         register_setting("section", "facebook_url");
  163.         register_setting("section", "twitter_url");
  164.         register_setting("section", "google_plus_url");
  165.         register_setting("section", "youtube_url");
  166.         register_setting("section", "instagram_url");      
  167.         register_setting("section", "pinterest_url");
  168.         register_setting("section", "linkedin_url");
  169.         register_setting("section", "email_url");      
  170.         register_setting("section", "phone_ws");
  171.         register_setting("section", "customize_url_ws");
  172.         register_setting("section", "copyright_text");
  173.         register_setting("section", 'logo');
  174.         register_setting('section', 'plugin_options', 'validate_setting');
  175.  
  176.     }
  177.     add_action("admin_init", "display_theme_panel_fields");
  178.  
  179.     function validate_setting($plugin_options)
  180.     {
  181.         $keys = array_keys($_FILES);
  182.  
  183.         $i = 0;
  184.         foreach ( $_FILES as $image )
  185.         {  
  186.             // if a files was upload  
  187.             if ($image['size'])
  188.             {    
  189.                 // if it is an image    
  190.                 if ( preg_match('/(jpg|jpeg|png|gif)$/', $image['type']) ) {      
  191.                     $override = array('test_form' => false);      
  192.                     // save the file, and store an array, containing its location in $file      
  193.                     $file = wp_handle_upload( $image, $override );      
  194.                     $plugin_options[$keys[$i]] = $file['url'];    
  195.                 }
  196.                 else
  197.                 {      
  198.                 // Not an image.        
  199.                 $options = get_option('plugin_options');      
  200.                 $plugin_options[$keys[$i]] = $options[$logo];      
  201.                 // Die and let the user know that they made a mistake.      
  202.                 wp_die('No image was uploaded.');    
  203.                 }  
  204.             }  
  205.             // Else, the user didn't upload a file.  
  206.             // Retain the image that's already on file.  
  207.             else
  208.             {    
  209.                 $options = get_option('plugin_options');    
  210.                 $plugin_options[$keys[$i]] = $options[$keys[$i]];  
  211.             }
  212.  
  213.         $i++;
  214.  
  215.         }
  216.        
  217.         return $plugin_options;
  218.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement