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,362 @@
<?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' ) { // 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( dirname( __FILE__ ) . '/views/html-options-page.php', $this->page );
}
}
// initialize
new acf_admin_options_page();
endif;
?>

View File

@ -0,0 +1,261 @@
<?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() {
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,
'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,
);
// 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 ) {
if ( isset( $update['license_valid'] ) && ! $update['license_valid'] ) {
$this->view['license_error'] = true;
acf_new_admin_notice(
array(
'text' => __( '<b>Error</b>. 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 has been modified
if ( $update && ! $update['package'] ) {
$this->view['license_error'] = true;
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();
}
}
}
}
/**
* 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( dirname( __FILE__ ) . '/views/html-settings-updates.php', $this->view );
}
}
// Initialize.
acf_new_instance( 'ACF_Admin_Updates' );
endif; // class_exists check

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,141 @@
<?php
// vars
$active = $license ? true : false;
$nonce = $active ? 'deactivate_pro_license' : 'activate_pro_license';
$button = $active ? __( 'Deactivate License', 'acf' ) : __( 'Activate License', 'acf' );
$readonly = $active ? 1 : 0;
?>
<div class="wrap acf-settings-wrap acf-updates">
<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">
<?php if ( $is_defined_license ) { ?>
<p>
<?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 ) { ?>
<form action="" method="post">
<?php acf_nonce_input( 'acf_delete_activation_transient' ); ?>
<input type="submit" value="<?php echo esc_attr( __( 'Retry Activation', 'acf' ) ); ?>" class="button button-primary">
</form>
<?php } ?>
<?php } else { ?>
<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' ), acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/pro/', 'ACF upgrade', 'license activations' ) ); ?></p>
<form action="" method="post" class="acf-activation-form">
<?php acf_nonce_input( $nonce ); ?>
<label for="acf-field-acf_pro_license"><?php _e( 'License Key', 'acf' ); ?></label>
<?php
// render field
acf_render_field(
array(
'type' => 'text',
'name' => 'acf_pro_license',
'value' => str_repeat( '*', strlen( $license ) ),
'readonly' => $readonly,
)
);
?>
<input type="submit" value="<?php echo esc_attr( $button ); ?>" class="acf-btn">
</form>
<?php } ?>
</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 else : ?>
<span style="margin-right: 5px;"><?php _e( 'No', 'acf' ); ?></span>
<?php endif; ?>
</td>
</tr>
<?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>
<?php if ( $changelog ) : ?>
<div class="acf-update-changelog">
<?php echo acf_esc_html( $changelog ); ?>
</div>
<?php endif; ?>
<?php if ( $update_available ) : ?>
<?php if ( $license_error ) : ?>
<a class="button" disabled="disabled" href="#"><?php _e( 'Please reactivate your license to unlock updates', 'acf' ); ?></a>
<?php elseif ( $active ) : ?>
<a class="acf-btn" 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( '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 _e( 'Check For Updates', 'acf' ); ?></a>
<?php endif; ?>
</div>
</div>
</div>
<style type="text/css">
#acf_pro_license {
width: 75%;
}
#acf-update-information td h4 {
display: none;
}
</style>