elementor / wp2static

WordPress static site generator for security, performance and cost benefits
https://wp2static.com
The Unlicense
1.42k stars 265 forks source link

Bedrock Support / Filtering SiteInfo Class #814

Open palmiak opened 2 years ago

palmiak commented 2 years ago

There is a problem with WP2Static and Bedrock. Bedrock has a bit different folder structure (https://roots.io/docs/bedrock/master/folder-structure/) and the ABSPATH is pointing a bit wrong (it's pointing the wp folder when it should point to the web folder).

Apart from Bedrock probably this could also cause problems where home_url and site_url are different (although I'm guessing here).

So I think that we should make all the properties filterable - something like:

$info = [
    // Core
    'site_path' => ABSPATH,
    'site_url' => $site_url,

    /*
        Note:  'home_path' => get_home_path(),
        // errors trying to find it in WP2Static\get_home_path()...
    */
    'home_url' => trailingslashit( get_home_url() ),
    'includes_path' => trailingslashit( ABSPATH . WPINC ),
    'includes_url' => includes_url(),

    /*
        TODO: Q on subdir:

        Does it matter?
        'subdirectory' => $this->isSiteInstalledInSubDirectory(),

        A: It shouldn't, but current mechanism for rewriting URLs
        has some cases that require knowledge of it...
    */

    // Content
    'content_path' => trailingslashit( WP_CONTENT_DIR ),
    'content_url' => trailingslashit( content_url() ),
    'uploads_path' =>
        trailingslashit( $upload_path_and_url['basedir'] ),
    'uploads_url' => trailingslashit( $upload_path_and_url['baseurl'] ),

    // Plugins
    'plugins_path' => trailingslashit( WP_PLUGIN_DIR ),
    'plugins_url' => trailingslashit( plugins_url() ),

    // Themes
    'themes_root_path' => trailingslashit( get_theme_root() ),
    'themes_root_url' => trailingslashit( get_theme_root_uri() ),
    'parent_theme_path' => trailingslashit( get_template_directory() ),
    'parent_theme_url' =>
        trailingslashit( get_template_directory_uri() ),
    'child_theme_path' => trailingslashit( get_stylesheet_directory() ),
    'child_theme_url' =>
        trailingslashit( get_stylesheet_directory_uri() ),
];

self::$info = apply_filters( 'wp2static_modify_siteinfo', $info );

and than we could create a mu-plugin for Bedrock that would use the correct site_path based on:

/**
 * Directory containing all of the site's files
 *
 * @var string
 */
$root_dir = dirname(__DIR__);

/**
 * Document Root
 *
 * @var string
 */
$webroot_dir = $root_dir . '/web';

// OTHER CODE

Config::define('CONTENT_DIR', '/app');
Config::define('WP_CONTENT_DIR', $webroot_dir . Config::get('CONTENT_DIR'));

If you're OK with this I will gladly create a PR for this.

leonstafford commented 2 years ago

Sounds awesome! Would love to be supporting roots' Bedrock! Many thanks and sounds solid for PR!

Do you think the Bedrock support needs to be in separate plugin or we could handle by detecting Bedrock env within WP2Static core?

Tradeoff of keeping core lean vs supporting popular dev env out of the box

palmiak commented 2 years ago

I would go for separate. It's a bit of Bedrock way - https://github.com/roots/multisite-url-fixer - this how the fix for WP Multisite looks like.

Here I would do the same - a separate plugin with Composer support for "type": "wordpress-muplugin",

leonstafford commented 2 years ago

Great! Makes sense!

leonstafford commented 2 years ago

I know we have wp2static_modify_initial_crawl_list, but also have wp2static_curl_user_agent. Let's drop the modify for this one and use wp2static_siteinfo as the filter name.

leonstafford commented 2 years ago

SiteInfo filtering supported merged in with @palmiak's PR

Keeping this open until there's a plugin to make use of it

leonstafford commented 2 years ago

@palmiak if you create a repo for the Bedrock plugin or just some function code, would you like to add something on docs site: https://github.com/WP2Static/wp2static-www when ready?