### Install Composer Dependencies Source: https://github.com/futtta/autoptimize/blob/beta/README.md Run this command to install project dependencies using Composer. ```bash composer install ``` -------------------------------- ### Install WordPress Test Suite Source: https://github.com/futtta/autoptimize/blob/beta/README.md Run this command to install the WordPress test suite required for Autoptimize testing. ```bash bin/install-wp-tests.sh ``` -------------------------------- ### Run WordPress Tests Installation Script Source: https://github.com/futtta/autoptimize/blob/beta/bin/readme-windows.txt Execute the `install-wp-tests.sh` script with necessary parameters to set up the WordPress test environment. ```bash C:\\PortableGit\\bin\\bash.exe bin/install-wp-tests.sh wordpress_test webodjel webber localhost 4.3.1 ``` -------------------------------- ### Basic Admin Notice Markup Source: https://github.com/futtta/autoptimize/blob/beta/classes/external/php/persist-admin-notices-dismissal/README.md Example of a standard WordPress admin notice markup before making it dismissible. ```php function sample_admin_notice__success() { ?>

getVcsApi()->enableReleaseAssets(); ``` -------------------------------- ### Build Plugin Update Checker Instance Source: https://github.com/futtta/autoptimize/blob/beta/classes/external/php/plugin-update-checker/README.md Instantiate the update checker for a plugin. Ensure the second argument is the absolute path to the main plugin file and the third is a unique slug. ```php require 'plugin-update-checker/plugin-update-checker.php'; $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker( 'https://github.com/user-name/repo-name/', __FILE__, 'unique-plugin-or-theme-slug' ); ``` -------------------------------- ### Initialize PAnD with Autoloader Source: https://github.com/futtta/autoptimize/blob/beta/classes/external/php/persist-admin-notices-dismissal/README.md When using an autoloader, ensure PAnD is initialized outside of 'admin_notices' or 'network_admin_notices' hooks. ```php add_action( 'admin_init', array( 'PAnD', 'init' ) ); ``` -------------------------------- ### Alternative NGINX Configuration for Autoptimize 404 Fallbacks Source: https://github.com/futtta/autoptimize/blob/beta/readme.txt An alternative NGINX configuration for Autoptimize's 404 fallback handler, specifically directing CSS and JS to their respective fallback files. This is useful for more granular control. ```nginx location ~* /wp-content/cache/autoptimize/.* .(css) { try_files $uri $uri/ /wp-content/cache/autoptimize/css/autoptimize_fallback.css; } location ~* /wp-content/cache/autoptimize/.* .(js) { try_files $uri $uri/ /wp-content/cache/autoptimize/js/autoptimize_fallback.js; } ``` -------------------------------- ### PHP Plugin Update Checker Initialization Source: https://github.com/futtta/autoptimize/blob/beta/classes/external/php/plugin-update-checker/README.md Initialize the Plugin Update Checker library in your main plugin file or functions.php. This requires the library and builds the checker instance pointing to your JSON details file. ```php require 'path/to/plugin-update-checker/plugin-update-checker.php'; $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker( 'http://example.com/path/to/details.json', __FILE__, //Full path to the main plugin file or functions.php. 'unique-plugin-or-theme-slug' ); ``` -------------------------------- ### Initialize Update Checker for Self-Hosted GitLab Source: https://github.com/futtta/autoptimize/blob/beta/classes/external/php/plugin-update-checker/README.md Initialize the update checker for a self-hosted GitLab instance. This requires specifying the GitLab API endpoint and the repository path. ```php $myUpdateChecker = new Puc_v4p9_Vcs_PluginUpdateChecker( new Puc_v4p9_Vcs_GitLabApi('https://myserver.com/user-name/repo-name/'), __FILE__, 'unique-plugin-or-theme-slug' ); //Optional: Add setAuthentication(...) and setBranch(...) as shown above. ``` -------------------------------- ### NGINX Configuration for Autoptimize 404 Fallbacks Source: https://github.com/futtta/autoptimize/blob/beta/readme.txt This NGINX configuration snippet helps prevent broken pages by serving fallback CSS/JS when Autoptimized files are not found. It should be added to your NGINX server block. ```nginx location ~* /wp-content/cache/autoptimize/.* .(js|css) { try_files $uri $uri/ /wp-content/autoptimize_404_handler.php; } ``` -------------------------------- ### Re-enable LQIP for Lazy Loaded Images Source: https://github.com/futtta/autoptimize/blob/beta/readme.txt By default, Autoptimize no longer sets a Low Quality Image Placeholder (LQIP) when optimizing images with lazy loading enabled, due to a minor performance penalty. Use this filter to re-enable LQIP if desired. ```php add_filter( 'autoptimize_filter_imgopt_lazyload_dolqip', '__return_true'); ``` -------------------------------- ### Plugin JSON Update Details Source: https://github.com/futtta/autoptimize/blob/beta/classes/external/php/plugin-update-checker/README.md Minimal JSON structure for a self-hosted plugin update. Includes essential fields like name, version, download URL, and description. ```json { "name" : "Plugin Name", "version" : "2.0", "download_url" : "http://example.com/plugin-name-2.0.zip", "sections" : { "description" : "Plugin description here. You can use HTML." } } ``` -------------------------------- ### Initialize Update Checker for GitLab Source: https://github.com/futtta/autoptimize/blob/beta/classes/external/php/plugin-update-checker/README.md Use this code to initialize the update checker for a public GitLab repository. Ensure you replace placeholders with your actual repository URL, file path, and a unique slug. ```php require 'plugin-update-checker/plugin-update-checker.php'; $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker( 'https://gitlab.com/user-name/repo-name/', __FILE__, 'unique-plugin-or-theme-slug' ); //Optional: If you're using a private repository, specify the access token like this: $myUpdateChecker->setAuthentication('your-token-here'); //Optional: Set the branch that contains the stable release. $myUpdateChecker->setBranch('stable-branch-name'); ``` -------------------------------- ### Enable CDN for Fonts in Autoptimize Source: https://github.com/futtta/autoptimize/blob/beta/readme.txt To enable Autoptimize to put fonts on the CDN, hook into the API and set 'autoptimize_filter_css_fonts_cdn' to true. This requires proper cross-origin request policy configuration. ```php add_filter( 'autoptimize_filter_css_fonts_cdn', '__return_true' ); ``` -------------------------------- ### WordPress Tests Configuration - Default Path Source: https://github.com/futtta/autoptimize/blob/beta/bin/readme-windows.txt The default `ABSPATH` definition in the `wp-tests-config.php` file. ```php define( 'ABSPATH', '/c/Windows/Temp/wordpress/' ); ``` -------------------------------- ### Theme JSON Update Details Source: https://github.com/futtta/autoptimize/blob/beta/classes/external/php/plugin-update-checker/README.md Complete JSON structure for a self-hosted theme update. Includes all theme-related fields like version, details URL, and download URL. ```json { "version": "2.0", "details_url": "http://example.com/version-2.0-details.html", "download_url": "http://example.com/example-theme-2.0.zip" } ``` -------------------------------- ### Initialize Update Checker for GitLab with Subgroups Source: https://github.com/futtta/autoptimize/blob/beta/classes/external/php/plugin-update-checker/README.md Configure the update checker for GitLab instances with nested groups or subgroups. You must explicitly define the subgroup path within the API URL. ```php $myUpdateChecker = new Puc_v4p9_Vcs_PluginUpdateChecker( new Puc_v4p9_Vcs_GitLabApi('https://myserver.com/group-name/subgroup-level1/subgroup-level2/subgroup-level3/repo-name/', null, 'subgroup-level1/subgroup-level2/subgroup-level3'), __FILE__, 'unique-plugin-or-theme-slug' ); ``` -------------------------------- ### WordPress Tests Configuration - Corrected Path Source: https://github.com/futtta/autoptimize/blob/beta/bin/readme-windows.txt Manually corrected `ABSPATH` definition for `wp-tests-config.php` when using msys/mingw environments. ```php define( 'ABSPATH', 'C:/Windows/Temp/wordpress/' ); ``` -------------------------------- ### Set Private Repository Authentication Source: https://github.com/futtta/autoptimize/blob/beta/classes/external/php/plugin-update-checker/README.md Configure the update checker to use a personal access token for private GitHub repositories. ```php $myUpdateChecker->setAuthentication('your-token-here'); ``` -------------------------------- ### Private BitBucket Repository Authentication Source: https://github.com/futtta/autoptimize/blob/beta/classes/external/php/plugin-update-checker/README.md Use this method to authenticate with private BitBucket repositories using OAuth consumer credentials. Ensure the consumer is marked as private. ```php $myUpdateChecker->setAuthentication(array( 'consumer_key' => '...', 'consumer_secret' => '...', )); ``` -------------------------------- ### Exclude Content from Autoptimize Source: https://github.com/futtta/autoptimize/blob/beta/readme.txt Wrap content that should not be autoptimized with noptimize tags. This can be done in page/post content, widgets, or theme files. ```html ``` -------------------------------- ### Enable Minify Inline JS/CSS Filter Source: https://github.com/futtta/autoptimize/blob/beta/readme.txt Use this filter to re-enable the 'minify inline CSS/JS' option, which was temporarily rolled back. It's now a default-off option that can be enabled programmatically. ```php add_filter( 'autoptimize_html_minify_inline_js_css', '__return_true'); ``` -------------------------------- ### Defer Inline JS with Nonce or Post ID Source: https://github.com/futtta/autoptimize/blob/beta/readme.txt This improvement allows 'defer inline JS' to function even when the inline JavaScript contains a nonce or post_id. No specific code snippet is required as this is a core improvement. -------------------------------- ### Uninstall Routine for PAnD Data Cleanup Source: https://github.com/futtta/autoptimize/blob/beta/classes/external/php/persist-admin-notices-dismissal/README.md Add this code to your plugin's uninstall.php file to remove PAnD related data from the WordPress options or sitemeta table. ```php global $wpdb; $table = is_multisite() ? $wpdb->base_prefix . 'sitemeta' : $wpdb->base_prefix . 'options'; $column = is_multisite() ? 'meta_key' : 'option_name'; $delete_string = 'DELETE FROM ' . $table . ' WHERE ' . $column . ' LIKE %s LIMIT 1000'; $wpdb->query( $wpdb->prepare( $delete_string, array( '%pand-%' ) ) ); ``` -------------------------------- ### Set Stable Branch for Updates Source: https://github.com/futtta/autoptimize/blob/beta/classes/external/php/plugin-update-checker/README.md Configure the update checker to use a specific branch for checking updates. This is an alternative to using GitHub releases or tags. ```php $updateChecker->setBranch('branch-name'); ``` -------------------------------- ### Set Stable Release Branch Source: https://github.com/futtta/autoptimize/blob/beta/classes/external/php/plugin-update-checker/README.md Specify the Git branch that contains the stable release for the update checker. ```php $myUpdateChecker->setBranch('stable-branch-name'); ``` -------------------------------- ### Disable NextGen Gallery Resource Manager Source: https://github.com/futtta/autoptimize/blob/beta/readme.txt Use this filter to disable NextGen Gallery's resource manager, allowing Autoptimize to aggregate its JavaScript. ```php add_filter( 'run_ngg_resource_manager', '__return_false' ); ``` -------------------------------- ### Disable Autoptimize Cache Purge Listening Source: https://github.com/futtta/autoptimize/blob/beta/readme.txt Disable Autoptimize's default behavior of listening to page cache purges. Use this filter if you encounter issues with cache synchronization. ```php add_filter('autoptimize_filter_main_hookpagecachepurge','__return_false'); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.