Skip to content

Add Developer Actions and Filters - #766

Open
ronalfy wants to merge 16 commits into
westonruter:developfrom
DLXPlugins:feature/add-developer-actions-filters
Open

ronalfy wants to merge 16 commits into
westonruter:developfrom
DLXPlugins:feature/add-developer-actions-filters

Conversation

@ronalfy

@ronalfy ronalfy commented Oct 7, 2023

Copy link
Copy Markdown

This PR seeks to add several actions and filters that'll help others extend the block.

Resolves #488 #191

Background

I'd like to add a few addons for this plugin:

  1. Copy code functionality
  2. Code captions

I need several filters/actions to do this, hence this PR. I've put together a proof-of-concept of the first addon, which adds a copy button to the code block.

I've done my best to only insert actions/filters where needed. To see examples of some of these in use, please check out my addon code for this plugin: https://github.com/DLXPlugins/syntax-highlighting-code-block-copy-addon/blob/main/syntax-highlighting-code-block-copy-addon.php

Proof of Concept

dlx-000054

Please see repo release with attached ZIP files: https://github.com/DLXPlugins/syntax-highlighting-code-block-copy-addon/releases/tag/1.0.0

Thank you for considering this PR.

New Action: `syntax_highlighting_code_block_boot`. This action is run post boot after the `plugins_loaded` action has been executed. This is useful for letting others know when the plugin has finished its boot process in order to modify any early actions and filters the plugin uses.
…highlighting_code_block_injected_markup

New filter: `syntax_highlighting_code_block_transient_key` - This is for filtering the language param that's returned. See: westonruter#191
New filter: `syntax_highlighting_code_block_injected_markup` - This is for being able to modify the output before its returned. This is to help those who want to extend the markup or introduce their own.
New action: `syntax_highlighting_code_block_highlighter_init` - Fires in the `render_block` function after the highlighter has been initialized. Helps fix: westonruter#191
…nguage names.

Filter: `syntax_highlighting_code_block_language_names` - Resolves issue: westonruter#488
Filter `syntax_highlighting_code_block_injected_markup` is added to the output for the highlighted portion.
Filter: `syntaxHighlightingCodeBlockAttributes` allows you to set defaults for the code block.
Filter `syntax_highlighting_code_block_pre_start_tag` is for adding markup to pre tag and honoring block alignment.
Filter `syntax_highlighting_code_block_code_classes` allows you to add custom classes to the `code` element.
Remove filter `syntax_highlighting_code_block_pre_start_tag` as pre tag is not designed to have extra markup injected.

@westonruter westonruter left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Could you surface the commit messages in which you explain the reasons for the new hooks to be PR description? This will make sure they aren't buried. You can then add the GitHub Closes #... annotations to the description to link the PR to the issues that it closes.

Lastly, for the extension plugin you made, it doesn't seem like you actually need any of the filters you're introducing here. You can just use the render_block_core/code filter to inject your desired markup along with the HTML API introduced in WordPress 6.2.

@ronalfy

ronalfy commented Oct 9, 2023 via email

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow filtering to reduce the total number of languages listed

3 participants

Sponsor
SponsoredKunjungi sekarang
Promo