/google-font-fix-options.php

  1. <?php 
  2. add_action('admin_menu', 'gff_option_admin_menu'); 
  3. function gff_option_admin_menu() { 
  4. add_options_page( 
  5. 'Google Font Fix Options',  
  6. 'Google Font Fix',  
  7. 'manage_options',  
  8. 'google-font-fix',  
  9. 'gff_option_page' 
  10. ); 
  11.  
  12. add_action('init', 'gff_load_plugin_textdomain'); 
  13. function gff_load_plugin_textdomain() { 
  14. $domain = 'google-font-fix'; 
  15. $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); 
  16.  
  17. load_textdomain($domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo'); 
  18. load_plugin_textdomain($domain, FALSE, basename(dirname( __FILE__ )) . '/languages/'); 
  19.  
  20. /** 
  21. * User Settings. 
  22. */ 
  23. $google_service = get_option('google_service'); 
  24. $gravatar_service = get_option('gravatar_service'); 
  25.  
  26. /** 
  27. * Variables 
  28. * Assignments are for default value - change on admin page. 
  29. */ 
  30. $gff_options = array( 
  31. 'google_service' => !empty($google_service) ? $google_service : 'lug.ustc.edu.cn',  
  32. 'gravatar_service' => !empty($gravatar_service) ? $gravatar_service : 'https://secure.gravatar.com/avatar',  
  33. ); 
  34.  
  35. /** 
  36. * Option Page 
  37. */ 
  38. function gff_option_page() { 
  39. global $gff_options; 
  40.  
  41. $google_service = $_POST['google-service']; 
  42. $gravatar_service = $_POST['gravatar-service']; 
  43. if ( isset($google_service) ) { 
  44. update_option('google_service', $google_service); 
  45. $gff_options['google_service'] = $google_service; 
  46. if ( isset($gravatar_service) ) { 
  47. update_option('gravatar_service', $gravatar_service); 
  48. $gff_options['gravatar_service'] = $gravatar_service; 
  49. ?> 
  50. <div class="wrap"> 
  51. <h1><?php echo __('Google Font Fix Options', 'google-font-fix'); ?></h1> 
  52. <form method="POST" action="" novalidate="novalidate"> 
  53. <h2><?php echo __('Google Service'); ?></h2> 
  54. <table class="form-table"> 
  55. <tr> 
  56. <th scope="row"> 
  57. <label for="google-service"><?php echo __('Service Provider', 'google-font-fix'); ?></label> 
  58. </th> 
  59. <td> 
  60. <select name="google-service" id="google-service"> 
  61. <?php if ( !is_ssl() ): ?> 
  62. <option value="useso.com"><?php echo __('Qihoo 360 Technology Co. Ltd.', 'google-font-fix'); ?></option> 
  63. <?php endif; ?> 
  64. <option value="lug.ustc.edu.cn"><?php echo __('University of Science and Technology of China', 'google-font-fix'); ?></option> 
  65. <option value="css.network"><?php echo __('CSS.NET', 'google-font-fix'); ?></option> 
  66. </select> 
  67. </td> 
  68. </tr> 
  69. </table> <!-- .form-table --> 
  70. <h2><?php echo __('Gravatar Service'); ?></h2> 
  71. <table class="form-table"> 
  72. <tr> 
  73. <th scope="row"> 
  74. <label for="gravatar-service"><?php echo __('Service Provider', 'google-font-fix'); ?></label> 
  75. </th> 
  76. <td> 
  77. <select name="gravatar-service" id="gravatar-service"> 
  78. <option value="https://secure.gravatar.com/avatar"><?php echo __('Gravatar Secure Connection', 'google-font-fix'); ?></option> 
  79. <option value="//cn.gravatar.com/avatar"><?php echo __('Gravatar in China', 'google-font-fix'); ?></option> 
  80. <option value="//gravatar.css.network/avatar"><?php echo __('CSS.NET', 'google-font-fix'); ?></option> 
  81. <option value="//cdn.v2ex.com/gravatar"><?php echo __('V2EX', 'google-font-fix'); ?></option> 
  82. </select> 
  83. </td> 
  84. </tr> 
  85. </table> <!-- .form-table --> 
  86. <?php submit_button(); ?> 
  87. </form> 
  88. </div> <!-- .wrap --> 
  89. <script type="text/javascript"> 
  90. (function($) { 
  91. $(function() { 
  92. $('#google-service').val('<?php echo $gff_options['google_service']; ?>'); 
  93. $('#gravatar-service').val('<?php echo $gff_options['gravatar_service']; ?>'); 
  94. }); 
  95. })(jQuery); 
  96. </script> 
  97. <?php 
.