+ * Current User Posts+ *+ * @package <your-brand>\CurrentUserPosts+ * @author <your-name>+ * @copyright <your-brand-and-year>+ * @license GPL-2.0-or-later+ *+ * @wordpress-plugin * Plugin Name: Current User Posts- * Description: Example block scaffolded with Create Block tool.+ * Description: Display the posts created by the current user.
* Version: 0.1.0
* Requires at least: 6.7
* Requires PHP: 7.4
- * Author: The WordPress Contributors+ * Author: <your-brand>+ * Author URI: <your-uri>
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
+ * Domain Path: /languages
* Text Domain: current-user-posts
- *- * @package CurrentUserPosts
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if access directly
}
/**
* Registers the block using a `blocks-manifest.php` file, which improves the performance of block type registration.
* Behind the scenes, it also registers all assets so they can be enqueued
* through the block editor in the corresponding context.
*+ * @since 0.1.0+ *+ * @return void+ * @action init
* @see https://make.wordpress.org/core/2025/03/13/more-efficient-block-type-registration-in-6-8/
* @see https://make.wordpress.org/core/2024/10/17/new-block-type-registration-apis-to-improve-performance-in-wordpress-6-7/
*/
-function current_user_posts_current_user_posts_block_init() {+function <your-brand>_current_user_posts_block_init() {
/**
* Registers the block(s) metadata from the `blocks-manifest.php` and registers the block type(s)
* based on the registered block metadata.
@@ -56,4 +68,47 @@ function current_user_posts_current_user_posts_block_init() {
register_block_type( __DIR__ . "/build/{$block_type}" );
}
}
-add_action( 'init', 'current_user_posts_current_user_posts_block_init' );+add_action( 'init', '<your-brand>_current_user_posts_block_init' );++/**+ * Load the includes for the block in the block Editor.+ *+ * @since 0.1.0+ * @return void+ * @action enqueue_block_editor_assets+ */++function <your-brand>_current_user_posts_enqueue_inc() {+/**+ * Enqueues a JavaScript filter that resets the query for the current-user Query Loop block variation.+ *+ * This ensures that the author field is automatically populated with the current user’s ID+ * after a Query Loop pattern is inserted.+ *+ * @see https://developer.wordpress.org/block-editor/reference-guides/filters/block-filters/#editor-blockedit+ */+wp_enqueue_script(+'<your-brand>-current-user-posts-query-filter',+plugins_url( '/inc/query-filter.js', __FILE__ ),+[ 'wp-blocks', 'wp-hooks', 'wp-compose', 'wp-data', 'wp-element' ],+1.0,+true+);++/**+ * Enqueue the script that registers the block variation.+ *+ * Removes the author control from the Query Loop block when using the custom variation.+ *+ * @see https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/extending-the-query-loop-block/+ */+wp_enqueue_script(+'<your-brand>-current-user-posts-query-variation',+plugins_url( '/inc/block-variation.js', __FILE__ ),+[ 'wp-blocks', 'wp-dom-ready', 'wp-edit-post' ],+1.0,+true+);+}++add_action( 'enqueue_block_editor_assets', '<your-brand>_current_user_posts_enqueue_inc' );