Skip to content

Commit

Permalink
Merge pull request #268 from lloc/double-output
Browse files Browse the repository at this point in the history
Tests adjusted
  • Loading branch information
lloc authored Jan 6, 2024
2 parents 9817042 + f61275c commit 5629f6e
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 86 deletions.
19 changes: 10 additions & 9 deletions includes/MslsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,16 @@ public function block_init() {
$callback = [ $this, 'block_render' ];

global $pagenow;
$toLoad = [ 'wp-blocks', 'wp-element', 'wp-components' ];
if ( $pagenow === 'widgets.php' ) $toLoad[] = 'wp-edit-widgets';
else $toLoad[] = 'wp-editor';

wp_register_script(
$handle,
self::plugins_url( 'js/msls-widget-block.js' ),
$toLoad
);

$toLoad = [ 'wp-blocks', 'wp-element', 'wp-components' ];
if ( $pagenow === 'widgets.php' ) $toLoad[] = 'wp-edit-widgets';
else $toLoad[] = 'wp-editor';

wp_register_script(
$handle,
self::plugins_url( 'js/msls-widget-block.js' ),
$toLoad
);

register_block_type( 'lloc/msls-widget-block', [
'attributes' => [ 'title' => [ 'type' => 'string' ] ],
Expand Down
72 changes: 36 additions & 36 deletions includes/MslsPostTag.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* MslsPostTag
*
* @author Dennis Ploetner <[email protected]>
* @since 0.9.8
*/
Expand All @@ -9,6 +10,7 @@

/**
* Post Tag
*
* @package Msls
*/
class MslsPostTag extends MslsMain {
Expand All @@ -27,12 +29,12 @@ public static function suggest() {
filter_input( INPUT_POST, 'blog_id', FILTER_SANITIZE_NUMBER_INT )
);

$args = array(
$args = [
'orderby' => 'name',
'order' => 'ASC',
'number' => 10,
'hide_empty' => 0,
);
];

if ( filter_has_var( INPUT_POST, 's' ) ) {
$args['search'] = sanitize_text_field(
Expand Down Expand Up @@ -69,20 +71,13 @@ public static function suggest() {
/**
* Init
*
* @codeCoverageIgnore
*
* @return MslsPostTag
*/
public static function init() {
$options = MslsOptions::instance();
$collection = msls_blog_collection();

if ( $options->activate_autocomplete ) {
$obj = new static( $options, $collection );
}
else {
$obj = new MslsPostTagClassic( $options, $collection );
}
$class = $options->activate_autocomplete ? MslsPostTag::class : MslsPostTagClassic::class;
$obj = new $class( $options, $collection );

$taxonomy = MslsContentTypes::create()->acl_request();
if ( '' != $taxonomy ) {
Expand All @@ -98,9 +93,13 @@ public static function init() {
/**
* Add the input fields to the add-screen of the taxonomies
*
* @param \StdClass $tag
* @param string $taxonomy
*/
public function add_input( $tag ) {
public function add_input( string $taxonomy ): void {
if ( did_action( "{$taxonomy}_add_form_fields" ) !== 1 ) {
return;
}

$title_format = '<h3>%s</h3>
<input type="hidden" name="msls_post_type" id="msls_post_type" value="%s"/>
<input type="hidden" name="msls_action" id="msls_action" value="suggest_terms"/>';
Expand All @@ -110,15 +109,20 @@ public function add_input( $tag ) {
<input class="msls_title" id="msls_title_%1$s" name="msls_title_%1$s" type="text" value="%5$s"/>';

echo '<div class="form-field">';
$this->the_input( $tag, $title_format, $item_format );
$this->the_input( $taxonomy, $title_format, $item_format );
echo '</div>';
}

/**
* Add the input fields to the edit-screen of the taxonomies
* @param \StdClass $tag
*
* @param string $taxonomy
*/
public function edit_input( $tag ) {
public function edit_input( string $taxonomy ): void {
if ( did_action( "{$taxonomy}_edit_form_fields" ) !== 1 ) {
return;
}

$title_format = '<tr>
<th colspan="2">
<strong>%s</strong>
Expand All @@ -128,7 +132,7 @@ public function edit_input( $tag ) {
</tr>';

$item_format = '<tr class="form-field">
<th scope="row" valign="top">
<th scope="row">
<label for="msls_title_%1$s">%2$s</label>
</th>
<td>
Expand All @@ -137,15 +141,18 @@ public function edit_input( $tag ) {
</td>
</tr>';

$this->the_input( $tag, $title_format, $item_format );
$this->the_input( $taxonomy, $title_format, $item_format );
}

/**
* Print the input fields
*
* Returns true if the blogcollection is not empty
* @param \StdClass $tag
*
* @param mixed $tag
* @param string $title_format
* @param string $item_format
*
* @return boolean
*/
public function the_input( $tag, $title_format, $item_format ) {
Expand All @@ -156,7 +163,7 @@ public function the_input( $tag, $title_format, $item_format ) {

$this->maybe_set_linked_term( $my_data );

$type = MslsContentTypes::create()->get_request();
$type = MslsContentTypes::create()->get_request();

printf(
$title_format,
Expand All @@ -166,17 +173,13 @@ public function the_input( $tag, $title_format, $item_format ) {
),
$type
);

foreach ( $blogs as $blog ) {
switch_to_blog( $blog->userblog_id );

$language = $blog->get_language();
$icon = MslsAdminIcon::create()
->set_language( $language );
if( $this->options->admin_display === 'label' ) {
$icon->set_icon_type( 'label' );
} else {
$icon->set_icon_type( 'flag' );
}
$language = $blog->get_language();
$icon_type = $this->options->get_icon_type();
$icon = MslsAdminIcon::create()->set_language( $language )->set_icon_type( $icon_type );

$value = $title = '';
if ( $my_data->has_value( $language ) ) {
Expand All @@ -188,23 +191,20 @@ public function the_input( $tag, $title_format, $item_format ) {
}
}

printf(
$item_format,
$blog->userblog_id,
$icon,
$language,
$value,
$title
);
printf( $item_format, $blog->userblog_id, $icon, $language, $value, $title );

restore_current_blog();
}

return true;
}

return false;
}

/**
* Set calls the save method if taxonomy is set
*
* @param int $term_id
* @codeCoverageIgnore
*/
Expand Down
43 changes: 24 additions & 19 deletions includes/MslsPostTagClassic.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@
namespace lloc\Msls;

/**
* Post Tag Clasic
* Post Tag Classic
*
* @package Msls
*/
class MslsPostTagClassic extends MslsPostTag {

/**
* Add the input fields to the add-screen of the taxonomies
* @param \StdClass $tag
*
* @param string $taxonomy
*/
public function add_input( $tag ): void {
public function add_input( string $taxonomy ): void {
if ( did_action( "{$taxonomy}_add_form_fields" ) !== 1 ) {
return;
}

$title_format = '<h3>%s</h3>';

$item_format = '<label for="msls_input_%1$s">%2$s</label>
Expand All @@ -27,15 +33,20 @@ public function add_input( $tag ): void {
</select>';

echo '<div class="form-field">';
$this->the_input( $tag, $title_format, $item_format );
$this->the_input( $taxonomy, $title_format, $item_format );
echo '</div>';
}

/**
* Add the input fields to the edit-screen of the taxonomies
* @param \StdClass $tag
*
* @param string $taxonomy
*/
public function edit_input( $tag ): void {
public function edit_input( string $taxonomy ): void {
if ( did_action( "{$taxonomy}_edit_form_fields" ) !== 1 ) {
return;
}

$title_format = '<tr>
<th colspan="2">
<strong>%s</strong>
Expand All @@ -52,7 +63,7 @@ public function edit_input( $tag ): void {
</select></td>
</tr>';

$this->the_input( $tag, $title_format, $item_format );
$this->the_input( $taxonomy, $title_format, $item_format );
}

/**
Expand All @@ -67,22 +78,16 @@ public function edit_input( $tag ): void {
public function print_option( MslsBlog $blog, string $type, MslsOptionsTax $mydata, string $item_format ): void {
switch_to_blog( $blog->userblog_id );

$language = $blog->get_language();
$icon = MslsAdminIcon::create()
->set_language( $language );

if( $this->options->admin_display === 'label' ) {
$icon->set_icon_type( 'label' );
} else {
$icon->set_icon_type( 'flag' );
}
$options = '';
$terms = get_terms( [ 'taxonomy' => $type, 'hide_empty' => false ] );
$language = $blog->get_language();
$icon_type = $this->options->get_icon_type();
$icon = MslsAdminIcon::create()->set_language( $language )->set_icon_type( $icon_type );

if ( $mydata->has_value( $language ) ) {
$icon->set_href( $mydata->$language );
}

$options = '';
$terms = get_terms( [ 'taxonomy' => $type, 'hide_empty' => false ] );
if ( ! empty( $terms ) ) {
foreach ( $terms as $term ) {
$options .= sprintf(
Expand All @@ -103,7 +108,7 @@ public function print_option( MslsBlog $blog, string $type, MslsOptionsTax $myda
* Print the input fields
* Returns true if the blogcollection is not empty
*
* @param \StdClass $tag
* @param mixed $tag
* @param string $title_format
* @param string $item_format
* @return boolean
Expand Down
10 changes: 3 additions & 7 deletions includes/MslsWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ class MslsWidget extends \WP_Widget {
* Constructor
*/
public function __construct() {
parent::__construct(
$this->id_base,
apply_filters(
'msls_widget_title',
__( 'Multisite Language Switcher', 'multisite-language-switcher' )
)
);
$name = apply_filters('msls_widget_title', __( 'Multisite Language Switcher', 'multisite-language-switcher' ) );

parent::__construct( $this->id_base, $name, [ 'show_instance_in_rest' => true ] );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Msls_UnitTestCase extends TestCase {
*
* @var object $test
*/
protected $test;
protected object $test;

protected function setUp(): void {
parent::setUp();
Expand Down
Loading

0 comments on commit 5629f6e

Please sign in to comment.