Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dev-lib
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PROJECT_TYPE=theme
WPCS_STANDARD=phpcs.xml.dist
PATH_EXCLUDES_PATTERN='^(.*/)?(vendor|node_modules)/.*'
DEV_LIB_SKIP=yuicompressor,codeception,grunt,jshint,phpunit
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[{.jshintrc,*.json,*.yml}]
indent_style = space
indent_size = 2

[{*.txt,wp-config-sample.php}]
end_of_line = crlf
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.DS_Store
composer.lock
/node_modules/
/vendor/
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
language: php
sudo: false

cache:
directories:
node_modules
vendor

addons:
apt:
packages:
- libxml2-utils

matrix:
include:
- php: '5.6'
- php: '7.0'
- php: '7.1'
- php: '7.2'

install:
- composer install
- export DEV_LIB_PATH=vendor/xwp/wp-dev-lib
- source $DEV_LIB_PATH/travis.install.sh

script:
- source $DEV_LIB_PATH/travis.script.sh
43 changes: 43 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "beans/beans-child",
"description": "Beans theme starter child theme.",
"type": "wordpress-theme",
"license": "GPL-2.0+",
"homepage": "http://www.getbeans.io/",
"support": {
"issues": "https://github.com/Getbeans/Beans-Starter-Child-Theme/issues",
"source": "https://github.com/Getbeans/Beans-Starter-Child-Theme"
},
"prefer-stable": true,
"repositories": [
{
"type": "package",
"package": {
"name": "xwp/wp-dev-lib",
"version": "1.0.1",
"source": {
"url": "https://github.com/xwp/wp-dev-lib.git",
"type": "git",
"reference": "master"
}
}
}
],
"require-dev": {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest that we set up this composer.json with the same dependencies and scripts as in Beans. It would then give a developer the environment, s/he needs to start building a theme and writing tests.

We could think of the child theme as the starting development environment for a new theme.

"dealerdirect/phpcodesniffer-composer-installer": "^0.4.3",
"sirbrillig/phpcs-variable-analysis": "^2.0",
"wp-coding-standards/wpcs": "^0.14.0",
"xwp/wp-dev-lib": "^1.0.1"
},
"scripts": {
"install-codestandards": [
"Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run"
],
"phpcs-src": "\"vendor/bin/phpcs\"",
"phpcs-tests": "\"vendor/bin/phpcs\" --runtime-set testVersion 5.6 tests/phpunit/",
"phpcs": [
"@phpcs-src",
"@phpcs-tests"
]
}
}
28 changes: 28 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Beans Child
*
* @package Beans\StarterChildTheme
*/

namespace Beans\StarterChildTheme;

// Include Beans. Do not remove the line below.
require_once get_template_directory() . '/lib/init.php';

/**
* Enqueue LESS and CSS style to the UIkit compiler.
*
* IMPORTANT: The function below enqueue both the style.less and style.css to the UIkit compiler. Remove one of the
* two enqueuer according to your needs
*
* To make sure the compiler re-compile your LESS or CSS on the fly (on page reload), make sure to enable development
* mode via the Admin->Appearance->Settings option.
*/
add_action( 'beans_uikit_enqueue_scripts', function() {

@hellofromtonya hellofromtonya Jan 23, 2018

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of using closures as the hooked callback. Why?

Our code provides an example of how to build code. And in some cases a closure is fine. But in most others it is not because it cannot be unhooked.

Here, one could argue that this callback will never be unhooked. But in many other cases, you may build a plugin that needs to unhook another part of your theme. If you use a closure, that is no longer possible, well unless we use beans_add_action.

Choices:

Option 1

Use the standard function as the callback.

add_action( 'beans_uikit_enqueue_scripts', __NAMESPACE__ . '\enqueue_uikit' );
/**
 * Enqueue LESS and CSS style to the UIkit compiler.
 *
 * IMPORTANT: The function below enqueue both the style.less and style.css to the UIkit compiler. Remove one of the
 * two enqueuer according to your needs
 *
 * To make sure the compiler re-compile your LESS or CSS on the fly (on page reload), make sure to enable development
 * mode via the Admin->Appearance->Settings option.
 */
function enqueue_uikit() {

Option 2

Use beans_add_action() with the closure, thereby, giving the ability for a plugin to modify or remove the closure.

/**
 * Enqueue LESS and CSS style to the UIkit compiler.
 *
 * IMPORTANT: The function below enqueue both the style.less and style.css to the UIkit compiler. Remove one of the
 * two enqueuer according to your needs
 *
 * To make sure the compiler re-compile your LESS or CSS on the fly (on page reload), make sure to enable development
 * mode via the Admin->Appearance->Settings option.
 */
beans_add_action( 'beans_child_enqueue_uikit', 'beans_uikit_enqueue_scripts', function() {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thinking behind is that Child Theme are not meant to be extendable to a certain extent, but I am definitely in a agreement that it can be the case sometimes. I think using beans_add_action() is a good showcase of how closure can safely be used with Beans.

// To remove if you are using style.css only.
beans_compiler_add_fragment( 'uikit', get_stylesheet_directory_uri() . '/style.less', 'less' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why call get_stylesheet_directory_uri() twice? It's more performant to store it in a variable and then use that variable, like this:

	$uri = get_stylesheet_directory_uri();

	// To remove if you are using style.css only.
	beans_compiler_add_fragment( 'uikit', $uri . '/style.less', 'less' );

	// To remove if you are using style.less only.
	wp_enqueue_style( 'child-style', $uri . '/style.css' );

@ThierryA ThierryA Jan 24, 2018

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because one of the too calls below are meant to be removed. Either users choose LESS or CSS but not enqueue both. Then users will most likely leave the function assigned to the variable unnecessary.


// To remove if you are using style.less only.
beans_compiler_add_fragment( 'uikit', get_stylesheet_directory_uri() . '/style.css', 'less' );
} );
36 changes: 36 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<ruleset name="Beans Child">
<description>The code standard for Beans Child.</description>

<file>.</file>

<!-- Ignore these directories -->
<exclude-pattern>node_modules/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>

<!-- PHP only. We'll use other validators for JS, CSS, etc. -->
<arg name="extensions" value="php"/>

<!-- WordPress Rules -->
<rule ref="WordPress">
<exclude name="WordPress.VIP"/>

<!-- Exclude until v2 as this applies after WP 4.4 with upgrades in PHP 5.3 -->
<exclude name="WordPress.WP.AlternativeFunctions.parse_url_parse_url"/>
<exclude name="PEAR.NamingConventions.ValidClassName.StartWithCapital"/>
</rule>

<rule ref="WordPress.Files.FileName">
<properties>
<property name="is_theme" value="true"/>
<property name="strict_class_file_names" value="false"/>
</properties>
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase"/>
</rule>

<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array" value="beans-child" />
</properties>
</rule>
</ruleset>
27 changes: 27 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
bootstrap="tests/phpunit/unit/bootstrap.php"
backupGlobals="false"
colors="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="true">

<testsuites>
<testsuite name="unit">
<directory suffix=".php">./tests/phpunit/unit/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">.</directory>
</whitelist>
</filter>
</phpunit>
Binary file added screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Theme Name: Beans child
Description: Starter Child Theme for the Beans Theme.
Author: Beans
Author URI: http://www.getbeans.io
Template: tm-beans
Version: 1.0.0
Text Domain: beans-child
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
4 changes: 4 additions & 0 deletions style.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
* In this file, you may style your site using CSS or LESS as well as overwrite UIkit LESS variables.
* Make sure to enable development mode via the Admin->Appearance->Settings option while working on your website. LESS will then be processed on the fly.
*/