forked from ThemeFuse/Unyson-Portfolio-Extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhooks.php
More file actions
64 lines (52 loc) · 1.78 KB
/
hooks.php
File metadata and controls
64 lines (52 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php if ( ! defined( 'FW' ) ) {
die( 'Forbidden' );
}
/**
* Replace the content of the current template with the content of portfolio view
*
* @param string $the_content
*
* @return string
*/
function _filter_fw_ext_portfolio_the_content( $the_content ) {
/**
* @var FW_Extension_Portfolio $portfolio
*/
$portfolio = fw()->extensions->get( 'portfolio' );
return fw_render_view( $portfolio->locate_view_path( 'content' ), array( 'the_content' => $the_content ) );
}
/**
* Check if the there are defined views for the portfolio templates, otherwise are used theme templates
*
* @param string $template
*
* @return string
*/
function _filter_fw_ext_portfolio_template_include( $template ) {
/**
* @var FW_Extension_Portfolio $portfolio
*/
$portfolio = fw()->extensions->get( 'portfolio' );
if ( is_singular( $portfolio->get_post_type_name() ) ) {
if ( preg_match( '/single-' . '.*\.php/i', basename( $template ) ) === 1 ) {
return $template;
}
if ( $portfolio->locate_view_path( 'single' ) ) {
return $portfolio->locate_view_path( 'single' );
} else {
add_filter( 'the_content', '_filter_fw_ext_portfolio_the_content' );
}
} else if ( is_tax( $portfolio->get_taxonomy_name() ) && $portfolio->locate_view_path( 'taxonomy' ) ) {
if ( preg_match( '/taxonomy-' . '.*\.php/i', basename( $template ) ) === 1 ) {
return $template;
}
return $portfolio->locate_view_path( 'taxonomy' );
} else if ( is_post_type_archive( $portfolio->get_post_type_name() ) && $portfolio->locate_view_path( 'archive' ) ) {
if ( preg_match( '/archive-' . '.*\.php/i', basename( $template ) ) === 1 ) {
return $template;
}
return $portfolio->locate_view_path( 'archive' );
}
return $template;
}
add_filter( 'template_include', '_filter_fw_ext_portfolio_template_include' );