PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.9.1
Secure Custom Fields v6.9.1
6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / acf-post-type-functions.php
secure-custom-fields / includes Last commit date
Blocks 1 week ago Datastore 1 month ago Meta 1 year ago abilities 1 week ago admin 1 week ago ajax 1 month ago api 2 days ago fields 2 days ago forms 2 days ago legacy 1 year ago locations 1 year ago post-types 2 months ago rest-api 1 week ago walkers 1 year ago acf-bidirectional-functions.php 1 year ago acf-field-functions.php 2 months ago acf-field-group-functions.php 7 months ago acf-form-functions.php 1 year ago acf-helper-functions.php 1 year ago acf-hook-functions.php 1 year ago acf-input-functions.php 7 months ago acf-internal-post-type-functions.php 7 months ago acf-meta-functions.php 3 weeks ago acf-post-functions.php 1 year ago acf-post-type-functions.php 1 year ago acf-taxonomy-functions.php 1 year ago acf-user-functions.php 1 week ago acf-utility-functions.php 1 year ago acf-value-functions.php 1 year ago acf-wp-functions.php 2 days ago assets.php 1 week ago blocks-auto-inline-editing.php 2 months ago blocks.php 3 weeks ago class-acf-data.php 10 months ago class-acf-internal-post-type.php 1 week ago class-acf-options-page.php 1 year ago class-acf-site-health.php 3 months ago class-scf-json-schema-validator.php 6 months ago class-scf-schema-builder.php 2 months ago compatibility.php 1 year ago datastore.php 1 month ago deprecated.php 1 year ago fields.php 10 months ago index.php 1 year ago l10n.php 1 year ago local-fields.php 1 year ago local-json.php 1 month ago local-meta.php 1 year ago locations.php 1 year ago loop.php 10 months ago media.php 1 year ago rest-api.php 10 months ago revisions.php 1 month ago scf-ui-options-page-functions.php 1 year ago third-party.php 7 months ago upgrades.php 3 weeks ago validation.php 10 months ago wpml.php 1 year ago
acf-post-type-functions.php
301 lines
1 <?php
2 /**
3 * Functions for ACF post type objects.
4 *
5 * @package wordpress/secure-custom-fields
6 */
7
8 /**
9 * Get an ACF CPT as an array
10 *
11 * @param integer|string $id The post ID being queried.
12 * @return array|false The post type object.
13 */
14 function acf_get_post_type( $id ) {
15 return acf_get_internal_post_type( $id, 'acf-post-type' );
16 }
17
18 /**
19 * Retrieves a raw ACF CPT.
20 *
21 * @since ACF 6.1
22 *
23 * @param integer|string $id The post ID.
24 * @return array|false The internal post type array.
25 */
26 function acf_get_raw_post_type( $id ) {
27 return acf_get_raw_internal_post_type( $id, 'acf-post-type' );
28 }
29
30 /**
31 * Gets a post object for an ACF CPT.
32 *
33 * @since ACF 6.1
34 *
35 * @param integer|string $id The post ID, key, or name.
36 * @return object|boolean The post object, or false on failure.
37 */
38 function acf_get_post_type_post( $id ) {
39 return acf_get_internal_post_type_post( $id, 'acf-post-type' );
40 }
41
42 /**
43 * Returns true if the given identifier is an ACF CPT key.
44 *
45 * @since ACF 6.1
46 *
47 * @param string $id The identifier.
48 * @return boolean
49 */
50 function acf_is_post_type_key( $id ) {
51 return acf_is_internal_post_type_key( $id, 'acf-post-type' );
52 }
53
54 /**
55 * Validates an ACF CPT.
56 *
57 * @since ACF 6.1
58 *
59 * @param array $post_type The ACF post type array.
60 * @return array|boolean
61 */
62 function acf_validate_post_type( array $post_type = array() ) {
63 return acf_validate_internal_post_type( $post_type, 'acf-post-type' );
64 }
65
66 /**
67 * Translates the settings for an ACF internal post type.
68 *
69 * @since ACF 6.1
70 *
71 * @param array $post_type The ACF post type array.
72 * @return array
73 */
74 function acf_translate_post_type( array $post_type ) {
75 return acf_translate_internal_post_type( $post_type, 'acf-post-type' );
76 }
77
78 /**
79 * Returns and array of ACF post types for the given $filter.
80 *
81 * @since ACF 6.1
82 *
83 * @param array $filter An array of args to filter results by.
84 * @return array
85 */
86 function acf_get_acf_post_types( array $filter = array() ) {
87 return acf_get_internal_post_type_posts( 'acf-post-type', $filter );
88 }
89
90 /**
91 * Returns an array of raw ACF post types.
92 *
93 * @since ACF 6.1
94 *
95 * @return array
96 */
97 function acf_get_raw_post_types() {
98 return acf_get_raw_internal_post_type_posts( 'acf-post-type' );
99 }
100
101 /**
102 * Returns a filtered array of ACF post types based on the given $args.
103 *
104 * @since ACF 6.1
105 *
106 * @param array $post_types An array of ACF posts.
107 * @param array $args An array of args to filter by.
108 * @return array
109 */
110 function acf_filter_post_types( array $post_types, array $args = array() ) {
111 return acf_filter_internal_post_type_posts( $post_types, $args, 'acf-post-type' );
112 }
113
114 /**
115 * Updates an ACF post type in the database.
116 *
117 * @since ACF 6.1
118 *
119 * @param array $post_type The main ACF post type array.
120 * @return array
121 */
122 function acf_update_post_type( array $post_type ) {
123 return acf_update_internal_post_type( $post_type, 'acf-post-type' );
124 }
125
126 /**
127 * Deletes all caches for the provided ACF post type.
128 *
129 * @since ACF 6.1
130 *
131 * @param array $post_type The ACF post type array.
132 * @return void
133 */
134 function acf_flush_post_type_cache( array $post_type ) {
135 acf_flush_internal_post_type_cache( $post_type, 'acf-post-type' );
136 }
137
138 /**
139 * Deletes an ACF post type from the database.
140 *
141 * @since ACF 6.1
142 *
143 * @param integer|string $id The ACF post type ID, key or name.
144 * @return boolean True if post type was deleted.
145 */
146 function acf_delete_post_type( $id = 0 ) {
147 return acf_delete_internal_post_type( $id, 'acf-post-type' );
148 }
149
150 /**
151 * Trashes an ACF post type.
152 *
153 * @since ACF 6.1
154 *
155 * @param integer|string $id The post type ID, key, or name.
156 * @return boolean True if post was trashed.
157 */
158 function acf_trash_post_type( $id = 0 ) {
159 return acf_trash_internal_post_type( $id, 'acf-post-type' );
160 }
161
162 /**
163 * Restores an ACF post type from the trash.
164 *
165 * @since ACF 6.1
166 *
167 * @param integer|string $id The post type ID, key, or name.
168 * @return boolean True if post was untrashed.
169 */
170 function acf_untrash_post_type( $id = 0 ) {
171 return acf_untrash_internal_post_type( $id, 'acf-post-type' );
172 }
173
174 /**
175 * Returns true if the given params match an ACF post type.
176 *
177 * @since ACF 6.1
178 *
179 * @param array $post_type The ACF post type array.
180 * @return boolean
181 */
182 function acf_is_post_type( $post_type ) {
183 return acf_is_internal_post_type( $post_type, 'acf-post-type' );
184 }
185
186 /**
187 * Duplicates an ACF post type.
188 *
189 * @since ACF 6.1
190 *
191 * @param integer|string $id The ACF post type ID, key or name.
192 * @param integer $new_post_id Optional ID to override.
193 * @return array|boolean The new ACF post type, or false on failure.
194 */
195 function acf_duplicate_post_type( $id = 0, $new_post_id = 0 ) {
196 return acf_duplicate_internal_post_type( $id, $new_post_id, 'acf-post-type' );
197 }
198
199 /**
200 * Activates or deactivates an ACF post type.
201 *
202 * @param integer|string $id The ACF post type ID, key or name.
203 * @param boolean $activate True if the post type should be activated.
204 * @return boolean
205 */
206 function acf_update_post_type_active_status( $id, $activate = true ) {
207 return acf_update_internal_post_type_active_status( $id, $activate, 'acf-post-type' );
208 }
209
210 /**
211 * Checks if the current user can edit the post type and returns the edit url.
212 *
213 * @since ACF 6.1
214 *
215 * @param integer $post_id The ACF post type ID.
216 * @return string
217 */
218 function acf_get_post_type_edit_link( $post_id ) {
219 return acf_get_internal_post_type_edit_link( $post_id, 'acf-post-type' );
220 }
221
222 /**
223 * Returns a modified ACF post type ready for export.
224 *
225 * @since ACF 6.1
226 *
227 * @param array $post_type The ACF post type array.
228 * @return array
229 */
230 function acf_prepare_post_type_for_export( array $post_type = array() ) {
231 return acf_prepare_internal_post_type_for_export( $post_type, 'acf-post-type' );
232 }
233
234 /**
235 * Exports an ACF post type as PHP.
236 *
237 * @since ACF 6.1
238 *
239 * @param array $post_type The ACF post type array.
240 * @return string|boolean
241 */
242 function acf_export_post_type_as_php( array $post_type ) {
243 return acf_export_internal_post_type_as_php( $post_type, 'acf-post-type' );
244 }
245
246 /**
247 * Prepares an ACF post type for the import process.
248 *
249 * @since ACF 6.1
250 *
251 * @param array $post_type The ACF post type array.
252 * @return array
253 */
254 function acf_prepare_post_type_for_import( array $post_type = array() ) {
255 return acf_prepare_internal_post_type_for_import( $post_type, 'acf-post-type' );
256 }
257
258 /**
259 * Imports an ACF post type into the database.
260 *
261 * @since ACF 6.1
262 *
263 * @param array $post_type The ACF post type array.
264 * @return array The imported post type.
265 */
266 function acf_import_post_type( array $post_type ) {
267 return acf_import_internal_post_type( $post_type, 'acf-post-type' );
268 }
269
270 /**
271 * Exports the "Enter Title Here" text for the provided ACF post types.
272 *
273 * @since ACF 6.2.1
274 *
275 * @param array $post_types The post types being exported.
276 * @return string
277 */
278 function acf_export_enter_title_here( array $post_types ) {
279 $to_export = array();
280 $export = '';
281
282 foreach ( $post_types as $post_type ) {
283 if ( ! empty( $post_type['enter_title_here'] ) ) {
284 $to_export[ $post_type['post_type'] ] = $post_type['enter_title_here'];
285 }
286 }
287
288 if ( ! empty( $to_export ) ) {
289 $export .= "\r\nadd_filter( 'enter_title_here', function( \$default, \$post ) {\r\n";
290 $export .= "\tswitch ( \$post->post_type ) {\r\n";
291
292 foreach ( $to_export as $post_type => $enter_title_here ) {
293 $export .= "\t\tcase '$post_type':\r\n\t\t\treturn '$enter_title_here';\r\n";
294 }
295
296 $export .= "\t}\r\n\r\n\treturn \$default;\r\n}, 10, 2 );\r\n\r\n";
297 }
298
299 return esc_textarea( $export );
300 }
301