ACF_Location_Post_Template::match
Matches the provided rule against the screen args returning a bool result.
Method of the class: ACF_Location_Post_Template{}
No Hooks.
Returns
true|false.
Usage
$ACF_Location_Post_Template = new ACF_Location_Post_Template(); $ACF_Location_Post_Template->match( $rule, $screen, $field_group );
- $rule(array) (required)
- The location rule.
- $screen(array) (required)
- The screen args.
- $field_group(array) (required)
- The field group settings.
Changelog
| Since 5.9.0 | Introduced. |
ACF_Location_Post_Template::match() ACF Location Post Template::match code ACF 6.0.4
public function match( $rule, $screen, $field_group ) {
// Check screen args.
if ( isset( $screen['post_type'] ) ) {
$post_type = $screen['post_type'];
} elseif ( isset( $screen['post_id'] ) ) {
$post_type = get_post_type( $screen['post_id'] );
} else {
return false;
}
// Check if this post type has templates.
$post_templates = acf_get_post_templates();
if ( ! isset( $post_templates[ $post_type ] ) ) {
return false;
}
// Get page template allowing for screen or database value.
if ( isset( $screen['page_template'] ) ) {
$page_template = $screen['page_template'];
} elseif ( isset( $screen['post_id'] ) ) {
$page_template = get_post_meta( $screen['post_id'], '_wp_page_template', true );
} else {
$page_template = '';
}
// Treat empty value as default template.
if ( $page_template === '' ) {
$page_template = 'default';
}
// Compare rule against $page_template.
return $this->compare_to_rule( $page_template, $rule );
}