Merge pull request #209 from timnolte/feature/coding-standards-static-analysis
Feature/coding standards static analysisisekai
commit
4ad4a6a95b
@ -0,0 +1,24 @@
|
||||
# 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
|
||||
|
||||
[*.yml,*.yml.dist]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[{*.txt,wp-config-sample.php}]
|
||||
end_of_line = crlf
|
@ -1,2 +1,52 @@
|
||||
vendor/**/*
|
||||
composer.lock
|
||||
# Numerous always-ignore extensions
|
||||
*.diff
|
||||
*.err
|
||||
*.orig
|
||||
*.log
|
||||
*.rej
|
||||
*.swo
|
||||
*.swp
|
||||
*.vi
|
||||
*~
|
||||
*.sass-cache
|
||||
|
||||
# Local Development files/folders.
|
||||
.env
|
||||
phpcs.xml
|
||||
phpstan.neon
|
||||
phpunit.xml
|
||||
|
||||
# OS or Editor folders
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
.cache
|
||||
tags.*
|
||||
.project
|
||||
.settings
|
||||
.tmproj
|
||||
*.esproj
|
||||
nbproject
|
||||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
.idea
|
||||
clover.xml
|
||||
|
||||
# Dreamweaver added files
|
||||
_notes
|
||||
dwsync.xml
|
||||
|
||||
# Komodo
|
||||
*.komodoproject
|
||||
.komodotools
|
||||
|
||||
# Folders to ignore
|
||||
.hg
|
||||
.svn
|
||||
.CVS
|
||||
intermediate
|
||||
.idea
|
||||
cache
|
||||
node_modules
|
||||
vendor
|
||||
dist
|
||||
wordpress
|
||||
|
@ -0,0 +1,118 @@
|
||||
# Travis CI Configuration File
|
||||
|
||||
# Tell Travis CI which distro to use
|
||||
dist: trusty
|
||||
|
||||
sudo: false
|
||||
|
||||
# Tell Travis CI we're using PHP
|
||||
language: php
|
||||
|
||||
# Tell Travis CI which notifications to send
|
||||
notifications:
|
||||
email:
|
||||
on_success: never
|
||||
on_failure: change
|
||||
|
||||
# whitelist branches for the "push" build check
|
||||
branches:
|
||||
only:
|
||||
- main
|
||||
- /^dev\-release\/.*$/
|
||||
- /^feature\/.*$/
|
||||
- /^fix\/.*$/
|
||||
|
||||
# Git clone depth
|
||||
# By default Travis CI clones repositories to a depth of 50 commits
|
||||
git:
|
||||
depth: 1
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- vendor
|
||||
- $HOME/.composer/cache
|
||||
|
||||
# Define a matrix of additional build configurations
|
||||
# The versions listed above will automatically create our first configuration,
|
||||
# so it doesn't need to be re-defined below.
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- name: Coding Standards
|
||||
php: 7.3
|
||||
env: WP_MODE=single WP_VERSION=5.4.* PHP_LINT=1 COVERAGE=1
|
||||
- name: Static Code Analysis
|
||||
php: 7.3
|
||||
env: WP_MODE=single WP_VERSION=5.4.* PHP_ANALYZE=1
|
||||
- name: Latest Stable
|
||||
php: 7.3
|
||||
env: WP_MODE=single WP_VERSION=5.4.* PHP_UNIT=1
|
||||
- name: Preferred Minimum requirements
|
||||
php: 7.2
|
||||
env: WP_MODE=single WP_VERSION=5.3.* PHP_UNIT=1
|
||||
- name: Minimum requirements
|
||||
php: 7.1
|
||||
env: WP_MODE=single WP_VERSION=5.2.* PHP_UNIT=1
|
||||
- name: Bleeding Edge
|
||||
php: 7.4
|
||||
env: WP_MODE=single WP_VERSION=dev-master PHP_UNIT=1
|
||||
- name: Multisite Compatibility
|
||||
php: 7.3
|
||||
env: WP_MODE=multi WP_VERSION=5.4.* PHP_UNIT=1
|
||||
allow_failures:
|
||||
- name: Bleeding Edge
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- nodejs
|
||||
|
||||
before_install:
|
||||
- npm install -g npm@6.14
|
||||
- npm install -g grunt-cli
|
||||
- composer require "wordpress/wordpress:${WP_VERSION}" --dev --prefer-source --no-update
|
||||
|
||||
install:
|
||||
- composer update --prefer-source --no-interaction --dev --optimize-autoloader
|
||||
- npm install
|
||||
|
||||
before_script:
|
||||
- export PATH="$HOME/.composer/vendor/bin:$PATH"
|
||||
# Setup WordPress coding standards
|
||||
- |
|
||||
if [[ "$PHP_LINT" == "1" ]]; then
|
||||
composer global require wp-coding-standards/wpcs
|
||||
fi
|
||||
# Setup unit testing environment
|
||||
- |
|
||||
if [[ "$PHP_UNIT" == "1" ]]; then
|
||||
# bash scripts/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
|
||||
if [[ $TRAVIS_PHP_VERSION == "7.4" ]]; then
|
||||
composer global require "phpunit/php-code-coverage=dev-master"
|
||||
composer global require "sebastian/global-state:dev-master"
|
||||
composer global require "phpunit/phpunit=dev-master"
|
||||
else
|
||||
composer global require "phpunit/phpunit=7.*"
|
||||
fi
|
||||
fi
|
||||
|
||||
script:
|
||||
- |
|
||||
if [[ "$PHP_LINT" == "1" ]]; then
|
||||
if [[ "$WP_MODE" == "single" ]]; then WP_MULTISITE=0 npm run lint; fi
|
||||
fi
|
||||
- |
|
||||
if [[ "$PHP_ANALYZE" == "1" ]]; then
|
||||
if [[ "$WP_MODE" == "single" ]]; then WP_MULTISITE=0 npm run analyze; fi
|
||||
fi
|
||||
- |
|
||||
if [[ "$PHP_UNIT" == "1" ]]; then
|
||||
if [[ "$WP_MODE" == "multi" ]]; then WP_MULTISITE=1 npm run test; fi
|
||||
if [[ "$WP_MODE" == "single" ]]; then WP_MULTISITE=0 npm run test; fi
|
||||
fi
|
||||
|
||||
after_success:
|
||||
- |
|
||||
if [[ "$COVERAGE" == "1" ]]; then
|
||||
bash <(curl -s https://codecov.io/bash)
|
||||
fi
|
@ -0,0 +1,17 @@
|
||||
{
|
||||
"core": "./wordpress/build",
|
||||
"mappings": {
|
||||
"wp-content/mu-plugins": "./tools/local-env/mu-plugins",
|
||||
"wp-content/plugins/daggerhart-openid-connect-generic": "."
|
||||
},
|
||||
"config": {
|
||||
"PHP_INI_MEMORY_LIMIT": "512M",
|
||||
"WP_MEMORY_LIMIT": "512M",
|
||||
"WP_DEBUG": true,
|
||||
"WP_DEBUG_LOG": true,
|
||||
"WP_DEBUG_DISPLAY": true,
|
||||
"SCRIPT_DEBUG": true,
|
||||
"SMTP_HOST": "mailhog",
|
||||
"SMTP_PORT": 1025
|
||||
}
|
||||
}
|
@ -0,0 +1,200 @@
|
||||
module.exports = function (grunt) {
|
||||
|
||||
require('load-grunt-tasks')(grunt);
|
||||
|
||||
// Project configuration.
|
||||
grunt.initConfig({
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
|
||||
composerBin: 'vendor/bin',
|
||||
|
||||
shell: {
|
||||
phpcs: {
|
||||
options: {
|
||||
stdout: true
|
||||
},
|
||||
command: '<%= composerBin %>/phpcs'
|
||||
},
|
||||
|
||||
phpcbf: {
|
||||
options: {
|
||||
stdout: true
|
||||
},
|
||||
command: '<%= composerBin %>/phpcbf'
|
||||
},
|
||||
|
||||
phpstan: {
|
||||
options: {
|
||||
stdout: true
|
||||
},
|
||||
command: '<%= composerBin %>/phpstan analyze .'
|
||||
},
|
||||
|
||||
phpunit: {
|
||||
options: {
|
||||
stdout: true
|
||||
},
|
||||
command: '<%= composerBin %>/phpunit'
|
||||
},
|
||||
},
|
||||
|
||||
gitinfo: {
|
||||
commands: {
|
||||
'local.tag.current.name': ['name-rev', '--tags', '--name-only', 'HEAD'],
|
||||
'local.tag.current.nameLong': ['describe', '--tags', '--long']
|
||||
}
|
||||
},
|
||||
|
||||
clean: {
|
||||
main: ['dist'], //Clean up build folder
|
||||
i18n: ['languages/*.mo', 'languages/*.pot']
|
||||
},
|
||||
|
||||
copy: {
|
||||
// Copy the plugin to a versioned release directory
|
||||
main: {
|
||||
src: [
|
||||
'**',
|
||||
'!*.xml', '!*.log', //any config/log files
|
||||
'!node_modules/**', '!Gruntfile.js', '!package.json', '!package-lock.json', //npm/Grunt
|
||||
'!assets/**', //wp-org assets
|
||||
'!dist/**', //build directory
|
||||
'!.git/**', //version control
|
||||
'!tests/**', '!scripts/**', '!phpunit.xml', '!phpunit.xml.dist', //unit testing
|
||||
'!vendor/**', '!composer.lock', '!composer.phar', '!composer.json', //composer
|
||||
'!wordpress/**',
|
||||
'!.*', '!**/*~', //hidden files
|
||||
'!CONTRIBUTING.md',
|
||||
'!README.md',
|
||||
'!phpcs.xml', '!phpcs.xml.dist', '!phpstan.neon.dist', '!grumphp.yml.dist', // CodeSniffer Configuration.
|
||||
'!docker-compose.override.yml', // Local Docker Development configuration.
|
||||
'!codecov.yml', // Code coverage configuration.
|
||||
'!tools/**', // Local Development/Build tools configuration.
|
||||
],
|
||||
dest: 'dist/',
|
||||
options: {
|
||||
processContentExclude: ['**/*.{png,gif,jpg,ico,mo}'],
|
||||
processContent: function (content, srcpath) {
|
||||
if (srcpath == 'readme.txt' || srcpath == 'openid-connect-generic.php') {
|
||||
if (grunt.config.get('gitinfo').local.tag.current.name !== 'undefined') {
|
||||
content = content.replace('{{version}}', grunt.config.get('gitinfo').local.tag.current.name);
|
||||
} else {
|
||||
content = content.replace('{{version}}', grunt.config.get('gitinfo').local.tag.current.nameLong);
|
||||
}
|
||||
}
|
||||
return content;
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
addtextdomain: {
|
||||
options: {
|
||||
textdomain: 'daggerhart-openid-connect-generic', // Project text domain.
|
||||
},
|
||||
update_all_domains: {
|
||||
options: {
|
||||
updateDomains: true
|
||||
},
|
||||
src: ['*.php', '**/*.php', '!node_modules/**', '!tests/**', '!scripts/**', '!wordpress/**']
|
||||
},
|
||||
},
|
||||
|
||||
wp_readme_to_markdown: {
|
||||
dest: {
|
||||
files: {
|
||||
'README.md': 'readme.txt'
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
makepot: {
|
||||
target: {
|
||||
options: {
|
||||
domainPath: '/languages', // Where to save the POT file.
|
||||
exclude: [
|
||||
'node_modules/.*', //npm
|
||||
'assets/.*', //wp-org assets
|
||||
'dist/.*', //build directory
|
||||
'.git/.*', //version control
|
||||
'tests/.*', 'scripts/.*', //unit testing
|
||||
'vendor/.*', //composer
|
||||
'wordpress/.*',
|
||||
], // List of files or directories to ignore.
|
||||
mainFile: 'openid-connect-generic.php', // Main project file.
|
||||
potFilename: 'openid-connect-generic.pot', // Name of the POT file.
|
||||
potHeaders: {
|
||||
poedit: true, // Includes common Poedit headers.
|
||||
'x-poedit-keywordslist': true // Include a list of all possible gettext functions.
|
||||
}, // Headers to add to the generated POT file.
|
||||
type: 'wp-plugin', // Type of project (wp-plugin or wp-theme).
|
||||
updateTimestamp: true, // Whether the POT-Creation-Date should be updated without other changes.
|
||||
updatePoFiles: true // Whether to update PO files in the same directory as the POT file.
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
po2mo: {
|
||||
plugin: {
|
||||
src: 'languages/*.po',
|
||||
expand: true
|
||||
}
|
||||
},
|
||||
|
||||
checkrepo: {
|
||||
deploy: {
|
||||
tagged: true, // Check that the last commit (HEAD) is tagged
|
||||
clean: true // Check that working directory is clean
|
||||
}
|
||||
},
|
||||
|
||||
checktextdomain: {
|
||||
options: {
|
||||
text_domain: 'daggerhart-openid-connect-generic',
|
||||
keywords: [
|
||||
'__:1,2d',
|
||||
'_e:1,2d',
|
||||
'_x:1,2c,3d',
|
||||
'esc_html__:1,2d',
|
||||
'esc_html_e:1,2d',
|
||||
'esc_html_x:1,2c,3d',
|
||||
'esc_attr__:1,2d',
|
||||
'esc_attr_e:1,2d',
|
||||
'esc_attr_x:1,2c,3d',
|
||||
'_ex:1,2c,3d',
|
||||
'_x:1,2c,3d',
|
||||
'_n:1,2,4d',
|
||||
'_nx:1,2,4c,5d',
|
||||
'_n_noop:1,2,3d',
|
||||
'_nx_noop:1,2,3c,4d'
|
||||
],
|
||||
},
|
||||
files: {
|
||||
src: [
|
||||
'**/*.php',
|
||||
'!node_modules/**',
|
||||
'!dist/**',
|
||||
'!tests/**',
|
||||
'!vendor/**',
|
||||
'!wordpress/**',
|
||||
'!*~',
|
||||
],
|
||||
expand: true,
|
||||
},
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
grunt.registerTask('phpcs', ['shell:phpcs']);
|
||||
grunt.registerTask('phpcbf', ['shell:phpcbf']);
|
||||
grunt.registerTask('phpstan', ['shell:phpstan']);
|
||||
grunt.registerTask('phpunit', ['shell:phpunit']);
|
||||
grunt.registerTask('i18n', ['addtextdomain', 'makepot', 'po2mo']);
|
||||
grunt.registerTask('readme', ['wp_readme_to_markdown']);
|
||||
grunt.registerTask('test', ['checktextdomain', 'phpcs']);
|
||||
grunt.registerTask('build', ['gitinfo', 'test', 'clean', 'i18n', 'readme', 'copy']);
|
||||
//grunt.registerTask( 'deploy', [ 'checkbranch:master', 'checkrepo', 'build' ] );
|
||||
grunt.registerTask('deploy', ['checkrepo', 'build']);
|
||||
|
||||
};
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,75 @@
|
||||
version: '3.7'
|
||||
services:
|
||||
wordpress-develop:
|
||||
depends_on:
|
||||
- php
|
||||
- mailhog
|
||||
|
||||
environment:
|
||||
LOCAL_DIR: ${LOCAL_DIR-src}
|
||||
SMTP_HOST: ${SMTP_HOST-mailhog}
|
||||
SMTP_PORT: ${SMTP_PORT-1025}
|
||||
|
||||
volumes:
|
||||
- ../tools/local-env/default.template:/etc/nginx/conf.d/default.template
|
||||
- ..:/var/www/${LOCAL_DIR-src}/wp-content/plugins/daggerhart-openid-connect-generic
|
||||
- ../tools/local-env/mu-plugins:/var/www/${LOCAL_DIR-src}/wp-content/mu-plugins
|
||||
|
||||
# Load our config file, substituning environment variables into the config.
|
||||
command: /bin/sh -c "envsubst '$$LOCAL_DIR $$LOCAL_HOSTNAME' < /etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"
|
||||
|
||||
php:
|
||||
environment:
|
||||
LOCAL_PHP_XDEBUG: ${LOCAL_PHP_XDEBUG-false}
|
||||
LOCAL_PHP_MEMCACHED: ${LOCAL_PHP_MEMCACHED-false}
|
||||
PHP_FPM_UID: ${PHP_FPM_UID-1000}
|
||||
PHP_FPM_GID: ${PHP_FPM_GID-1000}
|
||||
SMTP_HOST: ${SMTP_HOST-mailhog}
|
||||
SMTP_PORT: ${SMTP_PORT-1025}
|
||||
|
||||
volumes:
|
||||
- ..:/var/www/${LOCAL_DIR-src}/wp-content/plugins/daggerhart-openid-connect-generic/
|
||||
- ../tools/local-env/mu-plugins:/var/www/${LOCAL_DIR-src}/wp-content/mu-plugins
|
||||
|
||||
cli:
|
||||
environment:
|
||||
LOCAL_PHP_XDEBUG: ${LOCAL_PHP_XDEBUG-false}
|
||||
LOCAL_PHP_MEMCACHED: ${LOCAL_PHP_MEMCACHED-false}
|
||||
PHP_FPM_UID: ${PHP_FPM_UID-1000}
|
||||
PHP_FPM_GID: ${PHP_FPM_GID-1000}
|
||||
SMTP_HOST: ${SMTP_HOST-mailhog}
|
||||
SMTP_PORT: ${SMTP_PORT-1025}
|
||||
|
||||
volumes:
|
||||
- ..:/var/www/${LOCAL_DIR-src}/wp-content/plugins/daggerhart-openid-connect-generic/
|
||||
- ../tools/local-env/mu-plugins:/var/www/${LOCAL_DIR-src}/wp-content/mu-plugins
|
||||
|
||||
phpunit:
|
||||
environment:
|
||||
LOCAL_PHP_XDEBUG: ${LOCAL_PHP_XDEBUG-false}
|
||||
LOCAL_PHP_MEMCACHED: ${LOCAL_PHP_MEMCACHED-false}
|
||||
LOCAL_DIR: ${LOCAL_DIR-src}
|
||||
WP_MULTISITE: ${WP_MULTISITE-false}
|
||||
PHP_FPM_UID: ${PHP_FPM_UID-1000}
|
||||
PHP_FPM_GID: ${PHP_FPM_GID-1000}
|
||||
TRAVIS_BRANCH: ${TRAVIS_BRANCH-false}
|
||||
TRAVIS_PULL_REQUEST: ${TRAVIS_PULL_REQUEST-false}
|
||||
SMTP_HOST: ${SMTP_HOST-mailhog}
|
||||
SMTP_PORT: ${SMTP_PORT-1025}
|
||||
|
||||
volumes:
|
||||
- ..:/var/www/${LOCAL_DIR-src}/wp-content/plugins/daggerhart-openid-connect-generic/
|
||||
- ../tools/local-env/mu-plugins:/var/www/${LOCAL_DIR-src}/wp-content/mu-plugins
|
||||
|
||||
## SMTP Server + Web Interface for viewing and testing emails during development.
|
||||
mailhog:
|
||||
image: mailhog/mailhog
|
||||
|
||||
restart: always
|
||||
|
||||
networks:
|
||||
- wpdevnet
|
||||
|
||||
ports:
|
||||
- "${MAILHOG_PORT:-8025}:8025"
|
||||
- "${SMTP_PORT:-1025}:1025"
|
@ -0,0 +1,38 @@
|
||||
# grumphp.yml
|
||||
parameters:
|
||||
git_dir: .
|
||||
bin_dir: 'vendor/bin'
|
||||
stop_on_failure: true
|
||||
process_timeout: 120
|
||||
parallel:
|
||||
enabled: true
|
||||
max_workers: 32
|
||||
fixer:
|
||||
enabled: false
|
||||
fix_by_default: false
|
||||
tasks:
|
||||
git_blacklist:
|
||||
keywords:
|
||||
- 'wp_die('
|
||||
- 'die('
|
||||
git_branch_name:
|
||||
blacklist:
|
||||
- 'main'
|
||||
- 'master'
|
||||
- 'dev*'
|
||||
allow_detached_head: false
|
||||
git_commit_message:
|
||||
allow_empty_message: false
|
||||
enforce_capitalized_subject: true
|
||||
phpcs:
|
||||
standard: './phpcs.xml.dist'
|
||||
report: 'summary'
|
||||
ignore_patterns:
|
||||
- '/^assets\/(.*)/'
|
||||
phpstan:
|
||||
configuration: './phpstan.neon.dist'
|
||||
level: 5
|
||||
ignore_patterns:
|
||||
- '/^assets\/(.*)/'
|
||||
memory_limit: '-1'
|
||||
securitychecker: ~
|
File diff suppressed because it is too large
Load Diff
@ -1,60 +1,177 @@
|
||||
<?php
|
||||
/**
|
||||
* Class OpenId_Connect_Generic_Option_Settings
|
||||
* WordPress options handling class.
|
||||
*
|
||||
* @package OpenID_Connect_Generic
|
||||
* @category Settings
|
||||
* @author Jonathan Daggerhart <jonathan@daggerhart.com>
|
||||
* @copyright 2015-2020 daggerhart
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
|
||||
*/
|
||||
|
||||
/**
|
||||
* OpenId_Connect_Generic_Option_Settings class.
|
||||
*
|
||||
* WordPress options handling.
|
||||
*
|
||||
* @package OpenID_Connect_Generic
|
||||
* @category Settings
|
||||
*
|
||||
* Legacy Settings:
|
||||
*
|
||||
* @property string $ep_login The login endpoint.
|
||||
* @property string $ep_token The token endpoint.
|
||||
* @property string $ep_userinfo The userinfo endpoint.
|
||||
*
|
||||
* OAuth Client Settings:
|
||||
*
|
||||
* @property string $login_type How the client (login form) should provide login options.
|
||||
* @property string $client_id The ID the client will be recognized as when connecting the to Identity provider server.
|
||||
* @property string $client_secret The secret key the IDP server expects from the client.
|
||||
* @property string $scope The list of scopes this client should access.
|
||||
* @property string $endpoint_login The IDP authorization endpoint URL.
|
||||
* @property string $endpoint_userinfo The IDP User information endpoint URL.
|
||||
* @property string $endpoint_token The IDP token validation endpoint URL.
|
||||
* @property string $endpoint_end_session The IDP logout endpoint URL.
|
||||
*
|
||||
* Non-standard Settings:
|
||||
*
|
||||
* @property bool $no_sslverify The flag to enable/disable SSL verification during authorization.
|
||||
* @property int $http_request_timeout The timeout for requests made to the IDP. Default value is 5.
|
||||
* @property string $identity_key The key in the user claim array to find the user's identification data.
|
||||
* @property string $nickname_key The key in the user claim array to find the user's nickname.
|
||||
* @property string $email_format The key(s) in the user claim array to formulate the user's email address.
|
||||
* @property string $displayname_format The key(s) in the user claim array to formulate the user's display name.
|
||||
* @property bool $identify_with_username The flag which indicates how the user's identity will be determined.
|
||||
* @property int $state_time_limit The valid time limit of the state, in seconds. Defaults to 180 seconds.
|
||||
*
|
||||
* Plugin Settings:
|
||||
*
|
||||
* @property bool $enforce_privacy The flag to indicates whether a user us required to be authenticated to access the site.
|
||||
* @property bool $alternate_redirect_uri The flag to indicate whether to use the alternative redirect URI.
|
||||
* @property bool $token_refresh_enable The flag whether to support refresh tokens by IDPs.
|
||||
* @property bool $link_existing_users The flag to indicate whether to link to existing WordPress-only accounts or greturn an error.
|
||||
* @property bool $create_if_does_not_exist The flag to indicate whether to create new users or not.
|
||||
* @property bool $redirect_user_back The flag to indicate whether to redirect the user back to the page on which they started.
|
||||
* @property bool $redirect_on_logout The flag to indicate whether to redirect to the login screen on session expiration.
|
||||
* @property bool $enable_logging The flag to enable/disable logging.
|
||||
* @property int $log_limit The maximum number of log entries to keep.
|
||||
*/
|
||||
class OpenID_Connect_Generic_Option_Settings {
|
||||
|
||||
// wp option name/key
|
||||
/**
|
||||
* WordPress option name/key.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $option_name;
|
||||
|
||||
// stored option values array
|
||||
/**
|
||||
* Stored option values array.
|
||||
*
|
||||
* @var array<mixed>
|
||||
*/
|
||||
private $values;
|
||||
|
||||
// default plugin settings values
|
||||
/**
|
||||
* Default plugin settings values.
|
||||
*
|
||||
* @var array<mixed>
|
||||
*/
|
||||
private $default_settings;
|
||||
|
||||
/**
|
||||
* @param $option_name
|
||||
* @param array $default_settings
|
||||
* @param bool|TRUE $granular_defaults
|
||||
* The class constructor.
|
||||
*
|
||||
* @param string $option_name The option name/key.
|
||||
* @param array<mixed> $default_settings The default plugin settings values.
|
||||
* @param bool $granular_defaults The granular defaults.
|
||||
*/
|
||||
function __construct( $option_name, $default_settings = array(), $granular_defaults = true ){
|
||||
function __construct( $option_name, $default_settings = array(), $granular_defaults = true ) {
|
||||
$this->option_name = $option_name;
|
||||
$this->default_settings = $default_settings;
|
||||
$this->values = get_option( $this->option_name, $this->default_settings );
|
||||
$this->values = array();
|
||||
|
||||
if ( ! empty( $this->option_name ) ) {
|
||||
get_option( $this->option_name, $this->default_settings );
|
||||
}
|
||||
|
||||
if ( $granular_defaults ) {
|
||||
$this->values = array_replace_recursive( $this->default_settings, $this->values );
|
||||
}
|
||||
}
|
||||
|
||||
function __get( $key ){
|
||||
/**
|
||||
* Magic getter for settings.
|
||||
*
|
||||
* @param string $key The array key/option name.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function __get( $key ) {
|
||||
if ( isset( $this->values[ $key ] ) ) {
|
||||
return $this->values[ $key ];
|
||||
}
|
||||
}
|
||||
|
||||
function __set( $key, $value ){
|
||||
/**
|
||||
* Magic setter for settings.
|
||||
*
|
||||
* @param string $key The array key/option name.
|
||||
* @param mixed $value The option value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __set( $key, $value ) {
|
||||
$this->values[ $key ] = $value;
|
||||
}
|
||||
|
||||
function __isset( $key ){
|
||||
/**
|
||||
* Magic method to check is an attribute isset.
|
||||
*
|
||||
* @param string $key The array key/option name.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function __isset( $key ) {
|
||||
return isset( $this->values[ $key ] );
|
||||
}
|
||||
|
||||
function __unset( $key ){
|
||||
unset( $this->values[ $key ]);
|
||||
/**
|
||||
* Magic method to clear an attribute.
|
||||
*
|
||||
* @param string $key The array key/option name.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __unset( $key ) {
|
||||
unset( $this->values[ $key ] );
|
||||
}
|
||||
|
||||
function get_values(){
|
||||
/**
|
||||
* Get the plugin settings array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_values() {
|
||||
return $this->values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plugin WordPress options name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_option_name() {
|
||||
return $this->option_name;
|
||||
}
|
||||
|
||||
function save(){
|
||||
/**
|
||||
* Save the plugin options to the WordPress options table.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function save() {
|
||||
update_option( $this->option_name, $this->values );
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,60 @@
|
||||
{
|
||||
"name": "openid-connect-generic",
|
||||
"version": "3.7.0",
|
||||
"description": "OpenID Connect generic WordPress plugin.",
|
||||
"main": "Gruntfile.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/daggerhart/openid-connect-generic"
|
||||
},
|
||||
"keywords": [
|
||||
"wordpress",
|
||||
"openid"
|
||||
],
|
||||
"author": "Jonathan Daggerhart",
|
||||
"license": "GPL-2.0-only",
|
||||
"bugs": {
|
||||
"url": "https://github.com/daggerhart/openid-connect-generic/issues"
|
||||
},
|
||||
"homepage": "https://github.com/daggerhart/openid-connect-generic#readme",
|
||||
"dependencies": {
|
||||
"dev-require": "^0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@floatwork/grunt-po2mo": "^0.3.0",
|
||||
"@ndigitals/grunt-checkrepo": "^0.2.0",
|
||||
"@wordpress/env": "^1.6.0",
|
||||
"@wordpress/scripts": "^12.1.0",
|
||||
"grunt": "~1.0.4",
|
||||
"grunt-checkbranch": "^1.0.4",
|
||||
"grunt-checktextdomain": "^1.0.1",
|
||||
"grunt-contrib-clean": "^2.0.0",
|
||||
"grunt-contrib-copy": "^1.0.0",
|
||||
"grunt-gitinfo": "^0.1.9",
|
||||
"grunt-shell": "^2.1.0",
|
||||
"grunt-wp-i18n": "^1.0.3",
|
||||
"grunt-wp-readme-to-markdown": "~2.0.0",
|
||||
"load-grunt-tasks": "^3.5",
|
||||
"puppeteer": "^1.20.0",
|
||||
"typescript": "^3.9.7"
|
||||
},
|
||||
"wp-env": {
|
||||
"plugin-dir": "daggerhart-openid-connect-generic",
|
||||
"plugin-name": "OpenID Connect Generic",
|
||||
"docker-template": "./docker-compose.override.yml",
|
||||
"welcome-build-command": "npm run env start"
|
||||
},
|
||||
"scripts": {
|
||||
"grunt": "node_modules/.bin/grunt",
|
||||
"test": "npm run grunt test",
|
||||
"build": "npm run grunt build",
|
||||
"wp-env": "wp-env",
|
||||
"wp": "wp-env run cli wp",
|
||||
"makepot": "wp-env run cli wp i18n make-pot . languages/ --slug=daggerhart-openid-connect-generic --include=openid-connect-generic.php,includes",
|
||||
"lint": "npm run lint:php",
|
||||
"lint:php": "composer run-script phpcs .",
|
||||
"lint-fix:php": "composer run-script phpcbf .",
|
||||
"analyze": "npm run analyze:php",
|
||||
"analyze:php": "composer run-script phpstan analyze ."
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="WordPress Coding Standards for Plugins">
|
||||
<description>Generally-applicable sniffs for WordPress plugins</description>
|
||||
|
||||
<rule ref="WordPress-Core">
|
||||
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
|
||||
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
|
||||
</rule>
|
||||
<rule ref="WordPress-Docs" />
|
||||
|
||||
<!-- Check all PHP files in directory tree by default. -->
|
||||
<arg name="basepath" value="." />
|
||||
<arg name="extensions" value="php" />
|
||||
<arg name="report" value="summary" />
|
||||
<!-- Show colors. -->
|
||||
<arg name="colors" />
|
||||
<!-- Show progress. -->
|
||||
<arg value="p" />
|
||||
<arg value="n" />
|
||||
|
||||
<file>.</file>
|
||||
|
||||
<!-- Show sniff codes in all reports -->
|
||||
<arg value="s"/>
|
||||
|
||||
<exclude-pattern>*/dist/*</exclude-pattern>
|
||||
<exclude-pattern>*/node_modules/*</exclude-pattern>
|
||||
<exclude-pattern>*/tests/*</exclude-pattern>
|
||||
<exclude-pattern>*/tools/*</exclude-pattern>
|
||||
<exclude-pattern>*/vendor/*</exclude-pattern>
|
||||
<exclude-pattern>*/wordpress/*</exclude-pattern>
|
||||
</ruleset>
|
@ -0,0 +1,51 @@
|
||||
#$ composer update --optimize-autoloader
|
||||
#$ vendor/bin/phpstan analyze
|
||||
|
||||
includes:
|
||||
# @see https://github.com/phpstan/phpstan-src/blob/master/conf/bleedingEdge.neon
|
||||
- phar://phpstan.phar/conf/bleedingEdge.neon
|
||||
# Include this extension
|
||||
# - vendor/szepeviktor/phpstan-wordpress/extension.neon
|
||||
parameters:
|
||||
level: 5
|
||||
inferPrivatePropertyTypeFromConstructor: true
|
||||
bootstrapFiles:
|
||||
- tests/phpstan-bootstrap.php
|
||||
# autoload_files:
|
||||
# Missing constants, function and class stubs
|
||||
# - tests/phpstan/bootstrap.php
|
||||
# Plugin stubs
|
||||
# - tests/phpstan/PLUGIN-stubs.php
|
||||
# Procedural code
|
||||
# - myplugin-functions.php
|
||||
# autoload_directories:
|
||||
# - inc/
|
||||
paths:
|
||||
- includes/
|
||||
- ./
|
||||
excludes_analyse:
|
||||
- node_modules/
|
||||
- scripts/
|
||||
- tests/
|
||||
- tools/
|
||||
- vendor/
|
||||
- wordpress/
|
||||
# scanFiles:
|
||||
# - includes/class.php
|
||||
scanDirectories:
|
||||
- wordpress/src/
|
||||
ignoreErrors:
|
||||
# Uses func_get_args()
|
||||
- '#^Function apply_filters(_ref_array)? invoked with [34567] parameters, 2 required\.$#'
|
||||
# Fixed in WordPress 5.3
|
||||
# - '#^Function do_action(_ref_array)? invoked with [3456] parameters, 1-2 required\.$#'
|
||||
# - '#^Function current_user_can invoked with 2 parameters, 1 required\.$#'
|
||||
# - '#^Function add_query_arg invoked with [123] parameters?, 0 required\.$#'
|
||||
# - '#^Function wp_sprintf invoked with [23456] parameters, 1 required\.$#'
|
||||
# - '#^Function add_post_type_support invoked with [345] parameters, 2 required\.$#'
|
||||
# - '#^Function ((get|add)_theme_support|current_theme_supports) invoked with [2345] parameters, 1 required\.$#'
|
||||
# https://core.trac.wordpress.org/ticket/43304
|
||||
# - '/^Parameter #2 \$deprecated of function load_plugin_textdomain expects string, false given\.$/'
|
||||
# WP-CLI accepts a class as callable
|
||||
# - '/^Parameter #2 \$callable of static method WP_CLI::add_command\(\) expects callable\(\): mixed, \S+ given\.$/'
|
||||
# Please consider commenting ignores: issue URL or reason for ignoring
|
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0"?>
|
||||
<phpunit
|
||||
bootstrap="tests/bootstrap.php"
|
||||
backupGlobals="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Includes">
|
||||
<directory suffix="_test.php">./tests/phpunit/includes/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">src/</directory>
|
||||
<!-- <file>/path/to/file</file> -->
|
||||
<exclude>
|
||||
<directory suffix=".php">src/views</directory>
|
||||
<!-- <file>/path/to/file</file> -->
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
<logging>
|
||||
<log type="coverage-clover" target="clover.xml"/>
|
||||
</logging>
|
||||
</phpunit>
|
@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ $# -lt 3 ]; then
|
||||
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DB_NAME=$1
|
||||
DB_USER=$2
|
||||
DB_PASS=$3
|
||||
DB_HOST=${4-localhost}
|
||||
WP_VERSION=${5-latest}
|
||||
SKIP_DB_CREATE=${6-false}
|
||||
|
||||
WP_TESTS_DIR=${WP_TESTS_DIR-${TMPDIR-/tmp}/wordpress-tests-lib}
|
||||
WP_CORE_DIR=${WP_CORE_DIR-${TMPDIR-/tmp}/wordpress/}
|
||||
|
||||
download() {
|
||||
if [ `which curl` ]; then
|
||||
curl -s "$1" > "$2";
|
||||
elif [ `which wget` ]; then
|
||||
wget -nv -O "$2" "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
|
||||
WP_TESTS_TAG="tags/$WP_VERSION"
|
||||
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
|
||||
WP_TESTS_TAG="trunk"
|
||||
else
|
||||
# http serves a single offer, whereas https serves multiple. we only want one
|
||||
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
|
||||
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
|
||||
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
|
||||
if [[ -z "$LATEST_VERSION" ]]; then
|
||||
echo "Latest WordPress version could not be found"
|
||||
exit 1
|
||||
fi
|
||||
WP_TESTS_TAG="tags/$LATEST_VERSION"
|
||||
fi
|
||||
|
||||
set -ex
|
||||
|
||||
install_wp() {
|
||||
|
||||
if [ -d $WP_CORE_DIR ]; then
|
||||
return;
|
||||
fi
|
||||
|
||||
mkdir -p $WP_CORE_DIR
|
||||
|
||||
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
|
||||
mkdir -p /tmp/wordpress-nightly
|
||||
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
|
||||
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
|
||||
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
|
||||
else
|
||||
if [ $WP_VERSION == 'latest' ]; then
|
||||
local ARCHIVE_NAME='latest'
|
||||
else
|
||||
local ARCHIVE_NAME="wordpress-$WP_VERSION"
|
||||
fi
|
||||
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
|
||||
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
|
||||
fi
|
||||
|
||||
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
|
||||
}
|
||||
|
||||
install_test_suite() {
|
||||
# portable in-place argument for both GNU sed and Mac OSX sed
|
||||
if [[ $(uname -s) == 'Darwin' ]]; then
|
||||
local ioption='-i .bak'
|
||||
else
|
||||
local ioption='-i'
|
||||
fi
|
||||
|
||||
# set up testing suite if it doesn't yet exist
|
||||
if [ ! -d $WP_TESTS_DIR ]; then
|
||||
# set up testing suite
|
||||
mkdir -p $WP_TESTS_DIR
|
||||
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
|
||||
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
|
||||
fi
|
||||
|
||||
if [ ! -f wp-tests-config.php ]; then
|
||||
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
|
||||
# remove all forward slashes in the end
|
||||
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
|
||||
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
|
||||
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
|
||||
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
|
||||
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
|
||||
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
install_db() {
|
||||
|
||||
if [ ${SKIP_DB_CREATE} = "true" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# parse DB_HOST for port or socket references
|
||||
local PARTS=(${DB_HOST//\:/ })
|
||||
local DB_HOSTNAME=${PARTS[0]};
|
||||
local DB_SOCK_OR_PORT=${PARTS[1]};
|
||||
local EXTRA=""
|
||||
|
||||
if ! [ -z $DB_HOSTNAME ] ; then
|
||||
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
|
||||
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
|
||||
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
|
||||
EXTRA=" --socket=$DB_SOCK_OR_PORT"
|
||||
elif ! [ -z $DB_HOSTNAME ] ; then
|
||||
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
|
||||
fi
|
||||
fi
|
||||
|
||||
# create database
|
||||
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
|
||||
}
|
||||
|
||||
install_wp
|
||||
install_test_suite
|
||||
install_db
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Phpstan bootstrap file.
|
||||
*
|
||||
* @package OpenID_Connect_Generic
|
||||
* @author Jonathan Daggerhart <jonathan@daggerhart.com>
|
||||
* @author Tim Nolte <tim.nolte@ndigitals.com>
|
||||
* @copyright 2015-2020 daggerhart
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
|
||||
* @link https://github.com/daggerhart
|
||||
*/
|
||||
|
||||
// Define WordPress language directory.
|
||||
defined( 'WP_LANG_DIR' ) || define( 'WP_LANG_DIR', 'wordpress/src/wp-includes/languages/' );
|
||||
|
||||
defined( 'COOKIE_DOMAIN' ) || define( 'COOKIE_DOMAIN', 'localhost' );
|
||||
defined( 'COOKIEPATH' ) || define( 'COOKIEPATH', '/');
|
||||
|
||||
|
@ -0,0 +1,30 @@
|
||||
server {
|
||||
index index.php index.html;
|
||||
|
||||
listen 80 default_server;
|
||||
|
||||
server_name localhost penguin.linux.test ${LOCAL_HOSTNAME};
|
||||
|
||||
client_max_body_size 1g;
|
||||
|
||||
error_log /var/log/nginx/error.log;
|
||||
access_log /var/log/nginx/access.log;
|
||||
|
||||
root /var/www/${LOCAL_DIR};
|
||||
|
||||
absolute_redirect off;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$args;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
fastcgi_pass php:9000;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: MailHog PhpMailer Setup
|
||||
* Description: Establishes a connection between the PhpMailer library and the MailHog local-dev Docker container.
|
||||
*
|
||||
* @package OpenID_Connect_Generic_MuPlugins
|
||||
*/
|
||||
|
||||
// If this file is called directly, abort.
|
||||
if ( ! defined( 'WPINC' ) ) {
|
||||
die;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the configuration for PhpMailer to use MailHog.
|
||||
*
|
||||
* @param PHPMailer $phpmailer The PHPMailer instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function mailhog_phpmailer_setup( PHPMailer $phpmailer ) {
|
||||
|
||||
defined( 'SMTP_HOST' ) || define( 'SMTP_HOST', 'mailhog' );
|
||||
// PHPMailer doesn't follow WordPress naming conventions so this can be ignored.
|
||||
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
|
||||
$phpmailer->Host = SMTP_HOST;
|
||||
|
||||
defined( 'SMTP_PORT' ) || define( 'SMTP_PORT', 1025 );
|
||||
// PHPMailer doesn't follow WordPress naming conventions so this can be ignored.
|
||||
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
|
||||
$phpmailer->Port = SMTP_PORT;
|
||||
|
||||
$phpmailer->IsSMTP();
|
||||
|
||||
}
|
||||
|
||||
add_action( 'phpmailer_init', 'mailhog_phpmailer_setup', 10, 2 );
|
Loading…
Reference in New Issue