Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/lingotek-translation/admin/filters-columns.php
+++ b/lingotek-translation/admin/filters-columns.php
@@ -29,9 +29,8 @@
}
/**
- * Adds languages and translations columns in posts, pages, media, categories and tags tables
- * overrides Polylang method to display all languages including the filtered one
- * as well as displaying a tooltip with the language name and locale when there is no flag
+ * Adds languages and translations columns in posts, pages, media, categories and tags tables.
+ * Inserts the Lingotek columns, then lets Polylang add its own language columns.
*
* @since 0.2
*
@@ -50,6 +49,8 @@
$this->print_word_limit_error();
$columns ['lingotek_source'] = __( 'Lingotek source', 'lingotek-translation' );
$columns ['lingotek_targets'] = __( 'Lingotek translations', 'lingotek-translation' );
+ $columns = isset( $end ) ? array_merge( $columns, $end ) : $columns;
+
$current_user_id = get_current_user_id();
$post_languages = get_user_meta( $current_user_id, 'manageedit-postcolumnshidden', true );
$page_languages = get_user_meta( $current_user_id, 'manageedit-pagecolumnshidden', true );
@@ -57,21 +58,18 @@
$page_languages = is_array( $page_languages ) ? $page_languages : array();
foreach ( $this->model->get_languages_list() as $language ) {
$language_key = 'language_' . $language->slug;
- $columns[ $language_key ] = $this->links->get_flag_html( $language ) . '<span class="screen-reader-text">' . esc_html( $language->name ) . '</span>';
- $is_pll_item = substr( $language_key, 0, 9 ) === "language_";
- if ($is_pll_item) {
- if (!in_array($language_key, $post_languages)) {
- $post_languages[] = $language_key;
- }
- if (!in_array($language_key, $page_languages)) {
- $page_languages[] = $language_key;
- }
+ if (!in_array($language_key, $post_languages)) {
+ $post_languages[] = $language_key;
+ }
+ if (!in_array($language_key, $page_languages)) {
+ $page_languages[] = $language_key;
}
}
update_user_meta($current_user_id,'manageedit-postcolumnshidden', $post_languages);
update_user_meta($current_user_id,'manageedit-pagecolumnshidden', $page_languages);
- return isset( $end ) ? array_merge( $columns, $end ) : $columns;
+ // Let Polylang add its own language (flag) columns before $before, so we don't depend on its flag API.
+ return parent::add_column( $columns, $before );
}
private function print_cancel_error() {
--- a/lingotek-translation/lingotek.php
+++ b/lingotek-translation/lingotek.php
@@ -2,7 +2,7 @@
/**
Plugin name: Ray Enterprise Translation
Plugin URI: https://lingotek.com/project/content-translation-for-wordpress-cms/
- Version: 1.7.3
+ Version: 1.7.4
Author: Ray Enterprise and Frédéric Demarle
Author uri: http://lingotek.com
Description: Ray Enterprise offers convenient cloud-based localization and translation.
@@ -23,7 +23,7 @@
}
// Plugin version (should match above meta).
-define( 'LINGOTEK_VERSION', '1.7.3' );
+define( 'LINGOTEK_VERSION', '1.7.4' );
define( 'LINGOTEK_MIN_PLL_VERSION', '1.8' );
// Plugin name as known by WordPress.
define( 'LINGOTEK_BASENAME', plugin_basename( __FILE__ ) );
--- a/lingotek-translation/tests/bootstrap.php
+++ b/lingotek-translation/tests/bootstrap.php
@@ -1,45 +0,0 @@
-<?php
-/**
- * PHPUnit bootstrap file.
- *
- * @package Lingotek_Translation
- */
-
-$_tests_dir = getenv( 'WP_TESTS_DIR' );
-
-if ( ! $_tests_dir ) {
- $_tests_dir = rtrim( sys_get_temp_dir(), '/\' ) . '/wordpress-tests-lib';
-}
-
-if ( ! file_exists( "{$_tests_dir}/includes/functions.php" ) ) {
- echo "Could not find {$_tests_dir}/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL;
- exit( 1 );
-}
-
-require_once "{$_tests_dir}/includes/functions.php";
-
-/**
- * Manually load Polylang and the plugin being tested.
- */
-function _manually_load_plugin() {
- $polylang_dir = getenv( 'POLYLANG_DIR' );
-
- if ( ! $polylang_dir ) {
- $polylang_dir = WP_PLUGIN_DIR . '/polylang';
- }
-
- if ( file_exists( $polylang_dir . '/polylang.php' ) ) {
- require_once $polylang_dir . '/polylang.php';
- }
-
- require dirname( dirname( __FILE__ ) ) . '/lingotek.php';
-}
-
-tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
-
-$GLOBALS['wp_tests_options'] = array(
- 'active_plugins' => array( 'polylang/polylang.php', 'lingotek-translation/lingotek.php' ),
-);
-
-require "{$_tests_dir}/includes/bootstrap.php";
-
--- a/lingotek-translation/tests/test-action-url.php
+++ b/lingotek-translation/tests/test-action-url.php
@@ -1,43 +0,0 @@
-<?php
-/**
- * Class ActionUrlTest
- *
- * @package Lingotek_Translation
- */
-
-/**
- * Sample test case.
- */
-class ActionUrlTest extends WP_UnitTestCase {
-
- /**
- * Tests the rendering of an action url.
- *
- * @test
- * @dataProvider actionsDataProvider
- *
- * @param string $url The url.
- * @param string $title The title.
- * @param string $expected The expected html.
- */
- public function SecondaryActionIsRendered( $url, $title, $expected ) {
- $action = new Lingotek_Action_Url( $url, $title );
- $this->assertSame( $url, $action->getUri() );
- $this->assertSame( $title, $action->getTitle() );
- $this->assertXmlStringEqualsXmlString( $expected, $action->render() );
- }
-
- /**
- * Data provider for actions.
- *
- * @see ::SecondaryActionIsRendered
- */
- public function actionsDataProvider() {
- yield 'secondary action' => array(
- 'https://www.lingotek.com',
- 'Lingotek website',
- '<li><a href="https://www.lingotek.com">Lingotek website</a></li>',
- );
- }
-
-}
--- a/lingotek-translation/tests/test-lingotek-installation.php
+++ b/lingotek-translation/tests/test-lingotek-installation.php
@@ -1,86 +0,0 @@
-<?php
-/**
- * Class LingotekInstallationTest
- *
- * @package Lingotek_Translation
- */
-
-/**
- * Sample test case.
- */
-class LingotekInstallationTest extends WP_UnitTestCase {
-
- /**
- * Tests the initial options are set on activation.
- *
- * @test
- * @dataProvider getInitialOptions
- *
- * @param string $option The option name.
- * @param mixed $value The expected value.
- */
- public function InitialOptionsAreSet( $option, $value ) {
- $this->ltk = new Lingotek();
- $this->ltk->activate();
-
- $this->assertSame( $value, get_option( $option ) );
- }
-
- /**
- * Tests the initial profiles are created on activation.
- *
- * @test
- */
- public function InitialProfilesAreCreated() {
- $this->ltk = new Lingotek();
- $this->ltk->activate();
-
- $profiles = get_option( 'lingotek_profiles', false );
-
- $this->assertEquals( 3, count( $profiles ) );
- $this->assertTrue( isset( $profiles['automatic'] ) );
- $this->assertTrue( isset( $profiles['manual'] ) );
- $this->assertTrue( isset( $profiles['disabled'] ) );
- }
-
- /**
- * Data provider for initial options values.
- *
- * @see ::InitialOptionsAreSet
- */
- public function getInitialOptions() {
- yield 'lingotek_plugin_version' => array( 'lingotek_plugin_version', LINGOTEK_VERSION );
- yield 'lingotek_profiles' => array(
- 'lingotek_profiles',
- array(
- 'automatic' => array(
- 'profile' => 'automatic',
- 'name' => 'Automatic',
- 'upload' => 'automatic',
- 'download' => 'automatic',
- ),
- 'manual' => array(
- 'profile' => 'manual',
- 'name' => 'Manual',
- 'upload' => 'manual',
- 'download' => 'manual',
- ),
- 'disabled' => array(
- 'profile' => 'disabled',
- 'name' => 'Disabled',
- ),
- ),
- );
- }
-
- /**
- * Helper function for outputting data while running tests (debug purposes).
- *
- * @param mixed $data The data to be logged.
- */
- public function log( $data ) {
- // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export,WordPress.WP.AlternativeFunctions.file_system_read_fwrite
- fwrite( STDERR, var_export( $data, true ) );
- }
-
-}
--- a/lingotek-translation/tests/test-polylang-admin-columns.php
+++ b/lingotek-translation/tests/test-polylang-admin-columns.php
@@ -1,105 +0,0 @@
-<?php
-/**
- * Behavioral regression tests for Lingotek_Filters_Columns.
- *
- * Verifies that the overridden column methods preserve the parent
- * contract expected by Polylang and WordPress list-table rendering.
- *
- * @package Lingotek_Translation
- */
-
-class PolylangAdminColumnsTest extends WP_UnitTestCase {
-
- /**
- * add_column must return an array containing Lingotek columns
- * without corrupting inherited columns.
- *
- * @test
- */
- public function add_column_returns_array_with_lingotek_columns() {
- if ( ! class_exists( 'Lingotek_Filters_Columns' ) ) {
- $this->markTestSkipped( 'Lingotek_Filters_Columns not available.' );
- }
-
- $user_id = self::factory()->user->create();
- wp_set_current_user( $user_id );
-
- $ref = new ReflectionMethod( 'Lingotek_Filters_Columns', 'add_column' );
- $ref->setAccessible( true );
-
- $polylang = isset( $GLOBALS['polylang'] ) ? $GLOBALS['polylang'] : null;
- if ( ! $polylang ) {
- $this->markTestSkipped( 'Polylang global not initialized.' );
- }
-
- $instance = new Lingotek_Filters_Columns( $polylang );
- $columns = array(
- 'cb' => '<input type="checkbox" />',
- 'title' => 'Title',
- 'date' => 'Date',
- );
-
- $result = $ref->invoke( $instance, $columns, 'date' );
-
- $this->assertIsArray( $result, 'add_column must return an array.' );
- $this->assertArrayHasKey( 'lingotek_source', $result );
- $this->assertArrayHasKey( 'lingotek_targets', $result );
- $this->assertArrayHasKey( 'cb', $result, 'Pre-existing columns must be preserved.' );
- $this->assertArrayHasKey( 'title', $result, 'Pre-existing columns must be preserved.' );
- $this->assertArrayHasKey( 'date', $result, 'Columns after $before must be preserved.' );
-
- $languages = PLL()->model->get_languages_list();
- if ( empty( $languages ) ) {
- $this->markTestSkipped( 'No Polylang languages configured.' );
- }
-
- $language = reset( $languages );
- $this->assertArrayHasKey(
- 'language_' . $language->slug,
- $result,
- 'Language columns must use Polylang slugs.'
- );
-
- if ( $language->locale !== $language->slug ) {
- $this->assertArrayNotHasKey(
- 'language_' . $language->locale,
- $result,
- 'Language columns must not use Polylang locales.'
- );
- }
-
- $post_hidden_columns = get_user_meta( $user_id, 'manageedit-postcolumnshidden', true );
- $page_hidden_columns = get_user_meta( $user_id, 'manageedit-pagecolumnshidden', true );
-
- $this->assertIsArray( $post_hidden_columns );
- $this->assertIsArray( $page_hidden_columns );
- $this->assertContains( 'language_' . $language->slug, $post_hidden_columns );
- $this->assertContains( 'language_' . $language->slug, $page_hidden_columns );
- }
-
- /**
- * term_column must return $custom_data for non-language columns
- * instead of returning null.
- *
- * @test
- */
- public function term_column_returns_custom_data_for_non_language_column() {
- if ( ! class_exists( 'Lingotek_Filters_Columns' ) ) {
- $this->markTestSkipped( 'Lingotek_Filters_Columns not available.' );
- }
-
- $polylang = isset( $GLOBALS['polylang'] ) ? $GLOBALS['polylang'] : null;
- if ( ! $polylang ) {
- $this->markTestSkipped( 'Polylang global not initialized.' );
- }
-
- $instance = new Lingotek_Filters_Columns( $polylang );
-
- $result = $instance->term_column( 'existing_data', 'name', 1 );
- $this->assertSame(
- 'existing_data',
- $result,
- 'term_column must pass through $custom_data for non-language columns.'
- );
- }
-}
--- a/lingotek-translation/tests/test-polylang-filters-term.php
+++ b/lingotek-translation/tests/test-polylang-filters-term.php
@@ -1,154 +0,0 @@
-<?php
-/**
- * Regression tests for Lingotek_Filters_Term compatibility behavior.
- *
- * @package Lingotek_Translation
- */
-
-class Lingotek_Filters_Term_Document_Fake {
- public $pre_save_terms_calls = array();
-
- public function pre_save_terms( $term_id, $taxonomy, $language ) {
- $this->pre_save_terms_calls[] = array(
- 'term_id' => $term_id,
- 'taxonomy' => $taxonomy,
- 'language' => $language,
- );
- }
-}
-
-class Lingotek_Filters_Term_Lgtm_Fake {
- public $document;
- public $upload_calls = array();
- public $can_upload = true;
-
- public function __construct( $document ) {
- $this->document = $document;
- }
-
- public function get_group( $type, $term_id ) {
- return $this->document;
- }
-
- public function can_upload( $type, $term_id ) {
- return $this->can_upload;
- }
-
- public function upload_term( $term_id, $taxonomy ) {
- $this->upload_calls[] = array(
- 'term_id' => $term_id,
- 'taxonomy' => $taxonomy,
- );
- }
-}
-
-class Lingotek_Filters_Term_Test_Double extends Lingotek_Filters_Term {
- public $force_import_request = false;
- public $force_should_autoupload = false;
- public $saved_parent_calls = array();
-
- public function __construct() {}
-
- protected function is_import_request() {
- return $this->force_import_request;
- }
-
- protected function save_parent_term( $term_id, $tt_id, $taxonomy ) {
- $this->saved_parent_calls[] = array(
- 'term_id' => $term_id,
- 'tt_id' => $tt_id,
- 'taxonomy' => $taxonomy,
- );
- }
-
- protected function should_auto_upload_term( $taxonomy, $term_id ) {
- return $this->force_should_autoupload;
- }
-}
-
-class PolylangFiltersTermTest extends WP_UnitTestCase {
- private function set_object_property( $object, $property_name, $value ) {
- $reflection = new ReflectionClass( $object );
-
- while ( $reflection ) {
- if ( $reflection->hasProperty( $property_name ) ) {
- $property = $reflection->getProperty( $property_name );
- $property->setAccessible( true );
- $property->setValue( $object, $value );
- return;
- }
- $reflection = $reflection->getParentClass();
- }
-
- $this->fail( "Property {$property_name} was not found." );
- }
-
- private function create_translated_category_term() {
- if ( ! isset( $GLOBALS['polylang'] ) ) {
- $this->markTestSkipped( 'Polylang global not initialized.' );
- }
-
- $languages = PLL()->model->get_languages_list();
- if ( empty( $languages ) ) {
- $this->markTestSkipped( 'No Polylang languages configured.' );
- }
-
- $language = reset( $languages );
- $term_id = self::factory()->term->create(
- array(
- 'taxonomy' => 'category',
- 'name' => 'Lingotek term ' . wp_generate_password( 8, false ),
- )
- );
-
- PLL()->model->term->set_language( $term_id, $language );
-
- return array( $term_id, $language );
- }
-
- /**
- * @test
- */
- public function save_term_skips_parent_save_and_upload_during_import_requests() {
- list( $term_id ) = $this->create_translated_category_term();
-
- $document = new Lingotek_Filters_Term_Document_Fake();
- $lgtm = new Lingotek_Filters_Term_Lgtm_Fake( $document );
- $subject = new Lingotek_Filters_Term_Test_Double();
-
- $this->set_object_property( $subject, 'model', PLL()->model );
- $subject->lgtm = $lgtm;
- $subject->force_import_request = true;
- $subject->force_should_autoupload = true;
-
- $subject->save_term( $term_id, 0, 'category' );
-
- $this->assertCount( 1, $document->pre_save_terms_calls );
- $this->assertSame( array(), $subject->saved_parent_calls );
- $this->assertSame( array(), $lgtm->upload_calls );
- }
-
- /**
- * @test
- */
- public function save_term_calls_parent_save_and_upload_when_not_importing() {
- list( $term_id ) = $this->create_translated_category_term();
-
- $document = new Lingotek_Filters_Term_Document_Fake();
- $lgtm = new Lingotek_Filters_Term_Lgtm_Fake( $document );
- $subject = new Lingotek_Filters_Term_Test_Double();
-
- $this->set_object_property( $subject, 'model', PLL()->model );
- $subject->lgtm = $lgtm;
- $subject->force_import_request = false;
- $subject->force_should_autoupload = true;
-
- $subject->save_term( $term_id, 0, 'category' );
-
- $this->assertCount( 1, $document->pre_save_terms_calls );
- $this->assertCount( 1, $subject->saved_parent_calls );
- $this->assertCount( 1, $lgtm->upload_calls );
- $this->assertSame( $term_id, $lgtm->upload_calls[0]['term_id'] );
- $this->assertSame( 'category', $lgtm->upload_calls[0]['taxonomy'] );
- }
-}
--- a/lingotek-translation/tests/test-polylang-signature-compat.php
+++ b/lingotek-translation/tests/test-polylang-signature-compat.php
@@ -1,119 +0,0 @@
-<?php
-/**
- * Regression tests: Polylang parent/child method signature compatibility.
- *
- * Uses PHP Reflection to verify that every overridden method in Lingotek
- * admin classes declares the same parameter types and return types as the
- * Polylang parent it extends. A mismatch here means a PHP 8 fatal.
- *
- * @package Lingotek_Translation
- */
-
-class PolylangSignatureCompatTest extends WP_UnitTestCase {
-
- /**
- * Verify Polylang is available in the test environment.
- *
- * @test
- */
- public function polylang_is_loaded_in_test_environment() {
- $this->assertTrue(
- class_exists( 'PLL_Admin_Filters_Columns' ),
- 'Polylang must be loaded for signature-compat tests to be meaningful.'
- );
- }
-
- /**
- * @test
- * @dataProvider signaturePairsProvider
- *
- * @param string $parent_class Fully-qualified parent class name.
- * @param string $child_class Fully-qualified child class name.
- * @param string $method Method name to compare.
- */
- public function child_method_signature_matches_parent( $parent_class, $child_class, $method ) {
- if ( ! class_exists( $parent_class ) || ! class_exists( $child_class ) ) {
- $this->markTestSkipped( "Skipping: $parent_class or $child_class not available." );
- }
-
- $parent_ref = new ReflectionMethod( $parent_class, $method );
- $child_ref = new ReflectionMethod( $child_class, $method );
-
- $this->assertSame(
- (string) $parent_ref->getReturnType(),
- (string) $child_ref->getReturnType(),
- "Return type of $child_class::$method must match $parent_class::$method"
- );
-
- $parent_params = $parent_ref->getParameters();
- $child_params = $child_ref->getParameters();
-
- $this->assertSame(
- count( $parent_params ),
- count( $child_params ),
- "Parameter count of $child_class::$method must match $parent_class::$method"
- );
-
- foreach ( $parent_params as $i => $parent_param ) {
- $parent_type = (string) $parent_param->getType();
- $child_type = (string) $child_params[ $i ]->getType();
- if ( '' === $parent_type ) {
- continue;
- }
- $this->assertSame(
- $parent_type,
- $child_type,
- "Parameter #{$i} type of $child_class::$method must match $parent_class::$method"
- );
- }
- }
-
- /**
- * Provides parent/child/method triples for signature comparison.
- *
- * @return Generator
- */
- public function signaturePairsProvider() {
- yield 'add_column' => array(
- 'PLL_Admin_Filters_Columns',
- 'Lingotek_Filters_Columns',
- 'add_column',
- );
-
- yield 'post_column' => array(
- 'PLL_Admin_Filters_Columns',
- 'Lingotek_Filters_Columns',
- 'post_column',
- );
-
- yield 'save_post' => array(
- 'PLL_CRUD_Posts',
- 'Lingotek_Filters_Post',
- 'save_post',
- );
-
- yield 'save_term' => array(
- 'PLL_Admin_Filters_Term',
- 'Lingotek_Filters_Term',
- 'save_term',
- );
-
- yield 'column_translations' => array(
- 'PLL_Table_String',
- 'Lingotek_Table_String',
- 'column_translations',
- );
-
- yield 'prepare_items' => array(
- 'PLL_Table_String',
- 'Lingotek_Table_String',
- 'prepare_items',
- );
-
- yield 'process_posts' => array(
- 'PLL_WP_Import',
- 'Lingotek_WP_Import',
- 'process_posts',
- );
- }
-}
--- a/lingotek-translation/tests/test-polylang-table-string.php
+++ b/lingotek-translation/tests/test-polylang-table-string.php
@@ -1,97 +0,0 @@
-<?php
-/**
- * Regression tests for Lingotek_Table_String Polylang compatibility.
- *
- * Verifies that column_translations works with both the old array-based
- * and modern object-based Languages model introduced in Polylang 3.8.
- *
- * @package Lingotek_Translation
- */
-
-class PolylangTableStringTest extends WP_UnitTestCase {
-
- /**
- * column_translations must render language labels from the modern
- * Polylang Languages model object.
- *
- * @test
- */
- public function column_translations_handles_modern_languages_model() {
- if ( ! class_exists( 'PLL_Table_String' ) || ! class_exists( 'Lingotek_Table_String' ) ) {
- $this->markTestSkipped( 'PLL_Table_String or Lingotek_Table_String not available.' );
- }
-
- if ( ! isset( $GLOBALS['polylang'] ) || ! isset( PLL()->model->languages ) ) {
- $this->markTestSkipped( 'Polylang languages model not available.' );
- }
-
- $languages = PLL()->model->get_languages_list();
- if ( empty( $languages ) ) {
- $this->markTestSkipped( 'No Polylang languages configured.' );
- }
-
- $language = reset( $languages );
- $table = new Lingotek_Table_String( PLL()->model->languages );
- $output = $table->column_translations(
- array(
- 'translations' => array(
- $language->slug => 'Bonjour',
- ),
- 'multiline' => false,
- 'row' => 1,
- )
- );
-
- $this->assertIsString( $output );
- $this->assertStringContainsString( esc_html( $language->name ), $output );
- $this->assertStringContainsString( 'Bonjour', $output );
- }
-
- /**
- * prepare_items must delegate to the current Polylang implementation
- * using the modern Languages object and populate table items.
- *
- * @test
- */
- public function prepare_items_uses_current_polylang_table_implementation() {
- if ( ! class_exists( 'PLL_Table_String' ) || ! class_exists( 'Lingotek_Table_String' ) ) {
- $this->markTestSkipped( 'PLL_Table_String or Lingotek_Table_String not available.' );
- }
-
- if ( ! isset( $GLOBALS['polylang'] ) || ! isset( PLL()->model->languages ) ) {
- $this->markTestSkipped( 'Polylang languages model not available.' );
- }
-
- $table = new Lingotek_Table_String( PLL()->model->languages );
- $table->prepare_items();
-
- $method = new ReflectionMethod( 'Lingotek_Table_String', 'prepare_items' );
- $this->assertSame( 'PLL_Table_String', $method->getDeclaringClass()->getName() );
- $this->assertIsArray( $table->items );
- }
-
- /**
- * Lingotek_Model constructor must not fatal when $GLOBALS['polylang']
- * is not yet initialized (early load path).
- *
- * @test
- */
- public function lingotek_model_constructor_degrades_gracefully_without_polylang() {
- if ( ! class_exists( 'Lingotek_Model' ) ) {
- $this->markTestSkipped( 'Lingotek_Model not available.' );
- }
-
- $saved = isset( $GLOBALS['polylang'] ) ? $GLOBALS['polylang'] : null;
- unset( $GLOBALS['polylang'] );
-
- $model = new Lingotek_Model();
- $this->assertNull(
- $model->pllm,
- 'pllm must be null when Polylang is not available.'
- );
-
- if ( null !== $saved ) {
- $GLOBALS['polylang'] = $saved;
- }
- }
-}