Skip to content
Open
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ If you really like what we do or want to thank us for our quick work, feel free

## Changelog

* Version 1.1.6 :
* On editor load, query only the current post and not all posts, if one is selected.
* Replace big query (1000) posts by only 100 posts.
* Use Choices.js to enable search on select, load only searched posts.
* Version 1.1.5 :
* Allow to customize query_var and rewrite keyword
* Security, add some missing sanitizing
Expand Down
81 changes: 45 additions & 36 deletions inc/class.admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,23 @@ public function addRessources( $hook_suffix = '' ) {
( 'post.php' === $hook_suffix && isset( $_GET['post'] ) && SPTRANS_CPT === $post->post_type ) ||
( 'edit.php' === $hook_suffix && SPTRANS_CPT === $_GET['post_type'] )
) {
//wp_enqueue_style( 'admin-translation', SPTRANS_URL . '/ressources/admin.css', [], SPTRANS_VERSION, 'all' );

// Choices.js
wp_enqueue_style( 'choices-js-choices', SPTRANS_URL . '/ressources/vendors/[email protected]/choices.min.css', [], SPTRANS_VERSION, 'all' );
wp_enqueue_script( 'choices-js', SPTRANS_URL . '/ressources/vendors/[email protected]/choices.min.js', [], SPTRANS_VERSION, true );

wp_enqueue_style( 'admin-translation', SPTRANS_URL . '/ressources/admin.css', [], SPTRANS_VERSION, 'all' );
wp_enqueue_script( 'admin-translation', SPTRANS_URL . '/ressources/admin.js', [ 'jquery' ], SPTRANS_VERSION, true );
wp_localize_script(
'admin-translation',
'translationL10n',
[
'successText' => __( 'This translation is unique, fine...', 'punctual-translation' ),
'errorText' => __( 'Duplicate translation detected !', 'punctual-translation' ),
'successText' => __( 'This translation is unique, fine...', 'punctual-translation' ),
'errorText' => __( 'Duplicate translation detected !', 'punctual-translation' ),
'searchPlaceholder' => __( 'Search for an article...', 'punctual-translation' ),
'noResultsText' => __( 'No results found', 'punctual-translation' ),
'searchingText' => __( 'Searching...', 'punctual-translation' ),
'pleaseSearch' => __( 'Please search for at least 2 characters', 'punctual-translation' ),
]
);
}
Expand Down Expand Up @@ -226,7 +235,7 @@ public function MetaboxOriginalContent( $post ) {
$current_parent_id = $current_parent->ID;
}
?>
<div id="ajax-filter-original" class="hide-if-no-js">
<div id="ajax-filter-original" class="simple-punctual-translation-meta-box hide-if-no-js">
<p>
<label for="original_post_type_js"><?php _e( 'Post types', 'punctual-translation' ); ?></label>
<br/>
Expand Down Expand Up @@ -258,32 +267,12 @@ public function MetaboxOriginalContent( $post ) {
<label for="parent_id"><?php _e( 'Original', 'punctual-translation' ); ?></label>
<br/>
<select name="parent_id" id="parent_id" class="widefat">
<option value="-"><?php _e( 'Please choose a content', 'punctual-translation' ); ?></option>
<option value=""><?php _e( 'Please choose a content', 'punctual-translation' ); ?></option>
<?php
// Current selected value
if ( false !== $current_parent ) {
echo '<option selected="selected" value="' . esc_attr( $current_parent->ID ) . '">' . esc_html( $current_parent->ID ) . ' - ' . esc_html( $current_parent->post_title ) . '</option>' . "\n";
}

$current_options = get_option( SPTRANS_OPTIONS_NAME );

// List all other content
$q_all_content = new WP_Query(
[
'post_type' => ! empty( $current_options['cpt'] ) ? $current_options['cpt'] : 'any',
'post_status' => 'any',
'posts_per_page' => 2000,
'no_found_rows' => true,
'post__not_in' => [ $current_parent_id ],
'orderby' => 'title',
'order' => 'ASC',
]
);
if ( $q_all_content->have_posts() ) {
foreach ( $q_all_content->posts as $object ) {
echo '<option value="' . esc_attr( $object->ID ) . '">' . esc_html( $object->ID ) . ' - ' . esc_html( $object->post_title ) . '</option>' . "\n";
}
}
?>
</select>
</div>
Expand Down Expand Up @@ -370,19 +359,39 @@ public function ajaxBuildSelect() {
status_header( '404' );
die();
}
$q_all_content = new WP_Query(
[
'post_type' => $_REQUEST['post_type'],
'post_status' => 'any',
'posts_per_page' => 1000,
'no_found_rows' => true,
'orderby' => 'title',
'order' => 'ASC',
]
);

// Sanitize inputs
$post_type = sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ) );
$current_value = isset( $_REQUEST['current_value'] ) ? absint( $_REQUEST['current_value'] ) : 0;
$search_term = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : '';
$load_selected_only = isset( $_REQUEST['load_selected_only'] ) && 'true' === $_REQUEST['load_selected_only'];
$limit = isset( $_REQUEST['limit'] ) ? absint( $_REQUEST['limit'] ) : 100;

// Build query arguments
$query_args = [
'post_type' => $post_type,
'post_status' => 'any',
'posts_per_page' => $limit,
'no_found_rows' => true,
'orderby' => 'title',
'order' => 'ASC',
];

// If loading only selected value, add post__in filter
if ( $load_selected_only && $current_value > 0 ) {
$query_args['post__in'] = [ $current_value ];
}

// If search term provided, add search filter
if ( ! empty( $search_term ) && strlen( $search_term ) >= 2 ) {
$query_args['s'] = $search_term;
}

$q_all_content = new WP_Query( $query_args );

if ( $q_all_content->have_posts() ) {
foreach ( $q_all_content->posts as $object ) {
echo '<option value="' . esc_attr( $object->ID ) . '" ' . selected( $object->ID, (int) $_REQUEST['current_value'], false ) . '>' . esc_html( $object->ID ) . ' - ' . esc_html( $object->post_title ) . '</option>' . "\n";
echo '<option value="' . esc_attr( $object->ID ) . '" ' . selected( $object->ID, $current_value, false ) . '>' . esc_html( $object->ID ) . ' - ' . esc_html( $object->post_title ) . '</option>' . "\n";
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion punctual-translation.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
Plugin Name: Simple Punctual Translation
Version: 1.1.5
Version: 1.1.6
Plugin URI: http://www.beapi.fr
Description: A small plugin for WordPress that allow to translate any post type in another languages. This plugin is not usable out of the box. It's require some changes on your theme.
Author: BeAPI
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: http://beapi.fr/donate/
Tags: administration, languages, traduction, translation, dropdown, i18n, language, localization, WPML, bilingual, switcher, multilingual, multilanguage, professional
Requires at least: 6.0
Tested up to: 6.4
Stable tag: 1.1.5
Stable tag: 1.1.6

A plugin for WordPress that allow to translate any post type in another languages. Translate only the single view.

Expand Down Expand Up @@ -85,6 +85,10 @@ The Simple Punctual Translation can be installed in 3 easy steps:

== Changelog ==

* Version 1.1.6 :
* On editor load, query only the current post and not all posts, if one is selected.
* Replace big query (1000) posts by only 100 posts.
* Use Choices.js to enable search on select, load only searched posts.
* Version 1.1.5 :
* Allow to customize query_var and rewrite keyword
* Security, add some missing sanitizing
Expand Down
23 changes: 23 additions & 0 deletions ressources/admin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.simple-punctual-translation-meta-box * {
box-sizing: border-box;
}

.simple-punctual-translation-meta-box label {
margin-bottom: 8px;
}

.simple-punctual-translation-meta-box .choices__inner {
background-color: transparent;
border : 1px solid #8c8f94 ;
}

.simple-punctual-translation-meta-box .choices__inner .choices__item {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}

.simple-punctual-translation-meta-box .choices__list--dropdown, .choices__list[aria-expanded] {
z-index: 2;
}
Loading