Guest User

Untitled

a guest
Dec 16th, 2013
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.88 KB | None | 0 0
  1. <?php
  2. /*
  3. tagDiv - 2013
  4. Our portofolio: http://themeforest.net/user/tagDiv/portfolio
  5. Thanks for using our theme !
  6. */
  7.  
  8.  
  9. /* ----------------------------------------------------------------------------
  10. deploy mode - this file tells the theme what settings to load (demo, (dev) development, deploy)
  11. */
  12. require_once('td_deploy_mode.php');
  13.  
  14.  
  15. /* ----------------------------------------------------------------------------
  16. wp_cake - this is our theme framework - all the content and settings are there
  17. */
  18. require_once('includes/td_wp_cake.php');
  19.  
  20.  
  21. /*
  22. * author meta support
  23. */
  24. require_once('wp-admin/td_author.php' );
  25.  
  26.  
  27. /*
  28. * generic filter support
  29. */
  30. require_once('includes/class/td_generic_filter_array.php' );
  31.  
  32.  
  33. /*
  34. * generic filter buider class
  35. */
  36. require_once('includes/content_builder/td_generic_filter_builder.php' );
  37.  
  38.  
  39. /*
  40. * modal window for user login
  41. */
  42. require_once('includes/app/td_login.php' );
  43.  
  44.  
  45. /*
  46. * if debug - the constants are used to load the live color customizer (demo) and to remove the tf bar on ios devices
  47. */
  48. if (TD_DEBUG_LIVE_THEME_STYLE) {
  49. require_once('includes/deploy/td_theme_style.php' );
  50. }
  51.  
  52. if (TD_DEBUG_IOS_REDIRECT) {
  53. require_once('includes/deploy/td_ios_redirect.php' );
  54. }
  55.  
  56. require_once('includes/app/widgets/td_login_widget.php' );
  57.  
  58. /* ----------------------------------------------------------------------------
  59. CSS - front end
  60. */
  61.  
  62. function td_load_css() {
  63.  
  64. //google fonts
  65. $td_protocol = is_ssl() ? 'https' : 'http';
  66. if ((defined('TD_DEPLOY_MODE') and (TD_DEPLOY_MODE == 'demo' or TD_DEPLOY_MODE == 'dev')) or defined('TD_SPEED_BOOSTER')) { //on demo and dev we load only the latin fonts
  67. //modify this collection if you want to optimize the fonts loaded
  68. //collection url -> : http://www.google.com/fonts#ReviewPlace:refine/Collection:PT+Sans:400,700,400italic|Ubuntu:400,400italic|Open+Sans:400italic,400|Oswald:400,700|Roboto+Condensed:400italic,700italic,400,700
  69. wp_enqueue_style('google-font-rest', $td_protocol . '://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic|Ubuntu:400,400italic|Open+Sans:400italic,400|Oswald:400,700|Roboto+Condensed:400italic,700italic,400,700'); //used on menus/small text
  70. } else {
  71. wp_enqueue_style('google-font-opensans', $td_protocol . '://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&amp;subset=latin,cyrillic-ext,greek-ext,greek,vietnamese,latin-ext,cyrillic'); //used on menus/small text
  72. wp_enqueue_style('google-font-ubuntu', $td_protocol . '://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700,300italic,400italic,500italic,700italic&amp;subset=latin,cyrillic-ext,greek-ext,greek,latin-ext,cyrillic'); //used on content
  73. wp_enqueue_style('google-font-pt-sans', $td_protocol . '://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic&subset=latin,cyrillic-ext,latin-ext,cyrillic'); //used on content
  74. wp_enqueue_style('google-font-oswald', $td_protocol . '://fonts.googleapis.com/css?family=Oswald:400,300,700&subset=latin,latin-ext'); //used on content
  75. wp_enqueue_style('google-roboto-cond', $td_protocol . '://fonts.googleapis.com/css?family=Roboto+Condensed:300italic,400italic,700italic,400,300,700&subset=latin,cyrillic-ext,greek-ext,greek,vietnamese,latin-ext,cyrillic'); //used on content
  76. }
  77.  
  78.  
  79.  
  80. //bootstrap - custom built - it was generated via compilation of /external/bootstrap-master/less/bootstrap.less
  81. $responsive = td_util::get_customizer_option('responsive');
  82. switch ($responsive) {
  83. case '980_responsive':
  84. wp_enqueue_style('td-bootstrap', get_template_directory_uri() . '/external/td-bootstrap-980-responsive.css', '', TD_THEME_VERSION, 'all' );
  85. break;
  86.  
  87. case '980':
  88. wp_enqueue_style('td-bootstrap', get_template_directory_uri() . '/external/td-bootstrap-980-not-resp.css', '', TD_THEME_VERSION, 'all' );
  89. break;
  90.  
  91. case '1170':
  92. wp_enqueue_style('td-bootstrap', get_template_directory_uri() . '/external/td-bootstrap-1170-not-resp.css', '', TD_THEME_VERSION, 'all' );
  93. break;
  94.  
  95. default:
  96. wp_enqueue_style('td-bootstrap', get_template_directory_uri() . '/external/td-bootstrap.css', '', TD_THEME_VERSION, 'all' );
  97. break;
  98. }
  99.  
  100.  
  101.  
  102.  
  103.  
  104. //main theme style - set the TD_DEBUG_USE_LESS flag in /includes/app/td_config.php and the theme will load the less files and compile them for you
  105. if (TD_DEBUG_USE_LESS) {
  106. wp_enqueue_style('td-theme', get_template_directory_uri() . '/td_less_compiler.php', array('td-bootstrap'), TD_THEME_VERSION, 'all' );
  107. //wp_enqueue_style('td-theme', get_template_directory_uri() . '/style.less', array('td-bootstrap'), TD_THEME_VERSION, 'all' );
  108. } else {
  109. wp_enqueue_style('td-theme', get_stylesheet_uri(), array('td-bootstrap'), TD_THEME_VERSION, 'all' );
  110. }
  111. }
  112. add_action('wp_enqueue_scripts', 'td_load_css');
  113.  
  114.  
  115.  
  116. /* ----------------------------------------------------------------------------
  117. CSS - wp-admin
  118. */
  119.  
  120. function td_load_td_admin_css() {
  121. wp_enqueue_style('td-wp-admin-style', get_template_directory_uri() . '/wp-admin/css/wp-admin-style.css', false, TD_THEME_VERSION, 'all' );
  122. wp_enqueue_style('td-wp-admin-td-panel', get_template_directory_uri() . '/wp-admin/css/wp-admin-td-panel.css', false, TD_THEME_VERSION, 'all' );
  123. }
  124. add_action('admin_enqueue_scripts', 'td_load_td_admin_css');
  125. add_action('customize_controls_print_styles', 'td_load_td_admin_css'); //load our css in wp theme customizer
  126.  
  127.  
  128.  
  129. /* ----------------------------------------------------------------------------
  130. JS - main
  131. */
  132.  
  133. function td_load_js() {
  134.  
  135. if (TD_DEPLOY_MODE == 'demo') { //on demo load compressed js
  136. //wp_enqueue_script('site', get_template_directory_uri() . '/js/site.js',array( 'jquery' ), 1, true); //the main site script
  137. //wp_enqueue_script('site', get_template_directory_uri() . '/js/min/site.min.js',array( 'jquery' ), 1, true); //the main site script
  138. //wp_enqueue_script('site-external', get_template_directory_uri() . '/js/min/external.min.js', array( 'site' ), 1, true); //load at begining
  139.  
  140. wp_enqueue_script('site-external', get_template_directory_uri() . '/js/min/external.min.js', array( 'jquery' ), 1, true); //load at begining
  141. wp_enqueue_script('site', get_template_directory_uri() . '/js/min/site.min.js',array( 'site-external' ), 1, true); //the main site script
  142.  
  143. /*
  144. * //it's already appended
  145. if (TD_DEBUG_LIVE_THEME_STYLE) {
  146. wp_enqueue_script('td-js-style-customizer', get_template_directory_uri() . '/js/min/style_customizer.min.js',array( 'jquery'), 1, true);
  147. }
  148. (*/
  149. } else {
  150. wp_enqueue_script('site-external', get_template_directory_uri() . '/js/external.js',array( 'jquery' ), 1, true); //load at begining
  151. wp_enqueue_script('site', get_template_directory_uri() . '/js/site.js',array( 'site-external' ), 1, true); //the main site script
  152.  
  153. if (TD_DEBUG_LIVE_THEME_STYLE) {
  154. wp_enqueue_script('td-js-style-customizer', get_template_directory_uri() . '/js/style_customizer.js',array( 'jquery'), 1, true);
  155. }
  156. }
  157.  
  158.  
  159. }
  160. add_action('wp_enqueue_scripts', 'td_load_js');
  161.  
  162.  
  163.  
  164. /* ----------------------------------------------------------------------------
  165. JS - admin
  166. */
  167.  
  168. function td_load_js_admin() {
  169. wp_enqueue_script('td-wp-admin-js', get_template_directory_uri() . '/wp-admin/js/wp-admin-js.js', array('jquery'), 1, false);
  170. }
  171. add_action('admin_enqueue_scripts', 'td_load_js_admin');
  172.  
  173.  
  174.  
  175. /* ----------------------------------------------------------------------------
  176. JS - theme customizer
  177. */
  178.  
  179. function td_load_js_theme_customizer() {
  180. wp_enqueue_script('td-theme-custom', get_template_directory_uri() . '/wp-admin/js/theme-customizer.js', array('jquery'), 1, true);
  181. }
  182. add_action('customize_controls_init', 'td_load_js_theme_customizer');
  183.  
  184.  
  185.  
  186. // used by ie8 - there is no other way to add js for ie8 only
  187. function add_ie_html5_shim () {
  188. echo '<!--[if lt IE 9]>';
  189. echo '<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>';
  190. echo '<![endif]-->
  191. ';
  192. }
  193. add_action('wp_head', 'add_ie_html5_shim');
  194.  
  195.  
  196.  
  197. /* ----------------------------------------------------------------------------
  198. Custom <title> wp_title - seo
  199. */
  200. function td_wp_title( $title, $sep ) {
  201. global $paged, $page;
  202.  
  203. if ( is_feed() )
  204. return $title;
  205.  
  206. // Add the site name.
  207. $title .= get_bloginfo( 'name' );
  208.  
  209. // Add the site description for the home/front page.
  210. $site_description = get_bloginfo( 'description', 'display' );
  211. if ( $site_description && ( is_home() || is_front_page() ) )
  212. $title = "$title $sep $site_description";
  213.  
  214. // Add a page number if necessary.
  215. if ( $paged >= 2 || $page >= 2 )
  216. $title = "$title $sep " . __td('Page') . ' ' . max( $paged, $page );
  217.  
  218. return $title;
  219. }
  220. add_filter( 'wp_title', 'td_wp_title', 10, 2 );
  221.  
  222.  
  223.  
  224. /* ----------------------------------------------------------------------------
  225. Pagebuilder
  226. */
  227.  
  228. global $td_row_count, $td_column_count;
  229.  
  230. $td_row_count = 0;
  231. $td_column_count = 0;
  232.  
  233. $dir = dirname(__FILE__) . '/wpbakery';
  234.  
  235.  
  236. $composer_settings = Array(
  237. 'APP_ROOT' => $dir . '/js_composer',
  238. 'WP_ROOT' => dirname( dirname( dirname( dirname($dir ) ) ) ). '/',
  239. 'APP_DIR' => basename( $dir ) . '/js_composer/',
  240. 'CONFIG' => $dir . '/js_composer/config/',
  241. 'ASSETS_DIR' => 'assets/',
  242. 'COMPOSER' => $dir . '/js_composer/composer/',
  243. 'COMPOSER_LIB' => $dir . '/js_composer/composer/lib/',
  244. 'SHORTCODES_LIB' => $dir . '/js_composer/composer/lib/shortcodes/',
  245.  
  246. /* for which content types Visual Composer should be enabled by default */
  247. 'default_post_types' => Array('page')
  248. );
  249.  
  250.  
  251. require_once locate_template('/wpbakery/js_composer/js_composer.php');
  252.  
  253. //map all of our blocks in page builder
  254. td_global_blocks::wpb_map_all();
  255.  
  256. //remove unused composer elements;
  257. vc_remove_element("vc_separator");
  258. vc_remove_element("vc_text_separator");
  259. vc_remove_element("vc_message");
  260. vc_remove_element("vc_toggle");
  261. vc_remove_element("vc_gallery");
  262. vc_remove_element("vc_tour"); //wtf
  263. vc_remove_element("vc_accordion");
  264. vc_remove_element("vc_teaser_grid");
  265. vc_remove_element("vc_posts_slider");
  266. vc_remove_element("vc_posts_grid");
  267. vc_remove_element("vc_cta_button");
  268. vc_remove_element("vc_progress_bar");
  269. vc_remove_element("vc_wp_links");
  270. vc_remove_element("vc_facebook");
  271.  
  272.  
  273. $wpVC_setup->init($composer_settings);
  274.  
  275.  
  276.  
  277. /* ----------------------------------------------------------------------------
  278. visual composer rewrite classes
  279. */
  280.  
  281. function custom_css_classes_for_vc_row_and_vc_column($class_string, $tag) {
  282. if ($tag=='vc_row' || $tag=='vc_row_inner') {
  283. $class_string = str_replace('vc_row-fluid', 'row-fluid', $class_string);
  284. }
  285. if ($tag=='vc_column' || $tag=='vc_column_inner') {
  286. $class_string = preg_replace('/vc_span(\d{1,2})/', 'span$1', $class_string);
  287. }
  288. return $class_string;
  289. }
  290. // Filter to Replace default css class for vc_row shortcode and vc_column
  291. add_filter('vc_shortcodes_css_class', 'custom_css_classes_for_vc_row_and_vc_column', 10, 2);
  292.  
  293.  
  294.  
  295. /* ----------------------------------------------------------------------------
  296. Category metadata
  297. */
  298.  
  299. require_once("wp-admin/external/Tax-meta-class/Tax-meta-class.php");
  300. if (is_admin()){
  301. /*
  302. * configure your meta box
  303. */
  304. $config = array(
  305. 'id' => 'demo_meta_box', // meta box id, unique per meta box
  306. 'title' => 'Demo Meta Box', // meta box title
  307. 'pages' => array('category'), // taxonomy name, accept categories, post_tag and custom taxonomies
  308. 'context' => 'normal', // where the meta box appear: normal (default), advanced, side; optional
  309. 'fields' => array(), // list of meta fields (can be added by field arrays)
  310. 'local_images' => false, // Use local or hosted images (meta box images for add/remove)
  311. 'use_with_theme' => true //change path if used with theme set to true, false for a plugin or anything else for a custom path(default false).
  312. );
  313.  
  314.  
  315.  
  316. /*
  317. * Initiate your meta box
  318. */
  319.  
  320. $my_meta = new Tax_Meta_Class($config);
  321.  
  322. /*
  323. * Add fields to your meta box
  324. */
  325. $td_module_list = array(
  326. '0' => ' - default - ',
  327. '1' => 'module 1',
  328. '2' => 'module 2',
  329. '3' => 'module 3',
  330. '4' => 'module 4',
  331. '5' => 'module 5',
  332. '6' => 'module 6',
  333. '7' => 'module 7',
  334. '8' => 'module 8',
  335. '9' => 'module 9',
  336. 'search' => 'module search'
  337. );
  338. //layout
  339. $my_meta->addSelect('tdc_layout', $td_module_list, array('name'=> __('Layout ','tax-meta'), 'std'=> array('')));
  340.  
  341. //sidebar position:
  342. $my_meta->addSelect('tdc_sidebar_pos', array(
  343. '' => ' - default - ',
  344. 'sidebar_right' => 'Right sidebar',
  345. 'sidebar_left' => 'Left sidebar',
  346. 'no_sidebar' => 'No sidebar'
  347. ), array('name' => __('Sidebar position ','tax-meta'), 'std'=> array('')));
  348.  
  349. //category sidebar
  350. $currentSidebars = td_util::get_option('sidebars'); //read the sidebars
  351. $categorySidebar = array();
  352.  
  353. $categorySidebar[''] = ' - default sidebar - ';
  354. if (!empty($currentSidebars)) {
  355. foreach ($currentSidebars as $sidebar) {
  356. $categorySidebar[$sidebar] = $sidebar;
  357. }
  358. }
  359.  
  360. if (count($categorySidebar) > 0) {
  361. $my_meta->addSelect('tdc_sidebar_name', $categorySidebar, array('name'=> __('Category sidebar','tax-meta'), 'std'=> array('')));
  362. }
  363.  
  364.  
  365. //slider
  366. $my_meta->addSelect('tdc_slider', array(
  367. ''=>' - small slider - ',
  368. 'hide_slider'=> 'hide slider'
  369. ), array('name'=> __('Show featured slider on category ','tax-meta'), 'std'=> array('')));
  370.  
  371. //Category color
  372. $my_meta->addColor('tdc_color', array('name'=> __('Category color ','tax-meta')));
  373.  
  374. //background image
  375. $my_meta->addImage('tdc_image', array('name'=> __('Category background ','tax-meta')));
  376. $my_meta->addSelect('tdc_bg_repeat', array(
  377. ''=>' - Stretch - ',
  378. 'tile'=>'Tile'
  379. ),array('name'=> __('background style ','tax-meta'), 'std'=> array('')));
  380.  
  381. //Category background color
  382. $my_meta->addColor('tdc_bg_color', array('name'=> __('Category background color ','tax-meta')));
  383.  
  384.  
  385.  
  386.  
  387. $my_meta->addSelect('tdc_hide_on_post', array(''=> 'show on post', 'hide'=>'Hide on post'),array('name'=> __('Hide on post ','tax-meta'), 'std'=> array('')));
  388.  
  389. $my_meta->Finish();
  390. }
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399. /* ----------------------------------------------------------------------------
  400. page view counter
  401. */
  402.  
  403. remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
  404.  
  405.  
  406.  
  407. /* ----------------------------------------------------------------------------
  408. archive widget - add current class
  409. */
  410. function theme_get_archives_link ( $link_html ) {
  411. global $wp;
  412. static $current_url;
  413. if ( empty( $current_url ) ) {
  414. $current_url = add_query_arg( $_SERVER['QUERY_STRING'], '', home_url( $wp->request ) );
  415. }
  416. if ( stristr( $current_url, 'page' ) !== false ) {
  417. $current_url = substr($current_url, 0, strrpos($current_url, 'page'));
  418. }
  419. if ( stristr( $link_html, $current_url ) !== false ) {
  420. $link_html = preg_replace( '/(<[^\s>]+)/', '\1 class="current"', $link_html, 1 );
  421. }
  422. return $link_html;
  423. }
  424. add_filter('get_archives_link', 'theme_get_archives_link');
  425.  
  426.  
  427.  
  428. /* ----------------------------------------------------------------------------
  429. add span wrap for category number in widget
  430. */
  431.  
  432. add_filter('wp_list_categories', 'cat_count_span');
  433. function cat_count_span($links) {
  434. $links = str_replace('</a> (', '<span class="td-widget-no">', $links);
  435. $links = str_replace(')', '</span></a>', $links);
  436. return $links;
  437. }
  438.  
  439. //fix archives widget
  440. add_filter('get_archives_link', 'archive_count_no_brackets');
  441. function archive_count_no_brackets($links) {
  442. $links = str_replace('</a>&nbsp;(', '<span class="td-widget-no">', $links);
  443. $links = str_replace(')', '</span></a>', $links);
  444. return $links;
  445. }
  446.  
  447.  
  448. //remove gallery style css
  449. add_filter( 'use_default_gallery_style', '__return_false' );
  450.  
  451.  
  452.  
  453. function remove_more_link_scroll( $link ) {
  454.  
  455. $link = preg_replace( '|#more-[0-9]+|', '', $link );
  456.  
  457. $link = '<div class="more-link-wrap wpb_button wpb_btn-danger">' . $link . '</div>';
  458. return $link;
  459. }
  460. add_filter( 'the_content_more_link', 'remove_more_link_scroll' );
  461.  
  462.  
  463.  
  464. /* ----------------------------------------------------------------------------
  465. excerpt lenght
  466. */
  467.  
  468. add_filter('excerpt_length', 'my_excerpt_length');
  469. function my_excerpt_length($length) {
  470. $excerpt_length = td_util::get_option('tds_wp_default_excerpt');
  471. if (!empty($excerpt_length) and is_numeric($excerpt_length)) {
  472. return $excerpt_length;
  473. } else {
  474. return 22; //default
  475. }
  476. }
  477.  
  478.  
  479.  
  480. /* ----------------------------------------------------------------------------
  481. more text
  482. */
  483.  
  484. add_filter('excerpt_more', 'new_excerpt_more');
  485. function new_excerpt_more($text){
  486. return ' ';
  487. }
  488.  
  489.  
  490.  
  491. /* ----------------------------------------------------------------------------
  492. editor style
  493. */
  494.  
  495. add_editor_style();
  496.  
  497.  
  498.  
  499. /* ----------------------------------------------------------------------------
  500. thumbnails
  501. */
  502.  
  503. //the image sizes that we use
  504. add_theme_support( 'post-thumbnails' );
  505.  
  506. //featured image
  507. $td_crop_features_image = td_util::get_customizer_option('crop_features_image');
  508. if ($td_crop_features_image == '') {
  509. add_image_size('featured-image', 700, 0, true);
  510. } else {
  511. add_image_size('featured-image', 700, 357, true);
  512. }
  513.  
  514. //the small thumbnails
  515. set_post_thumbnail_size( 100, 65, true );
  516. add_image_size('art-thumb', 100, 65, true);
  517.  
  518. //small height, 1 col wide
  519. add_image_size('art-wide', 326, 159, true);
  520.  
  521. //medium height 1 col wide
  522. add_image_size('art-big-1col', 326, 235, true);
  523.  
  524. //the slides
  525. add_image_size('art-slide-small', 326, 406, true);
  526. add_image_size('art-slide-med', 700, 357, true);
  527. add_image_size('art-slide-big', 1074, 483, true);
  528.  
  529. //big slider - big image
  530. add_image_size('art-slidebig-main', 745, 483, true);
  531.  
  532. //the gallery
  533. add_image_size('art-gal', 210, 210, true);
  534.  
  535.  
  536.  
  537. /* ----------------------------------------------------------------------------
  538. Post formats
  539. */
  540.  
  541. add_theme_support('post-formats', array('gallery', 'video', 'link', 'quote'));
  542.  
  543.  
  544.  
  545. /* ----------------------------------------------------------------------------
  546. localization
  547. */
  548.  
  549. function my_theme_setup(){
  550. load_theme_textdomain(TD_THEME_NAME, get_template_directory() . '/languages');
  551. }
  552. add_action('after_setup_theme', 'my_theme_setup');
  553.  
  554.  
  555.  
  556. /* ----------------------------------------------------------------------------
  557. shortcodes in widgets
  558. */
  559.  
  560. add_filter('widget_text', 'do_shortcode');
  561.  
  562.  
  563.  
  564. /* ----------------------------------------------------------------------------
  565. content width
  566. */
  567.  
  568. if (!isset($content_width)) {
  569. $content_width = 700;
  570. }
  571.  
  572.  
  573.  
  574. /* ----------------------------------------------------------------------------
  575. rss supporrt
  576. */
  577.  
  578. add_theme_support('automatic-feed-links');
  579.  
  580.  
  581.  
  582. /* ----------------------------------------------------------------------------
  583. Register the themes default menus
  584. */
  585.  
  586. add_filter('wp_nav_menu_objects', 'my_nav_menu_objects_shortcode_mangler', 11);
  587.  
  588.  
  589. //do shortcodes in menu
  590. function my_nav_menu_objects_shortcode_mangler($items) {
  591. $td_is_firstMenu = true;
  592. foreach ($items as $item) {
  593. if ($td_is_firstMenu) {
  594. $item->classes[] = 'menu-item-first';
  595. $td_is_firstMenu = false;
  596. }
  597. if (strpos($item->title,'[') === false) {
  598.  
  599. } else {
  600. //on shortcodes [home] etc.. do not show down arrow
  601. //print_r($item);
  602. $item->classes[] = 'td-no-down-arrow';
  603. }
  604.  
  605. $item->title = do_shortcode($item->title);
  606. }
  607. return $items;
  608. }
  609.  
  610.  
  611.  
  612. function register_my_menus() {
  613. register_nav_menus(
  614. array(
  615. 'top-menu' => __( 'Top Header Menu', TD_THEME_NAME),
  616. 'header-menu' => __( 'Header Menu (main)', TD_THEME_NAME),
  617. 'footer-menu' => __( 'Footer Menu', TD_THEME_NAME)
  618. )
  619. );
  620. }
  621. add_action( 'init', 'register_my_menus' );
  622.  
  623.  
  624.  
  625. /* ----------------------------------------------------------------------------
  626. Register the themes default sidebars + dinamic ones
  627. */
  628.  
  629. //register the default sidebar
  630. register_sidebar(array(
  631. 'name'=> TD_THEME_NAME . ' default',
  632. 'id' => 'td-default', //the id is used by the importer
  633. 'before_widget' => '<aside class="widget %2$s">',
  634. 'after_widget' => '</aside>',
  635. 'before_title' => '<div class="block-title"><span>',
  636. 'after_title' => '</span></div>'
  637. ));
  638.  
  639. register_sidebar(array(
  640. 'name'=>'Top right (social)',
  641. 'id' => 'td-top-right',
  642. 'before_widget' => '',
  643. 'after_widget' => '',
  644. 'before_title' => '',
  645. 'after_title' => '',
  646. ));
  647.  
  648. register_sidebar(array(
  649. 'name'=>'Footer 1',
  650. 'id' => 'td-footer-1',
  651. 'before_widget' => '<aside class="widget %2$s">',
  652. 'after_widget' => '</aside>',
  653. 'before_title' => '<div class="block-title"><span>',
  654. 'after_title' => '</span></div>'
  655. ));
  656.  
  657. register_sidebar(array(
  658. 'name'=>'Footer 2',
  659. 'id' => 'td-footer-2',
  660. 'before_widget' => '<aside class="widget %2$s">',
  661. 'after_widget' => '</aside>',
  662. 'before_title' => '<div class="block-title"><span>',
  663. 'after_title' => '</span></div>'
  664. ));
  665.  
  666. register_sidebar(array(
  667. 'name'=>'Footer 3',
  668. 'id' => 'td-footer-3',
  669. 'before_widget' => '<aside class="widget %2$s">',
  670. 'after_widget' => '</aside>',
  671. 'before_title' => '<div class="block-title"><span>',
  672. 'after_title' => '</span></div>'
  673. ));
  674.  
  675.  
  676.  
  677. //get our custom dynamic sidebars
  678. $currentSidebars = td_util::get_option('sidebars');
  679.  
  680. //if we have user made sidebars, register them in wp
  681. if (!empty($currentSidebars)) {
  682. foreach ($currentSidebars as $sidebar) {
  683. register_sidebar(array(
  684. 'name'=>$sidebar,
  685. 'id' => 'td-' . td_util::sidebar_name_to_id($sidebar),
  686. 'before_widget' => '<aside class="widget %2$s">',
  687. 'after_widget' => '</aside>',
  688. 'before_title' => '<div class="block-title"><span>',
  689. 'after_title' => '</span></div>',
  690. ));
  691.  
  692. } //end foreach
  693. }
  694.  
  695.  
  696. /* -----------------------------------------------------------------------------
  697. WP-ADMIN section
  698. */
  699.  
  700.  
  701.  
  702. /*
  703. * the wp-admin panels
  704. */
  705.  
  706. require_once('wp-admin/td_mvc/td_controller.php');
  707.  
  708. /*
  709. * the wp-admin TinyMCE editor buttons
  710. */
  711. require_once('wp-admin/tinymce/tinymce.php');
  712.  
  713.  
  714. /*
  715. * Custom content metaboxes (the select sidebar dropdown/post etc)
  716. */
  717. require_once ('wp-admin/content-metaboxes/td_templates_settings.php');
  718.  
  719.  
  720.  
  721.  
  722.  
  723. //the bottom code for analytics and stuff
  724. function td_bottom_code() {
  725. $td_analytics = td_util::get_option('td_analytics');
  726. echo stripslashes($td_analytics);
  727. echo '
  728.  
  729. <!--
  730. Theme: ' . TD_THEME_NAME .' by tagDiv 2013
  731. Version: ' . TD_THEME_VERSION . ' (rara)
  732. Deploy mode: ' . TD_DEPLOY_MODE . '
  733. -->
  734.  
  735. ';
  736.  
  737.  
  738. $authorMetaGoogle = get_the_author_meta('googleplus');
  739. if (!empty($authorMetaGoogle)) {
  740. echo '<a href="' . $authorMetaGoogle . '?rel=author"></a>';
  741. }
  742. }
  743. add_action('wp_footer', 'td_bottom_code');
  744.  
  745.  
  746.  
  747.  
  748.  
  749. //Append page slugs to the body class
  750. function add_slug_to_body_class( $classes ) {
  751. global $post;
  752. if( is_home() ) {
  753. $key = array_search( 'blog', $classes );
  754. if($key > -1) {
  755. unset( $classes[$key] );
  756. };
  757. } elseif( is_page() ) {
  758. $classes[] = sanitize_html_class( $post->post_name );
  759. } elseif(is_singular()) {
  760. $classes[] = sanitize_html_class( $post->post_name );
  761. };
  762.  
  763.  
  764. $i = 0;
  765. foreach ($classes as $key => $value) {
  766. $pos = strripos($value, 'span');
  767. if ($pos !== false) {
  768. unset($classes[$i]);
  769. }
  770.  
  771. $pos = strripos($value, 'row');
  772. if ($pos !== false) {
  773. unset($classes[$i]);
  774. }
  775.  
  776. $pos = strripos($value, 'container');
  777. if ($pos !== false) {
  778. unset($classes[$i]);
  779. }
  780. $i++;
  781. }
  782. return $classes;
  783. }
  784. add_filter('body_class', 'add_slug_to_body_class');
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791. //remove span row container classes from post_class()
  792. function add_slug_to_post_class( $classes ) {
  793. $i = 0;
  794. foreach ($classes as $key => $value) {
  795. $pos = strripos($value, 'span');
  796. if ($pos !== false) {
  797. unset($classes[$i]);
  798. }
  799.  
  800. $pos = strripos($value, 'row');
  801. if ($pos !== false) {
  802. unset($classes[$i]);
  803. }
  804.  
  805. $pos = strripos($value, 'container');
  806. if ($pos !== false) {
  807. unset($classes[$i]);
  808. }
  809. $i++;
  810. }
  811. return $classes;
  812. }
  813. add_filter('post_class', 'add_slug_to_post_class');
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821. /* -----------------------------------------------------------------------------
  822. TGM_Plugin_Activation
  823. */
  824. require_once dirname( __FILE__ ) . '/includes/external/class-tgm-plugin-activation.php';
  825.  
  826. add_action('tgmpa_register', 'td_required_plugins');
  827.  
  828. function td_required_plugins() {
  829.  
  830. /**
  831. * Array of plugin arrays. Required keys are name and slug.
  832. * If the source is NOT from the .org repo, then source is also required.
  833. */
  834. $plugins = array(
  835.  
  836. array(
  837. 'name' => 'tagDiv social counter', // The plugin name
  838. 'slug' => 'td-social-counter', // The plugin slug (typically the folder name)
  839. 'source' => get_template_directory_uri() . '/includes/plugins/td-social-counter.zip', // The plugin source
  840. 'required' => false, // If false, the plugin is only 'recommended' instead of required
  841. 'version' => '', // E.g. 1.0.0. If set, the active plugin must be this version or higher, otherwise a notice is presented
  842. 'force_activation' => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch
  843. 'force_deactivation' => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins
  844. 'external_url' => '', // If set, overrides default API URL and points to an external URL
  845. ),
  846. array(
  847. 'name' => 'Revolution slider', // The plugin name
  848. 'slug' => 'revslider', // The plugin slug (typically the folder name)
  849. 'source' => get_template_directory_uri() . '/includes/plugins/revslider.zip', // The plugin source
  850. 'required' => false, // If false, the plugin is only 'recommended' instead of required
  851. 'version' => '', // E.g. 1.0.0. If set, the active plugin must be this version or higher, otherwise a notice is presented
  852. 'force_activation' => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch
  853. 'force_deactivation' => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins
  854. 'external_url' => '', // If set, overrides default API URL and points to an external URL
  855. ),
  856. // This is an example of how to include a plugin from the WordPress Plugin Repository
  857. array(
  858. 'name' => 'Jetpack',
  859. 'slug' => 'jetpack',
  860. 'required' => false,
  861. ),
  862. array(
  863. 'name' => 'Animated Gif Resize',
  864. 'slug' => 'animated-gif-resize',
  865. 'required' => false,
  866. ),
  867. array(
  868. 'name' => 'Contact form 7',
  869. 'slug' => 'contact-form-7',
  870. 'required' => false,
  871. )
  872.  
  873. );
  874.  
  875. // Change this to your theme text domain, used for internationalising strings
  876. $theme_text_domain = 'tgmpa';
  877.  
  878. /**
  879. * Array of configuration settings. Amend each line as needed.
  880. * If you want the default strings to be available under your own theme domain,
  881. * leave the strings uncommented.
  882. * Some of the strings are added into a sprintf, so see the comments at the
  883. * end of each line for what each argument will be.
  884. */
  885. $config = array(
  886. 'domain' => $theme_text_domain, // Text domain - likely want to be the same as your theme.
  887. 'default_path' => '', // Default absolute path to pre-packaged plugins
  888. 'parent_menu_slug' => 'themes.php', // Default parent menu slug
  889. 'parent_url_slug' => 'themes.php', // Default parent URL slug
  890. 'menu' => 'install-required-plugins', // Menu slug
  891. 'has_notices' => true, // Show admin notices or not
  892. 'is_automatic' => false, // Automatically activate plugins after installation or not
  893. 'message' => '', // Message to output right before the plugins table
  894. 'strings' => array(
  895. 'page_title' => __( 'Install Required Plugins', $theme_text_domain ),
  896. 'menu_title' => __( 'Install Plugins', $theme_text_domain ),
  897. 'installing' => __( 'Installing Plugin: %s', $theme_text_domain ), // %1$s = plugin name
  898. 'oops' => __( 'Something went wrong with the plugin API.', $theme_text_domain ),
  899. 'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.' ), // %1$s = plugin name(s)
  900. 'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.' ), // %1$s = plugin name(s)
  901. 'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.' ), // %1$s = plugin name(s)
  902. 'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.' ), // %1$s = plugin name(s)
  903. 'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.' ), // %1$s = plugin name(s)
  904. 'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.' ), // %1$s = plugin name(s)
  905. 'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.' ), // %1$s = plugin name(s)
  906. 'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.' ), // %1$s = plugin name(s)
  907. 'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins' ),
  908. 'activate_link' => _n_noop( 'Activate installed plugin', 'Activate installed plugins' ),
  909. 'return' => __( 'Return to Required Plugins Installer', $theme_text_domain ),
  910. 'plugin_activated' => __( 'Plugin activated successfully.', $theme_text_domain ),
  911. 'complete' => __( 'All plugins installed and activated successfully. %s', $theme_text_domain ), // %1$s = dashboard link
  912. 'nag_type' => 'updated' // Determines admin notice type - can only be 'updated' or 'error'
  913. )
  914. );
  915.  
  916. tgmpa( $plugins, $config );
  917.  
  918. }
  919.  
  920.  
  921.  
  922. /* -----------------------------------------------------------------------------
  923. Our custom admin bar
  924. */
  925. add_action('admin_bar_menu', 'td_custom_menu', 1000);
  926. function td_custom_menu() {
  927. global $wp_admin_bar;
  928. if(!is_super_admin() || !is_admin_bar_showing()) return;
  929.  
  930. $wp_admin_bar->add_menu(array(
  931. 'parent' => 'site-name',
  932. 'title' => 'Theme - options',
  933. 'href' => admin_url('themes.php?page=td_controller'),
  934. 'id' => 'td-menu1'
  935. ));
  936.  
  937.  
  938. $wp_admin_bar->add_menu(array(
  939. 'parent' => 'site-name',
  940. 'title' => 'Theme - sidebars',
  941. 'href' => admin_url('themes.php?page=td_controller.php&td_page=sidebars'),
  942. 'id' => 'td-menu2'
  943. ));
  944.  
  945.  
  946. $wp_admin_bar->add_menu(array(
  947. 'parent' => 'site-name',
  948. 'title' => 'Theme - translation',
  949. 'href' => admin_url('themes.php?page=td_controller.php&td_page=translate'),
  950. 'id' => 'td-menu3'
  951. ));
  952.  
  953.  
  954. $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  955. $wp_admin_bar->add_menu(array(
  956. 'parent' => 'site-name',
  957. 'title' => '<span class="td-admin-bar-red">Theme - customizer</span>',
  958. 'href' => add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() ),
  959. //'href' => admin_url('customize.php'),
  960. 'id' => 'customize'
  961. ));
  962.  
  963. $wp_admin_bar->add_menu( array(
  964. 'id' => 'our_support_item',
  965. 'meta' => array('title' => 'Theme support', 'target' => '_blank'),
  966. 'title' => 'Theme support',
  967. 'href' => 'http://forum.tagdiv.com' ));
  968.  
  969. }
  970.  
  971.  
  972. /* -----------------------------------------------------------------------------
  973. Woo commerce
  974. */
  975.  
  976. if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' )))) { // check if we have woo commerce installed
  977. // breadcrumb
  978. add_filter( 'woocommerce_breadcrumb_defaults', 'td_woocommerce_breadcrumbs' );
  979.  
  980. function td_woocommerce_breadcrumbs() {
  981. return array(
  982. 'delimiter' => ' <span class="td-sp td-sp-breadcrumb-arrow td-bread-sep"></span> ',
  983. 'wrap_before' => '<div class="entry-crumbs" itemprop="breadcrumb">',
  984. 'wrap_after' => '</div>',
  985. 'before' => '',
  986. 'after' => '',
  987. 'home' => _x( 'Home', 'breadcrumb', 'woocommerce' ),
  988. );
  989. }
  990.  
  991. // number of products to display on shop page
  992. add_filter('loop_shop_per_page', create_function('$cols', 'return 8;'));
  993.  
  994.  
  995.  
  996. if (!function_exists('woocommerce_pagination')) {
  997. // pagination
  998. function woocommerce_pagination(){
  999. echo td_page_generator::get_pagination();
  1000. }
  1001. }
  1002.  
  1003.  
  1004. if (!function_exists('woocommerce_output_related_products')) {
  1005. // number of related product
  1006. function woocommerce_output_related_products() {
  1007. woocommerce_related_products(4,4); // Display 4 products in rows of 4
  1008. }
  1009. }
  1010. }
  1011.  
  1012.  
  1013.  
  1014. /**
  1015. * Add prev and next links to a numbered link list - the pagination on single.
  1016. */
  1017. function wp_link_pages_args_prevnext_add($args)
  1018. {
  1019. global $page, $numpages, $more, $pagenow;
  1020.  
  1021. if (!$args['next_or_number'] == 'next_and_number')
  1022. return $args; # exit early
  1023.  
  1024. $args['next_or_number'] = 'number'; # keep numbering for the main part
  1025. if (!$more)
  1026. return $args; # exit early
  1027.  
  1028. if($page-1) # there is a previous page
  1029. $args['before'] .= _wp_link_page($page-1)
  1030. . $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a>'
  1031. ;
  1032.  
  1033. if ($page<$numpages) # there is a next page
  1034. $args['after'] = _wp_link_page($page+1)
  1035. . $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . '</a>'
  1036. . $args['after']
  1037. ;
  1038.  
  1039. return $args;
  1040. }
  1041. add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add');
  1042. add_theme_support('woocommerce');
Advertisement
Add Comment
Please, Sign In to add comment