123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
- if ( ! defined( 'ABSPATH' ) ) {
- exit;
- }
- if ( ! class_exists( 'ACF_Form_Gutenberg' ) ) :
- class ACF_Form_Gutenberg {
-
- function __construct() {
-
- add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
-
- add_action( 'acf/validate_save_post', array( $this, 'acf_validate_save_post' ), 999 );
- }
-
- function enqueue_block_editor_assets() {
-
- add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 20, 0 );
-
- add_action( 'block_editor_meta_box_hidden_fields', array( $this, 'block_editor_meta_box_hidden_fields' ) );
-
- add_filter( 'filter_block_editor_meta_boxes', array( $this, 'filter_block_editor_meta_boxes' ) );
-
- acf_enqueue_scripts(
- array(
- 'uploader' => true,
- )
- );
- }
-
- function add_meta_boxes() {
-
- remove_action( 'edit_form_after_title', array( acf_get_instance( 'ACF_Form_Post' ), 'edit_form_after_title' ) );
- }
-
- function block_editor_meta_box_hidden_fields() {
-
- acf_get_instance( 'ACF_Form_Post' )->edit_form_after_title();
- }
-
- function filter_block_editor_meta_boxes( $wp_meta_boxes ) {
-
- global $current_screen;
-
- if ( isset( $wp_meta_boxes[ $current_screen->id ]['acf_after_title'] ) ) {
-
- $locations = $wp_meta_boxes[ $current_screen->id ];
-
- if ( ! isset( $locations['normal'] ) ) {
- $locations['normal'] = array();
- }
- if ( ! isset( $locations['normal']['high'] ) ) {
- $locations['normal']['high'] = array();
- }
-
- foreach ( $locations['acf_after_title'] as $priority => $meta_boxes ) {
- $locations['normal']['high'] = array_merge( $meta_boxes, $locations['normal']['high'] );
- }
-
- $wp_meta_boxes[ $current_screen->id ] = $locations;
- unset( $wp_meta_boxes[ $current_screen->id ]['acf_after_title'] );
-
- add_filter( 'get_user_option_meta-box-order_' . $current_screen->id, array( $this, 'modify_user_option_meta_box_order' ) );
- }
-
- return $wp_meta_boxes;
- }
-
- function modify_user_option_meta_box_order( $locations ) {
- if ( ! empty( $locations['acf_after_title'] ) ) {
- if ( ! empty( $locations['normal'] ) ) {
- $locations['normal'] = $locations['acf_after_title'] . ',' . $locations['normal'];
- } else {
- $locations['normal'] = $locations['acf_after_title'];
- }
- unset( $locations['acf_after_title'] );
- }
- return $locations;
- }
-
- function acf_validate_save_post() {
-
- if ( isset( $_GET['meta-box-loader'] ) ) {
- acf_reset_validation_errors();
- }
- }
- }
- acf_new_instance( 'ACF_Form_Gutenberg' );
- endif;
|