Guest User

Untitled

a guest
Oct 7th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 98.39 KB | None | 0 0
  1. Skip to content
  2. Search or jump to…
  3.  
  4. Pull requests
  5. Issues
  6. Marketplace
  7. Explore
  8.  
  9. @ncalex93
  10. 8
  11. 00opradu/td-composer Private
  12. Code Issues 12 Pull requests 0 Projects 0 Wiki Security Insights
  13. td-composer/legacy/common/wp_booster/td_wp_booster_functions.php
  14. @alinvlad alinvlad fix - tagdiv composer disable lazyload
  15. e4dc3d7 on Sep 6
  16. @nicugergely@alinvlad@cristeaioan@cristealucian@pmarius05
  17. 2710 lines (2084 sloc) 96.4 KB
  18.  
  19. <?php
  20. /**
  21. * WordPress booster V 3.1 by tagDiv
  22. */
  23. do_action('td_wp_booster_before'); //@todo is probably not used by anyone
  24. // theme utility files
  25. require_once('td_global.php');
  26. require_once('td_options.php');
  27. //td_global::$td_options = get_option(TD_THEME_OPTIONS_NAME); //read the theme settings once
  28. require_once('td_util.php');
  29. // load the wp_booster_api
  30. require_once('td_api.php');
  31. // !!!! 22.07.2016 - this should run on the td_global_after hook. BUT it should be first on that hook
  32. // I've checked td_global, td_util & td_api and it's safe to load this here for pathing the td_global::$td_options
  33. require_once('wp-admin/panel/panel_core/td_panel_data_source.php');
  34. // Was moved before 'td_global_after' hook, to allow api to get fonts
  35. require_once("td_fonts.php"); // no autoload - fonts support
  36. // hook here to use the theme api
  37. do_action('td_global_after');
  38. require_once('td_first_install.php');
  39. require_once('td_global_blocks.php'); // no autoload -
  40. require_once('td_menu.php'); // theme menu support
  41. td_api_autoload::add('td_nav_menu_edit_walker', td_global::$get_template_directory . '/legacy/common/wp_booster/td_menu_back.php');
  42. require_once('td_social_icons.php'); // no autoload (almost always needed) - The social icons
  43. require_once('td_js_buffer.php'); // no autoload - the theme always outputs JS form this buffer
  44. require_once('td_unique_posts.php'); // no autoload - unique posts (uses hooks + do_action('td_wp_boost_new_module'); )
  45. require_once('td_module.php'); // module builder
  46. require_once('td_block.php'); // block builder
  47. require_once('td_cake.php');
  48. require_once('td_js_generator.php'); // no autoload - the theme always outputs JS
  49. require_once('td_block_widget.php'); // no autoload - used to make widgets from our blocks
  50. require_once('td_background.php'); // background support - is not autoloaded due to issues
  51. require_once('td_background_render.php');
  52. require_once('td_style.php'); // - base class for block' styles
  53. require_once('td_autoload_classes.php'); //used to autoload classes [modules, blocks]
  54. // Every class after this (that has td_ in the name) is auto loaded only when it's required
  55. td_api_autoload::add('td_log', td_global::$get_template_directory . '/legacy/common/wp_booster/td_log.php');
  56. td_api_autoload::add('td_css_inline', td_global::$get_template_directory . '/legacy/common/wp_booster/td_css_inline.php');
  57. td_api_autoload::add('td_login', td_global::$get_template_directory . '/legacy/common/wp_booster/td_login.php');
  58. td_api_autoload::add('td_category_template', td_global::$get_template_directory . '/legacy/common/wp_booster/td_category_template.php');
  59. td_api_autoload::add('td_category_top_posts_style', td_global::$get_template_directory . '/legacy/common/wp_booster/td_category_top_posts_style.php');
  60. td_api_autoload::add('td_page_generator', td_global::$get_template_directory . '/legacy/common/wp_booster/td_page_generator.php'); //not used on some homepages
  61. td_api_autoload::add('td_block_layout', td_global::$get_template_directory . '/legacy/common/wp_booster/td_block_layout.php');
  62. td_api_autoload::add('td_template_layout', td_global::$get_template_directory . '/legacy/common/wp_booster/td_template_layout.php');
  63. td_api_autoload::add('td_css_compiler', td_global::$get_template_directory . '/legacy/common/wp_booster/td_css_compiler.php');
  64. td_api_autoload::add('td_css_res_compiler', td_global::$get_template_directory . '/legacy/common/wp_booster/td_css_res_compiler.php');
  65. td_api_autoload::add('td_module_single_base', td_global::$get_template_directory . '/legacy/common/wp_booster/td_module_single_base.php');
  66. td_api_autoload::add('td_smart_list', td_global::$get_template_directory . '/legacy/common/wp_booster/td_smart_list.php');
  67. td_api_autoload::add('td_remote_cache', td_global::$get_template_directory . '/legacy/common/wp_booster/td_remote_cache.php');
  68. td_api_autoload::add('td_css_buffer', td_global::$get_template_directory . '/legacy/common/wp_booster/td_css_buffer.php');
  69. td_api_autoload::add('td_data_source', td_global::$get_template_directory . '/legacy/common/wp_booster/td_data_source.php');
  70. td_api_autoload::add('td_help_pointers', td_global::$get_template_directory . '/legacy/common/wp_booster/td_help_pointers.php');
  71. td_api_autoload::add('td_block_template', td_global::$get_template_directory . '/legacy/common/wp_booster/td_block_template.php');
  72. td_api_autoload::add('td_social_sharing', td_global::$get_template_directory . '/legacy/common/wp_booster/td_social_sharing.php');
  73. /* ----------------------------------------------------------------------------
  74. * PageView support
  75. */
  76. td_api_autoload::add('td_page_views', td_global::$get_template_directory . '/legacy/common/wp_booster/td_page_views.php');
  77. add_filter('manage_post_posts_columns', array('td_page_views', 'on_manage_posts_columns_views'));
  78. add_action('manage_post_posts_custom_column', array('td_page_views', 'on_manage_posts_custom_column'), 5, 2);
  79. /* ----------------------------------------------------------------------------
  80. * JSON LD Breadcrumbs
  81. */
  82. add_action('wp_head', array('td_page_generator', 'get_breadcrumbs_json_ld'), 45);
  83. /* ----------------------------------------------------------------------------
  84. * Review support
  85. */
  86. td_api_autoload::add('td_review', td_global::$get_template_directory . '/legacy/common/wp_booster/td_review.php');
  87. add_filter('save_post', array('td_review', 'on_save_post_update_review'), 11);
  88. /* ----------------------------------------------------------------------------
  89. * Ajax support
  90. */
  91. td_api_autoload::add('td_ajax', td_global::$get_template_directory . '/legacy/common/wp_booster/td_ajax.php');
  92. // ajax: block ajax hooks
  93. add_action('wp_ajax_nopriv_td_ajax_block', array('td_ajax', 'on_ajax_block'));
  94. add_action('wp_ajax_td_ajax_block', array('td_ajax', 'on_ajax_block'));
  95. // ajax: Renders loop pagination, for now used only on categories
  96. add_action('wp_ajax_nopriv_td_ajax_loop', array('td_ajax', 'on_ajax_loop'));
  97. add_action('wp_ajax_td_ajax_loop', array('td_ajax', 'on_ajax_loop'));
  98. // ajax: site wide search
  99. add_action('wp_ajax_nopriv_td_ajax_search', array('td_ajax', 'on_ajax_search'));
  100. add_action('wp_ajax_td_ajax_search', array('td_ajax', 'on_ajax_search'));
  101. // ajax: login window login
  102. add_action('wp_ajax_nopriv_td_mod_login', array('td_ajax', 'on_ajax_login'));
  103. add_action('wp_ajax_td_mod_login', array('td_ajax', 'on_ajax_login'));
  104. // ajax: login window register
  105. add_action('wp_ajax_nopriv_td_mod_register', array('td_ajax', 'on_ajax_register'));
  106. add_action('wp_ajax_td_mod_register', array('td_ajax', 'on_ajax_register'));
  107. // ajax: login window remember pass?
  108. add_action('wp_ajax_nopriv_td_mod_remember_pass', array('td_ajax', 'on_ajax_remember_pass'));
  109. add_action('wp_ajax_td_mod_remember_pass', array('td_ajax', 'on_ajax_remember_pass'));
  110. // ajax: update views - via ajax only when enable in panel
  111. add_action('wp_ajax_nopriv_td_ajax_update_views', array('td_ajax', 'on_ajax_update_views'));
  112. add_action('wp_ajax_td_ajax_update_views', array('td_ajax', 'on_ajax_update_views'));
  113. // ajax: get views - via ajax only when enabled in panel
  114. add_action('wp_ajax_nopriv_td_ajax_get_views', array('td_ajax', 'on_ajax_get_views'));
  115. add_action('wp_ajax_td_ajax_get_views', array('td_ajax', 'on_ajax_get_views'));
  116. // Secure Ajax
  117. add_action('wp_ajax_td_ajax_new_sidebar', array('td_ajax', 'on_ajax_new_sidebar')); // ajax: admin panel - new sidebar #sec
  118. add_action('wp_ajax_td_ajax_delete_sidebar', array('td_ajax', 'on_ajax_delete_sidebar')); // ajax: admin panel - delete sidebar #sec
  119. //ajax: translation
  120. add_action('wp_ajax_td_ajax_get_translation', array('td_ajax', 'on_ajax_get_translation')); // ajax: get translations
  121. //ajax: activation
  122. add_action('wp_ajax_td_ajax_check_envato_code', array('td_ajax', 'on_ajax_check_envato_code'));
  123. add_action('wp_ajax_td_ajax_register_forum_user', array('td_ajax', 'on_ajax_register_forum_user'));
  124. add_action('wp_ajax_td_ajax_manual_activation', array('td_ajax', 'on_ajax_manual_activation'));
  125. //ajax: db check
  126. add_action('wp_ajax_td_ajax_db_check', array('td_ajax', 'on_ajax_db_check'));
  127. //ajax: theme status check
  128. add_action('wp_ajax_td_ajax_theme_status_check', array('td_ajax', 'on_ajax_check_theme_status'));
  129. //ajax: system status - TD Log - toggle status ( on/off )
  130. add_action('wp_ajax_td_ajax_system_status_toggle_td_log', array('td_ajax', 'on_ajax_system_status_toggle_td_log'));
  131. add_action('wp_ajax_nopriv_td_ajax_get_template_style', array('td_ajax', 'on_ajax_get_template_style'));
  132. add_action('wp_ajax_td_ajax_get_template_style', array('td_ajax', 'on_ajax_get_template_style'));
  133. add_action('wp_ajax_nopriv_td_render_content', array('td_ajax', 'on_ajax_render_content'));
  134. add_action('wp_ajax_td_render_content', array('td_ajax', 'on_ajax_render_content'));
  135. /**
  136. * Fix for page templates ( after the wp booster was moved to td composer the page templates select metabox stoped showing to pages admin editor )
  137. * @since tf refactor to comply with wp requirements
  138. */
  139. add_filter( 'theme_page_templates', function( $page_templates ){
  140. $page_templates = array_merge(
  141. array(
  142. 'page-pagebuilder-latest.php' => 'Pagebuilder + latest articles + pagination',
  143. 'page-pagebuilder-title.php' => 'Pagebuilder + page title',
  144. ),
  145. $page_templates
  146. );
  147. return $page_templates;
  148. });
  149. /**
  150. * This points the 'Pagebuilder + latest articles + pagination' && 'Pagebuilder + page title' page templates to the ones found in composer legacy
  151. * @since tf refactor to comply with wp requirements
  152. */
  153. add_filter( 'page_template', function( $page_template ){
  154. if ( is_page_template( 'page-pagebuilder-latest.php' ) ) {
  155. $page_template = TDC_PATH_LEGACY . '/page-pagebuilder-latest.php';
  156. } elseif ( is_page_template( 'page-pagebuilder-title.php' ) ) {
  157. $page_template = TDC_PATH_LEGACY . '/page-pagebuilder-title.php';
  158. }
  159. return $page_template;
  160. });
  161. //// !!!! MUST
  162. //add_action('wp_footer', 'td_wp_footer_debug');
  163. //function td_wp_footer_debug() {
  164. // td_api_base::_debug_show_autoloaded_components();
  165. //}
  166. if (TD_DEBUG_IOS_REDIRECT) {
  167. require_once('td_ios_redirect.php' );
  168. }
  169. // at this point it's not safe to update the Theme API because it's already used
  170. do_action('td_wp_booster_loaded'); //used by our plugins
  171. /* ----------------------------------------------------------------------------
  172. * Add theme support for features
  173. */
  174. add_theme_support('post-thumbnails');
  175. add_theme_support('automatic-feed-links');
  176. add_theme_support('html5', array('comment-list', 'comment-form', 'search-form', 'gallery', 'caption'));
  177. add_theme_support('woocommerce');
  178. add_theme_support('bbpress');
  179. //Gutenberg
  180. if ('Newspaper' === TD_THEME_NAME) {
  181. add_theme_support('align-wide');
  182. add_theme_support('align-full');
  183. add_theme_support('editor-font-sizes', array(
  184. array(
  185. 'name' => 'small',
  186. 'shortName' => 'S',
  187. 'size' => 11,
  188. 'slug' => 'small'
  189. ),
  190. array(
  191. 'name' => 'regular',
  192. 'shortName' => 'M',
  193. 'size' => 15,
  194. 'slug' => 'regular'
  195. ),
  196. array(
  197. 'name' => 'large',
  198. 'shortName' => 'L',
  199. 'size' => 32,
  200. 'slug' => 'large'
  201. ),
  202. array(
  203. 'name' => 'larger',
  204. 'shortName' => 'XL',
  205. 'size' => 50,
  206. 'slug' => 'larger'
  207. )
  208. ));
  209. } else { //Newsmag
  210. add_theme_support('editor-font-sizes', array(
  211. array(
  212. 'name' => 'small',
  213. 'shortName' => 'S',
  214. 'size' => 10,
  215. 'slug' => 'small'
  216. ),
  217. array(
  218. 'name' => 'regular',
  219. 'shortName' => 'M',
  220. 'size' => 14,
  221. 'slug' => 'regular'
  222. ),
  223. array(
  224. 'name' => 'large',
  225. 'shortName' => 'L',
  226. 'size' => 30,
  227. 'slug' => 'large'
  228. ),
  229. array(
  230. 'name' => 'larger',
  231. 'shortName' => 'XL',
  232. 'size' => 48,
  233. 'slug' => 'larger'
  234. )
  235. ));
  236. }
  237. /*
  238. * front end js composer file !!!! - check it why is this way
  239. * without this code - on newsmag the composer.min.css is loaded in footer and overwrite our style.css from head (this happens only on other pages like categoris or post - on frontpage works fine)
  240. */
  241. add_action('wp_enqueue_scripts', 'load_js_composer_front', 1000);
  242. function load_js_composer_front() {
  243. wp_enqueue_style('js_composer_front');
  244. }
  245. /* ----------------------------------------------------------------------------
  246. * front end css files
  247. */
  248. add_action('wp_enqueue_scripts', 'load_front_css', 1001); // 1001 priority because visual composer uses 1000 (1002 is for legacy)
  249. function load_front_css() {
  250. if (TD_DEBUG_USE_LESS) {
  251. wp_enqueue_style('td-theme', td_global::$get_template_directory_uri . '/td_less_style.css.php?part=style.css_v2&theme_name=' . TD_THEME_NAME, '', TD_THEME_VERSION, 'all' );
  252. // load WooCommerce LESS only when needed
  253. if (td_global::$is_woocommerce_installed === true ) {
  254. wp_enqueue_style('td-theme-woo', td_global::$get_template_directory_uri . '/td_less_style.css.php?part=woocommerce', '', TD_THEME_VERSION, 'all');
  255. }
  256. // load Bbpress LESS only when needed
  257. if (td_global::$is_bbpress_installed === true ) {
  258. wp_enqueue_style('td-theme-bbpress', td_global::$get_template_directory_uri . '/td_less_style.css.php?part=bbpress', '', TD_THEME_VERSION, 'all');
  259. }
  260. } else {
  261. wp_enqueue_style('td-theme', get_stylesheet_uri(), '', TD_THEME_VERSION, 'all' );
  262. // load the WooCommerce CSS only when needed
  263. if (td_global::$is_woocommerce_installed === true ) {
  264. wp_enqueue_style('td-theme-woo', td_global::$get_template_directory_uri . '/style-woocommerce.css', '', TD_THEME_VERSION, 'all' );
  265. }
  266. // load the Bbpress CSS only when needed
  267. if (td_global::$is_bbpress_installed === true ) {
  268. wp_enqueue_style('td-theme-bbpress', td_global::$get_template_directory_uri . '/style-bbpress.css', '', TD_THEME_VERSION, 'all' );
  269. }
  270. }
  271. ob_start();
  272. ?>
  273. <style>
  274. @media (max-width: 767px) {
  275. .td-header-desktop-wrap {
  276. display: none;
  277. }
  278. }
  279. @media (min-width: 767px) {
  280. .td-header-mobile-wrap {
  281. display: none;
  282. }
  283. }
  284. </style>
  285. <?php
  286. $custom_style = td_util::remove_style_tag(ob_get_clean());
  287. wp_add_inline_style( 'td-theme', $custom_style );
  288. }
  289. add_action('wp_enqueue_scripts', 'load_demo_front_css', 1003); // 1003 priority because visual composer uses 1000 (1002 is for legacy)
  290. function load_demo_front_css() {
  291. $demo_id = td_util::get_loaded_demo_id();
  292. if (TD_DEBUG_USE_LESS) {
  293. if ($demo_id !== false and td_global::$demo_list[$demo_id]['uses_custom_style_css'] === true) {
  294. wp_enqueue_style('td-theme-demo-style', TDC_URL_LEGACY . '/td_less_style.css.php?part=' . $demo_id . '&theme_name=' . TD_THEME_NAME, '', TD_THEME_VERSION, 'all');
  295. }
  296. } else {
  297. // If we have a DEMO installed - load the demo CSS
  298. if ($demo_id !== false and td_global::$demo_list[$demo_id]['uses_custom_style_css'] === true) {
  299. wp_enqueue_style('td-theme-demo-style', TDC_URL_LEGACY . '/includes/demos/' . $demo_id . '/demo_style.css', '', TD_THEME_VERSION, 'all');
  300. }
  301. }
  302. }
  303. /* ----------------------------------------------------------------------------
  304. * CSS fonts / google fonts in front end
  305. *
  306. * this function reads the google fonts used by user and all needed info and
  307. * builds the FULL google font url for ALL fonts including the default ones from td_config to: td_fonts_css_files
  308. * @since 10.1.2017
  309. */
  310. add_action('wp_enqueue_scripts', 'td_load_css_fonts');
  311. function td_load_css_fonts() {
  312. td_util::check_header();
  313. $cur_td_fonts = td_options::get_array('td_fonts'); // get the google fonts used by user
  314. $unique_google_fonts_ids = array();
  315. //filter the google fonts used by user
  316. if (!empty($cur_td_fonts)) {
  317. foreach ( $cur_td_fonts as $section_font_settings ) {
  318. if ( isset( $section_font_settings['font_family'] ) ) {
  319. $explode_font_family = explode( '_', $section_font_settings['font_family'] );
  320. if ( $explode_font_family[0] == 'g' ) {
  321. $unique_google_fonts_ids[] = $explode_font_family[1];
  322. }
  323. }
  324. }
  325. }
  326. $extra_google_fonts_ids = array();
  327. // Filter used to modify the post checked for icon fonts
  328. $post_id = apply_filters( 'td_filter_google_fonts_post_id', get_the_ID() );
  329. $tds_footer_page = td_util::get_option('tds_footer_page');
  330. if ( intval($tds_footer_page) !== $post_id ) {
  331. $footer_page = get_post( $tds_footer_page );
  332. if ( $footer_page instanceof WP_Post ) {
  333. $footer_google_fonts_ids = get_post_meta( $footer_page->ID, 'tdc_google_fonts', true );
  334. if ( ! empty( $footer_google_fonts_ids ) && is_array( $footer_google_fonts_ids ) ) {
  335. foreach ( $footer_google_fonts_ids as $footer_google_fonts_id ) {
  336. $extra_google_fonts_ids[] = $footer_google_fonts_id;
  337. }
  338. }
  339. }
  340. }
  341. // 'td_filter_google_fonts' - custom hook used to add google fonts from extra source
  342. $extra_google_fonts_ids = apply_filters( 'td_filter_google_fonts', $extra_google_fonts_ids );
  343. $post_google_fonts_ids = get_post_meta( $post_id, 'tdc_google_fonts', true );
  344. if ( ! empty( $post_google_fonts_ids ) && is_array( $post_google_fonts_ids ) ) {
  345. foreach ( $post_google_fonts_ids as $post_google_fonts_id ) {
  346. $extra_google_fonts_ids[] = $post_google_fonts_id;
  347. }
  348. }
  349. // remove duplicated font ids
  350. $unique_google_fonts_ids = array_unique( array_merge( $unique_google_fonts_ids, $extra_google_fonts_ids ));
  351. //used to pull fonts from google
  352. $td_fonts_css_files = '://fonts.googleapis.com/css?family=' . td_fonts::get_google_fonts_names($unique_google_fonts_ids) . td_fonts::get_google_fonts_subset_query();
  353. /*
  354. * add the google link for fonts used by user
  355. * td_fonts_css_files: holds the link to fonts.googleapis.com built above
  356. * this section will appear in the header of the source of the page
  357. */
  358. if(!empty($td_fonts_css_files) && td_options::get('g_use_google_fonts') !== 'disabled') {
  359. wp_enqueue_style( 'google-fonts-style', td_global::$http_or_https . $td_fonts_css_files, array(), TD_THEME_VERSION );
  360. }
  361. }
  362. /* ----------------------------------------------------------------------------
  363. * front end javascript files
  364. */
  365. add_action('wp_enqueue_scripts', 'load_front_js');
  366. function load_front_js() {
  367. $td_deploy_mode = TD_DEPLOY_MODE;
  368. //switch the deploy mode to demo if we have tagDiv speed booster
  369. if (defined('TD_SPEED_BOOSTER')) {
  370. $td_deploy_mode = 'demo';
  371. }
  372. if ($td_deploy_mode == 'dev') {
  373. // dev version - load each file separately
  374. $last_js_file_id = '';
  375. foreach (td_global::$js_files as $js_file_id => $js_file) {
  376. if ($last_js_file_id == '') {
  377. wp_enqueue_script($js_file_id, td_global::$get_template_directory_uri . $js_file, array('jquery'), TD_THEME_VERSION, true); //first, load it with jQuery dependency
  378. } else {
  379. wp_enqueue_script($js_file_id, td_global::$get_template_directory_uri . $js_file, array($last_js_file_id), TD_THEME_VERSION, true); //not first - load with the last file dependency
  380. }
  381. $last_js_file_id = $js_file_id;
  382. }
  383. } else {
  384. wp_enqueue_script('td-site-min', TDC_URL_LEGACY . '/js/tagdiv_theme.min.js', array('jquery'), TD_THEME_VERSION, true);
  385. }
  386. //add the comments reply to script on single pages
  387. if (is_singular()) {
  388. wp_enqueue_script('comment-reply');
  389. }
  390. }
  391. /* ----------------------------------------------------------------------------
  392. * css for wp-admin / backend
  393. */
  394. add_action('admin_enqueue_scripts', 'load_wp_admin_css', 11);
  395. function load_wp_admin_css() {
  396. //load the panel font in wp-admin
  397. $td_protocol = is_ssl() ? 'https' : 'http';
  398. 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
  399. if (TD_DEPLOY_MODE == 'dev') {
  400. wp_enqueue_style('td-wp-admin-td-panel-2', td_global::$get_template_directory_uri . '/td_less_style.css.php?part=wp-admin.css&theme_name=' . TD_THEME_NAME, false, TD_THEME_VERSION, 'all' );
  401. } else {
  402. wp_enqueue_style('td-wp-admin-td-panel-2', td_global::$get_template_directory_uri . '/legacy/common/wp_booster/wp-admin/css/wp-admin.css', false, TD_THEME_VERSION, 'all' );
  403. }
  404. //load the colorpicker
  405. wp_enqueue_style( 'wp-color-picker' );
  406. // load the media library - necessary for block widgets with image params
  407. wp_enqueue_media();
  408. }
  409. /* ----------------------------------------------------------------------------
  410. * farbtastic color picker CSS and JS for wp-admin / backend - loaded only in the widgets screen. Is used by our widget builder!
  411. */
  412. function td_on_admin_print_scripts_farbtastic() {
  413. wp_enqueue_script('farbtastic');
  414. }
  415. function td_on_admin_print_styles_farbtastic() {
  416. wp_enqueue_style('farbtastic');
  417. }
  418. add_action('admin_print_scripts-widgets.php', 'td_on_admin_print_scripts_farbtastic');
  419. add_action('admin_print_styles-widgets.php', 'td_on_admin_print_styles_farbtastic');
  420. /* ----------------------------------------------------------------------------
  421. * js for wp-admin / backend admin js - we use this strange thing to make sure that our scripts are depended on each other
  422. * and appear one after another exactly like we add them in td_global.php
  423. */
  424. add_action('admin_enqueue_scripts', 'load_wp_admin_js');
  425. function load_wp_admin_js() {
  426. if (TD_DEPLOY_MODE == 'dev') {
  427. // dev version - load each file separately
  428. $last_js_file_id = '';
  429. foreach (td_global::$js_files_for_wp_admin as $js_file_id => $js_file_params) {
  430. if ($last_js_file_id == '') {
  431. wp_enqueue_script($js_file_id, td_global::$get_template_directory_uri . $js_file_params, array('jquery', 'wp-color-picker'), TD_THEME_VERSION, false); //first, load it with jQuery dependency
  432. } else {
  433. wp_enqueue_script($js_file_id, td_global::$get_template_directory_uri . $js_file_params, array($last_js_file_id), TD_THEME_VERSION, false); //not first - load with the last file dependency
  434. }
  435. $last_js_file_id = $js_file_id;
  436. }
  437. } else {
  438. wp_enqueue_script('td-wp-admin-js', TDC_URL_LEGACY . '/js/td_wp_admin.min.js', array('jquery', 'wp-color-picker'), TD_THEME_VERSION, false);
  439. }
  440. if (isset($_GET['page']) && $_GET['page'] === 'td_theme_panel') {
  441. $last_js_file_id = '';
  442. foreach (td_global::$js_files_for_td_theme_panel as $js_file_id => $js_file_params) {
  443. if ($last_js_file_id == '') {
  444. wp_enqueue_script($js_file_id, td_global::$get_template_directory_uri . $js_file_params, array('jquery', 'wp-color-picker'), TD_THEME_VERSION, false); //first, load it with jQuery dependency
  445. } else {
  446. wp_enqueue_script($js_file_id, td_global::$get_template_directory_uri . $js_file_params, array($last_js_file_id), TD_THEME_VERSION, false); //not first - load with the last file dependency
  447. }
  448. $last_js_file_id = $js_file_id;
  449. }
  450. }
  451. add_thickbox();
  452. }
  453. /*
  454. * set media-upload is loaded js global
  455. * used by tdConfirm.js
  456. */
  457. add_action('admin_print_footer_scripts', 'check_if_media_uploads_is_loaded', 9999);
  458. function check_if_media_uploads_is_loaded() {
  459. $wp_scripts = wp_scripts();
  460. $media_upload = $wp_scripts->query('media-upload', 'done');
  461. if ($media_upload === true) {
  462. //td_js_buffer::add_to_wp_admin_footer('var td_media_upload_loaded = true;');
  463. //echo '<script>var td_media_upload_loaded = true;</script>';
  464. echo '<script>tdConfirm.mediaUploadLoaded = true;</script>';
  465. }
  466. }
  467. /* ----------------------------------------------------------------------------
  468. * Prepare the head canonical links on smart lists and pages with pagination.
  469. * @see https://googlewebmastercentral.blogspot.de/2011/09/pagination-with-relnext-and-relprev.html
  470. * Applied from July 2019, until now it was only by request
  471. */
  472. add_action('wp_head', 'td_on_wp_head_canonical', 1);
  473. function td_on_wp_head_canonical(){
  474. global $post;
  475. // $td_smart_list = td_util::get_post_meta_array($post->ID, 'td_post_theme_settings');
  476. /** ----------------------------------------------------------------------------
  477. * Smart list support. class_exists and new object WORK VIA AUTOLOAD
  478. * @see td_autoload_classes::loading_classes
  479. */
  480. // if (!empty($td_smart_list['smart_list_template'])) {
  481. //
  482. // $td_smart_list_class = $td_smart_list['smart_list_template'];
  483. // if (class_exists($td_smart_list_class)) {
  484. //
  485. // global $paged, $page;
  486. // $td_page = max($paged, $page);
  487. //
  488. // $content = $post->post_content;
  489. // $content = apply_filters('the_content', $content);
  490. // $content = str_replace(']]>', ']]&gt;', $content);
  491. //
  492. // // Remove the wp action links
  493. // remove_action('wp_head', 'rel_canonical');
  494. // remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
  495. //
  496. // if (class_exists('WPSEO_Frontend')) {
  497. // // Remove the canonical action of the Yoast SEO plugin
  498. // remove_action( 'wpseo_head', array( WPSEO_Frontend::get_instance(), 'canonical' ), 20 );
  499. // }
  500. //
  501. // // For the first page, there is no page setting, so we use 1
  502. // if ($td_page === 0) {
  503. // $td_page = 1;
  504. // }
  505. //
  506. // /**
  507. // * @var $td_smart_list_obj td_smart_list
  508. // */
  509. // $td_smart_list_obj = new $td_smart_list_class(); // make the class from string * magic :)
  510. //
  511. // // prepare the settings for the smart list
  512. // $smart_list_settings = array(
  513. // 'post_content' => $content,
  514. // 'counting_order_asc' => false,
  515. // 'td_smart_list_h' => 'h3',
  516. // 'extract_first_image' => td_api_smart_list::get_key($td_smart_list_class, 'extract_first_image')
  517. // );
  518. //
  519. // if (!empty($td_smart_list['td_smart_list_order'])) {
  520. // $smart_list_settings['counting_order_asc'] = true;
  521. // }
  522. //
  523. // if (!empty($td_smart_list['td_smart_list_h'])) {
  524. // $smart_list_settings['td_smart_list_h'] = $td_smart_list['td_smart_list_h'];
  525. // }
  526. //
  527. // $list_items = $td_smart_list_obj->get_formatted_list_items($smart_list_settings);
  528. //
  529. // if (array_key_exists('list_items', $list_items) && !empty($list_items['list_items'])) {
  530. // $count_items = count($list_items['list_items']);
  531. // foreach ($list_items['list_items'] as $list_item) {
  532. // if ($td_page == $list_item['current_item_number']) {
  533. // echo '<link rel="canonical" href="' . $td_smart_list_obj->_wp_link_page($td_page) . '"/>';
  534. // if ($td_page > 1) {
  535. // echo '<link rel="prev" href="' . $td_smart_list_obj->_wp_link_page($td_page - 1) . '"/>';
  536. // }
  537. // if ($td_page < $count_items) {
  538. // echo '<link rel="next" href="' . $td_smart_list_obj->_wp_link_page($td_page + 1) . '"/>';
  539. // }
  540. // break;
  541. // }
  542. // }
  543. // }
  544. // }
  545. //
  546. // } else
  547. if (is_page() && 'page-pagebuilder-latest.php' === get_post_meta($post->ID, '_wp_page_template', true)) {
  548. $td_page = get_query_var('page') ? get_query_var('page') : 1; //rewrite the global var
  549. $td_paged = get_query_var('paged') ? get_query_var('paged') : 1; //rewrite the global var
  550. $td_page = intval($td_page);
  551. $td_paged = intval($td_paged);
  552. //paged works on single pages, page - works on homepage
  553. if ($td_paged > $td_page) {
  554. $paged = $td_paged;
  555. } else {
  556. $paged = $td_page;
  557. }
  558. global $wp_query;
  559. $td_homepage_loop = td_util::get_post_meta_array($post->ID, 'td_homepage_loop');
  560. query_posts(td_data_source::metabox_to_args($td_homepage_loop, $paged));
  561. $max_page = $wp_query->max_num_pages;
  562. // Remove the wp action links
  563. remove_action('wp_head', 'rel_canonical');
  564. remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
  565. if (class_exists('WPSEO_Frontend')) {
  566. // Remove the canonical action of the Yoast SEO plugin
  567. remove_action( 'wpseo_head', array( WPSEO_Frontend::get_instance(), 'canonical' ), 20 );
  568. }
  569. echo '<link rel="canonical" href="' . get_pagenum_link($paged) . '"/>';
  570. if ($paged > 1) {
  571. echo '<link rel="prev" href="' . get_pagenum_link($paged - 1) . '"/>';
  572. }
  573. if ($paged < $max_page) {
  574. echo '<link rel="next" href="' . get_pagenum_link($paged + 1) . '"/>';
  575. }
  576. wp_reset_query();
  577. }
  578. }
  579. /* ----------------------------------------------------------------------------
  580. * Prepare head related links
  581. */
  582. add_action('wp_head', 'hook_wp_head', 1); //hook on wp_head -> 1 priority, we are first
  583. function hook_wp_head() {
  584. // if (is_single()) {
  585. // global $post;
  586. //
  587. // facebook sharing fix for videos, we add the custom meta data
  588. // this is not used anymore, the meta are add by Yoast
  589. // if (has_post_thumbnail($post->ID)) {
  590. // $td_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
  591. // if (!empty($td_image[0])) {
  592. // echo '<meta property="og:image" content="' . $td_image[0] . '" />';
  593. // }
  594. // }
  595. // }
  596. // fav icon support
  597. $tds_favicon_upload = td_util::get_option('tds_favicon_upload');
  598. if (!empty($tds_favicon_upload)) {
  599. echo '<link rel="icon" type="image/png" href="' . $tds_favicon_upload . '">';
  600. }
  601. // ios bookmark icon support
  602. $tds_ios_76 = td_util::get_option('tds_ios_icon_76');
  603. $tds_ios_120 = td_util::get_option('tds_ios_icon_120');
  604. $tds_ios_152 = td_util::get_option('tds_ios_icon_152');
  605. $tds_ios_114 = td_util::get_option('tds_ios_icon_114');
  606. $tds_ios_144 = td_util::get_option('tds_ios_icon_144');
  607. if(!empty($tds_ios_76)) {
  608. echo '<link rel="apple-touch-icon-precomposed" sizes="76x76" href="' . $tds_ios_76 . '"/>';
  609. }
  610. if(!empty($tds_ios_120)) {
  611. echo '<link rel="apple-touch-icon-precomposed" sizes="120x120" href="' . $tds_ios_120 . '"/>';
  612. }
  613. if(!empty($tds_ios_152)) {
  614. echo '<link rel="apple-touch-icon-precomposed" sizes="152x152" href="' . $tds_ios_152 . '"/>';
  615. }
  616. if(!empty($tds_ios_114)) {
  617. echo '<link rel="apple-touch-icon-precomposed" sizes="114x114" href="' . $tds_ios_114 . '"/>';
  618. }
  619. if(!empty($tds_ios_144)) {
  620. echo '<link rel="apple-touch-icon-precomposed" sizes="144x144" href="' . $tds_ios_144 . '"/>';
  621. }
  622. // $tds_login_sing_in_widget = td_util::get_option('tds_login_sign_in_widget');
  623. // if (!empty($tds_login_sing_in_widget)) {
  624. // td_js_buffer::add_variable('tds_login_sing_in_widget', $tds_login_sing_in_widget);
  625. // }
  626. // js variable td_viewport_interval_list added to the window object
  627. td_js_buffer::add_variable('td_viewport_interval_list', td_global::$td_viewport_intervals);
  628. // !!!! aici se va schimba setarea, iar userii isi pierd setarea existenta
  629. // lazy loading images - animation effect
  630. //$tds_lazy_loading_image = td_util::get_option('tds_lazy_loading_image');
  631. $tds_animation_stack = td_util::get_option('tds_animation_stack');
  632. // the body css supplementary classes and the global js animation effects variables are set only if the option 'tds_animation_stack' is set
  633. if (empty($tds_animation_stack) && ! tdc_state::is_live_editor_iframe() ) {
  634. // js variable td_animation_stack_effect added to the window object
  635. $td_animation_stack_effect_type = 'type0';
  636. if (td_options::get('tds_animation_stack_effect') != '' ) {
  637. $td_animation_stack_effect_type = td_options::get('tds_animation_stack_effect');
  638. }
  639. td_js_buffer::add_variable('td_animation_stack_effect', $td_animation_stack_effect_type);
  640. td_js_buffer::add_variable('tds_animation_stack', true);
  641. foreach (td_global::$td_animation_stack_effects as $td_animation_stack_effect) {
  642. if ((($td_animation_stack_effect['val'] == '') and ($td_animation_stack_effect_type == 'type0')) ||
  643. ($td_animation_stack_effect['val'] == $td_animation_stack_effect_type)) {
  644. td_js_buffer::add_variable('td_animation_stack_specific_selectors', $td_animation_stack_effect['specific_selectors']);
  645. td_js_buffer::add_variable('td_animation_stack_general_selectors', $td_animation_stack_effect['general_selectors']);
  646. break;
  647. }
  648. }
  649. add_filter('body_class','td_hook_add_custom_body_class');
  650. }
  651. $tds_general_modal_image = td_util::get_option('tds_general_modal_image');
  652. if (!empty($tds_general_modal_image)) {
  653. td_js_buffer::add_variable('tds_general_modal_image', $tds_general_modal_image);
  654. }
  655. }
  656. /** ----------------------------------------------------------------------------
  657. * The function hook to alter body css classes.
  658. * It applies the necessary animation images effect to body @see animation-stack.less
  659. *
  660. * @param $classes
  661. *
  662. * @return array
  663. */
  664. function td_hook_add_custom_body_class($classes) {
  665. if (td_options::get('tds_animation_stack') == '') {
  666. $td_animation_stack_effect_type = 'type0';
  667. if (td_options::get('tds_animation_stack_effect') != '') {
  668. $td_animation_stack_effect_type = td_options::get('tds_animation_stack_effect');
  669. }
  670. $classes[] = 'td-animation-stack-' . $td_animation_stack_effect_type;
  671. }
  672. return $classes;
  673. }
  674. /* ----------------------------------------------------------------------------
  675. * localization
  676. */
  677. add_action('after_setup_theme', 'td_load_text_domains');
  678. function td_load_text_domains() {
  679. load_theme_textdomain( strtolower( TD_THEME_NAME ), get_template_directory() . '/translation');
  680. }
  681. add_action('after_setup_theme', function() {
  682. // theme specific config values
  683. require_once('td_translate.php');
  684. }, 12);
  685. add_action( 'after_setup_theme', function() {
  686. remove_theme_support( 'title-tag' );
  687. });
  688. /* ----------------------------------------------------------------------------
  689. Custom <title> wp_title - seo
  690. */
  691. add_filter( 'wp_title', 'td_wp_title', 10, 2 );
  692. function td_wp_title( $title, $sep ) {
  693. global $paged, $page;
  694. if ( is_feed() )
  695. return $title;
  696. // Add the site name.
  697. $title .= get_bloginfo( 'name' );
  698. // Add the site description for the home/front page.
  699. $site_description = get_bloginfo( 'description', 'display' );
  700. if ( $site_description && ( is_home() || is_front_page() ) )
  701. $title = "$title $sep $site_description";
  702. // Add a page number if necessary.
  703. if ( $paged >= 2 || $page >= 2 )
  704. $title = "$title $sep " . __td('Page', TD_THEME_NAME) . ' ' . max( $paged, $page );
  705. return $title;
  706. }
  707. /**
  708. * - filter 'wpseo_title' is used by WordPress SEO plugin and, by default, it returns a seo title that hasn't the page number inside of it,
  709. * when it's used on td pages [those who have a custom pagination]. At that seo title is added the page info, and just for pages greater than 1
  710. */
  711. add_filter('wpseo_title', 'td_wpseo_title', 10, 1);
  712. function td_wpseo_title($seo_title) {
  713. $is_smart_list = false;
  714. if (is_singular('post')) {
  715. global $post;
  716. $td_post_theme_settings = td_util::get_post_meta_array($post->ID, 'td_post_theme_settings');
  717. if (is_array($td_post_theme_settings) && array_key_exists('smart_list_template', $td_post_theme_settings)) {
  718. $is_smart_list = true;
  719. }
  720. }
  721. // outside the loop, it's reliable to check the page template
  722. if (!in_the_loop() && (is_page_template('page-pagebuilder-latest.php') || $is_smart_list)) {
  723. $td_page = (get_query_var('page')) ? get_query_var('page') : 1; //rewrite the global var
  724. $td_paged = (get_query_var('paged')) ? get_query_var('paged') : 1; //rewrite the global var
  725. if ($td_paged > $td_page) {
  726. $local_paged = $td_paged;
  727. } else {
  728. $local_paged = $td_page;
  729. }
  730. // the custom title is when the pagination is greater than 1
  731. if ($local_paged > 1) {
  732. return $seo_title . ' - ' . __td('Page', TD_THEME_NAME) . ' ' . $local_paged;
  733. }
  734. }
  735. // otherwise, the param $seo_title is returned as it is
  736. return $seo_title;
  737. }
  738. /** ----------------------------------------------------------------------------
  739. archive widget - adds .current class in the archive widget and maybe it's used in other places too!
  740. */
  741. add_filter('get_archives_link', 'theme_get_archives_link');
  742. function theme_get_archives_link ( $link_html ) {
  743. global $wp;
  744. static $current_url;
  745. if ( empty( $current_url ) ) {
  746. global $wp;
  747. if ( empty ( $wp->query_string ) ) {
  748. $current_url = esc_url ( home_url ( $wp->request . '/' ) );
  749. } else {
  750. $current_url = esc_url( add_query_arg ( $wp->query_string, '', home_url ( $wp->request . '/' ) ) );
  751. }
  752. }
  753. if ( stristr( $current_url, 'page' ) !== false ) {
  754. $current_url = substr($current_url, 0, strrpos($current_url, 'page'));
  755. }
  756. if ( stristr( $link_html, $current_url ) !== false ) {
  757. $link_html = preg_replace( '/(<[^\s>]+)/', '\1 class="current"', $link_html, 1 );
  758. }
  759. return $link_html;
  760. }
  761. /* ----------------------------------------------------------------------------
  762. add span wrap for category number in widget
  763. */
  764. add_filter('wp_list_categories', 'cat_count_span');
  765. function cat_count_span($links) {
  766. $pattern = '/<\/a> \(([\d]+)\)/';
  767. $links = preg_replace($pattern, '<span class="td-widget-no">$1</span></a>', $links);
  768. return $links;
  769. }
  770. /* ----------------------------------------------------------------------------
  771. remove gallery style css
  772. */
  773. add_filter( 'use_default_gallery_style', '__return_false' );
  774. /* ----------------------------------------------------------------------------
  775. editor style
  776. */
  777. add_action( 'after_setup_theme', 'my_theme_add_editor_styles' );
  778. function my_theme_add_editor_styles() {
  779. if (TD_DEPLOY_MODE == 'dev') {
  780. // we need the full url here due to a WP strange s*it with ?queries
  781. add_editor_style(get_stylesheet_directory_uri() . '/tagdiv-less-style.css.php?part=editor-style');
  782. } else {
  783. add_editor_style(); // add the default style
  784. }
  785. }
  786. /* ----------------------------------------------------------------------------
  787. the bottom code for css
  788. */
  789. add_action('wp_footer', 'td_bottom_code');
  790. function td_bottom_code() {
  791. global $post;
  792. // try to detect speed booster
  793. $speed_booster = '';
  794. if (defined('TD_SPEED_BOOSTER')) {
  795. $speed_booster = 'Speed booster: ' . TD_SPEED_BOOSTER . "\n";
  796. }
  797. echo '
  798. <!--
  799. Theme: ' . TD_THEME_NAME .' by tagDiv.com 2019
  800. Version: ' . TD_THEME_VERSION . ' (rara)
  801. Deploy mode: ' . TD_DEPLOY_MODE . '
  802. ' . $speed_booster . '
  803. uid: ' . uniqid() . '
  804. -->
  805. ';
  806. // get and paste user custom css
  807. $td_custom_css = stripslashes(td_util::get_option('tds_custom_css'));
  808. // get the custom css for the responsive values
  809. $responsive_css_values = array();
  810. foreach (td_global::$theme_panel_custom_css_fields_list as $option_id => $css_params) {
  811. $responsive_css = td_util::get_option($option_id);
  812. if ($responsive_css != '') {
  813. $responsive_css_values[$css_params['media_query']] = $responsive_css;
  814. }
  815. }
  816. // check if we have to show any css
  817. if (!empty($td_custom_css) or count($responsive_css_values) > 0) {
  818. $css_buffy = PHP_EOL . '<style type="text/css" media="screen">';
  819. //paste custom css
  820. if(!empty($td_custom_css) ) {
  821. $css_buffy .= PHP_EOL . '/* custom css theme panel */' . PHP_EOL;
  822. $css_buffy .= $td_custom_css . PHP_EOL;
  823. }
  824. foreach ($responsive_css_values as $media_query => $responsive_css) {
  825. $css_buffy .= PHP_EOL . PHP_EOL . '/* custom responsive css from theme panel (Advanced CSS) */';
  826. $css_buffy .= PHP_EOL . $media_query . ' {' . PHP_EOL;
  827. $css_buffy .= $responsive_css;
  828. $css_buffy .= PHP_EOL . '}' . PHP_EOL;
  829. }
  830. $css_buffy .= '</style>' . PHP_EOL . PHP_EOL;
  831. // echo the css buffer
  832. echo PHP_EOL . '<!-- Custom css from theme panel -->' . $css_buffy;
  833. }
  834. if ( ! tdc_state::is_live_editor_iframe() ) {
  835. //get and paste user custom html
  836. $td_custom_html = stripslashes(td_util::get_option('tds_custom_html'));
  837. if(!empty($td_custom_html)) {
  838. echo '<div class="td-container">' . $td_custom_html . '</div>';
  839. }
  840. //get and paste user custom javascript
  841. $td_custom_javascript = stripslashes( td_util::get_option( 'tds_custom_javascript' ) );
  842. if ( ! empty( $td_custom_javascript ) ) {
  843. echo '<script type="text/javascript">'
  844. . $td_custom_javascript .
  845. '</script>';
  846. }
  847. }
  848. //AJAX POST VIEW COUNT
  849. if(td_util::get_option('tds_ajax_post_view_count') == 'enabled') {
  850. //Ajax get & update counter views
  851. if(is_single()) {
  852. //echo 'post page: '. $post->ID;
  853. if($post->ID > 0) {
  854. td_js_buffer::add_to_footer('
  855. jQuery().ready(function jQuery_ready() {
  856. tdAjaxCount.tdGetViewsCountsAjax("post",' . json_encode('[' . $post->ID . ']') . ');
  857. });
  858. ');
  859. }
  860. }
  861. }
  862. }
  863. /* ----------------------------------------------------------------------------
  864. google analytics and footer custom JS
  865. */
  866. if ( ! tdc_state::is_live_editor_iframe() ) {
  867. add_action( 'wp_head', 'td_header_analytics_code', 40 );
  868. function td_header_analytics_code() {
  869. $td_analytics = td_util::get_option( 'td_analytics' );
  870. echo stripslashes( $td_analytics );
  871. }
  872. add_action( 'wp_footer', 'td_footer_script_code', 40 );
  873. function td_footer_script_code() {
  874. $td_footer_code = td_util::get_option( 'td_footer_code' );
  875. echo stripslashes( $td_footer_code );
  876. }
  877. }
  878. /* ----------------------------------------------------------------------------
  879. Append page slugs to the body class
  880. */
  881. add_filter('body_class', 'add_slug_to_body_class');
  882. function add_slug_to_body_class( $classes ) {
  883. global $post;
  884. if( is_home() ) {
  885. $key = array_search( 'blog', $classes );
  886. if($key > -1) {
  887. unset( $classes[$key] );
  888. };
  889. } elseif( is_page() ) {
  890. $classes[] = sanitize_html_class( $post->post_name );
  891. } elseif(is_singular()) {
  892. $classes[] = sanitize_html_class( $post->post_name );
  893. };
  894. $i = 0;
  895. foreach ($classes as $key => $value) {
  896. $pos = strripos($value, 'span');
  897. if ($pos !== false) {
  898. unset($classes[$i]);
  899. }
  900. $pos = strripos($value, 'row');
  901. if ($pos !== false) {
  902. unset($classes[$i]);
  903. }
  904. $pos = strripos($value, 'container');
  905. if ($pos !== false) {
  906. unset($classes[$i]);
  907. }
  908. $i++;
  909. }
  910. $td_block_template_id = td_options::get('tds_global_block_template', 'td_block_template_1');
  911. $classes[] = str_replace('td', 'global', str_replace('_', '-', $td_block_template_id));
  912. return $classes;
  913. }
  914. /* ----------------------------------------------------------------------------
  915. remove span row container classes from post_class()
  916. */
  917. add_filter('post_class', 'add_slug_to_post_class');
  918. function add_slug_to_post_class($classes) {
  919. global $post;
  920. // on custom post types, we add the .post class for better css compatibility
  921. if (is_single() and $post->post_type != 'post') {
  922. $classes[]= 'post';
  923. }
  924. $i = 0;
  925. foreach ($classes as $key => $value) {
  926. $pos = strripos($value, 'span');
  927. if ($pos !== false) {
  928. unset($classes[$i]);
  929. }
  930. $pos = strripos($value, 'row');
  931. if ($pos !== false) {
  932. unset($classes[$i]);
  933. }
  934. $pos = strripos($value, 'container');
  935. if ($pos !== false) {
  936. unset($classes[$i]);
  937. }
  938. $i++;
  939. }
  940. return $classes;
  941. }
  942. /* -----------------------------------------------------------------------------
  943. * Add prev and next links to a numbered link list - the pagination on single.
  944. */
  945. add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add');
  946. function wp_link_pages_args_prevnext_add($args)
  947. {
  948. global $page, $numpages, $more, $pagenow;
  949. if (!$args['next_or_number'] == 'next_and_number')
  950. return $args; # exit early
  951. $args['next_or_number'] = 'number'; # keep numbering for the main part
  952. if (!$more)
  953. return $args; # exit early
  954. if($page-1) # there is a previous page
  955. $args['before'] .= _wp_link_page($page-1)
  956. . $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a>'
  957. ;
  958. if ($page<$numpages) # there is a next page
  959. $args['after'] = _wp_link_page($page+1)
  960. . $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . '</a>'
  961. . $args['after']
  962. ;
  963. return $args;
  964. }
  965. /* -----------------------------------------------------------------------------
  966. * Add, on theme body element, the custom classes from Theme Panel -> Custom Css -> Custom Body class(s)
  967. */
  968. add_filter('body_class','td_my_custom_class_names_on_body');
  969. function td_my_custom_class_names_on_body($classes) {
  970. //get the custom classes from theme options
  971. $custom_classes = td_util::get_option('td_body_classes');
  972. if(!empty($custom_classes)) {
  973. // add 'custom classes' to the $classes array
  974. $classes[] = $custom_classes;
  975. }
  976. // return the $classes array
  977. return $classes;
  978. }
  979. /* ----------------------------------------------------------------------------
  980. add extra contact information for author in wp-admin -> users -> your profile
  981. */
  982. add_filter('user_contactmethods', 'td_extra_contact_info_for_author');
  983. function td_extra_contact_info_for_author($contactmethods) {
  984. unset($contactmethods['aim']);
  985. unset($contactmethods['yim']);
  986. unset($contactmethods['jabber']);
  987. foreach (td_social_icons::$td_social_icons_array as $td_social_id => $td_social_name) {
  988. $contactmethods[$td_social_id] = $td_social_name;
  989. }
  990. return $contactmethods;
  991. }
  992. /* ----------------------------------------------------------------------------
  993. * shortcodes in widgets
  994. */
  995. add_filter('widget_text', 'do_shortcode');
  996. /* ----------------------------------------------------------------------------
  997. * Visual Composer init
  998. */
  999. register_activation_hook('js_composer/js_composer.php', 'td_vc_kill_welcome', 11);
  1000. function td_vc_kill_welcome() {
  1001. remove_action('vc_activation_hook', 'vc_page_welcome_set_redirect');
  1002. }
  1003. /**
  1004. * visual composer rewrite classes
  1005. * Filter to Replace default css class for vc_row shortcode and vc_column
  1006. */
  1007. add_filter('vc_shortcodes_css_class', 'custom_css_classes_for_vc_row_and_vc_column', 10, 2);
  1008. function custom_css_classes_for_vc_row_and_vc_column($class_string, $tag) {
  1009. //vc_span4
  1010. if ($tag == 'vc_row' || $tag == 'vc_row_inner') {
  1011. $class_string = str_replace('vc_row-fluid', 'td-pb-row', $class_string);
  1012. }
  1013. if ($tag == 'vc_column' || $tag == 'vc_column_inner') {
  1014. $class_string = preg_replace('/vc_col-sm-(\d{1,2})/', 'td-pb-span$1', $class_string);
  1015. //$class_string = preg_replace('/vc_span(\d{1,2})/', 'td-pb-span$1', $class_string);
  1016. }
  1017. return $class_string;
  1018. }
  1019. add_action('vc_load_default_templates','my_custom_template_for_vc');
  1020. function my_custom_template_for_vc($templates) {
  1021. require_once(TDC_PATH_LEGACY . '/includes/td_templates_builder.php');
  1022. global $td_vc_templates;
  1023. global $vc_manager;
  1024. if (isset($vc_manager) and is_object($vc_manager) and method_exists($vc_manager, 'vc')) {
  1025. $vc = $vc_manager->vc();
  1026. if (isset($vc) and is_object($vc) and method_exists($vc, 'templatesPanelEditor')) {
  1027. $vc_template_panel_editor = $vc->templatesPanelEditor();
  1028. if (isset($vc_template_panel_editor)
  1029. and is_object($vc_template_panel_editor)
  1030. and has_filter('vc_load_default_templates_welcome_block', array($vc_template_panel_editor, 'loadDefaultTemplatesLimit'))) {
  1031. remove_filter('vc_load_default_templates_welcome_block', array($vc_template_panel_editor, 'loadDefaultTemplatesLimit'));
  1032. }
  1033. }
  1034. }
  1035. return $td_vc_templates;
  1036. }
  1037. td_vc_init();
  1038. function td_vc_init() {
  1039. // Force Visual Composer to initialize as "built into the theme". This will hide certain tabs under the Settings->Visual Composer page
  1040. if (function_exists('vc_set_as_theme')) {
  1041. vc_set_as_theme(true);
  1042. }
  1043. if (function_exists('vc_map')) {
  1044. //map all of our blocks in page builder
  1045. td_global_blocks::td_vc_map_all();
  1046. }
  1047. if (function_exists('vc_disable_frontend')) {
  1048. vc_disable_frontend();
  1049. }
  1050. }
  1051. /* ----------------------------------------------------------------------------
  1052. * TagDiv gallery - tinyMCE hooks
  1053. */
  1054. //add the gallery tinyMCE hooks only if it's enabled
  1055. if (td_api_features::is_enabled('tagdiv_slide_gallery') === true) {
  1056. add_action('print_media_templates', 'td_custom_gallery_settings_hook');
  1057. add_action('print_media_templates', 'td_change_backbone_js_hook');
  1058. }
  1059. /**
  1060. * custom gallery setting
  1061. */
  1062. function td_custom_gallery_settings_hook () {
  1063. // define your backbone template;
  1064. // the "tmpl-" prefix is required,
  1065. // and your input field should have a data-setting attribute
  1066. // matching the shortcode name
  1067. ?>
  1068. <script type="text/html" id="tmpl-td-custom-gallery-setting">
  1069. <label class="setting">
  1070. <span>Gallery Type</span>
  1071. <select data-setting="td_select_gallery_slide">
  1072. <option value="">Default </option>
  1073. <option value="slide">TagDiv Slide Gallery</option>
  1074. </select>
  1075. </label>
  1076.  
  1077. <label class="setting">
  1078. <span>Gallery Title</span>
  1079. <input type="text" value="" data-setting="td_gallery_title_input" />
  1080. </label>
  1081. </script>
  1082.  
  1083. <script>
  1084. jQuery(document).ready(function(){
  1085. // add your shortcode attribute and its default value to the
  1086. // gallery settings list; $.extend should work as well...
  1087. _.extend(wp.media.gallery.defaults, {
  1088. td_select_gallery_slide: '', td_gallery_title_input: ''
  1089. });
  1090. // merge default gallery settings template with yours
  1091. wp.media.view.Settings.Gallery = wp.media.view.Settings.Gallery.extend({
  1092. template: function(view){
  1093. return wp.media.template('gallery-settings')(view)
  1094. + wp.media.template('td-custom-gallery-setting')(view);
  1095. }
  1096. // ,initialize: function() {
  1097. // if (typeof this.model.get('td_select_gallery_slide') == 'undefined') {
  1098. // this.model.set({td_select_gallery_slide: 'slide'});
  1099. // }
  1100. // }
  1101. });
  1102. //console.log();
  1103. // wp.media.model.Attachments.trigger('change')
  1104. });
  1105. </script>
  1106. <?php
  1107. }
  1108. /**
  1109. * td-modal-image support in tinymce
  1110. */
  1111. function td_change_backbone_js_hook() {
  1112. //change the backbone js template
  1113. // make the buffer for the dropdown
  1114. $image_styles_buffer_for_select = '';
  1115. $image_styles_buffer_for_switch = '';
  1116. foreach (td_global::$tiny_mce_image_style_list as $tiny_mce_image_style_id => $tiny_mce_image_style_params) {
  1117. $image_styles_buffer_for_select .= "'<option value=\"" . $tiny_mce_image_style_id . "\">" . $tiny_mce_image_style_params['text'] . "</option>' + ";
  1118. $image_styles_buffer_for_switch .= "
  1119. case '$tiny_mce_image_style_id':
  1120. td_clear_all_classes(); //except the modal one
  1121. td_add_image_css_class('" . $tiny_mce_image_style_params['class'] . "');
  1122. break;
  1123. ";
  1124. }
  1125. ?>
  1126. <script type="text/javascript">
  1127. (function (){
  1128. var td_template_content = jQuery('#tmpl-image-details').text();
  1129. var td_our_content = '' +
  1130. // modal image settings
  1131. '<div class="setting">' +
  1132. '<span>Modal image</span>' +
  1133. '<div class="button-large button-group" >' +
  1134. '<button class="button active td-modal-image-off" value="left">Off</button>' +
  1135. '<button class="button td-modal-image-on" value="left">On</button>' +
  1136. '</div><!-- /setting -->' +
  1137. // image style settings
  1138. '<div class="setting">' +
  1139. '<span>tagDiv image style</span>' +
  1140. '<select class="size td-wp-image-style">' +
  1141. '<option value="">Default</option>' +
  1142. <?php printf( '%1$s', $image_styles_buffer_for_select ) ?>
  1143. '</select>' +
  1144. '</div>' +
  1145. '</div>';
  1146. //inject our settings in the template - before <div class="setting align">
  1147. td_template_content = td_template_content.replace('<div class="setting align">', td_our_content + '<div class="setting align">');
  1148. //save the template
  1149. jQuery('#tmpl-image-details').html(td_template_content);
  1150. //modal off - click event
  1151. jQuery(".td-modal-image-on").live( "click", function() {
  1152. if (jQuery(this).hasClass('active')) {
  1153. return;
  1154. }
  1155. td_add_image_css_class('td-modal-image');
  1156. jQuery(".td-modal-image-off").removeClass('active');
  1157. jQuery(".td-modal-image-on").addClass('active');
  1158. });
  1159. //modal on - click event
  1160. jQuery(".td-modal-image-off").live( "click", function() {
  1161. if (jQuery(this).hasClass('active')) {
  1162. return;
  1163. }
  1164. td_remove_image_css_class('td-modal-image');
  1165. jQuery(".td-modal-image-off").addClass('active');
  1166. jQuery(".td-modal-image-on").removeClass('active');
  1167. });
  1168. // select change event
  1169. jQuery(".td-wp-image-style").live( "change", function() {
  1170. switch (jQuery( ".td-wp-image-style").val()) {
  1171. <?php printf( '%1$s', $image_styles_buffer_for_switch) ?>
  1172. default:
  1173. td_clear_all_classes(); //except the modal one
  1174. jQuery('*[data-setting="extraClasses"]').change(); //trigger the change event for backbonejs
  1175. }
  1176. });
  1177. //util functions to edit the image details in wp-admin
  1178. function td_add_image_css_class(new_class) {
  1179. var td_extra_classes_value = jQuery('*[data-setting="extraClasses"]').val();
  1180. jQuery('*[data-setting="extraClasses"]').val(td_extra_classes_value + ' ' + new_class);
  1181. jQuery('*[data-setting="extraClasses"]').change(); //trigger the change event for backbonejs
  1182. }
  1183. function td_remove_image_css_class(new_class) {
  1184. var td_extra_classes_value = jQuery('*[data-setting="extraClasses"]').val();
  1185. //try first with a space before the class
  1186. var td_regex = new RegExp(" " + new_class,"g");
  1187. td_extra_classes_value = td_extra_classes_value.replace(td_regex, '');
  1188. var td_regex = new RegExp(new_class,"g");
  1189. td_extra_classes_value = td_extra_classes_value.replace(td_regex, '');
  1190. jQuery('*[data-setting="extraClasses"]').val(td_extra_classes_value);
  1191. jQuery('*[data-setting="extraClasses"]').change(); //trigger the change event for backbonejs
  1192. }
  1193. //clears all classes except the modal image one
  1194. function td_clear_all_classes() {
  1195. var td_extra_classes_value = jQuery('*[data-setting="extraClasses"]').val();
  1196. if (td_extra_classes_value.indexOf('td-modal-image') > -1) {
  1197. //we have the modal image one - keep it, remove the others
  1198. jQuery('*[data-setting="extraClasses"]').val('td-modal-image');
  1199. } else {
  1200. jQuery('*[data-setting="extraClasses"]').val('');
  1201. }
  1202. }
  1203. //monitor the backbone template for the current status of the picture
  1204. setInterval(function(){
  1205. var td_extra_classes_value = jQuery('*[data-setting="extraClasses"]').val();
  1206. if (typeof td_extra_classes_value !== 'undefined' && td_extra_classes_value != '') {
  1207. // if we have modal on, switch the toggle
  1208. if (td_extra_classes_value.indexOf('td-modal-image') > -1) {
  1209. jQuery(".td-modal-image-off").removeClass('active');
  1210. jQuery(".td-modal-image-on").addClass('active');
  1211. }
  1212. <?php
  1213. foreach (td_global::$tiny_mce_image_style_list as $tiny_mce_image_style_id => $tiny_mce_image_style_params) {
  1214. ?>
  1215. //change the select
  1216. if (td_extra_classes_value.indexOf('<?php printf( '%1$s', $tiny_mce_image_style_params['class'] ) ?>') > -1) {
  1217. jQuery(".td-wp-image-style").val('<?php printf( '%1$s', $tiny_mce_image_style_id ) ?>');
  1218. }
  1219. <?php
  1220. }
  1221. ?>
  1222. }
  1223. }, 1000);
  1224. })(); //end anon function
  1225. </script>
  1226. <?php
  1227. }
  1228. /* ----------------------------------------------------------------------------
  1229. * TagDiv gallery - front end hooks
  1230. */
  1231. //add the gallery frontend hook only if it's enabled
  1232. if (td_api_features::is_enabled('tagdiv_slide_gallery') === true) {
  1233. add_filter('post_gallery', 'td_gallery_shortcode', 10, 4);
  1234. }
  1235. /**
  1236. * @param string $output - is empty !!!
  1237. * @param $atts
  1238. * @param bool $content
  1239. * @return mixed
  1240. */
  1241. function td_gallery_shortcode($output = '', $atts, $content = false) {
  1242. global $loop_sidebar_position;
  1243. global $post;
  1244. $page_template_slug = get_page_template_slug($post->ID);
  1245. $buffy = '';
  1246. //check for gallery = slide
  1247. if(!empty($atts) and !empty($atts['td_select_gallery_slide']) and $atts['td_select_gallery_slide'] == 'slide') {
  1248. $td_double_slider2_no_js_limit = 1;
  1249. $td_nr_columns_slide = 'td-slide-on-2-columns';
  1250. $nr_title_chars = 95;
  1251. //check to see if we have or not sidebar on the page, to set the small images when need to show them on center
  1252. //if(td_global::$cur_single_template_sidebar_pos == 'no_sidebar') {
  1253. if ( is_single() ) {
  1254. if ( $loop_sidebar_position == 'no_sidebar' || $page_template_slug === 'page-pagebuilder-latest.php' ) {
  1255. $td_double_slider2_no_js_limit = 11;
  1256. $td_nr_columns_slide = 'td-slide-on-3-columns';
  1257. $nr_title_chars = 170;
  1258. }
  1259. }
  1260. $title_slide = '';
  1261. //check for the title
  1262. if(!empty($atts['td_gallery_title_input'])) {
  1263. $title_slide = $atts['td_gallery_title_input'];
  1264. //check how many chars the tile have, if more then 84 then that cut it and add ... after
  1265. if(mb_strlen ($title_slide, 'UTF-8') > $nr_title_chars) {
  1266. $title_slide = mb_substr($title_slide, 0, $nr_title_chars, 'UTF-8') . '...';
  1267. }
  1268. }
  1269. $slide_images_thumbs_css = '';
  1270. $slide_display_html = '';
  1271. $slide_cursor_html = '';
  1272. $image_ids = explode(',', $atts['ids']);
  1273. //check to make sure we have images
  1274. if (count($image_ids) == 1 and !is_numeric($image_ids[0])) {
  1275. return;
  1276. }
  1277. $image_ids = array_map('trim', $image_ids);//trim elements of the $ids_gallery array
  1278. //generate unique gallery slider id
  1279. $gallery_slider_unique_id = td_global::td_generate_unique_id();
  1280. $cur_item_nr = 1;
  1281. foreach($image_ids as $image_id) {
  1282. //get the info about attachment
  1283. $image_attachment = td_util::attachment_get_full_info($image_id);
  1284. //get images url
  1285. $td_temp_image_url_80x60 = wp_get_attachment_image_src($image_id, 'td_80x60'); //for the slide - for small images slide popup
  1286. $td_temp_image_url_full = $image_attachment['src']; //default big image - for magnific popup
  1287. //image type and width - used to retrieve retina image
  1288. $thumbnail_type = 'td_0x420';
  1289. $thumbnail_width = '420';
  1290. //if we are on full wight (3 columns use the default images not the resize ones)
  1291. if ($loop_sidebar_position == 'no_sidebar' || $page_template_slug === 'page-pagebuilder-latest.php') {
  1292. switch (TD_THEME_NAME) {
  1293. case 'Newspaper' :
  1294. $td_temp_image_url = wp_get_attachment_image_src($image_id, 'td_1068x580'); //1021x580 images - for big slide
  1295. //change image type and width - used to retrieve retina image
  1296. $thumbnail_type = 'td_1068x580';
  1297. $thumbnail_width = '1068';
  1298. break;
  1299. case 'Newsmag' :
  1300. $td_temp_image_url = wp_get_attachment_image_src($image_id, 'td_1021x580'); //1021x580 images - for big slide
  1301. //image type and width - used to retrieve retina image
  1302. $thumbnail_type = 'td_1021x580';
  1303. $thumbnail_width = '1021';
  1304. break;
  1305. }
  1306. } else {
  1307. $td_temp_image_url = wp_get_attachment_image_src($image_id, 'td_0x420'); //0x420 image sizes - for big slide
  1308. }
  1309. //check if we have all the images
  1310. if(!empty($td_temp_image_url[0]) and !empty($td_temp_image_url_80x60[0]) and !empty($td_temp_image_url_full)) {
  1311. //retina image
  1312. $srcset_sizes = td_util::get_srcset_sizes($image_id, $thumbnail_type, $thumbnail_width, $td_temp_image_url[0]);
  1313. if (td_util::get_option('tds_thumb_td_80x60_retina') == 'yes') {
  1314. $small_thumb = wp_get_attachment_image_src($image_id, 'td_80x60_retina');
  1315. if ($small_thumb !== false) {
  1316. $td_temp_image_url_80x60[0] = $small_thumb[0];
  1317. }
  1318. }
  1319. //css for display the small cursor image
  1320. $slide_images_thumbs_css .= '
  1321. #' . $gallery_slider_unique_id . ' .td-doubleSlider-2 .td-item' . $cur_item_nr . ' {
  1322. background: url(' . $td_temp_image_url_80x60[0] . ') 0 0 no-repeat;
  1323. }';
  1324. //html for display the big image
  1325. $class_post_content = '';
  1326. if(!empty($image_attachment['description']) or !empty($image_attachment['caption'])) {
  1327. $class_post_content = 'td-gallery-slide-content';
  1328. }
  1329. //if picture has caption & description
  1330. $figcaption = '';
  1331. if(!empty($image_attachment['caption']) or !empty($image_attachment['description'])) {
  1332. $figcaption = '<figcaption class = "td-slide-caption ' . $class_post_content . '">';
  1333. if(!empty($image_attachment['caption'])) {
  1334. $figcaption .= '<div class = "td-gallery-slide-copywrite">' . $image_attachment['caption'] . '</div>';
  1335. }
  1336. if(!empty($image_attachment['description'])) {
  1337. $figcaption .= '<span>' . $image_attachment['description'] . '</span>';
  1338. }
  1339. $figcaption .= '</figcaption>';
  1340. }
  1341. $slide_display_html .= '
  1342. <div class = "td-slide-item td-item' . $cur_item_nr . '">
  1343. <figure class="td-slide-galery-figure td-slide-popup-gallery">
  1344. <a class="slide-gallery-image-link" href="' . $td_temp_image_url_full . '" title="' . $image_attachment['title'] . '" data-caption="' . esc_attr($image_attachment['caption'], ENT_QUOTES) . '" data-description="' . htmlentities($image_attachment['description'], ENT_QUOTES) . '">
  1345. <img src="' . $td_temp_image_url[0] . '"' . $srcset_sizes . ' alt="' . htmlentities($image_attachment['alt'], ENT_QUOTES) . '">
  1346. </a>
  1347. ' . $figcaption . '
  1348. </figure>
  1349. </div>';
  1350. //html for display the small cursor image
  1351. $slide_cursor_html .= '
  1352. <div class = "td-button td-item' . $cur_item_nr . '">
  1353. <div class = "td-border"></div>
  1354. </div>';
  1355. $cur_item_nr++;
  1356. }//end check for images
  1357. }//end foreach
  1358. //check if we have html code for the slider
  1359. if(!empty($slide_display_html) and !empty($slide_cursor_html)) {
  1360. //get the number of slides
  1361. $nr_of_slides = count($image_ids);
  1362. if($nr_of_slides < 0) {
  1363. $nr_of_slides = 0;
  1364. }
  1365. $buffy = '
  1366. <style type="text/css">
  1367. ' .
  1368. $slide_images_thumbs_css . '
  1369. </style>
  1370. <div id="' . $gallery_slider_unique_id . '" class="td-gallery ' . $td_nr_columns_slide . '">
  1371. <div class="post_td_gallery">
  1372. <div class="td-gallery-slide-top">
  1373. <div class="td-gallery-title">' . $title_slide . '</div>
  1374. <div class="td-gallery-controls-wrapper">
  1375. <div class="td-gallery-slide-count"><span class="td-gallery-slide-item-focus">1</span> ' . __td('of', TD_THEME_NAME) . ' ' . $nr_of_slides . '</div>
  1376. <div class="td-gallery-slide-prev-next-but">
  1377. <i class = "td-icon-left doubleSliderPrevButton"></i>
  1378. <i class = "td-icon-right doubleSliderNextButton"></i>
  1379. </div>
  1380. </div>
  1381. </div>
  1382. <div class = "td-doubleSlider-1 ">
  1383. <div class = "td-slider">
  1384. ' . $slide_display_html . '
  1385. </div>
  1386. </div>
  1387. <div class = "td-doubleSlider-2">
  1388. <div class = "td-slider">
  1389. ' . $slide_cursor_html . '
  1390. </div>
  1391. </div>
  1392. </div>
  1393. </div>
  1394. ';
  1395. $slide_javascript = '
  1396. <script>
  1397. //total number of slides
  1398. var ' . $gallery_slider_unique_id . '_nr_of_slides = ' . $nr_of_slides . ';
  1399. jQuery(document).ready(function() {
  1400. //magnific popup
  1401. jQuery("#' . $gallery_slider_unique_id . ' .td-slide-popup-gallery").magnificPopup({
  1402. delegate: "a.slide-gallery-image-link",
  1403. type: "image",
  1404. tLoading: "Loading image #%curr%...",
  1405. mainClass: "mfp-img-mobile",
  1406. gallery: {
  1407. enabled: true,
  1408. navigateByImgClick: true,
  1409. preload: [0,1],
  1410. tCounter: \'%curr% ' . __td('of', TD_THEME_NAME) . ' %total%\'
  1411. },
  1412. image: {
  1413. tError: "<a href=\'%url%\'>The image #%curr%</a> could not be loaded.",
  1414. titleSrc: function(item) {//console.log(item.el);
  1415. //alert(jQuery(item.el).data("caption"));
  1416. return item.el.attr("data-caption") + "<div>" + item.el.attr("data-description") + "<div>";
  1417. }
  1418. },
  1419. zoom: {
  1420. enabled: true,
  1421. duration: 300,
  1422. opener: function(element) {
  1423. return element.find("img");
  1424. }
  1425. },
  1426. callbacks: {
  1427. change: function() {
  1428. // Will fire when popup is closed
  1429. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-1").iosSlider("goToSlide", this.currItem.index + 1 );
  1430. }
  1431. }
  1432. });
  1433. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-1").iosSlider({
  1434. scrollbar: true,
  1435. snapToChildren: true,
  1436. desktopClickDrag: true,
  1437. infiniteSlider: true,
  1438. responsiveSlides: true,
  1439. navPrevSelector: jQuery("#' . $gallery_slider_unique_id . ' .doubleSliderPrevButton"),
  1440. navNextSelector: jQuery("#' . $gallery_slider_unique_id . ' .doubleSliderNextButton"),
  1441. scrollbarHeight: "2",
  1442. scrollbarBorderRadius: "0",
  1443. scrollbarOpacity: "0.5",
  1444. onSliderResize: td_gallery_resize_update_vars_' . $gallery_slider_unique_id . ',
  1445. onSliderLoaded: doubleSlider2Load_' . $gallery_slider_unique_id . ',
  1446. onSlideChange: doubleSlider2Load_' . $gallery_slider_unique_id . ',
  1447. keyboardControls:true
  1448. });
  1449. //small image slide
  1450. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-2 .td-button").each(function(i) {
  1451. jQuery(this).bind("click", function() {
  1452. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-1").iosSlider("goToSlide", i+1);
  1453. });
  1454. });
  1455.  
  1456.  
  1457.  
  1458.  
  1459. // Create slider_2 only when the content elements are wider than the wrapper
  1460. var $gallery_slider_unique_id = jQuery("#' . $gallery_slider_unique_id . '");
  1461.  
  1462. if ( $gallery_slider_unique_id.length ) {
  1463.  
  1464. var sliderWidth = $gallery_slider_unique_id.width(),
  1465. elementsWidth = 0;
  1466.  
  1467. $gallery_slider_unique_id.find( ".td-button").each(function(index, el) {
  1468. elementsWidth += jQuery(el).outerWidth( true );
  1469. });
  1470.  
  1471. //check the number of slides
  1472. //if( parseInt(' . $gallery_slider_unique_id . '_nr_of_slides) > $td_double_slider2_no_js_limit) {
  1473. if( elementsWidth > sliderWidth ) {
  1474. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-2").iosSlider({
  1475. desktopClickDrag: true,
  1476. snapToChildren: true,
  1477. snapSlideCenter: true,
  1478. infiniteSlider: true
  1479. });
  1480. } else {
  1481. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-2").addClass("td_center_slide2");
  1482. }
  1483. }
  1484.  
  1485.  
  1486.  
  1487.  
  1488. function doubleSlider2Load_' . $gallery_slider_unique_id . '(args) {
  1489. //var currentSlide = args.currentSlideNumber;
  1490. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-2").iosSlider("goToSlide", args.currentSlideNumber);
  1491. //put a transparent border around all small sliders
  1492. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-2 .td-button .td-border").css("border", "3px solid #ffffff").css("opacity", "0.5");
  1493. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-2 .td-button").css("border", "0");
  1494. //put a white border around the focused small slide
  1495. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-2 .td-button:eq(" + (args.currentSlideNumber-1) + ") .td-border").css("border", "3px solid #ffffff").css("opacity", "1");
  1496. //jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-2 .td-button:eq(" + (args.currentSlideNumber-1) + ")").css("border", "3px solid #ffffff");
  1497. //write the current slide number
  1498. td_gallery_write_current_slide_' . $gallery_slider_unique_id . '(args.currentSlideNumber);
  1499. }
  1500. //writes the current slider beside to prev and next buttons
  1501. function td_gallery_write_current_slide_' . $gallery_slider_unique_id . '(slide_nr) {
  1502. jQuery("#' . $gallery_slider_unique_id . ' .td-gallery-slide-item-focus").html(slide_nr);
  1503. }
  1504. /*
  1505. * Resize the iosSlider when the page is resided (fixes bug on Android devices)
  1506. */
  1507. function td_gallery_resize_update_vars_' . $gallery_slider_unique_id . '(args) {
  1508. if(tdDetect.isAndroid || tdDetect.isIos) {
  1509. setTimeout(function(){
  1510. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-1").iosSlider("update");
  1511. }, 1500);
  1512. }
  1513. }
  1514. });
  1515. </script>
  1516. ';
  1517. $slide_javascript = td_util::remove_script_tag( $slide_javascript );
  1518. td_js_buffer::add_to_footer( $slide_javascript);
  1519. }//end check if we have html code for the slider
  1520. }//end if slide
  1521. //!!!!!! WARNING
  1522. //$return has to be != empty to overwride the default output
  1523. return $buffy;
  1524. }
  1525. /* ----------------------------------------------------------------------------
  1526. * add custom classes to the single templates, also mix fixes for white menu and white grid
  1527. */
  1528. add_filter('body_class', 'td_add_single_template_class');
  1529. function td_add_single_template_class($classes) {
  1530. if (is_single()) {
  1531. global $post;
  1532. $active_single_template = '';
  1533. $td_post_theme_settings = td_util::get_post_meta_array($post->ID, 'td_post_theme_settings');
  1534. if (!empty($td_post_theme_settings['td_post_template'])) {
  1535. // we have a post template set in the post
  1536. $active_single_template = $td_post_theme_settings['td_post_template'];
  1537. } else {
  1538. // we may have a global post template form td panel
  1539. $td_default_site_post_template = td_util::get_option('td_default_site_post_template');
  1540. if(!empty($td_default_site_post_template)) {
  1541. $active_single_template = $td_default_site_post_template;
  1542. }
  1543. }
  1544. // add the class if we have a post template
  1545. if (!empty($active_single_template)) {
  1546. if ( td_global::is_tdb_template( $active_single_template ) ) {
  1547. td_global::$cur_single_template = 'single_template';
  1548. } else {
  1549. td_global::$cur_single_template = $active_single_template;
  1550. }
  1551. $classes []= sanitize_html_class($active_single_template);
  1552. }
  1553. }
  1554. // if main menu background color is white to fix the menu appearance on all headers
  1555. if (td_util::get_option('tds_menu_color') == '#ffffff' or td_util::get_option('tds_menu_color') == 'ffffff') {
  1556. $classes[] = 'white-menu';
  1557. }
  1558. // if grid color is white to fix the menu appearance on all headers
  1559. if (td_util::get_option('tds_grid_line_color') == '#ffffff' or td_util::get_option('tds_grid_line_color') == 'ffffff') {
  1560. $classes[] = 'white-grid';
  1561. }
  1562. return $classes;
  1563. }
  1564. if( TD_THEME_NAME == 'Newsmag' || ( TD_THEME_NAME == 'Newspaper' && defined('TD_STANDARD_PACK') ) ) {
  1565. /* ----------------------------------------------------------------------------
  1566. * add custom classes to the category templates, also mix fixes for white menu and white grid
  1567. */
  1568. add_filter('body_class', 'td_add_category_template_class');
  1569. function td_add_category_template_class($classes) {
  1570. if(!is_admin() and is_category()) {
  1571. if ( td_global::is_tdb_registered() ) {
  1572. $current_category = get_queried_object();
  1573. $tdb_category_template_global = td_options::get( 'tdb_category_template' );
  1574. $tdb_category_template = td_util::get_category_option( $current_category->cat_ID, 'tdb_category_template');
  1575. if ( empty( $tdb_category_template ) ) {
  1576. $tdb_category_template = $tdb_category_template_global;
  1577. }
  1578. if ( ! empty( $tdb_category_template ) && ( 'theme_templates' !== $tdb_category_template ) && td_global::is_tdb_template( $tdb_category_template, true ) ) {
  1579. return $classes;
  1580. }
  1581. }
  1582. $classes [] = sanitize_html_class(td_api_category_template::_helper_get_active_id());
  1583. $classes [] = sanitize_html_class(td_api_category_top_posts_style::_helper_get_active_id());
  1584. }
  1585. return $classes;
  1586. }
  1587. /* ----------------------------------------------------------------------------
  1588. * modify the main query for category pages
  1589. */
  1590. add_action('pre_get_posts', 'td_modify_main_query_for_category_page');
  1591. function td_modify_main_query_for_category_page($query) {
  1592. //checking for category page and main query
  1593. if(!is_admin() and is_category() and $query->is_main_query()) {
  1594. // get the category object - with or without permalinks
  1595. if (empty($query->query_vars['cat'])) {
  1596. td_global::$current_category_obj = get_category_by_path(get_query_var('category_name'), false); // when we have permalinks, we have to get the category object like this.
  1597. } else {
  1598. td_global::$current_category_obj = get_category($query->query_vars['cat']);
  1599. }
  1600. // we are on a category page with an ID that doesn't exists - wp will show a 404 and we do nothing
  1601. if (is_null(td_global::$current_category_obj)) {
  1602. return;
  1603. }
  1604. // run our filter and check it's returned value. If tdb plugin did it's query modifications this will return 'true' and we do nothing here.
  1605. $tdb_template_overwrite = apply_filters( 'tdb_category_template_query_overwrite', false );
  1606. // if the was overwritten return here
  1607. if ( $tdb_template_overwrite === true ) {
  1608. return;
  1609. }
  1610. //get the number of page where on
  1611. $paged = get_query_var('paged');
  1612. //get the `filter_by` URL($_GET) variable
  1613. $filter_by = '';
  1614. if (isset($_GET['filter_by'])) {
  1615. $filter_by = $_GET['filter_by'];
  1616. }
  1617. //get the limit of posts on the category page
  1618. $limit = get_option('posts_per_page');
  1619. switch ($filter_by) {
  1620. case 'featured':
  1621. //get the category object
  1622. $query->set('category_name', td_global::$current_category_obj->slug);
  1623. $query->set('cat', get_cat_ID(TD_FEATURED_CAT)); //add the fetured cat
  1624. break;
  1625. case 'popular':
  1626. $query->set('meta_key', td_page_views::$post_view_counter_key);
  1627. $query->set('orderby', 'meta_value_num');
  1628. $query->set('order', 'DESC');
  1629. break;
  1630. case 'popular7':
  1631. $query->set('meta_key', td_page_views::$post_view_counter_7_day_total);
  1632. $query->set('orderby', 'meta_value_num');
  1633. $query->set('order', 'DESC');
  1634. break;
  1635. case 'review_high':
  1636. $query->set('meta_key', 'td_review_key');
  1637. $query->set('orderby', 'meta_value_num');
  1638. $query->set('order', 'DESC');
  1639. break;
  1640. case 'random_posts':
  1641. $query->set('orderby', 'rand');
  1642. break;
  1643. }//end switch
  1644. // how many posts are we showing in the big grid for this category
  1645. $offset = td_api_category_top_posts_style::_helper_get_posts_shown_in_the_loop();
  1646. // offset + custom pagination - if we have offset, WordPress overwrites the pagination and works with offset + limit
  1647. if(empty($query->is_feed)) {
  1648. if ( $paged > 1 ) {
  1649. $query->set( 'offset', intval($offset) + ( ( $paged - 1 ) * $limit ) );
  1650. } else {
  1651. $query->set( 'offset', intval($offset) );
  1652. }
  1653. }
  1654. //print_r($query);
  1655. }//end if main query
  1656. }
  1657. /* ----------------------------------------------------------------------------
  1658. * register the default footer sidebars
  1659. */
  1660. add_action( 'widgets_init', function (){
  1661. register_sidebar(
  1662. array(
  1663. 'name'=>'Footer 1',
  1664. 'id' => 'td-footer-1',
  1665. 'before_widget' => '<aside class="widget %2$s">',
  1666. 'after_widget' => '</aside>',
  1667. 'before_title' => '<div class="block-title"><span>',
  1668. 'after_title' => '</span></div>'
  1669. )
  1670. );
  1671. register_sidebar(
  1672. array(
  1673. 'name'=>'Footer 2',
  1674. 'id' => 'td-footer-2',
  1675. 'before_widget' => '<aside class="widget %2$s">',
  1676. 'after_widget' => '</aside>',
  1677. 'before_title' => '<div class="block-title"><span>',
  1678. 'after_title' => '</span></div>'
  1679. )
  1680. );
  1681. register_sidebar(
  1682. array(
  1683. 'name'=>'Footer 3',
  1684. 'id' => 'td-footer-3',
  1685. 'before_widget' => '<aside class="widget %2$s">',
  1686. 'after_widget' => '</aside>',
  1687. 'before_title' => '<div class="block-title"><span>',
  1688. 'after_title' => '</span></div>'
  1689. )
  1690. );
  1691. }, 11);
  1692. // This points to the post format archive template( like video post format )
  1693. add_filter( 'archive_template', function( $taxonomy_post_format ){
  1694. if ( is_tax( 'post_format' ) ) {
  1695. $taxonomy_post_format = TDC_PATH_LEGACY . '/taxonomy-post_format.php';
  1696. }
  1697. return $taxonomy_post_format;
  1698. });
  1699. }
  1700. /** ----------------------------------------------------------------------------
  1701. * update category shared terms
  1702. * @since WordPress 4.2
  1703. * @link https://make.wordpress.org/core/2015/02/16/taxonomy-term-splitting-in-4-2-a-developer-guide/
  1704. */
  1705. add_action('split_shared_term', 'td_category_split_shared_term', 10, 4);
  1706. function td_category_split_shared_term($term_id, $new_term_id, $term_taxonomy_id, $taxonomy) {
  1707. $td_options = &td_options::get_all_by_ref();
  1708. if (($taxonomy === 'category') and (isset($td_options['category_options'][$term_id]))) {
  1709. $current_settings = $td_options['category_options'][$term_id];
  1710. $td_options['category_options'][$new_term_id] = $current_settings;
  1711. unset($td_options['category_options'][$term_id]);
  1712. td_options::schedule_save();
  1713. // update_option(TD_THEME_OPTIONS_NAME, td_global::$td_options);
  1714. }
  1715. }
  1716. /* ----------------------------------------------------------------------------
  1717. * TagDiv WordPress booster init
  1718. */
  1719. global $content_width;
  1720. if ( !isset($content_width) ) {
  1721. $content_width = 1068; // Overwritten by td_init_booster
  1722. }
  1723. td_init_booster();
  1724. function td_init_booster() {
  1725. global $content_width;
  1726. // content width - this is overwritten in post
  1727. switch (TD_THEME_NAME) {
  1728. case 'Newspaper' :
  1729. $content_width = 696;
  1730. break;
  1731. case 'Newsmag' :
  1732. $content_width = 640;
  1733. break;
  1734. }
  1735. /* ----------------------------------------------------------------------------
  1736. * add_image_size for WordPress - register all the thumbs from the thumblist
  1737. */
  1738. foreach (td_api_thumb::get_all() as $thumb_array) {
  1739. if (td_util::get_option('tds_thumb_' . $thumb_array['name']) != '') {
  1740. add_image_size($thumb_array['name'], $thumb_array['width'], $thumb_array['height'], $thumb_array['crop']);
  1741. //add retina thumb (only if it is enabled)
  1742. if (td_util::get_option('tds_thumb_' . $thumb_array['name'] . '_retina') != '') {
  1743. add_image_size($thumb_array['name'] . '_retina', $thumb_array['width']*2, $thumb_array['height']*2, $thumb_array['crop']);
  1744. }
  1745. }
  1746. }
  1747. /**
  1748. * Add default render function for 'td_block_social_counter' shortcode.
  1749. * It's overwritten by the social counter plugin.
  1750. */
  1751. /*
  1752. add_shortcode('td_block_social_counter', 'td_block_social_counter_func');
  1753. function td_block_social_counter_func($atts) {
  1754. if ( current_user_can( 'administrator' ) ) {
  1755. $buffer = '';
  1756. $buffer .= '<style>
  1757. .td-block-social-counter {
  1758. border: 1px solid red;
  1759. min-height: 50px;
  1760. line-height: 50px;
  1761. vertical-align: middle;
  1762. text-align: center;
  1763. }
  1764. .td-block-social-counter:before {
  1765. content: "Activate Social Counter plugin";
  1766. }
  1767. </style>';
  1768. $buffer .= '<div class="td-block-social-counter"></div>';
  1769. return $buffer;
  1770. }
  1771. return '';
  1772. }
  1773. */
  1774. /* ----------------------------------------------------------------------------
  1775. * Add lazy shortcodes of the registered blocks
  1776. */
  1777. foreach (td_api_block::get_all() as $block_settings_key => $block_settings_value) {
  1778. $global_block_class = 'td_global_blocks';
  1779. if ( class_exists( 'tdc_global_blocks', false )) {
  1780. $global_block_class = 'tdc_global_blocks';
  1781. }
  1782. $global_block_class::add_lazy_shortcode($block_settings_key);
  1783. }
  1784. /* ----------------------------------------------------------------------------
  1785. * register the default sidebars + dynamic ones
  1786. */
  1787. add_action( 'widgets_init', function (){
  1788. register_sidebar(
  1789. array(
  1790. 'name'=> TD_THEME_NAME . ' default',
  1791. 'id' => 'td-default', //the id is used by the importer
  1792. 'before_widget' => '<aside class="widget %2$s">',
  1793. 'after_widget' => '</aside>',
  1794. 'before_title' => '<div class="block-title"><span>',
  1795. 'after_title' => '</span></div>'
  1796. )
  1797. );
  1798. // get our custom dynamic sidebars
  1799. $currentSidebars = td_options::get_array('sidebars');
  1800. // if we have any, register them in wp
  1801. if ( ! empty( $currentSidebars ) ) {
  1802. foreach ( $currentSidebars as $sidebar ) {
  1803. register_sidebar(
  1804. array(
  1805. 'name' => $sidebar,
  1806. 'id' => 'td-' . td_util::sidebar_name_to_id( $sidebar ),
  1807. 'before_widget' => '<aside class="widget %2$s">',
  1808. 'after_widget' => '</aside>',
  1809. 'before_title' => '<div class="block-title"><span>',
  1810. 'after_title' => '</span></div>',
  1811. )
  1812. );
  1813. }
  1814. }
  1815. });
  1816. }
  1817. //@td_js
  1818. require_once('td_js.php');
  1819. /* ----------------------------------------------------------------------------
  1820. check to see if we are on the backend
  1821. */
  1822. if (is_admin()) {
  1823. // demo inmporter
  1824. require_once('wp-admin/panel/td_demo_installer.php');
  1825. require_once('wp-admin/panel/td_demo_util.php');
  1826. /* ----------------------------------------------------------------------------
  1827. The theme panel + plugins panels
  1828. */
  1829. require_once('wp-admin/panel/panel_core/td_panel_core.php');
  1830. require_once('wp-admin/panel/panel_core/td_panel_generator.php');
  1831. if ( current_user_can('switch_themes' ) ) {
  1832. // add the theme panel only if we have permissions
  1833. require_once('wp-admin/panel/td_panel.php');
  1834. require_once(ABSPATH . 'wp-admin/includes/file.php');
  1835. WP_Filesystem();
  1836. }
  1837. /**
  1838. * the wp-admin TinyMCE editor buttons
  1839. */
  1840. require_once('wp-admin/tinymce/tinymce.php');
  1841. /**
  1842. * get tinymce formats
  1843. */
  1844. td_api_tinymce_formats::_helper_get_tinymce_format();
  1845. /**
  1846. * Helper pointers
  1847. */
  1848. add_action('admin_enqueue_scripts', 'td_help_pointers');
  1849. function td_help_pointers() {
  1850. //First we define our pointers
  1851. $pointers = array(
  1852. array(
  1853. 'id' => 'vc_columns_pointer', // unique id for this pointer
  1854. 'screen' => 'page', // this is the page hook we want our pointer to show on
  1855. 'target' => '.composer-switch .logo-icon', // the css selector for the pointer to be tied to, best to use ID's
  1856. 'title' => TD_THEME_NAME . ' (tagDiv) tip',
  1857. 'content' => '<img class="td-tip-vc-columns" style="max-width:100%" src="' . td_global::$get_template_directory_uri . '/legacy/common/wp_booster/wp-admin/images/td_helper_pointers/vc-columns.png' . '">',
  1858. 'position' => array(
  1859. 'edge' => 'top', //top, bottom, left, right
  1860. 'align' => 'left' //top, bottom, left, right, middle
  1861. )
  1862. )
  1863. // more as needed
  1864. );
  1865. //Now we instantiate the class and pass our pointer array to the constructor
  1866. new td_help_pointers($pointers);
  1867. }
  1868. // Important! For the shortcode widgets that have 'block_template_id' param, the new instance (the modified instance) is returned.
  1869. // This BECAUSE the new instance have the all modifications (including new params)
  1870. // Changed from 10 to 1 for WPML support
  1871. add_filter('widget_update_callback', 'td_widget_update', 1, 2);
  1872. function td_widget_update($instance, $new_instance) {
  1873. if (array_key_exists('block_template_id', $new_instance)) {
  1874. return $new_instance;
  1875. }
  1876. return $instance;
  1877. }
  1878. }
  1879. add_filter('redirect_canonical', 'td_fix_wp_441_pagination', 10, 2);
  1880. function td_fix_wp_441_pagination($redirect_url, $requested_url) {
  1881. global $wp_query;
  1882. if (is_page() && !is_feed() && isset($wp_query->queried_object) && get_query_var('page') && get_page_template_slug($wp_query->queried_object->ID) == 'page-pagebuilder-latest.php') {
  1883. return false;
  1884. }
  1885. return $redirect_url;
  1886. }
  1887. /**
  1888. * adds Theme Panel button in wp theme customizer panel
  1889. * useful for clients who don't know where the theme settings are located
  1890. *
  1891. * @since 28.03.2019 this is available only if the td composer plugin is active and the theme panel is enabled from api features
  1892. *
  1893. */
  1894. if ( td_api_features::is_enabled('require_panel' ) ) {
  1895. add_action('customize_controls_print_footer_scripts', 'td_customize_js');
  1896. }
  1897. function td_customize_js() {
  1898. echo "<script type=\"text/javascript\">
  1899. (function() {
  1900. jQuery('#customize-theme-controls > ul').prepend('<li id=\"accordion-section-theme-panel\" class=\"accordion-section control-section\"><h3 class=\"accordion-section-title\">Theme Panel</h3></li>');
  1901. jQuery('#accordion-section-theme-panel').on('click', function(){
  1902. window.location.replace('" . admin_url() . "admin.php?page=td_theme_panel');
  1903. });
  1904. })()
  1905. </script>
  1906. ";
  1907. }
  1908. add_filter('admin_body_class', 'td_on_admin_body_class' );
  1909. function td_on_admin_body_class( $classes ) {
  1910. $classes .= ' td-theme-' . TD_THEME_NAME;
  1911. return $classes;
  1912. }
  1913. // Remove 'block_template_id' param from VC params
  1914. add_action('vc_edit_form_fields_after_render', 'td_vc_edit_form_fields_after_render');
  1915. function td_vc_edit_form_fields_after_render() {
  1916. ob_start();
  1917. ?>
  1918. <script type="text/javascript">
  1919. (function(){
  1920. var $panelEditElement = jQuery('#vc_ui-panel-edit-element');
  1921. if ($panelEditElement.length) {
  1922. var $selectBlockTemplateId = $panelEditElement.find("select[name='block_template_id']");
  1923. if ($selectBlockTemplateId.length) {
  1924. $selectBlockTemplateId.closest('.vc_shortcode-param').hide();
  1925. }
  1926. }
  1927. })();
  1928. </script>
  1929. <?php
  1930. echo ob_get_clean();
  1931. }
  1932. /**
  1933. * Filter sets the global block template to the wp widgets
  1934. * @see 'widget_display_callback' hook on 'class-wp-widget.php'
  1935. */
  1936. add_filter('widget_display_callback', 'on_widget_display_callback', 10, 3);
  1937. function on_widget_display_callback($currentWidgetInstanceSettings, $currentWidgetInstance, $widgetArgs) {
  1938. if (strpos($widgetArgs['widget_id'], 'td_block') !== 0) {
  1939. // var_dump($widgetArgs);
  1940. // var_dump($currentWidgetInstance);
  1941. $global_block_template_id = td_options::get('tds_global_block_template', 'td_block_template_1');
  1942. $widgetArgs['before_widget'] = str_replace(' class="', " class=\"$global_block_template_id ", $widgetArgs['before_widget']);
  1943. $block_title_class = 'td-block-title';
  1944. if ($global_block_template_id === 'td_block_template_1') {
  1945. $block_title_class = 'block-title';
  1946. }
  1947. $widgetArgs['before_title'] = '<h4 class="' . $block_title_class . '"><span>';
  1948. $widgetArgs['after_title'] = '</span></h4>';
  1949. call_user_func_array(array($currentWidgetInstance, 'widget'), array($widgetArgs, $currentWidgetInstanceSettings));
  1950. // Returning false will effectively short-circuit display of the widget.
  1951. return false;
  1952. }
  1953. // Returning $currentWidgetInstanceSettings, as the apply_filters of this hook require
  1954. return $currentWidgetInstanceSettings;
  1955. }
  1956. /**
  1957. * tagDiv AMP/AMP plugins notices
  1958. * @since 28.02.2019 this also disables the tagDiv amp plugin and displays a message that the tagDiv amp plugin has been discontinued and the AMP + tagDiv Mobile Theme now provide full support for amp
  1959. */
  1960. add_action( 'init', 'td_add_amp_plugin_action_link_filters_on_init' );
  1961. function td_add_amp_plugin_action_link_filters_on_init() {
  1962. // get all the plugins
  1963. $wp_installed_plugins_list = get_plugins();
  1964. foreach ( $wp_installed_plugins_list as $plugin_slug => $plugin_data ) {
  1965. if ( $plugin_data['Title'] === 'tagDiv AMP' ) {
  1966. if ( class_exists( 'td_amp_version_check', false ) ) {
  1967. deactivate_plugins( 'td-amp/td-amp.php' );
  1968. }
  1969. add_filter( 'plugin_action_links_' . $plugin_slug, function ( $actions ) {
  1970. unset( $actions['activate'] );
  1971. return $actions;
  1972. }, 20 );
  1973. add_action( 'after_plugin_row_' . $plugin_slug, function ($plugin_file, $plugin_data, $status){
  1974. echo '
  1975. <tr class="td-amp-plugin-warning plugin-update-tr">
  1976. <td colspan="3" class="plugin-update colspanchange">
  1977. <div class="notice inline notice-warning notice-alt" style="">
  1978. <p>The <b>tagDiv AMP</b> plugin has been automatically disabled as it was discontinued by the author. <br> NOTE: We recommend using the new AMP solution that is now builtin the <b>tagDiv Mobile Theme</b> plugin. You can find out more <a href="https://tagdiv.com/amp-newspaper-theme/" target="_blank">here</a>.</p>
  1979. </div>
  1980. </td>
  1981. </tr>
  1982. ';
  1983. }, 10, 3 );
  1984. }
  1985. if ( $plugin_data['Title'] === 'AMP' ) {
  1986. add_action( 'after_plugin_row_' . $plugin_slug, function ($plugin_file, $plugin_data, $status){
  1987. echo '
  1988. <tr class="td-amp-plugin-warning plugin-update-tr">
  1989. <td colspan="3" class="plugin-update colspanchange">
  1990. <div class="notice inline notice-warning notice-alt" style="">
  1991. <p>The <b>tagDiv Mobile Theme</b> now works best with the <b>AMP</b> plugin to provide a complete solution for your content on mobiles. You can find out more <a href="https://tagdiv.com/amp-newspaper-theme/" target="_blank">here</a>.</p>
  1992. </div>
  1993. </td>
  1994. </tr>
  1995. ';
  1996. }, 10, 3 );
  1997. }
  1998. }
  1999. }
  2000. /**
  2001. * - intercept the single template
  2002. * - @since 26.2.2018 - this method of verifying the template is very odd. There is no reason why it's done this way instead of is_singular('post')
  2003. * - RUNS AFTER the hook from the template builder
  2004. * - we do nothing here where a template builder id is detected
  2005. */
  2006. add_filter( 'template_include', 'td_template_include_filter');
  2007. function td_template_include_filter( $wordpress_template_path ) {
  2008. $td_is_td_template_include_filter = false;
  2009. // check if child theme is active - fix for changing post template, when the template file doesn't exist in child theme
  2010. if (is_child_theme()) {
  2011. if (
  2012. is_single() &&
  2013. (
  2014. $wordpress_template_path == TEMPLATEPATH . '/single.php' ||
  2015. $wordpress_template_path == STYLESHEETPATH . '/single.php'
  2016. )
  2017. ) {
  2018. // remove the filter to allow Child theme overwrite
  2019. remove_filter( 'template_include', 'tdc_template_include', 99);
  2020. $td_is_td_template_include_filter = true;
  2021. }
  2022. }
  2023. if (
  2024. is_single() && (
  2025. true ||
  2026. $wordpress_template_path == td_global::$get_template_directory . '/single.php' ||
  2027. $wordpress_template_path == get_stylesheet_directory() . '/single.php'
  2028. )
  2029. ) {
  2030. $td_is_td_template_include_filter = true;
  2031. }
  2032. if ($td_is_td_template_include_filter) {
  2033. global $post;
  2034. // if we are on a custom post type, leave the defaul loaded wordpress template
  2035. if ( $post->post_type != 'post' ) {
  2036. return $wordpress_template_path;
  2037. }
  2038. // check if we have a specific template set on the current post
  2039. $td_post_theme_settings = td_util::get_post_meta_array( $post->ID, 'td_post_theme_settings' );
  2040. if ( !empty( $td_post_theme_settings['td_post_template'] ) ) {
  2041. $single_template_id = $td_post_theme_settings['td_post_template'];
  2042. if ( td_global::is_tdb_template($single_template_id)) {
  2043. // make sure the template exists, maybe it was deleted or something
  2044. if ( td_global::is_tdb_template( $single_template_id, true ) ) {
  2045. $tdb_template_id = td_global::tdb_get_template_id($single_template_id);
  2046. // run our filter and check it's returned value. If tdb did nothing or it's not installed, we do nothing.
  2047. $td_single_override = apply_filters( 'td_single_override', $tdb_template_id ); // in: template id out: tdb view single template path
  2048. if ( $td_single_override != $tdb_template_id ) {
  2049. return $td_single_override;
  2050. }
  2051. } else {
  2052. // just reset the post template here, the panel default post template will kick in and load, if available
  2053. $td_post_theme_settings['td_post_template'] = '';
  2054. update_post_meta( $post->ID, 'td_post_theme_settings', $td_post_theme_settings );
  2055. }
  2056. } else {
  2057. // it's a theme template, load that one
  2058. return td_api_single_template::_get_theme_template( $single_template_id, $wordpress_template_path );
  2059. }
  2060. }
  2061. // read the global setting
  2062. $default_template_id = td_util::get_option('td_default_site_post_template');
  2063. // STOP here and load the default template if there's a single template id - The template builder does it's own thing in it's template_include if it's available!
  2064. if ( td_global::is_tdb_template( $default_template_id ) ) {
  2065. // make sure the template exists, maybe it was deleted or something
  2066. if ( td_global::is_tdb_template( $default_template_id, true ) ) {
  2067. // load the default tdb template
  2068. $tdb_template_id = td_global::tdb_get_template_id($default_template_id);
  2069. // run our filter and check it's returned value. If tdb did nothing or it's not installed, we do nothing.
  2070. $td_single_override = apply_filters( 'td_single_override', $tdb_template_id ); // in: template id out: tdb view single template path
  2071. if ( $td_single_override != $tdb_template_id ) {
  2072. return $td_single_override;
  2073. }
  2074. } else {
  2075. // if we have an non-existent cloud template update the default site wide post template
  2076. td_util::update_option('td_default_site_post_template', '' );
  2077. // and load the default theme template
  2078. return $wordpress_template_path;
  2079. }
  2080. } else {
  2081. // this was added for child theme, when default post template is set globally
  2082. // _get_theme_template cannot locate the default post template id (is empty)
  2083. if ( $default_template_id == '' ) {
  2084. $default_template_id = 'single_template';
  2085. }
  2086. // load the default theme template
  2087. return td_api_single_template::_get_theme_template( $default_template_id, $wordpress_template_path );
  2088. }
  2089. }
  2090. return $wordpress_template_path;
  2091. }
  2092. // remove wp versions on demos
  2093. if (TD_DEPLOY_MODE === 'demo') {
  2094. function td_demo_remove_version() {
  2095. return '';
  2096. }
  2097. add_filter('the_generator', 'td_demo_remove_version');
  2098. // do not allow auto updates
  2099. add_filter( 'allow_dev_auto_core_updates', '__return_false' );
  2100. add_filter( 'allow_major_auto_core_updates', '__return_false' );
  2101. add_filter( 'allow_minor_auto_core_updates', '__return_false' );
  2102. }
  2103. // remove the "Mobile Theme - Pagebuilder + latest articles + pagination" template from page templates list if the mobile theme plugin is not active
  2104. add_filter( 'theme_page_templates', function ($page_templates){
  2105. if ( ! class_exists( 'td_mobile_theme', false ) ) {
  2106. unset( $page_templates['mobile/page-pagebuilder-latest.php'] );
  2107. }
  2108. return $page_templates;
  2109. });
  2110. /**
  2111. * this point the default post templates towards the legacy '/comments.php' template
  2112. * we use 9 priority to allow plugins to overwrite this using the default priority
  2113. */
  2114. add_filter( 'comments_template', function (){
  2115. return TDC_PATH_LEGACY . '/comments.php';
  2116. }, 9);
  2117. © 2019 GitHub, Inc.
  2118. Terms
  2119. Privacy
  2120. Security
  2121. Status
  2122. Help
  2123. Contact GitHub
  2124. Pricing
  2125. API
  2126. Training
  2127. Blog
  2128. About
Advertisement
Add Comment
Please, Sign In to add comment