forked from Hube2/acf-filters-and-functions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomized-options-page.php
65 lines (50 loc) · 2.15 KB
/
customized-options-page.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
<?php
/*
At the time that I am setting up this example it is currently not possible to
modify an ACF Options Page beyond the settings in the options page and adding
field groups.
This file gives an example of how to insert content into several places in an
options page.
A note about the action hooks to use: You must know the action hook that will be used by
WP to call the callback function when ACF uses add_menu_page() and add_submenu_page().
The hook is not returned so you will need to figure out what it is.
top level options page hook = "toplevel_page_{$acf_menu_slug}"
if top level page redirects to first sub level page use sub options page slug
sub options page hook = "{$acf_parent_slug}_page_{$acf_sub_page_slug}"
*/
/*
create an action for your options page that will run before the ACF callback function
see above for information on the hook you need to use
*/
add_action('toplevel_page_YOUR-PAGE-SLUG', 'before_acf_options_page', 1);
function before_acf_options_page() {
/*
Before ACF outputs the options page content
start an object buffer so that we can capture the output
*/
ob_start();
}
/*
create an action for your options page that will run after the ACF callback function
see above for information on the hook you need to use
*/
add_action('toplevel_page_YOUR-PAGE-SLUG', 'after_acf_options_page', 20);
function after_acf_options_page() {
/*
After ACF finishes get the output and modify it
*/
$content = ob_get_clean();
$count = 1; // the number of times we should replace any string
// insert something before the <h1>
$my_content = '<p>This will be inserted before the <h1></p>';
$content = str_replace('<h1', $my_content.'<h1', $content, $count);
// insert something after the <h1>
$my_content = '<p>This will be inserted after the <h1></p>';
$content = str_replace('</h1>', '</h1>'.$my_content, $content, $count);
// insert something after the form
$my_content = '<p>This will be inserted after the form</p>';
$content = str_replace('</form>', '</form>'.$my_content, $content, $count);
// output the new content
echo $content;
}
?>