Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-----------------------------------------------------
- * Función de wordpress para administrar las opciones del tema
- *----------------------------------------------------*/
- function theme_settings_page()
- {
- ?>
- <div class="wrap">
- <h1>Theme Panel</h1>
- <form method="post" action="options.php" enctype="multipart/form-data">
- <?php
- settings_fields("section");
- do_settings_sections("theme-options");
- submit_button();
- ?>
- </form>
- </div>
- <?php
- }
- function add_theme_menu_item()
- {
- add_menu_page("Theme Panel", "Theme Panel", "manage_options", "theme-panel", "theme_settings_page", null, 99);
- }
- add_action("admin_menu", "add_theme_menu_item");
- /*-----------------------------------------------------
- * Función de wordpress para mostrar que opciones
- del tema se van a administrar
- *----------------------------------------------------*/
- function display_search_header()
- {
- ?>
- <input type="checkbox" name="theme_layout" value="1" <?php checked(1, get_option('theme_layout'), true); ?> /> Si
- <?php
- }
- function display_facebook_element()
- {
- ?>
- <input type="text" name="facebook_url" id="facebook_url" value="<?php echo get_option('facebook_url'); ?>" style="width: 50%;" />
- <?php
- }
- function display_twitter_element()
- {
- ?>
- <input type="text" name="twitter_url" id="twitter_url" value="<?php echo get_option('twitter_url'); ?>" style="width: 50%;" />
- <?php
- }
- function display_google_plus_element()
- {
- ?>
- <input type="text" name="google_plus_url" id="google_plus_url" value="<?php echo get_option('google_plus_url'); ?>" style="width: 50%;" />
- <?php
- }
- function display_youtube_element()
- {
- ?>
- <input type="text" name="youtube_url" id="youtube_url" value="<?php echo get_option('youtube_url'); ?>" style="width: 50%;" />
- <?php
- }
- function display_pinterest_element()
- {
- ?>
- <input type="text" name="pinterest_url" id="pinterest_url" value="<?php echo get_option('pinterest_url'); ?>" style="width: 50%;" />
- <?php
- }
- function display_instagram_element()
- {
- ?>
- <input type="text" name="instagram_url" id="instagram_url" value="<?php echo get_option('instagram_url'); ?>" style="width: 50%;" />
- <?php
- }
- function display_linkedin_element()
- {
- ?>
- <input type="text" name="linkedin_url" id="linkedin_url" value="<?php echo get_option('linkedin_url'); ?>" style="width: 50%;" />
- <?php
- }
- function display_phone_whatsapp()
- {
- ?>
- <input type="text" name="phone_ws" id="phone_ws" value="<?php echo get_option('phone_ws'); ?>" style="width: 50%;" />
- <?php
- }
- function display_link_customize()
- {
- ?>
- <input type="text" name="customize_url_ws" id="customize_url_ws" value="<?php echo get_option('customize_url_ws'); ?>" style="width: 50%;" />
- <?php
- }
- function display_email_element()
- {
- ?>
- <input type="text" name="email_url" id="email_url" value="<?php echo get_option('email_url'); ?>" style="width: 50%;" />
- <?php
- }
- /*-----------------------------------------------------
- * Función de wordpress para administrar los derechos
- de autor y administrar el logo en el pie de pagina
- *----------------------------------------------------*/
- function display_copyright_element()
- {
- ?>
- <input type="text" name="copyright_text" id="copyright_text" value="<?php echo get_option('copyright_text'); ?>" style="width: 50%;" />
- <?php
- }
- function logo_setting()
- {
- $options = get_option('plugin_options');
- if($options=="")
- {
- echo "";
- }
- else
- {
- ?>
- <p><img src="<?php echo $options['logo']; ?>" alt="Logo" /></p>
- <?php
- }
- ?>
- <input type="file" name="logo" />
- <?php
- }
- function display_theme_panel_fields()
- {
- add_settings_field("theme_layout", "Desea desactivar el buscador del header ?", "display_search_header", "theme-options", "section");
- add_settings_field("facebook_url", "Facebook Profile Url", "display_facebook_element", "theme-options", "section");
- add_settings_field("twitter_url", "Twitter Profile Url", "display_twitter_element", "theme-options", "section");
- add_settings_field("google_plus_url", "Google Plus Profile Url", "display_google_plus_element", "theme-options", "section");
- add_settings_field("youtube_url", "Youtube Channel Url", "display_youtube_element", "theme-options", "section");
- add_settings_field("instagram_url", "Instagram Account", "display_instagram_element", "theme-options", "section");
- add_settings_field("pinterest_url", "Pinterest Profile Url", "display_pinterest_element", "theme-options", "section");
- add_settings_field("linkedin_url", "Linkedin Profile Url", "display_linkedin_element", "theme-options", "section");
- add_settings_field("email_url", "E-mail de la empresa", "display_email_element", "theme-options", "section");
- add_settings_field("phone_ws", "Whatsapp number", "display_phone_whatsapp", "theme-options", "section");
- add_settings_field("customize_url_ws", "Enlace de whatsapp", "display_link_customize", "theme-options", "section");
- add_settings_field("copyright_text", "Copyright Text", "display_copyright_element", "theme-options", "section");
- // add settings filed with callback test_logo_display.
- add_settings_field('logo', 'Logo:', 'logo_setting', "theme-options", 'section'); // LOGO
- add_settings_section("section", "Cabecera y Footer Social Media", null, "theme-options");
- register_setting("section", "theme_layout");
- register_setting("section", "facebook_url");
- register_setting("section", "twitter_url");
- register_setting("section", "google_plus_url");
- register_setting("section", "youtube_url");
- register_setting("section", "instagram_url");
- register_setting("section", "pinterest_url");
- register_setting("section", "linkedin_url");
- register_setting("section", "email_url");
- register_setting("section", "phone_ws");
- register_setting("section", "customize_url_ws");
- register_setting("section", "copyright_text");
- register_setting("section", 'logo');
- register_setting('section', 'plugin_options', 'validate_setting');
- }
- add_action("admin_init", "display_theme_panel_fields");
- function validate_setting($plugin_options)
- {
- $keys = array_keys($_FILES);
- $i = 0;
- foreach ( $_FILES as $image )
- {
- // if a files was upload
- if ($image['size'])
- {
- // if it is an image
- if ( preg_match('/(jpg|jpeg|png|gif)$/', $image['type']) ) {
- $override = array('test_form' => false);
- // save the file, and store an array, containing its location in $file
- $file = wp_handle_upload( $image, $override );
- $plugin_options[$keys[$i]] = $file['url'];
- }
- else
- {
- // Not an image.
- $options = get_option('plugin_options');
- $plugin_options[$keys[$i]] = $options[$logo];
- // Die and let the user know that they made a mistake.
- wp_die('No image was uploaded.');
- }
- }
- // Else, the user didn't upload a file.
- // Retain the image that's already on file.
- else
- {
- $options = get_option('plugin_options');
- $plugin_options[$keys[$i]] = $options[$keys[$i]];
- }
- $i++;
- }
- return $plugin_options;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement