Advertisement
Ornela

my functions.php

Jan 24th, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.86 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * This program is a free software; you can use it and/or modify it under the terms of the GNU
  5. * General Public License as published by the Free Software Foundation; either version 2 of the License,
  6. * or (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  9. * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. *
  11. * You should have received a copy of the GNU General Public License along with this program; if not, write
  12. * to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  13. *
  14. * @package Customizr
  15. * @subpackage functions
  16. * @since 1.0
  17. * @author Nicolas GUILLAUME <nicolas@themesandco.com>
  18. * @copyright Copyright (c) 2013, Nicolas GUILLAUME
  19. * @link http://themesandco.com/customizr
  20. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. */
  22.  
  23.  
  24.  
  25. /**
  26. * This is where Customizr starts. This file defines and loads the theme's components :
  27. * 1) A function tc__f() used everywhere in the theme, extension of WP built-in apply_filters()
  28. * 2) Constants : CUSTOMIZR_VER, TC_BASE, TC_BASE_CHILD, TC_BASE_URL, TC_BASE_URL_CHILD, THEMENAME, TC_WEBSITE
  29. * 3) Default filtered values : images sizes, skins, featured pages, social networks, widgets, post list layout
  30. * 4) Text Domain
  31. * 5) Theme supports : editor style, automatic-feed-links, post formats, navigation menu, post-thumbnails, retina support
  32. * 6) Plugins compatibility : jetpack, bbpress, qtranslate, woocommerce and more to come
  33. * 7) Default filtered options for the customizer
  34. * 8) Customizr theme's hooks API : front end components are rendered with action and filter hooks
  35. *
  36. * The method TC__::tc__() loads the php files and instanciates all theme's classes.
  37. * All classes files (except the class__.php file which loads the other) are named with the following convention : class-[group]-[class_name].php
  38. *
  39. * The theme is entirely built on an extensible filter and action hooks API, which makes customizations easy as breeze, without ever needing to modify the core structure.
  40. * Customizr's code acts like a collection of plugins that can be enabled, disabled or extended.
  41. *
  42. */
  43.  
  44.  
  45.  
  46. /**
  47. * The best and safest way to extend Customizr with your own custom functions is to create a child theme.
  48. * You can add functions here but they will be lost on upgrade. If you use a child theme, you are safe!
  49. * More informations on how to create a child theme with Customizr here : http://themesandco.com/customizr/#child-theme
  50. */
  51.  
  52.  
  53.  
  54. /**
  55. * The tc__f() function is an extension of WP built-in apply_filters() where the $value param becomes optional.
  56. * It is shorter than the original apply_filters() and only used on already defined filters.
  57. *
  58. * By convention in Customizr, filter hooks are used as follow :
  59. * 1) declared with add_filters in class constructors (mainly) to hook on WP built-in callbacks or create "getters" used everywhere
  60. * 2) declared with apply_filters in methods to make the code extensible for developers
  61. * 3) accessed with tc__f() to return values (while front end content is handled with action hooks)
  62. *
  63. * Used everywhere in Customizr. Can pass up to five variables to the filter callback.
  64. *
  65. * @since Customizr 3.0
  66. */
  67. if( !function_exists( 'tc__f' )) :
  68. function tc__f ( $tag , $value = null , $arg_one = null , $arg_two = null , $arg_three = null , $arg_four = null , $arg_five = null) {
  69. return apply_filters( $tag , $value , $arg_one , $arg_two , $arg_three , $arg_four , $arg_five );
  70. }
  71. endif;
  72.  
  73.  
  74.  
  75. /**
  76. * Fires the theme : constants definition, core classes loading
  77. *
  78. *
  79. * @package Customizr
  80. * @subpackage classes
  81. * @since 3.0
  82. * @author Nicolas GUILLAUME <nicolas@themesandco.com>
  83. * @copyright Copyright (c) 2013, Nicolas GUILLAUME
  84. * @link http://themesandco.com/customizr
  85. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  86. */
  87.  
  88. class TC___ {
  89.  
  90. //Access any method or var of the class with classname::$instance -> var or method():
  91. static $instance;
  92.  
  93. public $tc_core;
  94.  
  95. function __construct () {
  96.  
  97. self::$instance =& $this;
  98.  
  99. //this is the structure of the Customizr code : groups => ('path' , 'class_suffix')
  100. $this -> tc_core = apply_filters( 'tc_core',
  101. array(
  102. 'fire' => array(
  103. array('inc' , 'init'),//defines default values (layout, socials, default slider...) and theme supports (after_setup_theme)
  104. array('inc' , 'resources'),//loads style (skins) and scripts
  105. array('inc' , 'utils'),//those are helpers used everywhere
  106. array('inc' , 'widgets'),//widget factory
  107. array('inc/admin' , 'admin_init'),//fires the customizer and the metaboxes for slider and layout options
  108. ),
  109. //the following files/classes define the action hooks for front end rendering : header, main content, footer
  110. 'header' => array(
  111. array('parts' , 'header_main'),
  112. array('parts' , 'menu'),
  113. array('parts' , 'nav_walker'),
  114. ),
  115. 'content' => array(
  116. array('parts', '404'),
  117. array('parts', 'attachment'),
  118. array('parts', 'breadcrumb'),
  119. array('parts', 'comments'),
  120. array('parts', 'featured_pages'),
  121. array('parts', 'gallery'),
  122. array('parts', 'headings'),
  123. array('parts', 'no_results'),
  124. array('parts', 'page'),
  125. array('parts', 'post'),
  126. array('parts', 'post_list'),
  127. array('parts', 'post_metas'),
  128. array('parts', 'post_navigation'),
  129. array('parts', 'sidebar'),
  130. array('parts', 'slider'),
  131. ),
  132. 'footer' => array(
  133. array('parts', 'footer_main'),
  134. ),
  135. 'addons' => apply_filters('tc_addons_classes' , array() )
  136. )//end of array
  137. );//end of filter
  138.  
  139. /* GETS INFORMATIONS FROM STYLE.CSS */
  140. // get themedata version wp 3.4+
  141. if( function_exists( 'wp_get_theme' ) )
  142. {
  143. //get WP_Theme object of customizr
  144. $tc_theme = wp_get_theme();
  145.  
  146. //Get infos from parent theme if using a child theme
  147. $tc_theme = $tc_theme -> parent() ? $tc_theme -> parent() : $tc_theme;
  148.  
  149. $tc_base_data['prefix'] = $tc_base_data['title'] = $tc_theme -> name;
  150. $tc_base_data['version'] = $tc_theme -> version;
  151. $tc_base_data['authoruri'] = $tc_theme -> {'Author URI'};
  152. }
  153.  
  154. // get themedata for lower versions (get_stylesheet_directory() points to the current theme root, child or parent)
  155. else
  156. {
  157. $tc_base_data = get_theme_data( get_stylesheet_directory().'/style.css' );
  158. $tc_base_data['prefix'] = $tc_base_data['title'];
  159. }
  160.  
  161. /* CUSTOMIZR_VER is the Version */
  162. if( ! defined( 'CUSTOMIZR_VER' ) ) { define( 'CUSTOMIZR_VER' , $tc_base_data['version'] ); }
  163.  
  164. /* TC_BASE is the root server path of the parent theme */
  165. if( ! defined( 'TC_BASE' ) ) { define( 'TC_BASE' , get_template_directory().'/' ); }
  166.  
  167. /* TC_BASE_CHILD is the root server path of the child theme */
  168. if( ! defined( 'TC_BASE_CHILD' ) ) { define( 'TC_BASE_CHILD' , get_stylesheet_directory().'/' ); }
  169.  
  170. /* TC_BASE_URL http url of the loaded parent theme*/
  171. if( ! defined( 'TC_BASE_URL' ) ) { define( 'TC_BASE_URL' , get_template_directory_uri() . '/' ); }
  172.  
  173. /* TC_BASE_URL_CHILD http url of the loaded child theme*/
  174. if( ! defined( 'TC_BASE_URL_CHILD' ) ) { define( 'TC_BASE_URL_CHILD' , get_stylesheet_directory_uri() . '/' ); }
  175.  
  176. /* THEMENAME contains the Name of the currently loaded theme */
  177. if( ! defined( 'THEMENAME' ) ) { define( 'THEMENAME' , $tc_base_data['title'] ); }
  178.  
  179. /* TC_WEBSITE is the home website of Customizr */
  180. if( ! defined( 'TC_WEBSITE' ) ) { define( 'TC_WEBSITE' , $tc_base_data['authoruri'] ); }
  181.  
  182. /* theme class groups instanciation */
  183. $this -> tc__ ( $this -> tc_core );
  184.  
  185. }//end of __construct()
  186.  
  187.  
  188.  
  189. /**
  190. * Class instanciation with a singleton factory :
  191. * Thanks to Ben Doherty (https://github.com/bendoh) for the great programming approach
  192. *
  193. *
  194. * @since Customizr 3.0
  195. */
  196. function tc__ ( $load ) {
  197.  
  198. static $instances;
  199.  
  200. foreach ( $load as $group => $files ) {
  201. foreach ($files as $path_suffix ) {
  202. //checks if a child theme is used and if the required file has to be overriden
  203. if ( $this -> tc_is_child() && file_exists( TC_BASE_CHILD . $path_suffix[0] . '/class-' . $group . '-' .$path_suffix[1] .'.php') ) {
  204. require_once ( TC_BASE_CHILD . $path_suffix[0] . '/class-' . $group . '-' .$path_suffix[1] .'.php') ;
  205. }
  206. else {
  207. require_once ( TC_BASE . $path_suffix[0] . '/class-' . $group . '-' .$path_suffix[1] .'.php') ;
  208. }
  209.  
  210. $classname = 'TC_' . $path_suffix[1];
  211. if( ! isset( $instances[ $classname ] ) )
  212. {
  213. $instances[ $classname ] = class_exists($classname) ? new $classname : '';
  214. }
  215. }
  216. }
  217.  
  218. return $instances[ $classname ];
  219. }
  220.  
  221.  
  222.  
  223. /**
  224. * Checks if we use a child theme. Uses a deprecated WP functions (get_theme_data) for versions <3.4
  225. * @return boolean
  226. *
  227. * @since Customizr 3.0.11
  228. */
  229. function tc_is_child() {
  230. // get themedata version wp 3.4+
  231. if( function_exists( 'wp_get_theme' ) ) {
  232. //get WP_Theme object of customizr
  233. $tc_theme = wp_get_theme();
  234. //define a boolean if using a child theme
  235. $is_child = ( $tc_theme -> parent() ) ? true : false;
  236. }
  237. else {
  238. $tc_theme = get_theme_data( get_stylesheet_directory() . '/style.css' );
  239. $is_child = ( ! empty($tc_theme['Template']) ) ? true : false;
  240. }
  241.  
  242. return $is_child;
  243. }
  244.  
  245. }//end of class
  246.  
  247. //Creates a new instance
  248. new TC___;
  249. function new_nav_menu_items($items) {
  250. if (function_exists('icl_get_languages')) {
  251. $languages = icl_get_languages('skip_missing=0');
  252. if (1 < count($languages)) {
  253. foreach ($languages as $l) {
  254. $items = $items . '<li class="menu-item custom-switcher"><a href="' . $l['url'] . '"><img src="' . $l['country_flag_url'] . '" height="12" alt="' . $l['language_code'] . '" width="18" /></a></li>';
  255. }
  256. }
  257. }
  258.  
  259. return $items;
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement