add missing files 0.2
authorymh <ymh.work@gmail.com>
Fri, 06 Dec 2019 00:53:05 +0100
changeset 3 5301eb6ce6e2
parent 2 7996096aaae3
child 4 16535597bd14
add missing files
README.md
deploy/deploy.sh
src/web/app/mu-plugins/bedrock-autoloader.php
src/web/app/mu-plugins/disallow-indexing.php
src/web/app/mu-plugins/register-theme-directory.php
src/web/app/plugins/.gitkeep
src/web/app/uploads/.gitkeep
--- a/README.md	Wed Dec 04 16:28:31 2019 +0100
+++ b/README.md	Fri Dec 06 00:53:05 2019 +0100
@@ -59,7 +59,7 @@
 
 ### Export database
 ```
-$ docker-compose exec wp /var/www/html/vendor/bin/wp --allow-root db export --add-drop-table - > pharmakon_dbase_2019-04-19.sql
+$ docker-compose exec wp /var/www/html/vendor/bin/wp --allow-root db export --add-drop-table - > "pharmakon_dbase_$(date '+%Y-%m-%d').sql"
 ```
 
 ### Export media
--- a/deploy/deploy.sh	Wed Dec 04 16:28:31 2019 +0100
+++ b/deploy/deploy.sh	Fri Dec 06 00:53:05 2019 +0100
@@ -32,6 +32,6 @@
 
 pushd "$SCRIPTPATH"
 
-ANSIBLE_SSH_PIPELINING=1 ANSIBLE_STDOUT_CALLBACK=debug ansible-playbook -v -i "./hosts/hosts.$config" -l "$config" ./deploy.yml --extra-vars "rc_version=${VERSION}" --ask-vault-pass
+ANSIBLE_SSH_PIPELINING=1 ANSIBLE_STDOUT_CALLBACK=debug ansible-playbook -v -i "./hosts/hosts.$config" -l "$config" ./deploy.yml --extra-vars "p_version=${VERSION}" --ask-vault-pass
 
 popd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/web/app/mu-plugins/bedrock-autoloader.php	Fri Dec 06 00:53:05 2019 +0100
@@ -0,0 +1,199 @@
+<?php
+/**
+ * Plugin Name: Bedrock Autoloader
+ * Plugin URI: https://github.com/roots/bedrock/
+ * Description: An autoloader that enables standard plugins to be required just like must-use plugins. The autoloaded plugins are included during mu-plugin loading. An asterisk (*) next to the name of the plugin designates the plugins that have been autoloaded.
+ * Version: 1.0.0
+ * Author: Roots
+ * Author URI: https://roots.io/
+ * License: MIT License
+ */
+
+namespace Roots\Bedrock;
+
+if (!is_blog_installed()) {
+    return;
+}
+
+/**
+ * Class Autoloader
+ * @package Roots\Bedrock
+ * @author Roots
+ * @link https://roots.io/
+ */
+class Autoloader
+{
+    /** @var static Singleton instance */
+    private static $instance;
+
+    /** @var array Store Autoloader cache and site option */
+    private $cache;
+
+    /** @var array Autoloaded plugins */
+    private $autoPlugins;
+
+    /** @var array Autoloaded mu-plugins */
+    private $muPlugins;
+
+    /** @var int Number of plugins */
+    private $count;
+
+    /** @var array Newly activated plugins */
+    private $activated;
+
+    /** @var string Relative path to the mu-plugins dir */
+    private $relativePath;
+
+    /**
+     * Create singleton, populate vars, and set WordPress hooks
+     */
+    public function __construct()
+    {
+        if (isset(self::$instance)) {
+            return;
+        }
+
+        self::$instance = $this;
+
+        $this->relativePath = '/../' . basename(__DIR__);
+
+        if (is_admin()) {
+            add_filter('show_advanced_plugins', [$this, 'showInAdmin'], 0, 2);
+        }
+
+        $this->loadPlugins();
+    }
+
+   /**
+    * Run some checks then autoload our plugins.
+    */
+    public function loadPlugins()
+    {
+        $this->checkCache();
+        $this->validatePlugins();
+        $this->countPlugins();
+
+        array_map(static function () {
+            include_once WPMU_PLUGIN_DIR . '/' . func_get_args()[0];
+        }, array_keys($this->cache['plugins']));
+
+        $this->pluginHooks();
+    }
+
+    /**
+     * Filter show_advanced_plugins to display the autoloaded plugins.
+     * @param $show bool Whether to show the advanced plugins for the specified plugin type.
+     * @param $type string The plugin type, i.e., `mustuse` or `dropins`
+     * @return bool We return `false` to prevent WordPress from overriding our work
+     * {@internal We add the plugin details ourselves, so we return false to disable the filter.}
+     */
+    public function showInAdmin($show, $type)
+    {
+        $screen = get_current_screen();
+        $current = is_multisite() ? 'plugins-network' : 'plugins';
+
+        if ($screen->base !== $current || $type !== 'mustuse' || !current_user_can('activate_plugins')) {
+            return $show;
+        }
+
+        $this->updateCache();
+
+        $this->autoPlugins = array_map(function ($auto_plugin) {
+            $auto_plugin['Name'] .= ' *';
+            return $auto_plugin;
+        }, $this->autoPlugins);
+
+        $GLOBALS['plugins']['mustuse'] = array_unique(array_merge($this->autoPlugins, $this->muPlugins), SORT_REGULAR);
+
+        return false;
+    }
+
+    /**
+     * This sets the cache or calls for an update
+     */
+    private function checkCache()
+    {
+        $cache = get_site_option('bedrock_autoloader');
+
+        if ($cache === false || (isset($cache['plugins'], $cache['count']) && count($cache['plugins']) !== $cache['count'])) {
+            $this->updateCache();
+            return;
+        }
+
+        $this->cache = $cache;
+    }
+
+    /**
+     * Get the plugins and mu-plugins from the mu-plugin path and remove duplicates.
+     * Check cache against current plugins for newly activated plugins.
+     * After that, we can update the cache.
+     */
+    private function updateCache()
+    {
+        require_once ABSPATH . 'wp-admin/includes/plugin.php';
+
+        $this->autoPlugins = get_plugins($this->relativePath);
+        $this->muPlugins   = get_mu_plugins();
+        $plugins           = array_diff_key($this->autoPlugins, $this->muPlugins);
+        $rebuild           = !is_array($this->cache['plugins']);
+        $this->activated   = $rebuild ? $plugins : array_diff_key($plugins, $this->cache['plugins']);
+        $this->cache       = ['plugins' => $plugins, 'count' => $this->countPlugins()];
+
+        update_site_option('bedrock_autoloader', $this->cache);
+    }
+
+    /**
+     * This accounts for the plugin hooks that would run if the plugins were
+     * loaded as usual. Plugins are removed by deletion, so there's no way
+     * to deactivate or uninstall.
+     */
+    private function pluginHooks()
+    {
+        if (!is_array($this->activated)) {
+            return;
+        }
+
+        foreach ($this->activated as $plugin_file => $plugin_info) {
+            do_action('activate_' . $plugin_file);
+        }
+    }
+
+    /**
+     * Check that the plugin file exists, if it doesn't update the cache.
+     */
+    private function validatePlugins()
+    {
+        foreach ($this->cache['plugins'] as $plugin_file => $plugin_info) {
+            if (!file_exists(WPMU_PLUGIN_DIR . '/' . $plugin_file)) {
+                $this->updateCache();
+                break;
+            }
+        }
+    }
+
+    /**
+     * Count the number of autoloaded plugins.
+     *
+     * Count our plugins (but only once) by counting the top level folders in the
+     * mu-plugins dir. If it's more or less than last time, update the cache.
+     *
+     * @return int Number of autoloaded plugins.
+     */
+    private function countPlugins()
+    {
+        if (isset($this->count)) {
+            return $this->count;
+        }
+
+        $count = count(glob(WPMU_PLUGIN_DIR . '/*/', GLOB_ONLYDIR | GLOB_NOSORT));
+
+        if (!isset($this->cache['count']) || $count !== $this->cache['count']) {
+            $this->count = $count;
+            $this->updateCache();
+        }
+
+        return $this->count;
+    }
+}
+
+new Autoloader();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/web/app/mu-plugins/disallow-indexing.php	Fri Dec 06 00:53:05 2019 +0100
@@ -0,0 +1,14 @@
+<?php
+/*
+Plugin Name:  Disallow Indexing
+Plugin URI:   https://roots.io/bedrock/
+Description:  Disallow indexing of your site on non-production environments.
+Version:      1.0.0
+Author:       Roots
+Author URI:   https://roots.io/
+License:      MIT License
+*/
+
+if (defined('WP_ENV') && WP_ENV !== 'production' && !is_admin()) {
+    add_action('pre_option_blog_public', '__return_zero');
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/web/app/mu-plugins/register-theme-directory.php	Fri Dec 06 00:53:05 2019 +0100
@@ -0,0 +1,14 @@
+<?php
+/*
+Plugin Name:  Register Theme Directory
+Plugin URI:   https://roots.io/bedrock/
+Description:  Register default theme directory
+Version:      1.0.0
+Author:       Roots
+Author URI:   https://roots.io/
+License:      MIT License
+*/
+
+if (!defined('WP_DEFAULT_THEME')) {
+    register_theme_directory(ABSPATH . 'wp-content/themes');
+}