Skip to content

Commit

Permalink
Deploying version 5.12
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgrshaw committed Feb 23, 2022
1 parent 94d69e5 commit 2495461
Show file tree
Hide file tree
Showing 9 changed files with 4,179 additions and 3,813 deletions.
66 changes: 64 additions & 2 deletions acf.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Advanced Custom Fields
Plugin URI: https://www.advancedcustomfields.com
Description: Customize WordPress with powerful, professional and intuitive fields.
Version: 5.11.4
Version: 5.12
Author: Delicious Brains
Author URI: https://www.advancedcustomfields.com
Text Domain: acf
Expand All @@ -19,7 +19,7 @@
class ACF {

/** @var string The plugin version number. */
var $version = '5.11.4';
var $version = '5.12';

/** @var array The plugin settings array. */
var $settings = array();
Expand Down Expand Up @@ -100,6 +100,7 @@ function initialize() {
'rest_api_enabled' => true,
'rest_api_format' => 'light',
'rest_api_embed_links' => true,
'preload_blocks' => true,
);

// Include utility functions.
Expand Down Expand Up @@ -193,6 +194,8 @@ function initialize() {
add_action( 'init', array( $this, 'init' ), 5 );
add_action( 'init', array( $this, 'register_post_types' ), 5 );
add_action( 'init', array( $this, 'register_post_status' ), 5 );
add_action( 'activated_plugin', array( $this, 'deactivate_other_instances' ) );
add_action( 'pre_current_active_plugins', array( $this, 'plugin_deactivated_notice' ) );

// Add filters.
add_filter( 'posts_where', array( $this, 'posts_where' ), 10, 2 );
Expand Down Expand Up @@ -444,6 +447,65 @@ function register_post_status() {
);
}

/**
* Checks if another version of ACF/ACF PRO is active and deactivates it.
* Hooked on `activated_plugin` so other plugin is deactivated when current plugin is activated.
*
* @param string $plugin The plugin being activated.
*/
public function deactivate_other_instances( $plugin ) {
if ( ! in_array( $plugin, array( 'advanced-custom-fields/acf.php', 'advanced-custom-fields-pro/acf.php' ) ) ) {
return;
}

$plugin_to_deactivate = 'advanced-custom-fields/acf.php';
$deactivated_notice_id = '1';

// If we just activated the free version, deactivate the pro version.
if ( $plugin === $plugin_to_deactivate ) {
$plugin_to_deactivate = 'advanced-custom-fields-pro/acf.php';
$deactivated_notice_id = '2';
}

if ( is_multisite() && is_network_admin() ) {
$active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
$active_plugins = array_keys( $active_plugins );
} else {
$active_plugins = (array) get_option( 'active_plugins', array() );
}

foreach ( $active_plugins as $plugin_basename ) {
if ( $plugin_to_deactivate === $plugin_basename ) {
set_transient( 'acf_deactivated_notice_id', $deactivated_notice_id, 1 * HOUR_IN_SECONDS );
deactivate_plugins( $plugin_basename );
return;
}
}
}

/**
* Displays a notice when either ACF or ACF PRO is automatically deactivated.
*/
public function plugin_deactivated_notice() {
$deactivated_notice_id = get_transient( 'acf_deactivated_notice_id' );
if ( ! in_array( $deactivated_notice_id, array( '1', '2' ) ) ) {
return;
}

$message = __( "Advanced Custom Fields and Advanced Custom Fields PRO should not be active at the same time. We've automatically deactivated Advanced Custom Fields.", 'acf' );
if ( '2' === $deactivated_notice_id ) {
$message = __( "Advanced Custom Fields and Advanced Custom Fields PRO should not be active at the same time. We've automatically deactivated Advanced Custom Fields PRO.", 'acf' );
}

?>
<div class="updated" style="border-left: 4px solid #ffba00;">
<p><?php echo esc_html( $message ); ?></p>
</div>
<?php

delete_transient( 'acf_deactivated_notice_id' );
}

/**
* posts_where
*
Expand Down
40 changes: 15 additions & 25 deletions includes/api/api-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3071,39 +3071,29 @@ function acf_get_attachment( $attachment ) {
}


/*
* acf_get_truncated
*
* This function will truncate and return a string
*
* @type function
* @date 8/08/2014
* @since 5.0.0
*
* @param $text (string)
* @param $length (int)
* @return (string)
*/

/**
* This function will truncate and return a string
*
* @date 8/08/2014
* @since 5.0.0
*
* @param string $text The text to truncate.
* @param int $length The number of characters to allow in the string.
*
* @return string
*/
function acf_get_truncated( $text, $length = 64 ) {

// vars
$text = trim( $text );
$the_length = strlen( $text );

// cut
$return = substr( $text, 0, ( $length - 3 ) );
$the_length = function_exists( 'mb_strlen' ) ? mb_strlen( $text ) : strlen( $text );

// ...
if ( $the_length > ( $length - 3 ) ) {
$cut_length = $length - 3;
$return = function_exists( 'mb_substr' ) ? mb_substr( $text, 0, $cut_length ) : substr( $text, 0, $cut_length );

if ( $the_length > $cut_length ) {
$return .= '...';

}

// return
return $return;

}

/*
Expand Down
9 changes: 8 additions & 1 deletion includes/forms/form-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ function enqueue_block_editor_assets() {
// Call edit_form_after_title manually.
add_action( 'block_editor_meta_box_hidden_fields', array( $this, 'block_editor_meta_box_hidden_fields' ) );

// Cusotmize editor metaboxes.
// Customize editor metaboxes.
add_filter( 'filter_block_editor_meta_boxes', array( $this, 'filter_block_editor_meta_boxes' ) );

// Trigger ACF enqueue scripts as the site editor doesn't trigger this from form-post.php
acf_enqueue_scripts(
array(
'uploader' => true,
)
);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions includes/rest-api/class-acf-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ class ACF_Rest_Api {
private $embed_links;

public function __construct() {
add_action( 'rest_api_init', array( $this, 'initialize' ) );
add_filter( 'rest_pre_dispatch', array( $this, 'initialize' ), 10, 3 );
}

public function initialize() {
public function initialize( $response, $handler, $request ) {
if ( ! acf_get_setting( 'rest_api_enabled' ) ) {
return;
}

// Parse request and set the object for local access.
$this->request = new ACF_Rest_Request();
$this->request->parse_request();
$this->request->parse_request( $request );

// Register the 'acf' REST property.
$this->register_field();
Expand Down Expand Up @@ -420,7 +420,7 @@ private function get_field_groups_by_object_type( $object_type ) {
$object_type_groups = array();

foreach ( $field_groups as $field_group ) {
if ( ! $field_group['show_in_rest'] ) {
if ( empty( $field_group['show_in_rest'] ) ) {
continue;
}

Expand Down
10 changes: 5 additions & 5 deletions includes/rest-api/class-acf-rest-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class ACF_Rest_Request {
/**
* Determine all required information from the current request.
*/
public function parse_request() {
public function parse_request( $request ) {
$this->set_http_method();
$this->set_current_route();
$this->set_current_route( $request );
$this->build_supported_routes();
$this->set_url_params();
$this->set_object_types();
Expand Down Expand Up @@ -102,8 +102,8 @@ private function set_http_method() {
/**
* Get the current REST route as determined by WordPress.
*/
private function set_current_route() {
$this->current_route = empty( $GLOBALS['wp']->query_vars['rest_route'] ) ? null : $GLOBALS['wp']->query_vars['rest_route'];
private function set_current_route( $request ) {
$this->current_route = $request->get_route();
}

/**
Expand Down Expand Up @@ -147,7 +147,7 @@ private function build_supported_routes() {
* Loop through supported routes to find matching pattern. Use matching pattern to determine any URL parameters.
*/
private function set_url_params() {
if ( ! $this->supported_routes ) {
if ( ! $this->supported_routes || ! is_string( $this->current_route ) ) {
return;
}

Expand Down
Binary file modified lang/acf-hr.mo
Binary file not shown.
Loading

0 comments on commit 2495461

Please sign in to comment.