Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Commit

Permalink
Add/acf dev tools (#234)
Browse files Browse the repository at this point in the history
* Add the acf component

* Add demo content
  • Loading branch information
Luehrsen authored Nov 12, 2020
1 parent 9399a8e commit eb9ce9b
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bin/install-wordpress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,16 @@ if ! $(${WP_CLI} wp core is-installed); then
# Import and activate needed plugins
${WP_CLI} wp plugin install gutenberg wordpress-importer query-monitor debug-bar --activate

echo $(status_message "Downloading WordPress theme unit test data...")
${WP_CLI} curl -O https://raw.githubusercontent.com/WPTRT/theme-unit-test/master/themeunittestdata.wordpress.xml >/dev/null 2>&1

echo $(status_message "Importing WordPress theme unit test data...\n")
${WP_CLI} wp import themeunittestdata.wordpress.xml --authors=create

# Activate debugging
${WP_CLI} wp config set WP_DEBUG true --raw
${WP_CLI} wp config set WP_ENVIRONMENT_TYPE "development"
${WP_CLI} wp config set LH_CURRENTLY_EDITING "lhpbp"

docker-compose run --user=root wordpress chown www-data -R /var/www/

Expand Down
93 changes: 93 additions & 0 deletions build/inc/ACF/Component.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/**
* Lhplugin\ACF\Component class
*
* @package lhpbp
*/

namespace WpMunich\lhpbp\ACF;
use WpMunich\lhpbp\Component_Interface;
use function add_action;
use function wp_get_environment_type;
use function acf_add_options_page;

/**
* A class to handle acf related logic..
*/
class Component implements Component_Interface {

/**
* Gets the unique identifier for the plugin component.
*
* @return string Component slug.
*/
public function get_slug() {
return 'acf';
}

/**
* Adds the action and filter hooks to integrate with WordPress.
*/
public function initialize() {
if ( wp_get_environment_type() === 'development' && defined( 'LH_CURRENTLY_EDITING' ) && LH_CURRENTLY_EDITING === 'lhpbp' ) {
add_filter( 'acf/settings/save_json', array( $this, 'acf_json_save_point' ) );
}

add_filter( 'acf/settings/load_json', array( $this, 'acf_json_load_point' ) );

add_action( 'acf/init', array( $this, 'add_options_page' ) );
}

/**
* Add the json save point for acf.
*
* @param string $path Save path.
*
* @return string Save path.
*/
public function acf_json_save_point( $path ) {
$path = LHTHEME_PATH . 'acf-json';
return $path;
}

/**
* Add the json load point for acf.
*
* @param array $paths An array of paths.
*
* @return array An array of paths.
*/
public function acf_json_load_point( $paths ) {
$paths[] = LHPLUGIN_PATH . 'acf-json';

return $paths;
}

/**
* Hide the acf admin
*
* @return void
*/
private function hide_acf_admin() {
add_filter( 'acf/settings/show_admin', '__return_false' );
}

/**
* Add a theme options page.
*/
public function add_options_page() {
if ( ! function_exists( 'acf_add_options_page' ) ) {
return;
}

$option_page = acf_add_options_page(
array(
'page_title' => __( 'Theme General Settings', 'lhpbp' ),
'menu_title' => __( 'Theme Settings', 'lhpbp' ),
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false,
)
);
}
}
1 change: 1 addition & 0 deletions build/inc/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ protected function get_default_components() {
$components = array(
new Blocks\Component(),
new i18n\Component(),
new ACF\Component(),
);

return $components;
Expand Down

0 comments on commit eb9ce9b

Please sign in to comment.