Advertisement
Guest User

Rubber Duckie

a guest
Aug 18th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.84 KB | None | 0 0
  1. <?php
  2. /**
  3. * Customizr functions
  4. *
  5. * The best way to add your own functions to Customizr is to create a child theme
  6. * http://codex.wordpress.org/Child_Themes
  7. *
  8. * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
  9. * General Public License as published by the Free Software Foundation; either version 2 of the License,
  10. * or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  13. * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * You should have received a copy of the GNU General Public License along with this program; if not, write
  16. * to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. *
  18. * @package Customizr
  19. * @subpackage functions
  20. * @since 3.0
  21. * @author Nicolas GUILLAUME <nicolas@themesandco.com>
  22. * @copyright Copyright (c) 2013, Nicolas GUILLAUME
  23. * @link http://themesandco.com/customizr
  24. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  25. */
  26.  
  27. //we hook the code on the __before_body hook, which is executed before the <body> rendering.
  28. // added 2014-03-26 by KLN
  29. add_action ('__before_body' , 'move_single_post_metas');
  30.  
  31. function move_single_post_metas() {
  32. //checks if we are displaying a single post. Returns false if not.
  33. if ( !is_single() )
  34. return;
  35. //we remove the original action hooked on '__post_metas'. tc_post_metas action is a method of the TC_post_metas class
  36. //We can access the instance of this class with a static property of this class that is a self instance.
  37. remove_action ( '__after_content_title' , array( TC_post_metas::$instance , 'tc_post_metas' ));
  38.  
  39. //we add the tc_post_metas action on a the __after_loop (check index.php file to see where this hook is called in the code)
  40. add_action ('__after_article' , array( TC_post_metas::$instance , 'tc_post_metas'), 10);
  41.  
  42. //Additional action to display an hr separator between content and metas.
  43. //We use the priority parameter to determine the rendering order of the action
  44. add_action ('__after_article' , 'display_hr', 0);
  45.  
  46. //this is a nested function (function in another function), allowed with PHP.
  47. function display_hr() {
  48. ?>
  49. <hr/>
  50. <?php
  51. }
  52. }
  53. //end move meta function
  54.  
  55.  
  56.  
  57. /**
  58. * Singleton factory : on demand class single instanciation
  59. * Thanks to Ben Doherty (https://github.com/bendoh) for the great programming approach
  60. *
  61. *
  62. * @since Customizr 3.0
  63. */
  64. if ( !function_exists( 'tc__' ) ) :
  65. function tc__ ( $instance_groups = null, $class = null ) {
  66.  
  67. static $instances;
  68.  
  69. $classname = '';
  70.  
  71. $instance_groups = is_array($instance_groups) ? $instance_groups : array($instance_groups);
  72.  
  73. //get the class file(s) array by group and name (if defined)
  74. $parent_files = tc_get_classes ( $instance_groups, $path = null ,$class );
  75. //Do we have to include some child theme classes?
  76. $child_files = tc_is_child() ? tc_get_classes ( $instance_groups, $path = null ,$class, $child=true) : array();
  77. $files = array_merge($parent_files, $child_files);
  78.  
  79. foreach ( $files as $f )
  80. {
  81. //load class files
  82. locate_template ( $f , true , true );//name, load, require_once
  83.  
  84. $classname = 'TC_'.tc_get_file_class( $f );
  85.  
  86. //instanciation
  87. if( !isset( $instances[ $classname ] ) )
  88. {
  89. $instances[ $classname ] = class_exists($classname) ? new $classname : '';
  90. }
  91. }//end foreach
  92. return $instances[ $classname ];
  93. }
  94. endif;
  95.  
  96. /**
  97. * *Center the logo from Customizr Code Snippet
  98. * */
  99. add_filter('tc_logo_text_display', 'your_logo_display');
  100. add_filter('tc_logo_img_display', 'your_logo_display');
  101. function your_logo_display($output) {
  102. return preg_replace('/brand span3/', 'brand span10 offset1', $output, -1);
  103. }
  104.  
  105.  
  106. /**
  107. * Checks if we use a child theme. Uses a deprecated WP functions (get_theme_data) for versions <3.4
  108. * @return boolean
  109. *
  110. * @since Customizr 3.0.11
  111. */
  112. if ( !function_exists( 'tc_is_child' ) ) :
  113. function tc_is_child() {
  114. // get themedata version wp 3.4+
  115. if( function_exists( 'wp_get_theme' ) ) {
  116. //CHECK IF WE ARE USING A CHILD THEME
  117. //get WP_Theme object of customizr
  118. $tc_theme = wp_get_theme();
  119. //define a boolean if using a child theme
  120. $is_child = ( $tc_theme -> parent() ) ? true : false;
  121. }
  122. else {
  123. $tc_theme = get_theme_data( get_stylesheet_directory() . '/style.css' );
  124. $is_child = ( !empty($tc_theme['Template']) ) ? true : false;
  125. }
  126.  
  127. return $is_child;
  128. }
  129. endif;
  130.  
  131.  
  132.  
  133.  
  134. /**
  135. * Recursive function, takes 4 parameters ( $group is required, $class, $path and $child are optional)
  136. * Scans the theme folder and returns an array of class file names according to their group/name
  137. *
  138. * @since Customizr 3.0
  139. */
  140. if ( !function_exists( 'tc_get_classes' ) ) :
  141. function tc_get_classes( $instance_groups , $path = null , $class = null, $child = null ) {
  142.  
  143. /* TC_BASE is the root server path of parent theme */
  144. if ( ! defined( 'TC_BASE' ) ) { define( 'TC_BASE' , get_template_directory().'/' ); }
  145.  
  146. if ( ! defined( 'TC_BASE_CHILD' ) ) { define( 'TC_BASE_CHILD' , get_stylesheet_directory().'/' ); }
  147.  
  148. //which folder are we scanning, parent or child?
  149. $tc_base = ($child) ? TC_BASE_CHILD: TC_BASE ;
  150.  
  151. //initializes the class files array
  152. $classes = array();
  153.  
  154. //root class instanciation : in this case we don't want to loop through all files
  155. if ( in_array('customizr', $instance_groups) ) {
  156. $classes[] = '/inc/class-customizr-__.php';
  157. }
  158.  
  159. //all other cases
  160. else {
  161.  
  162. $files = scandir($tc_base.$path) ;
  163.  
  164. foreach ( $files as $file)
  165. {
  166. if ( $file[0] != '.' )
  167. {
  168. if ( is_dir($tc_base.$path.$file) )
  169. {
  170. $classes = array_merge( $classes, tc_get_classes( $instance_groups, $path.$file.'/' , $class, $child));
  171. }
  172.  
  173. else if ( substr( $file, -4) == '.php' )
  174. {
  175. switch ( $class)
  176. {
  177. //if the class is not defined
  178. case null:
  179. if ( in_array( tc_get_file_group($file), $instance_groups) )
  180. {
  181. $classes[] = $path.$file;
  182. }
  183. break;
  184.  
  185. default:
  186. if ( tc_get_file_class($file) == $class)
  187. {
  188. $classes[] = $path.$file;
  189. }
  190. break;
  191. }//end switch
  192. }//end if
  193. } //end if
  194. }//end for each
  195. }//end if
  196.  
  197. return $classes;
  198.  
  199. }//end of function
  200. endif;
  201.  
  202.  
  203.  
  204.  
  205.  
  206. /**
  207. * Returns the class group from the file name
  208. *
  209. *
  210. * @since Customizr 3.0
  211. */
  212. if ( !function_exists( 'tc_get_file_group' ) ) :
  213. function tc_get_file_group( $file) {
  214.  
  215. $group = preg_match_all( '/\-(.*?)\-/' , $file , $match );
  216.  
  217. if ( isset( $match[1][0] ) )
  218. {
  219. return $match[1][0];
  220. }
  221. }
  222. endif;
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232. /**
  233. * Returns the class name from the file name
  234. *
  235. *
  236. * @since Customizr 3.0
  237. */
  238. if ( !function_exists( 'tc_get_file_class' ) ) :
  239. function tc_get_file_class( $file) {
  240. //find the name of the class=>after last occurence of '-' and remove .php
  241. $pos = strripos( $haystack = $file , $needle = '-' );
  242. //get the part of the string containing the class name
  243. $classname = substr( $file , $pos + 1);
  244. //get rid of '.php'
  245. $classname = substr_replace( $classname , '' , -4 , 4);
  246.  
  247. return $classname;
  248. }
  249. endif;
  250.  
  251.  
  252.  
  253.  
  254. /**
  255. * Allows WP apply_filter() function to accept up to 4 optional arguments
  256. *
  257. *
  258. * @since Customizr 3.0
  259. */
  260. if( !function_exists( 'tc__f' )) :
  261. function tc__f ( $filter , $arg1 = null , $arg2 = null , $arg3 = null, $arg4 = null) {
  262.  
  263. return apply_filters( $filter , $arg1 , $arg2 , $arg3, $arg4 );
  264.  
  265. }
  266. endif;
  267.  
  268.  
  269.  
  270. /* Gets the saved options array and make it global */
  271. $tc_saved_options = get_option( 'tc_theme_options');
  272. global $tc_saved_options;
  273.  
  274. /* Loads the theme classes framework */
  275. tc__( 'customizr' );//fires the theme
  276.  
  277. /* Starts recording for server execution timeline in dev tools */
  278. tc__f( 'rec' , __FILE__ );
  279.  
  280.  
  281.  
  282.  
  283. /*
  284. * The best and safest way to add your own functions to Customizr is to create a child theme
  285. * You can add functions here but it will be lost on upgrade. If you use a child theme, you are safe!
  286. * http://codex.wordpress.org/Child_Themes
  287. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement