ACF_Taxonomy::build_safe_context_for_metabox_cbpublicACF 6.3.8

Ensure the metabox being called does not perform any unsafe operations.

Метод класса: ACF_Taxonomy{}

Возвращает

Разное. The callback result.

Использование

$ACF_Taxonomy = new ACF_Taxonomy();
$ACF_Taxonomy->build_safe_context_for_metabox_cb( $post, $tax );
$post(WP_Post) (обязательный)
The post being rendered.
$tax(массив) (обязательный)
The provided taxonomy information required for callback render.

Список изменений

С версии 6.3.8 Введена.

Код ACF_Taxonomy::build_safe_context_for_metabox_cb() ACF 6.4.2

public function build_safe_context_for_metabox_cb( $post, $tax ) {
	$taxonomies = $this->get_posts();
	$this_tax   = array_filter(
		$taxonomies,
		function ( $taxonomy ) use ( $tax ) {
			return $taxonomy['taxonomy'] === $tax['args']['taxonomy'];
		}
	);
	if ( empty( $this_tax ) || ! is_array( $this_tax ) ) {
		// Unable to find the ACF taxonomy. Don't do anything.
		return;
	}
	$acf_taxonomy = array_shift( $this_tax );
	$original_cb  = isset( $acf_taxonomy['meta_box_cb'] ) ? $acf_taxonomy['meta_box_cb'] : false;

	// Prevent access to any wp_ prefixed functions in a callback.
	if ( apply_filters( 'acf/taxonomy/prevent_access_to_wp_functions_in_meta_box_cb', true ) && substr( strtolower( $original_cb ), 0, 3 ) === 'wp_' ) {
		// Don't execute register meta box callbacks if an internal wp function by default.
		return;
	}

	$unset     = array( '_POST', '_GET', '_REQUEST', '_COOKIE', '_SESSION', '_FILES', '_ENV', '_SERVER' );
	$originals = array();

	foreach ( $unset as $var ) {
		if ( isset( $GLOBALS[ $var ] ) ) {
			$originals[ $var ] = $GLOBALS[ $var ];
			$GLOBALS[ $var ]   = array(); //phpcs:ignore -- used for building a safe context
		}
	}

	$return = false;
	if ( is_callable( $original_cb ) ) {
		$return = call_user_func( $original_cb, $post, $tax );
	}

	foreach ( $unset as $var ) {
		if ( isset( $originals[ $var ] ) ) {
			$GLOBALS[ $var ] = $originals[ $var ]; //phpcs:ignore -- used for restoring the original context
		}
	}

	return $return;
}