Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ coverage.xml
.gitignore
.phpunit.result.cache
.scrutinizer.yml
Changelog.md
composer.json
composer.lock
mslsmenu.zip
package.json
package-lock.json
phpdoc.xml
phpstan.neon
.phpstan.neon.dist
.phpcs.cache
.phpcs.xml.dist
phpunit.xml
README.md
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
.phpunit.result.cache
.phpcs.cache
.idea/
vendor/
reports/
Expand Down
26 changes: 26 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<ruleset name="CS">
<description>PHPCS MslsMenu configuration</description>
<config name="testVersion" value="7.4-"/>
<exclude-pattern>bin/*</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
<exclude-pattern>vendor/*</exclude-pattern>

<arg value="ps"/>
<arg name="colors"/>
<arg name="parallel" value="100"/>
<arg name="extensions" value="php"/>
<arg name="cache" value=".phpcs.cache"/>

<rule ref="WordPress">
<exclude name="Generic.Commenting.DocComment.MissingShort" />
<exclude name="Squiz.Commenting.FileComment.Missing" />
<exclude name="Squiz.Commenting.ClassComment.Missing" />
<exclude name="Squiz.Commenting.FunctionComment.Missing" />
<exclude name="Squiz.Commenting.FunctionComment.MissingParamComment" />
<exclude name="WordPress.Files.FileName" />
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.Found" />
</rule>
<rule ref="WordPress-Extra"/>
<rule ref="WordPress-Docs"/>
</ruleset>
File renamed without changes.
70 changes: 36 additions & 34 deletions MslsMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @copyright Copyright (C) 2011-2022, Dennis Ploetner, re@lloc.de
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 or later
* @wordpress-plugin
* @package mslsmenu
*
* Plugin Name: MslsMenu
* Requires Plugins: multisite-language-switcher
Expand Down Expand Up @@ -35,6 +36,7 @@

/**
* MslsMenu Class
*
* @package mslsmenu
*/
final class MslsMenu {
Expand All @@ -56,8 +58,6 @@ final class MslsMenu {
*/
public function __construct( $options ) {
$this->options = $options;

load_plugin_textdomain( 'mslsmenu', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}

/**
Expand All @@ -71,21 +71,21 @@ public static function init( $options ): MslsMenu {
$obj = new self( $options );

if ( ! is_null( $options ) ) {
add_filter( 'wp_nav_menu_items', [ $obj, 'nav_item' ], 10, 2 );
add_action( 'msls_admin_register', [ $obj, 'admin_register' ] );
add_filter( 'wp_nav_menu_items', array( $obj, 'nav_item' ), 10, 2 );
add_action( 'msls_admin_register', array( $obj, 'admin_register' ) );
}

return $obj;
}

private function get_msls_output(): lloc\Msls\MslsOutput{
private function get_msls_output(): lloc\Msls\MslsOutput {
return function_exists( 'msls_output' ) ? msls_output() : lloc\Msls\MslsOutput::init();
}

/**
* Callback for wp_nav_menu_items
*
* @param string $items
* @param string $items
* @param \stdClass $args
*
* @return string
Expand All @@ -94,7 +94,7 @@ public function nav_item( string $items, \stdClass $args ): string {
$menu_locations = $this->options->mslsmenu_theme_location ?? '';
$theme_location = $args->theme_location ?? '';

if ( is_array( $menu_locations ) && in_array( $theme_location, $menu_locations ) ) {
if ( is_array( $menu_locations ) && in_array( $theme_location, $menu_locations, true ) ) {
$menu = '';

$obj = $this->get_msls_output();
Expand All @@ -118,31 +118,31 @@ public function admin_register( string $page ) {

$this->page = $page;

add_settings_section( self::SID, $label, [ $this, 'add_settings' ], $page );
add_settings_section( self::SID, $label, array( $this, 'add_settings' ), $page );
}

/**
* Callback for add_settings_section in admin_register
*/
public function add_settings(): void {
$args = [ 'msls_admin' => lloc\Msls\MslsAdmin::init() ];
$args = array( 'msls_admin' => lloc\Msls\MslsAdmin::init() );

$label = __( 'Theme Location', 'mslsmenu' );
$callback = [ $this, 'theme_location' ];
$callback = array( $this, 'theme_location' );
add_settings_field( 'mslsmenu_theme_location', $label, $callback, $this->page, self::SID, $args );

$label = __( 'Display', 'mslsmenu' );
$callback = [ $this, 'display' ];
$callback = array( $this, 'display' );
add_settings_field( 'mslsmenu_display', $label, $callback, $this->page, self::SID, $args );

$fields = [
$fields = array(
'mslsmenu_before_output' => __( 'Text/HTML before the list', 'mslsmenu' ),
'mslsmenu_after_output' => __( 'Text/HTML after the list', 'mslsmenu' ),
'mslsmenu_before_item' => __( 'Text/HTML before each item', 'mslsmenu' ),
'mslsmenu_after_item' => __( 'Text/HTML after each item', 'mslsmenu' ),
];
);

$callback = [ $this, 'input' ];
$callback = array( $this, 'input' );
foreach ( $fields as $id => $label ) {
$args['mslsmenu_input'] = $id;
add_settings_field( $id, $label, $callback, $this->page, self::SID, $args );
Expand All @@ -157,26 +157,26 @@ public function add_settings(): void {
public function theme_location( array $args ) {
$menu_locations = get_nav_menu_locations();
$theme_locations = $this->options->mslsmenu_theme_location ?? '';
$options = [
sprintf( '<option value="" %s>%s</option>', $this->selected( '', $theme_locations ), esc_html__( '-- empty --', 'mslsmenu' ) )
];
$options = array(
sprintf( '<option value="" %s>%s</option>', $this->selected( '', $theme_locations ), esc_html__( '-- empty --', 'mslsmenu' ) ),
);

foreach ( array_keys( $menu_locations ) as $value ) {
$options[] = sprintf( '<option value="%1$s" %2$s>%1$s</option>', esc_attr( $value ), $this->selected( $value, $theme_locations ) );
}

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
printf( '<select id="%1$s" name="msls[%1$s][]" multiple="multiple">%2$s</select>', 'mslsmenu_theme_location', implode( '', $options ) );
printf( '<select id="%1$s" name="msls[%1$s][]" multiple="multiple">%2$s</select>', 'mslsmenu_theme_location', implode( '', $options ) );
}

/**
* @param string $needle
* @param mixed $locations
* @param mixed $locations
*
* @return string
*/
protected function selected( string $needle, $locations ): string {
return is_array( $locations ) ? selected( true, in_array( $needle, $locations ), false ) : '';
return is_array( $locations ) ? selected( true, in_array( $needle, $locations, true ), false ) : '';
}

/**
Expand All @@ -188,9 +188,9 @@ public function display( array $args ) {
$types = lloc\Msls\MslsLink::get_types_description();
$display = $this->options->mslsmenu_display ?? '0';

/**
* Backward compatibility
*/
/**
* Backward compatibility
*/
if ( ! class_exists( lloc\Msls\Component\Input\Select::class ) ) {
// @codeCoverageIgnoreStart

Expand All @@ -211,14 +211,14 @@ public function display( array $args ) {
* @param array $args
*/
public function input( array $args ) {
/**
* Backward compatibility
*/
/**
* Backward compatibility
*/
if ( ! class_exists( 'lloc\Msls\Component\Input\Text' ) ) {
// @codeCoverageIgnoreStart

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $args['msls_admin']->render_input( $args['mslsmenu_input'] );
echo $args['msls_admin']->render_input( $args['mslsmenu_input'] );

return;
// @codeCoverageIgnoreEnd
Expand All @@ -228,16 +228,18 @@ public function input( array $args ) {
$value = $this->options->$key ?? '';

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo ( new lloc\Msls\Component\Input\Text( $key, $value ) )->render();
echo ( new lloc\Msls\Component\Input\Text( $key, $value ) )->render();
}

}

// @codeCoverageIgnoreStart
if ( function_exists( 'add_action' ) ) {
add_action( 'plugins_loaded', function () {
$options = class_exists( lloc\Msls\MslsOptions::class ) ? lloc\Msls\MslsOptions::instance() : null;
MslsMenu::init( $options );
} );
add_action(
'plugins_loaded',
function () {
$options = class_exists( lloc\Msls\MslsOptions::class ) ? lloc\Msls\MslsOptions::instance() : null;
MslsMenu::init( $options );
}
);
}
// @codeCoverageIgnoreEnd
// @codeCoverageIgnoreEnd
28 changes: 28 additions & 0 deletions bin/githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

echo ""
echo "phpcbf pre commit hook start"

PHP_CS_FIXER="vendor/bin/phpcbf"
HAS_PHP_CS_FIXER=false

# check if php-cs-fixer is installed as a composer dependency
if [ -x "$PHP_CS_FIXER" ]; then
HAS_PHP_CS_FIXER=true
fi

if $HAS_PHP_CS_FIXER; then

# gets a list of all staged but not deleted php-files
CHANGED_FILES=$(git diff --cached --name-only --diff-filter=ACMRTUXB HEAD | grep '\.php$')

if [ ! -z "${CHANGED_FILES}" ]; then
# runs phpcbf on the changed files
vendor/bin/phpcbf -w ${CHANGED_FILES}
# adds the changed files to staging again
git add ${CHANGED_FILES}
fi
fi

echo "phpcbf pre commit hook finish"
echo ""
18 changes: 15 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,29 @@
"brain/monkey": "2.*",
"phpstan/phpstan": "^1.8",
"szepeviktor/phpstan-wordpress": "^1.1",
"phpstan/extension-installer": "^1.1"
"phpstan/extension-installer": "^1.1",
"wp-coding-standards/wpcs": "^3.0"
},
"autoload-dev": {
"files": [ "MslsMenu.php" ]
},
"scripts": {
"test": "vendor/bin/pest",
"coverage": "php -d xdebug.mode=coverage vendor/bin/pest --coverage",
"analyze": "vendor/bin/phpstan analyze",
"phpstan": "vendor/bin/phpstan analyze",
"git-release": "bin/git-release.sh",
"build": [
"@git-release"
],
"githooks": [
"if [ -e bin/githooks/pre-commit ]; then cp bin/githooks/pre-commit ./.git/hooks/; fi",
"if [ -e .git/hooks/pre-commit ]; then chmod 0755 .git/hooks/pre-commit; fi"
],
"post-install-cmd": [
"@githooks"
],
"post-update-cmd": [
"@githooks"
]
},
"authors": [
Expand All @@ -45,7 +56,8 @@
"allow-plugins": {
"composer/installers": true,
"phpstan/extension-installer": true,
"pestphp/pest-plugin": true
"pestphp/pest-plugin": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
2 changes: 1 addition & 1 deletion languages/index.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php header( 'location: http://' . filter_input( INPUT_SERVER, 'HTTP_HOST', FILTER_SANITIZE_URL ) ); ?>
<?php header( 'location: http://' . filter_input( INPUT_SERVER, 'HTTP_HOST', FILTER_SANITIZE_URL ) );
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: realloc
Donate link: http://www.greenpeace.org/international/
Tags: multilingual, multisite, language, switcher, menu
Requires at least: 5.3
Tested up to: 6.7
Tested up to: 6.8
Requires PHP: 7.4
Stable tag: 2.5.1
License: GPLv2 or later
Expand Down
Loading