initial commit
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'acf_pro' ) ) :
|
||||
|
||||
class acf_pro {
|
||||
|
||||
/*
|
||||
* __construct
|
||||
*
|
||||
*
|
||||
*
|
||||
* @type function
|
||||
* @date 23/06/12
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param N/A
|
||||
* @return N/A
|
||||
*/
|
||||
|
||||
function __construct() {
|
||||
|
||||
// constants
|
||||
acf()->define( 'ACF_PRO', true );
|
||||
|
||||
// update setting
|
||||
acf_update_setting( 'pro', true );
|
||||
acf_update_setting( 'name', __( 'Advanced Custom Fields PRO', 'acf' ) );
|
||||
|
||||
// includes
|
||||
acf_include( 'pro/blocks.php' );
|
||||
acf_include( 'pro/options-page.php' );
|
||||
acf_include( 'pro/updates.php' );
|
||||
|
||||
if ( is_admin() ) {
|
||||
|
||||
acf_include( 'pro/admin/admin-options-page.php' );
|
||||
acf_include( 'pro/admin/admin-updates.php' );
|
||||
|
||||
}
|
||||
|
||||
// actions
|
||||
add_action( 'init', array( $this, 'register_assets' ) );
|
||||
add_action( 'acf/include_field_types', array( $this, 'include_field_types' ), 5 );
|
||||
add_action( 'acf/include_location_rules', array( $this, 'include_location_rules' ), 5 );
|
||||
add_action( 'acf/input/admin_enqueue_scripts', array( $this, 'input_admin_enqueue_scripts' ) );
|
||||
add_action( 'acf/field_group/admin_enqueue_scripts', array( $this, 'field_group_admin_enqueue_scripts' ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* include_field_types
|
||||
*
|
||||
* description
|
||||
*
|
||||
* @type function
|
||||
* @date 21/10/2015
|
||||
* @since 5.2.3
|
||||
*
|
||||
* @param $post_id (int)
|
||||
* @return $post_id (int)
|
||||
*/
|
||||
|
||||
function include_field_types() {
|
||||
|
||||
acf_include( 'pro/fields/class-acf-field-repeater.php' );
|
||||
acf_include( 'pro/fields/class-acf-field-flexible-content.php' );
|
||||
acf_include( 'pro/fields/class-acf-field-gallery.php' );
|
||||
acf_include( 'pro/fields/class-acf-field-clone.php' );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* include_location_rules
|
||||
*
|
||||
* description
|
||||
*
|
||||
* @type function
|
||||
* @date 10/6/17
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @param $post_id (int)
|
||||
* @return $post_id (int)
|
||||
*/
|
||||
|
||||
function include_location_rules() {
|
||||
|
||||
acf_include( 'pro/locations/class-acf-location-block.php' );
|
||||
acf_include( 'pro/locations/class-acf-location-options-page.php' );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* register_assets
|
||||
*
|
||||
* description
|
||||
*
|
||||
* @type function
|
||||
* @date 4/11/2013
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param $post_id (int)
|
||||
* @return $post_id (int)
|
||||
*/
|
||||
|
||||
function register_assets() {
|
||||
|
||||
// vars
|
||||
$version = acf_get_setting( 'version' );
|
||||
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
||||
|
||||
// register scripts
|
||||
wp_register_script( 'acf-pro-input', acf_get_url( "assets/build/js/pro/acf-pro-input{$min}.js" ), array( 'acf-input' ), $version );
|
||||
wp_register_script( 'acf-pro-field-group', acf_get_url( "assets/build/js/pro/acf-pro-field-group{$min}.js" ), array( 'acf-field-group' ), $version );
|
||||
|
||||
// register styles
|
||||
wp_register_style( 'acf-pro-input', acf_get_url( 'assets/build/css/pro/acf-pro-input.css' ), array( 'acf-input' ), $version );
|
||||
wp_register_style( 'acf-pro-field-group', acf_get_url( 'assets/build/css/pro/acf-pro-field-group.css' ), array( 'acf-input' ), $version );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* input_admin_enqueue_scripts
|
||||
*
|
||||
* description
|
||||
*
|
||||
* @type function
|
||||
* @date 4/11/2013
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param $post_id (int)
|
||||
* @return $post_id (int)
|
||||
*/
|
||||
|
||||
function input_admin_enqueue_scripts() {
|
||||
|
||||
wp_enqueue_script( 'acf-pro-input' );
|
||||
wp_enqueue_style( 'acf-pro-input' );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* field_group_admin_enqueue_scripts
|
||||
*
|
||||
* description
|
||||
*
|
||||
* @type function
|
||||
* @date 4/11/2013
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param $post_id (int)
|
||||
* @return $post_id (int)
|
||||
*/
|
||||
|
||||
function field_group_admin_enqueue_scripts() {
|
||||
|
||||
wp_enqueue_script( 'acf-pro-field-group' );
|
||||
wp_enqueue_style( 'acf-pro-field-group' );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// instantiate
|
||||
new acf_pro();
|
||||
|
||||
|
||||
// end class
|
||||
endif;
|
||||
|
||||
|
@@ -0,0 +1,368 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'acf_admin_options_page' ) ) :
|
||||
|
||||
class acf_admin_options_page {
|
||||
|
||||
/** @var array Contains the current options page */
|
||||
var $page;
|
||||
|
||||
|
||||
/*
|
||||
* __construct
|
||||
*
|
||||
* Initialize filters, action, variables and includes
|
||||
*
|
||||
* @type function
|
||||
* @date 23/06/12
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param n/a
|
||||
* @return n/a
|
||||
*/
|
||||
|
||||
function __construct() {
|
||||
|
||||
// add menu items
|
||||
add_action( 'admin_menu', array( $this, 'admin_menu' ), 99, 0 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* admin_menu
|
||||
*
|
||||
* description
|
||||
*
|
||||
* @type function
|
||||
* @date 24/02/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
|
||||
function admin_menu() {
|
||||
|
||||
// vars
|
||||
$pages = acf_get_options_pages();
|
||||
|
||||
// bail early if no pages
|
||||
if ( empty( $pages ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// loop
|
||||
foreach ( $pages as $page ) {
|
||||
|
||||
// vars
|
||||
$slug = '';
|
||||
|
||||
// parent
|
||||
if ( empty( $page['parent_slug'] ) ) {
|
||||
|
||||
$slug = add_menu_page( $page['page_title'], $page['menu_title'], $page['capability'], $page['menu_slug'], array( $this, 'html' ), $page['icon_url'], $page['position'] );
|
||||
|
||||
// child
|
||||
} else {
|
||||
|
||||
$slug = add_submenu_page( $page['parent_slug'], $page['page_title'], $page['menu_title'], $page['capability'], $page['menu_slug'], array( $this, 'html' ), $page['position'] );
|
||||
|
||||
}
|
||||
|
||||
// actions
|
||||
add_action( "load-{$slug}", array( $this, 'admin_load' ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* load
|
||||
*
|
||||
* description
|
||||
*
|
||||
* @type function
|
||||
* @date 2/02/13
|
||||
* @since 3.6
|
||||
*
|
||||
* @param $post_id (int)
|
||||
* @return $post_id (int)
|
||||
*/
|
||||
|
||||
function admin_load() {
|
||||
|
||||
// globals
|
||||
global $plugin_page;
|
||||
|
||||
// vars
|
||||
$this->page = acf_get_options_page( $plugin_page );
|
||||
|
||||
// get post_id (allow lang modification)
|
||||
$this->page['post_id'] = acf_get_valid_post_id( $this->page['post_id'] );
|
||||
|
||||
// verify and remove nonce
|
||||
if ( acf_verify_nonce( 'options' ) ) {
|
||||
|
||||
// save data
|
||||
if ( acf_validate_save_post( true ) ) {
|
||||
|
||||
// set autoload
|
||||
acf_update_setting( 'autoload', $this->page['autoload'] );
|
||||
|
||||
// save
|
||||
acf_save_post( $this->page['post_id'] );
|
||||
|
||||
// redirect
|
||||
wp_redirect( add_query_arg( array( 'message' => '1' ) ) );
|
||||
exit;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// load acf scripts
|
||||
acf_enqueue_scripts();
|
||||
|
||||
// actions
|
||||
add_action( 'acf/input/admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
||||
add_action( 'acf/input/admin_head', array( $this, 'admin_head' ) );
|
||||
|
||||
// add columns support
|
||||
add_screen_option(
|
||||
'layout_columns',
|
||||
array(
|
||||
'max' => 2,
|
||||
'default' => 2,
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* admin_enqueue_scripts
|
||||
*
|
||||
* This function will enqueue the 'post.js' script which adds support for 'Screen Options' column toggle
|
||||
*
|
||||
* @type function
|
||||
* @date 23/03/2016
|
||||
* @since 5.3.2
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
|
||||
function admin_enqueue_scripts() {
|
||||
|
||||
wp_enqueue_script( 'post' );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* admin_head
|
||||
*
|
||||
* This action will find and add field groups to the current edit page
|
||||
*
|
||||
* @type action (admin_head)
|
||||
* @date 23/06/12
|
||||
* @since 3.1.8
|
||||
*
|
||||
* @param n/a
|
||||
* @return n/a
|
||||
*/
|
||||
|
||||
function admin_head() {
|
||||
|
||||
// get field groups
|
||||
$field_groups = acf_get_field_groups(
|
||||
array(
|
||||
'options_page' => $this->page['menu_slug'],
|
||||
)
|
||||
);
|
||||
|
||||
// notices
|
||||
if ( ! empty( $_GET['message'] ) && $_GET['message'] == '1' ) {
|
||||
acf_add_admin_notice( $this->page['updated_message'], 'success' );
|
||||
}
|
||||
|
||||
// add submit div
|
||||
add_meta_box( 'submitdiv', __( 'Publish', 'acf' ), array( $this, 'postbox_submitdiv' ), 'acf_options_page', 'side', 'high' );
|
||||
|
||||
if ( empty( $field_groups ) ) {
|
||||
|
||||
acf_add_admin_notice( sprintf( __( 'No Custom Field Groups found for this options page. <a href="%s">Create a Custom Field Group</a>', 'acf' ), admin_url( 'post-new.php?post_type=acf-field-group' ) ), 'warning' );
|
||||
|
||||
} else {
|
||||
|
||||
foreach ( $field_groups as $i => $field_group ) {
|
||||
|
||||
// vars
|
||||
$id = "acf-{$field_group['key']}";
|
||||
$title = $field_group['title'];
|
||||
$context = $field_group['position'];
|
||||
$priority = 'high';
|
||||
$args = array( 'field_group' => $field_group );
|
||||
|
||||
// tweaks to vars
|
||||
if ( $context == 'acf_after_title' ) {
|
||||
|
||||
$context = 'normal';
|
||||
|
||||
} elseif ( $context == 'side' ) {
|
||||
|
||||
$priority = 'core';
|
||||
|
||||
}
|
||||
|
||||
// filter for 3rd party customization
|
||||
$priority = apply_filters( 'acf/input/meta_box_priority', $priority, $field_group );
|
||||
|
||||
// add meta box
|
||||
add_meta_box( $id, acf_esc_html( $title ), array( $this, 'postbox_acf' ), 'acf_options_page', $context, $priority, $args );
|
||||
|
||||
}
|
||||
// foreach
|
||||
|
||||
}
|
||||
// if
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* postbox_submitdiv
|
||||
*
|
||||
* This function will render the submitdiv metabox
|
||||
*
|
||||
* @type function
|
||||
* @date 23/03/2016
|
||||
* @since 5.3.2
|
||||
*
|
||||
* @param n/a
|
||||
* @return n/a
|
||||
*/
|
||||
|
||||
function postbox_submitdiv( $post, $args ) {
|
||||
|
||||
/**
|
||||
* Fires before the major-publishing-actions div.
|
||||
*
|
||||
* @date 24/9/18
|
||||
* @since 5.7.7
|
||||
*
|
||||
* @param array $page The current options page.
|
||||
*/
|
||||
do_action( 'acf/options_page/submitbox_before_major_actions', $this->page );
|
||||
?>
|
||||
<div id="major-publishing-actions">
|
||||
|
||||
<div id="publishing-action">
|
||||
<span class="spinner"></span>
|
||||
<input type="submit" accesskey="p" value="<?php echo $this->page['update_button']; ?>" class="button button-primary button-large" id="publish" name="publish">
|
||||
</div>
|
||||
|
||||
<?php
|
||||
/**
|
||||
* Fires before the major-publishing-actions div.
|
||||
*
|
||||
* @date 24/9/18
|
||||
* @since 5.7.7
|
||||
*
|
||||
* @param array $page The current options page.
|
||||
*/
|
||||
do_action( 'acf/options_page/submitbox_major_actions', $this->page );
|
||||
?>
|
||||
<div class="clear"></div>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* render_meta_box
|
||||
*
|
||||
* description
|
||||
*
|
||||
* @type function
|
||||
* @date 24/02/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param $post (object)
|
||||
* @param $args (array)
|
||||
* @return n/a
|
||||
*/
|
||||
|
||||
function postbox_acf( $post, $args ) {
|
||||
|
||||
// extract args
|
||||
extract( $args ); // all variables from the add_meta_box function
|
||||
extract( $args ); // all variables from the args argument
|
||||
|
||||
// vars
|
||||
$o = array(
|
||||
'id' => $id,
|
||||
'key' => $field_group['key'],
|
||||
'style' => $field_group['style'],
|
||||
'label' => $field_group['label_placement'],
|
||||
'editLink' => '',
|
||||
'editTitle' => __( 'Edit field group', 'acf' ),
|
||||
'visibility' => true,
|
||||
);
|
||||
|
||||
// edit_url
|
||||
if ( $field_group['ID'] && acf_current_user_can_admin() ) {
|
||||
|
||||
$o['editLink'] = admin_url( 'post.php?post=' . $field_group['ID'] . '&action=edit' );
|
||||
|
||||
}
|
||||
|
||||
// load fields
|
||||
$fields = acf_get_fields( $field_group );
|
||||
|
||||
// render
|
||||
acf_render_fields( $fields, $this->page['post_id'], 'div', $field_group['instruction_placement'] );
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
if( typeof acf !== 'undefined' ) {
|
||||
|
||||
acf.newPostbox(<?php echo json_encode( $o ); ?>);
|
||||
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* html
|
||||
*
|
||||
* @description:
|
||||
* @since: 2.0.4
|
||||
* @created: 5/12/12
|
||||
*/
|
||||
|
||||
function html() {
|
||||
|
||||
// load view
|
||||
acf_get_view( dirname( __FILE__ ) . '/views/html-options-page.php', $this->page );
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// initialize
|
||||
new acf_admin_options_page();
|
||||
|
||||
endif;
|
||||
|
||||
?>
|
@@ -0,0 +1,344 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Admin_Updates' ) ) :
|
||||
|
||||
class ACF_Admin_Updates {
|
||||
|
||||
/** @var array Data used in the view. */
|
||||
var $view = array();
|
||||
|
||||
/**
|
||||
* __construct
|
||||
*
|
||||
* Sets up the class functionality.
|
||||
*
|
||||
* @date 23/06/12
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
function __construct() {
|
||||
|
||||
// Add actions.
|
||||
add_action( 'admin_menu', array( $this, 'admin_menu' ), 20 );
|
||||
}
|
||||
|
||||
/**
|
||||
* display_wp_error
|
||||
*
|
||||
* Adds an admin notice using the provided WP_Error.
|
||||
*
|
||||
* @date 14/1/19
|
||||
* @since 5.7.10
|
||||
*
|
||||
* @param WP_Error $wp_error The error to display.
|
||||
* @return void
|
||||
*/
|
||||
function display_wp_error( $wp_error ) {
|
||||
|
||||
// Only show one error on page.
|
||||
if ( acf_has_done( 'display_wp_error' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create new notice.
|
||||
acf_new_admin_notice(
|
||||
array(
|
||||
'text' => __( '<b>Error</b>. Could not connect to update server', 'acf' ) . ' <span class="description">(' . esc_html( $wp_error->get_error_message() ) . ').</span>',
|
||||
'type' => 'error',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* get_changelog_changes
|
||||
*
|
||||
* Finds the specific changes for a given version from the provided changelog snippet.
|
||||
*
|
||||
* @date 14/1/19
|
||||
* @since 5.7.10
|
||||
*
|
||||
* @param string $changelog The changelog text.
|
||||
* @param string $version The version to find.
|
||||
* @return string
|
||||
*/
|
||||
function get_changelog_changes( $changelog = '', $version = '' ) {
|
||||
|
||||
// Explode changelog into sections.
|
||||
$bits = array_filter( explode( '<h4>', $changelog ) );
|
||||
|
||||
// Loop over each version chunk.
|
||||
foreach ( $bits as $bit ) {
|
||||
|
||||
// Find the version number for this chunk.
|
||||
$bit = explode( '</h4>', $bit );
|
||||
$bit_version = trim( $bit[0] );
|
||||
$bit_text = trim( $bit[1] );
|
||||
|
||||
// Compare the chunk version number against param and return HTML.
|
||||
if ( acf_version_compare( $bit_version, '==', $version ) ) {
|
||||
return '<h4>' . esc_html( $bit_version ) . '</h4>' . acf_esc_html( $bit_text );
|
||||
}
|
||||
}
|
||||
|
||||
// Return.
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* admin_menu
|
||||
*
|
||||
* Adds the admin menu subpage.
|
||||
*
|
||||
* @date 28/09/13
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
function admin_menu() {
|
||||
|
||||
// Bail early if no show_admin.
|
||||
if ( ! acf_get_setting( 'show_admin' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail early if no show_updates.
|
||||
if ( ! acf_get_setting( 'show_updates' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail early if not a plugin (included in theme).
|
||||
if ( ! acf_is_plugin_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add submenu.
|
||||
$page = add_submenu_page( 'edit.php?post_type=acf-field-group', __( 'Updates', 'acf' ), __( 'Updates', 'acf' ), acf_get_setting( 'capability' ), 'acf-settings-updates', array( $this, 'html' ) );
|
||||
|
||||
// Add actions to page.
|
||||
add_action( "load-$page", array( $this, 'load' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* load
|
||||
*
|
||||
* Runs when loading the submenu page.
|
||||
*
|
||||
* @date 7/01/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
function load() {
|
||||
|
||||
// Check activate.
|
||||
if ( acf_verify_nonce( 'activate_pro_licence' ) ) {
|
||||
$this->activate_pro_licence();
|
||||
|
||||
// Check deactivate.
|
||||
} elseif ( acf_verify_nonce( 'deactivate_pro_licence' ) ) {
|
||||
$this->deactivate_pro_licence();
|
||||
}
|
||||
|
||||
// vars
|
||||
$license = acf_pro_get_license_key();
|
||||
$this->view = array(
|
||||
'license' => $license,
|
||||
'active' => $license ? 1 : 0,
|
||||
'current_version' => acf_get_setting( 'version' ),
|
||||
'remote_version' => '',
|
||||
'update_available' => false,
|
||||
'changelog' => '',
|
||||
'upgrade_notice' => '',
|
||||
);
|
||||
|
||||
// get plugin updates
|
||||
$force_check = ! empty( $_GET['force-check'] );
|
||||
$info = acf_updates()->get_plugin_info( 'pro', $force_check );
|
||||
|
||||
// Display error.
|
||||
if ( is_wp_error( $info ) ) {
|
||||
return $this->display_wp_error( $info );
|
||||
}
|
||||
|
||||
// add info to view
|
||||
$this->view['remote_version'] = $info['version'];
|
||||
|
||||
// add changelog if the remote version is '>' than the current version
|
||||
$version = acf_get_setting( 'version' );
|
||||
|
||||
// check if remote version is higher than current version
|
||||
if ( version_compare( $info['version'], $version, '>' ) ) {
|
||||
|
||||
// update view
|
||||
$this->view['update_available'] = true;
|
||||
$this->view['changelog'] = $this->get_changelog_changes( $info['changelog'], $info['version'] );
|
||||
$this->view['upgrade_notice'] = $this->get_changelog_changes( $info['upgrade_notice'], $info['version'] );
|
||||
|
||||
// perform update checks if license is active
|
||||
$basename = acf_get_setting( 'basename' );
|
||||
$update = acf_updates()->get_plugin_update( $basename );
|
||||
if ( $license ) {
|
||||
|
||||
// display error if no package url
|
||||
// - possible if license key has been modified
|
||||
if ( $update && ! $update['package'] ) {
|
||||
$this->view['update_available'] = false;
|
||||
acf_new_admin_notice(
|
||||
array(
|
||||
'text' => __( '<b>Error</b>. Could not authenticate update package. Please check again or deactivate and reactivate your ACF PRO license.', 'acf' ),
|
||||
'type' => 'error',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// refresh transient
|
||||
// - if no update exists in the transient
|
||||
// - or if the transient 'new_version' is stale
|
||||
if ( ! $update || $update['new_version'] !== $info['version'] ) {
|
||||
acf_updates()->refresh_plugins_transient();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* activate_pro_licence
|
||||
*
|
||||
* Activates the submitted license key.
|
||||
*
|
||||
* @date 16/01/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
function activate_pro_licence() {
|
||||
|
||||
// Connect to API.
|
||||
$post = array(
|
||||
'acf_license' => trim( $_POST['acf_pro_licence'] ),
|
||||
'acf_version' => acf_get_setting( 'version' ),
|
||||
'wp_name' => get_bloginfo( 'name' ),
|
||||
'wp_url' => home_url(),
|
||||
'wp_version' => get_bloginfo( 'version' ),
|
||||
'wp_language' => get_bloginfo( 'language' ),
|
||||
'wp_timezone' => get_option( 'timezone_string' ),
|
||||
);
|
||||
$response = acf_updates()->request( 'v2/plugins/activate?p=pro', $post );
|
||||
|
||||
// Check response is expected JSON array (not string).
|
||||
if ( is_string( $response ) ) {
|
||||
$response = new WP_Error( 'server_error', esc_html( $response ) );
|
||||
}
|
||||
|
||||
// Display error.
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return $this->display_wp_error( $response );
|
||||
}
|
||||
|
||||
// On success.
|
||||
if ( $response['status'] == 1 ) {
|
||||
|
||||
// Update license.
|
||||
acf_pro_update_license( $response['license'] );
|
||||
|
||||
// Refresh plugins transient to fetch new update data.
|
||||
acf_updates()->refresh_plugins_transient();
|
||||
|
||||
// Show notice.
|
||||
acf_add_admin_notice( $response['message'], 'success' );
|
||||
|
||||
// On failure.
|
||||
} else {
|
||||
|
||||
// Show notice.
|
||||
acf_add_admin_notice( $response['message'], 'warning' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* activate_pro_licence
|
||||
*
|
||||
* Deactivates the registered license key.
|
||||
*
|
||||
* @date 16/01/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
function deactivate_pro_licence() {
|
||||
|
||||
// Get license key.
|
||||
$license = acf_pro_get_license_key();
|
||||
|
||||
// Bail early if no key.
|
||||
if ( ! $license ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Connect to API.
|
||||
$post = array(
|
||||
'acf_license' => $license,
|
||||
'wp_url' => home_url(),
|
||||
);
|
||||
$response = acf_updates()->request( 'v2/plugins/deactivate?p=pro', $post );
|
||||
|
||||
// Check response is expected JSON array (not string).
|
||||
if ( is_string( $response ) ) {
|
||||
$response = new WP_Error( 'server_error', esc_html( $response ) );
|
||||
}
|
||||
|
||||
// Display error.
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return $this->display_wp_error( $response );
|
||||
}
|
||||
|
||||
// Remove license key from DB.
|
||||
acf_pro_update_license( '' );
|
||||
|
||||
// Refresh plugins transient to fetch new update data.
|
||||
acf_updates()->refresh_plugins_transient();
|
||||
|
||||
// On success.
|
||||
if ( $response['status'] == 1 ) {
|
||||
|
||||
// Show notice.
|
||||
acf_add_admin_notice( $response['message'], 'info' );
|
||||
|
||||
// On failure.
|
||||
} else {
|
||||
|
||||
// Show notice.
|
||||
acf_add_admin_notice( $response['message'], 'warning' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* html
|
||||
*
|
||||
* Displays the submenu page's HTML.
|
||||
*
|
||||
* @date 7/01/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
function html() {
|
||||
acf_get_view( dirname( __FILE__ ) . '/views/html-settings-updates.php', $this->view );
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize.
|
||||
acf_new_instance( 'ACF_Admin_Updates' );
|
||||
|
||||
endif; // class_exists check
|
@@ -0,0 +1,46 @@
|
||||
<div class="wrap acf-settings-wrap">
|
||||
|
||||
<h1><?php echo $page_title; ?></h1>
|
||||
|
||||
<form id="post" method="post" name="post">
|
||||
|
||||
<?php
|
||||
|
||||
// render post data
|
||||
acf_form_data(
|
||||
array(
|
||||
'screen' => 'options',
|
||||
'post_id' => $post_id,
|
||||
)
|
||||
);
|
||||
|
||||
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
|
||||
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
|
||||
|
||||
?>
|
||||
|
||||
<div id="poststuff" class="poststuff">
|
||||
|
||||
<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
|
||||
|
||||
<div id="postbox-container-1" class="postbox-container">
|
||||
|
||||
<?php do_meta_boxes( 'acf_options_page', 'side', null ); ?>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="postbox-container-2" class="postbox-container">
|
||||
|
||||
<?php do_meta_boxes( 'acf_options_page', 'normal', null ); ?>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<br class="clear">
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
// vars
|
||||
$active = $license ? true : false;
|
||||
$nonce = $active ? 'deactivate_pro_licence' : 'activate_pro_licence';
|
||||
$button = $active ? __( 'Deactivate License', 'acf' ) : __( 'Activate License', 'acf' );
|
||||
$readonly = $active ? 1 : 0;
|
||||
|
||||
?>
|
||||
<div class="wrap acf-settings-wrap">
|
||||
|
||||
<h1><?php _e( 'Updates', 'acf' ); ?></h1>
|
||||
|
||||
<div class="acf-box" id="acf-license-information">
|
||||
<div class="title">
|
||||
<h3><?php _e( 'License Information', 'acf' ); ?></h3>
|
||||
</div>
|
||||
<div class="inner">
|
||||
<p><?php printf( __( 'To unlock updates, please enter your license key below. If you don\'t have a licence key, please see <a href="%s" target="_blank">details & pricing</a>.', 'acf' ), esc_url( 'https://www.advancedcustomfields.com/pro/?utm_source=ACF%2Bpro%2Bplugin&utm_medium=insideplugin&utm_campaign=ACF%2Bupgrade&utm_content=license%2Bactivations' ) ); ?></p>
|
||||
<form action="" method="post">
|
||||
<?php acf_nonce_input( $nonce ); ?>
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>
|
||||
<label for="acf-field-acf_pro_licence"><?php _e( 'License Key', 'acf' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<?php
|
||||
|
||||
// render field
|
||||
acf_render_field(
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'acf_pro_licence',
|
||||
'value' => str_repeat( '*', strlen( $license ) ),
|
||||
'readonly' => $readonly,
|
||||
)
|
||||
);
|
||||
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td>
|
||||
<input type="submit" value="<?php echo esc_attr( $button ); ?>" class="button button-primary">
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="acf-box" id="acf-update-information">
|
||||
<div class="title">
|
||||
<h3><?php _e( 'Update Information', 'acf' ); ?></h3>
|
||||
</div>
|
||||
<div class="inner">
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>
|
||||
<label><?php _e( 'Current Version', 'acf' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<?php echo esc_html( $current_version ); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<label><?php _e( 'Latest Version', 'acf' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<?php echo esc_html( $remote_version ); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<label><?php _e( 'Update Available', 'acf' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<?php if ( $update_available ) : ?>
|
||||
|
||||
<span style="margin-right: 5px;"><?php _e( 'Yes', 'acf' ); ?></span>
|
||||
|
||||
<?php if ( $active ) : ?>
|
||||
<a class="button button-primary" href="<?php echo esc_attr( admin_url( 'plugins.php?s=Advanced+Custom+Fields+Pro' ) ); ?>"><?php _e( 'Update Plugin', 'acf' ); ?></a>
|
||||
<?php else : ?>
|
||||
<a class="button" disabled="disabled" href="#"><?php _e( 'Please enter your license key above to unlock updates', 'acf' ); ?></a>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<span style="margin-right: 5px;"><?php _e( 'No', 'acf' ); ?></span>
|
||||
<a class="button" href="<?php echo esc_attr( add_query_arg( 'force-check', 1 ) ); ?>"><?php _e( 'Check Again', 'acf' ); ?></a>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php if ( $changelog ) : ?>
|
||||
<tr>
|
||||
<th>
|
||||
<label><?php _e( 'Changelog', 'acf' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<?php echo acf_esc_html( $changelog ); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
<?php if ( $upgrade_notice ) : ?>
|
||||
<tr>
|
||||
<th>
|
||||
<label><?php _e( 'Upgrade Notice', 'acf' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<?php echo acf_esc_html( $upgrade_notice ); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<style type="text/css">
|
||||
#acf_pro_licence {
|
||||
width: 75%;
|
||||
}
|
||||
|
||||
#acf-update-information td h4 {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
@@ -0,0 +1,728 @@
|
||||
<?php
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
// Register store.
|
||||
acf_register_store( 'block-types' );
|
||||
acf_register_store( 'block-cache' );
|
||||
|
||||
/**
|
||||
* acf_register_block_type
|
||||
*
|
||||
* Registers a block type.
|
||||
*
|
||||
* @date 18/2/19
|
||||
* @since 5.8.0
|
||||
*
|
||||
* @param array $block The block settings.
|
||||
* @return (array|false)
|
||||
*/
|
||||
function acf_register_block_type( $block ) {
|
||||
|
||||
// Validate block type settings.
|
||||
$block = acf_validate_block_type( $block );
|
||||
|
||||
/**
|
||||
* Filters the arguments for registering a block type.
|
||||
*
|
||||
* @since 5.8.9
|
||||
*
|
||||
* @param array $block The array of arguments for registering a block type.
|
||||
*/
|
||||
$block = apply_filters( 'acf/register_block_type_args', $block );
|
||||
|
||||
// Require name.
|
||||
if ( ! $block['name'] ) {
|
||||
$message = __( 'Block type name is required.', 'acf' );
|
||||
_doing_it_wrong( __FUNCTION__, $message, '5.8.0' );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Bail early if already exists.
|
||||
if ( acf_has_block_type( $block['name'] ) ) {
|
||||
$message = sprintf( __( 'Block type "%s" is already registered.' ), $block['name'] );
|
||||
_doing_it_wrong( __FUNCTION__, $message, '5.8.0' );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add to storage.
|
||||
acf_get_store( 'block-types' )->set( $block['name'], $block );
|
||||
|
||||
// Register block type in WP.
|
||||
if ( function_exists( 'register_block_type' ) ) {
|
||||
register_block_type(
|
||||
$block['name'],
|
||||
array(
|
||||
'attributes' => acf_get_block_type_default_attributes( $block ),
|
||||
'render_callback' => 'acf_render_block_callback',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Register action.
|
||||
add_action( 'enqueue_block_editor_assets', 'acf_enqueue_block_assets' );
|
||||
|
||||
// Return block.
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* acf_register_block
|
||||
*
|
||||
* See acf_register_block_type().
|
||||
*
|
||||
* @date 18/2/19
|
||||
* @since 5.7.12
|
||||
*
|
||||
* @param array $block The block settings.
|
||||
* @return (array|false)
|
||||
*/
|
||||
function acf_register_block( $block ) {
|
||||
return acf_register_block_type( $block );
|
||||
}
|
||||
|
||||
/**
|
||||
* acf_has_block_type
|
||||
*
|
||||
* Returns true if a block type exists for the given name.
|
||||
*
|
||||
* @date 18/2/19
|
||||
* @since 5.7.12
|
||||
*
|
||||
* @param string $name The block type name.
|
||||
* @return bool
|
||||
*/
|
||||
function acf_has_block_type( $name ) {
|
||||
return acf_get_store( 'block-types' )->has( $name );
|
||||
}
|
||||
|
||||
/**
|
||||
* acf_get_block_types
|
||||
*
|
||||
* Returns an array of all registered block types.
|
||||
*
|
||||
* @date 18/2/19
|
||||
* @since 5.7.12
|
||||
*
|
||||
* @param void
|
||||
* @return array
|
||||
*/
|
||||
function acf_get_block_types() {
|
||||
return acf_get_store( 'block-types' )->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* acf_get_block_types
|
||||
*
|
||||
* Returns a block type for the given name.
|
||||
*
|
||||
* @date 18/2/19
|
||||
* @since 5.7.12
|
||||
*
|
||||
* @param string $name The block type name.
|
||||
* @return (array|null)
|
||||
*/
|
||||
function acf_get_block_type( $name ) {
|
||||
return acf_get_store( 'block-types' )->get( $name );
|
||||
}
|
||||
|
||||
/**
|
||||
* acf_remove_block_type
|
||||
*
|
||||
* Removes a block type for the given name.
|
||||
*
|
||||
* @date 18/2/19
|
||||
* @since 5.7.12
|
||||
*
|
||||
* @param string $name The block type name.
|
||||
* @return void
|
||||
*/
|
||||
function acf_remove_block_type( $name ) {
|
||||
acf_get_store( 'block-types' )->remove( $name );
|
||||
}
|
||||
|
||||
/**
|
||||
* acf_get_block_type_default_attributes
|
||||
*
|
||||
* Returns an array of default attribute settings for a block type.
|
||||
*
|
||||
* @date 19/11/18
|
||||
* @since 5.8.0
|
||||
*
|
||||
* @param void
|
||||
* @return array
|
||||
*/
|
||||
function acf_get_block_type_default_attributes( $block_type ) {
|
||||
$attributes = array(
|
||||
'id' => array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
),
|
||||
'name' => array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
),
|
||||
'data' => array(
|
||||
'type' => 'object',
|
||||
'default' => array(),
|
||||
),
|
||||
'align' => array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
),
|
||||
'mode' => array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
),
|
||||
);
|
||||
if ( ! empty( $block_type['supports']['align_text'] ) ) {
|
||||
$attributes['align_text'] = array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
);
|
||||
}
|
||||
if ( ! empty( $block_type['supports']['align_content'] ) ) {
|
||||
$attributes['align_content'] = array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
);
|
||||
}
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* acf_validate_block_type
|
||||
*
|
||||
* Validates a block type ensuring all settings exist.
|
||||
*
|
||||
* @date 10/4/18
|
||||
* @since 5.8.0
|
||||
*
|
||||
* @param array $block The block settings.
|
||||
* @return array
|
||||
*/
|
||||
function acf_validate_block_type( $block ) {
|
||||
|
||||
// Add default settings.
|
||||
$block = wp_parse_args(
|
||||
$block,
|
||||
array(
|
||||
'name' => '',
|
||||
'title' => '',
|
||||
'description' => '',
|
||||
'category' => 'common',
|
||||
'icon' => '',
|
||||
'mode' => 'preview',
|
||||
'align' => '',
|
||||
'keywords' => array(),
|
||||
'supports' => array(),
|
||||
'post_types' => array(),
|
||||
'render_template' => false,
|
||||
'render_callback' => false,
|
||||
'enqueue_style' => false,
|
||||
'enqueue_script' => false,
|
||||
'enqueue_assets' => false,
|
||||
)
|
||||
);
|
||||
|
||||
// Restrict keywords to 3 max to avoid JS error in older versions.
|
||||
if ( acf_version_compare( 'wp', '<', '5.2' ) ) {
|
||||
$block['keywords'] = array_slice( $block['keywords'], 0, 3 );
|
||||
}
|
||||
|
||||
// Generate name with prefix.
|
||||
if ( $block['name'] ) {
|
||||
$block['name'] = 'acf/' . acf_slugify( $block['name'] );
|
||||
}
|
||||
|
||||
// Add default 'supports' settings.
|
||||
$block['supports'] = wp_parse_args(
|
||||
$block['supports'],
|
||||
array(
|
||||
'align' => true,
|
||||
'html' => false,
|
||||
'mode' => true,
|
||||
)
|
||||
);
|
||||
|
||||
// Correct "Experimental" flags.
|
||||
if ( isset( $block['supports']['__experimental_jsx'] ) ) {
|
||||
$block['supports']['jsx'] = $block['supports']['__experimental_jsx'];
|
||||
}
|
||||
|
||||
// Return block.
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* acf_prepare_block
|
||||
*
|
||||
* Prepares a block for use in render_callback by merging in all settings and attributes.
|
||||
*
|
||||
* @date 19/11/18
|
||||
* @since 5.8.0
|
||||
*
|
||||
* @param array $block The block props.
|
||||
* @return array
|
||||
*/
|
||||
function acf_prepare_block( $block ) {
|
||||
|
||||
// Bail early if no name.
|
||||
if ( ! isset( $block['name'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Replace className with wpClassName if it's set. This enables support for blocks API v2 filters.
|
||||
if ( isset( $block['wpClassName'] ) ) {
|
||||
$block['className'] = $block['wpClassName'];
|
||||
unset( $block['wpClassName'] );
|
||||
}
|
||||
|
||||
// Get block type and return false if doesn't exist.
|
||||
$block_type = acf_get_block_type( $block['name'] );
|
||||
if ( ! $block_type ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Generate default attributes.
|
||||
$attributes = array();
|
||||
foreach ( acf_get_block_type_default_attributes( $block_type ) as $k => $v ) {
|
||||
$attributes[ $k ] = $v['default'];
|
||||
}
|
||||
|
||||
// Merge together arrays in order of least to most specific.
|
||||
$block = array_merge( $block_type, $attributes, $block );
|
||||
|
||||
// Return block.
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* The render callback for all ACF blocks.
|
||||
*
|
||||
* @date 28/10/20
|
||||
* @since 5.9.2
|
||||
*
|
||||
* @param array $attributes The block attributes.
|
||||
* @param string $content The block content.
|
||||
* @param WP_Block $wp_block The block instance (since WP 5.5).
|
||||
* @return string The block HTML.
|
||||
*/
|
||||
function acf_render_block_callback( $attributes, $content = '', $wp_block = null ) {
|
||||
$is_preview = false;
|
||||
$post_id = get_the_ID();
|
||||
|
||||
// Set preview flag to true when rendering for the block editor.
|
||||
if ( is_admin() && acf_is_block_editor() ) {
|
||||
$is_preview = true;
|
||||
}
|
||||
|
||||
// Return rendered block HTML.
|
||||
return acf_rendered_block( $attributes, $content, $is_preview, $post_id, $wp_block );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the rendered block HTML.
|
||||
*
|
||||
* @date 28/2/19
|
||||
* @since 5.7.13
|
||||
*
|
||||
* @param array $attributes The block attributes.
|
||||
* @param string $content The block content.
|
||||
* @param bool $is_preview Whether or not the block is being rendered for editing preview.
|
||||
* @param int $post_id The current post being edited or viewed.
|
||||
* @param WP_Block $wp_block The block instance (since WP 5.5).
|
||||
* @return string The block HTML.
|
||||
*/
|
||||
function acf_rendered_block( $attributes, $content = '', $is_preview = false, $post_id = 0, $wp_block = null ) {
|
||||
$mode = isset( $attributes['mode'] ) ? $attributes['mode'] : 'auto';
|
||||
|
||||
ob_start();
|
||||
|
||||
if ( 'edit' === $mode && $is_preview ) {
|
||||
// Load the block form since we're in edit mode.
|
||||
$block = acf_prepare_block( $attributes );
|
||||
acf_setup_meta( $block['data'], $block['id'], true );
|
||||
$fields = acf_get_block_fields( $block );
|
||||
acf_prefix_fields( $fields, "acf-{$block['id']}" );
|
||||
|
||||
echo '<div class="acf-block-fields acf-fields">';
|
||||
acf_render_fields( $fields, $block['id'], 'div', 'field' );
|
||||
echo '</div>';
|
||||
} else {
|
||||
// Capture block render output.
|
||||
acf_render_block( $attributes, $content, $is_preview, $post_id, $wp_block );
|
||||
}
|
||||
|
||||
$html = ob_get_clean();
|
||||
|
||||
if ( 'preview' === $mode && $is_preview ) {
|
||||
$html = '<div class="acf-block-preview">' . $html . '</div>';
|
||||
}
|
||||
|
||||
// Replace <InnerBlocks /> placeholder on front-end.
|
||||
if ( ! $is_preview ) {
|
||||
// Escape "$" character to avoid "capture group" interpretation.
|
||||
$content = str_replace( '$', '\$', $content );
|
||||
$html = preg_replace( '/<InnerBlocks([\S\s]*?)\/>/', $content, $html );
|
||||
}
|
||||
|
||||
// Store in cache for preloading.
|
||||
acf_get_store( 'block-cache' )->set( $attributes['id'], $html );
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the block HTML.
|
||||
*
|
||||
* @date 19/2/19
|
||||
* @since 5.7.12
|
||||
*
|
||||
* @param array $attributes The block attributes.
|
||||
* @param string $content The block content.
|
||||
* @param bool $is_preview Whether or not the block is being rendered for editing preview.
|
||||
* @param int $post_id The current post being edited or viewed.
|
||||
* @param WP_Block $wp_block The block instance (since WP 5.5).
|
||||
* @return void
|
||||
*/
|
||||
function acf_render_block( $attributes, $content = '', $is_preview = false, $post_id = 0, $wp_block = null ) {
|
||||
|
||||
// Prepare block ensuring all settings and attributes exist.
|
||||
$block = acf_prepare_block( $attributes );
|
||||
if ( ! $block ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Find post_id if not defined.
|
||||
if ( ! $post_id ) {
|
||||
$post_id = get_the_ID();
|
||||
}
|
||||
|
||||
// Enqueue block type assets.
|
||||
acf_enqueue_block_type_assets( $block );
|
||||
|
||||
// Setup postdata allowing get_field() to work.
|
||||
acf_setup_meta( $block['data'], $block['id'], true );
|
||||
|
||||
// Call render_callback.
|
||||
if ( is_callable( $block['render_callback'] ) ) {
|
||||
call_user_func( $block['render_callback'], $block, $content, $is_preview, $post_id, $wp_block );
|
||||
|
||||
// Or include template.
|
||||
} elseif ( $block['render_template'] ) {
|
||||
|
||||
// Locate template.
|
||||
if ( file_exists( $block['render_template'] ) ) {
|
||||
$path = $block['render_template'];
|
||||
} else {
|
||||
$path = locate_template( $block['render_template'] );
|
||||
}
|
||||
|
||||
// Include template.
|
||||
if ( file_exists( $path ) ) {
|
||||
include $path;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset postdata.
|
||||
acf_reset_meta( $block['id'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* acf_get_block_fields
|
||||
*
|
||||
* Returns an array of all fields for the given block.
|
||||
*
|
||||
* @date 24/10/18
|
||||
* @since 5.8.0
|
||||
*
|
||||
* @param array $block The block props.
|
||||
* @return array
|
||||
*/
|
||||
function acf_get_block_fields( $block ) {
|
||||
|
||||
// Vars.
|
||||
$fields = array();
|
||||
|
||||
// Get field groups for this block.
|
||||
$field_groups = acf_get_field_groups(
|
||||
array(
|
||||
'block' => $block['name'],
|
||||
)
|
||||
);
|
||||
|
||||
// Loop over results and append fields.
|
||||
if ( $field_groups ) {
|
||||
foreach ( $field_groups as $field_group ) {
|
||||
$fields = array_merge( $fields, acf_get_fields( $field_group ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Return fields.
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* acf_enqueue_block_assets
|
||||
*
|
||||
* Enqueues and localizes block scripts and styles.
|
||||
*
|
||||
* @date 28/2/19
|
||||
* @since 5.7.13
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
function acf_enqueue_block_assets() {
|
||||
|
||||
// Localize text.
|
||||
acf_localize_text(
|
||||
array(
|
||||
'Switch to Edit' => __( 'Switch to Edit', 'acf' ),
|
||||
'Switch to Preview' => __( 'Switch to Preview', 'acf' ),
|
||||
'Change content alignment' => __( 'Change content alignment', 'acf' ),
|
||||
|
||||
/* translators: %s: Block type title */
|
||||
'%s settings' => __( '%s settings', 'acf' ),
|
||||
)
|
||||
);
|
||||
|
||||
// Get block types.
|
||||
$block_types = acf_get_block_types();
|
||||
|
||||
// Localize data.
|
||||
acf_localize_data(
|
||||
array(
|
||||
'blockTypes' => array_values( $block_types ),
|
||||
'postType' => get_post_type(),
|
||||
)
|
||||
);
|
||||
|
||||
// Enqueue script.
|
||||
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
||||
|
||||
|
||||
if ( acf_version_compare( 'wp', '<', '5.6' ) ) {
|
||||
$blocks_js_path = acf_get_url( "assets/build/js/pro/acf-pro-blocks-legacy{$min}.js" );
|
||||
} else {
|
||||
$blocks_js_path = acf_get_url( "assets/build/js/pro/acf-pro-blocks{$min}.js" );
|
||||
}
|
||||
|
||||
wp_enqueue_script( 'acf-blocks', $blocks_js_path, array( 'acf-input', 'wp-blocks' ), ACF_VERSION, true );
|
||||
|
||||
// Enqueue block assets.
|
||||
array_map( 'acf_enqueue_block_type_assets', $block_types );
|
||||
|
||||
// During the edit screen loading, WordPress renders all blocks in its own attempt to preload data.
|
||||
// Retrieve any cached block HTML and include this in the localized data.
|
||||
$preloaded_blocks = acf_get_store( 'block-cache' )->get_data();
|
||||
acf_localize_data(
|
||||
array(
|
||||
'preloadedBlocks' => $preloaded_blocks,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* acf_enqueue_block_type_assets
|
||||
*
|
||||
* Enqueues scripts and styles for a specific block type.
|
||||
*
|
||||
* @date 28/2/19
|
||||
* @since 5.7.13
|
||||
*
|
||||
* @param array $block_type The block type settings.
|
||||
* @return void
|
||||
*/
|
||||
function acf_enqueue_block_type_assets( $block_type ) {
|
||||
|
||||
// Generate handle from name.
|
||||
$handle = 'block-' . acf_slugify( $block_type['name'] );
|
||||
|
||||
// Enqueue style.
|
||||
if ( $block_type['enqueue_style'] ) {
|
||||
wp_enqueue_style( $handle, $block_type['enqueue_style'], array(), false, 'all' );
|
||||
}
|
||||
|
||||
// Enqueue script.
|
||||
if ( $block_type['enqueue_script'] ) {
|
||||
wp_enqueue_script( $handle, $block_type['enqueue_script'], array(), false, true );
|
||||
}
|
||||
|
||||
// Enqueue assets callback.
|
||||
if ( $block_type['enqueue_assets'] && is_callable( $block_type['enqueue_assets'] ) ) {
|
||||
call_user_func( $block_type['enqueue_assets'], $block_type );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* acf_ajax_fetch_block
|
||||
*
|
||||
* Handles the ajax request for block data.
|
||||
*
|
||||
* @date 28/2/19
|
||||
* @since 5.7.13
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
function acf_ajax_fetch_block() {
|
||||
|
||||
// Validate ajax request.
|
||||
if ( ! acf_verify_ajax() ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
// Get request args.
|
||||
extract(
|
||||
acf_request_args(
|
||||
array(
|
||||
'block' => false,
|
||||
'post_id' => 0,
|
||||
'query' => array(),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Bail ealry if no block.
|
||||
if ( ! $block ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
// Unslash and decode $_POST data.
|
||||
$block = wp_unslash( $block );
|
||||
$block = json_decode( $block, true );
|
||||
|
||||
// Prepare block ensuring all settings and attributes exist.
|
||||
if ( ! $block = acf_prepare_block( $block ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
// Load field defaults when first previewing a block.
|
||||
if ( ! empty( $query['preview'] ) && ! $block['data'] ) {
|
||||
$fields = acf_get_block_fields( $block );
|
||||
foreach ( $fields as $field ) {
|
||||
$block['data'][ "_{$field['name']}" ] = $field['key'];
|
||||
}
|
||||
}
|
||||
|
||||
// Setup postdata allowing form to load meta.
|
||||
acf_setup_meta( $block['data'], $block['id'], true );
|
||||
|
||||
// Vars.
|
||||
$response = array();
|
||||
|
||||
// Query form.
|
||||
if ( ! empty( $query['form'] ) ) {
|
||||
|
||||
// Load fields for form.
|
||||
$fields = acf_get_block_fields( $block );
|
||||
|
||||
// Prefix field inputs to avoid multiple blocks using the same name/id attributes.
|
||||
acf_prefix_fields( $fields, "acf-{$block['id']}" );
|
||||
|
||||
// Start Capture.
|
||||
ob_start();
|
||||
|
||||
// Render.
|
||||
echo '<div class="acf-block-fields acf-fields">';
|
||||
acf_render_fields( $fields, $block['id'], 'div', 'field' );
|
||||
echo '</div>';
|
||||
|
||||
// Store Capture.
|
||||
$response['form'] = ob_get_contents();
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
// Query preview.
|
||||
if ( ! empty( $query['preview'] ) ) {
|
||||
|
||||
// Render_callback vars.
|
||||
$content = '';
|
||||
$is_preview = true;
|
||||
|
||||
// Render and store HTML.
|
||||
$response['preview'] = acf_rendered_block( $block, $content, $is_preview, $post_id );
|
||||
}
|
||||
|
||||
// Send repsonse.
|
||||
wp_send_json_success( $response );
|
||||
}
|
||||
|
||||
// Register ajax action.
|
||||
acf_register_ajax( 'fetch-block', 'acf_ajax_fetch_block' );
|
||||
|
||||
/**
|
||||
* acf_parse_save_blocks
|
||||
*
|
||||
* Parse content that may contain HTML block comments and saves ACF block meta.
|
||||
*
|
||||
* @date 27/2/19
|
||||
* @since 5.7.13
|
||||
*
|
||||
* @param string $text Content that may contain HTML block comments.
|
||||
* @return string
|
||||
*/
|
||||
function acf_parse_save_blocks( $text = '' ) {
|
||||
|
||||
// Search text for dynamic blocks and modify attrs.
|
||||
return addslashes(
|
||||
preg_replace_callback(
|
||||
'/<!--\s+wp:(?P<name>[\S]+)\s+(?P<attrs>{[\S\s]+?})\s+(?P<void>\/)?-->/',
|
||||
'acf_parse_save_blocks_callback',
|
||||
stripslashes( $text )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Hook into saving process.
|
||||
add_filter( 'content_save_pre', 'acf_parse_save_blocks', 5, 1 );
|
||||
|
||||
/**
|
||||
* acf_parse_save_blocks_callback
|
||||
*
|
||||
* Callback used in preg_replace to modify ACF Block comment.
|
||||
*
|
||||
* @date 1/3/19
|
||||
* @since 5.7.13
|
||||
*
|
||||
* @param array $matches The preg matches.
|
||||
* @return string
|
||||
*/
|
||||
function acf_parse_save_blocks_callback( $matches ) {
|
||||
|
||||
// Defaults
|
||||
$name = isset( $matches['name'] ) ? $matches['name'] : '';
|
||||
$attrs = isset( $matches['attrs'] ) ? json_decode( $matches['attrs'], true ) : '';
|
||||
$void = isset( $matches['void'] ) ? $matches['void'] : '';
|
||||
|
||||
// Bail early if missing data or not an ACF Block.
|
||||
if ( ! $name || ! $attrs || ! acf_has_block_type( $name ) ) {
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
// Convert "data" to "meta".
|
||||
// No need to check if already in meta format. Local Meta will do this for us.
|
||||
if ( isset( $attrs['data'] ) ) {
|
||||
$attrs['data'] = acf_setup_meta( $attrs['data'], $attrs['id'] );
|
||||
}
|
||||
|
||||
// Prevent wp_targeted_link_rel from corrupting JSON.
|
||||
remove_filter( 'content_save_pre', 'wp_filter_post_kses' );
|
||||
remove_filter( 'content_save_pre', 'wp_targeted_link_rel' );
|
||||
remove_filter( 'content_save_pre', 'balanceTags', 50 );
|
||||
|
||||
/**
|
||||
* Filteres the block attributes before saving.
|
||||
*
|
||||
* @date 18/3/19
|
||||
* @since 5.7.14
|
||||
*
|
||||
* @param array $attrs The block attributes.
|
||||
*/
|
||||
$attrs = apply_filters( 'acf/pre_save_block', $attrs );
|
||||
|
||||
// Return new comment
|
||||
return '<!-- wp:' . $name . ' ' . acf_json_encode( $attrs ) . ' ' . $void . '-->';
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,886 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'acf_field_gallery' ) ) :
|
||||
|
||||
class acf_field_gallery extends acf_field {
|
||||
|
||||
|
||||
/*
|
||||
* __construct
|
||||
*
|
||||
* This function will setup the field type data
|
||||
*
|
||||
* @type function
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param n/a
|
||||
* @return n/a
|
||||
*/
|
||||
|
||||
function initialize() {
|
||||
|
||||
// vars
|
||||
$this->name = 'gallery';
|
||||
$this->label = __( 'Gallery', 'acf' );
|
||||
$this->category = 'content';
|
||||
$this->defaults = array(
|
||||
'return_format' => 'array',
|
||||
'preview_size' => 'medium',
|
||||
'insert' => 'append',
|
||||
'library' => 'all',
|
||||
'min' => 0,
|
||||
'max' => 0,
|
||||
'min_width' => 0,
|
||||
'min_height' => 0,
|
||||
'min_size' => 0,
|
||||
'max_width' => 0,
|
||||
'max_height' => 0,
|
||||
'max_size' => 0,
|
||||
'mime_types' => '',
|
||||
);
|
||||
|
||||
// actions
|
||||
add_action( 'wp_ajax_acf/fields/gallery/get_attachment', array( $this, 'ajax_get_attachment' ) );
|
||||
add_action( 'wp_ajax_nopriv_acf/fields/gallery/get_attachment', array( $this, 'ajax_get_attachment' ) );
|
||||
|
||||
add_action( 'wp_ajax_acf/fields/gallery/update_attachment', array( $this, 'ajax_update_attachment' ) );
|
||||
add_action( 'wp_ajax_nopriv_acf/fields/gallery/update_attachment', array( $this, 'ajax_update_attachment' ) );
|
||||
|
||||
add_action( 'wp_ajax_acf/fields/gallery/get_sort_order', array( $this, 'ajax_get_sort_order' ) );
|
||||
add_action( 'wp_ajax_nopriv_acf/fields/gallery/get_sort_order', array( $this, 'ajax_get_sort_order' ) );
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* input_admin_enqueue_scripts
|
||||
*
|
||||
* description
|
||||
*
|
||||
* @type function
|
||||
* @date 16/12/2015
|
||||
* @since 5.3.2
|
||||
*
|
||||
* @param $post_id (int)
|
||||
* @return $post_id (int)
|
||||
*/
|
||||
|
||||
function input_admin_enqueue_scripts() {
|
||||
|
||||
// localize
|
||||
acf_localize_text(
|
||||
array(
|
||||
'Add Image to Gallery' => __( 'Add Image to Gallery', 'acf' ),
|
||||
'Maximum selection reached' => __( 'Maximum selection reached', 'acf' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ajax_get_attachment
|
||||
*
|
||||
* description
|
||||
*
|
||||
* @type function
|
||||
* @date 13/12/2013
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param $post_id (int)
|
||||
* @return $post_id (int)
|
||||
*/
|
||||
|
||||
function ajax_get_attachment() {
|
||||
|
||||
// Validate requrest.
|
||||
if ( ! acf_verify_ajax() ) {
|
||||
die();
|
||||
}
|
||||
|
||||
// Get args.
|
||||
$args = acf_request_args(
|
||||
array(
|
||||
'id' => 0,
|
||||
'field_key' => '',
|
||||
)
|
||||
);
|
||||
|
||||
// Cast args.
|
||||
$args['id'] = (int) $args['id'];
|
||||
|
||||
// Bail early if no id.
|
||||
if ( ! $args['id'] ) {
|
||||
die();
|
||||
}
|
||||
|
||||
// Load field.
|
||||
$field = acf_get_field( $args['field_key'] );
|
||||
if ( ! $field ) {
|
||||
die();
|
||||
}
|
||||
|
||||
// Render.
|
||||
$this->render_attachment( $args['id'], $field );
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ajax_update_attachment
|
||||
*
|
||||
* description
|
||||
*
|
||||
* @type function
|
||||
* @date 13/12/2013
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param $post_id (int)
|
||||
* @return $post_id (int)
|
||||
*/
|
||||
|
||||
function ajax_update_attachment() {
|
||||
|
||||
// validate nonce
|
||||
if ( ! wp_verify_nonce( $_POST['nonce'], 'acf_nonce' ) ) {
|
||||
|
||||
wp_send_json_error();
|
||||
|
||||
}
|
||||
|
||||
// bail early if no attachments
|
||||
if ( empty( $_POST['attachments'] ) ) {
|
||||
|
||||
wp_send_json_error();
|
||||
|
||||
}
|
||||
|
||||
// loop over attachments
|
||||
foreach ( $_POST['attachments'] as $id => $changes ) {
|
||||
|
||||
if ( ! current_user_can( 'edit_post', $id ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$post = get_post( $id, ARRAY_A );
|
||||
|
||||
if ( 'attachment' != $post['post_type'] ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
if ( isset( $changes['title'] ) ) {
|
||||
$post['post_title'] = $changes['title'];
|
||||
}
|
||||
|
||||
if ( isset( $changes['caption'] ) ) {
|
||||
$post['post_excerpt'] = $changes['caption'];
|
||||
}
|
||||
|
||||
if ( isset( $changes['description'] ) ) {
|
||||
$post['post_content'] = $changes['description'];
|
||||
}
|
||||
|
||||
if ( isset( $changes['alt'] ) ) {
|
||||
$alt = wp_unslash( $changes['alt'] );
|
||||
if ( $alt != get_post_meta( $id, '_wp_attachment_image_alt', true ) ) {
|
||||
$alt = wp_strip_all_tags( $alt, true );
|
||||
update_post_meta( $id, '_wp_attachment_image_alt', wp_slash( $alt ) );
|
||||
}
|
||||
}
|
||||
|
||||
// save post
|
||||
wp_update_post( $post );
|
||||
|
||||
/** This filter is documented in wp-admin/includes/media.php */
|
||||
// - seems off to run this filter AFTER the update_post function, but there is a reason
|
||||
// - when placed BEFORE, an empty post_title will be populated by WP
|
||||
// - this filter will still allow 3rd party to save extra image data!
|
||||
$post = apply_filters( 'attachment_fields_to_save', $post, $changes );
|
||||
|
||||
// save meta
|
||||
acf_save_post( $id );
|
||||
|
||||
}
|
||||
|
||||
// return
|
||||
wp_send_json_success();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ajax_get_sort_order
|
||||
*
|
||||
* description
|
||||
*
|
||||
* @type function
|
||||
* @date 13/12/2013
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param $post_id (int)
|
||||
* @return $post_id (int)
|
||||
*/
|
||||
|
||||
function ajax_get_sort_order() {
|
||||
|
||||
// vars
|
||||
$r = array();
|
||||
$order = 'DESC';
|
||||
$args = acf_parse_args(
|
||||
$_POST,
|
||||
array(
|
||||
'ids' => 0,
|
||||
'sort' => 'date',
|
||||
'field_key' => '',
|
||||
'nonce' => '',
|
||||
)
|
||||
);
|
||||
|
||||
// validate
|
||||
if ( ! wp_verify_nonce( $args['nonce'], 'acf_nonce' ) ) {
|
||||
|
||||
wp_send_json_error();
|
||||
|
||||
}
|
||||
|
||||
// reverse
|
||||
if ( $args['sort'] == 'reverse' ) {
|
||||
|
||||
$ids = array_reverse( $args['ids'] );
|
||||
|
||||
wp_send_json_success( $ids );
|
||||
|
||||
}
|
||||
|
||||
if ( $args['sort'] == 'title' ) {
|
||||
|
||||
$order = 'ASC';
|
||||
|
||||
}
|
||||
|
||||
// find attachments (DISTINCT POSTS)
|
||||
$ids = get_posts(
|
||||
array(
|
||||
'post_type' => 'attachment',
|
||||
'numberposts' => -1,
|
||||
'post_status' => 'any',
|
||||
'post__in' => $args['ids'],
|
||||
'order' => $order,
|
||||
'orderby' => $args['sort'],
|
||||
'fields' => 'ids',
|
||||
)
|
||||
);
|
||||
|
||||
// success
|
||||
if ( ! empty( $ids ) ) {
|
||||
|
||||
wp_send_json_success( $ids );
|
||||
|
||||
}
|
||||
|
||||
// failure
|
||||
wp_send_json_error();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the sidebar HTML shown when selecting an attachmemnt.
|
||||
*
|
||||
* @date 13/12/2013
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param int $id The attachment ID.
|
||||
* @param array $field The field array.
|
||||
* @return void
|
||||
*/
|
||||
function render_attachment( $id, $field ) {
|
||||
// Load attachmenet data.
|
||||
$attachment = wp_prepare_attachment_for_js( $id );
|
||||
$compat = get_compat_media_markup( $id );
|
||||
|
||||
// Get attachment thumbnail (video).
|
||||
if ( isset( $attachment['thumb']['src'] ) ) {
|
||||
$thumb = $attachment['thumb']['src'];
|
||||
|
||||
// Look for thumbnail size (image).
|
||||
} elseif ( isset( $attachment['sizes']['thumbnail']['url'] ) ) {
|
||||
$thumb = $attachment['sizes']['thumbnail']['url'];
|
||||
|
||||
// Use url for svg.
|
||||
} elseif ( $attachment['type'] === 'image' ) {
|
||||
$thumb = $attachment['url'];
|
||||
|
||||
// Default to icon.
|
||||
} else {
|
||||
$thumb = wp_mime_type_icon( $id );
|
||||
}
|
||||
|
||||
// Get attachment dimensions / time / size.
|
||||
$dimensions = '';
|
||||
if ( $attachment['type'] === 'audio' ) {
|
||||
$dimensions = __( 'Length', 'acf' ) . ': ' . $attachment['fileLength'];
|
||||
} elseif ( ! empty( $attachment['width'] ) ) {
|
||||
$dimensions = $attachment['width'] . ' x ' . $attachment['height'];
|
||||
}
|
||||
if ( ! empty( $attachment['filesizeHumanReadable'] ) ) {
|
||||
$dimensions .= ' (' . $attachment['filesizeHumanReadable'] . ')';
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="acf-gallery-side-info">
|
||||
<img src="<?php echo esc_attr( $thumb ); ?>" alt="<?php echo esc_attr( $attachment['alt'] ); ?>" />
|
||||
<p class="filename"><strong><?php echo esc_html( $attachment['filename'] ); ?></strong></p>
|
||||
<p class="uploaded"><?php echo esc_html( $attachment['dateFormatted'] ); ?></p>
|
||||
<p class="dimensions"><?php echo esc_html( $dimensions ); ?></p>
|
||||
<p class="actions">
|
||||
<a href="#" class="acf-gallery-edit" data-id="<?php echo esc_attr( $id ); ?>"><?php _e( 'Edit', 'acf' ); ?></a>
|
||||
<a href="#" class="acf-gallery-remove" data-id="<?php echo esc_attr( $id ); ?>"><?php _e( 'Remove', 'acf' ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
// Render fields.
|
||||
$prefix = 'attachments[' . $id . ']';
|
||||
|
||||
acf_render_field_wrap(
|
||||
array(
|
||||
// 'key' => "{$field['key']}-title",
|
||||
'name' => 'title',
|
||||
'prefix' => $prefix,
|
||||
'type' => 'text',
|
||||
'label' => __( 'Title', 'acf' ),
|
||||
'value' => $attachment['title'],
|
||||
),
|
||||
'tr'
|
||||
);
|
||||
|
||||
acf_render_field_wrap(
|
||||
array(
|
||||
// 'key' => "{$field['key']}-caption",
|
||||
'name' => 'caption',
|
||||
'prefix' => $prefix,
|
||||
'type' => 'textarea',
|
||||
'label' => __( 'Caption', 'acf' ),
|
||||
'value' => $attachment['caption'],
|
||||
),
|
||||
'tr'
|
||||
);
|
||||
|
||||
acf_render_field_wrap(
|
||||
array(
|
||||
// 'key' => "{$field['key']}-alt",
|
||||
'name' => 'alt',
|
||||
'prefix' => $prefix,
|
||||
'type' => 'text',
|
||||
'label' => __( 'Alt Text', 'acf' ),
|
||||
'value' => $attachment['alt'],
|
||||
),
|
||||
'tr'
|
||||
);
|
||||
|
||||
acf_render_field_wrap(
|
||||
array(
|
||||
// 'key' => "{$field['key']}-description",
|
||||
'name' => 'description',
|
||||
'prefix' => $prefix,
|
||||
'type' => 'textarea',
|
||||
'label' => __( 'Description', 'acf' ),
|
||||
'value' => $attachment['description'],
|
||||
),
|
||||
'tr'
|
||||
);
|
||||
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
// Display compat fields.
|
||||
echo $compat['item'];
|
||||
}
|
||||
|
||||
/*
|
||||
* render_field()
|
||||
*
|
||||
* Create the HTML interface for your field
|
||||
*
|
||||
* @param $field - an array holding all the field's data
|
||||
*
|
||||
* @type action
|
||||
* @since 3.6
|
||||
* @date 23/01/13
|
||||
*/
|
||||
|
||||
function render_field( $field ) {
|
||||
|
||||
// Enqueue uploader assets.
|
||||
acf_enqueue_uploader();
|
||||
|
||||
// Control attributes.
|
||||
$attrs = array(
|
||||
'id' => $field['id'],
|
||||
'class' => "acf-gallery {$field['class']}",
|
||||
'data-library' => $field['library'],
|
||||
'data-preview_size' => $field['preview_size'],
|
||||
'data-min' => $field['min'],
|
||||
'data-max' => $field['max'],
|
||||
'data-mime_types' => $field['mime_types'],
|
||||
'data-insert' => $field['insert'],
|
||||
'data-columns' => 4,
|
||||
);
|
||||
|
||||
// Set gallery height with deafult of 400px and minimum of 200px.
|
||||
$height = acf_get_user_setting( 'gallery_height', 400 );
|
||||
$height = max( $height, 200 );
|
||||
$attrs['style'] = "height:{$height}px";
|
||||
|
||||
// Load attachments.
|
||||
$attachments = array();
|
||||
if ( $field['value'] ) {
|
||||
|
||||
// Clean value into an array of IDs.
|
||||
$attachment_ids = array_map( 'intval', acf_array( $field['value'] ) );
|
||||
|
||||
// Find posts in database (ensures all results are real).
|
||||
$posts = acf_get_posts(
|
||||
array(
|
||||
'post_type' => 'attachment',
|
||||
'post__in' => $attachment_ids,
|
||||
'update_post_meta_cache' => true,
|
||||
'update_post_term_cache' => false,
|
||||
)
|
||||
);
|
||||
|
||||
// Load attatchment data for each post.
|
||||
$attachments = array_map( 'acf_get_attachment', $posts );
|
||||
}
|
||||
|
||||
?>
|
||||
<div <?php acf_esc_attr_e( $attrs ); ?>>
|
||||
<input type="hidden" name="<?php echo esc_attr( $field['name'] ); ?>" value="" />
|
||||
<div class="acf-gallery-main">
|
||||
<div class="acf-gallery-attachments">
|
||||
<?php if ( $attachments ) : ?>
|
||||
<?php
|
||||
foreach ( $attachments as $i => $attachment ) :
|
||||
|
||||
// Vars
|
||||
$a_id = $attachment['ID'];
|
||||
$a_title = $attachment['title'];
|
||||
$a_type = $attachment['type'];
|
||||
$a_filename = $attachment['filename'];
|
||||
$a_class = "acf-gallery-attachment -{$a_type}";
|
||||
|
||||
// Get thumbnail.
|
||||
$a_thumbnail = acf_get_post_thumbnail( $a_id, $field['preview_size'] );
|
||||
$a_class .= ( $a_thumbnail['type'] === 'icon' ) ? ' -icon' : '';
|
||||
|
||||
?>
|
||||
<div class="<?php echo esc_attr( $a_class ); ?>" data-id="<?php echo esc_attr( $a_id ); ?>">
|
||||
<input type="hidden" name="<?php echo esc_attr( $field['name'] ); ?>[]" value="<?php echo esc_attr( $a_id ); ?>" />
|
||||
<div class="margin">
|
||||
<div class="thumbnail">
|
||||
<img src="<?php echo esc_url( $a_thumbnail['url'] ); ?>" alt="" />
|
||||
</div>
|
||||
<?php if ( $a_type !== 'image' ) : ?>
|
||||
<div class="filename"><?php echo acf_get_truncated( $a_filename, 30 ); ?></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<a class="acf-icon -cancel dark acf-gallery-remove" href="#" data-id="<?php echo esc_attr( $a_id ); ?>" title="<?php _e( 'Remove', 'acf' ); ?>"></a>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="acf-gallery-toolbar">
|
||||
<ul class="acf-hl">
|
||||
<li>
|
||||
<a href="#" class="acf-button button button-primary acf-gallery-add"><?php _e( 'Add to gallery', 'acf' ); ?></a>
|
||||
</li>
|
||||
<li class="acf-fr">
|
||||
<select class="acf-gallery-sort">
|
||||
<option value=""><?php _e( 'Bulk actions', 'acf' ); ?></option>
|
||||
<option value="date"><?php _e( 'Sort by date uploaded', 'acf' ); ?></option>
|
||||
<option value="modified"><?php _e( 'Sort by date modified', 'acf' ); ?></option>
|
||||
<option value="title"><?php _e( 'Sort by title', 'acf' ); ?></option>
|
||||
<option value="reverse"><?php _e( 'Reverse current order', 'acf' ); ?></option>
|
||||
</select>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="acf-gallery-side">
|
||||
<div class="acf-gallery-side-inner">
|
||||
<div class="acf-gallery-side-data"></div>
|
||||
<div class="acf-gallery-toolbar">
|
||||
<ul class="acf-hl">
|
||||
<li>
|
||||
<a href="#" class="acf-button button acf-gallery-close"><?php _e( 'Close', 'acf' ); ?></a>
|
||||
</li>
|
||||
<li class="acf-fr">
|
||||
<a class="acf-button button button-primary acf-gallery-update" href="#"><?php _e( 'Update', 'acf' ); ?></a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* render_field_settings()
|
||||
*
|
||||
* Create extra options for your field. This is rendered when editing a field.
|
||||
* The value of $field['name'] can be used (like bellow) to save extra data to the $field
|
||||
*
|
||||
* @type action
|
||||
* @since 3.6
|
||||
* @date 23/01/13
|
||||
*
|
||||
* @param $field - an array holding all the field's data
|
||||
*/
|
||||
|
||||
function render_field_settings( $field ) {
|
||||
|
||||
// clear numeric settings
|
||||
$clear = array(
|
||||
'min',
|
||||
'max',
|
||||
'min_width',
|
||||
'min_height',
|
||||
'min_size',
|
||||
'max_width',
|
||||
'max_height',
|
||||
'max_size',
|
||||
);
|
||||
|
||||
foreach ( $clear as $k ) {
|
||||
|
||||
if ( empty( $field[ $k ] ) ) {
|
||||
$field[ $k ] = '';
|
||||
}
|
||||
}
|
||||
|
||||
// return_format
|
||||
acf_render_field_setting(
|
||||
$field,
|
||||
array(
|
||||
'label' => __( 'Return Format', 'acf' ),
|
||||
'instructions' => '',
|
||||
'type' => 'radio',
|
||||
'name' => 'return_format',
|
||||
'layout' => 'horizontal',
|
||||
'choices' => array(
|
||||
'array' => __( 'Image Array', 'acf' ),
|
||||
'url' => __( 'Image URL', 'acf' ),
|
||||
'id' => __( 'Image ID', 'acf' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// preview_size
|
||||
acf_render_field_setting(
|
||||
$field,
|
||||
array(
|
||||
'label' => __( 'Preview Size', 'acf' ),
|
||||
'instructions' => '',
|
||||
'type' => 'select',
|
||||
'name' => 'preview_size',
|
||||
'choices' => acf_get_image_sizes(),
|
||||
)
|
||||
);
|
||||
|
||||
// insert
|
||||
acf_render_field_setting(
|
||||
$field,
|
||||
array(
|
||||
'label' => __( 'Insert', 'acf' ),
|
||||
'instructions' => __( 'Specify where new attachments are added', 'acf' ),
|
||||
'type' => 'select',
|
||||
'name' => 'insert',
|
||||
'choices' => array(
|
||||
'append' => __( 'Append to the end', 'acf' ),
|
||||
'prepend' => __( 'Prepend to the beginning', 'acf' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// library
|
||||
acf_render_field_setting(
|
||||
$field,
|
||||
array(
|
||||
'label' => __( 'Library', 'acf' ),
|
||||
'instructions' => __( 'Limit the media library choice', 'acf' ),
|
||||
'type' => 'radio',
|
||||
'name' => 'library',
|
||||
'layout' => 'horizontal',
|
||||
'choices' => array(
|
||||
'all' => __( 'All', 'acf' ),
|
||||
'uploadedTo' => __( 'Uploaded to post', 'acf' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// min
|
||||
acf_render_field_setting(
|
||||
$field,
|
||||
array(
|
||||
'label' => __( 'Minimum Selection', 'acf' ),
|
||||
'instructions' => '',
|
||||
'type' => 'number',
|
||||
'name' => 'min',
|
||||
)
|
||||
);
|
||||
|
||||
// max
|
||||
acf_render_field_setting(
|
||||
$field,
|
||||
array(
|
||||
'label' => __( 'Maximum Selection', 'acf' ),
|
||||
'instructions' => '',
|
||||
'type' => 'number',
|
||||
'name' => 'max',
|
||||
)
|
||||
);
|
||||
|
||||
// min
|
||||
acf_render_field_setting(
|
||||
$field,
|
||||
array(
|
||||
'label' => __( 'Minimum', 'acf' ),
|
||||
'instructions' => __( 'Restrict which images can be uploaded', 'acf' ),
|
||||
'type' => 'text',
|
||||
'name' => 'min_width',
|
||||
'prepend' => __( 'Width', 'acf' ),
|
||||
'append' => 'px',
|
||||
)
|
||||
);
|
||||
|
||||
acf_render_field_setting(
|
||||
$field,
|
||||
array(
|
||||
'label' => '',
|
||||
'type' => 'text',
|
||||
'name' => 'min_height',
|
||||
'prepend' => __( 'Height', 'acf' ),
|
||||
'append' => 'px',
|
||||
'_append' => 'min_width',
|
||||
)
|
||||
);
|
||||
|
||||
acf_render_field_setting(
|
||||
$field,
|
||||
array(
|
||||
'label' => '',
|
||||
'type' => 'text',
|
||||
'name' => 'min_size',
|
||||
'prepend' => __( 'File size', 'acf' ),
|
||||
'append' => 'MB',
|
||||
'_append' => 'min_width',
|
||||
)
|
||||
);
|
||||
|
||||
// max
|
||||
acf_render_field_setting(
|
||||
$field,
|
||||
array(
|
||||
'label' => __( 'Maximum', 'acf' ),
|
||||
'instructions' => __( 'Restrict which images can be uploaded', 'acf' ),
|
||||
'type' => 'text',
|
||||
'name' => 'max_width',
|
||||
'prepend' => __( 'Width', 'acf' ),
|
||||
'append' => 'px',
|
||||
)
|
||||
);
|
||||
|
||||
acf_render_field_setting(
|
||||
$field,
|
||||
array(
|
||||
'label' => '',
|
||||
'type' => 'text',
|
||||
'name' => 'max_height',
|
||||
'prepend' => __( 'Height', 'acf' ),
|
||||
'append' => 'px',
|
||||
'_append' => 'max_width',
|
||||
)
|
||||
);
|
||||
|
||||
acf_render_field_setting(
|
||||
$field,
|
||||
array(
|
||||
'label' => '',
|
||||
'type' => 'text',
|
||||
'name' => 'max_size',
|
||||
'prepend' => __( 'File size', 'acf' ),
|
||||
'append' => 'MB',
|
||||
'_append' => 'max_width',
|
||||
)
|
||||
);
|
||||
|
||||
// allowed type
|
||||
acf_render_field_setting(
|
||||
$field,
|
||||
array(
|
||||
'label' => __( 'Allowed file types', 'acf' ),
|
||||
'instructions' => __( 'Comma separated list. Leave blank for all types', 'acf' ),
|
||||
'type' => 'text',
|
||||
'name' => 'mime_types',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* format_value()
|
||||
*
|
||||
* This filter is appied to the $value after it is loaded from the db and before it is returned to the template
|
||||
*
|
||||
* @type filter
|
||||
* @since 3.6
|
||||
* @date 23/01/13
|
||||
*
|
||||
* @param $value (mixed) the value which was loaded from the database
|
||||
* @param $post_id (mixed) the $post_id from which the value was loaded
|
||||
* @param $field (array) the field array holding all the field options
|
||||
*
|
||||
* @return $value (mixed) the modified value
|
||||
*/
|
||||
|
||||
function format_value( $value, $post_id, $field ) {
|
||||
|
||||
// Bail early if no value.
|
||||
if ( ! $value ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Clean value into an array of IDs.
|
||||
$attachment_ids = array_map( 'intval', acf_array( $value ) );
|
||||
|
||||
// Find posts in database (ensures all results are real).
|
||||
$posts = acf_get_posts(
|
||||
array(
|
||||
'post_type' => 'attachment',
|
||||
'post__in' => $attachment_ids,
|
||||
'update_post_meta_cache' => true,
|
||||
'update_post_term_cache' => false,
|
||||
)
|
||||
);
|
||||
|
||||
// Bail early if no posts found.
|
||||
if ( ! $posts ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Format values using field settings.
|
||||
$value = array();
|
||||
foreach ( $posts as $post ) {
|
||||
|
||||
// Return object.
|
||||
if ( $field['return_format'] == 'object' ) {
|
||||
$item = $post;
|
||||
|
||||
// Return array.
|
||||
} elseif ( $field['return_format'] == 'array' ) {
|
||||
$item = acf_get_attachment( $post );
|
||||
|
||||
// Return URL.
|
||||
} elseif ( $field['return_format'] == 'url' ) {
|
||||
$item = wp_get_attachment_url( $post->ID );
|
||||
|
||||
// Return ID.
|
||||
} else {
|
||||
$item = $post->ID;
|
||||
}
|
||||
|
||||
// Append item.
|
||||
$value[] = $item;
|
||||
}
|
||||
|
||||
// Return.
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* validate_value
|
||||
*
|
||||
* description
|
||||
*
|
||||
* @type function
|
||||
* @date 11/02/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param $post_id (int)
|
||||
* @return $post_id (int)
|
||||
*/
|
||||
|
||||
function validate_value( $valid, $value, $field, $input ) {
|
||||
|
||||
if ( empty( $value ) || ! is_array( $value ) ) {
|
||||
|
||||
$value = array();
|
||||
|
||||
}
|
||||
|
||||
if ( count( $value ) < $field['min'] ) {
|
||||
|
||||
$valid = _n( '%1$s requires at least %2$s selection', '%1$s requires at least %2$s selections', $field['min'], 'acf' );
|
||||
$valid = sprintf( $valid, $field['label'], $field['min'] );
|
||||
|
||||
}
|
||||
|
||||
return $valid;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* update_value()
|
||||
*
|
||||
* This filter is appied to the $value before it is updated in the db
|
||||
*
|
||||
* @type filter
|
||||
* @since 3.6
|
||||
* @date 23/01/13
|
||||
*
|
||||
* @param $value - the value which will be saved in the database
|
||||
* @param $post_id - the $post_id of which the value will be saved
|
||||
* @param $field - the field array holding all the field options
|
||||
*
|
||||
* @return $value - the modified value
|
||||
*/
|
||||
|
||||
function update_value( $value, $post_id, $field ) {
|
||||
|
||||
// Bail early if no value.
|
||||
if ( empty( $value ) ) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
// Convert to array.
|
||||
$value = acf_array( $value );
|
||||
|
||||
// Format array of values.
|
||||
// - ensure each value is an id.
|
||||
// - Parse each id as string for SQL LIKE queries.
|
||||
$value = array_map( 'acf_idval', $value );
|
||||
$value = array_map( 'strval', $value );
|
||||
|
||||
// Return value.
|
||||
return $value;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// initialize
|
||||
acf_register_field_type( 'acf_field_gallery' );
|
||||
|
||||
endif; // class_exists check
|
||||
|
||||
?>
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Block' ) ) :
|
||||
|
||||
class ACF_Location_Block extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'block';
|
||||
$this->label = __( 'Block', 'acf' );
|
||||
$this->category = 'forms';
|
||||
$this->object_type = 'block';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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['block'] ) ) {
|
||||
$block = $screen['block'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compare rule against $block.
|
||||
return $this->compare_to_rule( $block, $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();
|
||||
|
||||
// Append block types.
|
||||
$blocks = acf_get_block_types();
|
||||
if ( $blocks ) {
|
||||
$choices['all'] = __( 'All', 'acf' );
|
||||
foreach ( $blocks as $block ) {
|
||||
$choices[ $block['name'] ] = $block['title'];
|
||||
}
|
||||
} else {
|
||||
$choices[''] = __( 'No block types exist', 'acf' );
|
||||
}
|
||||
|
||||
// Return choices.
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
|
||||
// initialize
|
||||
acf_register_location_type( 'ACF_Location_Block' );
|
||||
|
||||
endif; // class_exists check
|
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'ACF_Location_Options_Page' ) ) :
|
||||
|
||||
class ACF_Location_Options_Page extends ACF_Location {
|
||||
|
||||
/**
|
||||
* Initializes props.
|
||||
*
|
||||
* @date 5/03/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
public function initialize() {
|
||||
$this->name = 'options_page';
|
||||
$this->label = __( 'Options Page', 'acf' );
|
||||
$this->category = 'forms';
|
||||
$this->object_type = 'option';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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['options_page'] ) ) {
|
||||
$options_page = $screen['options_page'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compare rule against $nav_menu.
|
||||
return $this->compare_to_rule( $options_page, $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();
|
||||
|
||||
// Append pages.
|
||||
$pages = acf_get_options_pages();
|
||||
if ( $pages ) {
|
||||
foreach ( $pages as $page ) {
|
||||
$choices[ $page['menu_slug'] ] = $page['page_title'];
|
||||
}
|
||||
} else {
|
||||
$choices[''] = __( 'No options pages exist', 'acf' );
|
||||
}
|
||||
|
||||
// Return choices.
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
|
||||
// initialize
|
||||
acf_register_location_type( 'ACF_Location_Options_Page' );
|
||||
|
||||
endif; // class_exists check
|
@@ -0,0 +1,619 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'acf_options_page' ) ) :
|
||||
|
||||
class acf_options_page {
|
||||
|
||||
/** @var array Contains an array of options page settings */
|
||||
var $pages = array();
|
||||
|
||||
|
||||
/*
|
||||
* __construct
|
||||
*
|
||||
* Initialize filters, action, variables and includes
|
||||
*
|
||||
* @type function
|
||||
* @date 23/06/12
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param n/a
|
||||
* @return n/a
|
||||
*/
|
||||
|
||||
function __construct() {
|
||||
|
||||
/* do nothing */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates an Options Page settings array.
|
||||
*
|
||||
* @date 28/2/17
|
||||
* @since 5.5.8
|
||||
*
|
||||
* @param array|string $page The Options Page settings array or name.
|
||||
* @return array
|
||||
*/
|
||||
function validate_page( $page ) {
|
||||
|
||||
// Allow empty arg to generate the default Options Page.
|
||||
if ( empty( $page ) ) {
|
||||
$page_title = __( 'Options', 'acf' );
|
||||
$page = array(
|
||||
'page_title' => $page_title,
|
||||
'menu_title' => $page_title,
|
||||
'menu_slug' => 'acf-options',
|
||||
);
|
||||
|
||||
// Allow string to define Options Page name.
|
||||
} elseif ( is_string( $page ) ) {
|
||||
$page_title = $page;
|
||||
$page = array(
|
||||
'page_title' => $page_title,
|
||||
'menu_title' => $page_title,
|
||||
);
|
||||
}
|
||||
|
||||
// Apply defaults.
|
||||
$page = wp_parse_args(
|
||||
$page,
|
||||
array(
|
||||
'page_title' => '',
|
||||
'menu_title' => '',
|
||||
'menu_slug' => '',
|
||||
'capability' => 'edit_posts',
|
||||
'parent_slug' => '',
|
||||
'position' => null,
|
||||
'icon_url' => false,
|
||||
'redirect' => true,
|
||||
'post_id' => 'options',
|
||||
'autoload' => false,
|
||||
'update_button' => __( 'Update', 'acf' ),
|
||||
'updated_message' => __( 'Options Updated', 'acf' ),
|
||||
)
|
||||
);
|
||||
|
||||
// Allow compatibility for changed settings.
|
||||
$migrate = array(
|
||||
'title' => 'page_title',
|
||||
'menu' => 'menu_title',
|
||||
'slug' => 'menu_slug',
|
||||
'parent' => 'parent_slug',
|
||||
);
|
||||
foreach ( $migrate as $old => $new ) {
|
||||
if ( ! empty( $page[ $old ] ) ) {
|
||||
$page[ $new ] = $page[ $old ];
|
||||
}
|
||||
}
|
||||
|
||||
// If no menu_title is set, use the page_title value.
|
||||
if ( empty( $page['menu_title'] ) ) {
|
||||
$page['menu_title'] = $page['page_title'];
|
||||
}
|
||||
|
||||
// If no menu_slug is set, generate one using the menu_title value.
|
||||
if ( empty( $page['menu_slug'] ) ) {
|
||||
$page['menu_slug'] = 'acf-options-' . sanitize_title( $page['menu_title'] );
|
||||
}
|
||||
|
||||
// Standardize on position being either null or int.
|
||||
$page['position'] = is_numeric( $page['position'] ) ? (int) $page['position'] : null;
|
||||
|
||||
/**
|
||||
* Filters the $page array after it has been validated.
|
||||
*
|
||||
* @since 5.5.8
|
||||
* @param array $page The Options Page settings array.
|
||||
*/
|
||||
return apply_filters( 'acf/validate_options_page', $page );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* add_page
|
||||
*
|
||||
* This function will store an options page settings
|
||||
*
|
||||
* @type function
|
||||
* @date 9/6/17
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @param $page (array)
|
||||
* @return n/a
|
||||
*/
|
||||
|
||||
function add_page( $page ) {
|
||||
|
||||
// validate
|
||||
$page = $this->validate_page( $page );
|
||||
$slug = $page['menu_slug'];
|
||||
|
||||
// bail ealry if already exists
|
||||
if ( isset( $this->pages[ $slug ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// append
|
||||
$this->pages[ $slug ] = $page;
|
||||
|
||||
// return
|
||||
return $page;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* add_sub_page
|
||||
*
|
||||
* description
|
||||
*
|
||||
* @type function
|
||||
* @date 9/6/17
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @param $post_id (int)
|
||||
* @return $post_id (int)
|
||||
*/
|
||||
|
||||
function add_sub_page( $page ) {
|
||||
|
||||
// validate
|
||||
$page = $this->validate_page( $page );
|
||||
|
||||
// default parent
|
||||
if ( ! $page['parent_slug'] ) {
|
||||
$page['parent_slug'] = 'acf-options';
|
||||
}
|
||||
|
||||
// create default parent if not yet exists
|
||||
if ( $page['parent_slug'] == 'acf-options' && ! $this->get_page( 'acf-options' ) ) {
|
||||
|
||||
$this->add_page( '' );
|
||||
|
||||
}
|
||||
|
||||
// return
|
||||
return $this->add_page( $page );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* update_page
|
||||
*
|
||||
* This function will update an options page settings
|
||||
*
|
||||
* @type function
|
||||
* @date 9/6/17
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @param $slug (string)
|
||||
* @param $data (array)
|
||||
* @return (array)
|
||||
*/
|
||||
|
||||
function update_page( $slug = '', $data = array() ) {
|
||||
|
||||
// vars
|
||||
$page = $this->get_page( $slug );
|
||||
|
||||
// bail early if no page
|
||||
if ( ! $page ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// loop
|
||||
$page = array_merge( $page, $data );
|
||||
|
||||
// set
|
||||
$this->pages[ $slug ] = $page;
|
||||
|
||||
// return
|
||||
return $page;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* get_page
|
||||
*
|
||||
* This function will return an options page settings
|
||||
*
|
||||
* @type function
|
||||
* @date 6/07/2016
|
||||
* @since 5.4.0
|
||||
*
|
||||
* @param $slug (string)
|
||||
* @return (mixed)
|
||||
*/
|
||||
|
||||
function get_page( $slug ) {
|
||||
|
||||
return isset( $this->pages[ $slug ] ) ? $this->pages[ $slug ] : null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* get_pages
|
||||
*
|
||||
* This function will return all options page settings
|
||||
*
|
||||
* @type function
|
||||
* @date 6/07/2016
|
||||
* @since 5.4.0
|
||||
*
|
||||
* @param $slug (string)
|
||||
* @return (mixed)
|
||||
*/
|
||||
|
||||
function get_pages() {
|
||||
|
||||
return $this->pages;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* acf_options_page
|
||||
*
|
||||
* This function will return the options page instance
|
||||
*
|
||||
* @type function
|
||||
* @date 9/6/17
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @param n/a
|
||||
* @return (object)
|
||||
*/
|
||||
|
||||
function acf_options_page() {
|
||||
|
||||
global $acf_options_page;
|
||||
|
||||
if ( ! isset( $acf_options_page ) ) {
|
||||
|
||||
$acf_options_page = new acf_options_page();
|
||||
|
||||
}
|
||||
|
||||
return $acf_options_page;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// remove Options Page add-on conflict
|
||||
unset( $GLOBALS['acf_options_page'] );
|
||||
|
||||
|
||||
// initialize
|
||||
acf_options_page();
|
||||
|
||||
|
||||
endif; // class_exists check
|
||||
|
||||
|
||||
/*
|
||||
* acf_add_options_page
|
||||
*
|
||||
* alias of acf_options_page()->add_page()
|
||||
*
|
||||
* @type function
|
||||
* @date 24/02/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param $page (mixed)
|
||||
* @return (array)
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'acf_add_options_page' ) ) :
|
||||
|
||||
function acf_add_options_page( $page = '' ) {
|
||||
|
||||
return acf_options_page()->add_page( $page );
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
|
||||
/*
|
||||
* acf_add_options_sub_page
|
||||
*
|
||||
* alias of acf_options_page()->add_sub_page()
|
||||
*
|
||||
* @type function
|
||||
* @date 24/02/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param $page (mixed)
|
||||
* @return (array)
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'acf_add_options_sub_page' ) ) :
|
||||
|
||||
function acf_add_options_sub_page( $page = '' ) {
|
||||
|
||||
return acf_options_page()->add_sub_page( $page );
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
|
||||
/*
|
||||
* acf_update_options_page
|
||||
*
|
||||
* alias of acf_options_page()->update_page()
|
||||
*
|
||||
* @type function
|
||||
* @date 24/02/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param $slug (string)
|
||||
* @param $page (mixed)
|
||||
* @return (array)
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'acf_update_options_page' ) ) :
|
||||
|
||||
function acf_update_options_page( $slug = '', $data = array() ) {
|
||||
|
||||
return acf_options_page()->update_page( $slug, $data );
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
|
||||
/*
|
||||
* acf_get_options_page
|
||||
*
|
||||
* This function will return an options page settings
|
||||
*
|
||||
* @type function
|
||||
* @date 24/02/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param $slug (string)
|
||||
* @return (array)
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'acf_get_options_page' ) ) :
|
||||
|
||||
function acf_get_options_page( $slug ) {
|
||||
|
||||
// vars
|
||||
$page = acf_options_page()->get_page( $slug );
|
||||
|
||||
// bail early if no page
|
||||
if ( ! $page ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// filter
|
||||
$page = apply_filters( 'acf/get_options_page', $page, $slug );
|
||||
|
||||
// return
|
||||
return $page;
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
|
||||
/*
|
||||
* acf_get_options_pages
|
||||
*
|
||||
* This function will return all options page settings
|
||||
*
|
||||
* @type function
|
||||
* @date 24/02/2014
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param n/a
|
||||
* @return (array)
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'acf_get_options_pages' ) ) :
|
||||
|
||||
function acf_get_options_pages() {
|
||||
|
||||
// global
|
||||
global $_wp_last_utility_menu;
|
||||
|
||||
// vars
|
||||
$pages = acf_options_page()->get_pages();
|
||||
|
||||
// bail early if no pages
|
||||
if ( empty( $pages ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// apply filter to each page
|
||||
foreach ( $pages as $slug => &$page ) {
|
||||
|
||||
$page = acf_get_options_page( $slug );
|
||||
|
||||
}
|
||||
|
||||
// calculate parent => child redirectes
|
||||
foreach ( $pages as $slug => &$page ) {
|
||||
|
||||
// bail early if is child
|
||||
if ( $page['parent_slug'] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// add missing position
|
||||
if ( ! $page['position'] ) {
|
||||
|
||||
$_wp_last_utility_menu++;
|
||||
$page['position'] = $_wp_last_utility_menu;
|
||||
|
||||
}
|
||||
|
||||
// bail early if no redirect
|
||||
if ( ! $page['redirect'] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// vars
|
||||
$parent = $page['menu_slug'];
|
||||
$child = '';
|
||||
|
||||
// update children
|
||||
foreach ( $pages as &$sub_page ) {
|
||||
|
||||
// bail early if not child of this parent
|
||||
if ( $sub_page['parent_slug'] !== $parent ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// set child (only once)
|
||||
if ( ! $child ) {
|
||||
$child = $sub_page['menu_slug'];
|
||||
}
|
||||
|
||||
// update parent_slug to the first child
|
||||
$sub_page['parent_slug'] = $child;
|
||||
|
||||
}
|
||||
|
||||
// finally update parent menu_slug
|
||||
if ( $child ) {
|
||||
$page['menu_slug'] = $child;
|
||||
}
|
||||
}
|
||||
|
||||
// filter
|
||||
$pages = apply_filters( 'acf/get_options_pages', $pages );
|
||||
|
||||
// return
|
||||
return $pages;
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
|
||||
/*
|
||||
* acf_set_options_page_title
|
||||
*
|
||||
* This function is used to customize the options page admin menu title
|
||||
*
|
||||
* @type function
|
||||
* @date 13/07/13
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param $title (string)
|
||||
* @return n/a
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'acf_set_options_page_title' ) ) :
|
||||
|
||||
function acf_set_options_page_title( $title = 'Options' ) {
|
||||
|
||||
acf_update_options_page(
|
||||
'acf-options',
|
||||
array(
|
||||
'page_title' => $title,
|
||||
'menu_title' => $title,
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
|
||||
/*
|
||||
* acf_set_options_page_menu
|
||||
*
|
||||
* This function is used to customize the options page admin menu name
|
||||
*
|
||||
* @type function
|
||||
* @date 13/07/13
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param $title (string)
|
||||
* @return n/a
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'acf_set_options_page_menu' ) ) :
|
||||
|
||||
function acf_set_options_page_menu( $title = 'Options' ) {
|
||||
|
||||
acf_update_options_page(
|
||||
'acf-options',
|
||||
array(
|
||||
'menu_title' => $title,
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
|
||||
/*
|
||||
* acf_set_options_page_capability
|
||||
*
|
||||
* This function is used to customize the options page capability. Defaults to 'edit_posts'
|
||||
*
|
||||
* @type function
|
||||
* @date 13/07/13
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param $title (string)
|
||||
* @return n/a
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'acf_set_options_page_capability' ) ) :
|
||||
|
||||
function acf_set_options_page_capability( $capability = 'edit_posts' ) {
|
||||
|
||||
acf_update_options_page(
|
||||
'acf-options',
|
||||
array(
|
||||
'capability' => $capability,
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
|
||||
/*
|
||||
* register_options_page()
|
||||
*
|
||||
* This is an old function which is now referencing the new 'acf_add_options_sub_page' function
|
||||
*
|
||||
* @type function
|
||||
* @since 3.0.0
|
||||
* @date 29/01/13
|
||||
*
|
||||
* @param {string} $title
|
||||
* @return N/A
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'register_options_page' ) ) :
|
||||
|
||||
function register_options_page( $page = '' ) {
|
||||
|
||||
acf_add_options_sub_page( $page );
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
|
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'acf_pro_updates' ) ) :
|
||||
|
||||
class acf_pro_updates {
|
||||
|
||||
|
||||
/*
|
||||
* __construct
|
||||
*
|
||||
* Initialize filters, action, variables and includes
|
||||
*
|
||||
* @type function
|
||||
* @date 23/06/12
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param n/a
|
||||
* @return n/a
|
||||
*/
|
||||
|
||||
function __construct() {
|
||||
|
||||
// actions
|
||||
add_action( 'init', array( $this, 'init' ), 20 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* init
|
||||
*
|
||||
* description
|
||||
*
|
||||
* @type function
|
||||
* @date 10/4/17
|
||||
* @since 5.5.10
|
||||
*
|
||||
* @param $post_id (int)
|
||||
* @return $post_id (int)
|
||||
*/
|
||||
|
||||
function init() {
|
||||
|
||||
// bail early if no show_updates
|
||||
if ( ! acf_get_setting( 'show_updates' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// bail early if not a plugin (included in theme)
|
||||
if ( ! acf_is_plugin_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// register update
|
||||
acf_register_plugin_update(
|
||||
array(
|
||||
'id' => 'pro',
|
||||
'key' => acf_pro_get_license_key(),
|
||||
'slug' => acf_get_setting( 'slug' ),
|
||||
'basename' => acf_get_setting( 'basename' ),
|
||||
'version' => acf_get_setting( 'version' ),
|
||||
)
|
||||
);
|
||||
|
||||
// admin
|
||||
if ( is_admin() ) {
|
||||
|
||||
add_action( 'in_plugin_update_message-' . acf_get_setting( 'basename' ), array( $this, 'modify_plugin_update_message' ), 10, 2 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* modify_plugin_update_message
|
||||
*
|
||||
* Displays an update message for plugin list screens.
|
||||
*
|
||||
* @type function
|
||||
* @date 14/06/2016
|
||||
* @since 5.3.8
|
||||
*
|
||||
* @param $message (string)
|
||||
* @param $plugin_data (array)
|
||||
* @param $r (object)
|
||||
* @return $message
|
||||
*/
|
||||
|
||||
function modify_plugin_update_message( $plugin_data, $response ) {
|
||||
|
||||
// bail ealry if has key
|
||||
if ( acf_pro_get_license_key() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// display message
|
||||
echo '<br />' . sprintf( __( 'To enable updates, please enter your license key on the <a href="%1$s">Updates</a> page. If you don\'t have a licence key, please see <a href="%2$s" target="_blank">details & pricing</a>.', 'acf' ), admin_url( 'edit.php?post_type=acf-field-group&page=acf-settings-updates' ), 'https://www.advancedcustomfields.com/pro/?utm_source=ACF%2Bpro%2Bplugin&utm_medium=insideplugin&utm_campaign=ACF%2Bupgrade&utm_content=updates' );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// initialize
|
||||
new acf_pro_updates();
|
||||
|
||||
endif; // class_exists check
|
||||
|
||||
|
||||
/*
|
||||
* acf_pro_get_license
|
||||
*
|
||||
* This function will return the license
|
||||
*
|
||||
* @type function
|
||||
* @date 20/09/2016
|
||||
* @since 5.4.0
|
||||
*
|
||||
* @param n/a
|
||||
* @return n/a
|
||||
*/
|
||||
|
||||
function acf_pro_get_license() {
|
||||
|
||||
// get option
|
||||
$license = get_option( 'acf_pro_license' );
|
||||
|
||||
// bail early if no value
|
||||
if ( ! $license ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// decode
|
||||
$license = maybe_unserialize( base64_decode( $license ) );
|
||||
|
||||
// bail early if corrupt
|
||||
if ( ! is_array( $license ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// return
|
||||
return $license;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* acf_pro_get_license_key
|
||||
*
|
||||
* This function will return the license key
|
||||
*
|
||||
* @type function
|
||||
* @date 20/09/2016
|
||||
* @since 5.4.0
|
||||
*
|
||||
* @param n/a
|
||||
* @return n/a
|
||||
*/
|
||||
|
||||
function acf_pro_get_license_key() {
|
||||
|
||||
// vars
|
||||
$license = acf_pro_get_license();
|
||||
$home_url = home_url();
|
||||
|
||||
// bail early if empty
|
||||
if ( ! $license || ! $license['key'] ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// bail early if url has changed
|
||||
if ( acf_strip_protocol( $license['url'] ) !== acf_strip_protocol( $home_url ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// return
|
||||
return $license['key'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* acf_pro_update_license
|
||||
*
|
||||
* This function will update the DB license
|
||||
*
|
||||
* @type function
|
||||
* @date 20/09/2016
|
||||
* @since 5.4.0
|
||||
*
|
||||
* @param $key (string)
|
||||
* @return n/a
|
||||
*/
|
||||
|
||||
function acf_pro_update_license( $key = '' ) {
|
||||
|
||||
// vars
|
||||
$value = '';
|
||||
|
||||
// key
|
||||
if ( $key ) {
|
||||
|
||||
// vars
|
||||
$data = array(
|
||||
'key' => $key,
|
||||
'url' => home_url(),
|
||||
);
|
||||
|
||||
// encode
|
||||
$value = base64_encode( maybe_serialize( $data ) );
|
||||
|
||||
}
|
||||
|
||||
// re-register update (key has changed)
|
||||
acf_register_plugin_update(
|
||||
array(
|
||||
'id' => 'pro',
|
||||
'key' => $key,
|
||||
'slug' => acf_get_setting( 'slug' ),
|
||||
'basename' => acf_get_setting( 'basename' ),
|
||||
'version' => acf_get_setting( 'version' ),
|
||||
)
|
||||
);
|
||||
|
||||
// update
|
||||
return update_option( 'acf_pro_license', $value );
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user