Skip to content
Open
2 changes: 1 addition & 1 deletion assets/css/msls.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/js/msls-quick-create.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions includes/Component/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ abstract class Component {
const INPUT_PREFIX = 'msls_input_';

const ALLOWED_HTML = array(
'button' => array(
'type' => true,
'class' => true,
'title' => true,
'aria-label' => true,
'data-target-blog-id' => true,
'data-source-post-id' => true,
'data-source-blog-id' => true,
),
'form' => array(
'action' => true,
'method' => true,
Expand Down
6 changes: 6 additions & 0 deletions includes/MslsAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Administration of the options
*
* @method void activate_autocomplete()
* @method void activate_quick_create()
* @method void sort_by_description()
* @method void exclude_current_blog()
* @method void only_with_translation()
Expand Down Expand Up @@ -113,6 +114,10 @@
'Activate the content import functionality',
'multisite-language-switcher'
),
'activate_quick_create' => __(
'Create draft translations with a single click',
'multisite-language-switcher'
),
'sort_by_description' => __( 'Sort languages by description', 'multisite-language-switcher' ),
'exclude_current_blog' => __( 'Exclude this blog from output', 'multisite-language-switcher' ),
'only_with_translation' => __( 'Show only links with a translation', 'multisite-language-switcher' ),
Expand Down Expand Up @@ -239,7 +244,7 @@
*
* @since 1.0
*/
do_action( self::MSLS_REGISTER_ACTION, __CLASS__ );

Check warning on line 247 in includes/MslsAdmin.php

View workflow job for this annotation

GitHub Actions / test

WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound

Hook names invoked by a theme/plugin should start with the theme/plugin prefix. Found: "self::MSLS_REGISTER_ACTION".
}

/**
Expand Down Expand Up @@ -295,6 +300,7 @@
'reference_user' => esc_html__( 'Reference user', 'multisite-language-switcher' ),
'exclude_current_blog' => esc_html__( 'Exclude blog', 'multisite-language-switcher' ),
'activate_content_import' => esc_html__( 'Content import', 'multisite-language-switcher' ),
'activate_quick_create' => esc_html__( 'Quick Create', 'multisite-language-switcher' ),
);

return $this->add_settings_fields( $map, 'advanced_section' );
Expand Down Expand Up @@ -338,7 +344,7 @@
*
* @since 2.4.4
*/
do_action( self::MSLS_ACTION_PREFIX . $section, __CLASS__, $section );

Check warning on line 347 in includes/MslsAdmin.php

View workflow job for this annotation

GitHub Actions / test

WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound

Hook names invoked by a theme/plugin should start with the theme/plugin prefix. Found: "self::MSLS_ACTION_PREFIX . $section".

return count( $map );
}
Expand Down
35 changes: 35 additions & 0 deletions includes/MslsAdminIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ public function get_img(): string {
*/
public function get_a(): string {
if ( empty( $this->href ) ) {
if ( $this->should_quick_create() ) {
return $this->get_quick_create_a();
}

/* translators: %s: blog name */
$format = __( 'Create a new translation in the %s-blog', 'multisite-language-switcher' );
$href = $this->get_edit_new();
Expand All @@ -219,6 +223,37 @@ public function get_a(): string {
return sprintf( '<a title="%1$s" href="%2$s">%3$s</a>&nbsp;', esc_attr( $title ), esc_url( $href ), $this->get_icon() );
}

/**
* @return bool
*/
protected function should_quick_create(): bool {
return null !== $this->id
&& null !== $this->origin_language
&& msls_options()->activate_quick_create;
}

/**
* @return string
*/
protected function get_quick_create_a(): string {
$collection = msls_blog_collection();
$source_blog_id = $collection->get_blog_id( $this->origin_language );
$target_blog_id = get_current_blog_id();

/* translators: %s: blog name */
$format = __( 'Create a new translation in the %s-blog', 'multisite-language-switcher' );
$title = sprintf( $format, $this->language );

return sprintf(
'<button type="button" class="msls-quick-create" title="%1$s" aria-label="%1$s" data-target-blog-id="%2$d" data-source-post-id="%3$d" data-source-blog-id="%4$d">%5$s</button>&nbsp;',
esc_attr( $title ),
$target_blog_id,
$this->id,
$source_blog_id,
$this->get_icon()
);
}

/**
* Get icon as html-tag
*
Expand Down
1 change: 1 addition & 0 deletions includes/MslsOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @package Msls
* @property bool $activate_autocomplete
* @property bool $activate_content_import
* @property bool $activate_quick_create
* @property bool $output_current_blog
* @property bool $only_with_translation
* @property int $content_priority
Expand Down
5 changes: 5 additions & 0 deletions includes/MslsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static function init(): void {
add_action( 'admin_enqueue_scripts', array( $obj, 'custom_enqueue' ) );
add_action( 'wp_enqueue_scripts', array( $obj, 'custom_enqueue' ) );

add_action( 'rest_api_init', array( MslsRestApi::class, 'init' ) );
add_action( 'init', array( MslsAdminBar::class, 'init' ) );
add_action( 'init', array( MslsBlock::class, 'init' ) );
add_action( 'init', array( MslsShortCode::class, 'init' ) );
Expand Down Expand Up @@ -124,6 +125,10 @@ public function custom_enqueue(): void {
if ( $this->options->activate_autocomplete ) {
wp_enqueue_script( 'msls-autocomplete', self::plugins_url( "$folder/msls.js" ), array( 'jquery-ui-autocomplete' ), $ver, array( 'in_footer' => true ) );
}

if ( $this->options->activate_quick_create ) {
wp_enqueue_script( 'msls-quick-create', self::plugins_url( "$folder/msls-quick-create.js" ), array( 'jquery', 'wp-api-fetch' ), $ver, array( 'in_footer' => true ) );
}
}

/**
Expand Down
Loading
Loading