{"id":29651268,"url":"https://github.com/arraypress/wp-meta-utils","last_synced_at":"2025-07-22T05:06:29.504Z","repository":{"id":303300030,"uuid":"1012564451","full_name":"arraypress/wp-meta-utils","owner":"arraypress","description":"A lightweight WordPress library for comprehensive meta data management across all meta types with advanced operations and type safety.","archived":false,"fork":false,"pushed_at":"2025-07-06T21:14:15.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-06T22:24:51.031Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arraypress.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-02T14:21:07.000Z","updated_at":"2025-07-06T21:14:18.000Z","dependencies_parsed_at":"2025-07-06T22:25:08.975Z","dependency_job_id":"dfe6c54c-b81f-41e7-861e-491ef1187b97","html_url":"https://github.com/arraypress/wp-meta-utils","commit_stats":null,"previous_names":["arraypress/wp-meta-utils"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arraypress/wp-meta-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fwp-meta-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fwp-meta-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fwp-meta-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fwp-meta-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arraypress","download_url":"https://codeload.github.com/arraypress/wp-meta-utils/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fwp-meta-utils/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266430670,"owners_count":23927169,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-22T05:06:28.828Z","updated_at":"2025-07-22T05:06:29.483Z","avatar_url":"https://github.com/arraypress.png","language":"PHP","readme":"# WordPress Meta Utilities\n\nA lightweight WordPress library for working with metadata across all WordPress meta types (post, user, term, comment). Provides clean APIs for essential meta operations, bulk management, pattern-based operations, and advanced array handling with WordPress-style simplicity.\n\n## Features\n\n* 🎯 **Universal Support**: Works seamlessly with all WordPress meta types (post, user, term, comment)\n* 🚀 **Core Operations**: Essential CRUD with type casting and defaults\n* 📊 **Bulk Management**: Process multiple meta entries and objects efficiently\n* 🔍 **Pattern Matching**: Delete and retrieve by prefix patterns\n* 📈 **Advanced Arrays**: Comprehensive array manipulation (append, remove, nested operations)\n* 🔢 **Numeric Operations**: Increment, decrement with automatic initialization\n* 🔄 **JSON Support**: Seamless JSON encoding/decoding for complex data\n* 📋 **Search \u0026 Analysis**: Find objects by meta values, statistical analysis\n* 🧹 **Cleanup Tools**: Pattern-based deletion and maintenance operations\n\n## Installation\n\n```bash\ncomposer require arraypress/wp-meta-utils\n```\n\n## Quick Start\n\n### Basic Meta Operations\n\n```php\nuse ArrayPress\\MetaUtils\\Meta;\n\n// Basic CRUD - works with any meta type\n$exists = Meta::exists( 'post', 123, 'featured' );\n$value  = Meta::get( 'post', 123, 'featured' );\nMeta::update( 'post', 123, 'featured', true );\nMeta::delete( 'post', 123, 'featured' );\n\n// Get with defaults and type casting\n$view_count  = Meta::get_cast( 'post', 123, 'view_count', 'int', 0 );\n$settings    = Meta::get_cast( 'user', 456, 'preferences', 'array', [] );\n$is_featured = Meta::get_cast( 'post', 123, 'featured', 'bool', false );\n\n// Increment counters and toggle flags\n$new_views  = Meta::increment( 'post', 123, 'view_count' );\n$new_status = Meta::toggle( 'post', 123, 'featured' );\n```\n\n### Bulk Operations\n\n```php\nuse ArrayPress\\MetaUtils\\Metas;\n\n// Get multiple meta values for one object\n$meta_data = Metas::get( 'post', 123, [ 'title', 'description', 'featured' ] );\n\n// Update multiple values at once\n$updates      = [\n\t'title'      =\u003e 'New Title',\n\t'featured'   =\u003e true,\n\t'view_count' =\u003e 100\n];\n$updated_keys = Metas::update( 'post', 123, $updates );\n\n// Bulk operations across multiple objects\n$post_ids    = [ 123, 456, 789 ];\n$view_counts = Metas::bulk_get( 'post', $post_ids, 'view_count' );\nMetas::bulk_update( 'post', $post_ids, 'featured', true );\n\n// Find objects by meta value\n$featured_posts = Metas::find_objects_by_value( 'post', 'featured', true );\n```\n\n## Comprehensive Examples\n\n### E-commerce Product Management\n\n```php\n// Product inventory management\n$product_id = 123;\n\n// Get product data with type safety\n$price      = Meta::get_cast( 'post', $product_id, 'price', 'float', 0.00 );\n$stock      = Meta::get_cast( 'post', $product_id, 'stock_count', 'int', 0 );\n$categories = Meta::get_cast( 'post', $product_id, 'categories', 'array', [] );\n\n// Process sale - decrement stock\n$new_stock = Meta::decrement( 'post', $product_id, 'stock_count', 1 );\nif ( $new_stock \u003c= 0 ) {\n\tMeta::update( 'post', $product_id, 'in_stock', false );\n\n\t// Add to out-of-stock list\n\tMeta::array_append( 'post', $product_id, 'notifications', 'out_of_stock' );\n}\n\n// Track product analytics\nMeta::increment( 'post', $product_id, 'view_count' );\nMeta::increment( 'post', $product_id, 'sales_count' );\n\n// Update product categories\nif ( ! Meta::array_contains( 'post', $product_id, 'categories', 'bestseller' ) ) {\n\tMeta::array_append( 'post', $product_id, 'categories', 'bestseller' );\n}\n```\n\n### User Preferences and Activity\n\n```php\n$user_id = 456;\n\n// Complex user settings with nested data\n$preferences = [\n\t'notifications' =\u003e [\n\t\t'email' =\u003e true,\n\t\t'sms'   =\u003e false,\n\t\t'push'  =\u003e true\n\t],\n\t'display'       =\u003e [\n\t\t'theme'    =\u003e 'dark',\n\t\t'language' =\u003e 'en'\n\t]\n];\nMeta::set_json( 'user', $user_id, 'preferences', $preferences );\n\n// Get nested preference\n$email_enabled = Meta::get_nested( 'user', $user_id, 'preferences', 'notifications.email', false );\n\n// Update specific nested value\nMeta::set_nested( 'user', $user_id, 'preferences', 'display.theme', 'light' );\n\n// Track user activity\nMeta::increment( 'user', $user_id, 'login_count' );\nMeta::array_append( 'user', $user_id, 'recent_posts', $post_id );\n\n// Manage user favorites\nMeta::array_append( 'user', $user_id, 'favorites', $product_id );\n$favorite_count = Meta::array_count( 'user', $user_id, 'favorites' );\n```\n\n### Content Management System\n\n```php\n// SEO and content management\n$post_id = 789;\n\n// Batch update SEO data\n$seo_data = [\n\t'seo_title'        =\u003e 'Optimized Title',\n\t'meta_description' =\u003e 'SEO description',\n\t'focus_keyword'    =\u003e 'wordpress',\n\t'canonical_url'    =\u003e 'https://example.com/post'\n];\n$updated  = Metas::update( 'post', $post_id, $seo_data );\n\n// Track content performance\nMeta::increment( 'post', $post_id, 'social_shares' );\nMeta::array_append( 'post', $post_id, 'referrers', $_SERVER['HTTP_REFERER'] ?? 'direct' );\n\n// Content flags and status\nMeta::toggle( 'post', $post_id, 'needs_review' );\n$review_status = Meta::is_truthy( 'post', $post_id, 'needs_review' );\n\n// Related content management\n$related_posts = Meta::get_cast( 'post', $post_id, 'related_posts', 'array', [] );\nif ( count( $related_posts ) \u003c 5 ) {\n\tMeta::array_append( 'post', $post_id, 'suggested_related', $related_post_id );\n}\n```\n\n### Analytics and Reporting\n\n```php\n// Content analytics across multiple posts\n$post_ids = [ 100, 101, 102, 103, 104 ];\n\n// Get view statistics\n$stats = Metas::get_stats( 'post', $post_ids, 'view_count' );\n// Returns: count, numeric_values, min, max, average, sum\n\n// Compare engagement across posts\n$comparison = Metas::compare_values( 'post', $post_ids, 'engagement_score' );\n// Returns: values, unique_values, value_counts, objects_with_meta, objects_without_meta\n\n// Find high-performing content\n$popular_posts    = Metas::find_objects_by_value( 'post', 'view_count', 1000, '\u003e' );\n$featured_content = Metas::find_objects_by_value( 'post', 'featured', true );\n\n// Bulk operations for maintenance\n$large_meta = Metas::find_large( 'post', $post_id, 500000 ); // Find meta \u003e 500KB\nMetas::delete_by_prefix( 'post', 'temp_' ); // Clean temporary data\n```\n\n### Advanced Array Operations\n\n```php\n// Managing complex arrays\n$post_id = 123;\n\n// Tags management\nMeta::array_append( 'post', $post_id, 'tags', 'wordpress' );\nMeta::array_append( 'post', $post_id, 'tags', 'php' );\n\n// Remove outdated tags\nMeta::array_remove( 'post', $post_id, 'tags', 'old-tag' );\nMeta::array_remove_all( 'post', $post_id, 'tags', 'deprecated' );\n\n// Clean up duplicates\nMeta::array_unique( 'post', $post_id, 'tags' );\n\n// Check content and count\n$has_wp_tag = Meta::array_contains( 'post', $post_id, 'tags', 'wordpress' );\n$tag_count  = Meta::array_count( 'post', $post_id, 'tags' );\n\n// Nested array operations\n$metadata = [\n\t'seo'    =\u003e [ 'title' =\u003e 'Page Title', 'description' =\u003e 'Page Description' ],\n\t'social' =\u003e [ 'twitter' =\u003e '@username', 'facebook' =\u003e 'page-id' ]\n];\nMeta::update( 'post', $post_id, 'page_meta', $metadata );\n\n// Access nested data\n$twitter_handle = Meta::get_nested( 'post', $post_id, 'page_meta', 'social.twitter' );\nMeta::set_nested( 'post', $post_id, 'page_meta', 'seo.title', 'Updated Title' );\n```\n\n### System Maintenance and Migration\n\n```php\n// Data migration and cleanup\n$post_ids = [ 1, 2, 3, 4, 5 ];\n\n// Migrate old meta keys\nforeach ( $post_ids as $post_id ) {\n\tMeta::migrate_key( 'post', $post_id, 'old_view_count', 'view_count' );\n\tMeta::migrate_key( 'post', $post_id, 'legacy_status', 'current_status' );\n}\n\n// Backup critical meta before changes\n$backup = Metas::backup( 'post', 123, [ 'title', 'content', 'featured' ] );\n// ... perform risky operations ...\nMetas::restore( 'post', 123, $backup ); // Restore if needed\n\n// System-wide cleanup\nMetas::delete_by_prefix( 'post', 'cache_' );     // Remove all cache entries\nMetas::delete_by_prefix( 'user', 'temp_' );      // Remove temporary user data\n\n// Performance monitoring\n$large_meta = Metas::find_large( 'post', 123, 1048576 ); // Find meta \u003e 1MB\nforeach ( $large_meta as $key =\u003e $size ) {\n\terror_log( \"Large meta found: {$key} ({$size} bytes)\" );\n}\n```\n\n## API Reference\n\n### Meta Class Methods (Single Entry Operations)\n\n**Core Operations:**\n- `exists( $meta_type, $object_id, $meta_key )` - Check if meta exists\n- `get( $meta_type, $object_id, $meta_key, $single )` - Get meta value\n- `get_with_default( $meta_type, $object_id, $meta_key, $default )` - Get with fallback\n- `get_cast( $meta_type, $object_id, $meta_key, $cast_type, $default )` - Get with type casting\n- `update( $meta_type, $object_id, $meta_key, $meta_value )` - Update meta\n- `update_if_changed( $meta_type, $object_id, $meta_key, $meta_value )` - Conditional update\n- `delete( $meta_type, $object_id, $meta_key )` - Delete meta\n\n**Numeric Operations:**\n- `increment( $meta_type, $object_id, $meta_key, $amount )` - Increment value\n- `decrement( $meta_type, $object_id, $meta_key, $amount )` - Decrement value\n\n**Array Operations:**\n- `array_contains( $meta_type, $object_id, $meta_key, $value )` - Check if array contains value\n- `array_append( $meta_type, $object_id, $meta_key, $value )` - Add to array\n- `array_remove( $meta_type, $object_id, $meta_key, $value )` - Remove from array\n- `array_remove_all( $meta_type, $object_id, $meta_key, $value )` - Remove all occurrences\n- `array_unique( $meta_type, $object_id, $meta_key )` - Remove duplicates\n- `array_count( $meta_type, $object_id, $meta_key )` - Count array items\n\n**Nested Operations:**\n- `get_nested( $meta_type, $object_id, $meta_key, $key, $default )` - Get nested value\n- `set_nested( $meta_type, $object_id, $meta_key, $key, $value )` - Set nested value\n- `remove_nested( $meta_type, $object_id, $meta_key, $key )` - Remove nested key\n\n**JSON Operations:**\n- `get_json( $meta_type, $object_id, $meta_key, $default )` - Get as JSON array\n- `set_json( $meta_type, $object_id, $meta_key, $value )` - Set as JSON\n\n**Boolean Operations:**\n- `is_truthy( $meta_type, $object_id, $meta_key, $default )` - Check if truthy\n- `toggle( $meta_type, $object_id, $meta_key )` - Toggle boolean value\n\n**Utility Methods:**\n- `get_type( $meta_type, $object_id, $meta_key )` - Get value type\n- `get_size( $meta_type, $object_id, $meta_key )` - Get size in bytes\n- `is_type( $meta_type, $object_id, $meta_key, $type )` - Check value type\n- `is_large( $meta_type, $object_id, $meta_key, $size_limit )` - Check if large\n- `migrate_key( $meta_type, $object_id, $old_key, $new_key, $delete_old )` - Migrate meta key\n\n### Metas Class Methods (Bulk Operations)\n\n**Core Operations:**\n- `get( $meta_type, $object_id, $meta_keys, $single )` - Get multiple meta values\n- `get_all( $meta_type, $object_id )` - Get all meta for object\n- `update( $meta_type, $object_id, $meta_values, $skip_unchanged )` - Update multiple values\n- `delete( $meta_type, $object_id, $meta_keys )` - Delete multiple keys\n\n**Backup \u0026 Restore:**\n- `backup( $meta_type, $object_id, $meta_keys )` - Backup meta values\n- `restore( $meta_type, $object_id, $backup )` - Restore from backup\n\n**Pattern Operations:**\n- `get_by_prefix( $meta_type, $object_id, $prefix, $with_values )` - Get by prefix\n- `delete_by_prefix( $meta_type, $prefix )` - Delete by prefix\n\n**Bulk Operations:**\n- `bulk_get( $meta_type, $object_ids, $meta_key )` - Get meta for multiple objects\n- `bulk_update( $meta_type, $object_ids, $meta_key, $meta_value )` - Update multiple objects\n- `bulk_delete( $meta_type, $object_ids, $meta_key )` - Delete from multiple objects\n\n**Analysis \u0026 Search:**\n- `find_large( $meta_type, $object_id, $size_limit )` - Find large meta entries\n- `find_objects_by_value( $meta_type, $meta_key, $meta_value, $compare )` - Find objects by meta\n- `compare_values( $meta_type, $object_ids, $meta_key )` - Compare across objects\n- `get_stats( $meta_type, $object_ids, $meta_key )` - Statistical analysis\n\n## Supported Type Casting\n\nThe `get_cast()` method supports these types:\n- `'int'` or `'integer'` - Cast to integer\n- `'float'` or `'double'` - Cast to float\n- `'bool'` or `'boolean'` - Cast to boolean\n- `'array'` - Cast to array\n- `'string'` - Cast to string\n\n## Supported Meta Types\n\nAll methods work with these WordPress meta types:\n- `'post'` - Post meta (wp_postmeta table)\n- `'user'` - User meta (wp_usermeta table)\n- `'term'` - Term meta (wp_termmeta table)\n- `'comment'` - Comment meta (wp_commentmeta table)\n\n## When to Use What\n\n### Use Meta class for:\n- **Single meta operations** on individual objects\n- **Type-safe retrieval** with casting and defaults\n- **Array manipulation** without manual serialization\n- **Numeric counters** and boolean flags\n- **Nested data access** with dot notation\n\n```php\n// Type-safe operations\n$count    = Meta::get_cast( 'post', 123, 'view_count', 'int', 0 );\n$settings = Meta::get_cast( 'user', 456, 'preferences', 'array', [] );\n\n// Array operations\nMeta::array_append( 'post', 123, 'tags', 'new-tag' );\n$has_tag = Meta::array_contains( 'post', 123, 'tags', 'wordpress' );\n```\n\n### Use Metas class for:\n- **Bulk operations** across multiple objects or meta keys\n- **System maintenance** and cleanup\n- **Data analysis** and reporting\n- **Pattern-based operations**\n\n```php\n// Bulk operations\n$view_counts = Metas::bulk_get( 'post', [ 1, 2, 3 ], 'view_count' );\nMetas::delete_by_prefix( 'post', 'temp_' );\n\n// Analysis\n$stats    = Metas::get_stats( 'post', $post_ids, 'engagement_score' );\n$featured = Metas::find_objects_by_value( 'post', 'featured', true );\n```\n\n## Best Practices\n\n### Performance Optimization\n- Use bulk operations when working with multiple objects\n- Leverage `update_if_changed()` to avoid unnecessary database writes\n- Use type casting to ensure consistent data types\n- Monitor large meta entries with `find_large()`\n\n### Data Integrity\n- Always use defaults with `get_with_default()` or `get_cast()`\n- Use `backup()` and `restore()` for critical operations\n- Validate data types with `is_type()` before processing\n- Use `migrate_key()` for safe meta key transitions\n\n### Code Organization\n- Use consistent meta key naming patterns\n- Group related meta operations in transactions when possible\n- Use prefix patterns for easy cleanup and maintenance\n- Document meta key purposes and expected data types\n\n## Requirements\n\n- PHP 7.4+\n- WordPress 5.0+\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the GPL-2.0-or-later License.\n\n## Support\n\n- [Documentation](https://github.com/arraypress/wp-meta-utils)\n- [Issue Tracker](https://github.com/arraypress/wp-meta-utils/issues)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farraypress%2Fwp-meta-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farraypress%2Fwp-meta-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farraypress%2Fwp-meta-utils/lists"}