PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/boilerplate-admin/admin-menu.php

https://github.com/blackandblack/bb_boilerplate
PHP | 496 lines | 378 code | 56 blank | 62 comment | 94 complexity | 4ab812d9bdf7bda120cb93c74b5cc253 MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /*
  3. Begin Boilerplate Admin panel.
  4. */
  5. /* Define Boilerplate URI */
  6. define('BP_THEME_URL', get_template_directory_uri());
  7. /*
  8. There are essentially 5 sections to this:
  9. 1) Add "Boilerplate Admin" link to left-nav Admin Menu & callback function for clicking that menu link
  10. 2) Add Admin Page CSS if on the Admin Page
  11. 3) Add "Boilerplate Admin" Page options
  12. 4) Create functions to add above elements to pages
  13. 5) Add Boilerplate options to page as requested
  14. */
  15. /* 1) Add "Boilerplate Admin" link to left-nav Admin Menu & callback function for clicking that menu link */
  16. // Add option if in Admin Page
  17. if ( ! function_exists( 'create_boilerplate_admin_page' ) ):
  18. function create_boilerplate_admin_page() {
  19. add_theme_page('Boilerplate Admin', 'Boilerplate Admin', 'administrator', 'boilerplate-admin', 'build_boilerplate_admin_page');
  20. }
  21. add_action('admin_menu', 'create_boilerplate_admin_page');
  22. endif; // create_boilerplate_admin_page
  23. // You get this if you click the left-column "Boilerplate Admin" (added above)
  24. if ( ! function_exists( 'build_boilerplate_admin_page' ) ):
  25. function build_boilerplate_admin_page() {
  26. ?>
  27. <div id="boilerplate-options-wrap">
  28. <div class="icon32" id="icon-tools"><br /></div>
  29. <h2>Boilerplate Admin</h2>
  30. <p>So, there's actually a tremendous amount going on here. If you're not familiar with <a href="http://html5boilerplate.com/">HTML5 Boilerplate</a> or the <a href="http://starkerstheme.com/">Starkers theme</a> (upon which this theme is based) you should check them out.</p>
  31. <p>Choose below which options you want included in your site.</p>
  32. <p>The clumsiest part of this plug-in is dealing with the CSS files. Check the <a href="<?php echo BP_THEME_URL ?>/readme.txt">Read Me file</a> for details on how I suggest handling them.</p>
  33. <form method="post" action="options.php" enctype="multipart/form-data">
  34. <?php settings_fields('plugin_options'); /* very last function on this page... */ ?>
  35. <?php do_settings_sections('boilerplate-admin'); /* let's get started! */?>
  36. <p class="submit"><input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes'); ?>"></p>
  37. </form>
  38. </div>
  39. <?php
  40. }
  41. endif; // build_boilerplate_admin_page
  42. /* 2) Add Admin Page CSS if on the Admin Page */
  43. if ( ! function_exists( 'admin_register_head' ) ):
  44. function admin_register_head() {
  45. echo '<link rel="stylesheet" href="' .BP_THEME_URL. '/boilerplate-admin/admin-style.css">'.PHP_EOL;
  46. }
  47. add_action('admin_head', 'admin_register_head');
  48. endif; // admin_register_head
  49. /* 3) Add "Boilerplate Admin" Page options */
  50. // Register form elements
  51. if ( ! function_exists( 'register_and_build_fields' ) ):
  52. function register_and_build_fields() {
  53. register_setting('plugin_options', 'plugin_options', 'validate_setting');
  54. add_settings_section('main_section', '', 'section_cb', 'boilerplate-admin');
  55. add_settings_field('toolbar', 'IE6 Image Toolbar?:', 'toolbar_setting', 'boilerplate-admin', 'main_section');
  56. add_settings_field('google_chrome', 'IE-edge / Google Chrome?:', 'google_chrome_setting', 'boilerplate-admin', 'main_section');
  57. add_settings_field('google_verification', 'Google Verification?:', 'google_verification_setting', 'boilerplate-admin', 'main_section');
  58. add_settings_field('viewport', '<em><abbr title="iPhone, iTouch, iPad...">iThings</abbr></em> use full zoom?:', 'viewport_setting', 'boilerplate-admin', 'main_section');
  59. add_settings_field('favicon', 'Got Favicon?:', 'favicon_setting', 'boilerplate-admin', 'main_section');
  60. add_settings_field('favicon_ithing', 'Got <em><abbr title="iPhone, iTouch, iPad...">iThing</abbr></em> Favicon?', 'favicon_ithing_setting', 'boilerplate-admin', 'main_section');
  61. add_settings_field('ie_css', 'IE CSS?:', 'ie_css_setting', 'boilerplate-admin', 'main_section');
  62. add_settings_field('modernizr_js', 'Modernizr JS?:', 'modernizr_js_setting', 'boilerplate-admin', 'main_section');
  63. add_settings_field('respond_js', 'Respond JS?:', 'respond_js_setting', 'boilerplate-admin', 'main_section');
  64. add_settings_field('jquery_js', 'jQuery JS?:', 'jquery_js_setting', 'boilerplate-admin', 'main_section');
  65. add_settings_field('plugins_js', 'jQuery Plug-ins JS?:', 'plugins_js_setting', 'boilerplate-admin', 'main_section');
  66. add_settings_field('site_js', 'Site-specific JS?:', 'site_js_setting', 'boilerplate-admin', 'main_section');
  67. add_settings_field('cache_buster', 'Cache-Buster?:', 'cache_buster_setting', 'boilerplate-admin', 'main_section');
  68. }
  69. add_action('admin_init', 'register_and_build_fields');
  70. endif; // register_and_build_fields
  71. // Add Admin Page validation
  72. if ( ! function_exists( 'validate_setting' ) ):
  73. function validate_setting($plugin_options) {
  74. $keys = array_keys($_FILES);
  75. $i = 0;
  76. foreach ( $_FILES as $image ) {
  77. // if a files was upload
  78. if ($image['size']) {
  79. // if it is an image
  80. if ( preg_match('/(jpg|jpeg|png|gif)$/', $image['type']) ) {
  81. $override = array('test_form' => false);
  82. // save the file, and store an array, containing its location in $file
  83. $file = wp_handle_upload( $image, $override );
  84. $plugin_options[$keys[$i]] = $file['url'];
  85. } else {
  86. // Not an image.
  87. $options = get_option('plugin_options');
  88. $plugin_options[$keys[$i]] = $options[$logo];
  89. // Die and let the user know that they made a mistake.
  90. wp_die('No image was uploaded.');
  91. }
  92. } else { // else, the user didn't upload a file, retain the image that's already on file.
  93. $options = get_option('plugin_options');
  94. $plugin_options[$keys[$i]] = $options[$keys[$i]];
  95. }
  96. $i++;
  97. }
  98. return $plugin_options;
  99. }
  100. endif; // validate_setting
  101. // Add Admin Page options
  102. // in case you need it...
  103. if ( ! function_exists( 'section_cb' ) ):
  104. function section_cb() {}
  105. endif; // section_cb
  106. // callback fn for toolbar
  107. if ( ! function_exists( 'toolbar_setting' ) ):
  108. function toolbar_setting() {
  109. $options = get_option('plugin_options');
  110. $checked = (isset($options['toolbar']) && $options['toolbar']) ? 'checked="checked" ' : '';
  111. echo '<input class="check-field" type="checkbox" name="plugin_options[toolbar]" value="true" ' .$checked. '/>';
  112. echo '<p>Kill the IE6 Image Toolbar that appears when users hover over images on your site.</p>';
  113. echo '<p>Selecting this option will add the following code to the <code>&lt;head&gt;</code> of your pages:</p>';
  114. echo '<code>&lt;meta http-equiv="imagetoolbar" content="false"&gt;</code>';
  115. }
  116. endif; // toolbar_setting
  117. // callback fn for google_chrome
  118. if ( ! function_exists( 'google_chrome_setting' ) ):
  119. function google_chrome_setting() {
  120. $options = get_option('plugin_options');
  121. $checked = (isset($options['google_chrome']) && $options['google_chrome']) ? 'checked="checked" ' : '';
  122. echo '<input class="check-field" type="checkbox" name="plugin_options[google_chrome]" value="true" ' .$checked. '/>';
  123. echo '<p>Force the most-recent IE rendering engine or users with <a href="http://www.chromium.org/developers/how-tos/chrome-frame-getting-started">Google Chrome Frame</a> installed to see your site using Google Frame.</p>';
  124. echo '<p>Selecting this option will add the following code to the <code>&lt;head&gt;</code> of your pages:</p>';
  125. echo '<code>&lt;meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"&gt;</code>';
  126. }
  127. endif; // google_chrome_setting
  128. // callback fn for google_verification
  129. if ( ! function_exists( 'google_verification_setting' ) ):
  130. function google_verification_setting() {
  131. $options = get_option('plugin_options');
  132. $checked = (isset($options['google_verification']) && $options['google_verification'] && $options['google_verification_account'] && $options['google_verification_account'] !== 'XXXXXXXXX...') ? 'checked="checked" ' : '';
  133. $account = (isset($options['google_verification_account']) && $options['google_verification_account']) ? $options['google_verification_account'] : 'XXXXXXXXX...';
  134. $msg = ($account === 'XXXXXXXXX...') ? ', where </code>XXXXXXXXX...</code> will be replaced with the code you insert above' : '';
  135. echo '<input class="check-field" type="checkbox" name="plugin_options[google_verification]" value="true" ' .$checked. '/>';
  136. echo '<p>Add <a href="http://www.google.com/support/webmasters/bin/answer.py?answer=35179">Google Verificaton</a> code to the <code>&lt;head&gt;</code> of all your pages.</p>';
  137. echo '<p>To include Google Verificaton, select this option and include your Verificaton number here:<br />';
  138. echo '<input type="text" size="40" name="plugin_options[google_verification_account]" value="'.$account.'" onfocus="javascript:if(this.value===\'XXXXXXXXX...\'){this.select();}"></p>';
  139. echo '<p>Selecting this option will add the following code to the <code>&lt;head&gt;</code> of your pages'.$msg.'</p>';
  140. echo '<code>&lt;meta name="google-site-verification" content="'.$account.'"&gt;</code>';
  141. }
  142. endif; // google_verification_setting
  143. // callback fn for viewport
  144. if ( ! function_exists( 'viewport_setting' ) ):
  145. function viewport_setting() {
  146. $options = get_option('plugin_options');
  147. $checked = (isset($options['viewport']) && $options['viewport']) ? 'checked="checked" ' : '';
  148. echo '<input class="check-field" type="checkbox" name="plugin_options[viewport]" value="true" ' .$checked. '/>';
  149. echo '<p>Force <em><abbr title="iPhone, iTouch, iPad...">iThings</abbr></em> to <a href="http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html#//apple_ref/doc/uid/TP40006509-SW19">show site at full-zoom</a>, instead of trying to show the entire page.</p>';
  150. echo '<p>Selecting this option will add the following code to the <code>&lt;head&gt;</code> of your pages:</p>';
  151. echo '<code>&lt;meta name="viewport" content="width=device-width"&gt;</code>';
  152. }
  153. endif; // viewport_setting
  154. // callback fn for favicon
  155. if ( ! function_exists( 'favicon_setting' ) ):
  156. function favicon_setting() {
  157. $options = get_option('plugin_options');
  158. $checked = (isset($options['favicon']) && $options['favicon']) ? 'checked="checked" ' : '';
  159. echo '<input class="check-field" type="checkbox" name="plugin_options[favicon]" value="true" ' .$checked. '/>';
  160. echo '<p>If you plan to use a <a href="http://en.wikipedia.org/wiki/Favicon">favicon</a> for your site, place the "favicon.ico" file in the root directory of your site.</p>';
  161. echo '<p>If the file is in the right location, you don\'t really need to select this option, browsers will automatically look there and no additional code will be added to your pages.</p>';
  162. echo '<p>Selecting this option will add the following code to the <code>&lt;head&gt;</code> of your pages:</p>';
  163. echo '<code>&lt;link rel="shortcut icon" href="/favicon.ico"&gt;</code>';
  164. }
  165. endif; // favicon_setting
  166. // callback fn for favicon_ithing
  167. if ( ! function_exists( 'favicon_ithing_setting' ) ):
  168. function favicon_ithing_setting() {
  169. $options = get_option('plugin_options');
  170. $checked = (isset($options['favicon_ithing']) && $options['favicon_ithing']) ? 'checked="checked" ' : '';
  171. echo '<input class="check-field" type="checkbox" name="plugin_options[favicon_ithing]" value="true" ' .$checked. '/>';
  172. echo '<p>To allow <em><abbr title="iPhone, iTouch, iPad...">iThing</abbr></em> users to <a href="http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html">add an icon for your site to their Home screen</a>, place the "apple-touch-icon.png" file in the root directory of your site.</p>';
  173. echo '<p>If the file is in the right location, you don\'t really need to select this option, browsers will automatically look there and no additional code will be added to your pages.</p>';
  174. echo '<p>Selecting this option will add the following code to the <code>&lt;head&gt;</code> of your pages:</p>';
  175. echo '<code>&lt;link rel="apple-touch-icon" href="/apple-touch-icon.png"&gt;</code>';
  176. echo '<code>&lt;link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png"&gt;</code>';
  177. echo '<code>&lt;link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png"&gt;</code>';
  178. echo '<code>&lt;link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png"&gt;</code>';
  179. }
  180. endif; // favicon_ithing_setting
  181. // callback fn for ie_css
  182. if ( ! function_exists( 'ie_css_setting' ) ):
  183. function ie_css_setting() {
  184. $options = get_option('plugin_options');
  185. $checked = (isset($options['ie_css']) && $options['ie_css']) ? 'checked="checked" ' : '';
  186. echo '<input class="check-field" type="checkbox" name="plugin_options[ie_css]" value="true" ' .$checked. '/>';
  187. echo '<p>If you would like to add a IE-specific CSS file, Boilerplate provides a starter file located in:</p>';
  188. echo '<code>' .BP_THEME_URL. '/css/ie-starter.css</code>';
  189. echo '<p><strong>I recommend adding any custom IE-specific CSS to this file and either copying from the starter file or using an <code>@import</code> to add the starter file rather than editing the starter file itself. This will help to avoid your changes being overwritten during upgrades.</strong></p>';
  190. echo '<p><strong>And remember</strong>, you don\'t need IE-specific hacks if you activate the IE-Conditional <code>&lt;html&gt;</code> above, because you can target IE specifically by using the IE classes that are being added to <code>&lt;html&gt;</code>. Sweet!</p>';
  191. echo '<p>Selecting this option will add the following code to the <code>&lt;head&gt;</code> of your pages:</p>';
  192. echo '<code>&lt;!--[if IE ]&gt;&lt;link rel="stylesheet" href="' .BP_THEME_URL. '/css/ie.css"&gt;&lt;![endif]--&gt;</code>';
  193. }
  194. endif; // ie_css_setting
  195. // callback fn for modernizr_js
  196. if ( ! function_exists( 'modernizr_js_setting' ) ):
  197. function modernizr_js_setting() {
  198. $options = get_option('plugin_options');
  199. $checked = (isset($options['modernizr_js']) && $options['modernizr_js']) ? 'checked="checked" ' : '';
  200. echo '<input class="check-field" type="checkbox" name="plugin_options[modernizr_js]" value="true" ' .$checked. '/>';
  201. echo '<p><a href="http://modernizr.com/">Modernizr</a> is a JS library that appends classes to the <code>&lt;html&gt;</code> that indicate whether the user\'s browser is capable of handling advanced CSS, like "cssreflections" or "no-cssreflections". It\'s a really handy way to apply varying CSS techniques, depending on the user\'s browser\'s abilities, without resorting to CSS hacks.</p>';
  202. echo '<p>Selecting this option will add the following code to the <code>&lt;head&gt;</code> of your pages (note the lack of a version, when you\'re ready to upgrade, simply copy/paste the new version into the file below, and your site is ready to go!):</p>';
  203. echo '<code>&lt;script src="' .BP_THEME_URL. '/js/modernizr.js"&gt;&lt;/script&gt;</code>';
  204. echo '<p><strong>Note: If you do <em>not</em> include Modernizr, the IEShiv JS <em>will</em> be added to accommodate the HTML5 elements used in Boilerplate in weaker browsers:</strong></p>';
  205. echo '<code>&lt;!--[if lt IE 9]&gt;</code>';
  206. echo '<code> &lt;script src="//html5shiv.googlecode.com/svn/trunk/html5.js" onload="window.ieshiv=true;"&gt;&lt;/script&gt;</code>';
  207. echo '<code> &lt;script&gt;!window.ieshiv && document.write(unescape(\'%3Cscript src="' .BP_THEME_URL. '/js/ieshiv.js"%3E%3C/script%3E\'))&lt;/script&gt;</code>';
  208. echo '<code>&lt;![endif]--&gt;</code>';
  209. }
  210. endif; // modernizr_js_setting
  211. // callback fn for respond_js
  212. if ( ! function_exists( 'respond_js_setting' ) ):
  213. function respond_js_setting() {
  214. $options = get_option('plugin_options');
  215. $checked = (isset($options['respond_js']) && $options['respond_js']) ? 'checked="checked" ' : '';
  216. echo '<input class="check-field" type="checkbox" name="plugin_options[respond_js]" value="true" ' .$checked. '/>';
  217. echo '<p><a href="http://filamentgroup.com/lab/respondjs_fast_css3_media_queries_for_internet_explorer_6_8_and_more/">Respond.js</a> is a JS library that helps IE<=8 understand <code>@media</code> queries, specifically <code>min-width</code> and <code>max-width</code>, allowing you to more reliably implement <a href="http://www.alistapart.com/articles/responsive-web-design/">responsive design</a> across all browsers.</p>';
  218. echo '<p>Selecting this option will add the following code to the <code>&lt;head&gt;</code> of your pages (note the lack of a version, when you\'re ready to upgrade, simply copy/paste the new version into the file below, and your site is ready to go!):</p>';
  219. echo '<code>&lt;script src="' .BP_THEME_URL. '/js/respond.js"&gt;&lt;/script&gt;</code>';
  220. }
  221. endif; // respond_js_setting
  222. // callback fn for jquery_js
  223. if ( ! function_exists( 'jquery_js_setting' ) ):
  224. function jquery_js_setting() {
  225. $options = get_option('plugin_options');
  226. $checked = (isset($options['jquery_js']) && $options['jquery_js']) ? 'checked="checked" ' : '';
  227. $version = (isset($options['jquery_version']) && $options['jquery_version'] && $options['jquery_version'] !== '') ? $options['jquery_version'] : '1.7.1';
  228. $inhead = (isset($options['jquery_head']) && $options['jquery_head']) ? 'checked="checked" ' : '';
  229. echo '<input class="check-field" type="checkbox" name="plugin_options[jquery_js]" value="true" ' .$checked. '/>';
  230. echo '<p><a href="http://jquery.com/">jQuery</a> is a JS library that aids greatly in developing high-quality JavaScript quickly and efficiently.</p>';
  231. echo '<p>Selecting this option will add the following code to your pages just before the <code>&lt;/body&gt;</code>:</p>';
  232. echo '<code>&lt;script src="//ajax.googleapis.com/ajax/libs/jquery/'.$version.'/jquery.min.js">&lt;/script&gt;</code>';
  233. echo '<code>&lt;script&gt;!window.jQuery && document.write(unescape(\'%3Cscript src="'.BP_THEME_URL.'/js/jquery.js"%3E%3C/script%3E\'))&lt;/script&gt;</code>';
  234. echo '<p><input class="check-field" type="checkbox" name="plugin_options[jquery_head]" value="true" ' .$inhead. '/>';
  235. echo '<strong>Note: <a href="http://developer.yahoo.com/blogs/ydn/posts/2007/07/high_performanc_5/">Best-practices</a> recommend that you load JS as close to the <code>&lt;/body&gt;</code> as possible. If for some reason you would prefer jQuery and jQuery plug-ins to be in the <code>&lt;head&gt;</code>, please select this option.</strong></p>';
  236. echo '<p>The above code first tries to download jQuery from Google\'s CDN (which might be available via the user\'s browser cache). If this is not successful, it uses the theme\'s version.</p>';
  237. echo '<p><strong>Note: This plug-in tries to keep current with the most recent version of jQuery. If for some reason you would prefer to use another version, please indicate that version:</strong><br />';
  238. echo '<input type="text" size="6" name="plugin_options[jquery_version]" value="'.$version.'"> (<a href="http://code.google.com/apis/libraries/devguide.html#jquery">see all versions available via Google\'s CDN</a>)</p>';
  239. }
  240. endif; // jquery_js_setting
  241. // callback fn for plugins_js
  242. if ( ! function_exists( 'plugins_js_setting' ) ):
  243. function plugins_js_setting() {
  244. $options = get_option('plugin_options');
  245. $checked = (isset($options['plugins_js']) && $options['plugins_js']) ? 'checked="checked" ' : '';
  246. echo '<input class="check-field" type="checkbox" name="plugin_options[plugins_js]" value="true" ' .$checked. '/>';
  247. echo '<p>If you choose to use any <a href="http://plugins.jquery.com/">jQuery plug-ins</a>, I recommend downloading and concatenating them together in a single JS file, as below. This will <a href="http://developer.yahoo.com/performance/rules.html">reduce your site\'s HTTP Requests</a>, making your site a better experience.</p>';
  248. echo '<p>Selecting this option will add the following code to your pages just before the <code>&lt;/body&gt;</code>:</p>';
  249. echo '<code>&lt;script type=\'text/javascript\' src=\'' .BP_THEME_URL. '/js/plug-in.js?ver=x\'&gt;&lt;/script&gt;</code>';
  250. echo '<p>(The single quotes and no-longer-necessary attributes are from WP, would like to fix that... maybe next update...)</p>';
  251. echo '<p><strong>Note: If you do <em>not</em> include jQuery, this file will <em>not</em> be added to the page.</strong></p>';
  252. }
  253. endif; // plugins_js_setting
  254. // callback fn for site_js
  255. if ( ! function_exists( 'site_js_setting' ) ):
  256. function site_js_setting() {
  257. $options = get_option('plugin_options');
  258. $checked = (isset($options['site_js']) && $options['site_js']) ? 'checked="checked" ' : '';
  259. echo '<input class="check-field" type="checkbox" name="plugin_options[site_js]" value="true" ' .$checked. '/>';
  260. echo '<p>If you would like to add your own site JavaScript file, Boilerplate provides a starter file located in:</p>';
  261. echo '<code>' .BP_THEME_URL. '/js/script-starter.js</code>';
  262. echo '<p>Add what you want to that file and select this option.</p>';
  263. echo '<p>Selecting this option will add the following code to your pages just before the <code>&lt;/body&gt;</code>:</p>';
  264. echo '<code>&lt;script type=\'text/javascript\' src=\'' .BP_THEME_URL. '/js/script-starter.js?ver=x\'&gt;&lt;/script&gt;</code>';
  265. echo '<p>(The single quotes and no-longer-necessary attributes are from WP, would like to fix that... maybe next update...)</p>';
  266. }
  267. endif; // site_js_setting
  268. // callback fn for cache_buster
  269. if ( ! function_exists( 'cache_buster_setting' ) ):
  270. function cache_buster_setting() {
  271. $options = get_option('plugin_options');
  272. $checked = (isset($options['cache_buster']) && $options['cache_buster']) ? 'checked="checked" ' : '';
  273. $version = (isset($options['cache_buster_version']) && $options['cache_buster_version']) ? $options['cache_buster_version'] : '1';
  274. echo '<input class="check-field" type="checkbox" name="plugin_options[cache_buster]" value="true" ' .$checked. '/>';
  275. echo '<p>To force browsers to fetch a new version of a file, versus one it might already have cached, you can add a "cache buster" to the end of your CSS and JS files. ';
  276. echo 'To increment the cache buster version number, type something here:<br />';
  277. echo '<input type="text" size="4" name="plugin_options[cache_buster_version]" value="'.$version.'"></p>';
  278. echo '<p>Selecting this option will add the following code to the end of all of your CSS and JS file names on all of your pages:</p>';
  279. echo '<code>?ver='.$version.'</code>';
  280. }
  281. endif; // cache_buster_setting
  282. /* 4) Create functions to add above elements to pages */
  283. // $options['toolbar']
  284. if ( ! function_exists( 'add_toolbar' ) ):
  285. function add_toolbar() {
  286. echo '<meta http-equiv="imagetoolbar" content="false">'.PHP_EOL;
  287. }
  288. endif; // add_toolbar
  289. // $options['google_chrome']
  290. if ( ! function_exists( 'add_google_chrome' ) ):
  291. function add_google_chrome() {
  292. echo '<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">'.PHP_EOL;
  293. }
  294. endif; // add_google_chrome
  295. // $options['google_verification']
  296. if ( ! function_exists( 'add_google_verification' ) ):
  297. function add_google_verification() {
  298. $options = get_option('plugin_options');
  299. $account = $options['google_verification_account'];
  300. echo '<meta name="google-site-verification" content="'.$account.'">'.PHP_EOL;
  301. }
  302. endif; // add_google_verification
  303. // $options['viewport']
  304. if ( ! function_exists( 'add_viewport' ) ):
  305. function add_viewport() {
  306. echo '<meta name="viewport" content="width=device-width">'.PHP_EOL;
  307. }
  308. endif; // add_viewport
  309. // $options['favicon']
  310. if ( ! function_exists( 'add_favicon' ) ):
  311. function add_favicon() {
  312. echo '<link rel="shortcut icon" href="/favicon.ico">'.PHP_EOL;
  313. }
  314. endif; // add_favicon
  315. // $options['favicon_ithing']
  316. if ( ! function_exists( 'add_favicon_ithing' ) ):
  317. function add_favicon_ithing() {
  318. echo '<link rel="apple-touch-icon" href="/apple-touch-icon.png">'.PHP_EOL;
  319. echo '<link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png">'.PHP_EOL;
  320. echo '<link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png">'.PHP_EOL;
  321. echo '<link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png">'.PHP_EOL;
  322. }
  323. endif; // add_favicon_ithing
  324. // $options['ie_css'];
  325. if ( ! function_exists( 'add_ie_stylesheet' ) ):
  326. function add_ie_stylesheet() {
  327. $cache = cache_buster();
  328. echo '<!--[if IE ]><link rel="stylesheet" href="'.BP_THEME_URL.'/css/ie.css'.$cache.'"><![endif]-->'.PHP_EOL;
  329. }
  330. endif; // add_ie_stylesheet
  331. // $options['modernizr_js']
  332. if ( ! function_exists( 'add_modernizr_script' ) ):
  333. function add_modernizr_script() {
  334. $cache = cache_buster();
  335. wp_deregister_script( 'ieshiv' ); // get rid of IEShiv if it somehow got called too (IEShiv is included in Modernizr)
  336. wp_deregister_script( 'modernizr' ); // get rid of any native Modernizr
  337. echo '<script src="' .BP_THEME_URL. '/js/modernizr.js'.$cache.'"></script>'.PHP_EOL;
  338. }
  339. endif; // add_modernizr_script
  340. // $options['ieshiv_script']
  341. if ( ! function_exists( 'add_ieshiv_script' ) ):
  342. function add_ieshiv_script() {
  343. $cache = cache_buster();
  344. echo '<!--[if lt IE 9]>'.PHP_EOL;
  345. echo ' <script src="//html5shiv.googlecode.com/svn/trunk/html5.js" onload="window.ieshiv=true;"></script>'.PHP_EOL; // try getting from CDN
  346. echo ' <script>!window.ieshiv && document.write(unescape(\'%3Cscript src="' .BP_THEME_URL. '/js/ieshiv.js'.$cache.'"%3E%3C/script%3E\'))</script>'.PHP_EOL; // fallback to local if CDN fails
  347. echo '<![endif]-->'.PHP_EOL;
  348. }
  349. endif; // add_ieshiv_script
  350. // $options['respond_js']
  351. if ( ! function_exists( 'add_respond_script' ) ):
  352. function add_respond_script() {
  353. $cache = cache_buster();
  354. echo '<script src="' .BP_THEME_URL. '/js/respond.js'.$cache.'"></script>'.PHP_EOL;
  355. }
  356. endif; // add_respond_script
  357. // $options['jquery_js']
  358. if ( ! function_exists( 'add_jquery_script' ) ):
  359. function add_jquery_script() {
  360. $cache = cache_buster();
  361. $options = get_option('plugin_options');
  362. $version = ($options['jquery_version']) ? $options['jquery_version'] : '1.7.1';
  363. wp_deregister_script( 'jquery' ); // get rid of WP's jQuery
  364. echo '<script src="//ajax.googleapis.com/ajax/libs/jquery/'.$version.'/jquery.min.js"></script>'.PHP_EOL; // try getting from CDN
  365. echo '<script>window.jQuery || document.write(unescape(\'%3Cscript src="' .BP_THEME_URL. '/js/jquery.js'.$cache.'"%3E%3C/script%3E\'))</script>'.PHP_EOL; // fallback to local if CDN fails
  366. }
  367. endif; // add_jquery_script
  368. // $options['plugins_js']
  369. if ( ! function_exists( 'add_plugin_script' ) ):
  370. function add_plugin_script() {
  371. $cache = cache_buster();
  372. echo '<script src="' .BP_THEME_URL. '/js/plugins.js'.$cache.'"></script>'.PHP_EOL;
  373. }
  374. endif; // add_plugin_script
  375. // $options['site_js']
  376. if ( ! function_exists( 'add_site_script' ) ):
  377. function add_site_script() {
  378. $cache = cache_buster();
  379. echo '<script src="' .BP_THEME_URL. '/js/script.js'.$cache.'"></script>'.PHP_EOL;
  380. }
  381. endif; // add_site_script
  382. // $options['cache_buster']
  383. if ( ! function_exists( 'cache_buster' ) ):
  384. function cache_buster() {
  385. $options = get_option('plugin_options');
  386. return (isset($options['cache_buster']) && $options['cache_buster']) ? '?ver='.$options['cache_buster_version'] : '';
  387. }
  388. endif; // cache_buster
  389. /* 5) Add Boilerplate options to page as requested */
  390. if (!is_admin() ) {
  391. // get the options
  392. $options = get_option('plugin_options');
  393. // check if each option is set (meaning it exists) and check if it is true (meaning it was checked)
  394. if (isset($options['toolbar']) && $options['toolbar']) {
  395. // if yes to both, apply option
  396. add_action('wp_print_styles', 'add_toolbar');
  397. }
  398. if (isset($options['google_chrome']) && $options['google_chrome']) {
  399. add_action('wp_print_styles', 'add_google_chrome');
  400. }
  401. if (isset($options['google_verification']) && $options['google_verification'] && $options['google_verification_account'] && $options['google_verification_account'] !== 'XXXXXXXXX...') {
  402. add_action('wp_print_styles', 'add_google_verification');
  403. }
  404. if (isset($options['viewport']) && $options['viewport']) {
  405. add_action('wp_print_styles', 'add_viewport');
  406. }
  407. if (isset($options['favicon']) && $options['favicon']) {
  408. add_action('wp_print_styles', 'add_favicon');
  409. }
  410. if (isset($options['favicon_ithing']) && $options['favicon_ithing']) {
  411. add_action('wp_print_styles', 'add_favicon_ithing');
  412. }
  413. if (isset($options['modernizr_js']) && $options['modernizr_js']) {
  414. add_action('wp_print_styles', 'add_modernizr_script');
  415. } else {
  416. // if Modernizr isn't selected, add IEShiv inside an IE Conditional Comment
  417. add_action('wp_print_styles', 'add_ieshiv_script');
  418. }
  419. if (isset($options['respond_js']) && $options['respond_js']) {
  420. add_action('wp_print_styles', 'add_respond_script');
  421. }
  422. if (isset($options['ie_css']) && $options['ie_css']) {
  423. add_action('wp_print_styles', 'add_ie_stylesheet');
  424. }
  425. if (isset($options['jquery_js']) && $options['jquery_js'] && isset($options['jquery_version']) && $options['jquery_version'] && $options['jquery_version'] !== '') {
  426. // check if should be loaded in <head> or at end of <body>
  427. $hook = (isset($options['jquery_head']) && $options['jquery_head']) ? 'wp_print_styles' : 'wp_footer';
  428. add_action($hook, 'add_jquery_script');
  429. }
  430. // for jQuery plug-ins, make sure jQuery was also set
  431. if (isset($options['jquery_js']) && $options['jquery_js'] && isset($options['plugins_js']) && $options['plugins_js']) {
  432. // check if should be loaded in <head> or at end of <body>
  433. $hook = (isset($options['jquery_head']) && $options['jquery_head']) ? 'wp_print_styles' : 'wp_footer';
  434. add_action($hook, 'add_plugin_script');
  435. }
  436. if (isset($options['site_js']) && $options['site_js']) {
  437. add_action('wp_footer', 'add_site_script');
  438. }
  439. } // if (!is_admin() )
  440. ?>