-
Notifications
You must be signed in to change notification settings - Fork 92
feat: block doc navigation #231
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
sapayth
wants to merge
3
commits into
weDevsOfficial:develop
Choose a base branch
from
sapayth:feat/block_doc_navigaction
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
Changes from all commits
Commits
Show all changes
3 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
There are no files selected for viewing
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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| <?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '5c13835270f8b2070a23'); | ||
| <?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'c6bbe77b5153f76a3dd4'); |
Large diffs are not rendered by default.
Oops, something went wrong.
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,122 @@ | ||
| { | ||
| "$schema": "https://schemas.wp.org/trunk/block.json", | ||
| "apiVersion": 3, | ||
| "name": "wedocs/wedocs-doc-navigation", | ||
| "version": "1.0.0", | ||
| "title": "weDocs - Doc Navigation", | ||
| "icon": "arrow-left-alt2", | ||
| "category": "widgets", | ||
| "description": "Display previous and next document navigation links", | ||
| "supports": { | ||
| "html": false, | ||
| "spacing": { | ||
| "padding": true, | ||
| "margin": true | ||
| }, | ||
| "border": { | ||
| "color": true, | ||
| "radius": true, | ||
| "style": true, | ||
| "width": true | ||
| }, | ||
| "color": { | ||
| "background": true | ||
| }, | ||
| "shadow": true | ||
| }, | ||
| "render": "file:./render.php", | ||
| "attributes": { | ||
| "seoLinks": { | ||
| "type": "string", | ||
| "default": "none" | ||
| }, | ||
| "navPadding": { | ||
| "type": "object", | ||
| "default": { | ||
| "top": "12px", | ||
| "right": "16px", | ||
| "bottom": "12px", | ||
| "left": "16px" | ||
| } | ||
| }, | ||
| "navMargin": { | ||
| "type": "object", | ||
| "default": { | ||
| "top": "0px", | ||
| "right": "0px", | ||
| "bottom": "0px", | ||
| "left": "0px" | ||
| } | ||
| }, | ||
| "navBorderStyle": { | ||
| "type": "string", | ||
| "default": "none" | ||
| }, | ||
| "navBorderRadius": { | ||
| "type": "string", | ||
| "default": "4px" | ||
| }, | ||
| "navBorderWidth": { | ||
| "type": "string", | ||
| "default": "1px" | ||
| }, | ||
| "navBorderColor": { | ||
| "type": "string", | ||
| "default": "#dddddd" | ||
| }, | ||
| "navBoxShadow": { | ||
| "type": "string", | ||
| "default": "none" | ||
| }, | ||
| "navigationTextColor": { | ||
| "type": "string", | ||
| "default": "#333333" | ||
| }, | ||
| "navigationTextHoverColor": { | ||
| "type": "string", | ||
| "default": "#0073aa" | ||
| }, | ||
| "navigationFontSize": { | ||
| "type": "string", | ||
| "default": "16px" | ||
| }, | ||
| "navigationFontWeight": { | ||
| "type": "string", | ||
| "default": "400" | ||
| }, | ||
| "navigationFontStyle": { | ||
| "type": "string", | ||
| "default": "normal" | ||
| }, | ||
| "arrowSize": { | ||
| "type": "string", | ||
| "default": "16px" | ||
| }, | ||
| "arrowColor": { | ||
| "type": "string", | ||
| "default": "#333333" | ||
| }, | ||
| "arrowBackgroundColor": { | ||
| "type": "string", | ||
| "default": "transparent" | ||
| }, | ||
| "arrowPadding": { | ||
| "type": "object", | ||
| "default": { | ||
| "top": "8px", | ||
| "right": "8px", | ||
| "bottom": "8px", | ||
| "left": "8px" | ||
| } | ||
| }, | ||
| "arrowMargin": { | ||
| "type": "object", | ||
| "default": { | ||
| "top": "0px", | ||
| "right": "8px", | ||
| "bottom": "0px", | ||
| "left": "0px" | ||
| } | ||
| } | ||
| } | ||
| } |
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,246 @@ | ||
| <?php | ||
| /** | ||
| * Render the doc navigation block on frontend | ||
| * | ||
| * @param array $attributes Block attributes | ||
| * @param string $content Block content | ||
| * @return string Rendered block content | ||
| */ | ||
| function render_wedocs_doc_navigation($attributes, $content = '') { | ||
| // Extract custom attributes with defaults | ||
| $seo_links = $attributes['seoLinks'] ?? 'none'; | ||
| $nav_padding = $attributes['navPadding'] ?? null; | ||
| $nav_margin = $attributes['navMargin'] ?? null; | ||
| $nav_border_style = $attributes['navBorderStyle'] ?? 'none'; | ||
| $nav_border_radius = $attributes['navBorderRadius'] ?? '4px'; | ||
| $nav_border_width = $attributes['navBorderWidth'] ?? '1px'; | ||
| $nav_border_color = $attributes['navBorderColor'] ?? '#dddddd'; | ||
| $nav_box_shadow = $attributes['navBoxShadow'] ?? 'none'; | ||
| $navigation_text_color = $attributes['navigationTextColor'] ?? '#333333'; | ||
| $navigation_text_hover_color = $attributes['navigationTextHoverColor'] ?? '#0073aa'; | ||
| $navigation_font_size = $attributes['navigationFontSize'] ?? '16px'; | ||
| $navigation_font_weight = $attributes['navigationFontWeight'] ?? '400'; | ||
| $navigation_font_style = $attributes['navigationFontStyle'] ?? 'normal'; | ||
| $arrow_size = $attributes['arrowSize'] ?? '16px'; | ||
| $arrow_color = $attributes['arrowColor'] ?? '#333333'; | ||
| $arrow_background_color = $attributes['arrowBackgroundColor'] ?? 'transparent'; | ||
| $arrow_padding = $attributes['arrowPadding'] ?? null; | ||
| $arrow_margin = $attributes['arrowMargin'] ?? null; | ||
|
|
||
| // Use the existing navigation function logic | ||
| global $post, $wpdb; | ||
|
|
||
| if (!$post || $post->post_type !== 'docs') { | ||
| return ''; | ||
| } | ||
|
|
||
| // Use improved navigation logic that handles menu_order = 0 | ||
| $navigation_posts = wedocs_get_doc_navigation_posts($post); | ||
| $next_post = $navigation_posts['next']; | ||
| $prev_post = $navigation_posts['prev']; | ||
|
|
||
| // Check if we have any navigation to show | ||
| if (!$prev_post && !$next_post) { | ||
| return ''; | ||
| } | ||
|
|
||
| // Get WordPress style system classes and styles | ||
| $wrapper_attributes = get_block_wrapper_attributes(); | ||
|
|
||
| // Extract WordPress style system attributes | ||
| $wp_style = $attributes['style'] ?? []; | ||
| $wp_background_color = $attributes['backgroundColor'] ?? null; | ||
| $wp_text_color = $attributes['textColor'] ?? null; | ||
| $wp_class_name = $attributes['className'] ?? ''; | ||
|
|
||
| // Build WordPress style system styles | ||
| $wp_styles = []; | ||
|
|
||
| // Handle WordPress background color | ||
| if ($wp_background_color) { | ||
| $wp_styles[] = sprintf('background-color: var(--wp--preset--color--%s);', esc_attr($wp_background_color)); | ||
| } | ||
|
|
||
| // Handle WordPress text color | ||
| if ($wp_text_color) { | ||
| $wp_styles[] = sprintf('color: var(--wp--preset--color--%s);', esc_attr($wp_text_color)); | ||
| } | ||
|
|
||
| // Handle WordPress spacing (padding/margin from style system) | ||
| if (isset($wp_style['spacing']['padding'])) { | ||
| $padding = $wp_style['spacing']['padding']; | ||
| if (is_array($padding)) { | ||
| $wp_styles[] = sprintf( | ||
| 'padding: %s %s %s %s;', | ||
| esc_attr($padding['top'] ?? '0'), | ||
| esc_attr($padding['right'] ?? '0'), | ||
| esc_attr($padding['bottom'] ?? '0'), | ||
| esc_attr($padding['left'] ?? '0') | ||
| ); | ||
| } else { | ||
| $wp_styles[] = sprintf('padding: %s;', esc_attr($padding)); | ||
| } | ||
| } | ||
|
|
||
| if (isset($wp_style['spacing']['margin'])) { | ||
| $margin = $wp_style['spacing']['margin']; | ||
| if (is_array($margin)) { | ||
| $wp_styles[] = sprintf( | ||
| 'margin: %s %s %s %s;', | ||
| esc_attr($margin['top'] ?? '0'), | ||
| esc_attr($margin['right'] ?? '0'), | ||
| esc_attr($margin['bottom'] ?? '0'), | ||
| esc_attr($margin['left'] ?? '0') | ||
| ); | ||
| } else { | ||
| $wp_styles[] = sprintf('margin: %s;', esc_attr($margin)); | ||
| } | ||
| } | ||
|
|
||
| // Handle WordPress border styles | ||
| if (isset($wp_style['border']['color'])) { | ||
| $wp_styles[] = sprintf('border-color: %s;', esc_attr($wp_style['border']['color'])); | ||
| } | ||
| if (isset($wp_style['border']['width'])) { | ||
| $wp_styles[] = sprintf('border-width: %s;', esc_attr($wp_style['border']['width'])); | ||
| } | ||
| if (isset($wp_style['border']['style'])) { | ||
| $wp_styles[] = sprintf('border-style: %s;', esc_attr($wp_style['border']['style'])); | ||
| } | ||
| if (isset($wp_style['border']['radius'])) { | ||
| $wp_styles[] = sprintf('border-radius: %s;', esc_attr($wp_style['border']['radius'])); | ||
| } | ||
|
|
||
| // Handle WordPress shadow | ||
| if (isset($wp_style['shadow'])) { | ||
| $wp_styles[] = sprintf('box-shadow: var(--wp--preset--shadow--%s);', esc_attr($wp_style['shadow'])); | ||
| } | ||
|
|
||
| // Combine WordPress styles | ||
| $wp_style_string = implode(' ', $wp_styles); | ||
|
|
||
| // Build custom styles for navigation items | ||
| $custom_nav_styles = []; | ||
|
|
||
| // Handle custom padding (always apply since WordPress style system doesn't have spacing in this case) | ||
| if ($nav_padding) { | ||
| $custom_nav_styles[] = sprintf( | ||
| 'padding: %s %s %s %s;', | ||
| esc_attr($nav_padding['top'] ?? '12px'), | ||
| esc_attr($nav_padding['right'] ?? '16px'), | ||
| esc_attr($nav_padding['bottom'] ?? '12px'), | ||
| esc_attr($nav_padding['left'] ?? '16px') | ||
| ); | ||
| } | ||
|
|
||
| // Handle custom margin (always apply since WordPress style system doesn't have spacing in this case) | ||
| if ($nav_margin) { | ||
| $custom_nav_styles[] = sprintf( | ||
| 'margin: %s %s %s %s;', | ||
| esc_attr($nav_margin['top'] ?? '0px'), | ||
| esc_attr($nav_margin['right'] ?? '0px'), | ||
| esc_attr($nav_margin['bottom'] ?? '0px'), | ||
| esc_attr($nav_margin['left'] ?? '0px') | ||
| ); | ||
| } | ||
|
|
||
| // Handle custom border styles | ||
| if ($nav_border_style !== 'none') { | ||
| $custom_nav_styles[] = sprintf( | ||
| 'border: %s %s %s; border-radius: %s;', | ||
| esc_attr($nav_border_width), | ||
| esc_attr($nav_border_style), | ||
| esc_attr($nav_border_color), | ||
| esc_attr($nav_border_radius) | ||
| ); | ||
| } | ||
|
|
||
| // Handle custom box shadow | ||
| if ($nav_box_shadow !== 'none') { | ||
| $custom_nav_styles[] = sprintf('box-shadow: %s;', esc_attr($nav_box_shadow)); | ||
| } | ||
|
|
||
| // Combine custom navigation styles | ||
| $nav_item_style = implode(' ', $custom_nav_styles); | ||
|
|
||
| // Build navigation text styles | ||
| $navigation_style = sprintf( | ||
| 'color: %s; font-size: %s; font-weight: %s; font-style: %s;', | ||
| esc_attr($navigation_text_color), | ||
| esc_attr($navigation_font_size), | ||
| esc_attr($navigation_font_weight), | ||
| esc_attr($navigation_font_style) | ||
| ); | ||
|
|
||
| // Add hover color CSS | ||
| $hover_css = ''; | ||
| if ($navigation_text_hover_color && $navigation_text_hover_color !== $navigation_text_color) { | ||
| $hover_css = sprintf( | ||
| '<style>.wedocs-doc-navigation a:hover .wedocs-doc-nav-title { color: %s !important; }</style>', | ||
| esc_attr($navigation_text_hover_color) | ||
| ); | ||
| } | ||
|
|
||
| // Build arrow styles | ||
| $arrow_styles = []; | ||
| $arrow_styles[] = sprintf('font-size: %s;', esc_attr($arrow_size)); | ||
| $arrow_styles[] = sprintf('color: %s;', esc_attr($arrow_color)); | ||
| $arrow_styles[] = sprintf('background-color: %s;', esc_attr($arrow_background_color)); | ||
|
|
||
| if ($arrow_padding) { | ||
| $arrow_styles[] = sprintf( | ||
| 'padding: %s %s %s %s;', | ||
| esc_attr($arrow_padding['top'] ?? '8px'), | ||
| esc_attr($arrow_padding['right'] ?? '8px'), | ||
| esc_attr($arrow_padding['bottom'] ?? '8px'), | ||
| esc_attr($arrow_padding['left'] ?? '8px') | ||
| ); | ||
| } | ||
|
|
||
| if ($arrow_margin) { | ||
| $arrow_styles[] = sprintf( | ||
| 'margin: %s %s %s %s;', | ||
| esc_attr($arrow_margin['top'] ?? '0px'), | ||
| esc_attr($arrow_margin['right'] ?? '8px'), | ||
| esc_attr($arrow_margin['bottom'] ?? '0px'), | ||
| esc_attr($arrow_margin['left'] ?? '0px') | ||
| ); | ||
| } | ||
|
|
||
| $arrow_style = implode(' ', $arrow_styles); | ||
|
|
||
| // Start output buffering | ||
| ob_start(); | ||
| ?> | ||
| <?php echo $hover_css; ?> | ||
| <div class="wedocs-document wedocs-doc-navigation-preview" <?php echo $wrapper_attributes; ?>> | ||
| <div class="wedocs-doc-navigation flex justify-between"<?php echo $wp_style_string ? ' style="' . esc_attr($wp_style_string) . '"' : ''; ?>> | ||
| <?php if ($prev_post) : ?> | ||
| <div class="wedocs-doc-nav-prev"<?php echo $nav_item_style ? ' style="' . esc_attr($nav_item_style) . '"' : ''; ?>> | ||
| <a href="<?php echo esc_url(get_permalink($prev_post->ID)); ?>" | ||
| <?php echo ($seo_links === 'prev_next') ? 'rel="prev"' : ''; ?>> | ||
| <span class="wedocs-doc-nav-arrow" style="<?php echo esc_attr($arrow_style); ?>">←</span> | ||
| <span class="wedocs-doc-nav-title" style="<?php echo esc_attr($navigation_style); ?>"> | ||
| <?php echo esc_html(apply_filters('wedocs_translate_text', $prev_post->post_title)); ?> | ||
| </span> | ||
| </a> | ||
| </div> | ||
| <?php endif; ?> | ||
|
|
||
| <?php if ($next_post) : ?> | ||
| <div class="wedocs-doc-nav-next"<?php echo $nav_item_style ? ' style="' . esc_attr($nav_item_style) . '"' : ''; ?>> | ||
| <a href="<?php echo esc_url(get_permalink($next_post->ID)); ?>" | ||
| <?php echo ($seo_links === 'prev_next') ? 'rel="next"' : ''; ?>> | ||
| <span class="wedocs-doc-nav-title" style="<?php echo esc_attr($navigation_style); ?>"> | ||
| <?php echo esc_html(apply_filters('wedocs_translate_text', $next_post->post_title)); ?> | ||
| </span> | ||
| <span class="wedocs-doc-nav-arrow" style="<?php echo esc_attr($arrow_style); ?>">→</span> | ||
| </a> | ||
| </div> | ||
| <?php endif; ?> | ||
| </div> | ||
| </div> | ||
|
|
||
| <?php | ||
| return ob_get_clean(); | ||
| } | ||
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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| <?php return array('dependencies' => array(), 'version' => '9452b96fb7f339eb0d86'); | ||
| <?php return array('dependencies' => array(), 'version' => '4888e42adffccfab29ad'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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.
Fix duplicate class attribute on wrapper; merge classes into get_block_wrapper_attributes.
Current markup yields two class= attributes, which is invalid HTML.
Also applies to: 229-231
🧰 Tools
🪛 PHPMD (2.15.0)
67-67: Avoid unused local variables such as '$wp_class_name'. (undefined)
(UnusedLocalVariable)
🤖 Prompt for AI Agents