Skip to content
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

Parse PHP code via block different way #11527

Closed
StaggerLeee opened this issue Nov 6, 2018 · 4 comments
Closed

Parse PHP code via block different way #11527

StaggerLeee opened this issue Nov 6, 2018 · 4 comments
Labels
New Block Suggestion for a new block [Status] Not Implemented Issue/PR we will (likely) not implement. [Type] Enhancement A suggestion for improvement.

Comments

@StaggerLeee
Copy link

As it is meant to be full blooded visual theme maker/editor I suggest you make it easy to parse PHP code via one custom block. And for now to not to do it via shortcodes.
I know directly writing PHP code in block will never be allowed.

  • Something so simple as "Functions Block". (in custom functions.php)

  • It can be hidden, to not to force it to Users and clutter space for people who will not need it. Will be used mostly by developers.

  • function some_function () { echo 'some other code'; } add_filter('init', 'some_function');

  • Insert Functions block and in input field write name of the function: some_function.

Some easy way to parse PHP code via Block would be needed for visual theme editor. Shortcodes are OK, but in some cases complicated to convert to. And in some cases stubborn to work OK.

@designsimply designsimply added [Type] Enhancement A suggestion for improvement. [Block] Code Affects the Code Block labels Nov 6, 2018
@designsimply
Copy link
Member

Apologies in advance if I'm not understanding exactly on a first pass. I'm actually pretty sure I read this incorrectly before when I labeled this issue with [Block] Code which I now think is wrong. It's worth noting that we are not yet at the stage of being a theme maker or editor. Right now, the only thing being introduced is a block editor. The block editor is only for writing content in posts at this stage and will become the foundation for a page layout editor later—that is the next phase which has not been fully scoped yet. (You may already know this.)

Since you mention theming and functions.php, it sounds like you are looking for functionality similar to the Appearance > Editor section that is currently available in WordPress wp-admin, only with a live preview. What I am not sure about is why you're mentioning shortcodes. One of Gutenberg's main goals is to eliminate the need for complicated shortcodes by using blocks instead. So I think we may be on the same page but just saying the same thing in a different way.

@designsimply designsimply added [Status] Needs More Info Follow-up required in order to be actionable. and removed [Block] Code Affects the Code Block [Type] Enhancement A suggestion for improvement. labels Nov 6, 2018
@chrisvanpatten
Copy link
Member

Hi @StaggerLeee

I think it's unlikely that core will support this specific use-case, but you could certainly write a custom block with a PHP render_callback that runs a PHP hook wherever it's inserted. You could also potentially use a filter, with an array of PHP closures/callables, to make it possible to select from a pre-defined list of functions.

Again I don't think core would ever include this block, but it would definitely be possible to build.

@StaggerLeee
Copy link
Author

StaggerLeee commented Nov 6, 2018

Hi.

It is something for all those weird things, snippets, and even plugins without Gutenberg support. Just one Block with text input field for function name. All PHP code would be dealt with in custom functions.php, or custom plugin. Of course preview would not be possible, then it would be real Block.
Something only for developers.
Would help a lot for thousands of those free and premium WordPress themes. To be able to insert custom PHP but not touch theme, to keep updates.

I know it is not something for Editor, talking about visual theme builder later when it comes.
New sidebar, say 2 different Gutenberg widget-blocks, and be able to insert custom PHP between them. But not to touch theme (updates, overwrites).

Yes, all those weird things where building complex and complicated Gutenberg real block is not justified. Or not worth it, timely. Or person cannot build Gutenberg blocks.

I will later check second suggestion, thanks. Select is not option, as it tends to be long list.

@designsimply designsimply added [Type] Enhancement A suggestion for improvement. New Block Suggestion for a new block [Status] Not Implemented Issue/PR we will (likely) not implement. and removed [Status] Needs More Info Follow-up required in order to be actionable. labels Nov 14, 2018
@designsimply
Copy link
Member

I see now that a custom block as @chrisvanpatten suggested is the correct advice here. I am closing this issue in favor of that advice. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Block Suggestion for a new block [Status] Not Implemented Issue/PR we will (likely) not implement. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

3 participants