PageRenderTime 27ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/projects-by-woothemes/projects-template.php

https://gitlab.com/mostafame/team_website
PHP | 601 lines | 246 code | 104 blank | 251 comment | 86 complexity | a05e22be1eba60894f437d212ce4421d MD5 | raw file
  1. <?php
  2. /**
  3. * WooThemes Projects Template Functions
  4. *
  5. * Functions used in the template files to output content - in most cases hooked in via the template actions. All functions are pluggable.
  6. *
  7. * @author WooThemes
  8. * @category Core
  9. * @package Projects/Templates
  10. * @version 1.0.0
  11. */
  12. if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  13. /** Global ****************************************************************/
  14. /**
  15. * Handle redirects before content is output - hooked into template_redirect so is_page works.
  16. *
  17. * @return void
  18. */
  19. function projects_template_redirect() {
  20. global $wp_query, $wp;
  21. // Redirect project base page to post type archive url
  22. if ( ! empty( $_GET['page_id'] ) && get_option( 'permalink_structure' ) == "" && $_GET['page_id'] == projects_get_page_id( 'projects' ) ) {
  23. wp_safe_redirect( get_post_type_archive_link( 'project' ) );
  24. exit;
  25. }
  26. if ( is_front_page() && is_page( projects_get_page_id( 'projects' ) ) ) {
  27. wp_safe_redirect( get_post_type_archive_link( 'project' ) );
  28. }
  29. }
  30. /**
  31. * Fix active class in nav for shop page.
  32. *
  33. * @param array $menu_items
  34. * @param array $args
  35. * @return array
  36. */
  37. function projects_nav_menu_item_classes( $menu_items, $args ) {
  38. if ( ! is_projects() ) return $menu_items;
  39. $projects_page = (int) projects_get_page_id( 'projects' );
  40. $page_for_posts = (int) get_option( 'page_for_posts' );
  41. foreach ( (array) $menu_items as $key => $menu_item ) {
  42. $classes = (array) $menu_item->classes;
  43. // Unset active class for blog page
  44. if ( $page_for_posts == $menu_item->object_id ) {
  45. $menu_items[$key]->current = false;
  46. if ( in_array( 'current_page_parent', $classes ) )
  47. unset( $classes[ array_search('current_page_parent', $classes) ] );
  48. if ( in_array( 'current-menu-item', $classes ) )
  49. unset( $classes[ array_search('current-menu-item', $classes) ] );
  50. // Set active state if this is the shop page link
  51. } elseif ( is_projects() && $projects_page == $menu_item->object_id ) {
  52. $menu_items[$key]->current = true;
  53. $classes[] = 'current-menu-item';
  54. $classes[] = 'current_page_item';
  55. // Set parent state if this is a product page
  56. } elseif ( is_singular( 'project' ) && $projects_page == $menu_item->object_id ) {
  57. $classes[] = 'current_page_parent';
  58. }
  59. $menu_items[$key]->classes = array_unique( $classes );
  60. }
  61. return $menu_items;
  62. }
  63. if ( ! function_exists( 'projects_output_content_wrapper' ) ) {
  64. /**
  65. * Output the start of the page wrapper.
  66. *
  67. * Hooked into projects_before_main_content
  68. *
  69. * @access public
  70. * @return void
  71. */
  72. function projects_output_content_wrapper() {
  73. projects_get_template( 'layout/wrapper-start.php' );
  74. }
  75. }
  76. if ( ! function_exists( 'projects_output_content_wrapper_end' ) ) {
  77. /**
  78. * Output the end of the page wrapper.
  79. *
  80. * Hooked into projects_after_main_content
  81. *
  82. * @access public
  83. * @return void
  84. */
  85. function projects_output_content_wrapper_end() {
  86. projects_get_template( 'layout/wrapper-end.php' );
  87. }
  88. }
  89. if ( ! function_exists( 'projects_get_sidebar' ) ) {
  90. /**
  91. * Get the projects sidebar template.
  92. *
  93. * Hooked into projects_sidebar
  94. *
  95. * @access public
  96. * @return void
  97. */
  98. function projects_get_sidebar() {
  99. projects_get_template( 'layout/sidebar.php' );
  100. }
  101. }
  102. /** Loop ******************************************************************/
  103. if ( ! function_exists( 'projects_page_title' ) ) {
  104. /**
  105. * projects_page_title function.
  106. *
  107. * @access public
  108. * @return void
  109. */
  110. function projects_page_title() {
  111. if ( is_search() ) {
  112. $page_title = sprintf( __( 'Search Results: &ldquo;%s&rdquo;', 'projects-by-woothemes' ), get_search_query() );
  113. if ( get_query_var( 'paged' ) )
  114. $page_title .= sprintf( __( '&nbsp;&ndash; Page %s', 'projects-by-woothemes' ), get_query_var( 'paged' ) );
  115. } elseif ( is_tax() ) {
  116. $page_title = single_term_title( '', false );
  117. } else {
  118. $projects_page_id = projects_get_page_id( 'projects' );
  119. $page_title = get_the_title( $projects_page_id );
  120. }
  121. echo apply_filters( 'projects_page_title', $page_title );
  122. }
  123. }
  124. if ( ! function_exists( 'projects_project_loop_start' ) ) {
  125. /**
  126. * Output the start of a project loop. By default this is a UL
  127. *
  128. * @access public
  129. * @return void
  130. */
  131. function projects_project_loop_start( $echo = true ) {
  132. ob_start();
  133. projects_get_template( 'loop/loop-start.php' );
  134. if ( $echo )
  135. echo ob_get_clean();
  136. else
  137. return ob_get_clean();
  138. }
  139. }
  140. if ( ! function_exists( 'projects_project_loop_end' ) ) {
  141. /**
  142. * Output the end of a project loop. By default this is a UL
  143. *
  144. * @access public
  145. * @return void
  146. */
  147. function projects_project_loop_end( $echo = true ) {
  148. ob_start();
  149. projects_get_template( 'loop/loop-end.php' );
  150. if ( $echo )
  151. echo ob_get_clean();
  152. else
  153. return ob_get_clean();
  154. }
  155. }
  156. if ( ! function_exists( 'projects_taxonomy_archive_description' ) ) {
  157. /**
  158. * Show an archive description on taxonomy archives
  159. *
  160. * Hooked into projects_archive_description
  161. *
  162. * @access public
  163. * @subpackage Archives
  164. * @return void
  165. */
  166. function projects_taxonomy_archive_description() {
  167. if ( is_tax( array( 'project-category', 'project-tag' ) ) && get_query_var( 'paged' ) == 0 ) {
  168. $description = apply_filters( 'the_content', term_description() );
  169. if ( $description ) {
  170. echo '<div class="term-description">' . $description . '</div>';
  171. }
  172. }
  173. }
  174. }
  175. if ( ! function_exists( 'projects_project_archive_description' ) ) {
  176. /**
  177. * Show a projects page description on project archives
  178. *
  179. * Hooked into projects_archive_description
  180. *
  181. * @access public
  182. * @subpackage Archives
  183. * @return void
  184. */
  185. function projects_project_archive_description() {
  186. if ( is_post_type_archive( 'project' ) && get_query_var( 'paged' ) == 0 || is_page( projects_get_page_id( 'projects' ) ) ) {
  187. $projects_page = get_post( projects_get_page_id( 'projects' ) );
  188. $page_content = '';
  189. if ( isset( $projects_page->post_content ) ) {
  190. $page_content = $projects_page->post_content;
  191. }
  192. $description = apply_filters( 'the_content', $page_content );
  193. if ( $description ) {
  194. echo '<div class="page-description">' . $description . '</div>';
  195. }
  196. }
  197. }
  198. }
  199. if ( ! function_exists( 'projects_template_loop_project_thumbnail' ) ) {
  200. /**
  201. * Get the project thumbnail for the loop.
  202. *
  203. * Hooked into projects_loop_item
  204. *
  205. * @access public
  206. * @subpackage Loop
  207. * @return void
  208. */
  209. function projects_template_loop_project_thumbnail() {
  210. echo '<figure class="project-thumbnail">' . projects_get_project_thumbnail() . '</figure>';
  211. }
  212. }
  213. if ( ! function_exists( 'projects_template_loop_project_title' ) ) {
  214. /**
  215. * Display the project title in the loop.
  216. *
  217. * Hooked into projects_loop_item
  218. *
  219. * @access public
  220. * @subpackage Loop
  221. * @return void
  222. */
  223. function projects_template_loop_project_title() {
  224. echo '<h3>' . get_the_title() . '</h3>';
  225. }
  226. }
  227. if ( ! function_exists( 'projects_reset_loop' ) ) {
  228. /**
  229. * Reset the loop's index and columns when we're done outputting a project loop.
  230. *
  231. * @access public
  232. * @subpackage Loop
  233. * @return void
  234. */
  235. function projects_reset_loop() {
  236. global $projects_loop;
  237. // Reset loop/columns globals when starting a new loop
  238. $projects_loop['loop'] = $projects_loop['column'] = '';
  239. }
  240. }
  241. add_filter( 'loop_end', 'projects_reset_loop' );
  242. if ( ! function_exists( 'projects_get_project_thumbnail' ) ) {
  243. /**
  244. * Get the project thumbnail, or the placeholder if not set.
  245. *
  246. * @access public
  247. * @subpackage Loop
  248. * @param string $size (default: 'project-archive')
  249. * @param int $placeholder_width (default: 0)
  250. * @param int $placeholder_height (default: 0)
  251. * @return string
  252. */
  253. function projects_get_project_thumbnail( $size = 'project-archive' ) {
  254. global $post;
  255. if ( has_post_thumbnail() )
  256. return get_the_post_thumbnail( $post->ID, $size );
  257. }
  258. }
  259. if ( ! function_exists( 'projects_pagination' ) ) {
  260. /**
  261. * Output the pagination.
  262. *
  263. * Hooked into projects_after_loop
  264. *
  265. * @access public
  266. * @subpackage Loop
  267. * @return void
  268. */
  269. function projects_pagination() {
  270. projects_get_template( 'loop/pagination.php' );
  271. }
  272. }
  273. if ( ! function_exists( 'projects_template_short_description' ) ) {
  274. /**
  275. * Output the project short description.
  276. *
  277. * Hooked into projects_after_loop_item
  278. *
  279. * @access public
  280. * @subpackage Project
  281. * @return void
  282. */
  283. function projects_template_short_description() {
  284. projects_get_template( 'loop/short-description.php' );
  285. }
  286. }
  287. /** Single Project ********************************************************/
  288. if ( ! function_exists( 'projects_template_single_feature' ) ) {
  289. /**
  290. * Output the project feature before the single project summary.
  291. *
  292. * Hooked into projects_before_single_project_summary
  293. *
  294. * @access public
  295. * @subpackage Project
  296. * @return void
  297. */
  298. function projects_template_single_feature() {
  299. projects_get_template( 'single-project/project-feature.php' );
  300. }
  301. }
  302. if ( ! function_exists( 'projects_template_single_gallery' ) ) {
  303. /**
  304. * Output the project gallery before the single project summary.
  305. *
  306. * Hooked into projects_before_single_project_summary
  307. *
  308. * @access public
  309. * @subpackage Project
  310. * @return void
  311. */
  312. function projects_template_single_gallery() {
  313. projects_get_template( 'single-project/project-gallery.php' );
  314. }
  315. }
  316. if ( ! function_exists( 'projects_template_single_title' ) ) {
  317. /**
  318. * Output the project title.
  319. *
  320. * Hooked into projects_before_single_project_summary
  321. *
  322. * @access public
  323. * @subpackage Project
  324. * @return void
  325. */
  326. function projects_template_single_title() {
  327. projects_get_template( 'single-project/title.php' );
  328. }
  329. }
  330. if ( ! function_exists( 'projects_template_single_short_description' ) ) {
  331. /**
  332. * Output the project short description (excerpt).
  333. *
  334. * Hooked into projects_before_single_project_summary
  335. *
  336. * @access public
  337. * @subpackage Project
  338. * @return void
  339. */
  340. function projects_template_single_short_description() {
  341. projects_get_template( 'single-project/short-description.php' );
  342. }
  343. }
  344. if ( ! function_exists( 'projects_template_single_description' ) ) {
  345. /**
  346. * Output the project description.
  347. *
  348. * Hooked into projects_single_project_summary
  349. *
  350. * @access public
  351. * @subpackage Project
  352. * @return void
  353. */
  354. function projects_template_single_description() {
  355. projects_get_template( 'single-project/description.php' );
  356. }
  357. }
  358. if ( ! function_exists( 'projects_template_single_meta' ) ) {
  359. /**
  360. * Output the project meta.
  361. *
  362. * Hooked into projects_single_project_summary
  363. *
  364. * @access public
  365. * @subpackage Project
  366. * @return void
  367. */
  368. function projects_template_single_meta() {
  369. projects_get_template( 'single-project/meta.php' );
  370. }
  371. }
  372. if ( ! function_exists( 'projects_single_pagination' ) ) {
  373. /**
  374. * Output the project pagination.
  375. *
  376. * Hooked into projects_after_single_project
  377. *
  378. * @access public
  379. * @subpackage Project
  380. * @return void
  381. */
  382. function projects_single_pagination() {
  383. projects_get_template( 'single-project/pagination.php' );
  384. }
  385. }
  386. if ( ! function_exists( 'projects_content' ) ) {
  387. /**
  388. * Output Projects content.
  389. *
  390. * This function is only used in the optional 'projects.php' template
  391. * which people can add to their themes to add basic projects support
  392. * without hooks or modifying core templates.
  393. *
  394. * @access public
  395. * @return void
  396. */
  397. function projects_content() {
  398. if ( is_singular( 'project' ) ) {
  399. while ( have_posts() ) : the_post();
  400. projects_get_template_part( 'content', 'single-project' );
  401. endwhile;
  402. } else { ?>
  403. <?php if ( apply_filters( 'projects_show_page_title', true ) ) : ?>
  404. <h1 class="page-title"><?php projects_page_title(); ?></h1>
  405. <?php endif; ?>
  406. <?php do_action( 'projects_archive_description' ); ?>
  407. <?php if ( have_posts() ) : ?>
  408. <?php do_action( 'projects_before_loop' ); ?>
  409. <?php projects_project_loop_start(); ?>
  410. <?php while ( have_posts() ) : the_post(); ?>
  411. <?php projects_get_template_part( 'content', 'project' ); ?>
  412. <?php endwhile; // end of the loop. ?>
  413. <?php projects_project_loop_end(); ?>
  414. <?php do_action( 'projects_after_loop' ); ?>
  415. <?php else : ?>
  416. <?php projects_get_template( 'loop/no-products-found.php' ); ?>
  417. <?php endif;
  418. }
  419. }
  420. }
  421. if ( ! function_exists( 'projects_output_testimonial' ) ) {
  422. /**
  423. * Output Projects Testimonial.
  424. *
  425. * This function is only used if the Testimonials plugin is enabled.
  426. * It can be used to output a project's testimonial.
  427. *
  428. * Hooked into projects_after_single_project
  429. *
  430. * @access public
  431. * @return void
  432. * @since 1.1.0
  433. */
  434. function projects_output_testimonial() {
  435. if ( class_exists( 'Woothemes_Testimonials' ) && is_singular( 'project' ) ) {
  436. global $post;
  437. $testimonial_id = esc_attr( get_post_meta( $post->ID, '_testimonials_id', true ) );
  438. if ( isset( $testimonial_id ) && '' != $testimonial_id && '0' != $testimonial_id ) {
  439. $args = apply_filters( 'projects_testimonials_args', array(
  440. 'id' => $testimonial_id,
  441. 'per_row' => 1,
  442. ) );
  443. echo '<div class="project-testimonial">';
  444. woothemes_testimonials( $args );
  445. echo '</div>';
  446. }
  447. }
  448. }
  449. }
  450. if ( ! function_exists( 'projects_output_product' ) ) {
  451. /**
  452. * Output Projects Product.
  453. *
  454. * This function is only used if WooCommerce is enabled.
  455. * It can be used to output a 'buy now' button for a product associated with a project.
  456. *
  457. * Hooked into projects_after_meta
  458. *
  459. * @access public
  460. * @return void
  461. * @since 1.2.0
  462. */
  463. function projects_output_product() {
  464. if ( class_exists( 'WooCommerce' ) && is_singular( 'project' ) ) {
  465. global $post;
  466. $product_id = esc_attr( get_post_meta( $post->ID, '_products_id', true ) );
  467. if ( isset( $product_id ) && '' != $product_id && '0' != $product_id ) {
  468. echo '<div class="purchase">';
  469. echo '<h3>' . apply_filters( 'projects_meta_woocommerce_title', __( 'Purchase', 'projects-by-woothemes' ) ) . '</h3>';
  470. echo do_shortcode( '[add_to_cart id="' . $product_id . '" style=""]' );
  471. echo '</div>';
  472. }
  473. }
  474. }
  475. }
  476. if ( ! function_exists( 'projects_woocommerce_messages' ) ) {
  477. /**
  478. * Output Projects WooCommerce Messages.
  479. *
  480. * Displays WooCommerce Messages on the single project page - for feedback adding products to the cart when js is disabled
  481. *
  482. * Hooked into projects_before_single_project
  483. *
  484. * @access public
  485. * @return void
  486. * @since 1.2.0
  487. */
  488. function projects_woocommerce_messages() {
  489. if ( class_exists( 'WooCommerce' ) && is_singular( 'project' ) ) {
  490. global $post;
  491. $product_id = esc_attr( get_post_meta( $post->ID, '_products_id', true ) );
  492. if ( isset( $product_id ) && '' != $product_id && '0' != $product_id ) {
  493. echo do_shortcode( '[woocommerce_messages]' );
  494. }
  495. }
  496. }
  497. }