diff --git a/enable-button-icons.php b/enable-button-icons.php index 201f89c..bca7882 100644 --- a/enable-button-icons.php +++ b/enable-button-icons.php @@ -31,11 +31,11 @@ function enable_button_icons_enqueue_block_editor_assets() { $asset_file['version'] ); - wp_set_script_translations( - 'enable-button-icons-editor-scripts', - 'enable-button-icons', - plugin_dir_path( __FILE__ ) . 'languages' - ); + wp_set_script_translations( + 'enable-button-icons-editor-scripts', + 'enable-button-icons', + plugin_dir_path( __FILE__ ) . 'languages' + ); wp_enqueue_style( 'enable-button-icons-editor-styles', @@ -49,15 +49,15 @@ function enable_button_icons_enqueue_block_editor_assets() { * (Applies to both frontend and Editor) */ function enable_button_icons_block_styles() { - wp_enqueue_block_style( - 'core/button', - array( - 'handle' => 'enable-button-icons-block-styles', - 'src' => plugin_dir_url( __FILE__ ) . 'build/style.css', - 'ver' => wp_get_theme()->get( 'Version' ), - 'path' => plugin_dir_path( __FILE__ ) . 'build/style.css', - ) - ); + wp_enqueue_block_style( + 'core/button', + array( + 'handle' => 'enable-button-icons-block-styles', + 'src' => plugin_dir_url( __FILE__ ) . 'build/style.css', + 'ver' => wp_get_theme()->get( 'Version' ), + 'path' => plugin_dir_path( __FILE__ ) . 'build/style.css', + ) + ); } add_action( 'init', 'enable_button_icons_block_styles' ); @@ -65,53 +65,53 @@ function enable_button_icons_block_styles() { * Render icons on the frontend. */ function enable_button_icons_render_block_button( $block_content, $block ) { - if ( ! isset( $block['attrs']['icon'] ) ) { + if ( ! isset( $block['attrs']['icon'] ) ) { return $block_content; } - $icon = $block['attrs']['icon']; - $positionLeft = isset( $block['attrs']['iconPositionLeft'] ) ? $block['attrs']['iconPositionLeft'] : false; - - // All available icon SVGs. - $icons = array( - 'arrow-left' => "", - 'arrow-right' => "", - 'chevron-left' => "", - 'chevron-left-small' => "", - 'chevron-right' => "", - 'chevron-right-small' => "", - 'cloud' => "", - 'cloud-upload' => "", - 'comment-author-avatar' => "", - 'download' => "", - 'external' => "", - 'external-arrow' => "", - 'help' => "", - 'info' => "", - 'lock-outline' => "", - 'login' => "", - 'next' => "", - 'previous' => "", - 'shuffle' => "", - 'wordpress' => "", - ); + $icon = $block['attrs']['icon']; + $positionLeft = isset( $block['attrs']['iconPositionLeft'] ) ? $block['attrs']['iconPositionLeft'] : false; + + // All available icon SVGs. + $icons = array( + 'arrow-left' => "", + 'arrow-right' => "", + 'chevron-left' => "", + 'chevron-left-small' => "", + 'chevron-right' => "", + 'chevron-right-small' => "", + 'cloud' => "", + 'cloud-upload' => "", + 'comment-author-avatar' => "", + 'download' => "", + 'external' => "", + 'external-arrow' => "", + 'help' => "", + 'info' => "", + 'lock-outline' => "", + 'login' => "", + 'next' => "", + 'previous' => "", + 'shuffle' => "", + 'wordpress' => "", + ); - // Make sure the selected icon is in the array, otherwise bail. - if ( ! array_key_exists( $icon, $icons ) ) { - return $block_content; - } + // Make sure the selected icon is in the array, otherwise bail. + if ( ! array_key_exists( $icon, $icons ) ) { + return $block_content; + } - // Append the icon class to the block. - $p = new WP_HTML_Tag_Processor( $block_content ); - if ( $p->next_tag() ) { - $p->add_class( 'has-icon__' . $icon ); - } - $block_content = $p->get_updated_html(); + // Append the icon class to the block. + $p = new WP_HTML_Tag_Processor( $block_content ); + if ( $p->next_tag() ) { + $p->add_class( 'has-icon__' . $icon ); + } + $block_content = $p->get_updated_html(); - // Add the SVG icon either to the left of right of the button text. - $block_content = $positionLeft - ? preg_replace( '/(]*>)(.*?)(<\/a>)/i', '$1$2$3', $block_content ) - : preg_replace( '/(]*>)(.*?)(<\/a>)/i', '$1$2$3', $block_content ); + // Add the SVG icon either to the left of right of the button text. + $block_content = $positionLeft + ? preg_replace( '/(]*>)(.*?)(<\/a>)/i', '$1$2$3', $block_content ) + : preg_replace( '/(]*>)(.*?)(<\/a>)/i', '$1$2$3', $block_content ); return $block_content; }