integration = $integration; add_action( 'acf/input/admin_enqueue_scripts', [ $this, 'enqueue_input' ] ); add_action( 'acf/field_group/admin_enqueue_scripts', [ $this, 'enqueue_field_group' ] ); add_action( 'admin_footer', [ $this, 'print_field_data' ] ); } /** Enqueues modal assets on every ACF input screen; skips the field-group editor. */ public function enqueue_input(): void { $screen = get_current_screen(); if ( $screen && 'acf-field-group' === $screen->post_type ) { return; } wp_enqueue_style( 'aibs-fcp-for-acf-plugin-modal', AIBS_FCP_FOR_ACF_PLUGIN_URL . 'assets/css/modal.css', [], AIBS_FCP_FOR_ACF_PLUGIN_VERSION ); wp_enqueue_script( 'aibs-fcp-for-acf-plugin-modal', AIBS_FCP_FOR_ACF_PLUGIN_URL . 'assets/js/modal.js', // ACF PRO registers acf-input on edit screens; jquery-ui-sortable powers // the picker's drag-to-reorder mode. [ 'acf-input', 'jquery-ui-sortable' ], AIBS_FCP_FOR_ACF_PLUGIN_VERSION, true ); wp_localize_script( 'aibs-fcp-for-acf-plugin-modal', 'FcpForAcfPlugin', [ 'isWp7' => version_compare( get_bloginfo( 'version' ), '7.0', '>=' ), 'i18n' => [ 'modal_title' => esc_html__( 'Add Layout', 'aibs-flexible-content-picker-for-acf' ), 'close' => esc_html__( 'Close', 'aibs-flexible-content-picker-for-acf' ), 'no_description' => esc_html__( 'No description', 'aibs-flexible-content-picker-for-acf' ), 'layout_preview' => esc_html__( 'Layout Preview', 'aibs-flexible-content-picker-for-acf' ), 'search_placeholder' => esc_html__( 'Search layouts…', 'aibs-flexible-content-picker-for-acf' ), 'clear_search' => esc_html__( 'Clear search', 'aibs-flexible-content-picker-for-acf' ), 'no_results' => esc_html__( 'No layouts match your search.', 'aibs-flexible-content-picker-for-acf' ), 'add_selected' => esc_html__( 'Add selected', 'aibs-flexible-content-picker-for-acf' ), /* translators: %d: number of selected layouts */ 'add_n_selected' => esc_html__( 'Add %d selected', 'aibs-flexible-content-picker-for-acf' ), 'reorder' => esc_html__( 'Reorder Selected', 'aibs-flexible-content-picker-for-acf' ), 'done' => esc_html__( 'Done', 'aibs-flexible-content-picker-for-acf' ), 'clear' => esc_html__( 'Clear selected', 'aibs-flexible-content-picker-for-acf' ), ], ] ); } /** Enqueues assets for the ACF field group editor (fired only on that screen). */ public function enqueue_field_group(): void { wp_enqueue_media(); wp_enqueue_style( 'aibs-fcp-for-acf-plugin-field', AIBS_FCP_FOR_ACF_PLUGIN_URL . 'assets/css/field.css', [], AIBS_FCP_FOR_ACF_PLUGIN_VERSION ); wp_enqueue_script( 'aibs-fcp-for-acf-plugin-field', AIBS_FCP_FOR_ACF_PLUGIN_URL . 'assets/js/field.js', [ 'jquery', 'media-upload' ], AIBS_FCP_FOR_ACF_PLUGIN_VERSION, true ); wp_localize_script( 'aibs-fcp-for-acf-plugin-field', 'FcpForAcfPluginFS', [ 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'aibs_fcp_for_acf_plugin_autosave' ), 'i18n' => [ 'upload' => __( 'UPLOAD', 'aibs-flexible-content-picker-for-acf' ), 'select_image' => __( 'Select Image', 'aibs-flexible-content-picker-for-acf' ), ], ] ); } /** * Injects collected field data in admin_footer after ACF has rendered all fields. * Uses wp_add_inline_script so FcpForAcfPlugin (created by wp_localize_script) is * already on the page before this runs. */ public function print_field_data(): void { $data = $this->integration->get_fields_data(); if ( empty( $data ) ) { return; } wp_add_inline_script( 'aibs-fcp-for-acf-plugin-modal', '(function(){if(typeof FcpForAcfPlugin==="undefined"){FcpForAcfPlugin={};}FcpForAcfPlugin.fields=' . wp_json_encode( $data, JSON_HEX_TAG | JSON_HEX_AMP ) . ';})()', 'after' ); } }