Skip to content

ACF Options Pages support #39

@jasonbahl

Description

@jasonbahl

What problem does this address?

The current beta of this plugin doesn't map ACF Options Pages to the WPGraphQL Schema.

This is missing functionality that existed in the previous WPGraphQL for ACF and should be supported.

What is your proposed solution?

When registering an ACF Options Page, like so:

acf_add_options_page(
  [
    'page_title' => 'My Options Page',
    'menu_title' => __( 'My Options Page' ),
    'menu_slug'  => 'my-options-page',
    'capability' => 'edit_posts',
    // options pages will show in the Schema unless set to false
    //          'show_in_graphql'   => false,
  ]
);

And then assign a field group to it (we'll call our field group OptionsFields, and our field text)

I expect to be able to query like so:

{
  myOptionsPage {
    optionsFields {
      text
    }
  }
}

Show in GraphQL:

If I were to set "show_in_graphql" => false for the options page, I would expect it to be left out of the Schema.

i.e.:

acf_add_options_page(
	array_merge( [
		'page_title' => $title,
		'menu_title' => __( 'My Options Page' ),
		'menu_slug'  => 'my-options-page',
		'capability' => 'edit_posts',
		'show_in_graphql'   => false, # <-- prevent this options page from showing in the GraphQL Schema
	], $config )
);

GraphQL Field Name

If I were to provide a custom name to "graphql_field_name" for the options page, I would expect it to mapped to the Schema using that name.

i.e.:

acf_add_options_page(
	array_merge( [
		'page_title' => $title,
		'menu_title' => __( 'My Options Page' ),
		'menu_slug'  => 'my-options-page',
		'capability' => 'edit_posts',
		'graphql_field_name'   => 'CustomOptionsName', # <--use a different name than converting the menu_slug to a GraphQL friendly name
	], $config )
);

I would then expect to be able to query like so:

{
  customOptionsName {
    optionsFields {
      text
    }
  }
}

What alternatives have you considered?

No response

Additional Context

The previous version of WPGraphQL for ACF had (limited) support for ACF Options Pages.

There were some bugs with it (called ACF Pro functions even when ACF Pro wasn't active) and it didn't play nicely with WPGraphQL Smart Cache.

We should fix both of those bugs.

Metadata

Metadata

Assignees

Labels

type: enhancementImprovements to existing functionality

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions