Advertisement
lesdeveloper

Untitled

Oct 2nd, 2013
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 22.17 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Store our table name in $wpdb with correct prefix
  5.  */
  6. function st_register_table() {
  7.     global $wpdb;
  8.     $wpdb->st = "{$wpdb->prefix}st";
  9. } // end st_register_table
  10. add_action( 'init', 'st_register_table', 1 );
  11. add_action( 'switch_blog', 'st_register_table' );
  12.  
  13. /**
  14.  * Creating / Deleting Custom Database Table
  15.  */
  16.  
  17. function st_theme_activation() {
  18.     global $wpdb;
  19.     global $charset_collate;
  20.  
  21.     // Call this manually as we may have missed the init hook
  22.     st_register_table();
  23.  
  24.     if ( $wpdb->get_var('SHOW TABLES LIKE ' . $wpdb->st ) != $wpdb->st ) {
  25.         $query = "CREATE TABLE " . $wpdb->st . "(
  26.             option_id BIGINT(20) UNSIGNED AUTO_INCREMENT,
  27.             option_name VARCHAR(64),
  28.             option_value LONGTEXT,
  29.             autoload VARCHAR(20) DEFAULT 'yes',
  30.             PRIMARY KEY  (option_id) )";
  31.  
  32.             require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  33.             dbDelta($query);
  34.  
  35.             add_option( 'st_database_version', '1.0' );
  36.     }
  37. } // end st_theme_activation
  38. add_action( 'after_switch_theme', 'st_theme_activation' );
  39.  
  40.  
  41. function st_get_table_columns() {
  42.     return array(
  43.         'option_id' => '%d',
  44.         'option_name'   => '%s',
  45.         'option_value'  => '%s',
  46.         'autoload'  => '%s',
  47.     );
  48. } // end st_get_table_columns
  49.  
  50.  
  51. function st_theme_deactivation() {
  52.   global $wpdb;
  53.  
  54.   // Dropping Custom Database Table
  55.   $query = "DROP TABLE IF EXISTS {$wpdb->st}";
  56.   $wpdb->query($query);
  57.  
  58.   // Dropping option
  59.   delete_option( 'st_database_version' );
  60. } // end st_theme_deactivation
  61. add_action( 'switch_theme', 'st_theme_deactivation' );
  62.  
  63. /**
  64.  * Theme Options Page
  65.  */
  66. function stheme_menu() {
  67.  
  68.     $paged = add_theme_page(
  69.         's Theme',
  70.         's Theme',
  71.         'administrator',
  72.         'stheme_theme_options',
  73.         'stheme_theme_display'
  74.         );
  75.     add_action( 'admin_print_scripts-' . $paged, 'stheme_print_scripts' );
  76.     add_action( 'admin_print_styles-' . $paged, 'stheme_admin_scripts' );
  77.  
  78.     $stheme_options_page = add_menu_page(
  79.                 __('s Theme', 'stheme'),
  80.                 __('s Theme', 'stheme'),
  81.                 'administrator',
  82.                 'stheme_theme_menu',
  83.                 'stheme_theme_display',
  84.                 get_template_directory_uri().'/img/st-favicon.png'
  85.     );
  86.     add_action( 'admin_print_scripts-' . $stheme_options_page, 'stheme_print_scripts'  );
  87.  
  88.     $stheme_general_options_page = add_submenu_page(
  89.                     'stheme_theme_menu',
  90.                     __('General Options', 'stheme'),
  91.                     __('General Options', 'stheme'),
  92.                     'administrator',
  93.                     'stheme_theme_general_options',
  94.                     create_function(null, 'stheme_theme_display("general_options");')
  95.     );
  96.     add_action( 'admin_print_scripts-' . $stheme_general_options_page, 'stheme_print_scripts'  );
  97.                                        
  98.     add_submenu_page(
  99.         'stheme_theme_menu',
  100.         __('Homepage Options', 'stheme'),
  101.         __('Homepage Options', 'stheme'),
  102.         'administrator',
  103.         'stheme_homepage_options',
  104.         create_function(null, 'stheme_theme_display("homepage_options");' )
  105.     );
  106.  
  107.     add_submenu_page(
  108.         'stheme_theme_menu',
  109.         __('Footer Options', 'stheme'),
  110.         __('Footer Options', 'stheme'),
  111.         'administrator',
  112.         'stheme_footer_options',
  113.         create_function(null, 'stheme_theme_display("footer_options");')
  114.     );
  115.  
  116. } // end stheme_theme_menu
  117. add_action('admin_menu', 'stheme_menu');
  118.  
  119.  
  120.  
  121. /*==============================================================================================================*/
  122.  
  123. /**
  124.  * Renders a simple page to display for the theme menu defined above.
  125.  */
  126. function stheme_theme_display( $active_tab = null ) {
  127.     ?>
  128.         <!-- Create a header in the default WordPress 'wrap' container -->
  129.         <div class="wrap">         
  130.             <?php screen_icon( 'themes' ); ?>
  131.             <h2>s Theme Options</h2>
  132.             <?php settings_errors(); ?>
  133.  
  134.             <?php
  135.                 if ( isset($_GET['tab']) ) {
  136.                     $active_tab = $_GET['tab'];
  137.                 } else if ( $active_tab == 'homepage_options') {
  138.                     $active_tab = 'homepage_options';
  139.                 } else if ( $active_tab == 'footer_options') {
  140.                     $active_tab = 'footer_options';
  141.                 } else {
  142.                     $active_tab = 'general_options';
  143.                 } // end if else
  144.             ?>
  145.  
  146.             <h2 class="nav-tab-wrapper">
  147.                 <a href="?page=stheme_theme_options&tab=general_options" class="nav-tab <?php echo $active_tab == 'general_options' ? 'nav-tab-active' : '' ?>"><?php _e('General', 'stheme'); ?></a>
  148.                 <a href="?page=stheme_theme_options&tab=homepage_options" class="nav-tab <?php echo $active_tab == 'homepage_options' ? 'nav-tab-active' : '' ?>"><?php _e('Homepage', 'stheme'); ?></a>
  149.                 <a href="?page=stheme_theme_options&tab=footer_options" class="nav-tab <?php echo $active_tab == 'footer_options' ? 'nav-tab-active' : '' ?>"><?php _e('Footer', 'stheme'); ?></a>
  150.             </h2>
  151.  
  152.             <form method="POST" action="options.php">
  153.                 <?php
  154.                 if ( $active_tab == 'general_options' ) {
  155.                     settings_fields('stheme_theme_general_options');
  156.                     do_settings_sections('stheme_theme_general_options');
  157.                 } else if ( $active_tab == 'homepage_options' ) {
  158.                     settings_fields('stheme_homepage_options');
  159.                     do_settings_sections('stheme_homepage_options');
  160.                 } else if ( $active_tab == 'footer_options' ) {
  161.                     settings_fields('stheme_footer_options');
  162.                     do_settings_sections('stheme_footer_options');
  163.                 }
  164.                 submit_button();
  165.                 ?>             
  166.             </form>
  167.         </div> <!-- /.wrap -->
  168.     <?php
  169. } // end stheme_theme_display
  170.  
  171. /*==============================================================================================================*/
  172.  
  173. /**
  174.  * General Options
  175.  */
  176. // Set Options for General Options
  177. function stheme_default_options() {
  178.     $defaults = array(
  179.         'logo'      => 'test1',
  180.         'favicon'   => 'test2',
  181.         'top_nav'   => 'yes'
  182.     );
  183.     return apply_filters( 'stheme_default_options', $defaults );
  184. } // end stheme_default_options
  185.  
  186. /*==============================================================================================================*/
  187. // Set Options for Homepage Options
  188. function stheme_homepage_default_options() {
  189.     $defaults = array(
  190.         'show_homepage_blog'    => 'yes',
  191.         'show_sidebar'          => 'yes',
  192.         'show_footer'           => 'yes'
  193.     );
  194.     return apply_filters( 'stheme_homepage_default_options', $defaults );
  195. } // end stheme_homepage_default_options
  196.  
  197. /*==============================================================================================================*/
  198. // Set Options for Footer Options
  199. function stheme_footer_default_options() {
  200.     $defaults = array(
  201.         'footer_text_left'  => 'STheme',
  202.         'footer_text_right' => 'This is where you\'ll put the media icons.'
  203.     );
  204.     return apply_filters( 'stheme_footer_default_options', $defaults );
  205. } // end stheme_footer_default_options
  206.  
  207. /*==============================================================================================================*/
  208. // Initialization for General Options
  209. function stheme_initialize_theme_options() {
  210.     global $wpdb;
  211.     $data = array();
  212.  
  213.     // Collect the default values
  214.     $default = stheme_default_options();
  215.  
  216.     // Set default values
  217.     $data = wp_parse_args( $data, array(
  218.         'option_name'   => 'stheme_general_options',
  219.     ));
  220.  
  221.     // Initialise column format array
  222.     $column_formats = st_get_table_columns();
  223.  
  224.         $inserted = $wpdb->insert(
  225.             $wpdb->st,
  226.             array(
  227.                 'option_id'     => '',
  228.                 'option_name'   => 'stheme_theme_general_options',
  229.                 'option_value'  => apply_filters( 'stheme_default_options', stheme_default_options() ),
  230.                 'autoload'      => ''
  231.             ),
  232.             $column_formats
  233.         );
  234.  
  235.     // Register new options
  236.     add_settings_section(
  237.         'stheme_section',
  238.         __('General Options', 'stheme'),
  239.         'stheme_section_callback',
  240.         'stheme_theme_general_options'
  241.             );
  242.  
  243.     // Settings for logo
  244.     add_settings_field(
  245.         'stheme_logo',
  246.         __('sTheme Logo', 'stheme'),
  247.         'stheme_setting_logo_callback',
  248.         'stheme_theme_general_options',
  249.         'stheme_section'
  250.     );
  251.  
  252.     // Settings for Favicon
  253.     add_settings_field(
  254.         'stheme_favicon',
  255.         __('sTheme Favicon', 'stheme'),
  256.         'stheme_setting_favicon_callback',
  257.         'stheme_theme_general_options',
  258.         'stheme_section'
  259.     );
  260.  
  261.     // Setting for Top Navigation Position
  262.     add_settings_field(
  263.         'stheme_top_nav_position',
  264.         __('sTheme Top Navigation Position', 'stheme'),
  265.         'stheme_setting_top_nav_position_callback',
  266.         'stheme_theme_general_options',
  267.         'stheme_section'
  268.     );
  269.  
  270.     register_setting(
  271.         'stheme_theme_general_options',
  272.         'stheme_theme_general_options',
  273.         'stheme_theme_validate'
  274.     );
  275.  
  276. } // end stheme_initialize_theme_options
  277. add_action('admin_init', 'stheme_initialize_theme_options');
  278.  
  279. /*=============================================================================================================*/
  280.  
  281. // Initialization for Homepage Options
  282. function stheme_homepage_initialize_theme_options() {
  283.  
  284.     global $wpdb;
  285.  
  286.     // Initialise column format array
  287.     $column_formats = st_get_table_columns();
  288.  
  289.         $inserted = $wpdb->insert(
  290.             $wpdb->st,
  291.             array(
  292.                 'option_id'     => '',
  293.                 'option_name'   => 'stheme_homepage_options',
  294.                 'option_value'  => apply_filters( 'stheme_homepage_default_options', stheme_footer_default_options() ),
  295.                 'autoload'      => ''
  296.             ),
  297.             $column_formats
  298.         );
  299.  
  300.     add_settings_section(
  301.         'stheme_homepage_section',
  302.         __('Homepage Options', 'stheme'),
  303.         'stheme_homepage_callback',
  304.         'stheme_homepage_options'
  305.     );
  306.  
  307.     add_settings_field(
  308.         'stheme_show_homepage_blog',
  309.         __('Homepage Blog', 'stheme'),
  310.         'stheme_setting_show_blog_callback',
  311.         'stheme_homepage_options',
  312.         'stheme_homepage_section',
  313.         array(
  314.         __('Activate this to display the Homepage Blog.', 'stheme'),
  315.         )
  316.     );
  317.  
  318.     add_settings_field(
  319.         'stheme_show_sidebar',
  320.         __('Sidebar', 'stheme'),
  321.         'stheme_setting_show_sidebar_callback',
  322.         'stheme_homepage_options',
  323.         'stheme_homepage_section',
  324.         array(
  325.         __('Activate this to display the Page Sidebar.', 'stheme'),
  326.         )
  327.     );
  328.  
  329.     add_settings_field(
  330.         'stheme_show_masthead',
  331.         __('Masthead', 'stheme'),
  332.         'stheme_setting_show_masthead_callback',
  333.         'stheme_homepage_options',
  334.         'stheme_homepage_section',
  335.         array(
  336.         __('Activate this to display the Homepage Masthead.', 'stheme'),
  337.         )
  338.     );
  339.  
  340.     add_settings_field(
  341.         'stheme_show_featurette_f',
  342.         __('Featurette First', 'stheme'),
  343.         'stheme_setting_show_featurette_f_callback',
  344.         'stheme_homepage_options',
  345.         'stheme_homepage_section',
  346.         array(
  347.         __('Activate this to display the Homepage First Featurette.', 'stheme'),
  348.         )
  349.     );
  350.  
  351.     add_settings_field(
  352.         'stheme_show_featurette_s',
  353.         __('Featurette Second', 'stheme'),
  354.         'stheme_setting_show_featurette_s_callback',
  355.         'stheme_homepage_options',
  356.         'stheme_homepage_section',
  357.         array(
  358.         __('Activate this to display the Homepage Second Featurette', 'stheme'),
  359.         )
  360.     );
  361.  
  362.     register_setting(
  363.         'stheme_homepage_options',
  364.         'stheme_homepage_options'
  365.     );
  366.  
  367.  
  368. } // end stheme_homepage_initialize_theme_options
  369. add_action('admin_init', 'stheme_homepage_initialize_theme_options');
  370.  
  371. /*==============================================================================================================*/
  372.  
  373. // Initializations for Footer Options
  374. function stheme_footer_initialize_theme_options() {
  375.  
  376.     global $wpdb;
  377.  
  378.     // Initialise column format array
  379.     $column_formats = st_get_table_columns();
  380.  
  381.         $inserted = $wpdb->insert(
  382.             $wpdb->st,
  383.             array(
  384.                 'option_id'     => '',
  385.                 'option_name'   => 'stheme_footer_options',
  386.                 'option_value'  => apply_filters( 'stheme_footer_default_options', stheme_footer_default_options() ),
  387.                 'autoload'      => ''
  388.             ),
  389.             $column_formats
  390.         );
  391.  
  392.     add_settings_section(
  393.         'stheme_footer_section',
  394.         __('Footer Options', 'stheme'),
  395.         'stheme_footer_callback',
  396.         'stheme_footer_options'
  397.     );
  398.  
  399.     add_settings_field(
  400.         'stheme_footer_text_left',
  401.         __('Footer Text Left', 'stheme'),
  402.         'stheme_setting_footer_text_left_callback',
  403.         'stheme_footer_options',
  404.         'stheme_footer_section'
  405.     );
  406.  
  407.     add_settings_field(
  408.         'stheme_footer_text_right',
  409.         __('Footer Text Right', 'stheme'),
  410.         'stheme_setting_footer_text_right_callback',
  411.         'stheme_footer_options',
  412.         'stheme_footer_section'
  413.     );
  414.  
  415.     register_setting(
  416.         'stheme_footer_options',
  417.         'stheme_footer_options',
  418.         'stheme_theme_input_validate'
  419.     );
  420.  
  421.  
  422. } // end stheme_footer_initialize_theme_options
  423. add_action('admin_init', 'stheme_footer_initialize_theme_options');
  424.  
  425. /*==============================================================================================================*/
  426.  
  427. /**
  428.  * CallBacks
  429.  */
  430.  
  431. /**
  432. * This function provides a simple description for the General Options page.
  433. *
  434. * It's called from the 'stheme_initialize_theme_options' function by being passed as a parameter
  435. * in the add_settings_section function.
  436. */
  437. function stheme_section_callback() {
  438.     echo '<p>'.__( 'General settings for your s Theme.', 'stheme' ).'</p>';
  439. } // end stheme_general_options_callback
  440.  
  441.  
  442. /**
  443. * This function provides a simple description for the Homepage Options page.
  444. *
  445. * It's called from the 'stheme_homepage_initialize_theme_options' function by being passed as a parameter
  446. * in the add_settings_section function.
  447. */
  448. function stheme_homepage_callback() {
  449.     echo '<p>' . __( 'Select which areas of content you wish to display.', 'stheme' ) . '</p>';
  450. } // end stheme_general_callback
  451.  
  452. /**
  453. * This function provides a simple description for the Footer Options page.
  454. *
  455. * It's called from the 'stheme_footer_initialize_theme_options' function by being passed as a parameter
  456. * in the add_settings_section function.
  457. */
  458. function stheme_footer_callback() {
  459.     echo '<p>' . __( 'Type text for Footer.', 'stheme' ) . '</p>';
  460. } // end stheme_footer_callback
  461.  
  462. /*==============================================================================================================*/
  463.  
  464. /* General Logo Callback */
  465. function stheme_setting_logo_callback() {
  466.  
  467.     $options = get_option('stheme_theme_general_options');
  468.  
  469.     ?>
  470.    
  471.     <span class="upload">
  472.         <input type="text" id="stheme_logo" class="regular-text text-upload" name="stheme_theme_general_options[logo]" value="<?php echo esc_url( $options['logo'] ); ?>" />
  473.         <input type="button" class="button button-upload" value="Upload an image" /><br>
  474.         <img style="max-width: 300px display: block;" src="<?php echo esc_url($options['logo']); ?>" class="preview-upload" />
  475.     </span>
  476.  
  477.     <?php
  478.  
  479. } // end stheme_setting_logo_callback
  480.  
  481. /* General Favicon Callback */
  482. function stheme_setting_favicon_callback() {
  483.  
  484.     $options = get_option('stheme_theme_general_options');
  485.  
  486.     ?>
  487.  
  488.     <span class="upload">
  489.         <input type="text" id="stheme_favicon" class="regular-text text-upload" name="stheme_theme_general_options[favicon]" value="<?php echo esc_url( $options["favicon"] ); ?>" />
  490.         <input type="button" class="button button-upload" value="Upload an image"/></br>
  491.         <img style="max-width: 300px; display: block;" src="<?php echo esc_url( $options["favicon"] ); ?>" class="preview-upload" />
  492.     </span>
  493.  
  494.     <?php
  495.  
  496. } // end stheme_setting_logo_preview_callback
  497.  
  498. /* General Top Navigation Position */
  499. function stheme_setting_top_nav_position_callback() {
  500.  
  501.     $options = get_option('stheme_theme_general_options');
  502.  
  503.     $html = '<select id="stheme_top_nav_position" name="stheme_theme_general_options[stheme_top_nav_position]">';
  504.  
  505.     $html .= '<option value="default">' . __('Select Top Navigation Position..', 'stheme') . '</option>';
  506.  
  507.     $html .= '<option value="left"' . selected( $options['stheme_top_nav_position'], 'http://left', false) . '>' . __('Left Position', 'stheme') . '</option>';
  508.  
  509.     $html .= '<option value="bottom"' . selected( $options['stheme_top_nav_position'], 'http://bottom', false) . '>' . __('Bottom Position', 'stheme') . '</option>';
  510.  
  511.     $html .= '</select>';
  512.  
  513.     echo $html;
  514.  
  515. } // stheme_setting_top_nav_position_callback
  516.  
  517. /*==============================================================================================================*/
  518.  
  519. /* Homepage Show Blog Callback */
  520. function stheme_setting_show_blog_callback( $args ) {
  521.  
  522.     // First, we need to read the options selections
  523.     $options = get_option('stheme_homepage_options');
  524.  
  525.     // Next, we update the name attribute to access this element's ID in the context tof the display options array
  526.     // We also access the stheme_setting_show_blog_callback element of the options collection in the call to the checked() helper function
  527.     $html = '<input type="checkbox" id="stheme_show_homepage_blog" name="stheme_homepage_options[stheme_show_homepage_blog]" value="1" ' . checked( 1, isset( $options['stheme_show_homepage_blog'] ) ? $options['stheme_show_homepage_blog'] : 0, false ) . '/>';
  528.  
  529.     // Here, we'll take the first argument of the array and add it to a label next to the checkbox
  530.     $html .= '<label for="stheme_show_homepage_blog">&nbsp; ' . $args[0] . '</label>';
  531.  
  532.     // Display this to Browser
  533.     echo $html;
  534.  
  535. } // end stheme_setting_show_blog_callback
  536.  
  537. /* Homepage Show Page Sidebar Callback */
  538. function stheme_setting_show_sidebar_callback( $args ) {
  539.  
  540.     $options = get_option('stheme_homepage_options');
  541.  
  542.     $html = '<input type="checkbox" id="stheme_show_sidebar" name="stheme_homepage_options[stheme_show_sidebar]" value="1" ' . checked( 1, isset( $options['stheme_show_sidebar'] ) ? $options['stheme_show_sidebar'] : 0, false ) . '/>';
  543.  
  544.     $html .= '<label for="stheme_show_sidebar">&nbsp; ' . $args[0] . '</label>';
  545.  
  546.     echo $html;
  547.  
  548. } // end stheme_setting_show_sidebar_callback
  549.  
  550. /* Homepage Show Masthead Callback */
  551. function stheme_setting_show_masthead_callback( $args ) {
  552.  
  553.     $options = get_option('stheme_homepage_options');
  554.  
  555.     $html = '<input type="checkbox" id="stheme_show_masthead" name="stheme_homepage_options[stheme_show_masthead]" value="1" ' . checked( 1, isset( $options['stheme_show_masthead'] ) ? $options['stheme_show_masthead'] : 0, false ) . '/>';
  556.  
  557.     $html .= '<label for="stheme_show_masthead">&nbsp; ' . $args[0] . '</label>';
  558.  
  559.     echo $html;
  560.  
  561. } // end stheme_setting_show_masthead_callback
  562.  
  563. /* Homepage Show Featurette First Callback */
  564. function stheme_setting_show_featurette_f_callback( $args ) {
  565.  
  566.     $options = get_option('stheme_homepage_options');
  567.  
  568.     $html = '<input type="checkbox" id="stheme_setting_show_featurette_f_callback" name="stheme_homepage_options[stheme_setting_show_featurette_f_callback]" value="1" ' . checked( 1, isset( $options['stheme_setting_show_featurette_f_callback'] ) ? $options['stheme_setting_show_featurette_f_callback'] : 0, false ) . '/>';
  569.  
  570.     $html .= '<label for="stheme_setting_show_featurette_f_callback">&nbsp; ' . $args[0] . '</label>';
  571.  
  572.     echo $html;
  573.  
  574. } // end stheme_setting_show_featurette_f_callback
  575.  
  576. /* Homepage Show Featurette Second Callback */
  577. function stheme_setting_show_featurette_s_callback( $args ) {
  578.  
  579.     $options = get_option('stheme_homepage_options');
  580.  
  581.     $html = '<input type="checkbox" id="stheme_setting_show_featurette_s_callback" name="stheme_homepage_options[stheme_setting_show_featurette_s_callback]" value="1" ' . checked( 1, isset( $options['stheme_setting_show_featurette_s_callback'] ) ? $options['stheme_setting_show_featurette_s_callback'] : 0, false ) . '/>';
  582.  
  583.     $html .= '<label for="stheme_setting_show_featurette_s_callback">&nbsp; ' . $args[0] . '</label>';
  584.  
  585.     echo $html;
  586.  
  587. } // end stheme_setting_show_featurette_s_callback
  588.  
  589. /*===============================================================================================================*/
  590.  
  591. /* Footer Text Left Callback */
  592. function stheme_setting_footer_text_left_callback() {
  593.  
  594.     $options = get_option('stheme_footer_options');
  595.  
  596.     echo '<input type="text" id="stheme_footer_text_left" name="stheme_footer_options[stheme_footer_text_left]" value="' . $options['stheme_footer_text_left'] . '" />';
  597.  
  598.  
  599. } // end stheme_setting_footer_text_left_callback
  600.  
  601. /* Footer Text Right Callback */
  602. function stheme_setting_footer_text_right_callback() {
  603.  
  604.     $options = get_option('stheme_footer_options');
  605.  
  606.  
  607.     echo '<input type="text" id="stheme_footer_text_right" name="stheme_footer_options[stheme_footer_text_right]" value="' . $options['stheme_footer_text_right'] . '" />';
  608.  
  609.  
  610. } // end stheme_setting_footer_text_right_callback
  611.  
  612. /*==============================================================================================================*/
  613.  
  614. /* Add favico to site */
  615. function stheme_add_favicon() {
  616.  
  617.     $stheme_options = get_option( 'stheme_theme_general_options' );
  618.     $stheme_favicon = $stheme_options['favicon'];
  619.  
  620.     $favicon = $stheme_options['favicon'] != '' ? $stheme_favicon : get_template_directory_uri().'/img/st-favicon.png';
  621.  
  622.     ?>
  623.     <link rel="icon" type="image/png" href="<?php echo esc_url( $favicon ); ?>">
  624.     <?php
  625.  
  626. } // end stheme_add_favicon
  627. add_action('wp_head', 'stheme_add_favicon');
  628.  
  629. /**
  630.  * Validate
  631.  */
  632. function stheme_theme_validate( $values ) {
  633.  
  634.     foreach ( $values as $n => $v )
  635.         $values[$n] = esc_url( $v );
  636.     return $values;
  637.  
  638. } // end stheme_theme_validate
  639.  
  640. function stheme_theme_input_validate( $input ) {
  641.  
  642. // Create our array for storing the validated options
  643. $output = array();
  644.  
  645. // Loop through each of the incoming options
  646. foreach( $input as $key => $value ) {
  647.  
  648. // Check to see if the current option has a value. If so, process it.
  649. if( isset( $input[$key] ) ) {
  650.  
  651. // Strip all HTML and PHP tags and properly handle quoted strings
  652. $output[$key] = strip_tags( stripslashes( $input[ $key ] ) );
  653.  
  654. } // end if
  655.  
  656. } // end foreach
  657.  
  658. // Return the array processing any additional functions filtered by this action
  659. return apply_filters( 'stheme_theme_input_validate', $output, $input );
  660.  
  661. } // end stheme_theme_input_validate
  662.  
  663. function stheme_theme_social_validate( $input ) {
  664.  
  665.     // Define the array for the updated options
  666.     $output = array();
  667.  
  668.     // Loop through each of the options sanitizing the data
  669.     foreach( $input as $key => $val ) {
  670.  
  671.         if( isset ( $input[$key] ) ) {
  672.         $output[$key] = esc_url_raw( strip_tags( stripslashes( $input[$key] ) ) );
  673.         } // end if
  674.  
  675.     } // end foreach
  676.  
  677.     // Return the new collection
  678.     return apply_filters( 'sandbox_theme_sanitize_social_options', $output, $input );
  679.  
  680. } // end stheme_theme_social_validate
  681.  
  682. /**
  683.  * Embed Scripts
  684.  */
  685.  
  686. function stheme_print_scripts() {
  687.  
  688.     wp_enqueue_style( 'thickbox' );     // Stylesheet used by Thickbox
  689.     wp_enqueue_script( 'thickbox' );
  690.     wp_enqueue_script( 'media-upload' );
  691.     wp_enqueue_script( 'stheme-upload', get_template_directory_uri().'/st-options/js/st-upload.js', array('thickbox', 'media-upload') );
  692.  
  693. } // end stheme_print_scripts
  694.  
  695. function stheme_admin_scripts() {
  696.  
  697.     wp_enqueue_style( 'farbtastic' );
  698.     wp_enqueue_script( 'farbtastic' );
  699.     wp_enqueue_script( 'stheme_theme_style_options', get_template_directory_uri() . '/st-options/js/st-colourpick.js', array('farbtastic', 'jquery') );
  700.  
  701.  
  702. } // end stheme_admin_scripts
  703. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement