3

If you're adding theme support for editor-color-palette then you need to add styles for those colours to your stylesheet. As documented: Themes are responsible for creating the classes that apply the colors in different contexts. Core blocks use “color” and “background-color” contexts. So to correctly apply “strong magenta” to all contexts of core blocks a ...


3

I'm answering myself for the benefit of others. I was passing an array of post type slugs to apiFetch instead of passing an array with their rest_base parameter. So, the correct function should be: const postTypes = useSelect( ( select ) => { const { getPostTypes } = select( 'core' ); const excludedPostTypes = [ 'attachment' ]; const ...


2

My question is, is there a similar selector for when you don't know the post type of a post beforehand? No, at the current time of writing there is not. The fundamental problem is that the REST API doesn't provide a generic mechanism for getting a post type given a post ID. You can retrieve a post and it will say post but to do this you need to know the ...


2

Short Answer The second parameter for useSelect is the second parameter for useCallback, so check the React website and you'd understand what the heck that second parameter is.. :) Long Answer useSelect is a custom React hook which uses the core useCallback hook in React which returns a memoized callback which can avoid expensive calculations on every render,...


2

This took me a while to figure out... It's a bug. The JavaScript error occurs because the onFilterValueChange function is not defined... Even though the WordPress documentation says this function is optional. Simply adding onFilterValueChange with an anonymous function removes the JavaScript error. E.g. <ComboboxControl label="Font Size" ...


2

Explanation of the issues in your code: The main one which causes the block editor to crash, is because you used InnerBlocks in the save function. You should instead use InnerBlocks.Content. See this and this for more details on InnerBlocks usage, accepted props, etc. As for the getAttribute error, it's because you did not use useBlockProps in the edit ...


2

It is! I've toyed with this off and on for the last year or so, and have come up with a few different ways to accomplish it. These are just the products of my own fiddling, however - there may well be more compelling solutions out there. Given the direction of @wordpress/scripts development, I would expect this use-case to become easier down the road. NOTE: ...


2

You can use the admin_body_class hook to add your own CSS classes. For example (if you're using Gutenberg): function pb_admin_body_class($classes) { $screen = get_current_screen(); if (!$screen->is_block_editor()) { return $classes; } $post_id = isset($_GET['post']) ? intval($_GET['post']) : false; $post_type = get_post_type($...


2

You can eliminate the wrapping containers abandoning InnerBlocks and instead using the useInnerBlocksProps hook which is how the blocks that come with core do it. This will allow your block markup to match the frontend without the editor wrapping things in additional tags. If we look at the official buttons block: import { BlockControls, ...


1

*This is a supplemental answer to the accepted answer, so to OP, take this as a supplemental vitamin to the main one as prescribed by the doctor... :p So in reply to your comment: Is it possible to have additional elements in there? I have RichText and InspectorControls. From what I can tell, the return <div { ...innerBlocksProps } />; can't have ...


1

I assume it's because I need onSelect added, but I'm not sure what to do. What do I need to add to make it so when the user clicks on the variation it's entered in the editor? One way, is add a variation attribute to your block type, then change the attribute value in the onSelect callback of the variation picker. That in turn will instruct React to re-...


1

The main issue in your code is the following part, whereby you set the attribute source to text which means (after the block/post is saved) the editor will read the value from the inner text of the div returned by your save function: attributes: { content: { type: "string", source: "text", // this shouldn't be "...


1

You are looking for: is_plugin_active( string $plugin ) This function takes a string parameter that is the representation of the path to the plugin relative path in the plugins directory. So your practical implementation would look something like this: <?php if(is_plugin_active('elementor/elementor.php') || is_plugin_active('woocommerce/woocommerce.php'))...


1

Instead of doing multiple apiFetch calls for each post type, a more optimal solution to make a search across multiple post types is to use the WP REST API search endpoint, which I didn't know it existed until now. The downside is that you don't get the full post objects using this endpoint, but if you only need the post id, title, url and type, it's ok: ...


1

It's Not (Reasonably) Possible (Yet) :( This was such an interesting question to dig into. In short, we can get really, really close to accomplishing this using Block Filters and some hackish duct-tape on the PHP side. But it falls apart in the home stretch. It's worth noting that the crux of the complication is specific to the Latest Posts block's ...


1

Excerpt from "Creating dynamic blocks" in the block editor handbook: The server-side rendering is a function taking the block and the block inner content as arguments, and returning the markup (quite similar to shortcodes) So despite the "render" as in render_callback, a block render callback should not actually echo anything (and ...


1

I'm getting a Promise with the post object inside when I do a console.log( mypost ) Yes, because apiFetch() indeed returns a Promise object, and apiFetch() doesn't assign the response received from the server to the mypost constant, and the return value of your then() callback is also not going to be assigned to the mypost variable. How can I get the post ...


1

Of course, five minutes after I post the question, I find a solution: Using wp_deregister_style('wp-block-library') (instead of wp_dequeue_style('wp-block-library')) works for the block editor. It worked in either an admin_init or an admin_enqueue_scripts action.


1

UrlInput uses LinkControl internally, but neither have been built with the sidebar in mind, they're to be used inside popover components that appear inline such as when a toolbar button is clicked. They aren't intended to appear directly in toolbars either. Most if not all input components can't be shown in the toolbar, with the exception of buttons for ...


1

add these lines in your 'functions.php', it will work //if not gutenberg reapprove posts add_filter( 'wp_insert_post_data', 're_aprove', '99', 2 ); function re_aprove( $data, $postarr ) { //check if current user is not admin if ( ! current_user_can( 'manage_options' ) ) { if ( 'publish' === $data['post_status'] ) { $data['...


1

When you do this: '_related_posts': [post.id], you're actually overriding the entire array or the meta value, so to instead append an item to the existing array, you can use the spread (...) syntax like so: '_related_posts': [ ...meta._related_posts, post.id ]. But you may want not want to update the meta if the selected post ID is already in the current ...


Only top voted, non community-wiki answers of a minimum length are eligible