Sync plugins from current page

Signed-off-by: Adrian Nöthlich <git@promasu.tech>
This commit is contained in:
2019-09-11 19:08:46 +02:00
parent 85d41e4216
commit 8515ff9587
1847 changed files with 505469 additions and 0 deletions

View File

@@ -0,0 +1,127 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_attachment') ) :
class acf_location_attachment extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'attachment';
$this->label = __("Attachment",'acf');
$this->category = 'forms';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$attachment = acf_maybe_get( $screen, 'attachment' );
// validate
if( !$attachment ) return false;
// get attachment mime type
$mime_type = get_post_mime_type( $attachment );
// no specific mime
if( !strpos($rule['value'], '/') ) {
// explode into [0] => type, [1] => mime
$bits = explode('/', $mime_type);
// if type matches, fake the $mime_type to match
if( $rule['value'] === $bits[0] ) {
$mime_type = $rule['value'];
}
}
// match
return $this->compare( $mime_type, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// vars
$mimes = get_allowed_mime_types();
$choices = array(
'all' => __('All', 'acf')
);
// loop
foreach( $mimes as $type => $mime ) {
$group = current( explode('/', $mime) );
$choices[ $group ][ $group ] = sprintf( __('All %s formats', 'acf'), $group);
$choices[ $group ][ $mime ] = "$type ($mime)";
}
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_attachment' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,95 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_comment') ) :
class acf_location_comment extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'comment';
$this->label = __("Comment",'acf');
$this->category = 'forms';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$comment = acf_maybe_get( $screen, 'comment' );
// bail early if not comment
if( !$comment ) return false;
// return
return $this->compare( $comment, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// vars
$choices = array( 'all' => __('All', 'acf') );
$choices = array_merge( $choices, acf_get_pretty_post_types() );
// change this to post types that support comments
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_comment' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,128 @@
<?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 {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'current_user_role';
$this->label = __("Current User Role",'acf');
$this->category = 'user';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// bail early if not logged in
if( !is_user_logged_in() ) return false;
// vars
$user = wp_get_current_user();
// super_admin
if( $rule['value'] == 'super_admin' ) {
$result = is_super_admin( $user->ID );
// role
} else {
$result = in_array( $rule['value'], $user->roles );
}
// reverse if 'not equal to'
if( $rule['operator'] == '!=' ) {
$result = !$result;
}
// return
return $result;
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// global
global $wp_roles;
// specific roles
$choices = $wp_roles->get_names();
// multi-site
if( is_multisite() ) {
$prepend = array( 'super_admin' => __('Super Admin', 'acf') );
$choices = array_merge( $prepend, $choices );
}
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_current_user_role' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,111 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_current_user') ) :
class acf_location_current_user extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'current_user';
$this->label = __("Current User",'acf');
$this->category = 'user';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// logged in
if( $rule['value'] == 'logged_in' ) {
$result = is_user_logged_in();
// viewing_front
} elseif( $rule['value'] == 'viewing_front' ) {
$result = !is_admin();
// viewing_back
} elseif( $rule['value'] == 'viewing_back' ) {
$result = is_admin();
}
// reverse if 'not equal to'
if( $rule['operator'] == '!=' ) {
$result = !$result;
}
// return
return $result;
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
return array(
'logged_in' => __('Logged in', 'acf'),
'viewing_front' => __('Viewing front end', 'acf'),
'viewing_back' => __('Viewing back end', 'acf')
);
}
}
// initialize
acf_register_location_rule( 'acf_location_current_user' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,104 @@
<?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 {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'nav_menu_item';
$this->label = __("Menu Item",'acf');
$this->category = 'forms';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$nav_menu_item = acf_maybe_get( $screen, 'nav_menu_item' );
// bail early if not nav_menu_item
if( !$nav_menu_item ) return false;
// append nav_menu data
if( !isset($screen['nav_menu']) ) {
$screen['nav_menu'] = acf_get_data('nav_menu_id');
}
// return
return acf_get_location_rule('nav_menu')->rule_match( $result, $rule, $screen );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// get menu choices
$choices = acf_get_location_rule('nav_menu')->rule_values( $choices, $rule );
// append item types?
// dificult to get these details
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_nav_menu_item' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,138 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_nav_menu') ) :
class acf_location_nav_menu extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'nav_menu';
$this->label = __("Menu",'acf');
$this->category = 'forms';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$nav_menu = acf_maybe_get( $screen, 'nav_menu' );
// bail early if not nav_menu
if( !$nav_menu ) return false;
// location
if( substr($rule['value'], 0, 9) === 'location/' ) {
// vars
$location = substr($rule['value'], 9);
$menu_locations = get_nav_menu_locations();
// bail ealry if no location
if( !isset($menu_locations[$location]) ) return false;
// if location matches, update value
if( $menu_locations[$location] == $nav_menu ) {
$nav_menu = $rule['value'];
}
}
// return
return $this->compare( $nav_menu, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// all
$choices = array(
'all' => __('All', 'acf'),
);
// locations
$nav_locations = get_registered_nav_menus();
if( !empty($nav_locations) ) {
$cat = __('Menu Locations', 'acf');
foreach( $nav_locations as $slug => $title ) {
$choices[ $cat ][ 'location/'.$slug ] = $title;
}
}
// specific menus
$nav_menus = wp_get_nav_menus();
if( !empty($nav_menus) ) {
$cat = __('Menus', 'acf');
foreach( $nav_menus as $nav_menu ) {
$choices[ $cat ][ $nav_menu->term_id ] = $nav_menu->name;
}
}
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_nav_menu' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,100 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_page_parent') ) :
class acf_location_page_parent extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'page_parent';
$this->label = __("Page Parent",'acf');
$this->category = 'page';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$post_id = acf_maybe_get( $screen, 'post_id' );
$page_parent = acf_maybe_get( $screen, 'page_parent' );
// no page parent
if( $page_parent === null ) {
// bail early if no post id
if( !$post_id ) return false;
// get post parent
$post = get_post( $post_id );
$page_parent = $post->post_parent;
}
// compare
return $this->compare( $page_parent, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
return acf_get_location_rule('page')->rule_values( $choices, $rule );
}
}
// initialize
acf_register_location_rule( 'acf_location_page_parent' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,107 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_page_template') ) :
class acf_location_page_template extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'page_template';
$this->label = __("Page Template",'acf');
$this->category = 'page';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// Check if this rule is relevant to the current screen.
// Find $post_id in the process.
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;
}
// If this rule is set to "default" template, avoid matching on non "page" post types.
// Fixes issue where post templates were added in WP 4.7 and field groups appeared on all post type edit screens.
if( $rule['value'] === 'default' && $post_type !== 'page' ) {
return false;
}
// Return.
return acf_get_location_rule('post_template')->rule_match( $result, $rule, $screen );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// Default choices.
$choices = array(
'default' => apply_filters( 'default_page_template_title', __('Default Template', 'acf') )
);
// Load all templates, and merge in 'page' templates.
$post_templates = acf_get_post_templates();
if( isset($post_templates['page']) ) {
$choices = array_merge($choices, $post_templates['page']);
}
// Return choices.
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_page_template' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,162 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_page_type') ) :
class acf_location_page_type extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'page_type';
$this->label = __("Page Type",'acf');
$this->category = 'page';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$post_id = acf_maybe_get( $screen, 'post_id' );
// bail early if no post id
if( !$post_id ) return false;
// get post
$post = get_post( $post_id );
// bail early if no post
if( !$post ) return false;
// compare
if( $rule['value'] == 'front_page') {
// vars
$front_page = (int) get_option('page_on_front');
// compare
$result = ( $front_page === $post->ID );
} elseif( $rule['value'] == 'posts_page') {
// vars
$posts_page = (int) get_option('page_for_posts');
// compare
$result = ( $posts_page === $post->ID );
} elseif( $rule['value'] == 'top_level') {
// vars
$page_parent = acf_maybe_get( $screen, 'page_parent', $post->post_parent );
// compare
$result = ( $page_parent == 0 );
} elseif( $rule['value'] == 'parent' ) {
// get children
$children = get_posts(array(
'post_type' => $post->post_type,
'post_parent' => $post->ID,
'posts_per_page' => 1,
'fields' => 'ids',
));
// compare
$result = !empty( $children );
} elseif( $rule['value'] == 'child') {
// vars
$page_parent = acf_maybe_get( $screen, 'page_parent', $post->post_parent );
// compare
$result = ( $page_parent > 0 );
}
// reverse if 'not equal to'
if( $rule['operator'] == '!=' ) {
$result = !$result;
}
// return
return $result;
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $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_rule( 'acf_location_page_type' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,99 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_page') ) :
class acf_location_page extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'page';
$this->label = __("Page",'acf');
$this->category = 'page';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
return acf_get_location_rule('post')->rule_match( $result, $rule, $screen );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// get posts grouped by post type
$groups = acf_get_grouped_posts(array(
'post_type' => 'page'
));
// pop
$choices = array_pop( $groups );
// convert posts to titles
foreach( $choices as &$item ) {
$item = acf_get_post_title( $item );
}
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_page' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,88 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_post_category') ) :
class acf_location_post_category extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'post_category';
$this->label = __("Post Category",'acf');
$this->category = 'post';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
return acf_get_location_rule('post_taxonomy')->rule_match( $result, $rule, $screen );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
$terms = acf_get_taxonomy_terms( 'category' );
if( !empty($terms) ) {
$choices = array_pop($terms);
}
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_post_category' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,143 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_post_format') ) :
class acf_location_post_format extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'post_format';
$this->label = __("Post Format",'acf');
$this->category = 'post';
}
/*
* get_post_type
*
* This function will return the current post_type
*
* @type function
* @date 25/11/16
* @since 5.5.0
*
* @param $options (int)
* @return (mixed)
*/
function get_post_type( $screen ) {
// vars
$post_id = acf_maybe_get( $screen, 'post_id' );
$post_type = acf_maybe_get( $screen, 'post_type' );
// post_type
if( $post_type ) return $post_type;
// $post_id
if( $post_id ) return get_post_type( $post_id );
// return
return false;
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$post_format = acf_maybe_get( $screen, 'post_format' );
// find post format
if( !$post_format ) {
// get post id
$post_id = acf_maybe_get( $screen, 'post_id' );
$post_type = $this->get_post_type( $screen );
// bail early if not a post
if( !$post_id || !$post_type ) return false;
// does post_type support 'post-format'
if( post_type_supports($post_type, 'post-formats') ) {
// update
$post_format = get_post_format($post_id);
$post_format = $post_format ? $post_format : 'standard';
}
}
// compare
return $this->compare( $post_format, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
return get_post_format_strings();
}
}
// initialize
acf_register_location_rule( 'acf_location_post_format' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,161 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_post_status') ) :
class acf_location_post_status extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'post_status';
$this->label = __("Post Status",'acf');
$this->category = 'post';
}
/*
* get_post_type
*
* This function will return the current post_type
*
* @type function
* @date 25/11/16
* @since 5.5.0
*
* @param $options (int)
* @return (mixed)
*/
function get_post_type( $screen ) {
// vars
$post_id = acf_maybe_get( $screen, 'post_id' );
$post_type = acf_maybe_get( $screen, 'post_type' );
// post_type
if( $post_type ) return $post_type;
// $post_id
if( $post_id ) return get_post_type( $post_id );
// return
return false;
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$post_status = acf_maybe_get( $screen, 'post_status' );
// find post format
if( !$post_status ) {
// get post id
$post_id = acf_maybe_get( $screen, 'post_id' );
// bail early if not a post
if( !$post_id ) return false;
// update
$post_status = get_post_status( $post_id );
}
// auto-draft = draft
if( $post_status == 'auto-draft' ) {
$post_status = 'draft';
}
// match
return $this->compare( $post_status, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// globals
global $wp_post_statuses;
// append
if( !empty($wp_post_statuses) ) {
foreach( $wp_post_statuses as $status ) {
$choices[ $status->name ] = $status->label;
}
}
// return choices
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_post_status' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,130 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_post_taxonomy') ) :
class acf_location_post_taxonomy extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'post_taxonomy';
$this->label = __("Post Taxonomy",'acf');
$this->category = 'post';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$post_id = acf_maybe_get( $screen, 'post_id' );
$post_terms = acf_maybe_get( $screen, 'post_terms' );
// bail early if not a post
if( !$post_id ) return false;
// get selected term from rule
$term = acf_get_term( $rule['value'] );
// bail early if no term
if( !$term || is_wp_error($term) ) return false;
// if ajax, find the terms for the correct category
if( $post_terms !== null ) {
$post_terms = acf_maybe_get( $post_terms, $term->taxonomy, array() );
// if not ajax, load post's terms
} else {
$post_terms = wp_get_post_terms( $post_id, $term->taxonomy, array('fields' => 'ids') );
}
// If no terms, this is a new post and should be treated as if it has the "Uncategorized" (1) category ticked
if( !$post_terms && $term->taxonomy == 'category' ) {
$post_terms = array( 1 );
}
// compare term IDs and slugs
if( in_array($term->term_id, $post_terms) || in_array($term->slug, $post_terms) ) {
$result = true;
}
// reverse if 'not equal to'
if( $rule['operator'] == '!=' ) {
$result = !$result;
}
// return
return $result;
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// get
$choices = acf_get_taxonomy_terms();
// unset post_format
if( isset($choices['post_format']) ) {
unset( $choices['post_format']) ;
}
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_post_taxonomy' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,152 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_post_template') ) :
class acf_location_post_template extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'post_template';
$this->label = __("Post Template",'acf');
$this->category = 'post';
$this->public = acf_version_compare('wp', '>=', '4.7');
}
/*
* get_post_type
*
* This function will return the current post_type
*
* @type function
* @date 25/11/16
* @since 5.5.0
*
* @param $options (int)
* @return (mixed)
*/
function get_post_type( $screen ) {
// vars
$post_id = acf_maybe_get( $screen, 'post_id' );
$post_type = acf_maybe_get( $screen, 'post_type' );
// post_type
if( $post_type ) return $post_type;
// $post_id
if( $post_id ) return get_post_type( $post_id );
// return
return false;
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// Check if this rule is relevant to the current screen.
// Find $post_id in the process.
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.
$page_template = acf_maybe_get( $screen, 'page_template' );
$post_id = acf_maybe_get( $screen, 'post_id' );
if( $page_template === null ) {
$page_template = get_post_meta( $post_id, '_wp_page_template', true );
}
// Treat empty value as default template.
if( $page_template === '' ) {
$page_template = 'default';
}
// Compare.
return $this->compare( $page_template, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// Default choices.
$choices = array(
'default' => apply_filters( 'default_page_template_title', __('Default Template', 'acf') )
);
// Merge in all post templates.
$post_templates = acf_get_post_templates();
$choices = array_merge($choices, $post_templates);
// Return choices.
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_post_template' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,132 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_post_type') ) :
class acf_location_post_type extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'post_type';
$this->label = __("Post Type",'acf');
$this->category = 'post';
}
/*
* get_post_type
*
* This function will return the current post_type
*
* @type function
* @date 25/11/16
* @since 5.5.0
*
* @param $options (int)
* @return (mixed)
*/
function get_post_type( $screen ) {
// vars
$post_id = acf_maybe_get( $screen, 'post_id' );
$post_type = acf_maybe_get( $screen, 'post_type' );
// post_type
if( $post_type ) return $post_type;
// $post_id
if( $post_id ) return get_post_type( $post_id );
// return
return false;
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$post_type = $this->get_post_type( $screen );
// bail early if no post_type found (not a post)
if( !$post_type ) return false;
// match
return $this->compare( $post_type, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// get post types
// - removed show_ui to allow 3rd party code to register a post type using a custom admin edit page
$post_types = acf_get_post_types(array(
'show_ui' => 1,
'exclude' => array('attachment')
));
// return choices
return acf_get_pretty_post_types( $post_types );
}
}
// initialize
acf_register_location_rule( 'acf_location_post_type' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,128 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_post') ) :
class acf_location_post extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'post';
$this->label = __("Post",'acf');
$this->category = 'post';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$post_id = acf_maybe_get( $screen, 'post_id' );
// bail early if not post
if( !$post_id ) return false;
// compare
return $this->compare( $post_id, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// get post types
$post_types = acf_get_post_types(array(
'show_ui' => 1,
'exclude' => array('page', 'attachment')
));
// get posts grouped by post type
$groups = acf_get_grouped_posts(array(
'post_type' => $post_types
));
if( !empty($groups) ) {
foreach( array_keys($groups) as $group_title ) {
// vars
$posts = acf_extract_var( $groups, $group_title );
// override post data
foreach( array_keys($posts) as $post_id ) {
// update
$posts[ $post_id ] = acf_get_post_title( $posts[ $post_id ] );
};
// append to $choices
$choices[ $group_title ] = $posts;
}
}
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_post' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,95 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_taxonomy') ) :
class acf_location_taxonomy extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'taxonomy';
$this->label = __("Taxonomy",'acf');
$this->category = 'forms';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$taxonomy = acf_maybe_get( $screen, 'taxonomy' );
// bail early if not taxonomy
if( !$taxonomy ) return false;
// return
return $this->compare( $taxonomy, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// vars
$choices = array( 'all' => __('All', 'acf') );
$choices = array_merge( $choices, acf_get_taxonomy_labels() );
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_taxonomy' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,116 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_user_form') ) :
class acf_location_user_form extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'user_form';
$this->label = __("User Form",'acf');
$this->category = 'user';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$user_form = acf_maybe_get( $screen, 'user_form' );
// bail early if no user form
if( !$user_form ) return false;
// add is treated the same as edit
if( $user_form === 'add' ) {
$user_form = 'edit';
}
// match
return $this->compare( $user_form, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
return array(
'all' => __('All', 'acf'),
'edit' => __('Add / Edit', 'acf'),
'register' => __('Register', 'acf')
);
/*
// global
global $wp_roles;
// vars
$choices = array( 'all' => __('All', 'acf') );
$choices = array_merge( $choices, $wp_roles->get_names() );
// return
return $choices;
*/
}
}
// initialize
acf_register_location_rule( 'acf_location_user_form' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,127 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_user_role') ) :
class acf_location_user_role extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'user_role';
$this->label = __("User Role",'acf');
$this->category = 'user';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$user_id = acf_maybe_get( $screen, 'user_id' );
$user_role = acf_maybe_get( $screen, 'user_role' );
// if user_role is supplied (3rd party compatibility)
if( $user_role ) {
// do nothing
// user_id (expected)
} elseif( $user_id ) {
// new user
if( $user_id == 'new' ) {
// set to default role
$user_role = get_option('default_role');
// existing user
} elseif( user_can($user_id, $rule['value']) ) {
// set to value and allow match
$user_role = $rule['value'];
}
// else
} else {
// not a user
return false;
}
// match
return $this->compare( $user_role, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// global
global $wp_roles;
// vars
$choices = array( 'all' => __('All', 'acf') );
$choices = array_merge( $choices, $wp_roles->get_names() );
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_user_role' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,110 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location_widget') ) :
class acf_location_widget extends acf_location {
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function initialize() {
// vars
$this->name = 'widget';
$this->label = __("Widget",'acf');
$this->category = 'forms';
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
function rule_match( $result, $rule, $screen ) {
// vars
$widget = acf_maybe_get( $screen, 'widget' );
// bail early if not widget
if( !$widget ) return false;
// return
return $this->compare( $widget, $rule );
}
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
function rule_values( $choices, $rule ) {
// global
global $wp_widget_factory;
// vars
$choices = array( 'all' => __('All', 'acf') );
// loop
if( !empty( $wp_widget_factory->widgets ) ) {
foreach( $wp_widget_factory->widgets as $widget ) {
$choices[ $widget->id_base ] = $widget->name;
}
}
// return
return $choices;
}
}
// initialize
acf_register_location_rule( 'acf_location_widget' );
endif; // class_exists check
?>

View File

@@ -0,0 +1,263 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('acf_location') ) :
class acf_location {
/** @var string Rule name */
var $name = '';
/** @var string Rule label */
var $label = '';
/** @var string Rule category */
var $category = 'post';
/** @var bool Rule availability */
var $public = true;
/*
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
function __construct() {
// initialize
$this->initialize();
// filters
$this->add_filter('acf/location/rule_match', true, array($this, 'rule_match'), 5, 3);
$this->add_filter('acf/location/rule_operators', true, array($this, 'rule_operators'), 5, 2);
$this->add_filter('acf/location/rule_values', true, array($this, 'rule_values'), 5, 2);
}
/*
* initialize
*
* This function will initialize the location rule
*
* @type function
* @date 27/6/17
* @since 5.6.0
*
* @param n/a
* @return n/a
*/
function initialize() {
/* do nothing */
}
/*
* add_filter
*
* This function checks if the function is_callable before adding the filter
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param $tag (string)
* @param $function_to_add (string)
* @param $priority (int)
* @param $accepted_args (int)
* @return n/a
*/
function add_filter( $tag = '', $specific = false, $function_to_add = '', $priority = 10, $accepted_args = 1 ) {
// specific
if( $specific ) {
$tag .= '/' . $this->name;
}
// add
if( is_callable($function_to_add) ) {
add_filter( $tag, $function_to_add, $priority, $accepted_args );
}
}
/*
* add_action
*
* This function checks if the function is_callable before adding the action
*
* @type function
* @date 5/03/2014
* @since 5.0.0
*
* @param $tag (string)
* @param $function_to_add (string)
* @param $priority (int)
* @param $accepted_args (int)
* @return n/a
*/
function add_action( $tag = '', $specific = false, $function_to_add = '', $priority = 10, $accepted_args = 1 ) {
// specific
if( $specific ) {
$tag .= '/' . $this->name;
}
// add
if( is_callable($function_to_add) ) {
add_action( $tag, $function_to_add, $priority, $accepted_args );
}
}
/*
* compare
*
* This function will compare a value to a location rule and return a boolean result
*
* @type function
* @date 25/11/16
* @since 5.5.0
*
* @param $value (mixed)
* @param rule (array)
* @return (boolean)
*/
function compare( $value, $rule ) {
// match
$match = ( $value == $rule['value'] );
// override for "all"
if( $rule['value'] == 'all' ) $match = true;
// reverse if 'not equal to'
if( $rule['operator'] == '!=' ) {
$match = !$match;
}
// return
return $match;
}
/*
* rule_match
*
* This function is used to match this location $rule to the current $screen
*
* @type function
* @date 3/01/13
* @since 3.5.7
*
* @param $match (boolean)
* @param $rule (array)
* @return $options (array)
*/
/*
function rule_match( $result, $rule, $screen ) {
return $result;
}
*/
/*
* rule_operators
*
* This function returns the available operators for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
/*
function rule_operators( $operators, $rule ) {
return $operators;
}
*/
/*
* rule_operators
*
* This function returns the available values for this rule type
*
* @type function
* @date 30/5/17
* @since 5.6.0
*
* @param n/a
* @return (array)
*/
/*
function rule_values( $values, $rule ) {
return $values;
}
*/
/*
function rule_listeners() {
// js
}
*/
}
endif; // class_exists check
?>