From 6092419e23169254dfb01bfd7ed0af302ee2118a Mon Sep 17 00:00:00 2001 From: Jared Novack Date: Tue, 2 Jul 2019 11:49:55 -0400 Subject: [PATCH 1/5] Remove Composer.json; install through Travis --- .travis.yml | 2 ++ composer.json | 32 -------------------------------- functions.php | 5 ++++- 3 files changed, 6 insertions(+), 33 deletions(-) delete mode 100644 composer.json diff --git a/.travis.yml b/.travis.yml index 44a5ea9f7..08390f0ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,8 @@ env: before_script: - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION + - composer require timber/timber + - composer require phpunit/phpunit:5.7.16 - composer install --dev script: diff --git a/composer.json b/composer.json deleted file mode 100644 index f826d62ac..000000000 --- a/composer.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "upstatement/timber-starter-theme", - "description": "Starter theme to build a Timber theme", - "type":"wordpress-theme", - "minimum-stability" : "stable", - "authors": [ - { - "name": "jarednova", - "email": "jared@upstatement.com" - } - ], - "repositories": [ - { - "type": "composer", - "url": "https://wpackagist.org" - } - ], - "extra": { - "installer-paths": { - "../../plugins/{$name}/": [ - "wpackagist-plugin/*", - "type:wordpress-plugin" - ] - } - }, - "require": { - "wpackagist-plugin/timber-library": "1.*" - }, - "require-dev": { - "phpunit/phpunit": "5.7.16|6.*" - } -} diff --git a/functions.php b/functions.php index 90e2eeb44..025e05c25 100644 --- a/functions.php +++ b/functions.php @@ -8,6 +8,10 @@ * @since Timber 0.1 */ +if ( file_exists(__DIR__.'/vendor/autoload.php') ) { + require_once( __DIR__ . '/vendor/autoload.php' ); +} + if ( ! class_exists( 'Timber' ) ) { add_action( 'admin_notices', function() { echo '

Timber not activated. Make sure you activate the plugin in ' . esc_url( admin_url( 'plugins.php' ) ) . '

'; @@ -16,7 +20,6 @@ add_filter('template_include', function( $template ) { return get_stylesheet_directory() . '/static/no-timber.html'; }); - return; } From dd36735757ccc7c873f9d7cda3fac856df1e327a Mon Sep 17 00:00:00 2001 From: Jared Novack Date: Tue, 2 Jul 2019 12:01:26 -0400 Subject: [PATCH 2/5] Remove autoload from functions.php --- functions.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/functions.php b/functions.php index 025e05c25..d416252c6 100644 --- a/functions.php +++ b/functions.php @@ -8,9 +8,6 @@ * @since Timber 0.1 */ -if ( file_exists(__DIR__.'/vendor/autoload.php') ) { - require_once( __DIR__ . '/vendor/autoload.php' ); -} if ( ! class_exists( 'Timber' ) ) { add_action( 'admin_notices', function() { From d5d0124cf2c225546fd26966876d11710b1b0504 Mon Sep 17 00:00:00 2001 From: Jared Novack Date: Thu, 4 Jul 2019 11:54:17 -0400 Subject: [PATCH 3/5] Simplify test setup --- .travis.yml | 1 - tests/bootstrap.php | 5 ----- tests/test-timber-starter-theme.php | 34 ++++++++++------------------- 3 files changed, 11 insertions(+), 29 deletions(-) diff --git a/.travis.yml b/.travis.yml index 08390f0ce..ca1f8de61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,6 @@ before_script: - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION - composer require timber/timber - composer require phpunit/phpunit:5.7.16 - - composer install --dev script: - vendor/phpunit/phpunit/phpunit diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 22b3dd8bf..8eaa39ff1 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,10 +1,5 @@ assertTrue(is_array($context)); + } + function testFunctionsPHP() { $context = Timber::context(); $this->assertEquals('StarterSite', get_class($context['site'])); @@ -25,30 +31,12 @@ function testLoading() { } static function _setupStarterTheme(){ - $dest = WP_CONTENT_DIR.'/themes/starter-theme/'; - $src = __DIR__.'/../../starter-theme/'; - if (is_dir($src)) { - self::_copyDirectory($src, $dest); - switch_theme('starter-theme'); - } else { - echo 'no its not'; + $dest = WP_CONTENT_DIR.'/themes/starter-theme'; + $src = realpath(__DIR__.'/../../starter-theme/'); + if ( is_dir($src) && !file_exists($dest) ) { + symlink($src, $dest); } } - static function _copyDirectory($src, $dst){ - $dir = opendir($src); - @mkdir($dst); - while(false !== ( $file = readdir($dir)) ) { - if (( $file != '.' ) && ( $file != '..' )) { - if ( is_dir($src . '/' . $file) ) { - self::_copyDirectory($src . '/' . $file,$dst . '/' . $file); - } - else { - copy($src . '/' . $file,$dst . '/' . $file); - } - } - } - closedir($dir); - } } From b5ab962d7019e02431ae379f315b7d46f4ce289f Mon Sep 17 00:00:00 2001 From: Jared Novack Date: Thu, 4 Jul 2019 11:54:39 -0400 Subject: [PATCH 4/5] Include pattern for loading Timber via Composer --- functions.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/functions.php b/functions.php index d416252c6..fca7e4b38 100644 --- a/functions.php +++ b/functions.php @@ -8,8 +8,23 @@ * @since Timber 0.1 */ +/** + * If you are installing Timber as a Composer dependency in your theme, you'll need this block + * to load your dependencies and initialize Timber. If you are using Timber via the WordPress.org + * plug-in, you can safely delete this block. + */ +$composer_autoload = __DIR__ . '/vendor/autoload.php'; +if ( file_exists($composer_autoload) ) { + require_once( $composer_autoload ); + $timber = new Timber\Timber(); +} +/** + * This ensures that Timber is loaded and available as a PHP class. + * If not, it gives an error message to help direct developers on where to activate + */ if ( ! class_exists( 'Timber' ) ) { + add_action( 'admin_notices', function() { echo '

Timber not activated. Make sure you activate the plugin in ' . esc_url( admin_url( 'plugins.php' ) ) . '

'; }); From f1c3382d4d5c4c84b6a2ea5c7bcb25fa8ecebca2 Mon Sep 17 00:00:00 2001 From: Jared Novack Date: Thu, 4 Jul 2019 12:02:18 -0400 Subject: [PATCH 5/5] Restore composer.json -- simplify Travis --- .travis.yml | 3 +-- composer.json | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 composer.json diff --git a/.travis.yml b/.travis.yml index ca1f8de61..b6681f71e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,7 @@ env: before_script: - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION - - composer require timber/timber - - composer require phpunit/phpunit:5.7.16 + - composer install script: - vendor/phpunit/phpunit/phpunit diff --git a/composer.json b/composer.json new file mode 100644 index 000000000..99f33c739 --- /dev/null +++ b/composer.json @@ -0,0 +1,24 @@ +{ + "name": "upstatement/timber-starter-theme", + "description": "Starter theme to build a Timber theme", + "type":"wordpress-theme", + "minimum-stability" : "stable", + "authors": [ + { + "email": "jared@upstatement.com", + "name": "jarednova" + } + ], + "repositories": [ + { + "type": "composer", + "url": "https://wpackagist.org" + } + ], + "require": { + "timber/timber": "1.*" + }, + "require-dev": { + "phpunit/phpunit": "5.7.16|6.*" + } +}