{"id":149077,"date":"2021-10-26T20:32:04","date_gmt":"2021-10-26T20:32:04","guid":{"rendered":"https:\/\/wordpress.org\/plugins\/encute\/"},"modified":"2022-02-17T20:29:31","modified_gmt":"2022-02-17T20:29:31","slug":"encute","status":"publish","type":"plugin","link":"https:\/\/srd.wordpress.org\/plugins\/encute\/","author":2545,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"0.8.8","stable_tag":"0.8.8","tested":"5.8.13","requires":"5.8","requires_php":"7.4","requires_plugins":"","header_name":"Encute","header_author":"Mark Jaquith","header_description":"Fluent management of scripts and styles.","assets_banners_color":"e9c6b4","last_updated":"2022-02-17 20:29:31","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"","header_author_uri":"","rating":4,"author_block_rating":0,"active_installs":20,"downloads":7927,"num_ratings":1,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","faq"],"tags":{"0.8.3":{"tag":"0.8.3","author":"markjaquith","date":"2021-10-26 20:31:45"},"0.8.4":{"tag":"0.8.4","author":"markjaquith","date":"2021-10-27 05:26:03"},"0.8.5":{"tag":"0.8.5","author":"markjaquith","date":"2021-10-27 06:46:44"},"0.8.6":{"tag":"0.8.6","author":"markjaquith","date":"2021-10-27 19:55:49"},"0.8.7":{"tag":"0.8.7","author":"markjaquith","date":"2022-02-15 06:54:48"},"0.8.8":{"tag":"0.8.8","author":"markjaquith","date":"2022-02-17 20:29:31"}},"upgrade_notice":[],"ratings":{"1":0,"2":0,"3":0,"4":1,"5":0},"assets_icons":{"icon-128x128.png":{"filename":"icon-128x128.png","revision":2620522,"resolution":"128x128","location":"assets","locale":""},"icon-256x256.png":{"filename":"icon-256x256.png","revision":2620522,"resolution":"256x256","location":"assets","locale":""}},"assets_banners":{"banner-1544x500.png":{"filename":"banner-1544x500.png","revision":2620522,"resolution":"1544x500","location":"assets","locale":""},"banner-772x250.png":{"filename":"banner-772x250.png","revision":2620522,"resolution":"772x250","location":"assets","locale":""}},"assets_blueprints":{},"all_blocks":[],"tagged_versions":["0.8.3","0.8.4","0.8.5","0.8.6","0.8.7","0.8.8"],"block_files":[],"assets_screenshots":{"screenshot-1.png":{"filename":"screenshot-1.png","revision":2621007,"resolution":"1","location":"assets","locale":""}},"screenshots":{"1":"Code generation inside the plugin."},"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[247,2864,2003],"plugin_category":[54],"plugin_contributors":[77745],"plugin_business_model":[],"class_list":["post-149077","plugin","type-plugin","status-publish","hentry","plugin_tags-performance","plugin_tags-scripts","plugin_tags-styles","plugin_category-security-and-spam-protection","plugin_contributors-markjaquith","plugin_committers-markjaquith"],"banners":{"banner":"https:\/\/ps.w.org\/encute\/assets\/banner-772x250.png?rev=2620522","banner_2x":"https:\/\/ps.w.org\/encute\/assets\/banner-1544x500.png?rev=2620522","banner_rtl":false,"banner_2x_rtl":false},"icons":{"svg":false,"icon":"https:\/\/ps.w.org\/encute\/assets\/icon-128x128.png?rev=2620522","icon_2x":"https:\/\/ps.w.org\/encute\/assets\/icon-256x256.png?rev=2620522","generated":false},"screenshots":[{"src":"https:\/\/ps.w.org\/encute\/assets\/screenshot-1.png?rev=2621007","caption":"Code generation inside the plugin."}],"raw_content":"<!--section=description-->\n<p>Encute provides a fluent, declarative API for site owners to manipulate the scripts and styles that WordPress, themes, and plugins shove onto their site. Move things into the footer, defer loading, remove assets entirely. Or load scripts async, or as modules, or as nomodule!<\/p>\n\n<p>Here's an example of how you could use the plugin:<\/p>\n\n<pre><code>&lt;?php\n\nuse CWS\\Encute\\{ Plugin, Script, Style };\n\nadd_action(Plugin::class, function (Plugin $plugin) {\n    $isContactPage = fn () =&gt; is_page('contact');\n    Script::get('contact-form-7')-&gt;keepIf($isContactPage)-&gt;footer()-&gt;defer();\n    Style::get('contact-form-7')-&gt;keepIf($isContactPage)-&gt;footer()-&gt;defer();\n\n    Style::get(['mediaelement', 'wp-mediaelement'])-&gt;footer()-&gt;defer();\n    Style::get('material-icons')-&gt;defer();\n    Script::get('jquery')-&gt;remove();\n});\n<\/code><\/pre>\n\n<h3>Wrapper<\/h3>\n\n<p>Always run code in this wrapper:<\/p>\n\n<pre><code>add_action(\\CWS\\Encute\\Plugin::class, function (\\CWS\\Encute\\Plugin $encute) {\n    \/\/ Your code here.\n});\n<\/code><\/pre>\n\n<p>This wrapper will be a no-op if Encute is not available, and it will both wait for Encute to be available to run, and pass you Encute's main class instance.<\/p>\n\n<h3>Fluency<\/h3>\n\n<p>Both <code>Script::get()<\/code> and <code>Style::get()<\/code> return an instance of themselves, as do all calls to their methods, so you can just chain your calls.<\/p>\n\n<h3>Script<\/h3>\n\n<ul>\n<li><code>static CWS\\Encute\\Script::get(string $handle): CWS\\Encute\\Script<\/code> \u2014 get a Script instance for that handle.<\/li>\n<li><code>CWS\\Encute\\Script::module(): CWS\\Encute\\Script<\/code> \u2014 make the script a module.<\/li>\n<li><code>CWS\\Encute\\Script::noModule(): CWS\\Encute\\Script<\/code> \u2014 make the script nomodule.<\/li>\n<li><code>CWS\\Encute\\Script::footer(): CWS\\Encute\\Script<\/code> \u2014 send the script to the footer (along with its entire dependency family).<\/li>\n<li><code>CWS\\Encute\\Script::async(): CWS\\Encute\\Script<\/code> \u2014 make the script async.<\/li>\n<li><code>CWS\\Encute\\Script::defer(): CWS\\Encute\\Script<\/code> \u2014 make the script defer.<\/li>\n<li><code>CWS\\Encute\\Script::remove(): CWS\\Encute\\Script<\/code> \u2014 remove the script.<\/li>\n<li><code>CWS\\Encute\\Script::removeIf(callable $callback): CWS\\Encute\\Script<\/code> \u2014 remove the script if the callback resolves as true.<\/li>\n<li><code>CWS\\Encute\\Script::keepIf(callable $callback): CWS\\Encute\\Script<\/code> \u2014 keep the script if the callback resolves as true (else remove it).<\/li>\n<\/ul>\n\n<h3>Style<\/h3>\n\n<ul>\n<li><code>static CWS\\Encute\\Style::get(string $handle): CWS\\Encute\\Style<\/code> \u2014 get a Style instance for that handle.<\/li>\n<li><code>CWS\\Encute\\Style::footer(): CWS\\Encute\\Style<\/code> \u2014 send the style to the footer (along with its entire dependency family).<\/li>\n<li><code>CWS\\Encute\\Style::defer(): CWS\\Encute\\Style<\/code> \u2014 defer the style's loading.<\/li>\n<li><code>CWS\\Encute\\Style::remove(): CWS\\Encute\\Style<\/code> \u2014 remove the style.<\/li>\n<li><code>CWS\\Encute\\Style::removeIf(callable $callback): CWS\\Encute\\Style<\/code> \u2014 remove the style if the callback resolves as true.<\/li>\n<li><code>CWS\\Encute\\Style::keepIf(callable $callback): CWS\\Encute\\Style<\/code> \u2014 keep the style if the callback resolves as true (else remove it).<\/li>\n<\/ul>\n\n<!--section=faq-->\n<dl>\n<dt id='how%20do%20i%20use%20this%3F'><h3>How do I use this?<\/h3><\/dt>\n<dd><p>Go to Tools &gt; Encute and you'll be guided through code generation.<\/p><\/dd>\n<dt id='can%27t%20i%20do%20this%20through%20a%20ui%3F'><h3>Can't I do this through a UI?<\/h3><\/dt>\n<dd><p>Not currently. This is a pro-level tool. You need to know what you're doing. If writing code isn't for you, then this plugin probably isn't for you.<\/p><\/dd>\n\n<\/dl>","raw_excerpt":"Fluent API for site owners to manipulate the scripts and styles on the frontend of their site.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/149077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=149077"}],"author":[{"embeddable":true,"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/markjaquith"}],"wp:attachment":[{"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=149077"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=149077"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=149077"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=149077"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=149077"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=149077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}