From 121e3f20d7a2d5e5fb6c74b08ae37e832add88d1 Mon Sep 17 00:00:00 2001 From: QWp6t Date: Sat, 24 Dec 2016 23:45:05 -0800 Subject: [PATCH 1/4] Prefer passing class name when binding new shared instances --- src/lib/Sage/Template/BladeProvider.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/lib/Sage/Template/BladeProvider.php b/src/lib/Sage/Template/BladeProvider.php index 40d59b4..63f3247 100644 --- a/src/lib/Sage/Template/BladeProvider.php +++ b/src/lib/Sage/Template/BladeProvider.php @@ -16,11 +16,12 @@ class BladeProvider extends ViewServiceProvider /** * @param ContainerContract $container * @param array $config + * @SuppressWarnings(PHPMD.StaticAccess) */ public function __construct(ContainerContract $container = null, $config = []) { /** @noinspection PhpParamsInspection */ - parent::__construct($container ?: new Container); + parent::__construct($container ?: Container::getInstance()); $this->app->bindIf('config', function () use ($config) { return $config; @@ -45,9 +46,7 @@ class BladeProvider extends ViewServiceProvider */ public function registerFilesystem() { - $this->app->bindIf('files', function () { - return new Filesystem; - }, true); + $this->app->bindIf('files', Filesystem::class, true); return $this; } @@ -56,9 +55,7 @@ class BladeProvider extends ViewServiceProvider */ public function registerEvents() { - $this->app->bindIf('events', function () { - return new Dispatcher; - }, true); + $this->app->bindIf('events', Dispatcher::class, true); return $this; } From 725ee8446ba44e46edd24ca0456d14a41bfbb2c0 Mon Sep 17 00:00:00 2001 From: Ben Word Date: Sun, 25 Dec 2016 15:48:18 -0700 Subject: [PATCH 2/4] Enable selective refresh for widgets in customizer (#1778) --- src/admin.php | 6 ++++++ src/setup.php | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/admin.php b/src/admin.php index bb25aac..ba6979a 100644 --- a/src/admin.php +++ b/src/admin.php @@ -8,6 +8,12 @@ namespace App; add_action('customize_register', function (\WP_Customize_Manager $wp_customize) { // Add postMessage support $wp_customize->get_setting('blogname')->transport = 'postMessage'; + $wp_customize->selective_refresh->add_partial('blogname', [ + 'selector' => '.brand', + 'render_callback' => function () { + bloginfo('name'); + } + ]); }); /** diff --git a/src/setup.php b/src/setup.php index 63749ca..fcf4873 100644 --- a/src/setup.php +++ b/src/setup.php @@ -54,6 +54,12 @@ add_action('after_setup_theme', function () { */ add_theme_support('html5', ['caption', 'comment-form', 'comment-list', 'gallery', 'search-form']); + /** + * Enable selective refresh for widgets in customizer + * @link https://developer.wordpress.org/themes/advanced-topics/customizer-api/#theme-support-in-sidebars + */ + add_theme_support('customize-selective-refresh-widgets'); + /** * Use main stylesheet for visual editor * @see assets/styles/layouts/_tinymce.scss From 0b17f2a96c46d5f6a53cc665e8c947c70115493e Mon Sep 17 00:00:00 2001 From: QWp6t Date: Tue, 27 Dec 2016 22:15:55 -0800 Subject: [PATCH 3/4] Use `get_theme_file_path()` --- src/filters.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/filters.php b/src/filters.php index 3d7789c..531e9df 100644 --- a/src/filters.php +++ b/src/filters.php @@ -53,7 +53,7 @@ add_filter('template_include', function ($template) { echo template($template, $data); // Return a blank file to make WordPress happy - return get_template_directory() . '/index.php'; + return get_theme_file_path('index.php'); }, PHP_INT_MAX); /** From 6ccdb6d799e87a2aa0c169491d287989e0622fd9 Mon Sep 17 00:00:00 2001 From: QWp6t Date: Wed, 28 Dec 2016 13:19:19 -0800 Subject: [PATCH 4/4] Throw errors if minimum requirements aren't met (#1782) --- functions.php | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/functions.php b/functions.php index 1e33528..f3d72b4 100644 --- a/functions.php +++ b/functions.php @@ -5,23 +5,46 @@ */ /** - * Require Composer autoloader if installed on it's own + * Helper function for prettying up errors + * @param string $message + * @param string $subtitle + * @param string $title */ -if (file_exists($composer = __DIR__ . '/vendor/autoload.php')) { - require_once $composer; +$error = function ($message, $subtitle = '', $title = '') { + $title = $title ?: __('Sage › Error', 'sage'); + $footer = 'roots.io/sage/docs'; + $message = "

{$title}
{$subtitle}

{$message}

{$footer}

"; + wp_die($message, $title); +}; + +/** + * Ensure compatible version of PHP is used + */ +if (version_compare('5.6.4', phpversion(), '>=')) { + $error(__('You must be using PHP 5.6.4 or greater.', 'sage'), __('Invalid PHP version', 'sage')); } /** - * Sage includes - * - * The $sage_includes array determines the code library included in your theme. - * Add or remove files to the array as needed. Supports child theme overrides. - * - * Please note that missing files will produce a fatal error. + * Ensure dependencies are loaded */ -array_map(function ($file) { - if (!locate_template("src/{$file}.php", true, true)) { - trigger_error(sprintf(__('Error locating %s for inclusion', 'sage'), $file), E_USER_ERROR); +if (!file_exists($composer = __DIR__.'/vendor/autoload.php') && !class_exists('Roots\\Sage\\Container')) { + $error( + __('You must run composer install from the Sage directory.', 'sage'), + __('Autoloader not found.', 'sage') + ); +} +require_once $composer; + +/** + * Sage required files + * + * The mapped array determines the code library included in your theme. + * Add or remove files to the array as needed. Supports child theme overrides. + */ +array_map(function ($file) use ($error) { + $file = "src/{$file}.php"; + if (!locate_template($file, true, true)) { + $error(sprintf(__('Error locating %s for inclusion.', 'sage'), $file), 'File not found'); } }, ['helpers', 'setup', 'filters', 'admin']);