Monday, July 11, 2022
HomeWordPress Developmentthemes - Find out how to extract a .wp-env.json or composer.json containing...

themes – Find out how to extract a .wp-env.json or composer.json containing plugin variations from a manufacturing web site?


Is there a concise, typical means of extracting theme and plugin variations
right into a config file corresponding to .wp-env.json or composer.json with out
having direct entry to the database?

I assumed there existed a .wp-env.json generator for wp-cli, however I could not discover it. Which may assist if out there.

There are tons of how to clone a web site, however let’s assume we solely need to get a fundamental auto-generated .wp-env.json data instantly from the primary web site.

Unsure if it is helpful however here is a skeleton of a plugin that assumes solely plugins and themes hosted on wordpress.org:

<?php
/**
 * Plugin Identify: WPSE-407466 - REST endpoint for fundamental wp-env data
 */
add_action( 'rest_api_init', perform() {
    register_rest_route(
        'wpse/v1',
        '/wp-env/',
        array(
           'strategies'             => 'GET',
           'permission_callback' => perform () {
                return current_user_can( 'manage_options' );
            },
           'callback'            => perform( $request ) {
                $active_plugins = (array) get_option( 'active_plugins', array() );
                $information           = array();
                foreach( $active_plugins as $plugin ) {
                   $information['plugins'][] = 'WordPress/' . dirname( $plugin );
                }
                $information['themes']     = 'WordPress/' . get_stylesheet();
                $information['core']       = 'WordPress/WordPress#' . get_bloginfo( 'model' );
                $information['phpVersion'] = phpversion();
                return $information;
            },
        )
    );
} );

Visiting

https://instance.com/wp-json/wpse/v1/wp-env

as logged in person with manage_options functionality will output one thing like:

{
    plugins: [
        "WordPress/jetpack",
        "WordPress/buddypress"
    ],
    themes: [
        "WordPress/twentytwentytwo"
    ],
    core: "WordPress/WordPress#5.9.3",
    phpVersion: "7.4.11"
}

however be aware that this isn’t examined but with wp-env, simply used

https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/

as a steerage.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments