Skip to content

Commit

Permalink
nextwp-toolkit plugin: add logo / add headless templates creator / or…
Browse files Browse the repository at this point in the history
…ganize functions / cleanup
  • Loading branch information
CalebBarnes committed Jan 7, 2024
1 parent a6936f6 commit 7bb18e3
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 107 deletions.
9 changes: 9 additions & 0 deletions wordpress/plugins/nextwp-toolkit/acf/acf-prepare-revision.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
// Includes the ACF fields in the REST API response for post revisions
add_filter( 'rest_prepare_revision', function( $response, $post ) {
$data = $response->get_data();

$data['acf'] = get_fields( $post->ID );

return rest_ensure_response( $data );
}, 10, 2 );
11 changes: 11 additions & 0 deletions wordpress/plugins/nextwp-toolkit/acf/google-maps-key.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

function nextwp_acf_google_map_api( $api ){
$apiKey = get_field('nextwp_google_maps_api_key', 'options');
if ($apiKey) {
$api['key'] = $apiKey;
}
return $api;
}
add_filter('acf/fields/google_map/api', 'nextwp_acf_google_map_api');

152 changes: 90 additions & 62 deletions wordpress/plugins/nextwp-toolkit/acf/options-page.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
<?php
function nextwp_admin_menu_icon_css() {
?>
<style>
#adminmenu .toplevel_page_nextwp div.wp-menu-image img {
height: 20px;
}
</style>
<?php
}
add_action('admin_head', 'nextwp_admin_menu_icon_css');

if (function_exists('acf_add_options_page')) :

acf_add_options_page(array(
'page_title' => 'NextWP',
'page_title' => 'NextWP Toolkit',
'menu_title' => 'NextWP',
'menu_slug' => 'nextwp',
'capability' => 'edit_posts',
'icon_url' => 'dashicons-editor-code',
'position' => 2,
'icon_url' => 'https://www.nextwp.org/icon.png',
'position' => 98,
'redirect' => false
));

acf_add_options_page(array(
'page_title' => 'Theme Options',
'menu_title' => 'Theme Options',
'menu_slug' => 'theme-options',
'capability' => 'edit_posts',
'icon_url' => 'dashicons-admin-customizer',
'position' => 2,
'redirect' => false,
'show_in_graphql' => true

acf_add_options_sub_page(array(
'page_title' => 'NextWP Toolkit - ACF Utilities',
'menu_title' => 'ACF',
'menu_slug' => 'nextwp-flexible-content',
'parent_slug' => 'nextwp',
));


endif;


if (function_exists('acf_add_local_field_group')) :
acf_add_local_field_group(array(
'key' => 'group_1',
'title' => 'Headless Features',
'title' => 'Settings',
'fields' => array(
array(
'key' => 'field_63dac3a7baf64',
Expand All @@ -44,15 +53,15 @@
'class' => '',
'id' => '',
),
'default_value' => 'http://localhost:3000/',
'default_value' => 'http://localhost:3000',
'placeholder' => '',
'instructions' => 'The URL of your headless frontend. The preview mode will add /preview to the end of this.',
'instructions' => 'The URL of your Next.js frontend. The preview mode will use this for the preview iframe.',
),

array(
'key' => 'field_63dac3a7bal85',
'label' => 'Preview Secret',
'name' => 'preview_secret',
'name' => 'nextwp_preview_secret',
'aria-label' => '',
'type' => 'text',
'instructions' => '',
Expand All @@ -63,45 +72,97 @@
'class' => '',
'id' => '',
),
'default_value' => 'my-preview-secret',
'default_value' => '',
'placeholder' => '',
'instructions' => 'The secret used for entering preview mode. This should match the env NEXT_PREVIEW_SECRET in your Next.js App.',
'instructions' => 'The secret used for entering preview mode. This should match the env NEXT_PREVIEW_SECRET in your NextWP project.',
),

array(
'key' => 'headless_preview',
'label' => 'Headless Preview',
'instructions' => 'Enable preview mode for headless WordPress',
'instructions' => 'Enable preview mode for <a href="https://www.nextwp.org/" target="_blank">NextWP</a>.',
'name' => 'headless_preview',
'type' => 'true_false',
'message' => 'Enabled'
),



array(
'key' => 'decapitate_wp',
'label' => 'Decapitate WP',
'instructions' => 'Remove old frontend of WordPress',
'instructions' => 'Remove the default frontend of WordPress',
'name' => 'decapitate_wp',
'type' => 'true_false',
'message' => 'Enabled'
),

array(
'key' => 'menu_locations',
'label' => 'Additional Menu Locations',
'name' => 'menu_locations',
'type' => 'repeater',
'instructions' => 'Add additional menu locations if needed.',
'show_in_graphql' => 1,
'layout' => 'block',
'button_label' => 'Add Menu Location',
'sub_fields' => array(
array(
'key' => 'menu_location_name',
'label' => 'Name',
'name' => 'menu_location_name',
'type' => 'text',
'required' => 1,
'show_in_graphql' => 1,
'wrapper' => array(
'width' => '50%',
),
),
array(
'key' => 'menu_location_slug',
'label' => 'Slug',
'name' => 'menu_location_slug',
'type' => 'text',
'required' => 1,
'show_in_graphql' => 1,
'wrapper' => array(
'width' => '50%',
),
),
),
),
),
'location' => array(
array(
array(
'param' => 'options_page',
'operator' => '==',
'value' => 'nextwp',
),
),
),
'menu_order' => 1,
'style' => 'default',
));


acf_add_local_field_group(array(
'key' => 'nextwp_group_2',
'title' => 'ACF Utilities',
'fields' => array(

array(
'key' => 'flexible_content',
'label' => 'Flexible Content',
'instructions' => 'Auto add elements with title "Module: (...)" to flexible content section on default page template',
'label' => 'Clone Flexible Content Blocks',
'instructions' => 'Clones field groups with title "Module: (...)" to a flexible content field group on the default page template. <br/>Read more about using ACF Flexible Content in NextWP <a href="https://www.nextwp.org/packages/nextwp/core/components#flexible-content" target="_blank">here</a>.',
'name' => 'flexible_content',
'type' => 'true_false',
'message' => 'Enabled'
),
array(
'key' => 'field_623cd145eee11',
'label' => 'Modules Post Types',
'label' => 'Flexible Content Post Types',
'name' => 'modules_post_types',
'type' => 'repeater',
'instructions' => 'Additional post types to add the Modules field group to.',
'instructions' => 'Additional post types to add this ACF Flexible Content field group to.',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
Expand Down Expand Up @@ -142,40 +203,6 @@
),
),

array(
'key' => 'menu_locations',
'label' => 'Additional Menu Locations',
'name' => 'menu_locations',
'type' => 'repeater',
'instructions' => 'Add menu locations here (required to show menus in GraphQL)',
'show_in_graphql' => 1,
'layout' => 'block',
'button_label' => 'Add Menu Location',
'sub_fields' => array(
array(
'key' => 'menu_location_name',
'label' => 'Name',
'name' => 'menu_location_name',
'type' => 'text',
'required' => 1,
'show_in_graphql' => 1,
'wrapper' => array(
'width' => '50%',
),
),
array(
'key' => 'menu_location_slug',
'label' => 'Slug',
'name' => 'menu_location_slug',
'type' => 'text',
'required' => 1,
'show_in_graphql' => 1,
'wrapper' => array(
'width' => '50%',
),
),
),
),
array(
'key' => 'nextwp_google_maps_api_key',
'label' => 'Google Maps API Key',
Expand All @@ -192,15 +219,16 @@
),
'default_value' => false,
'placeholder' => '',
'instructions' => 'The Google Maps API Key to use for the Google Maps field type in ACF. May also be used in the headless app.',
'instructions' => 'The Google Maps API Key to use for the Google Maps field type in ACF. This value can also be used in a NextWP project with the <a href="https://www.nextwp.org/packages/nextwp/core/functions#get-options-page" target="_blank">getOptionsPage</a> function.',
),

),
'location' => array(
array(
array(
'param' => 'options_page',
'operator' => '==',
'value' => 'nextwp',
'value' => 'nextwp-flexible-content',
),
),
),
Expand Down
10 changes: 0 additions & 10 deletions wordpress/plugins/nextwp-toolkit/includes/console_log.php

This file was deleted.

Loading

1 comment on commit 7bb18e3

@vercel
Copy link

@vercel vercel bot commented on 7bb18e3 Jan 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nextwp-starter – ./apps/next-wordpress-starter

nextwp-starter.vercel.app
nextwp-starter-git-main-calebbarnes.vercel.app
nextwp-starter-calebbarnes.vercel.app

Please sign in to comment.