This repository has been archived by the owner on Jul 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
api.php
110 lines (100 loc) · 2.95 KB
/
api.php
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* ACF Content Blocks API
*
* @package ACF_Content_Blocks
*/
/**
* This function will instantiate a global variable containing the rows
* of a content blocks field, after which, it will determine if another
* row exists to loop through.
*
* @uses \ACF_Content_Blocks\API::have_content_blocks
*
* @param string $prefix ACF field group prefix.
* @param WP_Post|integer|string|null $post_id The post of which the value is saved against.
* @return boolean
*/
function have_content_blocks( $prefix = '', $post_id = null ) {
return ACF_Content_Blocks\API::have_content_blocks( $prefix, $post_id );
}
/**
* Alias of ACF the_row function.
*
* @uses \ACF_Content_Blocks\API::the_content_block
*
* @param boolean $format_values Whether or not to format values.
* @return array Current block data.
*/
function the_content_block( $format_values = false ) {
return ACF_Content_Blocks\API::the_content_block( $format_values );
}
/**
* Checks if current row in ACF loop is content block.
*
* @return boolean
*/
function is_content_block() {
return ACF_Content_Blocks\API::is_content_block();
}
/**
* Returns content block field value
*
* @uses \ACF_Content_Blocks\API::get_content_block_field
*
* @param string $selector The field name or key.
* @param boolean $format_value Whether or not to format the value.
* @return mixed
*/
function get_content_block_field( $selector, $format_value = true ) {
return ACF_Content_Blocks\API::get_content_block_field( $selector, $format_value );
}
/**
* Displays content block field value
*
* @uses \ACF_Content_Blocks\API::the_content_block_field
*
* @param string $selector The field name or key.
* @param boolean $format_value Whether or not to format the value.
* @return void
*/
function the_content_block_field( $selector, $format_value = true ) {
ACF_Content_Blocks\API::the_content_block_field( $selector, $format_value );
}
/**
* Alias for ACF get_row_layout function
*
* @uses \ACF_Content_Blocks\API::get_content_block_name
*
* @param string $context Context.
* @return string
*/
function get_content_block_name( $context = 'template' ) {
return ACF_Content_Blocks\API::get_content_block_name( $context );
}
/**
* Renders content blocks.
*
* @param string $prefix ACF field group prefix.
* @param \WP_Post|integer|string|null $post_id The post of which the value is saved against.
* @return void
*/
function the_content_blocks( $prefix = '', $post_id = null ) {
if ( have_content_blocks( $prefix, $post_id ) ) {
while ( have_content_blocks( $prefix, $post_id ) ) {
the_content_block();
$content_block_name = get_content_block_name();
$index = get_row_index();
$template = apply_filters(
'acb_content_block_get_template_part',
'blocks/' . $content_block_name,
$content_block_name,
$prefix,
$index
);
if ( ! empty( $template ) ) {
get_template_part( $template );
}
}
}
}