Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
  • Loading branch information
gmazzap committed Nov 1, 2018
2 parents 6cd5697 + 9e945a1 commit 0a6649a
Show file tree
Hide file tree
Showing 20 changed files with 324 additions and 133 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[wp-config.example,index.example]
indent_style = tab

[*.md]
trim_trailing_whitespace = false
85 changes: 85 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Contributing to WP Starter
First, let us say: **thank you** to be here! :+1:

---



## Did you find a bug?

- **Do not open up a GitHub issue if the bug is a security vulnerability**, and instead contact [Giuseppe](https://github.com/gmazzap) directly via email.
- Ensure the bug was not already reported by searching on GitHub under [issues](https://github.com/wecodemore/wpstarter/issues).
- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/wecodemore/wpstarter/issues/new?template=bug_report.md). Be sure to include a title and clear description, as much relevant information as possible. Code samples and / or executable test cases demonstrating the bug are very welcome.
- Use the bug report template to create the issue, providing all the information listed there.
- If you'd like to write a fix yourself, **please wait first for some feedback on the issue**. Then follow guidelines below to write the code and submit a PR.



## Would you like to add a new feature or change an existing one?

- [Open an issue](https://github.com/wecodemore/wpstarter/issues/new?template=feature_request.md) clearly explaining what feature you want to add or change and why.
- Use the feature request template to create the issue, providing all the information listed there.
- If you offer to implement the change yourself, there will be more chances that the addition / change will land to WP Starter. But **please don't start writing code before you get a positive feedback**.



---



## Guidelines

### Code Style

- For v2.* we use [PSR-1](https://www.php-fig.org/psr/psr-1/) and [PSR-2](https://www.php-fig.org/psr/psr-2/) code style;
- For v3+ we use [Inpsyde PHP coding standars](https://github.com/inpsyde/php-coding-standards).

By cloning the repository and running:

```shell
./vendor/bin/phpcs
```

it is possible to check code is compliant via [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer).

Be sure to install Composer dependencies first.

### Git

Before write any code:

- Ensure an issue exist describing the bug, the wanted change or the new feature. If not, [open one](https://github.com/wecodemore/wpstarter/issues/new/choose).

- Create **a new branch** named after the target issue plus a one-or-two words description of the topic:


```shell
git checkout -b issue-123-something-important
```

#### Commits

Please make one commit _per change_. If you are afraid that you might end up with too many commits, you can [squash commits](https://github.com/servo/servo/wiki/Beginner's-guide-to-rebasing-and-squashing).

Please, always write clear messages for your commits. A good message is succinct, but still clearly explains *why* the change has been made, more than *how*.

The whole commit message is made of 2 or 3 parts:

1. A summary, *mandatory*, 60 characters or less, used **only** to explain the changes. It should read well when read after the sentence *"If merged this commit will..."*
2. A more detailed description, *optional*, used only if the 60 characters of the summary are not enough to explain changes well.
3. A reference to the relevant issue(s), *mandatory*.

The different parts can be added to the commit by using the `-m` option multiple times. For example:

```bash
git commit \
-m"Improve output messages of wp-config step" \
-m"Old message was not making clear if the step failed or not" \
-m"See #123"
```

#### Pull Requests

1. Always **file PRs against the `dev` branch**. Nothing goes to `master` without going to `dev` first. In case you did not do that, please [update your pull request](https://help.github.com/articles/changing-the-base-branch-of-a-pull-request/).
1. If possible, include tests. We can always use more test coverage.
1. Use the text on the PR with a description of the change made. There's no need to duplicate information from the issue, but please remember to link the issue in the PR text.
25 changes: 25 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: Bug report
about: Create a report to help us improve

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**System (please complete the following information):**
- OS: [e.g. iOS]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
15 changes: 15 additions & 0 deletions .github/ISSUE_TEMPLATE/contribute-documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: Contribute documentation
about: Help us to keep documentation healty

---

- Did you find typo, grammar issues, or do you think some wording in documentation needs improvement?
- Did you think there's something relevant that is not documented?
- Is there documentation parts that you found hard to follow or understand?

**Contributions to documentation are very welcome!**

If you can contribute to documentation, please just do it. If you spotted a mistake, there's no need to opne an issue. Just file the changes directly to master (for current version) or to the "main" branch of the next version, if your changes regards that.

Otherwise, if you can't do changes yourself, please open an issue only if you think the issue is relevant, and avoid opening an issue for a single typo fix or a missing space or things like that.
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Feature request
about: Suggest an idea for this project

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
24 changes: 24 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Description

Please describe what you have changed or added

## How has this been tested?
Please describe in detail how you tested your changes.

## Types of changes
What types of changes does your code introduce?

### Bug fixes (non-breaking change which fixes an issue)
- ...
### New feature (non-breaking change which adds functionality)
- ...
## Breaking change (fix or feature that break existing functionality)
- ...

## Issues
Which issue(s) this PR is addressing?

## Checklist:
- [ ] My code is tested
- [ ] My code follows the project code style
- [ ] My code has documentation (for new features or changed behavior)
21 changes: 19 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# Change Log for WPStarter

## [2.4.3] - 2018-05-07
* Templates: Add EOF lines. See [#67].
* Removed check for required env vars [#63]

## [2.4.2] - 2017-06-29
* Define `WP_CONTENT_URL` only on single site. See [#48], [#57].
* Minor code standards fix.
* Update docs to adapt to change on `johnpbloch/wordpress`.
* Expicitly globalize `$table_prefix` in `wp-config.php`. See [#61].

## [2.4.1] - 2017-02-21
* Removed strict types declaration for PHP 5 compat.

## [2.4.0] - 2017-02-21

* Case whatever we get from `get_option(uninstall_plugins)` to an array, to avoid throwing a warning. See [#36].
* Cast whatever we get from `get_option(uninstall_plugins)` to an array, to avoid throwing a warning. See [#36].
* Fix variable syntax for `.env` file template. See [#38].
* Fix RuntimeException because of `DB_NAME`, `DB_USER`, `DB_PASSWORD` not set. See [#49].
* Improve `Helpers::addHook()` by using WordPress function when available and loading `plugin.php` earlier on WP 4.7+. See [#50].
Expand Down Expand Up @@ -139,6 +149,10 @@
[Alain Schlesser]: https://github.com/schlessera
[Gary Jones]: https://github.com/GaryJones

[#67]: https://github.com/wecodemore/wpstarter/issues/67
[#61]: https://github.com/wecodemore/wpstarter/issues/61
[#57]: https://github.com/wecodemore/wpstarter/issues/57
[#48]: https://github.com/wecodemore/wpstarter/issues/48
[#38]: https://github.com/wecodemore/wpstarter/issues/38
[#36]: https://github.com/wecodemore/wpstarter/issues/36
[#35]: https://github.com/wecodemore/wpstarter/issues/35
Expand All @@ -148,7 +162,10 @@
[#3]: https://github.com/wecodemore/wpstarter/issues/3
[#2]: https://github.com/wecodemore/wpstarter/issues/2

[Unreleased]: https://github.com/wecodemore/wpstarter/compare/2.3.2...HEAD
[Unreleased]: https://github.com/wecodemore/wpstarter/compare/2.4.2...HEAD
[2.4.2]: https://github.com/wecodemore/wpstarter/compare/2.4.1...2.4.2
[2.4.1]: https://github.com/wecodemore/wpstarter/compare/2.4.0...2.4.1
[2.4.0]: https://github.com/wecodemore/wpstarter/compare/2.3.2...2.4.0
[2.3.2]: https://github.com/wecodemore/wpstarter/compare/2.3.1...2.3.2
[2.3.1]: https://github.com/wecodemore/wpstarter/compare/2.3.0...2.3.1
[2.3.0]: https://github.com/wecodemore/wpstarter/compare/2.2.5...2.3.0
Expand Down
7 changes: 0 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@
"vlucas/phpdotenv": "~2.0",
"johnpbloch/wordpress": ">=4.2"
},
"suggest": {
"ext-exif": "Allow reading EXIF information form images.",
"ext-ftp": "Enable usege of FTP filesystem strategy.",
"ext-ssh2": "Enable usege of ssh2 functions.",
"gmagick": "Imaging processing extension.",
"imagick": "Imaging processing extension."
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.0",
"wimg/php-compatibility": "^8.0",
Expand Down
13 changes: 13 additions & 0 deletions docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ The `config.vendor-dir` setting is optional. In the example above it is used to
*(some files in wp folder have been omitted for the sake of readability)*



## There's More

The example in this page shows how simple it is to get started with WP Starter. However, by using both general Composer settings and WP Starter specific settings it is possible to do more with WP Starter and also to control and customize any aspect of the WP Starter flow.
Expand All @@ -89,3 +90,15 @@ The WP Starter flow is what happens when you go from a `composer.json` to a full
All these operations are called *steps* and are individually described on the ***"How It Works"*** doc page.

Moreover, the way every WP Starter step works can be configured with settings in the `composer.json` file. The ***"WP Starter Options"*** doc page describes all the available configurations.



## Important: Security Issue with .env file

In the example above, WP Starter will load the `.env` file from project root folder which happens to also be the folder assumed as webroot for the project.

If this is a non-issue in local-only installations, it can be a quite serious issue on anything that goes online. In fact, an `.env`file inside webroot could expose secrets stored in it (at very minimum DB credentials).

To avoid this issue one way is to create a subfolder inside project root and use it as webroot, keeping `.env `file one level above, in the project root. This is the approach shown in "Complete Usage Example"](https://github.com/wecodemore/wpstarter/blob/master/docs/complete-example.md) in these docs.

Moreover, it is a good practice setup file permission on .env file to prevent access from the web, and also setup the webserver to avoid access to the .env file. But that's something well over the purpose of these docs.
13 changes: 13 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<ruleset name="WPStarter">
<description>The code standard for WPStarter package.</description>
<file>wpstarter/src/</file>
<arg value="sp"/>
<arg name="extensions" value="php"/>
<arg name="report" value="full"/>
<arg name="report" value="summary"/>
<arg name="report" value="source"/>
<rule ref="PSR2"/>
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="5.3-"/>
</ruleset>
4 changes: 2 additions & 2 deletions wpstarter/src/Env/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,14 @@ private function process(array $vars, Loader $loader)
case in_array($var, self::$isBool, true):
$values[$var] = (bool) filter_var($value, FILTER_VALIDATE_BOOLEAN);
break;
case in_array($var, self::$isBoolOrInt, true) :
case in_array($var, self::$isBoolOrInt, true):
if (is_numeric($value)) {
$values[$var] = (int) $value;
break;
}
$values[$var] = (bool) filter_var($value, FILTER_VALIDATE_BOOLEAN);
break;
case in_array($var, self::$isMod, true) :
case in_array($var, self::$isMod, true):
$check = $this->checkMod($value);
is_null($check) or $values[$var] = $check;
break;
Expand Down
26 changes: 3 additions & 23 deletions wpstarter/src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,7 @@ class Helpers
*/
public static function settings($dir, $file = '.env')
{
$env = Env\Env::load($dir, $file);

$settings = $env->allVars();

$required = array(
'DB_NAME',
'DB_USER',
'DB_PASSWORD',
);

foreach ($required as $key) {
if (!isset($settings[$key]) || empty($settings[$key])) {
$names = implode(', ', $required);
throw new \RuntimeException($names.' environment variables are required.');
}
}

return $settings;
return Env\Env::load($dir, $file)->allVars();
}

/**
Expand All @@ -57,13 +40,11 @@ public static function settings($dir, $file = '.env')
public static function addHook($hook, $callable, $priority = 10, $argsNum = 1)
{
// sanity check
if (
!is_callable($callable)
if (!is_callable($callable)
|| !is_scalar($hook)
|| !$hook
|| !is_numeric($priority)
|| !is_int($argsNum)) {

return;
}

Expand All @@ -75,8 +56,7 @@ public static function addHook($hook, $callable, $priority = 10, $argsNum = 1)
return;
}

if (
defined(ABSPATH)
if (defined(ABSPATH)
&& is_file(ABSPATH.'wp-includes/class-wp-hook.php')
&& is_file(ABSPATH.'wp-includes/plugin.php')
) {
Expand Down
8 changes: 3 additions & 5 deletions wpstarter/src/MuLoader/MuLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ private function loading($refresh, $transient)
*/
private function loadPlugin($key, $file, $refresh, $transient)
{
if (
is_readable($file)
&& strtolower( (string) pathinfo($file, PATHINFO_EXTENSION)) === 'php'
if (is_readable($file)
&& strtolower((string) pathinfo($file, PATHINFO_EXTENSION)) === 'php'
) {
wp_register_plugin_realpath($file);
if (in_array($file, $this->regular, true)) {
Expand Down Expand Up @@ -232,8 +231,7 @@ private function showPluginsData($bool, $type, $refresh)
static $show;
if ($type === 'mustuse') {
$show = $bool; // does user want to show mustuse plugins?
} elseif (
$type === 'dropins' // dropins are checked after mustuse
} elseif ($type === 'dropins' // dropins are checked after mustuse
&& $show // if user want show mustuse plugins
&& $screen->base === $check // we are in right screen
&& current_user_can('activate_plugins') // and user has right capabilities
Expand Down
7 changes: 3 additions & 4 deletions wpstarter/src/MuLoader/PluginAsMuLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ public function install()
private function installPlugin($plugin)
{
$basename = plugin_basename($plugin);
$isUninstall = array_key_exists($this->uninstall, $basename);
if (
has_action("deactivate_{$basename}")
$isUninstall = array_key_exists($basename, $this->uninstall);
if ($isUninstall
|| has_action("deactivate_{$basename}")
|| file_exists(dirname($plugin).'/uninstall.php')
|| $isUninstall
) {
$this->error($basename, $isUninstall);
}
Expand Down
Loading

0 comments on commit 0a6649a

Please sign in to comment.