-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathfunctions.php
178 lines (154 loc) · 4.28 KB
/
functions.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/**
* Callbacks for adding AMP-related things to the admin.
*
* @package AMP
*/
/**
* Obsolete constant for flagging when Customizer is opened for AMP.
*
* @deprecated
* @var string
*/
define( 'AMP_CUSTOMIZER_QUERY_VAR', 'customize_amp' );
/**
* Sets up the AMP template editor for the Customizer.
*
* If this is in AMP canonical mode, exit.
* There's no need for the 'AMP' Customizer panel,
* And this does not need to toggle between the AMP and normal display.
*/
function amp_init_customizer() {
if ( amp_is_canonical() ) {
return;
}
// Fire up the AMP Customizer.
add_action( 'customize_register', array( 'AMP_Template_Customizer', 'init' ), 500 );
// Add some basic design settings + controls to the Customizer.
add_action( 'amp_init', array( 'AMP_Customizer_Design_Settings', 'init' ) );
// Add a link to the Customizer.
add_action( 'admin_menu', 'amp_add_customizer_link' );
}
/**
* Get permalink for the first AMP-eligible post.
*
* @return string|null
*/
function amp_admin_get_preview_permalink() {
/**
* Filter the post type to retrieve the latest for use in the AMP template customizer.
*
* @param string $post_type Post type slug. Default 'post'.
*/
$post_type = (string) apply_filters( 'amp_customizer_post_type', 'post' );
if ( ! post_type_supports( $post_type, amp_get_slug() ) ) {
return null;
}
$post_ids = get_posts( array(
'post_status' => 'publish',
'post_password' => '',
'post_type' => $post_type,
'posts_per_page' => 1,
'fields' => 'ids',
) );
if ( empty( $post_ids ) ) {
return false;
}
$post_id = $post_ids[0];
return amp_get_permalink( $post_id );
}
/**
* Registers a submenu page to access the AMP template editor panel in the Customizer.
*/
function amp_add_customizer_link() {
/** This filter is documented in includes/settings/class-amp-customizer-design-settings.php */
if ( ! apply_filters( 'amp_customizer_is_enabled', true ) || current_theme_supports( 'amp' ) ) {
return;
}
$menu_slug = add_query_arg( array(
'autofocus[panel]' => AMP_Template_Customizer::PANEL_ID,
'url' => rawurlencode( amp_admin_get_preview_permalink() ),
'return' => rawurlencode( admin_url() ),
), 'customize.php' );
// Add the theme page.
add_theme_page(
__( 'AMP', 'amp' ),
__( 'AMP', 'amp' ),
'edit_theme_options',
$menu_slug
);
}
/**
* Registers AMP settings.
*/
function amp_add_options_menu() {
if ( ! is_admin() ) {
return;
}
/**
* Filter whether to enable the AMP settings.
*
* @since 0.5
* @param bool $enable Whether to enable the AMP settings. Default true.
*/
$short_circuit = apply_filters( 'amp_options_menu_is_enabled', true );
if ( true !== $short_circuit ) {
return;
}
$amp_options = new AMP_Options_Menu();
$amp_options->init();
}
/**
* Add custom analytics.
*
* This is currently only used for legacy AMP post templates.
*
* @since 0.5
* @see amp_get_analytics()
*
* @param array $analytics Analytics.
* @return array Analytics.
*/
function amp_add_custom_analytics( $analytics = array() ) {
$analytics = amp_get_analytics( $analytics );
/**
* Add amp-analytics tags.
*
* This filter allows you to easily insert any amp-analytics tags without needing much heavy lifting.
* This filter should be used to alter entries for legacy AMP templates.
*
* @since 0.4
*
* @param array $analytics An associative array of the analytics entries we want to output. Each array entry must have a unique key, and the value should be an array with the following keys: `type`, `attributes`, `script_data`. See readme for more details.
* @param WP_Post $post The current post.
*/
$analytics = apply_filters( 'amp_post_template_analytics', $analytics, get_queried_object() );
return $analytics;
}
/**
* Bootstrap AMP post meta box.
*
* This function must be invoked only once through the 'wp_loaded' action.
*
* @since 0.6
*/
function amp_post_meta_box() {
$post_meta_box = new AMP_Post_Meta_Box();
$post_meta_box->init();
}
/**
* Bootstrap AMP Editor core blocks.
*/
function amp_editor_core_blocks() {
$editor_blocks = new AMP_Editor_Blocks();
$editor_blocks->init();
}
/**
* Bootstrap the AMP admin pointer class.
*
* @since 1.0
*/
function amp_admin_pointer() {
$admin_pointer = new AMP_Admin_Pointer();
$admin_pointer->init();
}