Advertisement
Guest User

theme-option

a guest
Jul 11th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.66 KB | None | 0 0
  1. <?php
  2. //create custom admin menu's
  3. // add the main menu
  4.  add_action('admin_menu', 'my_theme_menu');
  5.  function my_theme_menu(){
  6.  
  7. // the settings
  8.  
  9. $page_title = "My Themes Admin";
  10.  
  11. $menu_title = "Theme Settings";
  12. /*
  13. * Please not that this changed in the latest wordpress
  14. * versions from a number to words for user capabilities.
  15. * This would of been 7 but now you should use 'administrator'.
  16. */
  17. $capability = 'administrator';
  18.  
  19. $menu_slug = "theme-settings";
  20.  
  21. $function = "main_theme_menu_plugin";
  22.  
  23. $icon_url = ""; // could be anything jpg, png, gif
  24.  
  25. $position = '5';
  26.  
  27. add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); // create the menu
  28.  
  29. }
  30.  
  31. wp_enqueue_script( 'jquery' );  //this code here  enables jquery
  32.  
  33. // Here we add the jQuery UI script to our theme header
  34.  
  35. wp_register_script( 'jquery-ui-script', plugins_url('/js/jquery-ui-1.8.16.custom.min.js', __FILE__)); //this part registers the new script
  36.  
  37. wp_enqueue_script( 'jquery-ui-script' ); //this part puts the script in to our page header
  38.  
  39. // Here we add the jQuery UI theme Css to our header
  40. $myThemeStyleUrl = plugins_url('/css/ui-lightness/jquery-ui-1.8.16.custom.css', __FILE__); //set the path to our css
  41.  
  42. wp_enqueue_style('jquery-ui-style', $myThemeStyleUrl,'1.0','screen'); // this puts the css in the header
  43.  
  44. // Here we add the code that enables the tabbed menu
  45. add_action('admin_head', 'enableTabMenu_plugin');
  46.  
  47. function enableTabMenu_plugin(){
  48.  ?>
  49.  
  50. <script type="text/javascript">
  51.  
  52. jQuery(function() {
  53.  
  54. jQuery( '#tabs' ).tabs();
  55.  
  56. });
  57.  
  58. </script>
  59.  
  60. <?php
  61.  
  62. }
  63.  
  64. function main_theme_menu_plugin() {
  65.  
  66. ?>
  67.  
  68. <?php
  69. // Social Settings Page
  70. function socialSettings(){
  71.  
  72. $social = '
  73. <div id="social-settings">' . settings_fields( 'ty-option-group' ) . '
  74. <h2>Social Settings</h2>
  75. <div id="social-wrapper"><form action="" method="post" name="socialform"><label for="facebook">Facebook: </label><input id="facebook" type="text" name="facebook" value="' .  get_option('ty-facebook') . '" /><a href="' . get_option('ty-facebook') .'"><img src="' .get_bloginfo('template_url') .'/images/social/facebook.png" alt="facebook" /></a>
  76.  
  77. <label for="twitter">Twitter: </label><input id="twitter" type="text" name="twitter" value="'. get_option('ty-twitter') .'" /><a href="' . get_option('ty-twitter') .'"><img src="'. get_bloginfo('template_url') .'/images/social/twitter.png" alt="twitter" /></a>
  78.  
  79. <label for="linkedin">LinkedIn: </label><input id="linkedin" type="text" name="linkedin" value="' . get_option('ty-linkedin') .'" /><a href="' . get_option('ty-linkedin') .'"><img src="'. get_bloginfo('template_url') .'/images/social/linkedin.png" alt="linkedin" /></a>
  80.  
  81. <label for="flickr">Flickr: </label><input id="flickr" type="text" name="flickr" value="'. get_option('ty-flickr') .'" /><a href="'. get_option('ty-flickr') .'"><img src="'. get_bloginfo('template_url') .'/images/social/flickr.png" alt="flickr" /></a>
  82.  
  83. <label for="skype">Skype: </label><input id="skype" type="text" name="skype" value="'. get_option('ty-skype') .'" /><a href="'. get_option('ty-skype') .'"><img src="'. get_bloginfo('template_url') .'/images/social/skype.png" alt="skype" /></a>
  84.  
  85. <input id="social-button" class="button-primary" style="margin-top: 10px;" type="button" value="Save Social" />
  86. </form></div>
  87. </div>
  88. ';
  89.  
  90. return $social;
  91. }
  92.  
  93. // Save Social Settings Data
  94.  add_action('wp_ajax_slider_my_action', 'saveSocialSettings'); //ajax callback
  95. function saveSocialSettings() {
  96.     // set default values
  97.     if(get_option('ty-facebook') == ""){
  98.  
  99.         update_option( 'ty-facebook', 'Facebook URL...');
  100.  
  101.     }
  102.  
  103.     if(get_option('ty-twitter') == ""){
  104.  
  105.         update_option('ty-twitter', 'Twitter URL...');
  106.  
  107.     }
  108.  
  109.     if(get_option('ty-linkedin') == ''){
  110.  
  111.         update_option('ty-linkedin', 'Linkedin URL...');
  112.  
  113.     }
  114.  
  115.     if(get_option('ty-flickr') == ''){
  116.  
  117.         update_option('ty-flickr', 'Flickr URL...');
  118.  
  119.     }
  120.  
  121.     if(get_option('ty-skype') == ''){
  122.  
  123.         update_option('ty-skype', 'Skype URL...');
  124.  
  125.     }
  126.  
  127.     // Save data to option fields
  128.     if(! empty($_POST)){
  129.  
  130.         $facebook = $_POST['ty_facebook'];
  131.         $twitter = $_POST['ty_twitter'];
  132.         $linkedin = $_POST['ty_linkedin'];
  133.         $flickr = $_POST['ty_flickr'];
  134.         $skype = $_POST['ty_skype'];
  135.  
  136.         // save the form values to the option fields
  137.         update_option( 'ty-facebook', $facebook);
  138.         update_option( 'ty-twitter', $twitter);
  139.         update_option( 'ty-linkedin', $linkedin);
  140.         update_option( 'ty-flickr', $flickr);
  141.         update_option( 'ty-skype', $skype);
  142.  
  143.     }
  144.  
  145. }
  146. }
  147.  
  148. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement