PageRenderTime 63ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/functions.php

https://github.com/scottsweb/null
PHP | 879 lines | 378 code | 207 blank | 294 comment | 86 complexity | 379cdfacd79106fa362c584b398fd887 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. 8888888888888888888888888888888888888888
  4. 8888888888888888888888888888888888888888
  5. 8888888888888888888888888888888888888888
  6. 8888888888888888888888888888888888888888
  7. 8888888888888888888888888888888888888888
  8. 8888888888888888888888888888888888888888
  9. 888888888$1||120888888110811081108888888
  10. 88888880; ;;' '288880 20 20 28888888
  11. 88888881 '08881 08880 20 20 28888888
  12. 8888888; :88882 08880 20 20 28888888
  13. 8888888| :88882 08880 20 20 28888888
  14. 8888888; :88880' ;2$2; 00 20 28888888
  15. 88888881 ;8888801' '|080: $0' $8888888
  16. 8888888800888888880008888800880088888888
  17. 8888888888888888888888888888888888888888
  18. 8888888888888888888888888888888888888888
  19. 8888888888888888888888888888888888888888
  20. 8888888888888888888888888888888888888888
  21. 8888888888888888888888888888888888888888
  22. 8888888888888888888888888888888888888888
  23. Notes:
  24. ----------------------------------------
  25. future
  26. to-do: http://gridster.net/ - build virtual templates via UI (fork coming soon)
  27. - http://jsfiddle.net/maxgalbu/UfyjW/
  28. - https://github.com/ducksboard/gridster.js/issues/69
  29. - http://headwaythemes.com/features/headway-grid/
  30. - http://www.webresourcesdepot.com/grid-builder-drag-n-drop-html-grid-generator/
  31. - http://app.responsify.it/
  32. - https://www.scrollkit.com/
  33. - http://mcpants.github.io/jquery.shapeshift/index.html
  34. to-do: bundle xml file import for WordPress (use wordpress import/export feature) - theme unit test installer?
  35. to-do: perhaps move to: http://wordpress.org/extend/plugins/option-tree/ for options?
  36. - to-do: pre-configured site settings (so buddypress, multi site, multi author, client etc)
  37. to-do: a second take on responsive tables -> http://filamentgroup.com/examples/rwd-table-patterns/ / http://consulenza-web.com/jquery/MediaTable/?
  38. - http://css-tricks.com/responsive-data-table-roundup/ - more options for responsive tables
  39. to-do: font effects? https://developers.google.com/webfonts/docs/getting_started#Effects - shortcode?
  40. to-do: explore the gantry-framework http://www.gantry-framework.org/download
  41. to-do: ability to disable built in post types and taxonomies - http://core.trac.wordpress.org/ticket/14761
  42. to-do: move to an existing CSS/LESS framework?
  43. - clean up gravity forms less and test with some forms (not using GF much)
  44. - a beautiful, minimal, responsive design (old scott.ee site?)
  45. - http://typeplate.com/
  46. - https://github.com/clearleft/clearless
  47. - http://twitter.github.com/bootstrap/ also http://bootswatch.com/
  48. - http://responsablecss.com/ - baseline is not calculated
  49. - http://mateuszkocz.github.com/3l - seo helper is rather nifty
  50. - http://compass-style.org/reference/compass/css3/ - less mixin ideas from compass
  51. - https://github.com/dancrew32/lesslib/blob/master/mixins.less - less mixins
  52. - http://kushagragour.in/lab/hint/ - css tooltips
  53. - http://necolas.github.com/normalize.css/ - use normalize instead of full reset
  54. - investigate this grid system: https://t.co/GaP9MWsZtS
  55. - http://coding.smashingmagazine.com/2013/03/08/tips-tricks-print-style-sheets/ - improve print styles
  56. - http://gumbyframework.com/
  57. - http://www.99lime.com/elements/
  58. - http://www.formee.org/
  59. - http://simplegrid.info/
  60. - http://www.responsivegridsystem.com/
  61. - http://getpreboot.com/
  62. - http://www.fitgrd.com/
  63. - http://www.getuikit.com/
  64. - https://github.com/mojotech/jeet
  65. to-do: replace modernizr? http://conditionizr.com/
  66. to-do: live bind shortcode JS for instant search plugin compatibility - livequery? or .on
  67. to-do: compatibilty with live edit - http://wordpress.org/extend/plugins/live-edit/
  68. - if (function_exists("live_edit")) { live_edit(apply_filters('null_live_edit_loop', 'post_title, post_excerpt')); }
  69. to-do: HiDPI/vector icon post type icons - ready for 3.7 and MP6
  70. to-do: create an editable 404?
  71. to-do: feature tooltips restricted by user type (same code as with admin bar)
  72. to-do: improve gallery shortcode - css and filters tweaks - see chailey - make the built in gallery useful in more projects //http://wordpress.stackexchange.com/questions/4343/how-to-customise-the-output-of-the-wp-image-gallery-shortcode-from-a-plugin
  73. to-do: remove htaccess gubbins in favour of : https://github.com/roots/wp-h5bp-htaccess/
  74. ongoing
  75. to-do: update language files
  76. to-do: update modernizr
  77. to-do: update ligature symbols
  78. to-do: update less compiler 0.3.9+ / less plugin and grid - hopefully will work again and provide css compression
  79. to-do: update acf
  80. to-do: test against the theme guide: http://developer.wordpress.com/themes/
  81. to-do: theme options framework
  82. soon
  83. to-do: cache
  84. - (transients) null_get_extensions?
  85. - cache any wp-query and custom query?
  86. to-do: filter folder locations for extensions (a plugin could register extension folders?)
  87. to-do: Turn on certain extensions by default (child theme ships with X,Y,Z on)
  88. to-do: improve nav walker to provide better classes and support for other attributes
  89. to-do: issue - all templates that exist in the parent theme are a pain - if i just want index.php in child theme I have to overwrite category, tag etc etc - move all these to null child?
  90. - to-do: style and code for various post format types (chat, video, quote etc)
  91. - to-do: home.php
  92. to-do: Performance for htaccess? http://wp.tutsplus.com/tutorials/hosting/optimizing-wordpress-loading-speed-with-header-php-htaccess/
  93. to-do: please make sure your htaccess is writable notice on activation?
  94. to-do: navigation fix for cpt - see MHP
  95. to-do: remove more polyfills
  96. - webp images? - http://webpjs.appspot.com/ - https://developers.google.com/speed/webp/
  97. - One tool based on jQuery and modernizr - http://afarkas.github.io/webshim/demos/index.html
  98. - http://elclanrs.github.io/jq-idealforms/
  99. - https://github.com/louisremi/jquery-smartresize
  100. to-do: customise: https://github.com/devinsays/options-framework-theme/commit/476b24bd24b1f6392a793122e47366a4d3cd9eef
  101. to-do: https://github.com/mboynes/super-cpt
  102. to-do: beef up our mixins http://lesselements.com/ - https://github.com/drublic/less-mixins
  103. to-do: update IE8 pinned info http://www.buildmypinnedsite.com/en
  104. to-do: option to remove http://aahacreative.com/2013/08/05/remove-jquery-migrate-wordpress-36/
  105. to-do: http://wptheming.com/2013/11/optimizing-responsive-layouts/
  106. to-do: http://lessphp.gpeasy.com/ - move to this?
  107. */
  108. // load the options framework
  109. if (!function_exists( 'optionsframework_init' )) {
  110. define('OPTIONS_FRAMEWORK', get_template_directory() . '/assets/inc/options-framework/');
  111. define('OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/assets/inc/options-framework/');
  112. load_template(OPTIONS_FRAMEWORK . 'options-framework.php');
  113. load_template(get_template_directory() . '/options.php'); // temporary fix for options framework & theme customiser http://wptheming.com/2012/07/options-framework-theme-customizer/
  114. }
  115. // set PHP timezone from WordPress settings
  116. if ($timezone = get_option('timezone_string')) date_default_timezone_set($timezone);
  117. // force WordPress rewrite if option set
  118. if (of_get_option('force_rewrite', '0')) add_filter('got_rewrite', '__return_true');
  119. // parse template info from style.css - version number
  120. $theme_data = wp_get_theme();
  121. define('NULL_VERSION', $theme_data['Version']);
  122. // get the theme name from the stylesheet (lowercase and without spaces)
  123. $themename = $theme_data['Name'];
  124. $themename = preg_replace("/\W/", "", strtolower($themename));
  125. define('NULL_OPTION_NAME', $themename);
  126. // cache bust based on options settings and file gen time of main css - filterable for child themes to add different css filemtime
  127. $type = (of_get_option('disable_less', '1') ? 'css' : 'less');
  128. $cachefiles = intval(filemtime(get_template_directory() . '/assets/'.$type.'/screen.'.$type));
  129. $cacheoptions = md5(serialize(get_option(NULL_OPTION_NAME, array('0' => '1'))));
  130. $cacheoptions = intval($cacheoptions);
  131. $cachebust = apply_filters('null_cache_bust', abs(intval($cacheoptions+$cachefiles)));
  132. define('NULL_CACHE_BUST', $cachebust);
  133. // load activation code
  134. locate_template('/assets/inc/activation.php', true, true);
  135. // deprecated code - do not rely on code in this file
  136. load_template(get_template_directory() . '/assets/inc/deprecated.php');
  137. // compatibility - work nicely with other popular plugins
  138. load_template(get_template_directory() . '/assets/inc/compatibility.php');
  139. // email
  140. load_template(get_template_directory() . '/assets/inc/email.php');
  141. // custom post types
  142. load_template(get_template_directory() . '/assets/inc/post-types.php');
  143. // widgets and sidebars
  144. load_template(get_template_directory() . '/assets/inc/widgets.php');
  145. // cron
  146. load_template(get_template_directory() . '/assets/inc/cron.php');
  147. // shortcodes
  148. load_template(get_template_directory() . '/assets/inc/shortcodes.php');
  149. // breadcrumbs - http://wordpress.org/extend/plugins/breadcrumb-trail/
  150. if (!is_admin()) { locate_template('/assets/inc/breadcrumbs.php', true, true); }
  151. // load htaccess code, rewrites etc
  152. if (is_admin()) { locate_template('/assets/inc/htaccess.php', true, true); }
  153. // only load in admin functions in admin interface
  154. if (is_admin()) { locate_template('/assets/inc/admin.php', true, true); }
  155. // load update code
  156. if (is_admin()) { load_template(get_template_directory() . '/assets/inc/update.php'); }
  157. // only load front end functions for site
  158. if (!is_admin()) { locate_template('/assets/inc/theme.php', true, true); }
  159. // load theme hook alliance - https://github.com/zamoose/themehookalliance
  160. load_template(get_template_directory() . '/assets/inc/thahooks.php');
  161. // set content width - see: http://toggl.es/wEBCFs - largely irrelevant with responsive sites.. set it to the maximum possible width
  162. if (!isset($content_width)) $content_width = apply_filters('null_content_width', 656);
  163. /***************************************************************
  164. * Maintenance Mode
  165. * Take the front end of the site down for users that are not logged in and cannot manage optionsframework
  166. ***************************************************************/
  167. add_action('template_redirect', 'null_maintenance_mode');
  168. function null_maintenance_mode() {
  169. if (!is_user_logged_in() && !current_user_can('edit_theme_options') && of_get_option('maintenance_mode', '0')) {
  170. header('Retry-After: 600'); // 600 seconds/10 minutes
  171. wp_die(__('Website is down for maintenance.', 'null'), get_bloginfo('name').' | '.__('Maintenance (503)', 'null'), array('response' => 503));
  172. }
  173. }
  174. /***************************************************************
  175. * Functions null_admin_bar_updates
  176. * Remove the updates notification from the admin bar for non admins
  177. ***************************************************************/
  178. add_action('wp_before_admin_bar_render', 'null_admin_bar_updates', 25);
  179. function null_admin_bar_updates() {
  180. global $wp_admin_bar;
  181. if ((!current_user_can('update_plugins')) && (of_get_option('disable_updates', '1'))) {
  182. $wp_admin_bar->remove_menu('updates');
  183. }
  184. }
  185. /***************************************************************
  186. * Function null_howdy
  187. * Change Howdy? in the admin bar
  188. ***************************************************************/
  189. add_filter('gettext', 'null_howdy', 10, 2 );
  190. function null_howdy($translation, $original) {
  191. if ($howdy = of_get_option('howdy')) {
  192. if ('Howdy, %1$s' == $original) {
  193. return $howdy.' %1$s';
  194. }
  195. }
  196. return $translation;
  197. }
  198. /***************************************************************
  199. * Function null_setup
  200. * Setup theme, languages, enable post thumbnail support & custom menus etc
  201. ***************************************************************/
  202. add_action('after_setup_theme','null_setup');
  203. function null_setup() {
  204. // load language files for null framework
  205. load_theme_textdomain('null', get_template_directory() . '/assets/languages');
  206. // add support for custom header if setup
  207. if (of_get_option('custom_header', '0')) {
  208. add_theme_support('custom-header');
  209. }
  210. // add support for custom backgrounds if setup
  211. if (of_get_option('custom_background', '0')) {
  212. add_theme_support('custom-background');
  213. }
  214. // post-formats
  215. if (of_get_option('post_formats', '0')) {
  216. $formats = of_get_option('post_format_types', array());
  217. $supported = array();
  218. foreach ($formats as $key => $value) {
  219. if ($value == 1) $supported[] = $key;
  220. }
  221. add_theme_support('post-formats', $supported);
  222. }
  223. // add feed links for comments and posts to <head>
  224. add_theme_support('automatic-feed-links');
  225. // setup thumbnail support
  226. add_theme_support( 'post-thumbnails' );
  227. // html5 all the things
  228. add_theme_support( 'html5', array(
  229. 'comment-list',
  230. 'comment-form',
  231. 'search-form',
  232. 'gallery',
  233. 'captions'
  234. ) );
  235. // add theme hook alliance support (https://github.com/zamoose/themehookalliance) - filterable by child theme
  236. add_theme_support('tha_hooks', apply_filters('null_tha_hooks', array('body','head','header','content','entry','comments','sidebar','footer')));
  237. // set defualt thumbnail size: the_post_thumbnail();
  238. set_post_thumbnail_size( 150, 150, true );
  239. // custom hook to easily register more image sizes
  240. do_action('null_register_image_size');
  241. // custom menu support
  242. add_theme_support('menus');
  243. // register navigation menus for this theme
  244. register_nav_menus(apply_filters('null_register_menu', array(
  245. 'navigation' => __('Navigation', 'null'),
  246. 'footer' => __('Footer', 'null')
  247. )
  248. ));
  249. }
  250. // load php less parser if enabled
  251. if (!of_get_option('disable_less', '1')) { locate_template('/assets/inc/less.php', true, true); }
  252. /***************************************************************
  253. * Function null_less_vars
  254. * Parse theme options into less for use in stylesheets
  255. ***************************************************************/
  256. if (!of_get_option('disable_less', '0')) {
  257. add_filter('less_vars', 'null_less_vars', 10, 2 );
  258. }
  259. function null_less_vars($vars, $handle) {
  260. global $pagenow, $content_width;
  261. // $handle is a reference to the handle used with wp_enqueue_style()
  262. $vars['primarycol'] = of_get_option('primary_colour', '#141414');
  263. $vars['bodycol'] = of_get_option('body_colour', '#141414');
  264. $vars['linkcol'] = of_get_option('link_colour', '#0000EE');
  265. $vars['linkhovercol'] = of_get_option('link_hover_colour', '#551A8B');
  266. $vars['backgroundimage'] = of_get_option('background_image', get_template_directory_uri().'/assets/images/placeholder.png');
  267. $vars['headingfont'] = of_get_option('heading_font', 'Cabin');
  268. $vars['bodyfont'] = of_get_option('body_font', 'a1');
  269. $vars['cachebust'] = NULL_CACHE_BUST;
  270. $vars['contentwidth'] = $content_width;
  271. return $vars;
  272. }
  273. /***************************************************************
  274. * Function null_admin_css_setup
  275. * Register and enqueue all css/less files backend - http://toggl.es/tSgnfR
  276. ***************************************************************/
  277. add_action('admin_enqueue_scripts', 'null_admin_css_setup');
  278. function null_admin_css_setup() {
  279. // is less compiling enabled or disabled?
  280. $type = (of_get_option('disable_less', '1') ? 'css' : 'less');
  281. // custom admin css
  282. wp_register_style('null-admin', get_template_directory_uri() . '/assets/'.$type.'/wp-admin.'.$type, '', filemtime(get_template_directory() . '/assets/'.$type.'/wp-admin.'.$type));
  283. wp_enqueue_style('null-admin');
  284. // action for adding or removing admin css
  285. do_action('null_admin_css');
  286. }
  287. /***************************************************************
  288. * Function null_theme_css_setup
  289. * Register and enqueue all css/less files frontend - http://toggl.es/tSgnfR
  290. ***************************************************************/
  291. add_action('wp_enqueue_scripts', 'null_theme_css_setup');
  292. function null_theme_css_setup() {
  293. // is less compiling enabled or disabled?
  294. $type = (of_get_option('disable_less', '1') ? 'css' : 'less');
  295. // register all css/less
  296. // grab the google font based on font settings
  297. $heading_font = of_get_option('heading_font', 'Cabin');
  298. $body_font = of_get_option('body_font', 'a1'); // arial
  299. $allfonts = null_get_fonts();
  300. $gfonts = array();
  301. if ($heading_font != '') {
  302. if (!null_string_search('(system)', $allfonts[$heading_font])) {
  303. $gfonts[] = $heading_font;
  304. }
  305. }
  306. if (!null_string_search('(system)', $allfonts[$body_font])) {
  307. $gfonts[] = $body_font;
  308. }
  309. if (!empty($gfonts)) {
  310. $gfonts = array_unique($gfonts);
  311. $getfonts = implode('|', $gfonts);
  312. wp_register_style('google-font', 'http://fonts.googleapis.com/css?family='.$getfonts, '', null_slugify(NULL_VERSION), 'all');
  313. wp_enqueue_style('google-font');
  314. }
  315. // the rest of the styles
  316. wp_register_style('null-screen', get_template_directory_uri() . '/assets/'.$type.'/screen.'.$type, array(), NULL_CACHE_BUST, 'screen');
  317. wp_register_style('holmes', get_template_directory_uri() . '/assets/css/holmes.css', array('null-screen'), NULL_CACHE_BUST, 'screen');
  318. wp_register_style('null-print', get_template_directory_uri() . '/assets/'.$type.'/print.'.$type, array(), NULL_CACHE_BUST, 'print');
  319. // register ie styles
  320. wp_register_style('null-screen-ie', get_template_directory_uri() . '/assets/'.$type.'/screen-ie.'.$type, array(), NULL_CACHE_BUST, 'screen');
  321. // all styles for this theme
  322. wp_enqueue_style('null-screen');
  323. // holmes if in development mode and holmes is set
  324. if (of_get_option('development_mode_holmes', '0')) wp_enqueue_style('holmes');
  325. // remove admin bar css for print media - added already
  326. remove_action('wp_head', 'wp_admin_bar_header');
  327. // print style sheet (including admin bar hide removed above)
  328. wp_enqueue_style('null-print');
  329. // ie styles
  330. wp_enqueue_style('null-screen-ie');
  331. // action for adding or removing theme css
  332. do_action('null_theme_css');
  333. }
  334. /***************************************************************
  335. * Function null_login_css_setup
  336. * Add a custom stylesheet to the login (same CSS is also added to the admin)
  337. ***************************************************************/
  338. add_action('login_enqueue_scripts', 'null_login_css_setup');
  339. function null_login_css_setup() {
  340. // is less compiling enabled or disabled?
  341. $type = (of_get_option('disable_less', '1') ? 'css' : 'less');
  342. // custom admin css
  343. wp_register_style('null-admin', get_template_directory_uri() . '/assets/'.$type.'/wp-admin.'.$type, array(), filemtime(get_template_directory() . '/assets/'.$type.'/wp-admin.'.$type));
  344. wp_enqueue_style('null-admin');
  345. }
  346. /***************************************************************
  347. * Function null_admin_js_setup
  348. * Register and enqueue all admin javascript files
  349. ***************************************************************/
  350. add_action('admin_enqueue_scripts', 'null_admin_js_setup');
  351. function null_admin_js_setup() {
  352. // action for adding or removing more js in the admin
  353. do_action('null_admin_js');
  354. }
  355. /***************************************************************
  356. * Function null_theme_js_setup
  357. * Register and enqueue all frontend javascript files
  358. ***************************************************************/
  359. add_action('wp_enqueue_scripts', 'null_theme_js_setup');
  360. function null_theme_js_setup() {
  361. // grab settings
  362. $polyfills = of_get_option('polyfills', array(
  363. 'ios' => "1",
  364. 'selectivizr' => "0",
  365. 'html5_forms' => "1",
  366. 'imgsizer' => "0"
  367. ));
  368. // register all scripts
  369. wp_register_script('modernizr', get_template_directory_uri() . '/assets/js/modernizr.js', '', filemtime(get_template_directory() . '/assets/js/modernizr.js'));
  370. wp_register_script('html5-forms', get_template_directory_uri() . '/assets/js/forms.js', array('jquery'), filemtime(get_template_directory() . '/assets/js/forms.js'));
  371. wp_register_script('null-gat', get_template_directory_uri() . '/assets/js/analytics.js', array('jquery'), filemtime(get_template_directory() . '/assets/js/analytics.js'));
  372. wp_register_script('null', get_template_directory_uri() . '/assets/js/onload.js', array('jquery', 'jquery-ui-tabs', 'jquery-ui-accordion'), filemtime(get_template_directory() . '/assets/js/onload.js'));
  373. // comment threading
  374. if (is_singular() && get_option('thread_comments')) wp_enqueue_script('comment-reply');
  375. // standard shipped jquery
  376. wp_enqueue_script('jquery');
  377. // always load modernizr as it contains HTML5 shiv
  378. wp_enqueue_script('modernizr');
  379. // html5 forms if option is set
  380. if ($polyfills['html5_forms'] == "1") wp_enqueue_script('html5-forms');
  381. // analytics event tracking
  382. if ((of_get_option('gat')) && (of_get_option('gat_external_download', '0'))) wp_enqueue_script('null-gat');
  383. // the onload/custom js file
  384. wp_enqueue_script('null');
  385. // action for adding or removing more js on the theme
  386. do_action('null_theme_js');
  387. }
  388. /***************************************************************
  389. * Function null_conditional_ie_styles
  390. * Add conditional comments around IE specific stylesheets
  391. ***************************************************************/
  392. add_filter('style_loader_tag', 'null_conditional_ie_styles', 10, 2);
  393. function null_conditional_ie_styles( $tag, $handle ) {
  394. if ('null-screen-ie' == $handle || 'screen-ie' == $handle)
  395. $tag = '<!-- IE css -->' . "\n" .'<!--[if lt IE 9]>' . "\n" . $tag . '<![endif]-->' . "\n";
  396. return $tag;
  397. }
  398. /***************************************************************
  399. * Function null_clean_login_logout
  400. * Tidy up our URLs for WordPress login and WordPress logout & alter redirects
  401. ***************************************************************/
  402. add_filter('login_url', 'null_clean_login_logout');
  403. add_filter('logout_url', 'null_clean_login_logout');
  404. function null_clean_login_logout($url, $redirect='') {
  405. // logout
  406. if (null_string_search('logout', $url)) {
  407. if (empty($redirect) && of_get_option('logout_redirect_url')) {
  408. $redirect = of_get_option('logout_redirect_url');
  409. }
  410. if (!is_multisite() && !is_child_theme() && of_get_option('cleanup', '0')) {
  411. $url = str_replace('wp-login.php', 'logout/', $url);
  412. if (empty($redirect)) {
  413. $redirect = get_option('siteurl') . '/wp-login.php?loggedout=true';
  414. }
  415. }
  416. // login
  417. } else {
  418. if (!is_multisite() && !is_child_theme() && of_get_option('cleanup', '0')) {
  419. $url = str_replace('wp-login.php', 'login/', $url);
  420. }
  421. if (empty($redirect) && of_get_option('login_redirect_url')) {
  422. $redirect = of_get_option('login_redirect_url');
  423. }
  424. }
  425. if (!empty($redirect)) {
  426. $url = add_query_arg('redirect_to', urlencode($redirect), $url);
  427. }
  428. return $url;
  429. }
  430. /***************************************************************
  431. * Function null_get_extensions
  432. * Helper function for retrieving widgets, shortcodes and post-type extensions
  433. ***************************************************************/
  434. function null_get_extensions($type = 'post-types', $settings = false) {
  435. switch($type) {
  436. // shortcodes
  437. case "shortcodes":
  438. $folder_base = trailingslashit(get_template_directory() . '/assets/inc/shortcodes');
  439. $folder_child = trailingslashit(get_stylesheet_directory() . '/assets/inc/shortcodes');
  440. $preg = '|Shortcode Name:(.*)$|mi';
  441. // for shortcodes we want to check a second header (shortcode template)
  442. $pregtemplate = '|Shortcode Template:(.*)$|mi';
  443. break;
  444. // widgets
  445. case "widgets":
  446. $folder_base = trailingslashit(get_template_directory() . '/assets/inc/widgets');
  447. $folder_child = trailingslashit(get_stylesheet_directory() . '/assets/inc/widgets');
  448. $preg = '|Widget Name:(.*)$|mi';
  449. break;
  450. // post types
  451. case "post-types":
  452. default:
  453. $folder_base = trailingslashit(get_template_directory() . '/assets/inc/post-types');
  454. $folder_child = trailingslashit(get_stylesheet_directory() . '/assets/inc/post-types');
  455. $preg = '|Post Type Name:(.*)$|mi';
  456. break;
  457. }
  458. // array to store extensions
  459. $extensions = array();
  460. // loop the directory and grab the extension information
  461. if (file_exists($folder_base)) {
  462. foreach(glob($folder_base . '*.php') as $file) {
  463. $data = implode('', file($file));
  464. if (preg_match($preg, $data, $name)) {
  465. $name = _cleanup_header_comment($name[1]);
  466. }
  467. // additional check for shortcodes - rip the template header out too
  468. if (isset($pregtemplate)) {
  469. if (preg_match($pregtemplate, $data, $template)) {
  470. $template = _cleanup_header_comment($template[1]);
  471. }
  472. if (!empty($name) && !empty($template)) {
  473. $extensions[] = array("name" => trim($name), "nicename" => null_slugify(trim($name)), "path" => $file, "template" => $template);
  474. }
  475. } else {
  476. if (!empty($name)) {
  477. $extensions[] = array("name" => trim($name), "nicename" => null_slugify(trim($name)), "path" => $file);
  478. }
  479. }
  480. }
  481. }
  482. // if a child theme then do it again
  483. if (file_exists($folder_child) && ($folder_base != $folder_child)) {
  484. foreach(glob($folder_child . '*.php') as $file) {
  485. $data = implode('', file($file));
  486. if (preg_match($preg, $data, $name)) {
  487. $name = _cleanup_header_comment($name[1]);
  488. }
  489. // additional check for shortcodes - rip the template header out too
  490. if (isset($pregtemplate)) {
  491. if (preg_match($pregtemplate, $data, $template)) {
  492. $template = _cleanup_header_comment($template[1]);
  493. }
  494. if (!empty($name) && !empty($name)) {
  495. $extensions[] = array("name" => trim($name), "nicename" => null_slugify(trim($name)), "path" => $file, "template" => $template);
  496. }
  497. } else {
  498. if (!empty($name)) {
  499. $extensions[] = array("name" => trim($name), "nicename" => null_slugify(trim($name)), "path" => $file);
  500. }
  501. }
  502. }
  503. }
  504. // return an array of settings if set
  505. if ($settings) {
  506. $settings = array();
  507. foreach($extensions as $extension) {
  508. $settings[$extension['nicename']] = $extension['name'];
  509. }
  510. // sort
  511. ksort($settings);
  512. return $settings;
  513. }
  514. // sort
  515. $sorted = array();
  516. foreach ($extensions as $extension) {
  517. $sorted[] = $extension['name'];
  518. }
  519. array_multisort($sorted, SORT_ASC, $extensions);
  520. // return an array of extensions
  521. return $extensions;
  522. }
  523. /***************************************************************
  524. * Function null_extensions_enabled
  525. * Simple check to see if any extension is set to on within an extensions array
  526. ***************************************************************/
  527. function null_extensions_enabled($extensions) {
  528. $tmp = array_filter($extensions);
  529. if (empty($tmp)) return false;
  530. return true;
  531. }
  532. /***************************************************************
  533. * Function null_get_fonts
  534. * Get System & Google Web Fonts json object and save as transient
  535. ***************************************************************/
  536. function null_get_fonts($sort = 'alpha') {
  537. // sort options
  538. // alpha: Sort the list alphabetically
  539. // date: Sort the list by date added (most recent font added or updated first)
  540. // popularity: Sort the list by popularity (most popular family first)
  541. // style: Sort the list by number of styles available (family with most styles first)
  542. // trending: Sort the list by families seeing growth in usage (family seeing the most growth first)
  543. if (false === ($font_list = get_transient('null_google_fonts_'.$sort))) {
  544. // system fonts - the stacks are available in mixins.less and simple array references are used for compatibility with LESS guards
  545. $font_list['a1'] = 'Arial (system)';
  546. $font_list['a2'] = 'Arial Rounded (system)';
  547. $font_list['b1'] = 'Baskerville (system)';
  548. $font_list['c1'] = 'Cambria (system)';
  549. $font_list['c2'] = 'Centry Gothic (system)';
  550. $font_list['c3'] = 'Courier New (system)';
  551. $font_list['g1'] = 'Georgia (system)';
  552. $font_list['h1'] = 'Helvetica (system)';
  553. $font_list['l1'] = 'Lucida Bright (system)';
  554. $font_list['l2'] = 'Lucida Sans (system)';
  555. $font_list['t1'] = 'Tahoma (system)';
  556. $font_list['t2'] = 'Trebuchet MS (system)';
  557. $font_list['v1'] = 'Verdana (system)';
  558. // google fonts
  559. $api_key = 'AIzaSyCTTbK5s0or8LmQfUCNhndMfSvyz-f6jqk';
  560. $gwf_uri = "https://www.googleapis.com/webfonts/v1/webfonts?key=" . $api_key . "&sort=" . $sort;
  561. $raw = wp_remote_get( $gwf_uri );
  562. // if an error is detected then fail
  563. if ( is_wp_error( $raw ) ) { return false; }
  564. $fonts = json_decode($raw['body']);
  565. foreach ($fonts->items as $font) {
  566. $font_list[$font->family] = $font->family;
  567. }
  568. // cache for 3 days
  569. set_transient('null_google_fonts_' . $sort, $font_list, 60 * 60 * 24 * 3);
  570. }
  571. // return the saved list of Google Web Fonts
  572. return $font_list;
  573. }
  574. /***************************************************************
  575. * Function null_of_font_faces
  576. * Add Google fonts to the options framework typogrpahy choice
  577. ***************************************************************/
  578. add_filter( 'of_recognized_font_faces', 'null_of_font_faces' );
  579. function null_of_font_faces($faces) {
  580. $extra_fonts = null_get_fonts();
  581. // remove system fonts from the list (a bit of a bug - ideally function above would have sensible array keys but it does not due to LESS issues)
  582. unset($extra_fonts['a1'], $extra_fonts['a2'], $extra_fonts['b1'], $extra_fonts['c1'], $extra_fonts['c2'], $extra_fonts['c3'], $extra_fonts['g1'], $extra_fonts['h1'], $extra_fonts['l1'], $extra_fonts['l2'], $extra_fonts['t1'], $extra_fonts['t2'], $extra_fonts['v1']);
  583. return array_merge($faces, $extra_fonts);
  584. }
  585. /***************************************************************
  586. * Function null_cache_path
  587. * Return the path to the null-cache directory in /uploads/
  588. ***************************************************************/
  589. function null_cache_path() {
  590. $upload_dir = wp_upload_dir();
  591. $dir = apply_filters('null_cache_path', trailingslashit( $upload_dir[ 'basedir' ] ) . 'null-cache');
  592. // create folder if it doesn't exist yet
  593. if (!file_exists($dir))
  594. wp_mkdir_p($dir);
  595. return rtrim($dir, '/');
  596. }
  597. /***************************************************************
  598. * Function optionsframework_option_name
  599. * Determine a unique name for the theme options settings in database
  600. ***************************************************************/
  601. function optionsframework_option_name() {
  602. $optionsframework_settings = get_option('optionsframework');
  603. $optionsframework_settings['id'] = NULL_OPTION_NAME;
  604. update_option('optionsframework', $optionsframework_settings);
  605. }
  606. /***************************************************************
  607. * Function is_wp_version
  608. * What version of WordPress are we running?
  609. ***************************************************************/
  610. if (!function_exists('is_wp_version')) {
  611. function is_wp_version( $is_ver ) {
  612. $wp_ver = explode( '.', get_bloginfo( 'version' ) );
  613. $is_ver = explode( '.', $is_ver );
  614. for( $i=0; $i<=count( $is_ver ); $i++ )
  615. if( !isset( $wp_ver[$i] ) ) array_push( $wp_ver, 0 );
  616. foreach( $is_ver as $i => $is_val )
  617. if( $wp_ver[$i] < $is_val ) return false;
  618. return true;
  619. }
  620. }
  621. /***************************************************************
  622. * Function current_url
  623. * Determine the URL of the currently viewed page - will return array if $parse set to true
  624. ***************************************************************/
  625. if (!function_exists('current_url')) {
  626. function current_url($parse = false) {
  627. $s = empty($_SERVER['HTTPS']) ? '' : ($_SERVER['HTTPS'] == 'on') ? 's' : '';
  628. $protocol = substr(strtolower($_SERVER['SERVER_PROTOCOL']), 0, strpos(strtolower($_SERVER['SERVER_PROTOCOL']), '/')) . $s;
  629. $port = ($_SERVER['SERVER_PORT'] == '80') ? '' : (":".$_SERVER['SERVER_PORT']);
  630. if ($parse) {
  631. return parse_url($protocol . "://" . $_SERVER['HTTP_HOST'] . $port . $_SERVER['REQUEST_URI']);
  632. } else {
  633. return $protocol . "://" . $_SERVER['HTTP_HOST'] . $port . $_SERVER['REQUEST_URI'];
  634. }
  635. }
  636. }
  637. /***************************************************************
  638. * Function null_obscure_login
  639. * Make the login error message a touch more generic - add to options?
  640. ***************************************************************/
  641. add_filter( 'login_errors', 'null_obscure_login' );
  642. function null_obscure_login($error) {
  643. $new_message = __('The credentials you provided are incorrect.', 'null');
  644. $error = str_replace( 'Invalid username.', $new_message, $error );
  645. $error = preg_replace( '{The password you entered for the username <strong>.*</strong> is incorrect.}', $new_message, $error );
  646. return $error;
  647. }
  648. /***************************************************************
  649. * Function null_string_search
  650. * Search a $string for $needle
  651. ***************************************************************/
  652. function null_string_search($needle,$string) {
  653. return (strpos($string, $needle) !== false);
  654. }
  655. /***************************************************************
  656. * Function null_slugify
  657. * Create a friendly URL slug from a string
  658. ***************************************************************/
  659. function null_slugify($str) {
  660. // $str2 = sanitize_title_with_dashes($str); - replace with?
  661. $str = preg_replace('/[^a-zA-Z0-9 -]/', '', $str);
  662. $str = strtolower(str_replace(' ', '-', trim($str)));
  663. $str = preg_replace('/-+/', '-', $str);
  664. //if ($str != $str2) echo ('slugs differ ('.$str.' - '.$str2.')<br/>');
  665. return $str;
  666. }
  667. ?>