PageRenderTime 475ms CodeModel.GetById 57ms RepoModel.GetById 0ms app.codeStats 0ms

/andante/theme/andante/functions.php

https://gitlab.com/gthemes/andante_wp
PHP | 705 lines | 336 code | 154 blank | 215 comment | 59 complexity | d9155c5f163aef53bcca2dc772448072 MD5 | raw file
  1. <?php
  2. // Reporting E_NOTICE can be good too (to report uninitialized
  3. // variables or catch variable name misspellings ...)
  4. // error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
  5. /*
  6. *------------------------------------------------------------------------------------------------
  7. * Theme Setup
  8. *------------------------------------------------------------------------------------------------
  9. *
  10. * Do some stuff after installing the theme.
  11. *
  12. */
  13. function yo_theme_setup()
  14. {
  15. //----------------------------------------------------------------------------------------
  16. // Languages
  17. //----------------------------------------------------------------------------------------
  18. load_theme_textdomain('theme_admin', get_template_directory() . '/languages');
  19. $locale = get_locale();
  20. $locale_file = get_template_directory() . "/languages/$locale.php";
  21. if (is_readable($locale_file))
  22. require_once($locale_file);
  23. //----------------------------------------------------------------------------------------
  24. // Menus
  25. //----------------------------------------------------------------------------------------
  26. register_nav_menus(array(
  27. 'primary' => __('Main Menu', 'theme_admin'),
  28. // 'side' => __('Side Menu', 'theme_admin')
  29. ));
  30. //----------------------------------------------------------------------------------------
  31. // Post Formats (WP3.1+)
  32. //----------------------------------------------------------------------------------------
  33. $formats = array(/*'aside',*/ 'audio', 'gallery', 'image', 'link', 'quote', 'video', 'status');
  34. add_theme_support('post-formats', $formats);
  35. //----------------------------------------------------------------------------------------
  36. // Thumbnails (Custom sizes)
  37. //----------------------------------------------------------------------------------------
  38. add_theme_support('post-thumbnails');
  39. set_post_thumbnail_size( 83, 55, true ); // Normal post thumbnails
  40. // add_image_size('single-post', 400, false, true); // Blog post
  41. add_image_size('full-width', 1124, false, true); // Home slider images
  42. add_image_size('portfolio-details', 744, false, true); // Portfolio details page
  43. add_image_size('portfolio-4-columns', 269, false, true); // Portfolio overview with 4 columns
  44. add_image_size('portfolio-3-columns', 364, false, true); // ... 3 columns & Single post page
  45. add_image_size('portfolio-2-columns', 554, false, true); // ... 2 columns
  46. //----------------------------------------------------------------------------------------
  47. // Custom Headers (WP3.4+)
  48. //----------------------------------------------------------------------------------------
  49. // $headers = array(
  50. // The height and width of our custom header.
  51. // 'width' => apply_filters( 'yo_header_image_width', 1124 ),
  52. // 'height' => apply_filters( 'yo_header_image_height', 550 ),
  53. // 'flex-height' => true,
  54. // 'default-image' => get_template_directory_uri() . '/img/headers/header_1.jpg',
  55. // 'uploads' => true,
  56. // Callback for styling the header.
  57. // 'wp-head-callback' => 'twentyeleven_header_style',
  58. // Callback for styling the header preview in the admin.
  59. // 'admin-head-callback' => 'twentyeleven_admin_header_style',
  60. // Callback used to display the header preview in the admin.
  61. // 'admin-preview-callback' => 'twentyeleven_admin_header_image',
  62. // );
  63. // add_theme_support('custom-header', $headers);
  64. // Default custom headers included with the theme.
  65. // register_default_headers(array(
  66. // 'Green' => array(
  67. // 'url' => '%s/img/headers/header_1.jpg',
  68. // 'thumbnail_url' => '%s/img/admin/dark.jpg',
  69. // 'description' => __('Green', 'theme_admin')
  70. // ),
  71. // 'Forest' => array(
  72. // 'url' => '%s/img/headers/header_2.jpg',
  73. // 'thumbnail_url' => '%s/img/admin/forest.jpg',
  74. // 'description' => __('Forest', 'theme_admin')
  75. // ),
  76. // ));
  77. //----------------------------------------------------------------------------------------
  78. // Custom Backgrounds (WP3.4+)
  79. //----------------------------------------------------------------------------------------
  80. $backgrounds = array(
  81. 'default-color' => '000',
  82. 'default-image' => get_template_directory_uri() . '/img/content/background.png',
  83. // 'wp-head-callback' => '_custom_background_cb',
  84. // 'admin-head-callback' => '',
  85. // 'admin-preview-callback' => ''
  86. );
  87. // add_theme_support('custom-background', $backgrounds);
  88. //----------------------------------------------------------------------------------------
  89. // Add default posts and comments RSS feed links to <head>.
  90. //----------------------------------------------------------------------------------------
  91. add_theme_support('automatic-feed-links');
  92. //----------------------------------------------------------------------------------------
  93. // TinyMCE Style
  94. //----------------------------------------------------------------------------------------
  95. // Customize the visual editor style with editor-style.css to match the theme style.
  96. // add_editor_style('style.css');
  97. }
  98. add_action('after_setup_theme', 'yo_theme_setup');
  99. /*
  100. *------------------------------------------------------------------------------------------------
  101. * Admin bar Menu Items
  102. *------------------------------------------------------------------------------------------------
  103. *
  104. * Add some items to the admin menu, like the theme-options link to quickly customize the theme.
  105. *
  106. */
  107. function admin_menu_items($admin_bar)
  108. {
  109. $args = array(
  110. 'id' => 'theme-options',
  111. 'title' => __('Theme Options', 'theme_admin'),
  112. 'href' => site_url() .'/wp-admin/themes.php?page=yo-theme-options',
  113. 'meta' => array('title' => __('Click to edit the theme options', 'theme_admin'))
  114. );
  115. $admin_bar->add_menu($args);
  116. }
  117. add_action('admin_bar_menu', 'admin_menu_items', 100);
  118. /*
  119. *------------------------------------------------------------------------------------------------
  120. * Register Widgets (Sidebars)
  121. *------------------------------------------------------------------------------------------------
  122. *
  123. * These are the widget areas that can be customized in the Admin section (Appearance > Widgets).
  124. *
  125. */
  126. function yo_widgets_init()
  127. {
  128. // Portfolio Widget
  129. include_once('library/widget-portfolio.php');
  130. register_widget('Projects_Widget');
  131. // Better Recent Posts Widget
  132. include_once('library/widget-recent-posts.php');
  133. register_widget('YO_Better_Recent_Posts');
  134. // Latest tweets Widget
  135. include_once('library/widget-twitter.php');
  136. register_widget('YO_Twitter_Widget');
  137. // Flickr Widget
  138. include_once('library/widget-flickr.php');
  139. register_widget('YO_Hey_Its_Flickr');
  140. register_sidebar(array(
  141. 'name' => 'Sidebar',
  142. 'id' => 'siderbar',
  143. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  144. 'after_widget' => '</div>',
  145. 'before_title' => '<h3 class="widget-title">',
  146. 'after_title' => '</h3>'));
  147. register_sidebar(array(
  148. 'name' => 'Below Home Slideshow',
  149. 'id' => 'below-slideshow-widgets',
  150. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  151. 'after_widget' => '</div>',
  152. 'before_title' => '<h3 class="widget-title">',
  153. 'after_title' => '</h3><div class="hr_small"></div>'));
  154. register_sidebar(array(
  155. 'name' => 'Above Footer',
  156. 'id' => 'above-footer-widgets',
  157. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  158. 'after_widget' => '</div>',
  159. 'before_title' => '<h3 class="widget-title">',
  160. 'after_title' => '</h3><div class="hr_small"></div>'));
  161. register_sidebar(array(
  162. 'name' => 'Footer',
  163. 'id' => 'footer-widgets',
  164. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  165. 'after_widget' => '</div>',
  166. 'before_title' => '<h3 class="widget-title">',
  167. 'after_title' => '</h3><div class="hr_small"></div>'));
  168. }
  169. add_action('widgets_init', 'yo_widgets_init');
  170. /*
  171. *------------------------------------------------------------------------------------------------
  172. * Theme Notices & Plugins Install
  173. *------------------------------------------------------------------------------------------------
  174. *
  175. */
  176. // TODO: check the installed plugins here
  177. // if ( ! function_exists('some_plugin_function') && current_user_can('install_plugins'))
  178. if (current_user_can('install_plugins'))
  179. {
  180. /* Display a notice that can be dismissed */
  181. // add_action('admin_notices', 'yo_install_plugin_notice');
  182. function yo_install_plugin_notice()
  183. {
  184. $screen = get_current_screen();
  185. global $current_user;
  186. $user_id = $current_user->ID;
  187. /* Check that the user hasn't already clicked to ignore the message */
  188. if ( ! get_user_meta($user_id, 'yo_install_plugin_notice')) {
  189. add_thickbox();
  190. if ($screen->base != 'appearance_page_yo-shortcodes')
  191. {
  192. echo '<div class="updated"><p>';
  193. printf(__('If you wish to use custom post types for portfolios, please install the XXX Plugin. <a href="%1$s" class="thickbox onclick">Install Now</a> | <a href="%2$s">Hide Notice</a>', 'theme_admin'), admin_url() . 'plugin-install.php?tab=plugin-information&plugin=plugin-name&TB_iframe=true&width=640&height=517', '?example_nag_ignore=0');
  194. echo '</p></div>';
  195. }
  196. }
  197. }
  198. // add_action('admin_init', 'yo_post_plugin_ignore');
  199. function yo_post_plugin_ignore()
  200. {
  201. global $current_user;
  202. $user_id = $current_user->ID;
  203. /* If user clicks to ignore the notice, add that to their user meta */
  204. if (isset( $_GET['example_nag_ignore']) && '0' == $_GET['example_nag_ignore']) {
  205. add_user_meta($user_id, 'example_ignore_notice', 'true', true);
  206. }
  207. }
  208. }
  209. /*
  210. *------------------------------------------------------------------------------------------------
  211. * Yow Framework
  212. *------------------------------------------------------------------------------------------------
  213. *
  214. * Initalize the Yow Framework.
  215. * In the admin it makes the meta box and theme options fields available, while in the front-end
  216. * it fetches the stored data to use in theme pages.
  217. *
  218. */
  219. include('admin/init.php');
  220. /*
  221. *------------------------------------------------------------------------------------------------
  222. * Load utilities and custom elements
  223. *------------------------------------------------------------------------------------------------
  224. *
  225. */
  226. // Load useful helper functions
  227. include('library/utilities.php');
  228. // if (is_admin())
  229. // {
  230. // Add custom post type 'Portfolio'. It includes its meta boxes setup.
  231. include('library/type-portfolio.php');
  232. // Load the theme options
  233. include('library/theme-options.php');
  234. // }
  235. // Load the 'Menu Walker' class
  236. include('library/walker.php');
  237. // Load the Shortcodes
  238. include('library/shortcodes.php');
  239. /*
  240. *------------------------------------------------------------------------------------------------
  241. * Enqueue CSS & Javascript in the frontend
  242. *------------------------------------------------------------------------------------------------
  243. *
  244. */
  245. // Enqueue scripts
  246. function yo_enqueue_scripts()
  247. {
  248. // <!-- Stylesheets -->
  249. // <link href='http://fonts.googleapis.com/css?family=Armata' rel='stylesheet' type='text/css'>
  250. // <link rel="stylesheet" href="/normalize.css">
  251. // <link rel="stylesheet" href="grid.css">
  252. // <link rel="stylesheet" href="flexslider.css">
  253. // <link rel="stylesheet" href="prettyPhoto.css">
  254. // <link rel="stylesheet" href="">
  255. // <!-- Custom Modernizr -->
  256. // <script src="/js/libs/modernizr.custom.min.js"></script>
  257. if (is_singular() && comments_open() && get_option('thread_comments'))
  258. wp_enqueue_script('comment-reply');
  259. wp_enqueue_style('yo-armata', 'http://fonts.googleapis.com/css?family=Armata');
  260. wp_enqueue_style('yo-normalize', get_template_directory_uri().'/normalize.css', false, YO_VER);
  261. wp_enqueue_style('yo-grid', get_template_directory_uri().'/grid.css', false, YO_VER);
  262. wp_enqueue_style('yo-slider', get_template_directory_uri().'/flexslider.css', false, YO_VER);
  263. wp_enqueue_style('yo-lightbox', get_template_directory_uri().'/prettyPhoto.css', false, YO_VER);
  264. wp_enqueue_style('yo-style', get_template_directory_uri().'/style.css', false, YO_VER);
  265. // Main Javascript
  266. wp_register_script( 'yo-modernizr', get_template_directory_uri().'/js/libs/modernizr.custom.min.js', false, YO_VER);
  267. wp_register_script( 'yo-plugins', get_template_directory_uri().'/js/plugins.js', array('jquery'), YO_VER);
  268. wp_register_script( 'yo-script', get_template_directory_uri().'/js/script.js', array('jquery', 'yo-plugins'), YO_VER);
  269. wp_localize_script('yo-script', 'contact_data', array('ajaxurl' => admin_url('admin-ajax.php'), 'thank_you' => __('Thank you for contacting us!', 'theme_admin')));
  270. wp_enqueue_script( 'yo-modernizr' );
  271. wp_enqueue_script( 'yo-script' );
  272. // wp_enqueue_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', false, YO_VER);
  273. //wp_enqueue_script('yo-modernizr', get_template_directory_uri().'/js/libs/modernizr.custom.min.js', false, YO_VER);
  274. //wp_enqueue_script('yo-plugins', get_template_directory_uri().'/js/plugins.js', array('jquery'), YO_VER);
  275. //wp_enqueue_script('yo-script', get_template_directory_uri().'/js/script.js', array('jquery'), YO_VER);
  276. // Enqueue the skin CSS file chosen in the theme options (if any)
  277. $style_options = get_field('style_options', 'option');
  278. if ($style_options == 'skins')
  279. {
  280. $color_scheme = get_field('color_scheme', 'option');
  281. if ( ! empty($color_scheme) && $color_scheme != 'dark')
  282. wp_enqueue_style('yo-color-scheme', get_template_directory_uri().'/style_'.$color_scheme.'.css', false, YO_VER);
  283. }
  284. }
  285. add_action('wp_enqueue_scripts', 'yo_enqueue_scripts');
  286. /*
  287. *------------------------------------------------------------------------------------------------
  288. * Embed dynamic HTML, CSS & Javascript in the backend or frontend.
  289. *------------------------------------------------------------------------------------------------
  290. *
  291. */
  292. // BACKEND
  293. if (is_admin() && ( ! defined('DOING_AJAX') || ! DOING_AJAX))
  294. {
  295. }
  296. // FRONTEND
  297. else
  298. {
  299. // Embed custom styles
  300. // $style_options = get_field('style_options', 'option');
  301. if (get_field('style_options', 'option') == 'custom')
  302. {
  303. $body = '';
  304. // Background
  305. $background = get_field('background', 'option');
  306. // Body background image
  307. if ( ! empty($background['image']))
  308. $body .= 'background-image: url("'.get_the_image($background['image']).'");';
  309. // Body background color
  310. if ( ! empty($background['color']))
  311. $body .= 'background-color: '.$background['color'].';';
  312. // Body background repeat
  313. if ( ! empty($background['repeat']))
  314. $body .= 'background-repeat: '.$background['repeat'].';';
  315. // Body background position
  316. if ( ! empty($background['position']))
  317. $body .= 'background-position: '.$background['position'].';';
  318. // Body text
  319. $body_text = get_field('body_text', 'option');
  320. // Body text color
  321. if ( ! empty($body_text['color']))
  322. $body .= 'color: '.$body_text['color'].';';
  323. // Embed the body styles
  324. if ( ! empty($body))
  325. yo_css('body { '.$body.' }');
  326. // Text shadow
  327. if ( ! empty($body_text['shadow']))
  328. yo_css('h1,h2,h3,h4,p,#tagline { text-shadow: 0 1px 0 '.$body_text['shadow'].'; }');
  329. // Links color
  330. $links = get_field('links', 'option');
  331. if ( ! empty($links['color']))
  332. yo_css('a, a:link, a:active, a:visited { color: '.$links['color'].'; }');
  333. if ( ! empty($links['hover']))
  334. yo_css('a:hover { color: '.$links['hover'].'; }');
  335. // Logo & Tagline color
  336. $branding = get_field('branding', 'option');
  337. if ( ! empty($branding['logo_color']))
  338. yo_css('#logo a, #logo a:link, #logo a:active, #logo a:visited, #logo h1 { color: '.$branding['logo_color'].'; }');
  339. if ( ! empty($branding['tagline_color']))
  340. yo_css('#tagline { color: '.$branding['tagline_color'].'; }');
  341. // Buttons color
  342. $buttons = get_field('buttons', 'option');
  343. $bg_color = ( ! empty($buttons['bg_color'])) ? 'background-color:'.$buttons['bg_color'].';' : '';
  344. $bg_hover = ( ! empty($buttons['bg_hover'])) ? 'background-color:'.$buttons['bg_hover'].';' : '';
  345. $text_color = ( ! empty($buttons['text_color'])) ? 'color:'.$buttons['text_color'].';' : '';
  346. $text_shadow = ( ! empty($buttons['text_shadow'])) ? 'text-shadow:0 1px 0 '.$buttons['text_shadow'].';' : '';
  347. yo_css('.button, a.button, button, input[type="submit"] { '.$bg_color.$text_color.$text_shadow.' }');
  348. yo_css('.button:hover, a.button:hover, button:hover, input[type="submit"]:hover { '.$bg_hover.' }');
  349. }
  350. // Retina display logo
  351. $logo2x = get_field('logo2x', 'option');
  352. if ( ! empty($logo2x))
  353. {
  354. // $logo = get_field('logo', 'option');
  355. $image_attributes = wp_get_attachment_image_src($logo2x, 'full');
  356. // yo_css('.testsetset { '.get_the_image($logo2x).' }');
  357. yo_css('@media screen and (-webkit-min-device-pixel-ratio: 2), screen and (max--moz-device-pixel-ratio: 2) {
  358. #logo a img {
  359. visibility: hidden;
  360. }
  361. #logo a {
  362. background: url('.get_the_image($logo2x).') no-repeat;
  363. background-size: '.round($image_attributes[1]/2).'px '.round($image_attributes[2]/2).'px;
  364. padding: 3px 0;
  365. }
  366. }');
  367. }
  368. // Navigation top margin
  369. $main_nav_top = get_field('main_nav_top', 'option');
  370. if ( ! empty($main_nav_top))
  371. yo_css('#main-nav { top:'.$main_nav_top.'; }');
  372. // Tracking code
  373. $tracking_code = get_field('tracking_code', 'option');
  374. if ( ! empty($main_nav_top))
  375. yo_html($tracking_code, true);
  376. // Favicon2x
  377. $favicon2x = get_field('favicon2x', 'option');
  378. if ( ! empty($favicon2x))
  379. {
  380. yo_html('<link rel="apple-touch-icon" sizes="144x144" href="'.get_the_image($favicon2x).'"/>');
  381. yo_html('<link rel="apple-touch-icon" sizes="114x114" href="'.get_the_image($favicon2x).'"/>');
  382. yo_html('<link rel="apple-touch-icon" sizes="72x72" href="'.get_the_image($favicon2x).'"/>');
  383. yo_html('<link rel="apple-touch-icon" sizes="57x57" href="'.get_the_image($favicon2x).'"/>');
  384. yo_html('<link rel="icon" sizes="32x32" href="'.get_the_image($favicon2x).'"/>');
  385. }
  386. // Favicon
  387. $favicon = get_field('favicon', 'option');
  388. if ( ! empty($favicon))
  389. yo_html('<link rel="icon" type="'.get_post_mime_type($favicon).'" href="'.get_the_image($favicon).'">');
  390. // Custom CSS
  391. $custom_css = get_field('css', 'option');
  392. if ( ! empty($custom_css))
  393. yo_css($custom_css);
  394. // Custom Javascript
  395. $custom_js = get_field('js', 'option');
  396. if ( ! empty($custom_js))
  397. yo_js($custom_js, true);
  398. }
  399. /*
  400. *------------------------------------------------------------------------------------------------
  401. * Contact Form
  402. *------------------------------------------------------------------------------------------------
  403. *
  404. */
  405. function yo_ajax_contact()
  406. {
  407. if( ! empty($_POST))
  408. {
  409. $name = stripslashes($_POST['name']);
  410. $email = trim($_POST['email']);
  411. $subject = stripslashes($_POST['subject']);
  412. $message = stripslashes($_POST['message']);
  413. $response = array();
  414. $errors = array();
  415. // Check name
  416. if(!$name)
  417. $errors['name'] = __('Please enter your name.', 'theme_admin');
  418. // Check email
  419. if(!$email)
  420. $errors['email'] = __('Please enter an e-mail address.', 'theme_admin');
  421. if($email && !is_email($email))
  422. $errors['email'] = __('Please enter a valid e-mail address.', 'theme_admin');
  423. // Check message
  424. if(!$message)
  425. $errors['message'] = __('Please leave a message.', 'theme_admin');
  426. if(empty($errors))
  427. {
  428. $contact_email = get_field('contact_email', 'theme_admin');
  429. if ( ! $contact_email) $contact_email = get_bloginfo('admin_email');
  430. $mail = mail($contact_email, $subject, $message,
  431. "From: ".$name." <".$email.">\r\n"
  432. ."Reply-To: ".$email."\r\n"
  433. ."X-Mailer: PHP/" . phpversion());
  434. if($mail)
  435. $response['success'] = true;
  436. }
  437. else
  438. {
  439. $response['success'] = false;
  440. $response['errors'] = $errors;
  441. }
  442. }
  443. // Returns the array in JSON format
  444. die(array2json($response));
  445. }
  446. add_action('wp_ajax_contact_form', 'yo_ajax_contact');
  447. add_action('wp_ajax_nopriv_contact_form', 'yo_ajax_contact');
  448. /*
  449. *------------------------------------------------------------------------------------------------
  450. * Theme Customizer Settings (WP3.4+)
  451. *------------------------------------------------------------------------------------------------
  452. *
  453. */
  454. function andante_customize_register($wp_customize)
  455. {
  456. $wp_customize->get_setting('blogname')->transport = 'postMessage';
  457. $wp_customize->get_setting('blogdescription')->transport = 'postMessage';
  458. $options = get_option(THEME_OPTIONS);
  459. $defaults = array();
  460. // Default Layout
  461. $wp_customize->add_section('andante_layout', array(
  462. 'title' => __('Layout', 'theme_admin'),
  463. 'priority' => 50,
  464. ));
  465. $wp_customize->add_setting('andante_theme_options[theme_layout]', array(
  466. 'type' => 'option',
  467. // 'default' => $defaults['theme_layout'],
  468. 'sanitize_callback' => 'sanitize_key',
  469. ));
  470. $wp_customize->add_control('andante_theme_options[theme_layout]', array(
  471. 'section' => 'andante_layout',
  472. 'type' => 'radio',
  473. 'choices' => array('a' => 'A', 'b' => 'B'),
  474. ));
  475. }
  476. // add_action('customize_register', 'andante_customize_register');
  477. $content_width = ''; // Fix for Theme-Check
  478. /*
  479. *------------------------------------------------------------------------------------------------
  480. * Debug functions
  481. *------------------------------------------------------------------------------------------------
  482. *
  483. */
  484. global $turbine_debug_stack;
  485. $turbine_debug_stack = array();
  486. // Short function d() for t_debug()
  487. if (!function_exists('d')) { function d($var, $label = '', $verbose = false, $stack = false) { t_debug($var, $label, $verbose, $stack); } }
  488. function t_debug($var, $label = '', $verbose = false, $stack = false)
  489. {
  490. // Stop execution if not in debug mode
  491. if (defined('T_DEBUG') && T_DEBUG === false) return;
  492. // Only admins can see debug messages
  493. if (!current_user_can('manage_options')) return;
  494. global $turbine_debug_stack;
  495. $t = microtime(true);
  496. $micro = sprintf("%06d",($t - floor($t)) * 1000000);
  497. $debug = '<div>';
  498. $debug .= '<h2><strong>'.$label.'</strong></h2>';
  499. $debug .= '<pre>';
  500. ob_start();
  501. if ($verbose) var_dump($var); else print_r($var);
  502. $var_content = ob_get_contents();
  503. ob_end_clean();
  504. $debug .= htmlspecialchars($var_content, ENT_QUOTES);
  505. $debug .= '</pre>';
  506. $debug .= '<small>';
  507. $debug .= '#'.count($turbine_debug_stack).' &mdash; ';
  508. $debug .= date("l jS F \@\ g:i:s.".$micro." a", microtime(true));
  509. // if (class_exists('Turbine_UI')) $debug .= ' &mdash; Called by: ' . Turbine_UI::get_caller_class();
  510. $debug .= ' &mdash; Called by: ' . t_caller_class();
  511. if ($stack) $debug .= t_call_stack(debug_backtrace());
  512. $debug .= '</small>';
  513. $debug .= '</div><br><br><br>';
  514. $turbine_debug_stack[] = $debug;
  515. }
  516. function t_print_debug()
  517. {
  518. global $turbine_debug_stack;
  519. foreach ($turbine_debug_stack as $debug)
  520. echo '<div style="background:#fff;color:#333;border-top:1px solid #333; padding:30px;">'.$debug.'</div>';
  521. }
  522. add_action('admin_footer', 't_print_debug');
  523. add_action('wp_footer', 't_print_debug');
  524. function t_call_stack($stacktrace)
  525. {
  526. $output = '<br>'.str_repeat("=", 50) .'<br>';
  527. $i = 1;
  528. foreach($stacktrace as $node) {
  529. if (isset($node['file']) && isset($node['line']))
  530. $output .= "$i. <strong>".basename($node['file']) ."</strong>: " .$node['function'] ." (#" .$node['line'].")<br>";
  531. $i++;
  532. }
  533. return $output;
  534. }
  535. function t_caller_class()
  536. {
  537. $traces = debug_backtrace();
  538. return (isset($traces[2]['class'])) ? $traces[2]['class'] : null;
  539. }
  540. function t_log($msg = '')
  541. {
  542. // Stop execution if not in debug mode
  543. if (defined('T_DEBUG') && T_DEBUG === false) return;
  544. // open file
  545. $fd = fopen(trailingslashit(realpath(dirname(__FILE__))).'turbine_log.txt', "a");
  546. //$fd = fopen(T_PATH.'turbine_log.txt', "a");
  547. // write string
  548. fwrite($fd, date("Y-m-d H:i:s").' - '.$msg . "\n");
  549. // close file
  550. fclose($fd);
  551. }