-
Notifications
You must be signed in to change notification settings - Fork 92
Feature/print button #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arifulhoque7
wants to merge
5
commits into
weDevsOfficial:develop
Choose a base branch
from
arifulhoque7:feature/print-button
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/print button #228
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| { | ||
| "$schema": "https://schemas.wp.org/trunk/block.json", | ||
| "apiVersion": 3, | ||
| "name": "wedocs/print-button", | ||
| "version": "1.0.0", | ||
| "title": "weDocs - Print Button", | ||
| "icon": "printer", | ||
| "category": "wedocs", | ||
| "description": "Add a print button to allow users to print the current page", | ||
| "keywords": [ | ||
| "print", | ||
| "button", | ||
| "wedocs", | ||
| "documentation" | ||
| ], | ||
| "supports": { | ||
| "html": false, | ||
| "align": [ | ||
| "left", | ||
| "center", | ||
| "right" | ||
| ] | ||
| }, | ||
| "editorScript": "file:./index.js", | ||
| "editorStyle": "file:./index.css", | ||
| "style": "file:./style-index.css", | ||
| "render": "file:./render.php", | ||
| "attributes": { | ||
| "layout": { | ||
| "type": "string", | ||
| "default": "layout1" | ||
| }, | ||
| "alignment": { | ||
| "type": "string", | ||
| "default": "left" | ||
| }, | ||
| "buttonText": { | ||
| "type": "string", | ||
| "default": "Print" | ||
| }, | ||
| "showIcon": { | ||
| "type": "boolean", | ||
| "default": true | ||
| }, | ||
| "padding": { | ||
| "type": "object", | ||
| "default": { | ||
| "top": "10px", | ||
| "right": "15px", | ||
| "bottom": "10px", | ||
| "left": "15px" | ||
| } | ||
| }, | ||
| "margin": { | ||
| "type": "object", | ||
| "default": { | ||
| "top": "0px", | ||
| "right": "0px", | ||
| "bottom": "10px", | ||
| "left": "0px" | ||
| } | ||
| }, | ||
| "backgroundColor": { | ||
| "type": "string", | ||
| "default": "#0073aa" | ||
| }, | ||
| "textColor": { | ||
| "type": "string", | ||
| "default": "#ffffff" | ||
| }, | ||
| "hoverBackgroundColor": { | ||
| "type": "string", | ||
| "default": "#005177" | ||
| }, | ||
| "hoverTextColor": { | ||
| "type": "string", | ||
| "default": "#ffffff" | ||
| }, | ||
| "borderRadius": { | ||
| "type": "string", | ||
| "default": "4px" | ||
| }, | ||
| "borderWidth": { | ||
| "type": "string", | ||
| "default": "1px" | ||
| }, | ||
| "borderColor": { | ||
| "type": "string", | ||
| "default": "#0073aa" | ||
| }, | ||
| "borderStyle": { | ||
| "type": "string", | ||
| "default": "solid" | ||
| }, | ||
| "fontSize": { | ||
| "type": "string", | ||
| "default": "16px" | ||
| }, | ||
| "fontWeight": { | ||
| "type": "string", | ||
| "default": "normal" | ||
| }, | ||
| "additionalClasses": { | ||
| "type": "string", | ||
| "default": "" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| <?php | ||
| /** | ||
| * Server-side rendering for the Print Button block. | ||
| * | ||
| * @param array $attributes Block attributes. | ||
| * @return string | ||
| */ | ||
|
|
||
| function render_wedocs_print_button($attributes) { | ||
|
|
||
| // Check if we're on a weDocs post type | ||
| global $post; | ||
| if (!$post || $post->post_type !== 'docs') { | ||
| return ''; | ||
| } | ||
|
|
||
| ob_start(); | ||
|
|
||
| // Extract attributes with defaults | ||
| $layout = isset($attributes['layout']) ? $attributes['layout'] : 'layout1'; | ||
| $alignment = isset($attributes['alignment']) ? $attributes['alignment'] : 'left'; | ||
| $button_text = isset($attributes['buttonText']) ? $attributes['buttonText'] : __('Print', 'wedocs'); | ||
| $show_icon = isset($attributes['showIcon']) ? $attributes['showIcon'] : true; | ||
| $additional_classes = isset($attributes['additionalClasses']) ? $attributes['additionalClasses'] : ''; | ||
|
|
||
| // Spacing attributes with proper defaults for empty values | ||
| $padding_defaults = [ | ||
| 'top' => '10px', | ||
| 'right' => '15px', | ||
| 'bottom' => '10px', | ||
| 'left' => '15px' | ||
| ]; | ||
|
|
||
| $margin_defaults = [ | ||
| 'top' => '0px', | ||
| 'right' => '0px', | ||
| 'bottom' => '10px', | ||
| 'left' => '0px' | ||
| ]; | ||
|
|
||
| // Merge with defaults to handle empty/undefined individual properties | ||
| $padding = array_merge($padding_defaults, isset($attributes['padding']) ? array_filter($attributes['padding'], function($value) { | ||
| return !($value === null || $value === ''); | ||
| }) : []); | ||
|
|
||
| $margin = array_merge($margin_defaults, isset($attributes['margin']) ? array_filter($attributes['margin'], function($value) { | ||
| return !($value === null || $value === ''); | ||
| }) : []); | ||
|
|
||
| // Color and style attributes | ||
| $background_color = isset($attributes['backgroundColor']) ? $attributes['backgroundColor'] : '#0073aa'; | ||
| $text_color = isset($attributes['textColor']) ? $attributes['textColor'] : '#ffffff'; | ||
| $hover_bg_color = isset($attributes['hoverBackgroundColor']) ? $attributes['hoverBackgroundColor'] : '#005177'; | ||
| $hover_text_color = isset($attributes['hoverTextColor']) ? $attributes['hoverTextColor'] : '#ffffff'; | ||
| $border_radius = isset($attributes['borderRadius']) ? $attributes['borderRadius'] : '4px'; | ||
| $border_width = isset($attributes['borderWidth']) ? $attributes['borderWidth'] : '1px'; | ||
| $border_color = isset($attributes['borderColor']) ? $attributes['borderColor'] : '#0073aa'; | ||
| $border_style = isset($attributes['borderStyle']) ? $attributes['borderStyle'] : 'solid'; | ||
| $font_size = isset($attributes['fontSize']) ? $attributes['fontSize'] : '16px'; | ||
| $font_weight = isset($attributes['fontWeight']) ? $attributes['fontWeight'] : 'normal'; | ||
|
|
||
| // Generate unique ID for styles | ||
| $block_id = 'wedocs-print-btn-' . wp_generate_uuid4(); | ||
|
|
||
| // Container styles based on alignment | ||
| $container_styles = sprintf('text-align: %s; width: 100%%;', esc_attr($alignment)); | ||
|
|
||
| // Build CSS classes | ||
| $css_classes = sprintf('wedocs-print-article wedocs-print-button %s %s', | ||
| esc_attr($layout), | ||
| esc_attr($additional_classes) | ||
| ); | ||
|
|
||
| // Render layout variations | ||
| $button_content = ''; | ||
|
|
||
| switch ($layout) { | ||
| case 'layout2': | ||
| $button_content = sprintf( | ||
| '<a href="#" id="%s" class="%s layout-2" title="%s"> | ||
| %s | ||
| <span>%s</span> | ||
| </a>', | ||
| esc_attr($block_id), | ||
| esc_attr($css_classes), | ||
| esc_attr(__('Print this article', 'wedocs')), | ||
| $show_icon ? '<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="M19 8H5c-1.66 0-3 1.34-3 3v6h4v4h12v-4h4v-6c0-1.66-1.34-3-3-3zm-3 11H8v-5h8v5zm3-7c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1zm-1-9H6v4h12V3z"/></svg>' : '', | ||
| esc_html($button_text) | ||
| ); | ||
| break; | ||
|
|
||
| case 'layout3': | ||
| $button_content = sprintf( | ||
| '<a href="#" id="%s" class="%s layout-3" title="%s"> | ||
| %s | ||
| <span style="font-size: 12px;">%s</span> | ||
| </a>', | ||
| esc_attr($block_id), | ||
| esc_attr($css_classes), | ||
| esc_attr(__('Print this article', 'wedocs')), | ||
| $show_icon ? '<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="M19 8H5c-1.66 0-3 1.34-3 3v6h4v4h12v-4h4v-6c0-1.66-1.34-3-3-3zm-3 11H8v-5h8v5zm3-7c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1zm-1-9H6v4h12V3z"/></svg>' : '', | ||
| esc_html($button_text) | ||
| ); | ||
| break; | ||
|
|
||
| default: // layout1 | ||
| $button_content = sprintf( | ||
| '<a href="#" id="%s" class="%s layout-1" title="%s"> | ||
| %s | ||
| <span>%s</span> | ||
| </a>', | ||
| esc_attr($block_id), | ||
| esc_attr($css_classes), | ||
| esc_attr(__('Print this article', 'wedocs')), | ||
| $show_icon ? '<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="M19 8H5c-1.66 0-3 1.34-3 3v6h4v4h12v-4h4v-6c0-1.66-1.34-3-3-3zm-3 11H8v-5h8v5zm3-7c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1zm-1-9H6v4h12V3z"/></svg>' : '', | ||
| esc_html($button_text) | ||
| ); | ||
| break; | ||
| } | ||
|
|
||
| // Output the complete block with custom styles | ||
| ?> | ||
| <style> | ||
| #<?php echo esc_attr($block_id); ?> { | ||
| padding: <?php echo esc_attr($padding['top']); ?> <?php echo esc_attr($padding['right']); ?> <?php echo esc_attr($padding['bottom']); ?> <?php echo esc_attr($padding['left']); ?> !important; | ||
| margin: <?php echo esc_attr($margin['top']); ?> <?php echo esc_attr($margin['right']); ?> <?php echo esc_attr($margin['bottom']); ?> <?php echo esc_attr($margin['left']); ?> !important; | ||
| background-color: <?php echo esc_attr($background_color); ?> !important; | ||
| color: <?php echo esc_attr($text_color); ?> !important; | ||
| border: <?php echo esc_attr($border_width); ?> <?php echo esc_attr($border_style); ?> <?php echo esc_attr($border_color); ?> !important; | ||
| border-radius: <?php echo esc_attr($border_radius); ?> !important; | ||
| font-size: <?php echo esc_attr($font_size); ?> !important; | ||
| font-weight: <?php echo esc_attr($font_weight); ?> !important; | ||
| text-decoration: none !important; | ||
| cursor: pointer !important; | ||
| transition: all 0.2s ease-in-out !important; | ||
| display: inline-flex !important; | ||
| align-items: center !important; | ||
| justify-content: center !important; | ||
| gap: <?php echo $show_icon ? '8px' : '0'; ?> !important; | ||
| line-height: 1.4 !important; | ||
| } | ||
| <?php if ($layout === 'layout3'): ?> | ||
| #<?php echo esc_attr($block_id); ?> { | ||
| flex-direction: column !important; | ||
| gap: 4px !important; | ||
| } | ||
| <?php endif; ?> | ||
| #<?php echo esc_attr($block_id); ?>:hover { | ||
| background-color: <?php echo esc_attr($hover_bg_color); ?> !important; | ||
| color: <?php echo esc_attr($hover_text_color); ?> !important; | ||
| } | ||
| @media print { | ||
| #<?php echo esc_attr($block_id); ?>, | ||
| .wp-block-wedocs-print-button { | ||
| display: none !important; | ||
| } | ||
| } | ||
| </style> | ||
| <div class="wp-block-wedocs-print-button wedocs-print-button-wrapper" style="<?php echo esc_attr($container_styles); ?>"> | ||
| <?php echo $button_content; ?> | ||
| </div> | ||
| <?php | ||
| return ob_get_clean(); | ||
| } | ||
| ?> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scope print-hide CSS narrowly to avoid collateral hides.
The global [class*=print-button], [id*=wedocs-print] patterns in other CSS can hide unrelated content. Here you already hide the instance by id and wrapper; that’s sufficient.
@media print { - #<?php echo esc_attr($block_id); ?>, - .wp-block-wedocs-print-button { - display: none !important; - } + #<?php echo esc_attr($block_id); ?>, + .wp-block-wedocs-print-button { display: none !important; } }Ensure the built stylesheet removes broad attribute selectors too (see comment in assets/build/style-block.css).
🤖 Prompt for AI Agents