A lightweight, performant, and extensible posts grid block for WordPress, built with modern development practices.
- Modern Architecture: Clean separation of concerns with PSR-4 autoloading
- Performance Optimized: Built-in caching, lazy loading, and optimized queries
- Developer Friendly: Extensive hooks and filters for customization
- Modern WordPress: Built specifically for the block editor
- Security First: Proper data sanitization, escaping, and permission checks
- REST API: Complete REST API with rate limiting
- No Dependencies: No jQuery or external CSS frameworks
includes/
├── Core/
│ ├── AssetManager.php # Handles all asset loading
│ ├── CacheManager.php # Caching functionality
│ └── HooksManager.php # Extensibility hooks
├── Blocks/
│ ├── BlockRegistry.php # Block registration
│ └── BlockRenderer.php # Rendering logic
├── Api/
│ └── RestController.php # REST API endpoints
- Transient-based caching with object cache support
- Automatic cache invalidation on post updates
- Admin bar integration for manual cache clearing
- Rate limiting for REST API endpoints
- Proper permission callbacks
- CSRF protection
- Data sanitization throughout
- Conditional asset loading
- Lazy loading support
- Optimized database queries
- CSS custom properties for efficient theming
postgrid_before_grid- Before grid outputpostgrid_after_grid- After grid outputpostgrid_before_item- Before each itempostgrid_after_item- After each itempostgrid_init- Plugin initializationpostgrid_loaded- After plugin loads
postgrid_query_args- Modify WP_Query argumentspostgrid_supported_post_types- Add custom post typespostgrid_supported_taxonomies- Add custom taxonomiespostgrid_cache_expiration- Set cache durationpostgrid_item_classes- Modify item CSS classespostgrid_grid_classes- Modify grid CSS classes
add_filter( 'postgrid_supported_post_types', function( $post_types ) {
$post_types[] = 'product';
$post_types[] = 'portfolio';
return $post_types;
} );add_filter( 'postgrid_query_args', function( $args, $attributes ) {
// Only show posts from specific authors
$args['author__in'] = array( 1, 2, 3 );
return $args;
}, 10, 2 );add_action( 'postgrid_after_item', function( $post, $attributes ) {
echo '<div class="custom-content">';
echo get_post_meta( $post->ID, 'custom_field', true );
echo '</div>';
}, 10, 2 );add_filter( 'postgrid_cache_expiration', function() {
return 10 * MINUTE_IN_SECONDS;
} );POST /wp-json/postgrid/v1/posts
Parameters:
per_page(int) - Number of postsorderby(string) - Sort fieldorder(string) - Sort ordercategory(int) - Category IDpost_type(string) - Post typesearch(string) - Search terms
GET /wp-json/postgrid/v1/categories
GET /wp-json/postgrid/v1/post-types
Run PHPUnit tests:
composer testRun JavaScript tests:
npm run test:unit- Page Load: < 50ms render time
- Asset Size: < 10KB CSS, < 20KB JS
- Database Queries: 1-2 queries per block
- Cache Hit Rate: > 90% on typical usage
- Chrome/Edge (last 2 versions)
- Firefox (last 2 versions)
- Safari (last 2 versions)
- Mobile browsers (iOS Safari, Chrome Android)
- Fork the repository
- Create a feature branch
- Write tests for new functionality
- Ensure all tests pass
- Submit a pull request
GPL v2 or later