diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5654b105..2475e6f0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,6 +7,11 @@ jobs: tag: name: New tag runs-on: ubuntu-latest + permissions: + id-token: write + contents: read + attestations: write + timeout-minutes: 70 steps: - name: Checkout project uses: actions/checkout@v4 @@ -16,7 +21,14 @@ jobs: run: composer run-script build - name: WordPress Plugin Deploy uses: 10up/action-wordpress-plugin-deploy@stable + id: deploy env: SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} SVN_USERNAME: ${{ secrets.SVN_USERNAME }} SLUG: multisite-language-switcher + with: + generate-zip: true + - name: Attest build provenance + uses: johnbillion/action-wordpress-plugin-attestation@0.5.0 + with: + zip-path: ${{ steps.deploy.outputs.zip-path }} \ No newline at end of file diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 3ceec70b..00000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,13 +0,0 @@ -filter: - excluded_paths: [tests/*, bin/*] - -tools: - js_hint: true - - php_mess_detector: true - php_analyzer: true - php_cpd: true - php_pdepend: true - php_code_sniffer: - config: - standard: "WordPress" \ No newline at end of file diff --git a/README.md b/README.md index 1ce59959..8df4082f 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,16 @@ A simple, powerful, and user-friendly plugin that adds multilingual support to your [WordPress multisite](https://wordpress.org/documentation/article/create-a-network/) installation, whether using multiple subdomains or folders. Multisite Language Switcher allows you to effortlessly manage translations for posts, pages, custom post types, categories, tags, and custom taxonomies. -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lloc/Multisite-Language-Switcher/badges/quality-score.png?s=a2e5dbac2690bbd427f2d48b84473482e7e24fdb)](https://scrutinizer-ci.com/g/lloc/Multisite-Language-Switcher/) -[![codecov](https://codecov.io/gh/lloc/Multisite-Language-Switcher/graph/badge.svg?token=IlD4bX4KZ4)](https://codecov.io/gh/lloc/Multisite-Language-Switcher) +[![WordPress Plugin Version](https://img.shields.io/wordpress/plugin/v/multisite-language-switcher.svg)](https://wordpress.org/plugins/multisite-language-switcher/) +[![License](https://img.shields.io/badge/license-GPL_v2%2B-blue.svg)](http://opensource.org/licenses/GPL-2.0) +[![WordPress Tested](https://img.shields.io/wordpress/v/multisite-language-switcher.svg)](https://wordpress.org/plugins/multisite-language-switcher/) +[![codecov](https://codecov.io/gh/lloc/Multisite-Language-Switcher/graph/badge.svg?token=IlD4bX4KZ4)](https://codecov.io/gh/lloc/Multisite-Language-Switcher) ## Where to get the plugin [Download](http://downloads.wordpress.org/plugin/multisite-language-switcher.zip) the latest stable from the [WordPress Plugin Directory](https://wordpress.org/plugins/multisite-language-switcher/), and please remember to give this plugin [a five-star rating](https://wordpress.org/support/plugin/multisite-language-switcher/reviews/#new-post). -_Please note that the version of Multisite Language Switcher on GitHub is a work in progress._ +_Please note that while the master branch on GitHub is intended to be stable, it is not recommended for production use. Instead, please use the [official releases](https://github.com/lloc/Multisite-Language-Switcher/releases) for deployment._ If you plan to use the GitHub repository on a server, don't forget to run `composer install --no-dev`. diff --git a/composer.json b/composer.json index 58122d8f..eb53da85 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ }, "scripts": { "test": "vendor/bin/phpunit", - "coverage": "php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html tests/coverage", + "coverage": "@php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html tests/coverage", "analyze": "vendor/bin/phpstan analyze", "playwright": "npx playwright test", "php74": "phpcs -p ./*.php includes/ --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 7.4", diff --git a/includes/ContentImport/Importers/Importer.php b/includes/ContentImport/Importers/Importer.php index b81d222b..0714701a 100644 --- a/includes/ContentImport/Importers/Importer.php +++ b/includes/ContentImport/Importers/Importer.php @@ -9,9 +9,9 @@ interface Importer { /** - * @param array $data + * @param array $data * - * @return array + * @return array */ public function import( array $data ); diff --git a/includes/ContentImport/Importers/PostMeta/Duplicating.php b/includes/ContentImport/Importers/PostMeta/Duplicating.php index fbdc7c37..997e17ac 100644 --- a/includes/ContentImport/Importers/PostMeta/Duplicating.php +++ b/includes/ContentImport/Importers/PostMeta/Duplicating.php @@ -22,6 +22,11 @@ public static function info() { ); } + /** + * @param array $data + * + * @return array + */ public function import( array $data ) { $source_blog_id = $this->import_coordinates->source_blog_id; $source_post_id = $this->import_coordinates->source_post_id; diff --git a/includes/ContentImport/Importers/PostThumbnail/Linking.php b/includes/ContentImport/Importers/PostThumbnail/Linking.php index 32cbdcdd..54a1cba9 100644 --- a/includes/ContentImport/Importers/PostThumbnail/Linking.php +++ b/includes/ContentImport/Importers/PostThumbnail/Linking.php @@ -32,6 +32,11 @@ public static function info() { ); } + /** + * @param array $data + * + * @return array + */ public function import( array $data ) { $source_blog_id = $this->import_coordinates->source_blog_id; $source_post_id = $this->import_coordinates->source_post_id; @@ -142,7 +147,7 @@ function ( &$entry ) { /** * @param int $source_post_thumbnail_id * - * @return array + * @return array */ protected function get_attachment_meta( $source_post_thumbnail_id ) { $keys = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_attachment_image_alt' ); diff --git a/includes/ContentImport/LogWriters/AdminNoticeLogger.php b/includes/ContentImport/LogWriters/AdminNoticeLogger.php index 2fe55013..bbbd7691 100644 --- a/includes/ContentImport/LogWriters/AdminNoticeLogger.php +++ b/includes/ContentImport/LogWriters/AdminNoticeLogger.php @@ -15,6 +15,11 @@ class AdminNoticeLogger extends MslsRegistryInstance implements LogWriter { */ protected $import_coordinates; + /** + * @param array $data + * + * @return void + */ public function write( array $data ) { /* translators: %1$d: source post ID, %2$d: source blog ID, %3$d: destination post ID, %4$d: destination blog ID */ $format = esc_html__( 'From post %1$d on site %2$d to post %3$d on site %4$d', 'multisite-language-switcher' ); @@ -108,9 +113,9 @@ public function write( array $data ) { } /** - * @param string $section_title - * @param array $entries - * @param bool $escape_entries + * @param string $section_title + * @param string[] $entries + * @param bool $escape_entries * * @return string */ diff --git a/includes/ContentImport/LogWriters/LogWriter.php b/includes/ContentImport/LogWriters/LogWriter.php index be60e683..6fd2ab24 100644 --- a/includes/ContentImport/LogWriters/LogWriter.php +++ b/includes/ContentImport/LogWriters/LogWriter.php @@ -2,14 +2,13 @@ namespace lloc\Msls\ContentImport\LogWriters; - interface LogWriter { /** * Writes the log to the destination. * - * @param array $data An array of data to log. + * @param array $data An array of data to log. * * @return mixed */ public function write( array $data ); -} \ No newline at end of file +} diff --git a/includes/ContentImport/MetaBox.php b/includes/ContentImport/MetaBox.php index 0e527363..2365d794 100644 --- a/includes/ContentImport/MetaBox.php +++ b/includes/ContentImport/MetaBox.php @@ -14,6 +14,9 @@ class MetaBox extends MslsRegistryInstance { + /** + * @var array + */ protected array $data = array(); /** @@ -90,6 +93,11 @@ function ( $lang ) use ( $mydata ) { echo wp_kses( $output, Component::get_allowed_html() ); } + /** + * @param array $data + * + * @return string + */ protected function inline_thickbox_url( array $data = array() ): string { $args = array_merge( array( @@ -111,6 +119,12 @@ public function print_modal_html(): void { echo $this->inline_thickbox_html( true, $this->data ); } + /** + * @param bool $echo + * @param array $data + * + * @return string + */ protected function inline_thickbox_html( $echo = true, array $data = array() ): string { if ( ! isset( $data['msls_import'] ) ) { return ''; diff --git a/includes/ContentImport/Relations.php b/includes/ContentImport/Relations.php index c7bcea1e..edde05fd 100644 --- a/includes/ContentImport/Relations.php +++ b/includes/ContentImport/Relations.php @@ -13,8 +13,14 @@ */ class Relations { + /** + * @var array> + */ public array $to_create = array(); + /** + * @var array> + */ protected array $local_options = array(); /** @@ -45,7 +51,7 @@ public function merge( Relations $relations = null ): void { } /** - * @return array + * @return array> */ public function get_data(): array { return $this->to_create; diff --git a/includes/MslsAdmin.php b/includes/MslsAdmin.php index a705c7fa..0aea0e51 100644 --- a/includes/MslsAdmin.php +++ b/includes/MslsAdmin.php @@ -124,7 +124,7 @@ public function __call( $method, $args ) { /** * There is something wrong? Here comes the message... * - * @return bool + * @return void */ public function has_problems(): void { $message = ''; @@ -381,11 +381,12 @@ public function reference_user(): void { /* translators: %s: maximum number of users */ $format = __( - 'Multisite Language Switcher: Collection for reference user has been truncated because it exceeded the maximum of %s users. Please, use the hook "msls_reference_users" to filter the result before!', + 'Multisite Language Switcher: Collection for reference user has been truncated because it exceeded the maximum of %d users. Please, use the hook "msls_reference_users" to filter the result before!', 'multisite-language-switcher' ); - trigger_error( sprintf( esc_html( $format ), esc_attr( self::MAX_REFERENCE_USERS ) ) ); + // phpcs:ignore WordPress.Security.EscapeOutput + trigger_error( sprintf( esc_html( $format ), strval( self::MAX_REFERENCE_USERS ) ) ); } // phpcs:ignore WordPress.Security.EscapeOutput diff --git a/includes/MslsPostTag.php b/includes/MslsPostTag.php index cc444b4e..0c508481 100644 --- a/includes/MslsPostTag.php +++ b/includes/MslsPostTag.php @@ -106,9 +106,9 @@ public function add_input( string $taxonomy ): void { '; - $item_format = ' - - '; + $item_format = ' + + '; echo '
'; $this->the_input( null, $title_format, $item_format ); @@ -138,11 +138,11 @@ public function edit_input( \WP_Term $tag, string $taxonomy ): void { $item_format = ' - + - - + + '; @@ -195,11 +195,17 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo } } - echo wp_kses( - sprintf( $item_format, esc_attr( $blog->userblog_id ), $icon, esc_attr( $language ), esc_attr( $value ), esc_attr( $title ) ), - $allowed_html + $content = sprintf( + $item_format, + $blog->userblog_id, + $icon, + esc_attr( $language ), + esc_attr( $value ), + esc_attr( $title ) ); + echo wp_kses( $content, $allowed_html ); + restore_current_blog(); } diff --git a/includes/MslsPostTagClassic.php b/includes/MslsPostTagClassic.php index d8a83017..01b94bcc 100644 --- a/includes/MslsPostTagClassic.php +++ b/includes/MslsPostTagClassic.php @@ -131,11 +131,12 @@ public function print_option( MslsBlog $blog, string $type, MslsOptionsTax $myda 'hide_empty' => false, ) ); - if ( ! empty( $terms ) ) { + + if ( is_array( $terms ) ) { foreach ( $terms as $term ) { $options .= sprintf( - '', - esc_attr( $term->term_id ), + '', + $term->term_id, selected( $term->term_id, $mydata->$language, false ), esc_html( $term->name ) ); diff --git a/tests/phpunit/TestMslsPostTag.php b/tests/phpunit/TestMslsPostTag.php index 33c27399..b638885f 100644 --- a/tests/phpunit/TestMslsPostTag.php +++ b/tests/phpunit/TestMslsPostTag.php @@ -86,7 +86,7 @@ public function test_suggest(): void { public function test_edit_input(): void { $taxonomy = \Mockery::mock( MslsTaxonomy::class ); - $taxonomy->shouldReceive( 'is_taxonomy' )->atLeast()->once()->andReturnTrue(); + $taxonomy->shouldReceive( 'is_taxonomy' )->atLeast()->once()->andReturn( true ); $taxonomy->shouldReceive( 'get_request' )->atLeast()->once()->andReturn( 'post' ); $taxonomy->shouldReceive( 'acl_request' )->atLeast()->once()->andReturn( array( 'taxonomy', 'post_tag' ) ); @@ -112,19 +112,19 @@ public function test_edit_input(): void { - + - - + + - + - - + + '; @@ -155,11 +155,11 @@ public function test_add_input(): void { $output = '

Multisite Language Switcher

- - - - -
'; + + + + +
'; $this->expectOutputString( $output );