GithubHelp home page GithubHelp logo

roots / wp-stage-switcher Goto Github PK

View Code? Open in Web Editor NEW
370.0 28.0 43.0 38 KB

WordPress plugin that allows you to switch between different environments from the admin bar

Home Page: https://roots.io/plugins/stage-switcher/

License: MIT License

PHP 100.00%
wordpress-plugin bedrock wordpress

wp-stage-switcher's Introduction

WordPress Stage Switcher

Packagist Packagist Downloads

A WordPress plugin that allows you to switch between different environments from the admin bar.

WordPress Stage Switcher

Requirements

You'll need to have ENVIRONMENTS and WP_ENV defined in your WordPress config.

The ENVIRONMENTS constant must be a serialized array of 'environment' => 'url' elements:

$envs = [
  'development' => 'http://example.dev',
  'staging'     => 'http://staging.example.com',
  'production'  => 'http://example.com'
];
define('ENVIRONMENTS', serialize($envs));

Note: the serialize() call is not needed on PHP 7.0 or newer.

WP_ENV must be defined as the current environment:

define('WP_ENV', 'development');

If you use Bedrock, WP_ENV is already defined in the config.

Installation

This plugin must be installed via Composer. Add wp-stage-switcher to your project's dependencies:

composer require roots/wp-stage-switcher

Or manually add it to your composer.json:

"require": {
  "php": ">=7.1",
  "roots/wordpress": "5.1.1",
  "roots/wp-stage-switcher": "~2.1"
}

Support

Use the Roots Discourse to ask questions and get support.

wp-stage-switcher's People

Contributors

aaemnnosttv avatar arty2 avatar dotsam avatar grappler avatar kalenjohnson avatar knowler avatar ocean90 avatar retlehs avatar runofthemill avatar swalkinshaw avatar swissspidy avatar valentinocossar avatar xeader avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-stage-switcher's Issues

undefined constant

Notice: Use of undefined constant ENVIRONMENTS - assumed 'ENVIRONMENTS' in /public_html/bedrock/web/app/plugins/wp-stage-switcher-2.0.0/wp-stage-switcher.php on line 50 Notice: unserialize(): Error at offset 0 of 12 bytes in /public_html/bedrock/web/app/plugins/wp-stage-switcher-2.0.0/wp-stage-switcher.php on line 50 Warning: Invalid argument supplied for foreach() in /public_html/bedrock/web/app/plugins/wp-stage-switcher-2.0.0/wp-stage-switcher.php on line 53

Bug when WP is installed in a subfolder

Hi,

Great plugin. However, if I have WordPress installed in a subfolder of the domain, that subfolder is added to the urls of the other environments, which is obviously not desirable.

It would be great if you fix this.

Thanks!

Vasko

Doesn't work with Wordpress Multisite

This is one of the coolest and most useful plugins I've come across in a while, however, it doesn't appear to have support for multisite setups.

From what I can tell, the ENVIRONMENTS constant doesn't let you define more than 1 site.

Warning: Invalid argument supplied for foreach()

On initial composer update with plugin as required in composer.json

"require": { "php": ">=5.6", "composer/installers": "~1.0.12", "vlucas/phpdotenv": "^2.0.1", "johnpbloch/wordpress": "4.6.1", "oscarotero/env": "^1.0", "roots/wp-password-bcrypt": "1.0.0", "wpackagist-plugin/contact-form-7": "dev-trunk", "wpackagist-plugin/getty-images": "dev-trunk", "roots/wp-stage-switcher": "2.0.0", "roots/soil": "3.7.1"

I am using and have setup Trellis/Bedrock. Line 53 states an issue between the stages but as I understand Bedrock already has WP_ENV; defined?

( ! ) Warning: Invalid argument supplied for foreach() in /srv/www/thefootballfamily.com/current/web/app/plugins/wp-stage-switcher/wp-stage-switcher.php on line 53
Call Stack

Time Memory Function Location

1 0.0009 468976 {main}( ) .../plugins.php:0
2 0.2273 20106184 require_once( '/srv/www/thefootballfamily.com/current/web/wp/wp-admin/admin-header.php' ) .../plugins.php:408
3 0.2398 20186528 do_action( ) .../admin-header.php:214
4 0.2398 20186928 wp_admin_bar_render( ) .../plugin.php:524
5 0.2398 20187304 do_action_ref_array( ) .../admin-bar.php:83
6 0.2412 20193816 Roots\StageSwitcher\StageSwitcher->admin_bar_stage_switcher( ) .../plugin.php:600

Visibility should depend on roles

This menu should probably only be displayed for admins by default. We could allow a list of roles to be provided through a filter as well.

Add support for applying different colors based on environment

Summary

Add support for changing the color of the wp-admin based on environment

Having the ability for each environment to have a different color scheme would help make it more obvious as to which environment you are currently viewing

Implementation Ideas

  1. Add env-<environment> <body> classes to allow writing CSS to target based by environment
    add_filter('body_class', function($classes) {
        $classes[] = 'env-'.sanitize_title(WP_ENV);
        return $classes;
    });
  2. Add the ability to swap the wp-admin color scheme based on environment (inspired by wpmark)

Install without composer?

Is this possible? I want to use this on WP Engine, but WP Engine gives no ssh access. I need to be able to install it via SFTP. The issue is that this, of course, won't load dependencies and such properly.

Bug: Multisite URL Rewriting Not Functional

Terms

Description

What's wrong?

Subdomain-based multisite URLs aren't modified in any helpful way. The full current URL host-part is replaced by the stage's host-part, with no attempt made to preserve the blog's domain.

What have you tried?

Configured the ENVIRONMENTS array with the URLs of the "main site" or just the domain suffix.

What insights have you gained?

When originally implemented in 890a711, the host was split on the assumption that the subdomain would be only a single level, which worked in most cases, but not all. When rewritten in #7, Purl was used for its registerableDomain property to attempt to determine the base domain portion which should be replaced and the subdomain which should be kept. Finally, in #18, the Purl dependancy was removed, but the multisite_url method was simplified too much and all logic about trying to determine subdomain and base domain was removed.

Possible solutions

Without involving external dependancies (and even then, a solution may not be available for every possible outcome), determining with certainty the sub domain/base domain portion of a multisite URL is difficult. I propose moving back to a solution similar to the original in 890a711 but also providing a filter to allow for domain structures that don't fit.

Temporary workarounds

The ENVIRONMENTS array can be defined in a sunrise.php drop-in once the multisite domain has been resolved, but this still presents an issue where URL scheme might be changed based on the scheme of the current stage (ie. a production site using the https scheme would overwrite an http scheme for a development URL creating a broken link).

Steps To Reproduce

  1. Set up a subdomain-based multisite installation in 2 or more environments
  2. Configure the ENVIRONMENTS array with URLs for these environments

Expected Behavior

Subdomain portions of the environment URL will be maintained while base environment domains are replaced

Actual Behavior

The entire subdomain URL is replaced with the URL from the ENVIRONMENTS array, discarding the subdomain

Relevant Log Output

No response

Versions

2.1.1

Publish new version

There have been a few enhancements and bug fixes in the past that I think warrant a new release. Plus, there are 3 pull requests that are currently open that could be considered as well.

It would be really great if a new version could be tagged after these get in as well.

Please let me know if I can help with a changelog or something.

Make it un-ignorably obvious when you're editing a non-canonical environment

Here's an enhancement idea, that I'm willing to write code for, but want to get a ๐Ÿ‘ from project owners first. I could see this idea being judged as an entirely separate plugin, but for me it is the feature that's missing to make this really great. Please let me know if you see it as a good fit.

There would be two steps to this:

  1. Extend the ENVIRONMENT constant to optionally support meta data through nested arrays. Strings will still work, but you could now do something like this:
$envs = array(
  'development' => array(
    'url' => 'http://example.dev',
    'canonical' => false
  ),
  'staging'     => array(
    'url' => 'http://staging.example.com',
    'canonical' => false
  ),
  'production'  => 'http://example.com'
);
define('ENVIRONMENTS', serialize($envs));
  1. If the environment is not canonical, add an Admin notice with filterable text that conveys essentially "whoa be super careful!", and change the color of the admin bar to something eye catching, like bright red or orange.

The color, too, should probably be filterable. And since a user's admin color scheme is dynamic, this will need to account for that somehow โ€” that bit will take some research.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.