initial commit

This commit is contained in:
2024-04-29 13:12:44 +05:45
commit 34887303c5
19300 changed files with 5268802 additions and 0 deletions

View File

@ -0,0 +1,346 @@
<?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'] );
/**
* Fires after publishing a save on an options page.
*
* @since 6.1.7
*
* @param string|int $post_id The current id.
* @param string $menu_slug The current options page menu slug.
*/
do_action( 'acf/options_page/save', $this->page['post_id'], $this->page['menu_slug'] );
// 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' ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Used to display a notice.
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
}
/**
* Renders a postbox on an ACF options page.
*
* @date 24/02/2014
* @since 5.0.0
*
* @param object $post
* @param array $args
*
* @return void
*/
function postbox_acf( $post, $args ) {
$id = $args['id'];
$field_group = $args['args']['field_group'];
// 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( __DIR__ . '/views/html-options-page.php', $this->page );
}
}
// initialize
new acf_admin_options_page();
endif;
?>

View File

@ -0,0 +1,263 @@
<?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' => __( '<strong>Error</strong>. Could not connect to the 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 the updates page is not visible.
if ( ! acf_is_updates_page_visible() ) {
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() {
add_action( 'admin_body_class', array( $this, 'admin_body_class' ) );
// Check activate.
if ( acf_verify_nonce( 'activate_pro_license' ) ) {
acf_pro_activate_license( sanitize_text_field( $_POST['acf_pro_license'] ) );
// Check deactivate.
} elseif ( acf_verify_nonce( 'deactivate_pro_license' ) ) {
acf_pro_deactivate_license();
}
// vars
$license = acf_pro_get_license_key();
$this->view = array(
'license' => $license,
'license_status' => acf_pro_get_license_status( ! empty( $_GET['acf-recheck-license'] ) ),
'active' => $license ? 1 : 0,
'current_version' => acf_get_setting( 'version' ),
'remote_version' => '',
'update_available' => false,
'changelog' => '',
'upgrade_notice' => '',
'is_defined_license' => defined( 'ACF_PRO_LICENSE' ) && ! empty( ACF_PRO_LICENSE ) && is_string( ACF_PRO_LICENSE ),
'license_error' => false,
'wp_not_compatible' => false,
);
// 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 );
$no_update = acf_updates()->get_no_update( $basename );
if ( $no_update && ! empty( $no_update['reason'] ) && $no_update['reason'] === 'wp_not_compatible' ) {
$this->view['wp_not_compatible'] = true;
acf_new_admin_notice(
array(
/* translators: %s the version of WordPress required for this ACF update */
'text' => sprintf( __( 'An update to ACF is available, but it is not compatible with your version of WordPress. Please upgrade to WordPress %s or newer to update ACF.', 'acf' ), $no_update['requires'] ),
'type' => 'error',
)
);
}
if ( $license ) {
if ( isset( $update['license_valid'] ) && ! $update['license_valid'] ) {
$this->view['license_error'] = true;
acf_new_admin_notice(
array(
'text' => __( '<strong>Error</strong>. Your license for this site has expired or been deactivated. Please reactivate your ACF PRO license.', 'acf' ),
'type' => 'error',
)
);
} else {
// display error if no package url - possible if license key or site URL has been modified.
if ( $update && ! $update['package'] ) {
$this->view['license_error'] = true;
acf_new_admin_notice(
array(
'text' => __( '<strong>Error</strong>. 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();
}
}
}
}
/**
* Modifies the admin body class.
*
* @since 6.0.0
*
* @param string $classes Space-separated list of CSS classes.
* @return string
*/
public function admin_body_class( $classes ) {
$classes .= ' acf-admin-page';
return $classes;
}
/**
* html
*
* Displays the submenu page's HTML.
*
* @date 7/01/2014
* @since 5.0.0
*
* @param void
* @return void
*/
function html() {
acf_get_view( __DIR__ . '/views/html-settings-updates.php', $this->view );
}
}
// Initialize.
acf_new_instance( 'ACF_Admin_Updates' );
endif; // class_exists check

View File

@ -0,0 +1,499 @@
<?php
/**
* ACF Admin Post Type Class
*
* @package ACF
* @subpackage Admin
*/
if ( ! class_exists( 'ACF_Admin_UI_Options_Page' ) ) :
/**
* ACF Admin UI Options Page Class
*
* All the logic for editing an options page in the UI.
*/
class ACF_Admin_UI_Options_Page extends ACF_Admin_Internal_Post_Type {
/**
* The slug for the internal post type.
*
* @since 6.1
* @var string
*/
public $post_type = 'acf-ui-options-page';
/**
* The admin body class used for the post type.
*
* @since 6.1
* @var string
*/
public $admin_body_class = 'acf-admin-single-options-page';
/**
* Constructs the class.
*/
public function __construct() {
add_action( 'wp_ajax_acf/create_options_page', array( $this, 'ajax_create_options_page' ) );
add_action( 'acf/field_group/admin_enqueue_scripts', array( $this, 'add_js_parent_choices' ) );
parent::__construct();
}
/**
* This function will customize the message shown when editing a post type.
*
* @since 6.2
*
* @param array $messages Post type messages.
* @return array
*/
public function post_updated_messages( $messages ) {
$messages['acf-ui-options-page'] = array(
0 => '', // Unused. Messages start at index 1.
1 => $this->options_page_created_message(), // Updated.
2 => $this->options_page_created_message(),
3 => __( 'Options page deleted.', 'acf' ),
4 => __( 'Options page updated.', 'acf' ),
5 => false, // Post type does not support revisions.
6 => $this->options_page_created_message( true ), // Created.
7 => __( 'Options page saved.', 'acf' ),
8 => __( 'Options page submitted.', 'acf' ),
9 => __( 'Options page scheduled for.', 'acf' ),
10 => __( 'Options page draft updated.', 'acf' ),
);
return $messages;
}
/**
* Renders the options page created message.
*
* @since 6.1
*
* @param boolean $created True if the options page was just created.
* @return string
*/
public function options_page_created_message( $created = false ) {
global $post_id;
$title = get_the_title( $post_id );
/* translators: %s options page name */
$item_saved_text = sprintf( __( '%s options page updated', 'acf' ), $title );
/* translators: %s options page name */
$add_fields_text = sprintf( __( 'Add fields to %s', 'acf' ), $title );
if ( $created ) {
/* translators: %s options page name */
$item_saved_text = sprintf( __( '%s options page created', 'acf' ), $title );
}
$add_fields_link = wp_nonce_url(
admin_url( 'post-new.php?post_type=acf-field-group&use_options_page=' . $post_id ),
'add-fields-' . $post_id
);
ob_start();
?>
<p class="acf-item-saved-text"><?php echo esc_html( $item_saved_text ); ?></p>
<div class="acf-item-saved-links">
<a href="<?php echo esc_url( $add_fields_link ); ?>"><?php echo esc_html( $add_fields_text ); ?></a>
<a class="acf-link-field-groups" href="#"><?php esc_html_e( 'Link existing field groups', 'acf' ); ?></a>
</div>
<?php
return ob_get_clean();
}
/**
* Allow other pages to get available option page parents.
*
* @since 6.2
*/
public function add_js_parent_choices() {
acf_localize_data(
array(
'optionPageParentOptions' => $this->get_parent_page_choices(),
)
);
}
/**
* Enqueues any scripts necessary for internal post type.
*
* @since 6.2
*/
public function admin_enqueue_scripts() {
wp_enqueue_style( 'acf-field-group' );
acf_localize_text(
array(
'Post' => __( 'Post', 'acf' ),
'Posts' => __( 'Posts', 'acf' ),
'Page' => __( 'Page', 'acf' ),
'Pages' => __( 'Pages', 'acf' ),
'Default' => __( 'Default', 'acf' ),
)
);
parent::admin_enqueue_scripts();
do_action( 'acf/ui_options_page/admin_enqueue_scripts' );
}
/**
* Sets up all functionality for the post type edit page to work.
*
* @since 3.1.8
*
* @return void
*/
public function admin_head() {
// global.
global $post, $acf_ui_options_page;
// set global var.
$acf_ui_options_page = acf_get_internal_post_type( $post->ID, $this->post_type );
// metaboxes.
add_meta_box( 'acf-basic-settings', __( 'Basic Settings', 'acf' ), array( $this, 'mb_basic_settings' ), 'acf-ui-options-page', 'normal', 'high' );
add_meta_box( 'acf-advanced-settings', __( 'Advanced Settings', 'acf' ), array( $this, 'mb_advanced_settings' ), 'acf-ui-options-page', 'normal', 'high' );
// actions.
add_action( 'post_submitbox_misc_actions', array( $this, 'post_submitbox_misc_actions' ), 10, 0 );
add_action( 'edit_form_after_title', array( $this, 'edit_form_after_title' ), 10, 0 );
// filters.
add_filter( 'screen_settings', array( $this, 'screen_settings' ), 10, 1 );
add_filter( 'get_user_option_screen_layout_acf-ui-options-page', array( $this, 'screen_layout' ), 10, 1 );
add_filter( 'get_user_option_metaboxhidden_acf-ui-options-page', array( $this, 'force_basic_settings' ), 10, 1 );
add_filter( 'get_user_option_closedpostboxes_acf-ui-options-page', array( $this, 'force_basic_settings' ), 10, 1 );
add_filter( 'get_user_option_closedpostboxes_acf-ui-options-page', array( $this, 'force_advanced_settings' ), 10, 1 );
// 3rd party hook.
do_action( 'acf/ui_options_page/admin_head' );
}
/**
* This action will allow ACF to render metaboxes after the title.
*
* @return void
*/
public function edit_form_after_title() {
// globals.
global $post;
// render post data.
acf_form_data(
array(
'screen' => 'ui_options_page',
'post_id' => $post->ID,
'delete_fields' => 0,
'validation' => 1,
)
);
}
/**
* This function will add extra HTML to the acf form data element
*
* @since 5.3.8
*
* @param array $args Arguments array to pass through to action.
* @return void
*/
public function form_data( $args ) {
do_action( 'acf/ui_options_page/form_data', $args );
}
/**
* This function will append extra l10n strings to the acf JS object
*
* @since 5.3.8
*
* @param array $l10n The array of translated strings.
* @return array $l10n
*/
public function admin_l10n( $l10n ) {
return apply_filters( 'acf/ui_options_page/admin_l10n', $l10n );
}
/**
* Admin footer third party hook support
*
* @since 5.3.2
*
* @return void
*/
public function admin_footer() {
do_action( 'acf/ui_options_page/admin_footer' );
}
/**
* Screen settings html output
*
* @since 3.6.0
*
* @param string $html Current screen settings HTML.
* @return string $html
*/
public function screen_settings( $html ) {
return $html;
}
/**
* Sets the "Edit Post Type" screen to use a one-column layout.
*
* @param integer $columns Number of columns for layout.
*
* @return integer
*/
public function screen_layout( $columns = 0 ) {
return 1;
}
/**
* Force basic settings to always be visible
*
* @param array $hidden_metaboxes The metaboxes hidden on this page.
*
* @return array
*/
public function force_basic_settings( $hidden_metaboxes ) {
if ( ! is_array( $hidden_metaboxes ) ) {
return $hidden_metaboxes;
}
return array_diff( $hidden_metaboxes, array( 'acf-basic-settings' ) );
}
/**
* Force advanced settings to be visible
*
* @param array $hidden_metaboxes The metaboxes hidden on this page.
*
* @return array
*/
public function force_advanced_settings( $hidden_metaboxes ) {
if ( ! is_array( $hidden_metaboxes ) ) {
return $hidden_metaboxes;
}
return array_diff( $hidden_metaboxes, array( 'acf-advanced-settings' ) );
}
/**
* This function will customize the publish metabox
*
* @since 5.2.9
*
* @return void
*/
public function post_submitbox_misc_actions() {
global $acf_ui_options_page;
$status_label = $acf_ui_options_page['active'] ? _x( 'Active', 'post status', 'acf' ) : _x( 'Inactive', 'post status', 'acf' );
?>
<script type="text/javascript">
(function($) {
$('#post-status-display').html( '<?php echo esc_html( $status_label ); ?>' );
})(jQuery);
</script>
<?php
}
/**
* Saves post type data.
*
* @since 1.0.0
*
* @param integer $post_id The post ID.
* @param WP_Post $post The post object.
*
* @return integer $post_id
*/
public function save_post( $post_id, $post ) {
if ( ! $this->verify_save_post( $post_id, $post ) ) {
return $post_id;
}
// Disable filters to ensure ACF loads raw data from DB.
acf_disable_filters();
// phpcs:disable WordPress.Security.NonceVerification.Missing -- Validated in $this->verify_save_post() above.
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized when saved.
$_POST['acf_ui_options_page']['ID'] = $post_id;
$_POST['acf_ui_options_page']['title'] = isset( $_POST['acf_ui_options_page']['page_title'] ) ? $_POST['acf_ui_options_page']['page_title'] : '';
// Save the post type.
acf_update_internal_post_type( $_POST['acf_ui_options_page'], $this->post_type ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Validated in verify_save_post
// phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
// phpcs:enable WordPress.Security.NonceVerification.Missing
return $post_id;
}
/**
* Renders HTML for the basic settings metabox.
*
* @since 6.2
*
* @return void
*/
public function mb_basic_settings() {
global $acf_ui_options_page, $acf_parent_page_options;
if ( ! acf_is_internal_post_type_key( $acf_ui_options_page['key'], 'acf-ui-options-page' ) ) {
$acf_ui_options_page['key'] = uniqid( 'ui_options_page_' );
}
$acf_parent_page_options = $this->get_parent_page_choices( (int) $acf_ui_options_page['ID'] );
acf_get_view( __DIR__ . '/../views/acf-ui-options-page/basic-settings.php' );
}
/**
* Renders the HTML for the advanced settings metabox.
*
* @since 6.2
*
* @return void
*/
public function mb_advanced_settings() {
acf_get_view( __DIR__ . '/../views/acf-ui-options-page/advanced-settings.php' );
}
/**
* Iterates through the registered options pages and finds eligible parent pages.
*
* @since 6.2
*
* @param integer $post_id The post ID of a current ACF UI options page used to prevent selection of itself as a child.
* @return array
*/
public function get_parent_page_choices( int $post_id = 0 ) {
global $menu;
$acf_all_options_pages = acf_get_options_pages();
$acf_parent_page_choices = array( 'None' => array( 'none' => __( 'No Parent', 'acf' ) ) );
if ( is_array( $acf_all_options_pages ) ) {
foreach ( $acf_all_options_pages as $options_page ) {
// Can't assign to child pages.
if ( ! empty( $options_page['parent_slug'] ) ) {
continue;
}
// Can't be a child of itself.
if ( isset( $options_page['ID'] ) && $post_id === $options_page['ID'] ) {
continue;
}
$acf_parent_menu_slug = ! empty( $options_page['menu_slug'] ) ? $options_page['menu_slug'] : '';
// ACF overrides the `menu_slug` of parent pages with one child so they redirect to the child.
if ( ! empty( $options_page['_menu_slug'] ) ) {
$acf_parent_menu_slug = $options_page['_menu_slug'];
}
$acf_parent_page_choices['acfOptionsPages'][ $acf_parent_menu_slug ] = ! empty( $options_page['page_title'] ) ? $options_page['page_title'] : $options_page['menu_slug'];
}
}
foreach ( $menu as $item ) {
if ( ! empty( $item[0] ) ) {
$page_name = $item[0];
$markup = '/<[^>]+>.*<\/[^>]+>/';
$sanitized_name = preg_replace( $markup, '', $page_name );
// Ensure that the current item is not an ACF page or that ACF pages are an empty array before adding to others.
if ( ! empty( $acf_parent_page_choices['acfOptionsPages'] ) && ! in_array( $page_name, $acf_parent_page_choices['acfOptionsPages'], true ) || empty( $acf_parent_page_choices['acfOptionsPages'] ) ) {
// If matched menu slug is not in the list add it to others.
$acf_parent_page_choices['Others'][ $item[2] ] = acf_esc_html( $sanitized_name );
}
}
}
return $acf_parent_page_choices;
}
/**
* Creates a simple options page over AJAX.
*
* @since 6.2
* @return void
*/
public function ajax_create_options_page() {
// Disable filters to ensure ACF loads raw data from DB.
acf_disable_filters();
// phpcs:disable WordPress.Security.NonceVerification.Missing
$args = acf_parse_args(
$_POST,
array(
'nonce' => '',
'post_id' => 0,
'acf_ui_options_page' => array(),
'field_group_title' => '',
'acf_parent_page_choices' => array(),
)
);
// phpcs:enable WordPress.Security.NonceVerification.Missing
// Verify nonce and user capability.
if ( ! wp_verify_nonce( $args['nonce'], 'acf_nonce' ) || ! acf_current_user_can_admin() || ! $args['post_id'] ) {
die();
}
// Process form data.
if ( ! empty( $args['acf_ui_options_page'] ) ) {
// Prepare for save.
$options_page = acf_validate_internal_post_type( $args['acf_ui_options_page'], 'acf-ui-options-page' );
$options_page['key'] = uniqid( 'ui_options_page_' );
$options_page['title'] = ! empty( $args['acf_ui_options_page']['page_title'] ) ? $args['acf_ui_options_page']['page_title'] : '';
$existing_options_pages = acf_get_options_pages();
// Check for duplicates.
if ( ! empty( $existing_options_pages ) ) {
foreach ( $existing_options_pages as $existing_options_page ) {
if ( $existing_options_page['menu_slug'] === $options_page['menu_slug'] ) {
wp_send_json_error(
array(
'error' => __( 'The provided Menu Slug already exists.', 'acf' ),
)
);
}
}
}
// Save the options page.
acf_update_internal_post_type( $options_page, 'acf-ui-options-page' );
wp_send_json_success(
array(
'page_title' => esc_html( $options_page['page_title'] ),
'menu_slug' => esc_attr( $options_page['menu_slug'] ),
)
);
}
// Render the form.
ob_start();
acf_get_view(
__DIR__ . '/../views/acf-ui-options-page/create-options-page-modal.php',
array(
'field_group_title' => $args['field_group_title'],
'acf_parent_page_choices' => $args['acf_parent_page_choices'],
)
);
$content = ob_get_clean();
wp_send_json_success(
array(
'content' => $content,
'title' => esc_html__( 'Add New Options Page', 'acf' ),
)
);
}
}
new ACF_Admin_UI_Options_Page();
endif; // Class exists check.

View File

@ -0,0 +1,216 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'ACF_Admin_UI_Options_Pages' ) ) :
/**
* The ACF Post Types admin controller class
*/
#[AllowDynamicProperties]
class ACF_Admin_UI_Options_Pages extends ACF_Admin_Internal_Post_Type_List {
/**
* The slug for the internal post type.
*
* @since 6.1
* @var string
*/
public $post_type = 'acf-ui-options-page';
/**
* The admin body class used for the post type.
*
* @since 6.1
* @var string
*/
public $admin_body_class = 'acf-admin-options-pages';
/**
* The name of the store used for the post type.
*
* @var string
*/
public $store = 'options-pages';
/**
* If this is a pro feature or not.
*
* @var bool
*/
public $is_pro_feature = true;
/**
* Constructor.
*
* @since 6.2
*
* @return void
*/
public function __construct() {
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
parent::__construct();
}
/**
* Current screen actions for the post types list admin page.
*
* @since 6.1
*
* @return void
*/
public function current_screen() {
// Bail early if not post types admin page.
if ( ! acf_is_screen( "edit-{$this->post_type}" ) ) {
return;
}
parent::current_screen();
// Run a first-run routine to set some defaults which are stored in user preferences.
if ( ! acf_get_user_setting( 'options-pages-first-run', false ) ) {
$option_key = 'manageedit-' . $this->post_type . 'columnshidden';
$hidden_items = get_user_option( $option_key );
if ( ! is_array( $hidden_items ) ) {
$hidden_items = array();
}
if ( ! in_array( 'acf-key', $hidden_items ) ) {
$hidden_items[] = 'acf-key';
}
update_user_option( get_current_user_id(), $option_key, $hidden_items, true );
acf_update_user_setting( 'options-pages-first-run', true );
}
}
/**
* Add any menu items required for post types.
*
* @since 6.1
*/
public function admin_menu() {
$parent_slug = 'edit.php?post_type=acf-field-group';
$cap = acf_get_setting( 'capability' );
add_submenu_page( $parent_slug, __( 'Options Pages', 'acf' ), __( 'Options Pages', 'acf' ), $cap, 'edit.php?post_type=acf-ui-options-page' );
}
/**
* Customizes the admin table columns.
*
* @date 1/4/20
* @since 5.9.0
*
* @param array $_columns The columns array.
* @return array
*/
public function admin_table_columns( $_columns ) {
// Set the "no found" label to be our custom HTML for no results.
if ( empty( acf_request_arg( 's' ) ) ) {
global $wp_post_types;
$this->not_found_label = $wp_post_types[ $this->post_type ]->labels->not_found;
$wp_post_types[ $this->post_type ]->labels->not_found = $this->get_not_found_html();
}
$columns = array(
'cb' => $_columns['cb'],
'title' => $_columns['title'],
'acf-description' => __( 'Description', 'acf' ),
'acf-key' => __( 'Key', 'acf' ),
);
if ( acf_get_local_json_files( $this->post_type ) ) {
$columns['acf-json'] = __( 'Local JSON', 'acf' );
}
return $columns;
}
/**
* Renders a specific admin table column.
*
* @date 17/4/20
* @since 5.9.0
*
* @param string $column_name The name of the column to display.
* @param array $post The main ACF post array.
* @return void
*/
public function render_admin_table_column( $column_name, $post ) {
switch ( $column_name ) {
case 'acf-key':
echo '<i class="acf-icon acf-icon-key-solid"></i>';
echo esc_html( $post['key'] );
break;
// Description.
case 'acf-description':
if ( ! empty( $post['description'] ) && is_string( $post['description'] ) ) {
echo '<span class="acf-description">' . acf_esc_html( $post['description'] ) . '</span>';
} else {
echo '<span class="acf-emdash" aria-hidden="true">—</span>';
echo '<span class="screen-reader-text">' . esc_html__( 'No description', 'acf' ) . '</span>';
}
break;
// Local JSON.
case 'acf-json':
$this->render_admin_table_column_local_status( $post );
break;
}
}
/**
* Gets the translated action notice text for list table actions (activate, deactivate, sync, etc.).
*
* @since 6.1
*
* @param string $action The action being performed.
* @param int $count The number of items the action was performed on.
* @return string
*/
public function get_action_notice_text( $action, $count = 1 ) {
$text = '';
$count = (int) $count;
switch ( $action ) {
case 'acfactivatecomplete':
$text = sprintf(
/* translators: %s number of post types activated */
_n( 'Options page activated.', '%s options pages activated.', $count, 'acf' ),
$count
);
break;
case 'acfdeactivatecomplete':
$text = sprintf(
/* translators: %s number of post types deactivated */
_n( 'Options page deactivated.', '%s options pages deactivated.', $count, 'acf' ),
$count
);
break;
case 'acfduplicatecomplete':
$text = sprintf(
/* translators: %s number of post types duplicated */
_n( 'Options page duplicated.', '%s options pages duplicated.', $count, 'acf' ),
$count
);
break;
case 'acfsynccomplete':
$text = sprintf(
/* translators: %s number of post types synchronized */
_n( 'Options page synchronized.', '%s options pages synchronized.', $count, 'acf' ),
$count
);
break;
}
return $text;
}
}
// Instantiate.
acf_new_instance( 'ACF_Admin_UI_Options_Pages' );
endif; // Class exists check.

View File

@ -0,0 +1,278 @@
<?php
global $acf_ui_options_page;
foreach ( acf_get_combined_options_page_settings_tabs() as $tab_key => $tab_label ) {
acf_render_field_wrap(
array(
'type' => 'tab',
'label' => $tab_label,
'key' => 'acf_ui_options_page_tabs',
)
);
$wrapper_class = str_replace( '_', '-', $tab_key );
echo '<div class="acf-ui-options-page-advanced-settings acf-ui-options-page-' . esc_attr( $wrapper_class ) . '-settings">';
switch ( $tab_key ) {
case 'visibility':
$acf_dashicon_class_name = __( 'Dashicon class name', 'acf' );
$acf_dashicon_link = '<a href="https://developer.wordpress.org/resource/dashicons/" target="_blank">' . $acf_dashicon_class_name . '</a>';
$acf_menu_icon_instructions = sprintf(
/* translators: %s = "dashicon class name", link to the WordPress dashicon documentation. */
__( 'The icon used for the options page menu item in the admin dashboard. Can be a URL or %s to use for the icon.', 'acf' ),
$acf_dashicon_link
);
acf_render_field_wrap(
array(
'label' => __( 'Menu Icon', 'acf' ),
'type' => 'text',
'name' => 'icon_url',
'key' => 'icon_url',
'class' => 'acf-options-page-menu_icon',
'prefix' => 'acf_ui_options_page',
'value' => $acf_ui_options_page['icon_url'],
'instructions' => $acf_menu_icon_instructions,
'placeholder' => 'dashicons-admin-generic',
'conditions' => array(
'field' => 'parent_slug',
'operator' => '==',
'value' => 'none',
),
),
'div',
'field'
);
acf_render_field_wrap(
array(
'label' => __( 'Menu Title', 'acf' ),
'type' => 'text',
'name' => 'menu_title',
'key' => 'menu_title',
'class' => 'acf-options-page-menu_title',
'prefix' => 'acf_ui_options_page',
'value' => $acf_ui_options_page['menu_title'],
),
'div',
'field'
);
$acf_menu_position_link = sprintf(
'<a href="https://developer.wordpress.org/reference/functions/add_menu_page/#default-bottom-of-menu-structure" target="_blank">%s</a>',
__( 'Learn more about menu positions.', 'acf' )
);
$acf_menu_position_desc = sprintf(
/* translators: %s - link to WordPress docs to learn more about menu positions. */
__( 'The position in the menu where this page should appear. %s', 'acf' ),
$acf_menu_position_link
);
$acf_menu_position_desc_parent = sprintf(
/* translators: %s - link to WordPress docs to learn more about menu positions. */
__( 'The position in the menu where this page should appear. %s', 'acf' ),
$acf_menu_position_link
);
$acf_menu_position_desc_child = __( 'The position in the menu where this child page should appear. The first child page is 0, the next is 1, etc.', 'acf' );
$acf_menu_position_desc = '<span class="acf-menu-position-desc-parent">' . $acf_menu_position_desc_parent . '</span>';
$acf_menu_position_desc .= '<span class="acf-menu-position-desc-child">' . $acf_menu_position_desc_child . '</span>';
acf_render_field_wrap(
array(
'label' => __( 'Menu Position', 'acf' ),
'type' => 'text',
'name' => 'position',
'key' => 'position',
'prefix' => 'acf_ui_options_page',
'value' => $acf_ui_options_page['position'],
'instructions' => $acf_menu_position_desc,
),
'div',
'field'
);
acf_render_field_wrap(
array(
'label' => __( 'Redirect to Child Page', 'acf' ),
'instructions' => __( 'When child pages exist for this parent page, this page will redirect to the first child page.', 'acf' ),
'type' => 'true_false',
'name' => 'redirect',
'key' => 'redirect',
'prefix' => 'acf_ui_options_page',
'value' => $acf_ui_options_page['redirect'],
'ui' => 1,
'default' => 1,
'conditions' => array(
'field' => 'parent_slug',
'operator' => '==',
'value' => 'none',
),
)
);
acf_render_field_wrap(
array(
'type' => 'text',
'name' => 'description',
'key' => 'description',
'prefix' => 'acf_ui_options_page',
'value' => $acf_ui_options_page['description'],
'label' => __( 'Description', 'acf' ),
'instructions' => __( 'A descriptive summary of the options page.', 'acf' ),
),
'div',
'field'
);
break;
case 'labels':
acf_render_field_wrap(
array(
'label' => __( 'Update Button Label', 'acf' ),
'instructions' => __( 'The label used for the submit button which updates the fields on the options page.', 'acf' ),
'placeholder' => __( 'Update', 'acf' ),
'type' => 'text',
'name' => 'update_button',
'key' => 'update_button',
'prefix' => 'acf_ui_options_page',
'value' => $acf_ui_options_page['update_button'],
),
'div',
'field'
);
acf_render_field_wrap(
array(
'label' => __( 'Updated Message', 'acf' ),
'instructions' => __( 'The message that is displayed after successfully updating the options page.', 'acf' ),
'placeholder' => __( 'Updated Options', 'acf' ),
'type' => 'text',
'name' => 'updated_message',
'key' => 'updated_message',
'prefix' => 'acf_ui_options_page',
'value' => $acf_ui_options_page['updated_message'],
),
'div',
'field'
);
break;
case 'permissions':
$acf_all_caps = array();
foreach ( wp_roles()->roles as $acf_role ) {
$acf_all_caps = array_merge( $acf_all_caps, $acf_role['capabilities'] );
}
// Get rid of duplicates and set the keys equal to the values.
$acf_all_caps = array_unique( array_keys( $acf_all_caps ) );
$acf_all_caps = array_combine( $acf_all_caps, $acf_all_caps );
// Move the "edit_posts" to the first select option.
if ( in_array( 'edit_posts', $acf_all_caps, true ) ) {
$acf_all_caps = array_diff( $acf_all_caps, array( 'edit_posts' ) );
$acf_all_caps = array_merge( array( 'edit_posts' => 'edit_posts' ), $acf_all_caps );
}
// TODO: Should we AJAX load this? Seems to require UI = true, which breaks our custom template.
acf_render_field_wrap(
array(
'type' => 'select',
'name' => 'capability',
'key' => 'capability',
'prefix' => 'acf_ui_options_page',
'value' => $acf_ui_options_page['capability'],
'label' => __( 'Capability', 'acf' ),
'instructions' => __( 'The capability required for this menu to be displayed to the user.', 'acf' ),
'choices' => $acf_all_caps,
'default' => 'edit_posts',
'class' => 'acf-options-page-capability',
),
'div',
'field'
);
acf_render_field_wrap(
array(
'type' => 'select',
'name' => 'data_storage',
'key' => 'data_storage',
'prefix' => 'acf_ui_options_page',
'value' => $acf_ui_options_page['data_storage'],
'label' => __( 'Data Storage', 'acf' ),
'instructions' => __( 'By default, the option page stores field data in the options table. You can make the page load field data from a post, user, or term.', 'acf' ),
'choices' => array(
'options' => __( 'Options', 'acf' ),
'post_id' => __( 'Custom Storage', 'acf' ),
),
'default' => 'options',
'hide_search' => true,
'class' => 'acf-options-page-data_storage',
),
'div',
'field'
);
$acf_custom_storage_url = acf_add_url_utm_tags(
'https://www.advancedcustomfields.com/resources/get_field/',
'docs',
'options_page_ui',
'get-a-value-from-different-objects'
);
$acf_custom_storage_link = sprintf(
'<a href="%1$s" target="_blank">%2$s</a>',
$acf_custom_storage_url,
__( 'Learn more about available settings.', 'acf' )
);
$acf_custom_storage_desc = sprintf(
/* translators: %s = link to learn more about storage locations. */
__( 'Set a custom storage location. Can be a numeric post ID (123), or a string (`user_2`). %s', 'acf' ),
$acf_custom_storage_link
);
acf_render_field_wrap(
array(
'label' => __( 'Custom Storage', 'acf' ),
'instructions' => $acf_custom_storage_desc,
'type' => 'text',
'name' => 'post_id',
'key' => 'post_id',
'prefix' => 'acf_ui_options_page',
'value' => $acf_ui_options_page['post_id'],
'conditions' => array(
'field' => 'data_storage',
'operator' => '==',
'value' => 'post_id',
),
),
'div',
'field'
);
acf_render_field_wrap(
array(
'label' => __( 'Autoload Options', 'acf' ),
'instructions' => __( 'Improve performance by loading the fields in the option records automatically when WordPress loads.', 'acf' ),
'type' => 'true_false',
'name' => 'autoload',
'key' => 'autoload',
'prefix' => 'acf_ui_options_page',
'value' => $acf_ui_options_page['autoload'],
'ui' => 1,
'default' => 0,
)
);
break;
default:
}
do_action( "acf/ui_options_page/render_settings_tab/{$tab_key}", $acf_ui_options_page );
echo '</div>';
}

View File

@ -0,0 +1,74 @@
<?php
global $acf_ui_options_page, $acf_parent_page_options;
acf_render_field_wrap(
array(
'label' => __( 'Page Title', 'acf' ),
/* translators: example options page name */
'placeholder' => __( 'Site Settings', 'acf' ),
'type' => 'text',
'name' => 'page_title',
'key' => 'page_title',
'class' => 'acf_options_page_title acf_slugify_to_key',
'prefix' => 'acf_ui_options_page',
'value' => $acf_ui_options_page['page_title'],
'required' => true,
),
'div',
'field'
);
acf_render_field_wrap(
array(
'label' => __( 'Menu Slug', 'acf' ),
'type' => 'text',
'name' => 'menu_slug',
'key' => 'menu_slug',
'class' => 'acf-options-page-menu_slug acf_slugified_key',
'prefix' => 'acf_ui_options_page',
'value' => $acf_ui_options_page['menu_slug'],
'required' => true,
),
'div',
'field'
);
acf_render_field_wrap(
array(
'label' => __( 'Parent Page', 'acf' ),
'type' => 'select',
'name' => 'parent_slug',
'key' => 'parent_slug',
'class' => 'acf-options-page-parent_slug',
'prefix' => 'acf_ui_options_page',
'value' => $acf_ui_options_page['parent_slug'],
'choices' => $acf_parent_page_options,
'required' => true,
),
'div',
'field'
);
do_action( 'acf/post_type/basic_settings', $acf_ui_options_page );
acf_render_field_wrap( array( 'type' => 'seperator' ) );
acf_render_field_wrap(
array(
'label' => __( 'Advanced Configuration', 'acf' ),
'instructions' => __( 'I know what I\'m doing, show me all the options.', 'acf' ),
'type' => 'true_false',
'name' => 'advanced_configuration',
'key' => 'advanced_configuration',
'prefix' => 'acf_ui_options_page',
'value' => $acf_ui_options_page['advanced_configuration'],
'ui' => 1,
'class' => 'acf-advanced-settings-toggle',
)
);
?>
<div class="acf-hidden">
<input type="hidden" name="acf_ui_options_page[key]" value="<?php echo esc_attr( $acf_ui_options_page['key'] ); ?>" />
</div>
<?php

View File

@ -0,0 +1,66 @@
<form id="acf-create-options-page-form">
<?php
$acf_options_page_prefilled_title = '';
if ( ! empty( $field_group_title ) ) {
$acf_options_page_prefilled_title = (string) apply_filters( 'acf/options_page_modal/prefill_title', '%s' );
$acf_options_page_prefilled_title = sprintf(
$acf_options_page_prefilled_title,
$field_group_title
);
}
acf_render_field_wrap(
array(
'label' => __( 'Page Title', 'acf' ),
/* translators: example options page name */
'placeholder' => __( 'Site Settings', 'acf' ),
'value' => $acf_options_page_prefilled_title,
'type' => 'text',
'name' => 'page_title',
'key' => 'page_title',
'class' => 'acf_options_page_title acf_slugify_to_key',
'prefix' => 'acf_ui_options_page',
'required' => true,
),
'div',
'field'
);
acf_render_field_wrap(
array(
'label' => __( 'Menu Slug', 'acf' ),
'type' => 'text',
'name' => 'menu_slug',
'key' => 'menu_slug',
'class' => 'acf-options-page-menu_slug acf_slugified_key',
'prefix' => 'acf_ui_options_page',
'required' => true,
),
'div',
'field'
);
acf_render_field_wrap(
array(
'label' => __( 'Parent Page', 'acf' ),
'type' => 'select',
'name' => 'parent_slug',
'key' => 'parent_slug',
'class' => 'acf-options-page-parent_slug',
'prefix' => 'acf_ui_options_page',
'choices' => $acf_parent_page_choices,
'required' => true,
),
'div',
'field'
);
?>
<div class="acf-actions">
<button type="button" class="acf-btn acf-btn-secondary acf-close-popup"><?php esc_html_e( 'Cancel', 'acf' ); ?></button>
<button type="submit" class="acf-btn acf-btn-primary"><?php esc_html_e( 'Done', 'acf' ); ?></button>
</div>
</form>

View File

@ -0,0 +1,23 @@
<?php
$acf_options_pages_desc = sprintf(
/* translators: %s URL to ACF options pages documentation */
__( 'ACF <a href="%s" target="_blank">options pages</a> are custom admin pages for managing global settings via fields. You can create multiple pages and sub-pages.', 'acf' ),
acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/options-page/', 'docs', 'no-options-pages' )
);
$acf_getting_started = sprintf(
/* translators: %s url to getting started guide */
__( 'New to ACF? Take a look at our <a href="%s" target="_blank">getting started guide</a>.', 'acf' ),
acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/getting-started-with-acf/', 'docs', 'no-options-pages' )
);
?>
<script>document.body.classList.add('acf-no-options-pages');</script>
<div class="acf-no-options-pages-wrapper">
<div class="acf-no-options-pages-inner">
<img src="<?php echo esc_url( acf_get_url( 'assets/images/empty-post-types.svg' ) ); ?>" />
<h2><?php esc_html_e( 'Add Your First Options Page', 'acf' ); ?></h2>
<p><?php echo acf_esc_html( $acf_options_pages_desc ); ?></p>
<a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=acf-ui-options-page' ) ); ?>" class="acf-btn"><i class="acf-icon acf-icon-plus"></i> <?php esc_html_e( 'Add Options Page', 'acf' ); ?></a>
<p class="acf-small"><?php echo acf_esc_html( $acf_getting_started ); ?></p>
</div>
</div>

View File

@ -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>

View File

@ -0,0 +1,302 @@
<?php
/**
* Renders the "License Information" and "Update Information" metaboxes.
*
* @package ACF
*/
$nonce = $active ? 'deactivate_pro_license' : 'activate_pro_license';
$activate_deactivate_btn = $active ? __( 'Deactivate License', 'acf' ) : __( 'Activate License', 'acf' );
/**
* Renders the license status table.
*
* @since 6.?
*
* @param array $status The current license status array.
* @return void
*/
function acf_pro_render_license_status_table( $status ) {
// Bail early if we don't have a status from the server.
if ( acf_pro_get_license_key() && empty( $status['status'] ) ) {
return;
}
$status['status'] = ! empty( $status['status'] ) ? $status['status'] : 'inactive';
$status_text = _x( 'Inactive', 'license status', 'acf' );
$is_lifetime = ! empty( $status['lifetime'] );
if ( 'active' === $status['status'] ) {
$status_text = _x( 'Active', 'license status', 'acf' );
} elseif ( 'expired' === $status['status'] ) {
$status_text = _x( 'Expired', 'license status', 'acf' );
} elseif ( 'cancelled' === $status['status'] ) {
$status_text = _x( 'Cancelled', 'license status', 'acf' );
}
$indicator = '<span class="acf-license-status ' . esc_attr( $status['status'] ) . '">' . esc_html( $status_text ) . '</span>';
?>
<table class="acf-license-status-table">
<tr>
<th>
<?php
if ( $is_lifetime || 'inactive' === $status['status'] ) {
esc_html_e( 'License Status', 'acf' );
} else {
esc_html_e( 'Subscription Status', 'acf' );
}
?>
</th>
<td><?php echo acf_esc_html( $indicator ); ?></td>
</tr>
<?php if ( ! empty( $status['name'] ) ) : ?>
<tr>
<th>
<?php
if ( $is_lifetime ) {
esc_html_e( 'License Type', 'acf' );
} else {
esc_html_e( 'Subscription Type', 'acf' );
}
?>
</th>
<td>
<?php
if ( $is_lifetime ) {
esc_html_e( 'Lifetime - ', 'acf' );
}
echo esc_html( $status['name'] );
?>
</td>
</tr>
<?php endif; ?>
<?php if ( ! $is_lifetime && ! empty( $status['expiry'] ) && is_numeric( $status['expiry'] ) ) : ?>
<tr>
<th>
<?php
if ( acf_pro_is_license_expired( $status ) ) {
esc_html_e( 'Subscription Expired', 'acf' );
} else {
esc_html_e( 'Subscription Expires', 'acf' );
}
?>
</th>
<td>
<?php
$date_format = get_option( 'date_format', 'F j, Y' );
$expiry_date = date_i18n( $date_format, $status['expiry'] );
echo esc_html( $expiry_date );
?>
</td>
</tr>
<?php endif; ?>
</table>
<?php
}
/**
* Renders the "Manage License"/"Renew Subscription" button.
*
* @since 6.?
*
* @param array $status The current license status.
* @return void
*/
function acf_pro_render_manage_license_button( $status ) {
// Lifetime licenses don't have anything to manage.
if ( ! empty( $status['lifetime'] ) ) {
return;
}
$url = acf_pro_get_manage_license_url( $status );
$url = acf_add_url_utm_tags( $url, 'updates page', 'manage license button' );
$text = __( 'Manage License', 'acf' );
$class = '';
if ( acf_pro_is_license_expired( $status ) ) {
$text = __( 'Renew Subscription', 'acf' );
$class = ' acf-btn acf-renew-subscription';
}
printf(
'<a href="%1$s" target="_blank" class="acf-manage-license-btn%2$s">%3$s<i class="acf-icon acf-icon-arrow-up-right"></i></a>',
esc_url( $url ),
esc_attr( $class ),
esc_html( $text )
);
}
?>
<div class="wrap acf-settings-wrap acf-updates">
<h1><?php esc_html_e( 'Updates', 'acf' ); ?></h1>
<div class="acf-box" id="acf-license-information">
<div class="title">
<h3><?php esc_html_e( 'License Information', 'acf' ); ?></h3>
</div>
<div class="inner">
<?php if ( $is_defined_license ) : ?>
<p class="acf-license-defined">
<?php echo acf_esc_html( apply_filters( 'acf/admin/license_key_constant_message', __( 'Your license key is defined in wp-config.php.', 'acf' ) ) ); ?>
</p>
<?php if ( ! $active ) : ?>
<div class="acf-retry-activation">
<?php
$acf_recheck_class = ' acf-btn acf-btn-secondary';
if ( acf_pro_is_license_expired( $license_status ) ) {
acf_pro_render_manage_license_button( $license_status );
$acf_recheck_class = '';
}
$acf_recheck_nonce = wp_create_nonce( 'acf_retry_activation' );
$acf_recheck_url = admin_url( 'edit.php?post_type=acf-field-group&page=acf-settings-updates&acf_retry_nonce=' . $nonce );
$acf_recheck_text = __( 'Recheck License', 'acf' );
printf(
'<a class="acf-recheck-license%1$s" href="%2$s"><i class="acf-icon acf-icon-regenerate"></i>%3$s</a>',
esc_attr( $acf_recheck_class ),
esc_url( $acf_recheck_url ),
esc_html( $acf_recheck_text )
);
?>
</div>
<?php endif; ?>
<?php else : // License is not defined. ?>
<form action="" method="post" class="acf-activation-form">
<?php acf_nonce_input( $nonce ); ?>
<label for="acf-field-acf_pro_license"><?php esc_html_e( 'License Key', 'acf' ); ?></label>
<?php
acf_render_field(
array(
'type' => 'text',
'name' => 'acf_pro_license',
'value' => str_repeat( '*', strlen( $license ) ),
'readonly' => $active ? 1 : 0,
)
);
$activate_deactivate_btn_id = $active ? 'id="deactivate-license" ' : '';
$activate_deactivate_btn_class = $active ? ' acf-btn-tertiary' : '';
?>
<input <?php echo $activate_deactivate_btn_id; ?>type="submit" value="<?php echo esc_attr( $activate_deactivate_btn ); ?>" class="acf-btn<?php echo esc_attr( $activate_deactivate_btn_class ); ?>">
<?php
acf_pro_render_manage_license_button( $license_status );
if ( acf_pro_is_license_expired( $license_status ) ) {
$acf_recheck_url = admin_url( 'edit.php?post_type=acf-field-group&page=acf-settings-updates&acf-recheck-license=true' );
$acf_recheck_text = __( 'Recheck License', 'acf' );
printf(
'<a class="acf-recheck-license" href="%1$s"><i class="acf-icon acf-icon-regenerate"></i>%2$s</a>',
esc_url( $acf_recheck_url ),
esc_html( $acf_recheck_text )
);
}
?>
</form>
<?php endif; // End of license_defined check. ?>
<div class="acf-license-status-wrap">
<?php
acf_pro_render_license_status_table( $license_status );
if ( ! $active && ! defined( 'ACF_PRO_LICENSE' ) ) :
?>
<div class="acf-no-license-view-pricing">
<span>
<?php
$acf_view_pricing_text = esc_html__( 'View pricing & purchase', 'acf' );
$acf_view_pricing_link = sprintf(
'<a href=%s target="_blank">%s <i class="acf-icon acf-icon-arrow-up-right"></i></a>',
acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/pro/', 'ACF upgrade', 'license activations' ),
$acf_view_pricing_text
);
printf(
/* translators: %s - link to ACF website */
__( 'Don\'t have an ACF PRO license? %s', 'acf' ),
$acf_view_pricing_link
);
?>
</span>
</div>
<?php endif; ?>
</div>
</div>
</div>
<div class="acf-box" id="acf-update-information">
<div class="title">
<h3><?php esc_html_e( 'Update Information', 'acf' ); ?></h3>
</div>
<div class="inner">
<table class="form-table">
<tbody>
<tr>
<th>
<label><?php esc_html_e( 'Current Version', 'acf' ); ?></label>
</th>
<td>
<?php echo esc_html( $current_version ); ?>
</td>
</tr>
<tr>
<th>
<label><?php esc_html_e( 'Latest Version', 'acf' ); ?></label>
</th>
<td>
<?php echo esc_html( $remote_version ); ?>
</td>
</tr>
<tr>
<th>
<label><?php esc_html_e( 'Update Available', 'acf' ); ?></label>
</th>
<td>
<?php if ( $update_available ) : ?>
<span style="margin-right: 5px;"><?php esc_html_e( 'Yes', 'acf' ); ?></span>
<?php else : ?>
<span style="margin-right: 5px;"><?php esc_html_e( 'No', 'acf' ); ?></span>
<?php endif; ?>
</td>
</tr>
<?php if ( $upgrade_notice ) : ?>
<tr>
<th>
<label><?php esc_html_e( 'Upgrade Notice', 'acf' ); ?></label>
</th>
<td>
<?php echo acf_esc_html( $upgrade_notice ); ?>
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<?php if ( $changelog ) : ?>
<div class="acf-update-changelog">
<?php echo acf_esc_html( $changelog ); ?>
</div>
<?php endif; ?>
<?php if ( $update_available ) : ?>
<?php if ( $wp_not_compatible ) : ?>
<a class="button" disabled="disabled" href="#"><?php esc_html_e( 'Please upgrade WordPress to update ACF', 'acf' ); ?></a>
<?php elseif ( $license_error ) : ?>
<a class="button" disabled="disabled" href="#"><?php esc_html_e( 'Please reactivate your license to unlock updates', 'acf' ); ?></a>
<?php elseif ( $active && is_multisite() ) : ?>
<a class="button" disabled="disabled" href="#"><?php esc_html_e( 'Update ACF in Network Admin', 'acf' ); ?></a>
<?php elseif ( $active ) : ?>
<a class="acf-btn" href="<?php echo esc_attr( admin_url( 'plugins.php?s=Advanced+Custom+Fields+Pro' ) ); ?>"><?php esc_html_e( 'Update Plugin', 'acf' ); ?></a>
<?php else : ?>
<a class="button" disabled="disabled" href="#"><?php esc_html_e( 'Enter your license key to unlock updates', 'acf' ); ?></a>
<?php endif; ?>
<?php else : ?>
<a class="acf-btn acf-btn-secondary" href="<?php echo esc_attr( add_query_arg( 'force-check', 1 ) ); ?>"><?php esc_html_e( 'Check For Updates', 'acf' ); ?></a>
<?php endif; ?>
</div>
</div>
</div>