<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[13335] sites/trunk/wordpress.org/public_html/wp-content: Plugin directory: prompt plugin developers to create a blueprint for previews</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/13335">13335</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/13335","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>tellyworth</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-03-14 05:40:44 +0000 (Thu, 14 Mar 2024)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Plugin directory: prompt plugin developers to create a blueprint for previews

This adds a notice, visible only to a plugin's developers, prompting them to test and create a blueprint.json file so users can run a Live Preview of their plugin in the WordPress Playground. The notice can be dismissed.

See <a href="http://meta.trac.wordpress.org/ticket/7487">#7487</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryapiroutesclasspluginblueprintphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-blueprint.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryapiroutesclasspluginselftogglepreviewphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-self-toggle-preview.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclasstemplatephp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorycliclassimportphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgpluginsinctemplatetagsphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/inc/template-tags.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryapiroutesclasspluginblueprintphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-blueprint.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-blueprint.php   2024-03-14 04:27:09 UTC (rev 13334)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-blueprint.php     2024-03-14 05:40:44 UTC (rev 13335)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -39,6 +39,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->get_param('zip_hash') ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->reviewer_blueprint( $request, $plugin );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( $request->get_param('url_hash') ) {
+                       $this->developer_blueprint( $request, $plugin );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">         $blueprints = get_post_meta( $plugin->ID, 'assets_blueprints', true );
</span><span class="cx" style="display: block; padding: 0 10px">         // Note: for now, only use a file called `blueprint.json`.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -75,118 +78,147 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Direct zip preview for plugin reviewers
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $request->get_param('zip_hash') ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        foreach ( get_attached_media( 'application/zip', $plugin ) as $zip_file ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( hash_equals( Template::preview_link_hash( $zip_file->ID, 0 ), $request->get_param('zip_hash') ) ||
-                                    hash_equals( Template::preview_link_hash( $zip_file->ID, -1 ), $request->get_param('zip_hash') ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $zip_file_path = get_attached_file( $zip_file->ID );
+                               if ( hash_equals( Template::preview_link_hash( $zip_file_path, 0 ), $request->get_param('zip_hash') ) ||
+                                    hash_equals( Template::preview_link_hash( $zip_file_path, -1 ), $request->get_param('zip_hash') ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                         $zip_url = wp_get_attachment_url( $zip_file->ID );
</span><span class="cx" style="display: block; padding: 0 10px">                                        if ( $zip_url ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                $is_pcp = 'pcp' === $request->get_param('type');
+                                               $output = $this->generate_blueprint( $request, $plugin, $zip_url, $is_pcp, true );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                $landing_page = '/wp-admin/plugins.php';
-                                               $activate_plugin = true;
-                                               $dependencies = $plugin->requires_plugins ?: [];
-
-                                               if ( stripos( $plugin->post_title, 'woocommerce' ) ) {
-                                                       $dependencies[] = 'woocommerce';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         if ( $output ) {
+                                                       header( 'Access-Control-Allow-Origin: https://playground.wordpress.net' );
+                                                       die( $output );
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                if ( stripos( $plugin->post_title, 'buddypress' ) ) {
-                                                       $dependencies[] = 'buddypress';
-                                               }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 }
+                               }
+                       }
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                $dependencies = array_diff( $dependencies, [ $plugin->post_name ] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         return new \WP_Error( 'invalid_blueprint', 'Invalid file', array( 'status' => 500 ) );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                // Plugin deactivated, and land on the Plugin Check page
-                                               if ( 'pcp' === $request->get_param('type') ) {
-                                                       $landing_page = '/wp-admin/admin.php?page=plugin-check&plugin=' . sanitize_title( $request['plugin_slug'] );
-                                                       $activate_plugin = false;
-                                                       $dependencies = [];
-                                               }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function developer_blueprint( $request, $plugin ) {
+               // Generated blueprint for developers who haven't yet created a custom blueprint
+               if ( $request->get_param('url_hash') ) {
+                       $download_link = Template::download_link( $plugin );
+                       if ( $download_link ) {
+                               if ( hash_equals( Template::preview_link_hash( $download_link, 0 ), $request->get_param('url_hash') ) ||
+                                       hash_equals( Template::preview_link_hash( $download_link, -1 ), $request->get_param('url_hash') ) ) {
+                                       $output = $this->generate_blueprint( $request, $plugin, $download_link, false, false );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                $zip_blueprint = (object)[
-                                                       'landingPage' => $landing_page,
-                                                       'preferredVersions' => (object)[
-                                                               'php' => '8.0',
-                                                               'wp'  => 'latest',
-                                                       ],
-                                                       'phpExtensionBundles' => [
-                                                               'kitchen-sink'
-                                                       ],
-                                                       'features' => (object)[
-                                                               'networking' => true
-                                                       ],
-                                                       'steps' => [
-                                                               (object)[
-                                                                       'step' => 'installPlugin',
-                                                                       'pluginZipFile' => (object)[
-                                                                               'resource' => 'wordpress.org/plugins',
-                                                                               'slug'     => 'plugin-check',
-                                                                       ]
-                                                               ],
-                                                               (object)[
-                                                                       'step' => 'installPlugin',
-                                                                       'pluginZipFile' => (object)[
-                                                                               'resource' => 'url',
-                                                                               'url'      => $zip_url,
-                                                                       ],
-                                                                       'options' => (object)[
-                                                                               'activate' => (bool)$activate_plugin
-                                                                       ]
-                                                               ],
-                                                               (object)[
-                                                                       'step' => 'login',
-                                                                       'username' => 'admin',
-                                                                       'password' => 'password',
-                                                               ]
-                                                       ]
-                                               ];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 if ( $output ) {
+                                               header( 'Access-Control-Allow-Origin: https://playground.wordpress.net' );
+                                               die( $output );
+                                       }
+                               }
+                       }
+               }
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                if ( $dependencies ) {
-                                                       $dep_step = [];
-                                                       foreach ( $dependencies as $slug ) {
-                                                               $dep_step[] = (object)[
-                                                                       'step' => 'installPlugin',
-                                                                       'pluginZipFile' => [
-                                                                               'resource' => 'wordpress.org/plugins',
-                                                                               'slug'     => sanitize_title( $slug ),
-                                                                       ],
-                                                                       'options' => (object)[
-                                                                               'activate' => true
-                                                                       ]
-                                                               ];
-                                                       }
-                                                       // Insert dependencies aftter PCP
-                                                       array_splice( $zip_blueprint->steps, 1, 0, $dep_step );
-                                               }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function generate_blueprint( $request, $plugin, $zip_url, $install_pcp = true, $install_prh = true ) {
+               $landing_page = '/wp-admin/plugins.php';
+               $activate_plugin = true;
+               $dependencies = $plugin->requires_plugins ?: [];
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                // Include the helper plugin too
-                                               $helper_zip = self::get_zip_url_by_slug( 'playground-review-helper' );
-                                               if ( $helper_zip && 'pcp' !== $request->get_param('type') ) {
-                                                       $helper_step = [
-                                                               (object)[
-                                                                       'step' => 'installPlugin',
-                                                                       'pluginZipFile' => [
-                                                                               'resource' => 'url',
-                                                                               'url'      => $helper_zip,
-                                                                       ],
-                                                                       'options' => (object)[
-                                                                               'activate' => (bool)$activate_plugin
-                                                                       ]
-                                                               ]
-                                                       ];
-                                                       array_splice( $zip_blueprint->steps, 1, 0, $helper_step );
-                                               }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( stripos( $plugin->post_title, 'woocommerce' ) ) {
+                       $dependencies[] = 'woocommerce';
+               }
+               if ( stripos( $plugin->post_title, 'buddypress' ) ) {
+                       $dependencies[] = 'buddypress';
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                $output = json_encode( $zip_blueprint );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $dependencies = array_diff( $dependencies, [ $plugin->post_name ] );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                if ( $output ) {
-                                                       header( 'Access-Control-Allow-Origin: https://playground.wordpress.net' );
-                                                       die( $output );
-                                               }
-                                       }
-                               }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Plugin deactivated, and land on the Plugin Check page
+               if ( $install_pcp ) {
+                       $landing_page = '/wp-admin/admin.php?page=plugin-check&plugin=' . sanitize_title( $request['plugin_slug'] );
+                       $activate_plugin = false;
+                       $dependencies = [];
+               }
+
+               $zip_blueprint = (object)[
+                       'landingPage' => $landing_page,
+                       'preferredVersions' => (object)[
+                               'php' => '8.0',
+                               'wp'  => 'latest',
+                       ],
+                       'phpExtensionBundles' => [
+                               'kitchen-sink'
+                       ],
+                       'features' => (object)[
+                               'networking' => true
+                       ],
+               ];
+
+               $steps = [];
+
+               // PCP first, if needed.
+               if ( $install_pcp ) {
+                       $steps[] = (object)[
+                               'step' => 'installPlugin',
+                               'pluginZipFile' => (object)[
+                                       'resource' => 'wordpress.org/plugins',
+                                       'slug'     => 'plugin-check',
+                               ]
+                       ];
+               }
+
+               // Include the helper plugin too
+               $helper_zip = self::get_zip_url_by_slug( 'playground-review-helper' );
+               if ( $helper_zip && $install_prh ) {
+                       $steps[] = (object)[
+                                       'step' => 'installPlugin',
+                                       'pluginZipFile' => [
+                                               'resource' => 'url',
+                                               'url'      => $helper_zip,
+                                       ],
+                                       'options' => (object)[
+                                               'activate' => (bool)$activate_plugin
+                                       ]
+                               ];
+               }
+
+               // Dependencies next
+               if ( $dependencies ) {
+                       foreach ( $dependencies as $slug ) {
+                               $steps[] = (object)[
+                                       'step' => 'installPlugin',
+                                       'pluginZipFile' => [
+                                               'resource' => 'wordpress.org/plugins',
+                                               'slug'     => sanitize_title( $slug ),
+                                       ],
+                                       'options' => (object)[
+                                               'activate' => true
+                                       ]
+                               ];
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                return new \WP_Error( 'invalid_blueprint', 'Invalid file', array( 'status' => 500 ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Now the plugin itself
+               $steps[] = (object)[
+                                       'step' => 'installPlugin',
+                                       'pluginZipFile' => (object)[
+                                               'resource' => 'url',
+                                               'url'      => $zip_url,
+                                       ],
+                                       'options' => (object)[
+                                               'activate' => (bool)$activate_plugin
+                                       ]
+                               ];
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // Finally log in
+               $steps[] = (object)[
+                                       'step' => 'login',
+                                       'username' => 'admin',
+                                       'password' => 'password',
+                               ];
+
+               $zip_blueprint->steps = $steps;
+
+               $output = json_encode( $zip_blueprint, JSON_PRETTY_PRINT );
+
+               return $output;
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryapiroutesclasspluginselftogglepreviewphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-self-toggle-preview.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-self-toggle-preview.php 2024-03-14 04:27:09 UTC (rev 13334)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-self-toggle-preview.php   2024-03-14 05:40:44 UTC (rev 13335)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -63,6 +63,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                ];
</span><span class="cx" style="display: block; padding: 0 10px">                header( 'Location: ' . $result['location'] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( $request->get_param('dismiss') ) {
+                       return $this->self_dismiss( $request, $plugin );
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // Toggle the postmeta value. Note that there is a race condition here.
</span><span class="cx" style="display: block; padding: 0 10px">                $did = '';
</span><span class="cx" style="display: block; padding: 0 10px">                if ( get_post_meta( $plugin->ID, '_public_preview', true ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -82,4 +86,21 @@
</span><span class="cx" style="display: block; padding: 0 10px">                return $result;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        /**
+        * Endpoint special case to dismiss the missing blueprint notice.
+        *
+        * @param \WP_REST_Request $request The Rest API Request.
+        * @param object $plugin The plugin post.
+        * @return bool True if the toggle was successful.
+        */
+       public function self_dismiss( $request, $plugin ) {
+               $result = [
+                       'location' => wp_get_referer() ?: get_permalink( $plugin ),
+               ];
+
+               // Change the value from 1 to 0. This will persist and prevent it from being added again.
+               update_post_meta( $plugin->ID, '_missing_blueprint_notice', 0, 1 );
+
+               return $result;
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclasstemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php      2024-03-14 04:27:09 UTC (rev 13334)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php        2024-03-14 05:40:44 UTC (rev 13335)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -773,7 +773,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public static function preview_link_zip( $slug, $attachment_id, $type = null ) {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $zip_hash = self::preview_link_hash( $attachment_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $file = get_attached_file( $attachment_id );
+               $zip_hash = self::preview_link_hash( $file );
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( !$zip_hash ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return false;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -787,6 +788,29 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Generate a live preview (playground) link for a published plugin that does not yet have a custom blueprint. Needed for developer testing.
+        *
+        * @param string $slug            The slug of the plugin post.
+        * @param int $download_link      The URL of the zip download for the plugin.
+        * @param bool $blueprint_only    False will return a full preview URL. True will return only a blueprint URL.
+        * @return false|string           The preview or blueprint URL.
+        */
+       public static function preview_link_developer( $slug, $download_link, $blueprint_only = false ) {
+
+               $url_hash = self::preview_link_hash( $download_link );
+               if ( !$url_hash ) {
+                       return false;
+               }
+               $dev_blueprint = sprintf( 'https://wordpress.org/plugins/wp-json/plugins/v1/plugin/%s/blueprint.json?url_hash=%s', esc_attr( $slug ), esc_attr( $url_hash ) );
+               if ( $blueprint_only ) {
+                       return $dev_blueprint;
+               }
+               $url_preview = add_query_arg( 'blueprint-url', urlencode($dev_blueprint), 'https://playground.wordpress.net/' );
+
+               return $url_preview;
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Return a time-dependent variable for zip preview links.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param int $lifespan           The life span of the nonce, in seconds. Default is one week.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -799,17 +823,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * Return a nonce-style hash for zip preview links.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @param int $attachment_id      The ID of the attachment post corresponding to a plugin zip file.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @param string $zip_file        The filesystem path or URL of the zip file.
</ins><span class="cx" style="display: block; padding: 0 10px">          * @param int $tick_offest        Number to subtract from the nonce tick. Use both 0 and -1 to verify older nonces.
</span><span class="cx" style="display: block; padding: 0 10px">         * @return false|string           The hash as a hex string; or false if the attachment ID is invalid.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public static function preview_link_hash( $attachment_id, $tick_offset = 0 ) {
-               $file = get_attached_file( $attachment_id );
-               if ( !$file ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function preview_link_hash( $zip_file, $tick_offset = 0 ) {
+               if ( !$zip_file ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         return false;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">                $tick = self::preview_link_tick() - $tick_offset;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                return wp_hash( $tick . '|' . $file, 'nonce' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         return wp_hash( $tick . '|' . $zip_file, 'nonce' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -916,6 +939,21 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Generates a link to dismiss a missing blueprint notice.
+        *
+        * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
+        * @return string URL to toggle status.
+        */
+       public static function get_self_dismiss_blueprint_notice_link( $post = null ) {
+               $post = get_post( $post );
+
+               return add_query_arg(
+                       array( '_wpnonce' => wp_create_nonce( 'wp_rest' ), 'dismiss' => 1 ),
+                       home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/self-toggle-preview' )
+               );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Generates a link to enable Release Confirmations.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorycliclassimportphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php    2024-03-14 04:27:09 UTC (rev 13334)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php      2024-03-14 05:40:44 UTC (rev 13335)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -390,6 +390,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        update_post_meta( $plugin->ID, 'assets_blueprints', wp_slash( $assets['blueprint'] ) );
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><span class="cx" style="display: block; padding: 0 10px">                        delete_post_meta( $plugin->ID, 'assets_blueprints' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        // TODO: maybe if ( $touches_stable_tag )?
+                       add_post_meta( $plugin->ID, '_missing_blueprint_notice', 1, true );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Store the block data, if known
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgpluginsinctemplatetagsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/inc/template-tags.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/inc/template-tags.php   2024-03-14 04:27:09 UTC (rev 13334)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/inc/template-tags.php     2024-03-14 05:40:44 UTC (rev 13335)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -727,4 +727,45 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        wp_kses_post( $import_warnings )
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       // This is less important, so only show if there are no other notices.
+       if ( !$notice && !$import_warnings && get_post_meta( $post->ID, '_missing_blueprint_notice', true ) ) {
+               $blueprint_test_button = sprintf(
+                       '<a class="plugin-preview" target="_blank" href="%s">%s</a>',
+                       Template::preview_link_developer( $post->post_name, Template::download_link() ),
+                       esc_html__( 'Test your plugin in Playground', 'wporg-plugins' )
+               );
+               $blueprint_download_button = sprintf(
+                       '<a class="plugin-preview" target="_blank" href="%s">%s</a>',
+                       Template::preview_link_developer( $post->post_name, Template::download_link(), true ),
+                       esc_html__( 'Download blueprint.json', 'wporg-plugins' )
+               );
+               $blueprint_dismiss_button = sprintf(
+                       '<form method="POST" action="%s"><p><input type="submit" name="dismiss" value="%s" class="plugin-preview button button-secondary alignright" /></p></form>',
+                       #'<a class="plugin-preview button button-secondary alignright" href="%s">%s</a>',
+                       Template::get_self_dismiss_blueprint_notice_link( $post ),
+                       esc_html__( 'Dismiss', 'wporg-plugins' )
+               );
+
+               // There is surely a neater way to format this.
+               $blueprint_notice = sprintf(
+                       '<ol><li>%s</li><li>%s</li><li>%s</li><li>%s</li></ol>',
+                       $blueprint_test_button,
+                       esc_html__( 'Fix any bugs in your plugin that prevent it from working in Playground.', 'wporg-plugins' ),
+                       $blueprint_download_button,
+                       esc_html__( 'Commit your blueprint to svn.', 'wporg-plugins' )
+               );
+               $blueprint_more = sprintf(
+                       __( 'More info can be found in the <a href="%s">plugin handbook</a>.', 'wporg-plugins' ),
+                       'https://developer.wordpress.org/plugins/wordpress-org/previews-and-blueprints/'
+               );
+
+               printf(
+                       '<div class="notice notice-info notice-alt">%s</div>',
+                       '<p><strong>' . __( 'Your plugin does not yet have a blueprint file for user previews. If you\'d like to enable previews, please follow these steps to create a blueprint.', 'wporg-plugins' ) . '</strong></p>' .
+                       $blueprint_notice .
+                       $blueprint_dismiss_button .
+                       '<p>' . $blueprint_more . '</p>'
+               );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>