WordPress / WordPress/secure-custom-fields

Exported PHP doesn't register post_meta

Open
#384 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

[Type] Enhancement
Dominant language
PHP
Stars
131
Forks
64
Avg merge
10m
Merged PRs (30d)
1

Description

I set up a CPT and two custom fields.
I export the setup as PHP to add directly to the functions.php of a theme.
When trying to use the fields with block bindings it says acf/field is not registered.
Therefore the standalone PHP is not fully working for all the things you might want to use it for in a FSE block theme.

Workaround (from Claude) was to add the following code to the functions that registers those two fields as core/post-meta.

Added benefit: they automatically show up in Block Bindings Attributes menu

would be great if the SCF plugin exported the complete PHP!

add_action( 'init', function() {
    register_post_meta( 'bio-scf', 'bioscf', array(
        'single'       => true,
        'type'         => 'string',
        'show_in_rest' => true,
    ));

    register_post_meta( 'bio-scf', 'linkscf', array(
        'single'       => true,
        'type'         => 'string',
        'show_in_rest' => true,
    ));
});

Here's the PHP SCF exported:

add_action( 'acf/include_fields', function() {
	if ( ! function_exists( 'acf_add_local_field_group' ) ) {
		return;
	}

	acf_add_local_field_group( array(
	'key' => 'group_69aef45532825',
	'title' => 'BioSCFgroup',
	'fields' => array(
		array(
			'key' => 'field_69aef4553c5a5',
			'label' => 'BioSCF',
			'name' => 'bioscf',
			'aria-label' => '',
			'type' => 'text',
			'instructions' => '',
			'required' => 0,
			'conditional_logic' => 0,
			'wrapper' => array(
				'width' => '',
				'class' => '',
				'id' => '',
			),
			'default_value' => '',
			'maxlength' => '',
			'allow_in_bindings' => 1,
			'placeholder' => '',
			'prepend' => '',
			'append' => '',
		),
		array(
			'key' => 'field_69aef4aad1aa1',
			'label' => 'LinkSCF',
			'name' => 'linkscf',
			'aria-label' => '',
			'type' => 'text',
			'instructions' => '',
			'required' => 0,
			'conditional_logic' => 0,
			'wrapper' => array(
				'width' => '',
				'class' => '',
				'id' => '',
			),
			'default_value' => '',
			'maxlength' => '',
			'allow_in_bindings' => 1,
			'placeholder' => '',
			'prepend' => '',
			'append' => '',
		),
	),
	'location' => array(
		array(
			array(
				'param' => 'post_type',
				'operator' => '==',
				'value' => 'bio-scf',
			),
		),
	),
	'menu_order' => 0,
	'position' => 'normal',
	'style' => 'default',
	'label_placement' => 'top',
	'instruction_placement' => 'label',
	'hide_on_screen' => '',
	'active' => true,
	'description' => '',
	'show_in_rest' => 1,
	'display_title' => '',
) );
} );

add_action( 'init', function() {
	register_post_type( 'bio-scf', array(
	'labels' => array(
		'name' => 'Bios-SCF',
		'singular_name' => 'Bio-SCF',
		'menu_name' => 'Bio-SCF',
		'all_items' => 'All Bio-SCF',
		'edit_item' => 'Edit Bio-SCF',
		'view_item' => 'View Bio-SCF',
		'view_items' => 'View Bio-SCF',
		'add_new_item' => 'Add Bio-SCF',
		'add_new' => 'Add Bio-SCF',
		'new_item' => 'New Bio-SCF',
		'parent_item_colon' => 'Parent Bio-SCF:',
		'search_items' => 'Search Bio-SCF',
		'not_found' => 'No bio-scf found',
		'not_found_in_trash' => 'No bio-scf found in Trash',
		'archives' => 'Bio-SCF Archives',
		'attributes' => 'Bio-SCF Attributes',
		'insert_into_item' => 'Insert into bio-scf',
		'uploaded_to_this_item' => 'Uploaded to this bio-scf',
		'filter_items_list' => 'Filter bio-scf list',
		'filter_by_date' => 'Filter bio-scf by date',
		'items_list_navigation' => 'Bio-SCF list navigation',
		'items_list' => 'Bio-SCF list',
		'item_published' => 'Bio-SCF published.',
		'item_published_privately' => 'Bio-SCF published privately.',
		'item_reverted_to_draft' => 'Bio-SCF reverted to draft.',
		'item_scheduled' => 'Bio-SCF scheduled.',
		'item_updated' => 'Bio-SCF updated.',
		'item_link' => 'Bio-SCF Link',
		'item_link_description' => 'A link to a bio-scf.',
	),
	'public' => true,
	'show_in_rest' => true,
	'menu_icon' => 'dashicons-admin-users',
	'supports' => array(
		0 => 'title',
		1 => 'editor',
		2 => 'thumbnail',
		3 => 'custom-fields',
	),
	'delete_with_user' => false,
) );
} );

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the exported PHP in functions.php, tracing the acf/include_fields and init entry points shown in the report. Compare the generated field definitions with the register_post_meta workaround; done means exported PHP makes the custom fields available for block bindings without manual registration.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.