Skip to content

Commit

Permalink
Merge branch 'release-1.8.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
thingsym committed Dec 13, 2022
2 parents 3b0bb50 + 3ae23bd commit 581f648
Show file tree
Hide file tree
Showing 24 changed files with 904 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trim_trailing_whitespace = true
indent_style = tab
indent_size = 2

[*.{json,yml,xml,neon}]
[*.{json,yml,xml,neon,bats}]
indent_style = space

[*.md]
Expand Down
89 changes: 89 additions & 0 deletions .github/workflows/bats-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Bats test

on:
push:
branches:
- '**'
- '!svn-trunk'
- '!test-matrix'
tags-ignore:
- '**'
pull_request:
branches:
- '**'

jobs:
bats:
name: WordPress ${{ matrix.wordpress }} * PHP v${{ matrix.php }} * ${{ matrix.os }} * Multisite ${{ matrix.multisite }}
runs-on: ${{ matrix.os }}
timeout-minutes: 30

strategy:
fail-fast: false

matrix:
os: [ ubuntu-20.04 ]
php: [ '7.4' ]
wordpress: [ latest ]
multisite: [ 0 ]

env:
PHP_VERSION: ${{ matrix.php }}
WP_VERSION: ${{ matrix.wordpress }}
WP_MULTISITE: ${{ matrix.multisite }}

services:
database:
image: mysql:5.7
ports:
- 3306:3306
env:
MYSQL_ROOT_PASSWORD: root
options: --health-cmd "mysqladmin ping -h 0.0.0.0" --health-interval 20s --health-timeout 10s --health-retries 10

steps:
- name: Setup PHP v${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, intl, php-mysql

- name: Install WP-CLI
run: |
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp
- name: chown to runner:docker
run: sudo chown -R runner:docker /var/www/html

- name: Install WordPress
run: |
wp core download --version=${{ matrix.wordpress }}
wp config create --dbhost=0.0.0.0:3306 --dbname=wordpress_test --dbuser=root --dbpass=root --force
wp db create --allow-root
wp core install --url=example.com --title=Example --admin_user=admin --admin_password=admin --admin_email=admin@example.com
working-directory: /var/www/html

- name: Install default WordPress theme
run: |
wp theme install twentysixteen
wp theme install twentyfifteen
wp theme install twentynineteen
working-directory: /var/www/html

- uses: actions/checkout@v3

- name: Move plugin
run: cp -r /home/runner/work/multi-device-switcher/multi-device-switcher /var/www/html/wp-content/plugins/multi-device-switcher

- name: Active Plugin
run: wp plugin activate multi-device-switcher
working-directory: /var/www/html

- name: Setup Bats
uses: mig4/setup-bats@v1

- name: Run Bats test
run: bats tests/cli
working-directory: /var/www/html/wp-content/plugins/multi-device-switcher
2 changes: 1 addition & 1 deletion .github/workflows/wp-plugin-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
timeout-minutes: 30

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: WordPress Plugin Deploy
uses: 10up/action-wordpress-plugin-deploy@stable
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wp-plugin-trunk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
timeout-minutes: 30

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: WordPress.org plugin asset/readme update
uses: 10up/action-wordpress-plugin-asset-update@stable
Expand Down
45 changes: 44 additions & 1 deletion .github/workflows/wp-plugin-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ jobs:
- 3306:3306
env:
MYSQL_ROOT_PASSWORD: root
options: --health-cmd "mysqladmin ping -h 0.0.0.0" --health-interval 20s --health-timeout 10s --health-retries 10

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Setup PHP v${{ matrix.php }}
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -87,3 +88,45 @@ jobs:
- name: Run PHPUnit - WordPress ${{ matrix.wordpress }} * Multisite ${{ matrix.multisite }}
run: phpunit

phpcs:
name: PHP CodeSniffer
runs-on: ${{ matrix.os }}
timeout-minutes: 30

strategy:
fail-fast: false

matrix:
os: [ ubuntu-20.04 ]
php: [ '7.4' ]
wordpress: [ latest ]
multisite: [ 0 ]

env:
PHP_VERSION: ${{ matrix.php }}
WP_VERSION: ${{ matrix.wordpress }}
WP_MULTISITE: ${{ matrix.multisite }}

steps:
- uses: actions/checkout@v3

- name: Setup PHP v${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, intl, php-mysql

- name: Install php_codesniffer library and PHP_CodeSniffer rules
run: |
composer global require "squizlabs/php_codesniffer=3.*"
composer global require "wp-coding-standards/wpcs=2.*"
composer global require "phpcompatibility/phpcompatibility-wp=*"
- name: phpcs --config-set
run: |
phpcs --config-set installed_paths /home/runner/.composer/vendor/wp-coding-standards/wpcs,/home/runner/.composer/vendor/phpcompatibility/php-compatibility,/home/runner/.composer/vendor/phpcompatibility/phpcompatibility-paragonie,/home/runner/.composer/vendor/phpcompatibility/phpcompatibility-wp
phpcs -i
- name: Run phpcs
run: phpcs -p -s -v ./ --standard=./phpcs.ruleset.xml --extensions=php
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,17 @@ For operation compatibility between PHP version and WordPress version, see below

## Changelog

* Version 1.8.5
* add phpcs job to ci
* add healthcheck to database container
* add bats test to ci
* fix bats test case
* add test case
* fix phpcs.ruleset.xml
* add enqueue_styles method
* imporve code with phpcs
* fix composer scripts
* update github actions
* Version 1.8.4
* tested up to 6.1.0
* update japanese translation
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thingsym/multi-device-switcher",
"version": "1.8.4",
"version": "1.8.5",
"description": "This WordPress plugin allows you to set a separate theme for device (Smart Phone, Tablet PC, Mobile Phone, Game and custom).",
"author": [
{
Expand Down Expand Up @@ -37,8 +37,8 @@
"post-install-cmd": "@phpcs:config-set",
"post-update-cmd" : "@phpcs:config-set",
"phpcs:config-set": "phpcs --config-set installed_paths vendor/wp-coding-standards/wpcs,vendor/phpcompatibility/php-compatibility,vendor/phpcompatibility/phpcompatibility-paragonie,vendor/phpcompatibility/phpcompatibility-wp",
"phpcs": "phpcs -p -s -v -n ./ --standard=./phpcs.ruleset.xml --extensions=php",
"phpcs:warning": "phpcs -p -s -v ./ --standard=./phpcs.ruleset.xml --extensions=php",
"phpcs": "phpcs -p -s -v ./ --standard=./phpcs.ruleset.xml --extensions=php",
"phpcs:error": "phpcs -p -s -v -n ./ --standard=./phpcs.ruleset.xml --extensions=php",
"format:phpcbf": "phpcbf -p -s -v ./ --standard=./phpcs.ruleset.xml --extensions=php",
"phpmd": "phpmd ./ text ./phpmd.ruleset.xml --suffixes php --exclude /languages,/tests,/vendor,/node_modules",
"phpstan": "phpstan analyse",
Expand Down
2 changes: 1 addition & 1 deletion languages/multi-device-switcher-ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is distributed under the GPLv2 or later.
msgid ""
msgstr ""
"Project-Id-Version: Multi Device Switcher 1.8.4\n"
"Project-Id-Version: Multi Device Switcher 1.8.5\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/multi-device-"
"switcher\n"
"POT-Creation-Date: 2022-11-25T10:39:41+00:00\n"
Expand Down
2 changes: 1 addition & 1 deletion languages/multi-device-switcher.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is distributed under the GPLv2 or later.
msgid ""
msgstr ""
"Project-Id-Version: Multi Device Switcher 1.8.4\n"
"Project-Id-Version: Multi Device Switcher 1.8.5\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/multi-device-switcher\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down
50 changes: 34 additions & 16 deletions multi-device-switcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Multi Device Switcher
* Plugin URI: https://github.com/thingsym/multi-device-switcher
* Description: This WordPress plugin allows you to set a separate theme for device (Smart Phone, Tablet PC, Mobile Phone, Game and custom).
* Version: 1.8.4
* Version: 1.8.5
* Author: thingsym
* Author URI: https://www.thingslabo.com/
* License: GPLv2 or later
Expand Down Expand Up @@ -470,25 +470,48 @@ public function set_cookie_normal_theme() {
* @since 1.0.0
*/
public function session() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['pc-switcher'] ) ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
setcookie( $this->cookie_name_pc_switcher, $_GET['pc-switcher'] ? '1' : '', 0, '/', '', is_ssl(), false );
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
setcookie( $this->cookie_name_pc_switcher, sanitize_text_field( wp_unslash( $_GET['pc-switcher'] ) ) ? '1' : '', 0, '/', '', is_ssl(), false );

if ( isset( $_SERVER['REQUEST_URI'] ) ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$uri = preg_replace( '/^(.+?)(\?.*)$/', '$1', $_SERVER['REQUEST_URI'] );
}

// phpcs:ignore WordPress.Security.NonceVerification.Recommended
unset( $_GET['pc-switcher'] );
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( ! empty( $_GET ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$uri = $uri . '?' . http_build_query( $_GET );
}

wp_redirect( esc_url( $uri ) );
wp_safe_redirect( esc_url( $uri ) );
exit;
}
}

/**
* Enqueue styles for default_css
*
* @access public
*
* @return void
*
* @since 1.8.5
*/
public function enqueue_styles() {
wp_enqueue_style(
'pc-switcher-options',
plugins_url() . '/multi-device-switcher/pc-switcher.css',
array(),
$this->plugin_data['Version'],
'all'
);
}

/**
* Add pc switcher button.
*
Expand All @@ -510,16 +533,10 @@ public function add_pc_switcher( $pc_switcher = 0 ) {

if ( $pc_switcher && $name && 'None' !== $name ) {
if ( $options['default_css'] ) {
wp_enqueue_style(
'pc-switcher-options',
plugins_url() . '/multi-device-switcher/pc-switcher.css',
array(),
$this->plugin_data['Version'],
'all'
);
$this->enqueue_styles();
}

$uri = is_ssl() ? 'https://' : 'http://';
$uri = is_ssl() ? 'https://' : 'http://';

if ( isset( $_SERVER['HTTP_HOST'] ) ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
Expand Down Expand Up @@ -681,7 +698,8 @@ public function admin_enqueue_scripts( $hook_suffix = '' ) {
'multi-device-switcher-options',
plugins_url() . '/multi-device-switcher/multi-device-switcher.js',
array( 'jquery', 'jquery-ui-tabs' ),
$this->plugin_data['Version']
$this->plugin_data['Version'],
false
);
}

Expand Down Expand Up @@ -821,7 +839,7 @@ public function plugin_action_links( $links = array() ) {
* @since 1.8.1
*/
public function plugin_metadata_links( $links, $file ) {
if ( $file == plugin_basename( __MULTI_DEVICE_SWITCHER_FILE__ ) ) {
if ( $file === plugin_basename( __MULTI_DEVICE_SWITCHER_FILE__ ) ) {
$links[] = '<a href="https://github.com/sponsors/thingsym">' . __( 'Become a sponsor', 'multi-device-switcher' ) . '</a>';
}

Expand Down Expand Up @@ -910,7 +928,7 @@ public function load_textdomain() {
*/
public function load_plugin_data() {
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

$this->plugin_data = get_plugin_data( __MULTI_DEVICE_SWITCHER_FILE__ );
Expand Down Expand Up @@ -1321,7 +1339,7 @@ public function validate_options( $input ) {
}

if ( isset( $input['add_custom_switcher'] ) && ! empty( $input['custom_switcher'] ) && ! isset( $output[ 'custom_switcher_theme_' . $input['custom_switcher'] ] ) ) {
if ( ! in_array( $input['custom_switcher'], array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ) )
if ( ! in_array( $input['custom_switcher'], array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ), true )
&& preg_match( '/^[A-Za-z0-9]{1,20}$/', $input['custom_switcher'] ) ) {
$output[ 'custom_switcher_theme_' . $input['custom_switcher'] ] = 'None';
$output[ 'custom_switcher_userAgent_' . $input['custom_switcher'] ] = '';
Expand Down
2 changes: 1 addition & 1 deletion pc-switcher-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Widget Name: PC Switcher Widget
* Plugin URI: https://github.com/thingsym/multi-device-switcher
* Description: PC Switcher Widget add-on for the Multi Device Switcher. Use this widget to add the PC Switcher to a widget.
* Version: 1.8.4
* Version: 1.8.5
* Author: thingsym
* Author URI: https://www.thingslabo.com/
* License: GPLv2 or later
Expand Down
1 change: 1 addition & 0 deletions phpcs.ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<exclude name="WordPress.PHP.YodaConditions.NotYoda" />

<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
<exclude name="WordPress.NamingConventions.ValidHookName.UseUnderscores" />
</rule>

<rule ref="PHPCompatibilityWP">
Expand Down
14 changes: 13 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: thingsym
Link: https://github.com/thingsym/multi-device-switcher
Donate link: https://github.com/sponsors/thingsym
Tags: switcher, theme, ipad, iphone, android, tablet, mobile, game
Stable tag: 1.8.4
Stable tag: 1.8.5
Tested up to: 6.1.0
Requires at least: 4.9
Requires PHP: 5.6
Expand Down Expand Up @@ -395,6 +395,18 @@ For more information about the Multi Device Switcher Command, see `wp help multi

== Changelog ==

= 1.8.5 =
* add phpcs job to ci
* add healthcheck to database container
* add bats test to ci
* fix bats test case
* add test case
* fix phpcs.ruleset.xml
* add enqueue_styles method
* imporve code with phpcs
* fix composer scripts
* update github actions

= 1.8.4 =
* tested up to 6.1.0
* update japanese translation
Expand Down
Loading

0 comments on commit 581f648

Please sign in to comment.