Skip to content

Commit ffd3fea

Browse files
committed
Fixes for wasm
1 parent 55c1d90 commit ffd3fea

File tree

2 files changed

+4
-50
lines changed

2 files changed

+4
-50
lines changed

gp-includes/inline-translation.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ public function __construct() {
104104
add_action( 'ngettext', array( $this, 'ntranslate' ), 10, 5 );
105105
add_action( 'ngettext_with_context', array( $this, 'ntranslate_with_context' ), 10, 6 );
106106
add_action( 'wp_footer', array( $this, 'load_translator' ), 1000 );
107-
add_action( 'gp_footer', array( $this, 'load_translator' ), 1000 );
108107
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
109108

110109
add_action( 'admin_footer', array( $this, 'load_admin_translator' ), 1000 );
@@ -421,7 +420,7 @@ private function get_translation( $projects, $translation_sets, $original, $cont
421420
)
422421
);
423422

424-
if ( $translation !== $entry->singular ) {
423+
if ( $translation !== $entry->singular && isset( $translation_sets[ $project->id ] ) && is_object( $translation_sets[ $project->id ] ) ) {
425424
$translation_record = GP::$translation->create(
426425
array(
427426
'original_id' => $original_record->id,
@@ -537,8 +536,9 @@ public function load_translator( $locale_code = null ) {
537536
<input id="gp-inline-search" type="text" placeholder="<?php esc_attr_e( 'Search string', 'GlotPress' ); ?>"/>
538537
<ul>
539538
<?php
539+
540540
foreach ( $this->get_translations( GP_Locales::by_field( 'wp_locale', $locale_code ) ) as $translation ) {
541-
if ( is_array( $translation ) ) {
541+
if ( 1 * 1 || is_array( $translation ) ) {
542542
continue;
543543
}
544544
echo '<li>';

gp-includes/rest-api.php

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -245,52 +245,6 @@ public function save_translation( \WP_REST_Request $request ) {
245245
return $output;
246246
}
247247

248-
/**
249-
* A slightly modified version og GP_Original->by_project_id_and_entry without the BINARY search keyword
250-
* to make sure the index on the gp_originals table is used
251-
*
252-
* @param int $project_id The project id.
253-
* @param object $entry The entry.
254-
* @param string $status The status.
255-
*
256-
* @return array|null The original entry.
257-
*/
258-
private function by_project_id_and_entry( $project_id, $entry, $status = '+active' ) {
259-
global $wpdb;
260-
261-
$entry->plural = isset( $entry->plural ) ? $entry->plural : null;
262-
$entry->context = isset( $entry->context ) ? $entry->context : null;
263-
264-
$where = array();
265-
266-
$where[] = is_null( $entry->context ) ? '(context IS NULL OR %s IS NULL)' : 'context = %s';
267-
$where[] = 'singular = %s';
268-
$where[] = is_null( $entry->plural ) ? '(plural IS NULL OR %s IS NULL)' : 'plural = %s';
269-
$where[] = 'project_id = %d';
270-
$where[] = $wpdb->prepare( 'status = %s', $status );
271-
272-
$where = implode( ' AND ', $where );
273-
274-
$query = "SELECT * FROM $wpdb->gp_originals WHERE $where";
275-
$result = GP::$original->one( $query, $entry->context, $entry->singular, $entry->plural, $project_id );
276-
if ( ! $result ) {
277-
return null;
278-
}
279-
// We want case sensitive matching but this can't be done with MySQL while continuing to use the index therefore we do an additional check here.
280-
if ( $result->singular === $entry->singular ) {
281-
return $result;
282-
}
283-
284-
// We then get the whole result set here and check each entry manually.
285-
$results = GP::$original->many( $query . ' AND id != %d', $entry->context, $entry->singular, $entry->plural, $project_id, $result->id );
286-
foreach ( $results as $result ) {
287-
if ( $result->singular === $entry->singular ) {
288-
return $result;
289-
}
290-
}
291-
292-
return null;
293-
}
294248
/**
295249
* Gets translations by title.
296250
*
@@ -379,7 +333,7 @@ public function get_translations_by_originals( \WP_REST_Request $request ) {
379333
$checked_originals[ $key ] = true;
380334

381335
foreach ( $translation_sets[ $text_domain ] as $project_id => $translation_set ) {
382-
$original_record = $this->by_project_id_and_entry( $project_id, $original );
336+
$original_record = GP_Original::by_project_id_and_entry( $project_id, $original );
383337
if ( ! $original_record ) {
384338
continue;
385339
}

0 commit comments

Comments
 (0)