Skip to content

Commit

Permalink
Add code style check and build script (pluginkollektiv#202)
Browse files Browse the repository at this point in the history
* Add minify script, remove *.min.css

* Add code style check for CSS, fix existing violations

* Add code style check for PHP (WP CS + PHP compatibility)

* Rename files and variables according to WP code style

* Escape output according to WP code style, fix multiple assignments and prepared statement

* Fix input sanitization errors

* Update GitHub actions to include composer install

* Use latest version of the composer action, simply nonce sanitization

* Fix .gitattributes, add .distignore

* add .distignore to .gitattributes export-ignore

* update NPM dev dependencies

Co-authored-by: Stefan Kalscheuer <[email protected]>
  • Loading branch information
patrickrobrecht and stklcode authored Feb 7, 2021
1 parent 1e21870 commit f8326db
Show file tree
Hide file tree
Showing 32 changed files with 3,399 additions and 283 deletions.
18 changes: 18 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Directories
/.git
/.github
/.wordpress-org
/node_modules
/vendor

# Files
/.distignore
/.editorconfig
/.gitattributes
/.gitignore
/.stylelintrc.json
/composer.json
/composer.lock
/package.json
/package-lock.json
/phpcs.xml
7 changes: 6 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
/.github export-ignore
/.wordpress-org export-ignore
/node_modules export-ignore
/vendor export-ignore

# Files
/.distignore export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/Gruntfile.js export-ignore
/.stylelintrc.json export-ignore
/composer.json export-ignore
/composer.lock export-ignore
/package.json export-ignore
/package-lock.json export-ignore
/phpcs.xml export-ignore
7 changes: 4 additions & 3 deletions .github/workflows/wordpress-plugin-asset-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ jobs:
name: Push to master
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v2
- uses: php-actions/composer@v5
- name: WordPress.org plugin asset/readme update
uses: 10up/action-wordpress-plugin-asset-update@master
uses: 10up/action-wordpress-plugin-asset-update@stable
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
README_NAME: README.md
README_NAME: README.txt
17 changes: 9 additions & 8 deletions .github/workflows/wordpress-plugin-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ name: Deploy to WordPress.org
on:
push:
tags:
- "*"
- "!*-*"
- "*"
- "!*-*"
jobs:
tag:
name: New tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: WordPress Plugin Deploy
uses: 10up/action-wordpress-plugin-deploy@master
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
- uses: actions/checkout@v2
- uses: php-actions/composer@v5
- name: WordPress Plugin Deploy
uses: 10up/action-wordpress-plugin-deploy@stable
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
node_modules
vendor
.idea/
css/*.min.css
vendor/
node_modules/
7 changes: 7 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@wordpress/stylelint-config",
"rules": {
"declaration-property-unit-whitelist": null,
"selector-id-pattern": null
}
}
29 changes: 0 additions & 29 deletions Gruntfile.js

This file was deleted.

35 changes: 24 additions & 11 deletions apc/proxy.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/**
* Proxy for APC based caching.
*
* @package Cachify
*/

if ( ! empty( $_COOKIE ) ) {
foreach ( $_COOKIE as $k => $v ) {
Expand All @@ -18,7 +23,8 @@
*/
function cachify_is_ssl() {
if ( isset( $_SERVER['HTTPS'] ) ) {
if ( 'on' === strtolower( $_SERVER['HTTPS'] ) ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( 'on' === strtolower( wp_unslash( $_SERVER['HTTPS'] ) ) ) {
return true;
}

Expand All @@ -34,19 +40,26 @@ function cachify_is_ssl() {

if (
empty( $_cachify_logged_in )
&& extension_loaded( 'apc' )
&& ( strpos( filter_input( INPUT_SERVER, 'PHP_SELF', FILTER_SANITIZE_STRING ), '/wp-admin/' ) === false )
&& ( strpos( filter_input( INPUT_SERVER, 'HTTP_ACCEPT_ENCODING', FILTER_SANITIZE_STRING ), 'gzip' ) !== false )
&& extension_loaded( 'apc' )
&& ( $cache = apc_fetch( md5( ( cachify_is_ssl() ? 'https-' : '' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) . '.cachify' ) )
) {
ini_set( 'zlib.output_compression', 'Off' );
$prefix = cachify_is_ssl() ? 'https-' : '';
$cache = apc_fetch(
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
md5( $prefix . wp_unslash( $_SERVER['HTTP_HOST'] ) . wp_unslash( $_SERVER['REQUEST_URI'] ) )
. '.cachify'
);
if ( $cache ) {
ini_set( 'zlib.output_compression', 'Off' );

header( 'Vary: Accept-Encoding' );
header( 'X-Powered-By: Cachify' );
header( 'Content-Encoding: gzip' );
header( 'Content-Length: ' . strlen( $cache ) );
header( 'Content-Type: text/html; charset=utf-8' );
header( 'Vary: Accept-Encoding' );
header( 'X-Powered-By: Cachify' );
header( 'Content-Encoding: gzip' );
header( 'Content-Length: ' . strlen( $cache ) );
header( 'Content-Type: text/html; charset=utf-8' );

echo $cache;
exit;
echo $cache; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
exit;
}
}
45 changes: 25 additions & 20 deletions cachify.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php
/*
Plugin Name: Cachify
Description: Easy to use WordPress caching plugin. Serving static blog pages from database, disk, Memcached or APC.
Author: pluginkollektiv
Author URI: https://pluginkollektiv.org
Plugin URI: https://cachify.pluginkollektiv.org/
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Version: 2.3.0
Text Domain: cachify
Domain Path: /lang
*/
/**
* Plugin Name: Cachify
* Description: Easy to use WordPress caching plugin. Serving static blog pages from database, disk, Memcached or APC.
* Author: pluginkollektiv
* Author URI: https://pluginkollektiv.org
* Plugin URI: https://cachify.pluginkollektiv.org
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Version: 2.3.0
* Text Domain: cachify
*
* @package Cachify
*/

/*
Copyright (C) 2011-2015 Sergej Müller
Expand Down Expand Up @@ -74,24 +75,28 @@

/* WP-CLI */
add_action(
'cli_init',
array(
'Cachify_CLI',
'add_commands'
)
'cli_init',
array(
'Cachify_CLI',
'add_commands',
)
);

/* Autoload Init */
spl_autoload_register( 'cachify_autoload' );

/* Autoload function */
/**
* Autoload the class.
*
* @param string $class the class name.
*/
function cachify_autoload( $class ) {
if ( in_array( $class, array( 'Cachify', 'Cachify_APC', 'Cachify_DB', 'Cachify_HDD', 'Cachify_MEMCACHED', 'Cachify_CLI' ) ) ) {
require_once(
sprintf(
'%s/inc/%s.class.php',
'%s/inc/class-%s.php',
CACHIFY_DIR,
strtolower( $class )
strtolower( str_replace( '_', '-', $class ) )
)
);
}
Expand Down
35 changes: 35 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,40 @@
"require": {
"php": ">=5.2.0",
"composer/installers": "~1.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^v0.7",
"matthiasmullie/minify": "^1.3",
"squizlabs/php_codesniffer": "^3.5",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"wp-coding-standards/wpcs": "^2.3"
},
"scripts": {
"post-install-cmd": [
"@build"
],
"post-update-cmd": [
"@build"
],
"build": [
"minifycss css/dashboard.css > css/dashboard.min.css",
"minifycss css/settings.css > css/settings.min.css"
],
"cs": [
"@lint-php"
],
"csfix": [
"phpcbf --standard=phpcs.xml"
],
"lint-all": [
"@lint-php",
"@lint-css"
],
"lint-css": [
"npx stylelint css/dashboard.css css/settings.css"
],
"lint-php": [
"phpcs --standard=phpcs.xml -s"
]
}
}
Loading

0 comments on commit f8326db

Please sign in to comment.