Skip to content

Commit

Permalink
feat: change search block's default settings (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurelfulford authored May 31, 2023
1 parent 1f140be commit 1487a69
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions includes/class-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct() {
\add_action( 'after_setup_theme', [ __CLASS__, 'theme_support' ] );
\add_action( 'wp_enqueue_scripts', [ __CLASS__, 'theme_styles' ] );
\add_action( 'enqueue_block_editor_assets', [ __CLASS__, 'editor_scripts' ] );
\add_filter( 'block_type_metadata', [ __CLASS__, 'block_variations' ] );
}

/**
Expand Down Expand Up @@ -86,6 +87,26 @@ public static function editor_scripts() {
// Enqueue editor JavaScript.
wp_enqueue_script( 'editor-script', get_theme_file_uri( '/dist/editor.js' ), array( 'wp-blocks', 'wp-dom' ), wp_get_theme()->get( 'Version' ), true );
}

/**
* Add block variations.
*
* @since Newspack Block Theme 1.0
*
* We may be able to replace this with JavaScript; I'm unclear whether isDefault isn't working, or just not working as I expect it to.
* See: https://github.com/WordPress/gutenberg/issues/28119
*
* @return array Block metadata.
*/
public static function block_variations( $metadata ) {
if ( $metadata[ 'name' ] == 'core/search' ) {
$metadata['attributes']['buttonPosition']['default'] = 'button-inside';
$metadata['attributes']['buttonUseIcon']['default'] = true;
$metadata['attributes']['placeholder']['default'] = esc_html__( 'Search...', 'newspack-block-theme' );
$metadata['attributes']['showLabel']['default'] = false;
}
return $metadata;
}
}

Core::instance();

0 comments on commit 1487a69

Please sign in to comment.