Category: WordPress
-
Deleting Old Post Revisions in WordPress with WP-CLI
in WordPressWorking with a client’s large database, I crafted a custom WP-CLI command to purge post revisions based on specific criteria, saving backups of those deleted. This script efficiently prunes revisions older than a year and prior to post publication, reducing the overall database size prior to a site migration.
-
Debugging WordPress Hooks: Speed
in WordPressLearn how to measure the execution time of WordPress hooks with precision by capturing individual callback durations. Find out how to set up a timeline for targeted hooks and track start and stop times for each. Be cautious of potential overhead and conflicts with plugins using hook priorities. Utilize the provided PHP code to implement…
-
WordPress Post Meta and JSON
in WordPressLearn about the challenges of storing JSON strings in WordPress post meta. Discover how WordPress’s `wp_unslash()` function can unintentionally interfere with the data. Find out how to safely store JSON by using `wp_slash()` to double-encode it, ensuring data integrity when unslashing.
-
Better Caching in WordPress
in WordPressCaching data in WordPress is essential for performance. Using the Transients API is common but using the WP_Object_Cache functions can offer more flexibility, especially for scenarios like API data changes. Additionally, caching too much data can lead to inefficiencies, so optimizing cache object size can significantly improve performance.
-
Quick Tip: DreamHost cron and WP-CLI
in WordPressEnsure your WordPress cron events fire correctly on DreamHost by setting the correct PHP version in your code. Be mindful of PHP compatibility issues between your code and the version running via WP-CLI in DreamHost’s cron system to avoid syntax errors like “unexpected ‘?’.” Use the `WP_CLI_PHP` environment variable to specify the PHP version needed…