Completed
Push — feature/infinite-scroll-older-... ( 3c476c )
by
unknown
08:59
created

twentyfifteen.php ➔ twentyfifteen_infinite_scroll_render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Infinite Scroll Theme Assets
4
 *
5
 * Register support for Twenty Fifteen.
6
 */
7
8
/**
9
 * Add theme support for infinite scroll
10
 */
11
function jetpack_twentyfifteen_infinite_scroll_init() {
12
	add_theme_support( 'infinite-scroll', array(
13
		'container' => 'main',
14
		'render'    => 'twentyfifteen_infinite_scroll_render',
15
		'footer'    => 'page',
16
	) );
17
}
18
add_action( 'after_setup_theme', 'jetpack_twentyfifteen_infinite_scroll_init' );
19
20
/**
21
 * Needs to be defined so AMP logic kicks in.
22
 */
23
function twentyfifteen_infinite_scroll_render() {}
24
25
/**
26
 * Enqueue CSS stylesheet with theme styles for Infinite Scroll.
27
 */
28 View Code Duplication
function jetpack_twentyfifteen_infinite_scroll_enqueue_styles() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
	if ( wp_script_is( 'the-neverending-homepage' ) || class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
30
		$dep = wp_script_is( 'the-neverending-homepage' ) ? array( 'the-neverending-homepage' ) : array();
31
		wp_enqueue_style( 'infinity-twentyfifteen', plugins_url( 'twentyfifteen.css', __FILE__ ), $dep, '20141022' );
32
		wp_style_add_data( 'infinity-twentyfifteen', 'rtl', 'replace' );
33
	}
34
}
35
add_action( 'wp_enqueue_scripts', 'jetpack_twentyfifteen_infinite_scroll_enqueue_styles', 25 );
36
37
/**
38
 * Load AMP theme specific hooks for infinite scroll.
39
 *
40
 * @return void
41
 */
42
function amp_twentyfifteen_infinite_scroll_render_hooks() {
43
	add_filter( 'jetpack_amp_infinite_footers', 'twentyfifteen_amp_infinite_footers', 10, 2 );
44
	add_filter( 'jetpack_amp_infinite_output', 'twentyfifteen_amp_infinite_output' );
45
	add_filter( 'jetpack_amp_infinite_older_posts', 'twentyfifteen_amp_infinite_older_posts' );
46
}
47
48
/**
49
 * Get the theme specific footers.
50
 *
51
 * @param array  $footers The footers of the themes.
52
 * @param string $buffer  Contents of the output buffer.
53
 *
54
 * @return mixed
55
 */
56
function twentyfifteen_amp_infinite_footers( $footers, $buffer ) {
57
	// Collect the footer wrapper.
58
	preg_match(
59
		'/<footer id="colophon".*<!-- .site-footer -->/s',
60
		$buffer,
61
		$footer
62
	);
63
	$footers[] = reset( $footer );
64
65
	return $footers;
66
}
67
68
/**
69
 * Hide and remove various elements from next page load.
70
 *
71
 * @param string $buffer Contents of the output buffer.
72
 *
73
 * @return string
74
 */
75 View Code Duplication
function twentyfifteen_amp_infinite_output( $buffer ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
	// Hide site header on next page load.
77
	$buffer = preg_replace(
78
		'/<header id="masthead"/',
79
		'$0 next-page-hide',
80
		$buffer
81
	);
82
83
	// Hide skip link.
84
	$buffer = preg_replace(
85
		'/<a class="skip-link screen-reader-text"/',
86
		'$0 next-page-hide hidden',
87
		$buffer
88
	);
89
90
	// Hide below nav bar.
91
	$buffer = preg_replace(
92
		'/<nav class="navigation pagination"/',
93
		'$0 next-page-hide hidden',
94
		$buffer
95
	);
96
97
	// Remove the footer as it will be added back to amp next page footer.
98
	$buffer = preg_replace(
99
		'/<footer id="colophon".*<!-- .site-footer -->/s',
100
		'',
101
		$buffer
102
	);
103
104
	return $buffer;
105
}
106
107
/**
108
 * Filter the AMP infinite scroll older posts button
109
 *
110
 * @return string
111
 */
112
function twentyfifteen_amp_infinite_older_posts() {
113
	ob_start();
114
	?>
115
<div id="infinite-handle">
116
	<span>
117
		<a href="{{url}}">
118
			<button>
119
				{{title}}
120
			</button>
121
		</a>
122
	</span>
123
</div>
124
	<?php
125
	return ob_get_clean();
126
}
127