wpengine / faustjs

Faust.js™ - The Headless WordPress Framework
https://faustjs.org
Other
1.44k stars 134 forks source link

Proposal: Support use of Faust app as companion to regular WordPress site #1464

Closed rshov closed 1 year ago

rshov commented 1 year ago

I have a use case that may not be what Faust is intended for, but I think will be useful to a number of people. We are not ready to fully replace our WordPress site with a headless site, but would like to create one or more Faust apps to complement the existing WordPress site. The apps would live at subdomains of the main site, and are just for custom apps that we need, and are easier to implement in Next.js using the authentication features that Faust provides. This might eventually lead to going fully headless, but I think this would be a stepping stone for us.

The problem that we have run into though is mainly with the Menu Locations, where Faust basically takes over the Menu Locations from the existing site and replacing them with the Faust setting. When using the Faust plugin on the site, the menus went missing. We found we could work around this by commenting out this line in the plugin code:

image

But it seems like this would be nice to have as an option in the Faust settings. Something like this:

image

There may be other potential issues like this, but the Menus is all that I've run into so far.

I imagine there might be other people that want to continue using their existing WordPress site as they transition to a headless Faust site. I think that would be a good scenario to support if possible.

Thank you for the awesome work on this! This project is going to be incredibly useful.

josephfusco commented 1 year ago

Hey @rshov, thank you for the proposal! We agree that Faust should have the ability to be a companion to traditional WordPress, and that's something we are working towards.

In the spirit of this proposal, the WordPress plugin currently provides a filter, faustwp_exclude_from_public_redirect, allowing you to exclude specific routes from redirecting when the "Enable public route redirects" option is active.

josephfusco commented 1 year ago

This snippet should work for now.

/**
 * Use the active theme's menu locations.
 */
add_filter( 'faustwp_get_setting', function( $value, $name ) {
    if ( 'menu_locations' !== $name ) {
        return $value;
    }

    $locations = array_flip( get_nav_menu_locations() );

    return implode( ',', $locations );
}, 2, 10);