first commit

This commit is contained in:
DESKTOP-GBA0BK8\Admin
2023-04-08 12:19:53 -04:00
commit 7c8c8b1c76
4586 changed files with 2050693 additions and 0 deletions
@@ -0,0 +1,98 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('ACF_Ajax_Check_Screen') ) :
class ACF_Ajax_Check_Screen extends ACF_Ajax {
/** @var string The AJAX action name. */
var $action = 'acf/ajax/check_screen';
/** @var bool Prevents access for non-logged in users. */
var $public = false;
/**
* get_response
*
* Returns the response data to sent back.
*
* @date 31/7/18
* @since 5.7.2
*
* @param array $request The request args.
* @return mixed The response data or WP_Error.
*/
function get_response( $request ) {
// vars
$args = wp_parse_args($this->request, array(
'screen' => '',
'post_id' => 0,
'ajax' => true,
'exists' => array()
));
// vars
$response = array(
'results' => array(),
'style' => ''
);
// get field groups
$field_groups = acf_get_field_groups( $args );
// loop through field groups
if( $field_groups ) {
foreach( $field_groups as $i => $field_group ) {
// vars
$item = array(
'id' => 'acf-' . $field_group['key'],
'key' => $field_group['key'],
'title' => $field_group['title'],
'position' => $field_group['position'],
'style' => $field_group['style'],
'label' => $field_group['label_placement'],
'edit' => acf_get_field_group_edit_link( $field_group['ID'] ),
'html' => ''
);
// append html if doesnt already exist on page
if( !in_array($field_group['key'], $args['exists']) ) {
// load fields
$fields = acf_get_fields( $field_group );
// get field HTML
ob_start();
// render
acf_render_fields( $fields, $args['post_id'], 'div', $field_group['instruction_placement'] );
$item['html'] = ob_get_clean();
}
// append
$response['results'][] = $item;
}
// Get style from first field group.
$response['style'] = acf_get_field_group_style( $field_groups[0] );
}
// Custom metabox order.
if( $this->get('screen') == 'post' ) {
$response['sorted'] = get_user_option('meta-box-order_' . $this->get('post_type'));
}
// return
return $response;
}
}
acf_new_instance('ACF_Ajax_Check_Screen');
endif; // class_exists check
?>
@@ -0,0 +1,54 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('ACF_Ajax_Upgrade') ) :
class ACF_Ajax_Upgrade extends ACF_Ajax {
/** @var string The AJAX action name */
var $action = 'acf/ajax/upgrade';
/**
* get_response
*
* Returns the response data to sent back.
*
* @date 31/7/18
* @since 5.7.2
*
* @param array $request The request args.
* @return mixed The response data or WP_Error.
*/
function get_response( $request ) {
// Switch blog.
if( isset($request['blog_id']) ) {
switch_to_blog( $request['blog_id'] );
}
// Bail early if no upgrade avaiable.
if( !acf_has_upgrade() ) {
return new WP_Error( 'upgrade_error', __('No updates available.', 'acf') );
}
// Listen for output.
ob_start();
// Run upgrades.
acf_upgrade_all();
// Store output.
$error = ob_get_clean();
// Return error or success.
if( $error ) {
return new WP_Error( 'upgrade_error', $error );
}
return true;
}
}
acf_new_instance('ACF_Ajax_Upgrade');
endif; // class_exists check
@@ -0,0 +1,41 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('ACF_Ajax_User_Setting') ) :
class ACF_Ajax_User_Setting extends ACF_Ajax {
/** @var string The AJAX action name. */
var $action = 'acf/ajax/user_setting';
/** @var bool Prevents access for non-logged in users. */
var $public = true;
/**
* get_response
*
* Returns the response data to sent back.
*
* @date 31/7/18
* @since 5.7.2
*
* @param array $request The request args.
* @return mixed The response data or WP_Error.
*/
function get_response( $request ) {
// update
if( $this->has('value') ) {
return acf_update_user_setting( $this->get('name'), $this->get('value') );
// get
} else {
return acf_get_user_setting( $this->get('name') );
}
}
}
acf_new_instance('ACF_Ajax_User_Setting');
endif; // class_exists check
@@ -0,0 +1,184 @@
<?php
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists('ACF_Ajax') ) :
class ACF_Ajax {
/** @var string The AJAX action name. */
var $action = '';
/** @var array The $_REQUEST data. */
var $request;
/** @var bool Prevents access for non-logged in users. */
var $public = false;
/**
* __construct
*
* Sets up the class functionality.
*
* @date 31/7/18
* @since 5.7.2
*
* @param void
* @return void
*/
function __construct() {
$this->initialize();
$this->add_actions();
}
/**
* has
*
* Returns true if the request has data for the given key.
*
* @date 31/7/18
* @since 5.7.2
*
* @param string $key The data key.
* @return boolean
*/
function has( $key = '' ) {
return isset($this->request[$key]);
}
/**
* get
*
* Returns request data for the given key.
*
* @date 31/7/18
* @since 5.7.2
*
* @param string $key The data key.
* @return mixed
*/
function get( $key = '' ) {
return isset($this->request[$key]) ? $this->request[$key] : null;
}
/**
* set
*
* Sets request data for the given key.
*
* @date 31/7/18
* @since 5.7.2
*
* @param string $key The data key.
* @param mixed $value The data value.
* @return ACF_Ajax
*/
function set( $key = '', $value ) {
$this->request[$key] = $value;
return $this;
}
/**
* initialize
*
* Allows easy access to modifying properties without changing constructor.
*
* @date 31/7/18
* @since 5.7.2
*
* @param void
* @return void
*/
function initialize() {
/* do nothing */
}
/**
* add_actions
*
* Adds the ajax actions for this response.
*
* @date 31/7/18
* @since 5.7.2
*
* @param void
* @return void
*/
function add_actions() {
// add action for logged-in users
add_action( "wp_ajax_{$this->action}", array($this, 'request') );
// add action for non logged-in users
if( $this->public ) {
add_action( "wp_ajax_nopriv_{$this->action}", array($this, 'request') );
}
}
/**
* request
*
* Callback for ajax action. Sets up properties and calls the get_response() function.
*
* @date 1/8/18
* @since 5.7.2
*
* @param void
* @return void
*/
function request() {
// Verify ajax request
if( !acf_verify_ajax() ) {
wp_send_json_error();
}
// Store data for has() and get() functions.
$this->request = wp_unslash($_REQUEST);
// Send response.
$this->send( $this->get_response( $this->request ) );
}
/**
* get_response
*
* Returns the response data to sent back.
*
* @date 31/7/18
* @since 5.7.2
*
* @param array $request The request args.
* @return mixed The response data or WP_Error.
*/
function get_response( $request ) {
return true;
}
/**
* send
*
* Sends back JSON based on the $response as either success or failure.
*
* @date 31/7/18
* @since 5.7.2
*
* @param mixed $response The response to send back.
* @return void
*/
function send( $response ) {
// Return error.
if( is_wp_error($response) ) {
wp_send_json_error(array( 'error' => $response->get_error_message() ));
// Return success.
} else {
wp_send_json_success($response);
}
}
}
endif; // class_exists check
?>