first commit
This commit is contained in:
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Legacy_Location' ) ) :
|
||||
abstract class ACF_Legacy_Location {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
// Add legacy method filters.
|
||||
if ( method_exists( $this, 'rule_match' ) ) {
|
||||
add_filter( "acf/location/rule_match/{$this->name}", array( $this, 'rule_match' ), 5, 3 );
|
||||
}
|
||||
if ( method_exists( $this, 'rule_operators' ) ) {
|
||||
add_filter( "acf/location/rule_operators/{$this->name}", array( $this, 'rule_operators' ), 5, 2 );
|
||||
}
|
||||
if ( method_exists( $this, 'rule_values' ) ) {
|
||||
add_filter( "acf/location/rule_values/{$this->name}", array( $this, 'rule_values' ), 5, 2 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic __call method for backwards compatibility.
|
||||
*
|
||||
* @date 10/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param string $name The method name.
|
||||
* @param array $arguments The array of arguments.
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call( $name, $arguments ) {
|
||||
|
||||
// Add backwards compatibility for legacy methods.
|
||||
// - Combine 3x legacy filters cases together (remove first args).
|
||||
switch ( $name ) {
|
||||
case 'rule_match':
|
||||
$method = isset( $method ) ? $method : 'match';
|
||||
$arguments[3] = isset( $arguments[3] ) ? $arguments[3] : false; // Add $field_group param.
|
||||
case 'rule_operators':
|
||||
$method = isset( $method ) ? $method : 'get_operators';
|
||||
case 'rule_values':
|
||||
$method = isset( $method ) ? $method : 'get_values';
|
||||
array_shift( $arguments );
|
||||
return call_user_func_array( array( $this, $method ), $arguments );
|
||||
case 'compare':
|
||||
return call_user_func_array( array( $this, 'compare_to_rule' ), $arguments );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
endif; // class_exists check
|
@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location' ) ) :
|
||||
abstract class ACF_Location extends ACF_Legacy_Location {
|
||||
|
||||
/**
|
||||
* The location rule name.
|
||||
*
|
||||
* @since 5.9.0
|
||||
* @var string
|
||||
*/
|
||||
public $name = '';
|
||||
|
||||
/**
|
||||
* The location rule label.
|
||||
*
|
||||
* @since 5.9.0
|
||||
* @var string
|
||||
*/
|
||||
public $label = '';
|
||||
|
||||
/**
|
||||
* The location rule category.
|
||||
*
|
||||
* Accepts "post", "page", "user", "forms" or a custom label.
|
||||
*
|
||||
* @since 5.9.0
|
||||
* @var string
|
||||
*/
|
||||
public $category = 'post';
|
||||
|
||||
/**
|
||||
* Whether or not the location rule is publicly accessible.
|
||||
*
|
||||
* @since 5.0.0
|
||||
* @var bool
|
||||
*/
|
||||
public $public = true;
|
||||
|
||||
/**
|
||||
* The object type related to this location rule.
|
||||
*
|
||||
* Accepts an object type discoverable by `acf_get_object_type()`.
|
||||
*
|
||||
* @since 5.9.0
|
||||
* @var string
|
||||
*/
|
||||
public $object_type = '';
|
||||
|
||||
/**
|
||||
* The object subtype related to this location rule.
|
||||
*
|
||||
* Accepts a custom post type or custom taxonomy.
|
||||
*
|
||||
* @since 5.9.0
|
||||
* @var string
|
||||
*/
|
||||
public $object_subtype = '';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @date 8/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->initialize();
|
||||
|
||||
// Call legacy constructor.
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
// Set props here.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of operators for this location.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public static function get_operators( $rule ) {
|
||||
return array(
|
||||
'==' => __( 'is equal to', 'acf' ),
|
||||
'!=' => __( 'is not equal to', 'acf' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this location.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object_type connected to this location.
|
||||
*
|
||||
* @date 1/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return string
|
||||
*/
|
||||
public function get_object_type( $rule ) {
|
||||
return $this->object_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object_subtype connected to this location.
|
||||
*
|
||||
* @date 1/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return string|array
|
||||
*/
|
||||
public function get_object_subtype( $rule ) {
|
||||
return $this->object_subtype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the given value and rule params returning true when they match.
|
||||
*
|
||||
* @date 17/9/19
|
||||
* @since 5.8.1
|
||||
*
|
||||
* @param array $rule The location rule data.
|
||||
* @param mixed $value The value to compare against.
|
||||
* @return bool
|
||||
*/
|
||||
public function compare_to_rule( $value, $rule ) {
|
||||
$result = ( $value == $rule['value'] );
|
||||
|
||||
// Allow "all" to match any value.
|
||||
if ( $rule['value'] === 'all' ) {
|
||||
$result = true;
|
||||
}
|
||||
|
||||
// Reverse result for "!=" operator.
|
||||
if ( $rule['operator'] === '!=' ) {
|
||||
return ! $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
endif; // class_exists check
|
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Attachment' ) ) :
|
||||
|
||||
class ACF_Location_Attachment extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'attachment';
|
||||
$this->label = __( 'Attachment', 'acf' );
|
||||
$this->category = 'forms';
|
||||
$this->object_type = 'attachment';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
|
||||
// Check screen args.
|
||||
if ( isset( $screen['attachment'] ) ) {
|
||||
$attachment = $screen['attachment'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get attachment mime type
|
||||
$mime_type = get_post_mime_type( $attachment );
|
||||
|
||||
// Allow for unspecific mim_type matching such as "image" or "video".
|
||||
if ( ! strpos( $rule['value'], '/' ) ) {
|
||||
|
||||
// Explode mime_type into bits ([0] => type, [1] => subtype) and match type.
|
||||
$bits = explode( '/', $mime_type );
|
||||
if ( $bits[0] === $rule['value'] ) {
|
||||
$mime_type = $rule['value'];
|
||||
}
|
||||
}
|
||||
return $this->compare_to_rule( $mime_type, $rule );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
$choices = array(
|
||||
'all' => __( 'All', 'acf' ),
|
||||
);
|
||||
|
||||
// Get mime types and append into optgroups.
|
||||
$mime_types = get_allowed_mime_types();
|
||||
foreach ( $mime_types as $regex => $mime_type ) {
|
||||
|
||||
// Get type "image" from mime_type "image/jpeg".
|
||||
$type = current( explode( '/', $mime_type ) );
|
||||
|
||||
// Append group and mimetype.
|
||||
$choices[ $type ][ $type ] = sprintf( __( 'All %s formats', 'acf' ), $type );
|
||||
$choices[ $type ][ $mime_type ] = "$regex ($mime_type)";
|
||||
}
|
||||
|
||||
// return
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
|
||||
// Register.
|
||||
acf_register_location_type( 'ACF_Location_Attachment' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Comment' ) ) :
|
||||
|
||||
class ACF_Location_Comment extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'comment';
|
||||
$this->label = __( 'Comment', 'acf' );
|
||||
$this->category = 'forms';
|
||||
$this->object_type = 'comment';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
|
||||
// Check screen args.
|
||||
if ( isset( $screen['comment'] ) ) {
|
||||
$comment = $screen['comment'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return $this->compare_to_rule( $comment, $rule );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
return array_merge(
|
||||
array(
|
||||
'all' => __( 'All', 'acf' ),
|
||||
),
|
||||
acf_get_pretty_post_types() // Todo: Change to post types that support comments.
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Register.
|
||||
acf_register_location_type( 'ACF_Location_Comment' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Current_User_Role' ) ) :
|
||||
|
||||
class ACF_Location_Current_User_Role extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'current_user_role';
|
||||
$this->label = __( 'Current User Role', 'acf' );
|
||||
$this->category = 'user';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
|
||||
// Get current user.
|
||||
$user = wp_get_current_user();
|
||||
if ( ! $user ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check super_admin value.
|
||||
if ( $rule['value'] == 'super_admin' ) {
|
||||
$result = is_super_admin( $user->ID );
|
||||
|
||||
// Check role.
|
||||
} else {
|
||||
$result = in_array( $rule['value'], $user->roles );
|
||||
}
|
||||
|
||||
// Reverse result for "!=" operator.
|
||||
if ( $rule['operator'] === '!=' ) {
|
||||
return ! $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
$choices = wp_roles()->get_names();
|
||||
|
||||
// Prepend Super Admin choice.
|
||||
if ( is_multisite() ) {
|
||||
return array_merge(
|
||||
array(
|
||||
'super_admin' => __( 'Super Admin', 'acf' ),
|
||||
),
|
||||
$choices
|
||||
);
|
||||
}
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
|
||||
// Register.
|
||||
acf_register_location_type( 'ACF_Location_Current_User_Role' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Current_User' ) ) :
|
||||
|
||||
class ACF_Location_Current_User extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'current_user';
|
||||
$this->label = __( 'Current User', 'acf' );
|
||||
$this->category = 'user';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
switch ( $rule['value'] ) {
|
||||
case 'logged_in':
|
||||
$result = is_user_logged_in();
|
||||
break;
|
||||
case 'viewing_front':
|
||||
$result = ! is_admin();
|
||||
break;
|
||||
case 'viewing_back':
|
||||
$result = is_admin();
|
||||
break;
|
||||
default:
|
||||
$result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Reverse result for "!=" operator.
|
||||
if ( $rule['operator'] === '!=' ) {
|
||||
return ! $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
return array(
|
||||
'logged_in' => __( 'Logged in', 'acf' ),
|
||||
'viewing_front' => __( 'Viewing front end', 'acf' ),
|
||||
'viewing_back' => __( 'Viewing back end', 'acf' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Register.
|
||||
acf_register_location_type( 'ACF_Location_Current_User' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Nav_Menu_Item' ) ) :
|
||||
|
||||
class ACF_Location_Nav_Menu_Item extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'nav_menu_item';
|
||||
$this->label = __( 'Menu Item', 'acf' );
|
||||
$this->category = 'forms';
|
||||
$this->object_type = 'menu_item';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
|
||||
// Check screen args.
|
||||
if ( isset( $screen['nav_menu_item'] ) ) {
|
||||
$nav_menu_item = $screen['nav_menu_item'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Append "nav_menu" global data to $screen and call 'nav_menu' logic.
|
||||
if ( ! isset( $screen['nav_menu'] ) ) {
|
||||
$screen['nav_menu'] = acf_get_data( 'nav_menu_id' );
|
||||
}
|
||||
return acf_get_location_type( 'nav_menu' )->match( $rule, $screen, $field_group );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
return acf_get_location_type( 'nav_menu' )->get_values( $rule );
|
||||
}
|
||||
}
|
||||
|
||||
// Register.
|
||||
acf_register_location_type( 'ACF_Location_Nav_Menu_Item' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Nav_Menu' ) ) :
|
||||
|
||||
class ACF_Location_Nav_Menu extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'nav_menu';
|
||||
$this->label = __( 'Menu', 'acf' );
|
||||
$this->category = 'forms';
|
||||
$this->object_type = 'menu';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
|
||||
// Check screen args.
|
||||
if ( isset( $screen['nav_menu'] ) ) {
|
||||
$nav_menu = $screen['nav_menu'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Allow for "location/xxx" rule value.
|
||||
$bits = explode( '/', $rule['value'] );
|
||||
if ( $bits[0] === 'location' ) {
|
||||
$location = $bits[1];
|
||||
|
||||
// Get the map of menu locations [location => menu_id] and update $nav_menu to a location value.
|
||||
$menu_locations = get_nav_menu_locations();
|
||||
if ( isset( $menu_locations[ $location ] ) ) {
|
||||
$rule['value'] = $menu_locations[ $location ];
|
||||
}
|
||||
}
|
||||
|
||||
// Compare rule against $nav_menu.
|
||||
return $this->compare_to_rule( $nav_menu, $rule );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
$choices = array(
|
||||
'all' => __( 'All', 'acf' ),
|
||||
);
|
||||
|
||||
// Append locations.
|
||||
$nav_locations = get_registered_nav_menus();
|
||||
if ( $nav_locations ) {
|
||||
$cat = __( 'Menu Locations', 'acf' );
|
||||
foreach ( $nav_locations as $slug => $title ) {
|
||||
$choices[ $cat ][ "location/$slug" ] = $title;
|
||||
}
|
||||
}
|
||||
|
||||
// Append menu IDs.
|
||||
$nav_menus = wp_get_nav_menus();
|
||||
if ( $nav_menus ) {
|
||||
$cat = __( 'Menus', 'acf' );
|
||||
foreach ( $nav_menus as $nav_menu ) {
|
||||
$choices[ $cat ][ $nav_menu->term_id ] = $nav_menu->name;
|
||||
}
|
||||
}
|
||||
|
||||
// Return choices.
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
|
||||
// Register.
|
||||
acf_register_location_type( 'ACF_Location_Nav_Menu' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Page_Parent' ) ) :
|
||||
|
||||
class ACF_Location_Page_Parent extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'page_parent';
|
||||
$this->label = __( 'Page Parent', 'acf' );
|
||||
$this->category = 'page';
|
||||
$this->object_type = 'post';
|
||||
$this->object_subtype = 'page';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
|
||||
// Check screen args.
|
||||
if ( isset( $screen['page_parent'] ) ) {
|
||||
$page_parent = $screen['page_parent'];
|
||||
} elseif ( isset( $screen['post_id'] ) ) {
|
||||
$post = get_post( $screen['post_id'] );
|
||||
$page_parent = $post ? $post->post_parent : false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compare rule against $page_parent.
|
||||
return $this->compare_to_rule( $page_parent, $rule );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
return acf_get_location_type( 'page' )->get_values( $rule );
|
||||
}
|
||||
}
|
||||
|
||||
// Register.
|
||||
acf_register_location_type( 'ACF_Location_Page_Parent' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Page_Template' ) ) :
|
||||
|
||||
class ACF_Location_Page_Template extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'page_template';
|
||||
$this->label = __( 'Page Template', 'acf' );
|
||||
$this->category = 'page';
|
||||
$this->object_type = 'post';
|
||||
$this->object_subtype = 'page';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
// Page templates were extended in WordPress version 4.7 for all post types.
|
||||
// Prevent this rule (which is scoped to the "page" post type) appearing on all post types without a template selected (default template).
|
||||
if ( $rule['value'] === 'default' && $post_type !== 'page' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Match rule using Post Template logic.
|
||||
return acf_get_location_type( 'post_template' )->match( $rule, $screen, $field_group );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
$post_templates = acf_get_post_templates();
|
||||
return array_merge(
|
||||
array(
|
||||
'default' => apply_filters( 'default_page_template_title', __( 'Default Template', 'acf' ), 'meta-box' ),
|
||||
),
|
||||
$post_templates['page']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Register.
|
||||
acf_register_location_type( 'ACF_Location_Page_Template' );
|
||||
endif; // class_exists check.
|
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Page_Type' ) ) :
|
||||
|
||||
class ACF_Location_Page_Type extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'page_type';
|
||||
$this->label = __( 'Page Type', 'acf' );
|
||||
$this->category = 'page';
|
||||
$this->object_type = 'post';
|
||||
$this->object_subtype = 'page';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
|
||||
// Check screen args.
|
||||
if ( isset( $screen['post_id'] ) ) {
|
||||
$post_id = $screen['post_id'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get post.
|
||||
$post = get_post( $post_id );
|
||||
if ( ! $post ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compare.
|
||||
switch ( $rule['value'] ) {
|
||||
case 'front_page':
|
||||
$front_page = (int) get_option( 'page_on_front' );
|
||||
$result = ( $front_page === $post->ID );
|
||||
break;
|
||||
|
||||
case 'posts_page':
|
||||
$posts_page = (int) get_option( 'page_for_posts' );
|
||||
$result = ( $posts_page === $post->ID );
|
||||
break;
|
||||
|
||||
case 'top_level':
|
||||
$page_parent = (int) ( isset( $screen['page_parent'] ) ? $screen['page_parent'] : $post->post_parent );
|
||||
$result = ( $page_parent === 0 );
|
||||
break;
|
||||
|
||||
case 'parent':
|
||||
$children = get_posts(
|
||||
array(
|
||||
'post_type' => $post->post_type,
|
||||
'post_parent' => $post->ID,
|
||||
'posts_per_page' => 1,
|
||||
'fields' => 'ids',
|
||||
)
|
||||
);
|
||||
$result = ! empty( $children );
|
||||
break;
|
||||
|
||||
case 'child':
|
||||
$page_parent = (int) ( isset( $screen['page_parent'] ) ? $screen['page_parent'] : $post->post_parent );
|
||||
$result = ( $page_parent !== 0 );
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reverse result for "!=" operator.
|
||||
if ( $rule['operator'] === '!=' ) {
|
||||
return ! $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
return array(
|
||||
'front_page' => __( 'Front Page', 'acf' ),
|
||||
'posts_page' => __( 'Posts Page', 'acf' ),
|
||||
'top_level' => __( 'Top Level Page (no parent)', 'acf' ),
|
||||
'parent' => __( 'Parent Page (has children)', 'acf' ),
|
||||
'child' => __( 'Child Page (has parent)', 'acf' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// initialize
|
||||
acf_register_location_type( 'ACF_Location_Page_Type' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Page' ) ) :
|
||||
|
||||
class ACF_Location_Page extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'page';
|
||||
$this->label = __( 'Page', 'acf' );
|
||||
$this->category = 'page';
|
||||
$this->object_type = 'post';
|
||||
$this->object_subtype = 'page';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
return acf_get_location_type( 'post' )->match( $rule, $screen, $field_group );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
$choices = array();
|
||||
|
||||
// Get grouped posts.
|
||||
$groups = acf_get_grouped_posts(
|
||||
array(
|
||||
'post_type' => array( 'page' ),
|
||||
)
|
||||
);
|
||||
|
||||
// Get first group.
|
||||
$posts = reset( $groups );
|
||||
|
||||
// Append to choices.
|
||||
if ( $posts ) {
|
||||
foreach ( $posts as $post ) {
|
||||
$choices[ $post->ID ] = acf_get_post_title( $post );
|
||||
}
|
||||
}
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
|
||||
// Register.
|
||||
acf_register_location_type( 'ACF_Location_Page' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Post_Category' ) ) :
|
||||
|
||||
class ACF_Location_Post_Category extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'post_category';
|
||||
$this->label = __( 'Post Category', 'acf' );
|
||||
$this->category = 'post';
|
||||
$this->object_type = 'post';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
return acf_get_location_type( 'post_taxonomy' )->match( $rule, $screen, $field_group );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
$choices = acf_get_taxonomy_terms( array( 'category' ) );
|
||||
if ( $choices ) {
|
||||
return reset( $choices );
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object_subtype connected to this location.
|
||||
*
|
||||
* @date 1/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return string|array
|
||||
*/
|
||||
public function get_object_subtype( $rule ) {
|
||||
return acf_get_location_type( 'post_taxonomy' )->get_object_subtype( $rule );
|
||||
}
|
||||
}
|
||||
|
||||
// initialize
|
||||
acf_register_location_rule( 'ACF_Location_Post_Category' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Post_Format' ) ) :
|
||||
|
||||
class ACF_Location_Post_Format extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'post_format';
|
||||
$this->label = __( 'Post Format', 'acf' );
|
||||
$this->category = 'post';
|
||||
$this->object_type = 'post';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
|
||||
// Check screen args.
|
||||
if ( isset( $screen['post_format'] ) ) {
|
||||
$post_format = $screen['post_format'];
|
||||
} elseif ( isset( $screen['post_id'] ) ) {
|
||||
$post_type = get_post_type( $screen['post_id'] );
|
||||
$post_format = get_post_format( $screen['post_id'] );
|
||||
|
||||
// Treat new posts (that support post-formats) without a saved format as "standard".
|
||||
if ( ! $post_format && post_type_supports( $post_type, 'post-formats' ) ) {
|
||||
$post_format = 'standard';
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compare rule against $post_format.
|
||||
return $this->compare_to_rule( $post_format, $rule );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
return get_post_format_strings();
|
||||
}
|
||||
}
|
||||
|
||||
// initialize
|
||||
acf_register_location_type( 'ACF_Location_Post_Format' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Post_Status' ) ) :
|
||||
|
||||
class ACF_Location_Post_Status extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'post_status';
|
||||
$this->label = __( 'Post Status', 'acf' );
|
||||
$this->category = 'post';
|
||||
$this->object_type = 'post';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
|
||||
// Check screen args.
|
||||
if ( isset( $screen['post_status'] ) ) {
|
||||
$post_status = $screen['post_status'];
|
||||
} elseif ( isset( $screen['post_id'] ) ) {
|
||||
$post_status = get_post_status( $screen['post_id'] );
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Treat "auto-draft" as "draft".
|
||||
if ( $post_status === 'auto-draft' ) {
|
||||
$post_status = 'draft';
|
||||
}
|
||||
|
||||
// Compare rule against $post_status.
|
||||
return $this->compare_to_rule( $post_status, $rule );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
global $wp_post_statuses;
|
||||
|
||||
// Append to choices.
|
||||
$choices = array();
|
||||
if ( $wp_post_statuses ) {
|
||||
foreach ( $wp_post_statuses as $status ) {
|
||||
$choices[ $status->name ] = $status->label;
|
||||
}
|
||||
}
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
|
||||
// initialize
|
||||
acf_register_location_type( 'ACF_Location_Post_Status' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Post_Taxonomy' ) ) :
|
||||
|
||||
class ACF_Location_Post_Taxonomy extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'post_taxonomy';
|
||||
$this->label = __( 'Post Taxonomy', 'acf' );
|
||||
$this->category = 'post';
|
||||
$this->object_type = 'post';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
|
||||
// Check screen args.
|
||||
if ( isset( $screen['post_id'] ) ) {
|
||||
$post_id = $screen['post_id'];
|
||||
} elseif ( isset( $screen['attachment_id'] ) ) {
|
||||
$post_id = $screen['attachment_id'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get WP_Term from rule value.
|
||||
$term = acf_get_term( $rule['value'] );
|
||||
if ( ! $term || is_wp_error( $term ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get terms connected to post.
|
||||
if ( isset( $screen['post_terms'] ) ) {
|
||||
$post_terms = acf_maybe_get( $screen['post_terms'], $term->taxonomy, array() );
|
||||
} else {
|
||||
$post_terms = wp_get_post_terms( $post_id, $term->taxonomy, array( 'fields' => 'ids' ) );
|
||||
}
|
||||
|
||||
// If no post terms are found, and we are dealing with the "category" taxonomy, treat as default "Uncategorized" category.
|
||||
if ( ! $post_terms && $term->taxonomy == 'category' ) {
|
||||
$post_terms = array( 1 );
|
||||
}
|
||||
|
||||
// Search $post_terms for a match.
|
||||
$result = ( in_array( $term->term_id, $post_terms ) || in_array( $term->slug, $post_terms ) );
|
||||
|
||||
// Reverse result for "!=" operator.
|
||||
if ( $rule['operator'] === '!=' ) {
|
||||
return ! $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
return acf_get_taxonomy_terms();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object_subtype connected to this location.
|
||||
*
|
||||
* @date 1/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return string|array
|
||||
*/
|
||||
public function get_object_subtype( $rule ) {
|
||||
if ( $rule['operator'] === '==' ) {
|
||||
$term = acf_decode_term( $rule['value'] );
|
||||
if ( $term ) {
|
||||
$taxonomy = get_taxonomy( $term['taxonomy'] );
|
||||
if ( $taxonomy ) {
|
||||
return $taxonomy->object_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// initialize
|
||||
acf_register_location_type( 'ACF_Location_Post_Taxonomy' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Post_Template' ) ) :
|
||||
|
||||
class ACF_Location_Post_Template extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'post_template';
|
||||
$this->label = __( 'Post Template', 'acf' );
|
||||
$this->category = 'post';
|
||||
$this->object_type = 'post';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
return array_merge(
|
||||
array(
|
||||
'default' => apply_filters( 'default_page_template_title', __( 'Default Template', 'acf' ), 'meta-box' ),
|
||||
),
|
||||
acf_get_post_templates()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object_subtype connected to this location.
|
||||
*
|
||||
* @date 1/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return string|array
|
||||
*/
|
||||
public function get_object_subtype( $rule ) {
|
||||
if ( $rule['operator'] === '==' ) {
|
||||
$post_templates = acf_get_post_templates();
|
||||
|
||||
// If "default", return array of all post types which have templates.
|
||||
if ( $rule['value'] === 'default' ) {
|
||||
return array_keys( $post_templates );
|
||||
|
||||
// Otherwise, generate list of post types that have the selected template.
|
||||
} else {
|
||||
$post_types = array();
|
||||
foreach ( $post_templates as $post_type => $templates ) {
|
||||
if ( isset( $templates[ $rule['value'] ] ) ) {
|
||||
$post_types[] = $post_type;
|
||||
}
|
||||
}
|
||||
return $post_types;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// initialize
|
||||
acf_register_location_type( 'ACF_Location_Post_Template' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Post_Type' ) ) :
|
||||
|
||||
class ACF_Location_Post_Type extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'post_type';
|
||||
$this->label = __( 'Post Type', 'acf' );
|
||||
$this->category = 'post';
|
||||
$this->object_type = 'post';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
// Compare rule against $post_type.
|
||||
return $this->compare_to_rule( $post_type, $rule );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
|
||||
// Get post types.
|
||||
$post_types = acf_get_post_types(
|
||||
array(
|
||||
'show_ui' => 1,
|
||||
'exclude' => array( 'attachment' ),
|
||||
)
|
||||
);
|
||||
|
||||
// Return array of [type => label].
|
||||
return acf_get_pretty_post_types( $post_types );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object_subtype connected to this location.
|
||||
*
|
||||
* @date 1/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return string|array
|
||||
*/
|
||||
public function get_object_subtype( $rule ) {
|
||||
if ( $rule['operator'] === '==' ) {
|
||||
return $rule['value'];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// initialize
|
||||
acf_register_location_type( 'ACF_Location_Post_Type' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Post' ) ) :
|
||||
|
||||
class ACF_Location_Post extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'post';
|
||||
$this->label = __( 'Post', 'acf' );
|
||||
$this->category = 'post';
|
||||
$this->object_type = 'post';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
|
||||
// Check screen args.
|
||||
if ( isset( $screen['post_id'] ) ) {
|
||||
$post_id = $screen['post_id'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compare rule against post_id.
|
||||
return $this->compare_to_rule( $post_id, $rule );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
$choices = array();
|
||||
|
||||
// Get post types.
|
||||
$post_types = acf_get_post_types(
|
||||
array(
|
||||
'show_ui' => 1,
|
||||
'exclude' => array( 'page', 'attachment' ),
|
||||
)
|
||||
);
|
||||
|
||||
// Get grouped posts.
|
||||
$groups = acf_get_grouped_posts(
|
||||
array(
|
||||
'post_type' => $post_types,
|
||||
)
|
||||
);
|
||||
|
||||
// Append to choices.
|
||||
if ( $groups ) {
|
||||
foreach ( $groups as $label => $posts ) {
|
||||
$choices[ $label ] = array();
|
||||
foreach ( $posts as $post ) {
|
||||
$choices[ $label ][ $post->ID ] = acf_get_post_title( $post );
|
||||
}
|
||||
}
|
||||
}
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
|
||||
// initialize
|
||||
acf_register_location_type( 'ACF_Location_Post' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Taxonomy' ) ) :
|
||||
|
||||
class ACF_Location_Taxonomy extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'taxonomy';
|
||||
$this->label = __( 'Taxonomy', 'acf' );
|
||||
$this->category = 'forms';
|
||||
$this->object_type = 'term';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
|
||||
// Check screen args.
|
||||
if ( isset( $screen['taxonomy'] ) ) {
|
||||
$taxonomy = $screen['taxonomy'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compare rule against $taxonomy.
|
||||
return $this->compare_to_rule( $taxonomy, $rule );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
return array_merge(
|
||||
array(
|
||||
'all' => __( 'All', 'acf' ),
|
||||
),
|
||||
acf_get_taxonomy_labels()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object_subtype connected to this location.
|
||||
*
|
||||
* @date 1/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return string|array
|
||||
*/
|
||||
function get_object_subtype( $rule ) {
|
||||
if ( $rule['operator'] === '==' ) {
|
||||
return $rule['value'];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// initialize
|
||||
acf_register_location_type( 'ACF_Location_Taxonomy' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_User_Form' ) ) :
|
||||
|
||||
class ACF_Location_User_Form extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'user_form';
|
||||
$this->label = __( 'User Form', 'acf' );
|
||||
$this->category = 'user';
|
||||
$this->object_type = 'user';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
// REST API has no forms, so we should always allow it.
|
||||
if ( ! empty( $screen['rest'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check screen args.
|
||||
if ( isset( $screen['user_form'] ) ) {
|
||||
$user_form = $screen['user_form'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The "Add / Edit" choice (foolishly valued "edit") should match true for either "add" or "edit".
|
||||
if ( $rule['value'] === 'edit' && $user_form === 'add' ) {
|
||||
$user_form = 'edit';
|
||||
}
|
||||
|
||||
// Compare rule against $user_form.
|
||||
return $this->compare_to_rule( $user_form, $rule );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
return array(
|
||||
'all' => __( 'All', 'acf' ),
|
||||
'add' => __( 'Add', 'acf' ),
|
||||
'edit' => __( 'Add / Edit', 'acf' ),
|
||||
'register' => __( 'Register', 'acf' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Register.
|
||||
acf_register_location_type( 'ACF_Location_User_Form' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_User_Role' ) ) :
|
||||
|
||||
class ACF_Location_User_Role extends ACF_Location {
|
||||
|
||||
/**
|
||||
* initialize
|
||||
*
|
||||
* Sets up the class functionality.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
function initialize() {
|
||||
$this->name = 'user_role';
|
||||
$this->label = __( 'User Role', 'acf' );
|
||||
$this->category = 'user';
|
||||
$this->object_type = 'user';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
|
||||
// Check screen args.
|
||||
if ( isset( $screen['user_role'] ) ) {
|
||||
$user_role = $screen['user_role'];
|
||||
} elseif ( isset( $screen['user_id'] ) ) {
|
||||
$user_id = $screen['user_id'];
|
||||
$user_role = '';
|
||||
|
||||
// Determine $user_role from $user_id.
|
||||
if ( $user_id === 'new' ) {
|
||||
$user_role = get_option( 'default_role' );
|
||||
|
||||
// Check if user can, and if so, set the value allowing them to match.
|
||||
} elseif ( user_can( $user_id, $rule['value'] ) ) {
|
||||
$user_role = $rule['value'];
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compare rule against $user_role.
|
||||
return $this->compare_to_rule( $user_role, $rule );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
global $wp_roles;
|
||||
return array_merge(
|
||||
array(
|
||||
'all' => __( 'All', 'acf' ),
|
||||
),
|
||||
$wp_roles->get_names()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// initialize
|
||||
acf_register_location_type( 'ACF_Location_User_Role' );
|
||||
endif; // class_exists check
|
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Widget' ) ) :
|
||||
|
||||
class ACF_Location_Widget extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'widget';
|
||||
$this->label = __( 'Widget', 'acf' );
|
||||
$this->category = 'forms';
|
||||
$this->object_type = 'widget';
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the provided rule against the screen args returning a bool result.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule The location rule.
|
||||
* @param array $screen The screen args.
|
||||
* @param array $field_group The field group settings.
|
||||
* @return bool
|
||||
*/
|
||||
public function match( $rule, $screen, $field_group ) {
|
||||
|
||||
// Check screen args.
|
||||
if ( isset( $screen['widget'] ) ) {
|
||||
$widget = $screen['widget'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compare rule against $widget.
|
||||
return $this->compare_to_rule( $widget, $rule );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible values for this rule type.
|
||||
*
|
||||
* @date 9/4/20
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $rule A location rule.
|
||||
* @return array
|
||||
*/
|
||||
public function get_values( $rule ) {
|
||||
global $wp_widget_factory;
|
||||
|
||||
// Populate choices.
|
||||
$choices = array(
|
||||
'all' => __( 'All', 'acf' ),
|
||||
);
|
||||
if ( $wp_widget_factory->widgets ) {
|
||||
foreach ( $wp_widget_factory->widgets as $widget ) {
|
||||
$choices[ $widget->id_base ] = $widget->name;
|
||||
}
|
||||
}
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
|
||||
// initialize
|
||||
acf_register_location_type( 'ACF_Location_Widget' );
|
||||
endif; // class_exists check
|
Reference in New Issue
Block a user