ACF functionality and readme update
This commit is contained in:
10
README.md
10
README.md
@@ -1,6 +1,6 @@
|
|||||||
## WordPress Backend
|
## WordPress Backend
|
||||||
|
|
||||||
Before you install WordPress, make sure you have all the required software installed for your operating system.
|
The wordpress folder contains the plugin dependencies and the Saburly Headless theme. You can add them to your existing development environment. Or if you want to install WordPress and a full dev environment, you can use the scripts from this repository. In that case, make sure you have all the required software installed for your operating system.
|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
@@ -22,3 +22,11 @@ When the installation process completes successfully:
|
|||||||
* The WordPress GraphQL API is available at [http://localhost:8080/graphql](http://localhost:8080/graphql)
|
* The WordPress GraphQL API is available at [http://localhost:8080/graphql](http://localhost:8080/graphql)
|
||||||
* The WordPress admin is at [http://localhost:8080/wp-admin/](http://localhost:8080/wp-admin/)
|
* The WordPress admin is at [http://localhost:8080/wp-admin/](http://localhost:8080/wp-admin/)
|
||||||
|
|
||||||
|
|
||||||
|
### Manual install
|
||||||
|
|
||||||
|
You can replace the wordpress folder
|
||||||
|
|
||||||
|
### Frontend
|
||||||
|
|
||||||
|
The contains frontend is stored in a separate repository in Gitlab.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<?php
|
||||||
|
// @codingStandardsIgnoreFile -- for PHPCS 2.9 support in Atom
|
||||||
|
// phpcs:ignoreFile
|
||||||
|
// Silence is golden.
|
||||||
@@ -1,4 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// Frontend origin
|
||||||
|
require_once 'inc/frontend-origin.php';
|
||||||
|
|
||||||
|
// ACF commands
|
||||||
|
require_once 'inc/class-acf-commands.php';
|
||||||
|
|
||||||
// Logging functions
|
// Logging functions
|
||||||
require_once 'inc/log.php';
|
require_once 'inc/log.php';
|
||||||
|
|
||||||
@@ -15,4 +22,4 @@ require_once 'inc/menus.php';
|
|||||||
require_once 'inc/acf-options.php';
|
require_once 'inc/acf-options.php';
|
||||||
|
|
||||||
// Add custom API endpoints
|
// Add custom API endpoints
|
||||||
require_once 'inc/api-routes.php';
|
require_once 'inc/api-routes.php';
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// Add a custom options page to associate ACF fields with
|
||||||
|
if ( function_exists( 'acf_add_options_page' ) ) {
|
||||||
|
acf_add_options_page( [
|
||||||
|
'page_title' => 'Headless Settings',
|
||||||
|
'menu_title' => 'Headless',
|
||||||
|
'menu_slug' => 'headless-settings',
|
||||||
|
'capability' => 'manage_options',
|
||||||
|
'post_id' => 'headless-settings',
|
||||||
|
'redirect' => false,
|
||||||
|
] );
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
if ( defined( 'WP_CLI' ) && WP_CLI && ! class_exists( 'ACF_Commands' ) ) {
|
||||||
|
/**
|
||||||
|
* ACF_Commands
|
||||||
|
*/
|
||||||
|
class ACF_Commands extends WP_CLI_Command {
|
||||||
|
/**
|
||||||
|
* Sync ACF Fields
|
||||||
|
*
|
||||||
|
* ## OPTIONS
|
||||||
|
*
|
||||||
|
* @when init
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* wp acf sync
|
||||||
|
*
|
||||||
|
* @param arr $args Arguments
|
||||||
|
* @param arr $assoc_args Associated arguments
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function sync( $args, $assoc_args ) {
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$groups = acf_get_field_groups();
|
||||||
|
$sync = [];
|
||||||
|
|
||||||
|
// bail early if no field groups
|
||||||
|
if ( empty( $groups ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// find JSON field groups which have not yet been imported
|
||||||
|
foreach ( $groups as $group ) {
|
||||||
|
// vars
|
||||||
|
$local = acf_maybe_get( $group, 'local', false );
|
||||||
|
$modified = acf_maybe_get( $group, 'modified', 0 );
|
||||||
|
$private = acf_maybe_get( $group, 'private', false );
|
||||||
|
|
||||||
|
// ignore DB / PHP / private field groups
|
||||||
|
if ( 'json' !== $local || $private ) {
|
||||||
|
// do nothing
|
||||||
|
true;
|
||||||
|
} elseif ( ! $group['ID'] ) {
|
||||||
|
$sync[ $group['key'] ] = $group;
|
||||||
|
} elseif ( $modified && $modified > get_post_modified_time( 'U', true, $group['ID'], true ) ) {
|
||||||
|
$sync[ $group['key'] ] = $group;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// bail if no sync needed
|
||||||
|
if ( empty( $sync ) ) {
|
||||||
|
WP_CLI::success( 'No ACF Sync Required' );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $sync ) ) {
|
||||||
|
acf_update_setting( 'json', false );
|
||||||
|
|
||||||
|
// vars
|
||||||
|
$new_ids = [];
|
||||||
|
|
||||||
|
foreach ( $sync as $key => $v ) {
|
||||||
|
// append fields
|
||||||
|
if ( acf_have_local_fields( $key ) ) {
|
||||||
|
$sync[ $key ]['fields'] = acf_get_local_fields( $key );
|
||||||
|
}
|
||||||
|
// import
|
||||||
|
$field_group = acf_import_field_group( $sync[ $key ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WP_CLI::success( 'ACF SYNC SUCCESS!' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WP_CLI::add_command( 'acf', 'ACF_Commands' );
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user