Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-jacob committed Oct 22, 2024
2 parents 7d1f19c + 1921b45 commit 4416028
Show file tree
Hide file tree
Showing 22 changed files with 2,393 additions and 62 deletions.
77 changes: 72 additions & 5 deletions inc/admin/admin-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function wplng_admin_bar_menu() {
return;
}

$url = wplng_get_url_current();
$url_original = remove_query_arg(
$url = wplng_get_url_current();
$url_clean = remove_query_arg(
array( 'wplng-mode', 'wplng-load', 'wplng-nocache' ),
$url
);
Expand All @@ -63,7 +63,7 @@ function wplng_admin_bar_menu() {
'id' => 'wplingua-return',
'parent' => 'wplingua-menu',
'title' => __( 'Return on page', 'wplingua' ),
'href' => $url_original,
'href' => $url_clean,
)
);
}
Expand Down Expand Up @@ -111,7 +111,7 @@ function wplng_admin_bar_menu() {
'wplng-mode',
'editor',
wplng_url_translate(
wplng_get_url_original( $url_original ),
wplng_get_url_original( $url_clean ),
$language['id']
)
),
Expand All @@ -127,7 +127,7 @@ function wplng_admin_bar_menu() {
'wplng-mode',
'list',
wplng_url_translate(
wplng_get_url_original( $url_original ),
wplng_get_url_original( $url_clean ),
$language['id']
)
),
Expand All @@ -137,4 +137,71 @@ function wplng_admin_bar_menu() {
} // End foreach ( $languages_target as $language )
} // End if ( ! empty( $languages_target ) )

/**
* Edit slug translation link
*/

if ( is_404() ) {
return;
}

$url_original = wplng_get_url_original( $url_clean );
$url_original_parsed = parse_url( $url_original );

if ( ! isset( $url_original_parsed['path'] ) ) {
return;
}

$path = $url_original_parsed['path'];

// Return path if no contains slug

if ( '/' === $path || '' === $path ) {
return;
}

// Transform the multi part slug to an slug array

$slugs = explode( '/', $path );
$slugs = array_filter( $slugs );

$last_slug = '';

foreach ( $slugs as $slug ) {
if ( '/' === $slug || '' === $slug ) {
continue;
}
$last_slug = $slug;
}

if ( '/' === $last_slug
|| '' === $last_slug
|| ! wplng_text_is_translatable( $last_slug )
) {
return;
}

$slug_id = wplng_get_slug_saved_from_original( $last_slug );

if ( false === $slug_id ) {
$slug_id = wplng_create_slug( $slug );
}

$edit_slug_link = get_edit_post_link( $slug_id );

if ( ! is_string( $edit_slug_link ) ) {
return;
}

$wp_admin_bar->add_menu(
array(
'id' => 'wplingua-slug',
'parent' => 'wplingua-menu',
'title' => __( 'Edit the page slug', 'wplingua' ),
'href' => $edit_slug_link,
'meta' => array(
'target' => '_blank',
),
)
);
}
66 changes: 66 additions & 0 deletions inc/admin/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,72 @@ function wplng_translation_assets() {
}


/**
* Register wpLingua assets on slugs edit pages
*
* @return void
*/
function wplng_slug_assets() {

global $post_type;

if ( 'wplng_slug' === $post_type ) {

/**
* Enqueue jQuery
*/

wp_enqueue_script( 'jquery' );

/**
* Enqueue wpLingua JS scripts
*/

wp_enqueue_script(
'wplingua-slug',
plugins_url() . '/wplingua/assets/js/admin/slug.js',
array( 'jquery' ),
WPLNG_PLUGIN_VERSION
);

/**
* Localize script
*/

wp_localize_script(
'wplingua-slug',
'wplngLocalize',
array(
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'currentLanguage' => false,
'message' => array(
'exitPage' => esc_html__(
'You are about to leave the page without saving your changes. They will be lost if you continue. Would you like to leave the page anyway?',
'wplingua'
),
'exitEditorModal' => '',
'buttonSave' => '',
'buttonSaveInProgress' => '',
),
)
);

/**
* Enqueue wpLingua CSS styles
*/

wp_enqueue_style(
'wplingua-slug',
plugins_url() . '/wplingua/assets/css/admin/slug.css',
array(),
WPLNG_PLUGIN_VERSION
);

}

}


/**
* Print wpLingua head script (JSON with all languages informations)
*
Expand Down
9 changes: 9 additions & 0 deletions inc/admin/option-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ function wplng_create_menu() {
'wplng_option_page_exclusions'
);

add_submenu_page(
'wplingua-settings',
__( 'wplingua: Website slugs', 'wplingua' ),
__( 'Website slugs', 'wplingua' ),
'administrator',
'edit.php?post_type=wplng_slug',
false
);

add_submenu_page(
'wplingua-settings',
__( 'wplingua: Translations', 'wplingua' ),
Expand Down
Loading

0 comments on commit 4416028

Please sign in to comment.