Advertisement
Guest User

Thrive functions

a guest
Oct 19th, 2018
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 52.76 KB | None | 0 0
  1. <?php
  2. add_filter( 'auto_update_theme', '__return_true' );
  3. add_filter( 'previous_comments_link_attributes', 'thrive_get_previous_comments_link_attributes' );
  4. add_filter( 'next_comments_link_attributes', 'thrive_get_next_comments_link_attributes' );
  5. /*
  6. * Set up a global variable in order to know that this is a thrive theme
  7. */
  8. global $is_thrive_theme;
  9. $is_thrive_theme = true;
  10. /*
  11. * Include the init file that handles the main configurations and the backend
  12. * methods
  13. */
  14. include( get_template_directory() . '/inc/configs/init.php' );
  15.  
  16. include( get_template_directory() . "/inc/configs/theme-options.php" );
  17.  
  18. include( get_template_directory() . '/inc/tha-theme-hooks.php' );
  19.  
  20. include( get_template_directory() . '/inc/thrive-image-optimization.php' );
  21.  
  22. include( get_template_directory() . '/inc/templates/custom-menu-walker.php' );
  23.  
  24. include( get_template_directory() . '/inc/helpers/views.php' );
  25.  
  26. include( get_template_directory() . '/inc/dashboard/init.php' );
  27.  
  28. require( get_template_directory() . "/inc/theme-options.php" );
  29.  
  30. /*
  31. * Render the breadcrumbs
  32. */
  33. if ( ! function_exists( 'thrive_breadcrumbs' ) ) :
  34. function thrive_breadcrumbs() {
  35.  
  36. global $post;
  37.  
  38. if ( is_404() ) {
  39. return;
  40. }
  41.  
  42. $arrowImg = "&nbsp;ยป";
  43.  
  44.  
  45. if ( get_option( 'show_on_front' ) == 'page' ) {
  46. $posts_page_id = get_option( 'page_for_posts' );
  47. $posts_page_url = get_page_link( $posts_page_id );
  48. $homepage_id = get_option( 'page_on_front' );
  49. $homepage_url = empty( $homepage_id ) ? get_option( 'home' ) : get_page_link( $homepage_id );
  50. echo "<li typeof='v:Breadcrumb'><a rel='v:url' property='v:title' class='home' href='" . $homepage_url . "'> " . __( "Home", 'thrive' ) . $arrowImg . "</a></li>";
  51. if ( ! is_page() && ! empty( $posts_page_id ) ) {
  52. if ( ! is_home() ) {
  53. echo "<li typeof='v:Breadcrumb'><a rel='v:url' property='v:title' class='home' href='" . $posts_page_url . "'> " . __( "Blog", 'thrive' ) . $arrowImg . "</a></li>";
  54. } else {
  55. echo "<li typeof='v:Breadcrumb'><a class='no-link' rel='v:url' property='v:title' href='" . $posts_page_url . "'>" . __( "Blog", 'thrive' ) . "</a></li>";
  56. }
  57. }
  58. } else {
  59. echo "<li typeof='v:Breadcrumb'><a rel='v:url' property='v:title' class='home' href='" . get_option( 'home' ) . "'> " . __( "Home", 'thrive' ) . $arrowImg . "</a></li>";
  60. }
  61.  
  62.  
  63. if ( is_category() || is_single() ) {
  64. $cats = get_the_category( $post->ID );
  65. @usort( $cats, '_usort_terms_by_ID' );
  66. if ( ! empty( $cats ) ) {
  67. if ( isset( $cats[0] ) ) {
  68. echo "<li typeof='v:Breadcrumb'><a rel='v:url' property='v:title' href='" . get_category_link( $cats[0]->term_id ) . "'>" . $cats[0]->cat_name . "</a></li>";
  69. }
  70. }
  71. if ( is_single() ) {
  72. if ( ! isset( $cats[0] ) ) {
  73. $arrowImg = "";
  74. }
  75. echo "<li typeof='v:Breadcrumb'><a class='no-link' rel='v:url' property='v:title' href='" . get_permalink( $post->id ) . "'>" . $arrowImg . " ";
  76. echo get_the_title();
  77. echo "</a></li>";
  78. }
  79. } elseif ( is_page() ) {
  80. if ( $post->post_parent ) {
  81. $anc = array_reverse( get_post_ancestors( $post->ID ) );
  82. $output = "";
  83. foreach ( $anc as $ancestor ) {
  84. $anc_link = get_page_link( $ancestor );
  85. $output .= "<li typeof='v:Breadcrumb'><a rel='v:url' property='v:title' href='" . $anc_link . "'>" . get_the_title( $ancestor ) . " " . $arrowImg . "</a></li>";
  86. }
  87. echo $output . "<li typeof='v:Breadcrumb'><a class='no-link' rel='v:url' property='v:title' href='" . get_permalink() . "'>";
  88. the_title();
  89. echo "</a></li>";
  90. } else {
  91. echo "<li typeof='v:Breadcrumb'><a class='no-link' rel='v:url' property='v:title' href='" . get_permalink() . "'>";
  92. echo the_title();
  93. echo "</a></li>";
  94. }
  95. } elseif ( is_tag() ) {
  96. echo "<li typeof='v:Breadcrumb'>" . single_tag_title( '', false ) . '</li>';
  97. } elseif ( is_day() ) {
  98. echo "<li typeof='v:Breadcrumb'>" . __( "Archive", 'thrive' ) . ": ";
  99. the_time( 'F jS, Y' );
  100. echo '</li>';
  101. } elseif ( is_month() ) {
  102. echo "<li typeof='v:Breadcrumb'>" . __( "Archive", 'thrive' ) . ": ";
  103. the_time( 'F, Y' );
  104. echo '</li>';
  105. } elseif ( is_year() ) {
  106. echo "<li typeof='v:Breadcrumb'>" . __( "Archive", 'thrive' ) . ": ";
  107. the_time( 'Y' );
  108. echo '</li>';
  109. } elseif ( is_author() ) {
  110. echo "<li typeof='v:Breadcrumb'>" . __( "Author's archive", 'thrive' ) . ": ";
  111. echo '</li>';
  112. } elseif ( isset( $_GET['paged'] ) && ! empty( $_GET['paged'] ) ) {
  113. echo "<li typeof='v:Breadcrumb'>" . __( "Archive", 'thrive' ) . ": ";
  114. echo '</li>';
  115. } elseif ( is_search() ) {
  116. echo "<li typeof='v:Breadcrumb'>" . __( "Search results", 'thrive' ) . ": ";
  117. } elseif ( is_archive() ) {
  118. echo "<li typeof='v:Breadcrumb'>" . __( "Archive", 'thrive' ) . ": ";
  119. echo '</li>';
  120. }
  121.  
  122. return;
  123. }
  124. endif; //thrive_breadcrumbs
  125.  
  126. /*
  127. * Render the pagination links
  128. */
  129.  
  130. function thrive_pagination() {
  131. global $wp_query;
  132.  
  133. $total_pages = $wp_query->max_num_pages;
  134.  
  135. if ( $total_pages > 1 ) {
  136.  
  137. $current_page = max( 1, get_query_var( 'paged' ) );
  138.  
  139. /**
  140. * SUPP-3492 RISE pagination issues on search - Commented out the line
  141. */
  142. echo paginate_links( array(
  143. // 'format' => ( ( get_option( 'permalink_structure' ) && ! $wp_query->is_search ) || ( is_home() && get_option( 'show_on_front' ) !== 'page' && ! get_option( 'page_on_front' ) ) ) ? '?paged=%#%' : '&paged=%#%',
  144. 'current' => $current_page,
  145. 'total' => $total_pages,
  146. ) );
  147. }
  148. }
  149.  
  150. /*
  151. * Check if the curernt post (or page) has a focus area that needs to be rendered
  152. * @return Boolean
  153. */
  154.  
  155. function thrive_check_top_focus_area() {
  156. if ( is_home() || is_404() ) {
  157. return false;
  158. }
  159.  
  160. global $post;
  161. if ( ! $post || ! isset( $post->post_type ) ) {
  162. return false;
  163. }
  164. if ( $post->post_type == TT_APPR_POST_TYPE_LESSON || $post->post_type == TT_APPR_POST_TYPE_PAGE ) {
  165. $post->post_type = "post";
  166. }
  167. if ( $post->post_type == "post" ) {
  168. return _thrive_check_top_focus_area_post( $post );
  169. } else {
  170. return _thrive_check_top_focus_area_page( $post );
  171. }
  172. }
  173.  
  174. function thrive_check_blog_focus_area( $position ) {
  175. if ( ! is_home() ) {
  176. return false;
  177. }
  178. $query = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_location&meta_value=between_posts&order=ASC" );
  179. $focus_areas = $query->get_posts();
  180.  
  181. foreach ( $focus_areas as $temp_focus ) {
  182. $post_custom_atr = get_post_custom( $temp_focus->ID );
  183. if ( isset( $post_custom_atr['_thrive_meta_focus_display_between_posts'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_between_posts'][0] ) && $post_custom_atr['_thrive_meta_focus_display_between_posts'][0] == $position ) {
  184. return true;
  185. }
  186. }
  187.  
  188. return false;
  189. }
  190.  
  191. /*
  192. * Check if the curernt post (or page) has a focus area that needs to be rendered
  193. * @return Boolean
  194. */
  195.  
  196. function thrive_check_bottom_focus_area() {
  197.  
  198. if ( is_home() || is_404() ) {
  199. return false;
  200. }
  201.  
  202. global $post;
  203. if ( ! $post || ! isset( $post->post_type ) ) {
  204. return false;
  205. }
  206. if ( $post->post_type == "post" ) {
  207. return _thrive_check_top_focus_area_post( $post, "bottom" );
  208. } else {
  209. return _thrive_check_top_focus_area_page( $post, "bottom" );
  210. }
  211. }
  212.  
  213. /*
  214. * Helper function used to check if the curernt post has a focus area that needs to be rendered
  215. * @param Post object
  216. * @return Boolean
  217. */
  218.  
  219. function _thrive_check_top_focus_area_post( $post, $position = "top" ) {
  220. $custom_fields = get_post_custom( $post->ID );
  221.  
  222. if ( $position == "top" ) {
  223. if ( isset( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && $post->post_type == "post" ) {
  224. return true;
  225. }
  226.  
  227. if ( isset( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && $custom_fields['_thrive_meta_post_focus_area_top'][0] == "hide" && $post->post_type == "post" ) {
  228. return false;
  229. }
  230. } else {
  231. if ( isset( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && $post->post_type == "post" ) {
  232. return true;
  233. }
  234.  
  235. if ( isset( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && $custom_fields['_thrive_meta_post_focus_area_bottom'][0] == "hide" && $post->post_type == "post" ) {
  236. return false;
  237. }
  238. }
  239.  
  240. $post_categories = wp_get_post_categories( $post->ID );
  241.  
  242. $query1 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_post_type&meta_value=post&order=ASC&posts_per_page=-1" );
  243. foreach ( $query1->get_posts() as $p ) {
  244. //check for the top display option
  245. $post_custom_atr = get_post_custom( $p->ID );
  246. $focus_cats = json_decode( $post_custom_atr['_thrive_meta_focus_display_categories'][0] );
  247. if ( ! is_array( $focus_cats ) ) {
  248. $focus_cats = array();
  249. }
  250.  
  251. if ( isset( $post_custom_atr['_thrive_meta_focus_display_location'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_location'][0] ) && $post_custom_atr['_thrive_meta_focus_display_location'][0] == $position && ( $post_custom_atr['_thrive_meta_focus_display_is_default'][0] == 1 || count( array_intersect( $post_categories, $focus_cats ) ) > 0 ) ) {
  252. return true;
  253. }
  254. }
  255.  
  256. return false;
  257. }
  258.  
  259. /*
  260. * Helper function used to check if the curernt page has a focus area that needs to be rendered
  261. * @param Post object
  262. * @return Boolean
  263. */
  264.  
  265. function _thrive_check_top_focus_area_page( $post, $position = "top" ) {
  266. $custom_fields = get_post_custom( $post->ID );
  267. if ( $position == "top" ) {
  268. if ( isset( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && $post->post_type == "page" ) {
  269. return true;
  270. }
  271.  
  272. if ( isset( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && $custom_fields['_thrive_meta_post_focus_area_top'][0] == "hide" && $post->post_type == "page" ) {
  273. return false;
  274. }
  275. } else {
  276. if ( isset( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && $post->post_type == "page" ) {
  277. return true;
  278. }
  279.  
  280. if ( isset( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && $custom_fields['_thrive_meta_post_focus_area_bottom'][0] == "hide" && $post->post_type == "page" ) {
  281. return false;
  282. }
  283. }
  284. $query2 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_post_type&meta_value=page&order=ASC&posts_per_page=-1" );
  285.  
  286. $post_categories = wp_get_post_categories( $post->ID );
  287.  
  288. foreach ( $query2->get_posts() as $p ) {
  289. $post_custom_atr = get_post_custom( $p->ID );
  290. if ( isset( $post_custom_atr['_thrive_meta_focus_display_categories'] ) && $post_custom_atr['_thrive_meta_focus_display_categories'][0] ) {
  291. $focus_cats = json_decode( $post_custom_atr['_thrive_meta_focus_display_categories'][0] );
  292. } else {
  293. $focus_cats = array();
  294. }
  295. if ( ! is_array( $focus_cats ) ) {
  296. $focus_cats = array();
  297. }
  298.  
  299. if ( isset( $post_custom_atr['_thrive_meta_focus_display_location'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_location'][0] ) && $post_custom_atr['_thrive_meta_focus_display_location'][0] == $position ) {
  300. return true;
  301. }
  302. }
  303.  
  304. return false;
  305. }
  306.  
  307. /**
  308. * Renders the top focus area
  309. */
  310. function thrive_render_top_focus_area( $position = "top", $place = null ) {
  311. global $post;
  312. $current_post = $post;
  313. $page_focus = null;
  314. $post_focus = null;
  315. $current_focus = null;
  316. $current_focus_attrs = null;
  317.  
  318. $custom_fields = get_post_custom( $post->ID );
  319.  
  320. if ( $position == "top" ) {
  321. if ( isset( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && $post->post_type == "post" ) {
  322. $post_focus = get_post( $custom_fields['_thrive_meta_post_focus_area_top'][0] );
  323. }
  324.  
  325. if ( isset( $custom_fields['_thrive_meta_post_focus_area_top'] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_top'][0] ) && $post->post_type == "page" ) {
  326. $page_focus = get_post( $custom_fields['_thrive_meta_post_focus_area_top'][0] );
  327. }
  328. } else {
  329. if ( isset( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && $post->post_type == "post" ) {
  330. $post_focus = get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] );
  331. }
  332.  
  333. if ( isset( $custom_fields['_thrive_meta_post_focus_area_bottom'] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && $post->post_type == "page" ) {
  334. $page_focus = get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] );
  335. }
  336. }
  337.  
  338. if ( ! $post_focus ) {
  339. $post_categories = wp_get_post_categories( $post->ID );
  340. $query1 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_post_type&meta_value=post&order=ASC&posts_per_page=-1" );
  341. foreach ( $query1->get_posts() as $p ) {
  342. $post_custom_atr = get_post_custom( $p->ID );
  343. $focus_cats = json_decode( $post_custom_atr['_thrive_meta_focus_display_categories'][0] );
  344. if ( ! is_array( $focus_cats ) ) {
  345. $focus_cats = array();
  346. }
  347.  
  348. if ( isset( $post_custom_atr['_thrive_meta_focus_display_location'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_location'][0] ) && $post_custom_atr['_thrive_meta_focus_display_location'][0] == $position && ( $post_custom_atr['_thrive_meta_focus_display_is_default'][0] == 1 || count( array_intersect( $post_categories, $focus_cats ) ) > 0 ) ) {
  349. $post_focus = $p;
  350. }
  351. }
  352. }
  353.  
  354. if ( ! $page_focus ) {
  355. $post_categories = wp_get_post_categories( $post->ID );
  356. //get the focus area for the posts and for the pages, if any is set
  357. $query2 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_post_type&meta_value=page&order=ASC&posts_per_page=-1" );
  358. foreach ( $query2->get_posts() as $p ) {
  359. $post_custom_atr = get_post_custom( $p->ID );
  360. if ( isset( $post_custom_atr['_thrive_meta_focus_display_categories'] ) && $post_custom_atr['_thrive_meta_focus_display_categories'][0] ) {
  361. $focus_cats = json_decode( $post_custom_atr['_thrive_meta_focus_display_categories'][0] );
  362. } else {
  363. $focus_cats = array();
  364. }
  365. if ( ! is_array( $focus_cats ) ) {
  366. $focus_cats = array();
  367. }
  368. if ( isset( $post_custom_atr['_thrive_meta_focus_display_location'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_location'][0] ) && $post_custom_atr['_thrive_meta_focus_display_location'][0] == $position ) {
  369. $page_focus = $p;
  370. }
  371. }
  372. }
  373.  
  374. if ( $current_post->post_type == "post" ) {
  375. if ( $post_focus ) {
  376. $current_focus = $post_focus;
  377. }
  378. }
  379.  
  380. if ( $post->post_type == "page" ) {
  381. if ( $page_focus ) {
  382. $current_focus = $page_focus;
  383. }
  384. }
  385.  
  386. if ( $position == "between_posts" ) {
  387. $query3 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_location&meta_value=between_posts&order=ASC&posts_per_page=-1" );
  388. $focus_areas = $query3->get_posts();
  389.  
  390. foreach ( $focus_areas as $temp_focus ) {
  391. $post_custom_atr = get_post_custom( $temp_focus->ID );
  392. if ( isset( $post_custom_atr['_thrive_meta_focus_display_between_posts'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_between_posts'][0] ) && $post_custom_atr['_thrive_meta_focus_display_between_posts'][0] == $place ) {
  393. $current_focus = $temp_focus;
  394. }
  395. }
  396. }
  397.  
  398. if ( is_search() && ! $current_focus && $page_focus ) {
  399. $current_focus = $page_focus;
  400. }
  401.  
  402. if ( $place == "blog" || $place == "archive" ) {
  403.  
  404. if ( $place == "blog" ) {
  405. $query4 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_page_blog&meta_value=blog&order=ASC&posts_per_page=-1" );
  406. } elseif ( $place == "archive" ) {
  407. $query4 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_page_archive&meta_value=archive&order=ASC&posts_per_page=-1" );
  408. }
  409.  
  410. $focus_areas = $query4->get_posts();
  411.  
  412. foreach ( $focus_areas as $focus_area ) {
  413. $post_custom_atr = get_post_custom( $focus_area->ID );
  414.  
  415. if ( isset( $post_custom_atr['_thrive_meta_focus_display_location'] )
  416. && isset( $post_custom_atr['_thrive_meta_focus_display_location'][0] )
  417. && $post_custom_atr['_thrive_meta_focus_display_location'][0] == $position
  418. ) {
  419. $current_focus = $focus_area;
  420. }
  421. }
  422. }
  423.  
  424. /**
  425. * Danutz: logic for custom Zack focus area
  426. *
  427. * @see Everywhere on top option for location of focus area
  428. * @see child theme made for Zack
  429. */
  430. if ( ! $current_focus && $position === 'top_posts' ) {
  431. $query5 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_location&meta_value=top_posts&order=DESC&posts_per_page=1" );
  432. $focus_areas = $query5->get_posts();
  433. if ( ! empty( $focus_areas ) ) {
  434. $current_focus = current( $focus_areas );
  435. }
  436. }
  437.  
  438. if ( ! $current_focus ) {
  439. return;
  440. }
  441. $current_attrs = get_post_custom( $current_focus->ID );
  442.  
  443. if ( ! $current_attrs || ! isset( $current_attrs['_thrive_meta_focus_template'] ) || ! isset( $current_attrs['_thrive_meta_focus_template'][0] ) ) {
  444. return;
  445. }
  446.  
  447. if ( isset( $current_attrs['_thrive_meta_focus_optin'] ) && isset( $current_attrs['_thrive_meta_focus_optin'][0] ) ) {
  448. $optin_id = (int) $current_attrs['_thrive_meta_focus_optin'][0];
  449.  
  450. //form action
  451. $optinFormAction = get_post_meta( $optin_id, '_thrive_meta_optin_form_action', true );
  452.  
  453. //form method
  454. $optinFormMethod = get_post_meta( $optin_id, '_thrive_meta_optin_form_method', true );
  455. $optinFormMethod = strtolower( $optinFormMethod );
  456. $optinFormMethod = $optinFormMethod === 'post' || $optinFormMethod === 'get' ? $optinFormMethod : 'post';
  457.  
  458. //form hidden inputs
  459. $optinHiddenInputs = get_post_meta( $optin_id, '_thrive_meta_optin_hidden_inputs', true );
  460.  
  461. //form fields
  462. $optinFieldsJson = get_post_meta( $optin_id, '_thrive_meta_optin_fields_array', true );
  463. $optinFieldsArray = json_decode( $optinFieldsJson, true );
  464.  
  465. //form not visible inputs
  466. $optinNotVisibleInputs = get_post_meta( $optin_id, '_thrive_meta_optin_not_visible_inputs', true );
  467. } else {
  468. $optinFieldsArray = array();
  469. $optinFormAction = "";
  470. $optinHiddenInputs = "";
  471. }
  472. $value_focus_template = strtolower( $current_attrs['_thrive_meta_focus_template'][0] );
  473.  
  474. $base_path = get_template_directory();
  475. $base_path = apply_filters( 'thrive_focus_preview_template_base_path', $base_path, $current_attrs['_thrive_meta_focus_template'][0] );
  476.  
  477. $template_path = $base_path . "/focusareas/" . $value_focus_template . ".php";
  478. if ( $position != "top" ) {
  479. //echo $template_path; die;
  480. }
  481.  
  482. if ( ! empty( $_GET['tve'] ) ) {
  483. return;
  484. }
  485.  
  486. require $template_path;
  487. }
  488.  
  489. /*
  490. * Renders the bottom focus area
  491. */
  492.  
  493. function thrive_render_bottom_focus_area() {
  494. global $post;
  495. $current_post = $post;
  496. $page_focus = null;
  497. $post_focus = null;
  498. $current_focus = null;
  499.  
  500. $custom_fields = get_post_custom( $post->ID );
  501.  
  502. if ( isset( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && $post->post_type == "post" ) {
  503. $post_focus = get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] );
  504. }
  505.  
  506. if ( isset( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && is_numeric( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] ) && $post->post_type == "page" ) {
  507. $page_focus = get_post( $custom_fields['_thrive_meta_post_focus_area_bottom'][0] );
  508. }
  509.  
  510.  
  511. //get the focus area for the posts and for the pages, if any is set
  512. $query1 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_post_type&meta_value=post&order=ASC&posts_per_page=-1" );
  513. foreach ( $query1->get_posts() as $p ) {
  514. $post_custom_atr = get_post_custom( $p->ID );
  515. if ( isset( $post_custom_atr['_thrive_meta_focus_display_location'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_location'][0] ) && $post_custom_atr['_thrive_meta_focus_display_location'][0] == "bottom" ) {
  516. $post_focus = $p;
  517. }
  518. }
  519.  
  520. //get the focus area for the posts and for the pages, if any is set
  521. $query2 = new WP_Query( "post_type=focus_area&meta_key=_thrive_meta_focus_display_post_type&meta_value=page&order=ASC&posts_per_page=-1" );
  522. foreach ( $query2->get_posts() as $p ) {
  523. $post_custom_atr = get_post_custom( $p->ID );
  524. if ( isset( $post_custom_atr['_thrive_meta_focus_display_location'] ) && isset( $post_custom_atr['_thrive_meta_focus_display_location'][0] ) && $post_custom_atr['_thrive_meta_focus_display_location'][0] == "bottom" ) {
  525. $page_focus = $p;
  526. }
  527. }
  528.  
  529. if ( $current_post->post_type == "post" ) {
  530. if ( $post_focus ) {
  531. $current_focus = $post_focus;
  532. }
  533. }
  534.  
  535. if ( $post->post_type == "page" ) {
  536. if ( $page_focus ) {
  537. $current_focus = $page_focus;
  538. }
  539. }
  540.  
  541. if ( ! $current_focus ) {
  542. return;
  543. }
  544. $current_attrs = get_post_custom( $current_focus->ID );
  545.  
  546. if ( ! $current_attrs || ! isset( $current_attrs['_thrive_meta_focus_template'] ) || ! isset( $current_attrs['_thrive_meta_focus_template'][0] ) ) {
  547. return;
  548. }
  549.  
  550. $template_path = get_template_directory() . "/focusareas/" . strtolower( $current_attrs['_thrive_meta_focus_template'][0] ) . "_bottom.php";
  551.  
  552. require_once $template_path;
  553. }
  554.  
  555. /*
  556. * Changes the page menu markup in order to render it accordingly to the theme's markup
  557. * @param string $page_markup The menu markup
  558. * @return string The new markup
  559. */
  560.  
  561. function thrive_custom_page_menu( $page_markup ) {
  562. preg_match( '/^<div class=\"([a-z0-9-_]+)\">/i', $page_markup, $matches );
  563. $divclass = $matches[1];
  564. $toreplace = array( '<div class="' . $divclass . '">', '</div>' );
  565. $new_markup = str_replace( $toreplace, '', $page_markup );
  566. $new_markup = preg_replace( '/^<ul>/i', '<ul id="' . $divclass . '">', $new_markup );
  567. $new_markup = '<nav class="right">' . $new_markup . '</nav>';
  568.  
  569. return $new_markup;
  570. }
  571.  
  572. add_filter( 'wp_page_menu', 'thrive_custom_page_menu' );
  573.  
  574. // read more link
  575. add_filter( 'the_content_more_link', 'thrive_more_link', 10, 2 );
  576. function thrive_more_link( $more_link, $more_link_text ) {
  577. $options = thrive_get_theme_options();
  578. $read_more_class = ( $options['other_read_more_type'] == "button" ) ? "btn dark medium" : "readmore_link";
  579. $read_more_text = ( $options['other_read_more_text'] != "" ) ? $options['other_read_more_text'] : "Read more";
  580. $read_more_text = ( $options['other_read_more_type'] == "button" ) ? "<span>" . $options['other_read_more_text'] . "</span>" : $options['other_read_more_text'];
  581. $thrive_more_link = '<a class="' . $read_more_class . '" href="' . get_permalink() . '">' . $read_more_text . '</a>';
  582.  
  583. return $thrive_more_link;
  584. }
  585.  
  586. /**
  587. * Because TCB does apply filters on "the_content_more_link"
  588. * and because of the filter "the_content_more_link" added in this theme
  589. * This function removes the more_text appended to the excerpt
  590. *
  591. * @see thrive_more_link()
  592. */
  593. add_filter( "the_excerpt", "thrive_the_excerpt" );
  594. function thrive_the_excerpt( $excerpt ) {
  595. $thrive_read_more_text = trim( thrive_get_theme_options( 'other_read_more_text' ) );
  596. $last_occurrence = strrpos( $excerpt, $thrive_read_more_text );
  597. if ( $last_occurrence !== false ) {
  598. $excerpt = substr_replace( $excerpt, "", $last_occurrence, strlen( $thrive_read_more_text ) );
  599. }
  600.  
  601. return $excerpt;
  602. }
  603.  
  604. // Adding actions to show and edit the field
  605. add_action( 'show_user_profile', 'thrive_social_fields_display', 10 );
  606. add_action( 'edit_user_profile', 'thrive_social_fields_display', 10 );
  607.  
  608. function thrive_social_fields_display( $user ) {
  609. $tt_authorbox_image = esc_attr( get_the_author_meta( 'tt_authorbox_image', $user->ID ) );
  610. if ( empty( $tt_authorbox_image ) ) {
  611. $tt_authorbox_image = get_template_directory_uri() . "/images/" . TT_DEFAULT_AUTHORBOX_IMAGE;
  612. }
  613. require "inc/templates/user-thrive-authorbox-settings.php";
  614. }
  615.  
  616. add_action( 'personal_options_update', 'thrive_save_user_fields' );
  617. add_action( 'edit_user_profile_update', 'thrive_save_user_fields' );
  618.  
  619. function thrive_save_user_fields( $user_id ) {
  620.  
  621. if ( ! current_user_can( 'edit_user', $user_id ) ) {
  622. return false;
  623. }
  624.  
  625. $show_social_profiles = implode( ',', $_POST["show_social_profiles"] );
  626.  
  627. $_POST['gauthor'] = ( isset( $_POST['gauthor'] ) ) ? $_POST['gauthor'] : "";
  628. $_POST['gplus'] = ( isset( $_POST['gplus'] ) ) ? $_POST['gplus'] : "";
  629. $_POST['twitter'] = ( isset( $_POST['twitter'] ) ) ? $_POST['twitter'] : "";
  630. $_POST['facebook'] = ( isset( $_POST['facebook'] ) ) ? $_POST['facebook'] : "";
  631. $_POST['linkedin'] = ( isset( $_POST['linkedin'] ) ) ? $_POST['linkedin'] : "";
  632. $_POST['xing'] = ( isset( $_POST['xing'] ) ) ? $_POST['xing'] : "";
  633. $_POST['tt_authorbox_image'] = ( isset( $_POST['tt_authorbox_image'] ) ) ? $_POST['tt_authorbox_image'] : "";
  634. $_POST['thrive_author_website'] = ( isset( $_POST['thrive_author_website'] ) ) ? $_POST['thrive_author_website'] : "";
  635.  
  636. update_user_meta( $user_id, 'gauthor', $_POST['gauthor'] );
  637. update_user_meta( $user_id, 'gplus', $_POST['gplus'] );
  638. update_user_meta( $user_id, 'twitter', $_POST['twitter'] );
  639. update_user_meta( $user_id, 'facebook', $_POST['facebook'] );
  640. update_user_meta( $user_id, 'linkedin', $_POST['linkedin'] );
  641. update_user_meta( $user_id, 'xing', $_POST['xing'] );
  642. update_user_meta( $user_id, 'show_social_profiles', $show_social_profiles );
  643. update_user_meta( $user_id, 'thrive_author_website', $_POST['thrive_author_website'] );
  644. update_user_meta( $user_id, 'tt_authorbox_image', $_POST['tt_authorbox_image'] );
  645. if ( filter_var( $_POST['tt_authorbox_image'], FILTER_VALIDATE_URL ) ) {
  646. update_user_meta( $user_id, 'tt_authorbox_image', $_POST['tt_authorbox_image'] );
  647. } else {
  648. delete_user_meta( $user_id, 'tt_authorbox_image' );
  649. }
  650. }
  651.  
  652. // google authorship link
  653. add_action( 'wp_head', 'thrive_gauthorship' );
  654.  
  655. function thrive_gauthorship() {
  656. if ( is_single() || is_page() ) {
  657. global $post;
  658. $user_id = $post->post_author;
  659. $g_page = get_the_author_meta( 'gplus', $user_id );
  660. $g_activated = get_the_author_meta( 'gauthor', $user_id );
  661. if ( $g_page && $g_activated ):
  662. echo '<link rel="author" href="' . $g_page . '"/>';
  663. endif;
  664. }
  665. }
  666.  
  667. function thrive_exclude_category( $query ) {
  668. $hide_cat_option = thrive_get_theme_options( 'hide_cats_from_blog' );
  669.  
  670. if ( ! is_string( $hide_cat_option ) ) {
  671. $hide_cat_option = "";
  672. }
  673.  
  674. $hide_categories = is_array( json_decode( $hide_cat_option ) ) ? json_decode( $hide_cat_option ) : array();
  675. $temp_query_string_part = "";
  676. foreach ( $hide_categories as $temp_cat_id ) {
  677. $temp_query_string_part .= "-" . $temp_cat_id . " ";
  678. }
  679.  
  680. if ( $query->is_home() ) {
  681. $query->set( 'cat', $temp_query_string_part );
  682. }
  683.  
  684. return $query;
  685. }
  686.  
  687. add_filter( 'pre_get_posts', 'thrive_exclude_category' );
  688.  
  689. // prevent wrapping of paragraph tags around shortcodes
  690. add_filter( 'the_content', 'thrive_remove_autop_shortcodes' );
  691.  
  692. function thrive_remove_autop_shortcodes( $content ) {
  693. $array = array(
  694. '<p>[' => '[',
  695. ']</p>' => ']',
  696. ']<br />' => ']'
  697. );
  698.  
  699. $content = strtr( $content, $array );
  700.  
  701. return $content;
  702. }
  703.  
  704. // attach classes that are helpful for CSS to primary menu and remove all pages apart from top level pages from the footer menu
  705. function thrive_menu_set_dropdown( $sorted_menu_items, $args ) {
  706. if ( isset( $args->theme_location ) && $args->theme_location == "primary" ) {
  707. $last_top = 0;
  708. $post_id_key = array();
  709.  
  710. foreach ( $sorted_menu_items as $key => $obj ) {
  711. // if not parent element (class not to be applied to parent element
  712. if ( 0 != $obj->menu_item_parent ) {
  713. $sorted_menu_items[ $last_top ]->classes['dropdown'] = 'toplvl dropdown';
  714. // need to map key to post id
  715. $post_id_key[ $obj->db_id ] = $key;
  716.  
  717. // if menu item has parent
  718. if ( $obj->menu_item_parent ) {
  719. if ( isset( $post_id_key[ $obj->menu_item_parent ] ) ) {
  720. // give parent class identifier
  721. $sub_menu_parent_key = $post_id_key[ $obj->menu_item_parent ];
  722. $sorted_menu_items[ $sub_menu_parent_key ]->classes['dropdown'] = 'arl';
  723. }
  724. }
  725. } else {
  726. // top level menu item
  727. $sorted_menu_items[ $key ]->classes['dropdown'] = 'toplvl';
  728. $last_top = $key;
  729. }
  730. }
  731.  
  732. return $sorted_menu_items;
  733. }
  734.  
  735. return $sorted_menu_items;
  736. }
  737.  
  738. add_filter( 'wp_nav_menu_objects', 'thrive_menu_set_dropdown', 10, 2 );
  739.  
  740. require( get_template_directory() . "/inc/clone-post.php" );
  741. require( get_template_directory() . "/inc/theme-update.php" );
  742.  
  743. /*
  744. * Add a new default avatar image
  745. */
  746. add_filter( 'avatar_defaults', 'thrive_default_avatar_image' );
  747.  
  748. function thrive_default_avatar_image( $avatar_defaults ) {
  749. $myavatar = get_template_directory_uri() . '/images/default_avatar.png';
  750. $avatar_defaults[ $myavatar ] = "ThriveDefaultAvatar";
  751.  
  752. return $avatar_defaults;
  753. }
  754.  
  755. /*
  756. * Remove the query string for the static scripts and stylesheets used
  757. * by this theme
  758. */
  759.  
  760. function thrive_remove_script_version( $src ) {
  761. $thrive_files = array(
  762. "script.js",
  763. "jquery",
  764. "reset.css",
  765. "main_blue.css",
  766. "main_green.css",
  767. "main_orange.css",
  768. "main_purple.css",
  769. "main_red.css"
  770. );
  771.  
  772. if ( thrive_strposa( $src, $thrive_files ) ) {
  773. $my_theme = wp_get_theme();
  774. $parts = explode( '?', $src );
  775.  
  776. return $parts[0] . "?v=" . $my_theme->get( 'Version' );
  777. }
  778.  
  779. return $src;
  780. }
  781.  
  782. add_filter( 'script_loader_src', 'thrive_remove_script_version', 15, 1 );
  783. add_filter( 'style_loader_src', 'thrive_remove_script_version', 15, 1 );
  784.  
  785. add_action( 'wp_ajax_thrive_lazy_load_comments', 'thrive_lazy_load_comments' );
  786. add_action( 'wp_ajax_nopriv_thrive_lazy_load_comments', 'thrive_lazy_load_comments' );
  787. add_action( 'tve_dash_main_ajax_theme_comments', 'thrive_lazy_load_comments', 10, 2 );
  788.  
  789. function thrive_lazy_load_comments( $current = '', $post_data = null ) {
  790. $data = is_null( $post_data ) ? $_POST : $post_data;
  791. $post_id = isset( $data['post_id'] ) ? (int) $data['post_id'] : 0;
  792. $comment_page = isset( $data['comment_page'] ) ? (int) $data['comment_page'] : 1;
  793. $comments_per_page = 10;
  794.  
  795. $args = array(
  796. 'post_id' => $post_id,
  797. 'order' => strtoupper( get_option( 'comment_order', 'asc' ) ),
  798. 'number' => $comments_per_page,
  799. 'offset' => ( $comment_page - 1 ) * $comments_per_page,
  800. 'hierarchical' => true,
  801. );
  802. $comments = get_comments( $args );
  803. if ( ! is_null( $post_data ) ) {
  804. ob_start();
  805. }
  806. wp_list_comments(
  807. array(
  808. 'callback' => 'thrive_comments',
  809. 'reverse_top_level' => false
  810. ),
  811. $comments );
  812. if ( ! is_null( $post_data ) ) {
  813. $content = ob_get_contents();
  814. ob_end_clean();
  815.  
  816. return $content;
  817. }
  818. wp_die();
  819. }
  820.  
  821. /*
  822. * Render the comments template and the comments form
  823. * Used as a callback by wp_list_comments() for displaying the comments.
  824. */
  825. if ( ! function_exists( 'thrive_comments' ) ) :
  826. function thrive_comments( $comment, $args, $depth ) {
  827. $GLOBALS['comment'] = $comment;
  828. switch ( $comment->comment_type ) :
  829. case 'trackback' :
  830. break;
  831. case 'pingback' :
  832. default :
  833. // Proceed with normal comments.
  834. global $post;
  835. if ( ! $post ) {
  836. $post = get_post( $comment->comment_post_ID );
  837. }
  838. $show_comment_date = thrive_get_theme_options( 'other_show_comment_date' );
  839. $relative_time = thrive_get_theme_options( 'relative_time' );
  840. $highlight_author_comments = thrive_get_theme_options( 'highlight_author_comments' );
  841. $comment_author = get_user_by( 'email', get_comment_author_email() );
  842. $comment_author_url = get_comment_author_url();
  843. $display_name = null;
  844. $comment_container_class = "cmc";
  845. $comment_author_id = 0;
  846. $color_theme = thrive_get_theme_options( 'color_scheme' );
  847. if ( $comment_author ) {
  848. $fname = get_the_author_meta( 'first_name', $comment_author->ID );
  849. $lname = get_the_author_meta( 'last_name', $comment_author->ID );
  850. $author_name = get_the_author_meta( 'display_name', $comment_author->ID );
  851. $display_name = empty( $author_name ) ? $fname . " " . $lname : $author_name;
  852. if ( $post->post_author == $comment_author->ID && $highlight_author_comments == 1 ) {
  853. $comment_container_class .= " byAut";
  854. }
  855. $comment_author_id = $comment_author->ID;
  856. }
  857. if ( ! $display_name || $display_name == "" ) {
  858. $display_name = get_comment_author();
  859. }
  860. $client_ip = _thrive_get_client_ip();
  861. $comment_author_ip = get_comment_author_IP();
  862. $user_ID = get_current_user_id();
  863. $commenter = wp_get_current_commenter();
  864. $consent = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';
  865. ?>
  866. <?php if ( _thrive_check_comment_approved( $comment->comment_approved, $client_ip, $comment_author_ip, $user_ID, $comment_author_id ) ): ?>
  867. <div class="cmb" id="comment-<?php echo get_comment_ID(); ?>">
  868. <div class="<?php echo $comment_container_class; ?>">
  869. <div class="left">
  870. <?php echo get_avatar( get_comment_author_email(), 50 ); ?>
  871. </div>
  872.  
  873. <div class="ccr right">
  874. <span class="nam">
  875. <?php if ( $comment_author_url && $comment_author_url != "" ): ?>
  876. <a href="<?php echo $comment_author_url; ?>" target="_blank" rel="nofollow">
  877. <?php echo $display_name; ?>
  878. </a>
  879. <?php _e( 'says', 'thrive' ); ?>
  880. <?php else: ?>
  881. <span class="uNM"><?php echo $display_name; ?></span> <?php _e( 'says', 'thrive' ); ?>
  882. <?php endif; ?>
  883. </span>
  884. <span class="uDt">
  885. <?php if ( $show_comment_date == 1 ): ?>
  886. <?php if ( $relative_time == 1 ): ?>
  887. <?php echo thrive_human_time( get_comment_date( 'U' ) ); ?>
  888. <?php else: ?>
  889. <?php echo get_comment_date(); ?>
  890. <?php endif; ?>
  891. <?php endif; ?>
  892. </span>
  893.  
  894. <?php if ( '0' == $comment->comment_approved ): ?>
  895. <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'thrive' ); ?></p>
  896. <?php else: ?>
  897. <p><?php comment_text(); ?></p>
  898. <?php endif; ?>
  899.  
  900. <?php if ( comments_open() && ! post_password_required() && '0' != $comment->comment_approved ) : ?>
  901. <a class="rpl reply left" href="#"
  902. id="link-reply-<?php echo get_comment_ID(); ?>"
  903. cid="<?php echo get_comment_ID(); ?>">
  904. <?php _e( "Reply", 'thrive' ); ?>
  905. </a>
  906. <?php endif; ?>
  907. <div class="clear"></div>
  908.  
  909. </div>
  910. <div class="clear"></div>
  911. </div>
  912. <div class="lrp" id="respond-container-<?php echo get_comment_ID(); ?>" style="display: none;">
  913. <div class="clear"></div>
  914. <form action="<?php echo site_url( '/wp-comments-post.php' ) ?>" method="post">
  915. <?php if ( ! is_user_logged_in() ): ?>
  916. <div class="llw">
  917. <label for="author"><?php _e( "Name", 'thrive' ); ?><?php if ( get_option( "require_name_email" ) == 1 ) { ?>*<?php } ?></label>
  918. <input type="text" id="author" placeholder="" name="author"/>
  919. </div>
  920. <div class="llw">
  921. <label for="email"><?php _e( "Email", 'thrive' ); ?><?php if ( get_option( "require_name_email" ) == 1 ) { ?>*<?php } ?></label>
  922. <input type="text" id="email" placeholder="" name="email"/>
  923. </div>
  924. <label for="website"><?php _e( "Website", 'thrive' ); ?></label>
  925. <input type="text" id="website" placeholder="" name="website"/>
  926.  
  927. <p class="comment-form-cookies-consent">
  928. <input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes" <?php echo $consent; ?>/>
  929. <label for="wp-comment-cookies-consent">
  930. <?php echo __( 'Save my name, email, and website in this browser for the next time I comment.', 'thrive' ); ?>
  931. </label>
  932. </p>
  933. <?php endif; ?>
  934. <label for="comment"><?php _e( 'Comment', 'thrive' ); ?></label>
  935. <textarea id="comment" name="comment" class="textarea"></textarea>
  936.  
  937. <?php echo apply_filters( 'comment_form_submit_field', '' ); ?>
  938.  
  939. <div class="btn <?php echo $color_theme; ?> small">
  940. <input type="submit" value="<?php _e( "Post Comment", 'thrive' ); ?>">
  941. </div>
  942.  
  943. <input id="comment_post_ID" type="hidden" value="<?php echo get_the_ID(); ?>" name="comment_post_ID">
  944. <input id="comment_parent" type="hidden" value="<?php echo get_comment_ID(); ?>" name="comment_parent">
  945. </form>
  946. <a href="#" class="rpl right cancel_reply" cid="<?php echo get_comment_ID(); ?>">
  947. <?php _e( "Cancel", 'thrive' ); ?>
  948. </a>
  949.  
  950. <div class="clear"></div>
  951. </div>
  952. </div>
  953. <div class="clear"></div>
  954. <div class="lrp" style="display: none;" id="respond-container-<?php echo get_comment_ID(); ?>">
  955. </div>
  956. <?php endif; ?>
  957. <?php
  958. break;
  959. endswitch;
  960. }
  961. endif; //thrive_comments
  962.  
  963. /*
  964. * Add custom items to the menu from the admin part.
  965. */
  966. add_filter( 'wp_setup_nav_menu_item', 'thrive_custom_admin_nav_item' );
  967.  
  968. function thrive_custom_admin_nav_item( $menu_item ) {
  969. $menu_item->extended_activate = get_post_meta( $menu_item->ID, '_menu_item_extended_activate', true );
  970. $menu_item->highlight_menu = get_post_meta( $menu_item->ID, '_menu_item_highlight_menu_item', true );
  971. $menu_item->extended_columns = get_post_meta( $menu_item->ID, '_menu_item_extended_columns', true );
  972. $menu_item->extended_heading = get_post_meta( $menu_item->ID, '_menu_item_extended_heading', true );
  973. $menu_item->extended_disable_link = get_post_meta( $menu_item->ID, '_menu_item_extended_disable_link', true );
  974. $menu_item->extended_text_chk = get_post_meta( $menu_item->ID, '_menu_item_extended_text_chk', true );
  975. $menu_item->extended_free_text = get_post_meta( $menu_item->ID, '_menu_item_extended_free_text', true );
  976.  
  977. return $menu_item;
  978. }
  979.  
  980. add_action( 'wp_update_nav_menu_item', 'thrive_custom_admin_nav_update', 10, 3 );
  981.  
  982. function thrive_custom_admin_nav_update( $menu_id, $menu_item_db_id, $args ) {
  983. if ( isset( $_REQUEST['menu-item-extended-activate'][ $menu_item_db_id ] ) && is_array( $_REQUEST['menu-item-extended-activate'] ) ) {
  984. $custom_value = $_REQUEST['menu-item-extended-activate'][ $menu_item_db_id ];
  985. update_post_meta( $menu_item_db_id, '_menu_item_extended_activate', $custom_value );
  986. } else {
  987. update_post_meta( $menu_item_db_id, '_menu_item_extended_activate', 'off' );
  988. }
  989.  
  990. if ( isset( $_REQUEST['menu-item-highlight-menu-item'][ $menu_item_db_id ] ) && is_array( $_REQUEST['menu-item-highlight-menu-item'] ) ) {
  991. $custom_value = $_REQUEST['menu-item-highlight-menu-item'][ $menu_item_db_id ];
  992. update_post_meta( $menu_item_db_id, '_menu_item_highlight_menu_item', $custom_value );
  993. } else {
  994. update_post_meta( $menu_item_db_id, '_menu_item_highlight_menu_item', 'off' );
  995. }
  996.  
  997. if ( isset( $_REQUEST['menu-item-extended-columns'][ $menu_item_db_id ] ) && is_array( $_REQUEST['menu-item-extended-columns'] ) ) {
  998. $custom_value = $_REQUEST['menu-item-extended-columns'][ $menu_item_db_id ];
  999. update_post_meta( $menu_item_db_id, '_menu_item_extended_columns', $custom_value );
  1000. }
  1001.  
  1002. if ( isset( $_REQUEST['menu-item-extended-heading'][ $menu_item_db_id ] ) && is_array( $_REQUEST['menu-item-extended-heading'] ) ) {
  1003. $custom_value = $_REQUEST['menu-item-extended-heading'][ $menu_item_db_id ];
  1004. update_post_meta( $menu_item_db_id, '_menu_item_extended_heading', $custom_value );
  1005. } else {
  1006. if ( get_post_meta( $menu_item_db_id, '_menu_item_extended_heading', true ) == '' ) {
  1007. update_post_meta( $menu_item_db_id, '_menu_item_extended_heading', 'on' );
  1008. } else {
  1009. update_post_meta( $menu_item_db_id, '_menu_item_extended_heading', 'off' );
  1010. }
  1011. }
  1012.  
  1013. if ( isset( $_REQUEST['menu-item-extended-disable-link'][ $menu_item_db_id ] ) && is_array( $_REQUEST['menu-item-extended-disable-link'] ) ) {
  1014. $custom_value = $_REQUEST['menu-item-extended-disable-link'][ $menu_item_db_id ];
  1015. update_post_meta( $menu_item_db_id, '_menu_item_extended_disable_link', $custom_value );
  1016. } else {
  1017. update_post_meta( $menu_item_db_id, '_menu_item_extended_disable_link', 'off' );
  1018. }
  1019.  
  1020. if ( isset( $_REQUEST['menu-item-extended-text-chk'][ $menu_item_db_id ] ) && is_array( $_REQUEST['menu-item-extended-text-chk'] ) ) {
  1021. $custom_value = $_REQUEST['menu-item-extended-text-chk'][ $menu_item_db_id ];
  1022. update_post_meta( $menu_item_db_id, '_menu_item_extended_text_chk', $custom_value );
  1023. } else {
  1024. update_post_meta( $menu_item_db_id, '_menu_item_extended_text_chk', 'off' );
  1025. }
  1026.  
  1027. if ( isset( $_REQUEST['menu-item-extended-free-text'][ $menu_item_db_id ] ) && is_array( $_REQUEST['menu-item-extended-free-text'] ) ) {
  1028. $custom_value = $_REQUEST['menu-item-extended-free-text'][ $menu_item_db_id ];
  1029. update_post_meta( $menu_item_db_id, '_menu_item_extended_free_text', $custom_value );
  1030. }
  1031. }
  1032.  
  1033. add_filter( 'wp_edit_nav_menu_walker', 'thrive_function_admin_custom_menu_walker', 10, 2 );
  1034.  
  1035.  
  1036. function custom_nav_edit_walker( $walker, $menu_id ) {
  1037. return 'Walker_Nav_Menu_Edit_Custom';
  1038. }
  1039.  
  1040. /*
  1041. * add custom font css
  1042. */
  1043. add_action( "tha_head_top", "thrive_load_font_css" );
  1044.  
  1045. function thrive_load_font_css( $font ) {
  1046.  
  1047. $fonts = (array) json_decode( get_option( 'thrive_font_manager_options' ) );
  1048. if ( ! $fonts || ! is_array( $fonts ) ) {
  1049. return;
  1050. }
  1051. echo '<style type="text/css">';
  1052.  
  1053. foreach ( $fonts as $font ) {
  1054. echo ' .' . $font->font_class . '{';
  1055. echo "font-family: " . thrive_prepare_font_family( $font->font_name ) . ";";
  1056. echo 'font-size:' . $font->font_size . ';';
  1057. echo 'line-height:' . $font->font_height . ';';
  1058. echo 'color:' . $font->font_color . ';';
  1059. echo '} ';
  1060. echo $font->custom_css;
  1061. }
  1062.  
  1063. echo '</style>';
  1064. }
  1065.  
  1066. /**
  1067. * Prepare font family name to be added to css rule
  1068. *
  1069. * @param $font_family
  1070. *
  1071. * @return string
  1072. */
  1073. function thrive_prepare_font_family( $font_family ) {
  1074. $chunks = explode( ",", $font_family );
  1075. $length = count( $chunks );
  1076. $font = "";
  1077. foreach ( $chunks as $key => $value ) {
  1078. $font .= "'" . trim( $value ) . "'";
  1079. $font .= ( $key + 1 ) < $length ? ", " : "";
  1080. }
  1081.  
  1082. return $font;
  1083. }
  1084.  
  1085. function thrive_save_post_font( $post_id ) {
  1086.  
  1087. $post_content = get_post_field( 'post_content', $post_id );
  1088. preg_match_all( "/thrive_custom_font id='\d+'/", $post_content, $font_ids );
  1089.  
  1090. $post_fonts = array();
  1091. foreach ( $font_ids[0] as $font_id ) {
  1092. $parts = explode( "'", $font_id );
  1093. $id = $parts[1];
  1094. $font = thrive_get_font_options( $id );
  1095. if ( tve_dash_font_manager_is_safe_font( $font->font_name ) ) {
  1096. continue;
  1097. }
  1098. if ( Tve_Dash_Font_Import_Manager::isImportedFont( $font->font_name ) ) {
  1099. $post_fonts[] = Tve_Dash_Font_Import_Manager::getCssFile();
  1100. continue;
  1101. }
  1102. $post_fonts[] = "//fonts.googleapis.com/css?family=" . str_replace( " ", "+", $font->font_name ) . ( $font->font_style != 0 ? ":" . $font->font_style : "" ) . ( $font->font_bold != 0 ? "," . $font->font_bold : "" ) . ( $font->font_italic != 0 ? $font->font_italic : "" ) . ( $font->font_character_set != 0 ? "&subset=" . $font->font_character_set : "" );
  1103. }
  1104. $post_fonts = array_unique( $post_fonts );
  1105. update_post_meta( $post_id, 'thrive_post_fonts', sanitize_text_field( json_encode( $post_fonts ) ) );
  1106. }
  1107.  
  1108. add_action( 'save_post', 'thrive_save_post_font' );
  1109.  
  1110. function thrive_enqueue_head_fonts() {
  1111.  
  1112. if ( is_singular() ) {
  1113. $post_id = get_the_ID();
  1114. } else {
  1115. $post_id = array();
  1116. if ( have_posts() ) {
  1117. while ( have_posts() ) {
  1118. the_post();
  1119. $post_id[] = get_the_ID();
  1120. }
  1121. }
  1122. }
  1123. if ( is_array( $post_id ) ) {
  1124. foreach ( $post_id as $id ) {
  1125. $fonts = json_decode( get_post_meta( $id, 'thrive_post_fonts', true ) );
  1126. if ( $fonts != null ) {
  1127. foreach ( $fonts as $key => $font ) {
  1128. wp_enqueue_style( 'tcf_' . md5( $font ), $font );
  1129. }
  1130. }
  1131. }
  1132. } else {
  1133. $fonts = json_decode( get_post_meta( $post_id, 'thrive_post_fonts', true ) );
  1134. if ( $fonts != null ) {
  1135. foreach ( $fonts as $key => $font ) {
  1136. wp_enqueue_style( 'tcf_' . md5( $font ), $font );
  1137. }
  1138. }
  1139. }
  1140. }
  1141.  
  1142. add_filter( 'is_protected_meta', 'thrive_hide_custom_fields', 10, 2 );
  1143.  
  1144. function thrive_hide_custom_fields( $protected, $meta_key ) {
  1145. $keys = array(
  1146. 'thrive_post_fonts',
  1147. 'thrive_share_count'
  1148. );
  1149.  
  1150. if ( in_array( $meta_key, $keys ) ) {
  1151. return true;
  1152. }
  1153.  
  1154. return $protected;
  1155. }
  1156.  
  1157. add_action( 'wp_ajax_thrive_get_share_count', 'thrive_get_share_count' );
  1158. add_action( 'wp_ajax_nopriv_thrive_get_share_count', 'thrive_get_share_count' );
  1159.  
  1160. add_action( 'tve_dash_main_ajax_theme_shares', 'thrive_dash_social_ajax_share_counts', 10, 2 );
  1161.  
  1162. /**
  1163. * return share counts to the dashboard main ajax call
  1164. *
  1165. * @param array $current
  1166. * @param array $post_data
  1167. */
  1168. function thrive_dash_social_ajax_share_counts( $current, $post_data ) {
  1169. return thrive_get_share_count( true, $post_data );
  1170. }
  1171.  
  1172. /**
  1173. * @param bool|false $return
  1174. * @param null $post_data
  1175. *
  1176. * @return mixed
  1177. */
  1178. function thrive_get_share_count( $return = false, $post_data = null ) {
  1179. $post_data = null !== $post_data ? $post_data : $_REQUEST;
  1180.  
  1181. if ( isset( $post_data['post_id'] ) ) {
  1182. $post_id = $post_data['post_id'];
  1183. } else {
  1184. $post_id = 0;
  1185. }
  1186.  
  1187. if ( empty( $post_id ) ) {
  1188. return '';
  1189. }
  1190.  
  1191. $cache_lifetime = apply_filters( 'thrive_cache_shares_lifetime', 300 );
  1192.  
  1193. $share_count = json_decode( get_post_meta( $post_id, 'thrive_share_count', true ), true );
  1194. if ( empty( $share_count ) ) {
  1195. $share_count = array();
  1196. }
  1197.  
  1198. $post_link = get_permalink( $post_id );
  1199. if ( ! empty( $share_count['url'] ) && $share_count['url'] != $post_link ) { // if url has changed => refresh the cache
  1200. $share_count = array();
  1201. }
  1202.  
  1203. if ( empty( $_POST['no_cache'] ) && ! empty( $share_count['last_fetch'] ) && time() < $share_count['last_fetch'] + $cache_lifetime ) {
  1204. if ( $return ) {
  1205. return $share_count['total'] . ' ' . _n( 'Share', 'Shares', $share_count['total'], 'thrive' );
  1206. }
  1207. exit( $share_count['total'] . ' ' . _n( 'Share', 'Shares', $share_count['total'], 'thrive' ) );
  1208. }
  1209.  
  1210. $fb = thrive_get_facebook_share( $post_link );
  1211. if ( ! empty( $fb ) || ! isset( $share_count['facebook'] ) ) {
  1212. $share_count['facebook'] = $fb;
  1213. }
  1214.  
  1215. $share_count['twitter'] = 0;
  1216.  
  1217. $po = thrive_get_plusones_shares( $post_link );
  1218. if ( ! empty( $po ) || ! isset( $share_count['plusone'] ) ) {
  1219. $share_count['plusone'] = $po;
  1220. }
  1221.  
  1222. $pinterest = thrive_get_plusones_shares( $post_link, 'pinterest' );
  1223. if ( ! empty( $pinterest ) || ! isset( $share_count['pinterest'] ) ) {
  1224. $share_count['pinterest'] = $pinterest;
  1225. }
  1226. $li = thrive_get_linkedin_share( $post_link );
  1227. if ( ! empty( $li ) || ! isset( $share_count['linkedin'] ) ) {
  1228. $share_count['linkedin'] = $li;
  1229. }
  1230. $total = 0;
  1231. foreach ( $share_count as $network => $count ) {
  1232. if ( $network == 'last_fetch' || $network == 'total' || $network == 'url' ) {
  1233. continue;
  1234. }
  1235. $total += $count;
  1236. }
  1237. $share_count['total'] = $total;
  1238. $share_count['last_fetch'] = time();
  1239. $share_count['url'] = $post_link;
  1240. //update post meta options
  1241. update_post_meta( $post_id, 'thrive_share_count', sanitize_text_field( json_encode( $share_count ) ) );
  1242.  
  1243. if ( $return ) {
  1244. return $total . ' ' . _n( 'Share', 'Shares', $total + 12321, 'thrive' );
  1245. }
  1246. exit( $total . ' ' . _n( 'Share', 'Shares', $total, 'thrive' ) );
  1247. }
  1248.  
  1249. add_theme_support( 'woocommerce' );
  1250.  
  1251. /*
  1252. * Custom title output
  1253. */
  1254. if ( ! function_exists( 'thrive_wp_title' ) ) :
  1255. function thrive_wp_title( $title ) {
  1256. if ( is_front_page() ) {
  1257. return get_bloginfo( 'name' ) . ' | ' . get_bloginfo( 'description' );
  1258. } elseif ( is_feed() ) {
  1259. return ' | RSS Feed';
  1260. } else {
  1261. return trim( $title, '| ' ) . ' | ' . get_bloginfo( 'name' );
  1262. }
  1263.  
  1264. }
  1265.  
  1266. add_filter( 'wp_title', 'thrive_wp_title' );
  1267. endif;
  1268.  
  1269. /**
  1270. * add custom classes for woocommerce - the right way
  1271. */
  1272. add_filter( 'body_class', 'thrive_body_class' );
  1273.  
  1274. /**
  1275. * check if Woocommerce specific pages and append required classes
  1276. *
  1277. * @param array $classes
  1278. *
  1279. * @return array
  1280. */
  1281. function thrive_body_class( $classes ) {
  1282. if ( class_exists( 'WooCommerce' ) ) {
  1283. $classes [] = 'tve-woo-minicart';
  1284. } else {
  1285. return $classes;
  1286. }
  1287.  
  1288. if ( _thrive_check_is_woocommerce_page() || thrive_has_woo_shortcode() ) {
  1289. $classes [] = 'tve-woocommerce';
  1290. }
  1291.  
  1292. return $classes;
  1293. }
  1294.  
  1295. add_filter( 'get_avatar_url', 'thrive_get_avatar_url', 10, 3 );
  1296. /**
  1297. * Filter the avatar url
  1298. * Returns the thrive user image if is set
  1299. *
  1300. * @param $url
  1301. * @param $id_or_email
  1302. *
  1303. * @return string
  1304. */
  1305. function thrive_get_avatar_url( $url, $id_or_email ) {
  1306. if ( is_numeric( $id_or_email ) && $user = get_user_by( 'id', absint( $id_or_email ) ) ) {
  1307. $thrive_url = get_user_meta( $user->ID, 'tt_authorbox_image', true );
  1308. /** just some check for backwards compatibility */
  1309. if ( strpos( $thrive_url, 'TT_DEFAULT_AUTHORBOX_IMAGE' ) !== false ) {
  1310. return $url;
  1311. }
  1312.  
  1313. if ( ! empty( $thrive_url ) ) {
  1314. return $thrive_url;
  1315. }
  1316. }
  1317.  
  1318. return $url;
  1319. }
  1320.  
  1321. /**
  1322. * Display navigation to next/previous comments when applicable.
  1323. */
  1324. function thrive_theme_comment_nav() {
  1325. // Are there comments to navigate through?
  1326. if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) {
  1327. echo "<div class='pgn clearfix'>";
  1328.  
  1329. if ( $prev_link = get_previous_comments_link( __( 'Older Comments', 'thrive' ) ) ) {
  1330. printf( '%s', $prev_link );
  1331. }
  1332.  
  1333. if ( $next_link = get_next_comments_link( __( 'Newer Comments', 'thrive' ) ) ) {
  1334. printf( '%s', $next_link );
  1335. }
  1336.  
  1337. echo "</div><!-- .nav-links -->";
  1338. }
  1339. }
  1340.  
  1341. /**
  1342. * return the previous comments page link's class
  1343. *
  1344. * @return string
  1345. */
  1346. function thrive_get_previous_comments_link_attributes() {
  1347. return 'class="prev page-numbers"';
  1348. }
  1349.  
  1350. /**
  1351. * return the next comments page link's class
  1352. *
  1353. * @return string
  1354. */
  1355. function thrive_get_next_comments_link_attributes() {
  1356. return 'class="next page-numbers"';
  1357. }
  1358.  
  1359. add_action( 'wp_head', 'thrive_fb_comments_moderators' );
  1360.  
  1361. /**
  1362. * output the meta tags needed for FB comments moderation tool
  1363. *
  1364. * <meta property="fb:admins" content="{YOUR_FACEBOOK_USER_ID}"/>
  1365. *
  1366. */
  1367. function thrive_fb_comments_moderators() {
  1368. $fb_moderators = thrive_get_theme_options( 'fb_moderators' );
  1369. $fb_app_id = thrive_get_theme_options( 'fb_app_id' );
  1370.  
  1371. if ( empty( $fb_moderators ) ) {
  1372. return;
  1373. }
  1374.  
  1375. if ( ! is_singular() && ! is_front_page() && ! is_home() ) {
  1376. return;
  1377. }
  1378.  
  1379. foreach ( $fb_moderators as $moderator ) {
  1380. echo sprintf( '<meta property="fb:admins" content="%s"/>', $moderator );
  1381. }
  1382.  
  1383. echo sprintf( '<meta property="fb:app_id" content="%s"/>', $fb_app_id );
  1384.  
  1385. }
  1386.  
  1387. /**
  1388. * Get ttw url
  1389. *
  1390. * @return string
  1391. */
  1392. function thrive_get_ttw_url() {
  1393. $affiliate_id = get_option( 'thrive_affiliate_id' );
  1394.  
  1395. return ! empty( $affiliate_id ) ?
  1396. 'https://thrivethemes.com/affiliates/ref.php?id=' . $affiliate_id :
  1397. 'https://www.thrivethemes.com';
  1398.  
  1399. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement