get_all_registered() as $name => $type ) { if ( ! str_starts_with( $name, 'smilia/' ) ) { continue; } foreach ( (array) $type->editor_script_handles as $handle ) { wp_set_script_translations( $handle, 'smilia-core', SMILIA_CORE_DIR . '/languages' ); } } } public function keep_wide_sizes( string $image ): string { if ( false === strpos( $image, 'service-page__method-photo' ) ) { return $image; } $processor = new \WP_HTML_Tag_Processor( $image ); if ( $processor->next_tag( 'img' ) ) { $sizes = (string) $processor->get_attribute( 'sizes' ); if ( str_starts_with( $sizes, 'auto,' ) ) { $processor->set_attribute( 'sizes', trim( substr( $sizes, 5 ) ) ); } } return $processor->get_updated_html(); } public function asset_version( array $metadata ): array { if ( empty( $metadata['file'] ) || ! str_starts_with( wp_normalize_path( $metadata['file'] ), wp_normalize_path( self::DIR ) ) ) { return $metadata; } $asset = dirname( $metadata['file'] ) . '/index.asset.php'; if ( is_readable( $asset ) ) { $data = include $asset; if ( is_array( $data ) && ! empty( $data['version'] ) ) { $metadata['version'] = (string) $data['version']; } } return $metadata; } public function editor_data(): void { wp_add_inline_script( 'wp-blocks', 'window.smiliaBlocks = ' . wp_json_encode( array( 'images' => plugins_url( 'assets/img/', SMILIA_CORE_FILE ), 'admin' => admin_url(), ) ) . ';' ); } public function add_category( array $categories ): array { array_unshift( $categories, array( 'slug' => 'smilia', 'title' => __( 'Smilia', 'smilia-core' ), 'icon' => null, ) ); return $categories; } public function editor_settings( array $settings, WP_Block_Editor_Context $context ): array { $settings['enableOpenverseMediaCategory'] = false; if ( $context->post instanceof WP_Post && 'page' === $context->post->post_type ) { $settings['templateLock'] = current_user_can( 'manage_options' ) ? 'all' : 'contentOnly'; } return $settings; } }