<!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>[12335] sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory: Plugin Directory: Add initial plugin categorization features to the plugin.</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/12335">12335</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/12335","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>coffee2code</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-12-15 17:55:50 +0000 (Thu, 15 Dec 2022)</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: Add initial plugin categorization features to the plugin.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryadmineditphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/admin-edit.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryclassthemesapiphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-themes-api.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryrestapiphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/rest-api.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectorythemedirectoryphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryrestapiclassthemecategorizationphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/rest-api/class-theme-categorization.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryadmineditphp"></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/theme-directory/admin-edit.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/theme-directory/admin-edit.php   2022-12-15 16:57:48 UTC (rev 12334)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/admin-edit.php     2022-12-15 17:55:50 UTC (rev 12335)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -60,9 +60,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @param array  $caps Returns the user's actual capabilities.
</span><span class="cx" style="display: block; padding: 0 10px">  * @param string $cap  Capability name.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int    $user_id The user ID.
+ * @param mixed  $context Adds the context to the cap. Typically the object ID.
</ins><span class="cx" style="display: block; padding: 0 10px">  * @return array
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wporg_themes_map_meta_cap( $caps, $cap ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wporg_themes_map_meta_cap( $caps, $cap, $user_id, $context ) {
</ins><span class="cx" style="display: block; padding: 0 10px">         switch ( $cap ) {
</span><span class="cx" style="display: block; padding: 0 10px">                case 'delete_categories':
</span><span class="cx" style="display: block; padding: 0 10px">                case 'edit_categories':
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -82,11 +84,43 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $caps[] = 'reinstate_themes';
</span><span class="cx" style="display: block; padding: 0 10px">                        unset( $caps[ array_search( $cap, $caps ) ] );
</span><span class="cx" style="display: block; padding: 0 10px">                        break;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               case 'theme_configure_categorization_options':
+                       // Protect against a cap call without a theme context.
+                       $post = $context ? get_post( $context[0] ) : false;
+                       if ( ! $post ) {
+                               return [ 'do_not_allow' ];
+                       }
+
+                       // The current user instance.
+                       $user = new \WP_User( $user_id );
+
+                       // Shortcut, if no user specified, we can't help.
+                       if ( ! $user_id || ! $user->exists() ) {
+                               return [ 'do_not_allow' ];
+                       }
+
+                       // Post must be a published theme.
+                       if ( 'publish' !== $post->post_status || 'repopackage' !== $post->post_type ) {
+                               return [ 'do_not_allow' ];
+                       }
+
+                       // User must be able to edit theme or be the theme owner.
+                       if ( ! ( user_can( $user->ID, 'edit_post', $post ) || $user->ID === $post->post_author ) ) {
+                               return [ 'do_not_allow' ];
+                       }
+
+                       // Start over, we'll specify all caps below.
+                       $caps = [];
+
+                       // At this point, user is allowed.
+                       $caps[] = 'exist';
+                       break;
</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">        return $caps;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_filter( 'map_meta_cap', 'wporg_themes_map_meta_cap', 10, 2 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_filter( 'map_meta_cap', 'wporg_themes_map_meta_cap', 10, 4 );
</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">  * Mark themes as Delisted / Suspended on the admin post listing.
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryclassthemesapiphp"></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/theme-directory/class-themes-api.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/theme-directory/class-themes-api.php     2022-12-15 16:57:48 UTC (rev 12334)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-themes-api.php       2022-12-15 17:55:50 UTC (rev 12335)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -64,6 +64,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                'requires'           => false,
</span><span class="cx" style="display: block; padding: 0 10px">                'requires_php'       => false,
</span><span class="cx" style="display: block; padding: 0 10px">                'trac_tickets'       => false,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                'is_commercial'      => false,
+               'is_community'       => false,
+               'external_repository_url' => false,
+               'external_support_url' => false,
+               'can_configure_categorization_options' => false,
</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">@@ -71,7 +76,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @var string
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        private $cache_group = 'theme-info';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+//       private $cache_group = 'theme-info';
+private $cache_group = 'test-theme-info'; // Don't pollute production cache.
</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">         * The amount of time to keep information cached.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -78,7 +84,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @var int
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        private $cache_life = 600; // 10 minutes.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+//       private $cache_life = 600; // 10 minutes.
+private $cache_life = 1; // Disable caching.
</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">         * Flag the input as having been malformed.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -459,6 +466,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $defaults['requires'] = true;
</span><span class="cx" style="display: block; padding: 0 10px">                        $defaults['requires_php'] = true;
</span><span class="cx" style="display: block; padding: 0 10px">                        $defaults['creation_time'] = true;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $defaults['is_commercial'] = true;
+                       $defaults['is_community'] = true;
+                       $defaults['external_repository_url'] = true;
+                       $defaults['external_support_url'] = true;
+                       $defaults['can_configure_categorization_options'] = 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">                $this->request->fields = (array) ( $this->request->fields ?? [] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -525,6 +537,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $defaults['parent'] = true;
</span><span class="cx" style="display: block; padding: 0 10px">                        $defaults['requires'] = true;
</span><span class="cx" style="display: block; padding: 0 10px">                        $defaults['requires_php'] = true;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $defaults['is_commercial'] = true;
+                       $defaults['is_community'] = true;
+                       $defaults['external_repository_url'] = true;
+                       $defaults['external_support_url'] = true;
+                       $defaults['can_configure_categorization_options'] = 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">                $this->request->fields = (array) ( $this->request->fields ?? [] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -879,6 +896,36 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $phil->trac_tickets = get_post_meta( $theme->ID, '_ticket_id', true );
</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">+                if ( $this->fields['is_commercial'] ) {
+                       $phil->is_commercial = has_term( 'commercial', 'theme_business_model', $theme );
+               }
+
+               if ( $this->fields['external_support_url'] ) {
+                       // Only return external_support_url value if theme is commercial.
+                       if ( ! empty( $phil->is_commercial ) ) {
+                               $phil->external_support_url = get_post_meta( $theme->ID, 'external_support_url', true );
+                       } else {
+                               $phil->external_support_url = false;
+                       }
+               }
+
+               if ( $this->fields['is_community'] ) {
+                       $phil->is_community = has_term( 'community', 'theme_business_model', $theme );
+               }
+
+               if ( $this->fields['external_repository_url'] ) {
+                       // Only return external_repository_url value if theme is community.
+                       if ( ! empty( $phil->is_community ) ) {
+                               $phil->external_repository_url = get_post_meta( $theme->ID, 'external_repository_url', true );
+                       } else {
+                               $phil->external_repository_url = '';
+                       }
+               }
+
+               if ( $this->fields['can_configure_categorization_options'] ) {
+                       $phil->can_configure_categorization_options = current_user_can( 'theme_configure_categorization_options', $theme );
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( class_exists( 'GlotPress_Translate_Bridge' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $glotpress_project = "wp-themes/{$phil->slug}";
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryrestapiclassthemecategorizationphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/rest-api/class-theme-categorization.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/theme-directory/rest-api/class-theme-categorization.php                          (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/rest-api/class-theme-categorization.php    2022-12-15 17:55:50 UTC (rev 12335)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,239 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\Theme_Directory\Rest_API;
+
+use WP_Error;
+use WP_REST_Controller, WP_REST_Server, WP_REST_Response;
+
+defined( 'WPINC' ) || die();
+
+/**
+ *
+ * @see WP_REST_Controller
+ */
+class Theme_Categorization_Controller extends WP_REST_Controller {
+
+       /**
+        * Constructor.
+        *
+        */
+       public function __construct( ) {
+               $this->namespace         = 'themes/v1';
+               $this->rest_base         = 'theme';
+
+               $this->register_routes();
+       }
+
+       /**
+        * Registers the routes for the objects of the controller.
+        *
+        * @see register_rest_route()
+        */
+       public function register_routes() {
+               register_rest_route(
+                       $this->namespace,
+                       '/' . $this->rest_base . '/(?P<theme_slug>[^/]+)/commercial/?',
+                       [
+                               'methods'             => WP_REST_Server::EDITABLE,
+                               'callback'            => [ $this, 'save_external_support_url' ],
+                               'permission_callback' => [ $this, 'can_update_permissions_check' ],
+                               'args'                => [
+                                       'theme_slug' => [
+                                               'validate_callback' => [ $this, 'validate_theme_slug_callback' ],
+                                               'required'          => true,
+                                       ],
+                                       'supportURL' => [
+                                               'validate_callback' => [ $this, 'validate_url' ],
+                                               'required'          => true,
+                                       ],
+                               ],
+                       ]
+               );
+               register_rest_route(
+                       $this->namespace,
+                       '/' . $this->rest_base . '/(?P<theme_slug>[^/]+)/community/?',
+                       [
+                               'methods'             => WP_REST_Server::EDITABLE,
+                               'callback'            => [ $this, 'save_external_repository_url' ],
+                               'permission_callback' => [ $this, 'can_update_permissions_check' ],
+                               'args'                => [
+                                       'theme_slug' => [
+                                               'validate_callback' => [ $this, 'validate_theme_slug_callback' ],
+                                               'required'          => true,
+                                       ],
+                                       'repositoryURL' => [
+                                               'validate_callback' => [ $this, 'validate_url' ],
+                                               'required'          => true,
+                                       ],
+                               ],
+                       ]
+               );
+       }
+
+       /**
+        * Retrieve the WP_Post object representing a given theme.
+        *
+        * @static
+        * @global \WP_Post $post WordPress post object.
+        *
+        * @param int|string|\WP_Post $theme_slug The slug of the theme to retrieve.
+        * @return \WP_Post|bool
+        */
+       public function get_theme_post( $theme_slug = null ) {
+               if ( $theme_slug instanceof \WP_Post ) {
+                       return $theme_slug;
+               }
+
+               // Handle int $theme_slug being passed. NOT numeric slugs
+               if (
+                       is_int( $theme_slug ) &&
+                       ( $post = get_post( $theme_slug ) ) &&
+                       ( $post->ID === $theme_slug )
+               ) {
+                       return $post;
+               }
+
+               // Use the global $post object when appropriate
+               if (
+                       ! empty( $GLOBALS['post']->post_type ) &&
+                       'repopackage' === $GLOBALS['post']->post_type
+               ) {
+                       // Default to the global object.
+                       if ( is_null( $theme_slug ) || 0 === $theme_slug ) {
+                               return get_post( $GLOBALS['post']->ID );
+                       }
+
+                       // Avoid hitting the database if it matches.
+                       if ( $theme_slug == $GLOBALS['post']->post_name ) {
+                               return get_post( $GLOBALS['post']->ID );
+                       }
+               }
+               
+               $theme_slug = sanitize_title_for_query( $theme_slug );
+               if ( ! $theme_slug ) {
+                       return false;
+               }
+
+               $post    = false;
+               $post_id = wp_cache_get( $theme_slug, 'theme-slugs' );
+               if ( 0 === $post_id ) {
+                       // Unknown theme slug.
+                       return false;
+               } elseif ( $post_id ) {
+                       $post = get_post( $post_id );
+               }
+
+               if ( ! $post ) {
+                       $posts = get_posts( [
+                               'name'           => $theme_slug,
+                               'post_type'      => 'repopackage',
+                               'post_status'    => [ 'publish', 'pending', 'draft', 'future', 'suspend' ],
+                               'posts_per_page' => 1,
+                       ] );
+
+                       if ( ! $posts ) {
+                               $post = false;
+                               wp_cache_add( 0, $theme_slug, 'theme-slugs' );
+                       } else {
+                               $post = reset( $posts );
+                               wp_cache_add( $post->ID, $theme_slug, 'theme-slugs' );
+                       }
+               }
+
+               return $post;
+       }
+
+       /**
+        * Validates theme slug.
+        *
+        * @param string $value Submitted field value.
+        * @return bool True if slug is value, else false.
+        */
+       public function validate_theme_slug_callback( $value ) {
+               return is_string( $value ) && $value && self::get_theme_post( $value );
+       }
+
+       /**
+        * Validates a URL.
+        *
+        * @param string $value Submitted field value.
+        * @return bool True if URL is valid, else false.
+        */
+       public function validate_url( $value ) {
+               $value = trim( strip_tags( stripslashes( $value ) ) );
+
+               if ( ! $value ) {
+                       return true;
+               }
+
+               return (bool) filter_var( $value, FILTER_VALIDATE_URL );
+       }
+
+       /**
+        * Checks if current user can edit the categorization configuration for a theme.
+        *
+        * @param \WP_REST_Request $request The Rest API Request.
+        * @return bool|\WP_Error True if the token exists, WP_Error upon failure.
+        */
+       public function can_update_permissions_check( $request ) {
+               return current_user_can( 'theme_configure_categorization_options', self::get_theme_post( $request['theme_slug'] ) );
+       }
+
+       /**
+        * Saves the submitted support URL.
+        *
+        * @param WP_REST_Request $request Full details about the request.
+        * @return WP_Rest_Response|WP_Error WP_Rest_Response object on success, or WP_Error object on failure.
+        */
+       public function save_external_support_url( $request ) {
+               return $this->save_url( 'external_support_url', 'supportURL', $request );
+       }
+
+       /**
+        * Saves the submitted repository URL.
+        *
+        * @param WP_REST_Request $request Full details about the request.
+        * @return WP_Rest_Response|WP_Error WP_Rest_Response object on success, or WP_Error object on failure.
+        */
+       public function save_external_repository_url( $request ) {
+               return $this->save_url( 'external_repository_url', 'repositoryURL', $request );
+       }
+
+       /**
+        * Saves a URL as post meta.
+        *
+        * @param WP_REST_Request $request Full details about the request.
+        * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
+        */
+       protected function save_url( $meta_key, $request_key, $request ) {
+               $url  = $request[ $request_key ] ?? '';
+               $post = self::get_theme_post( $request['theme_slug'] );
+
+               if ( ! $post ) {
+                       return;
+               }
+
+               $fail = false;
+
+               // Sanitize URL.
+               if ( $url ) {
+                       $url = trim( strip_tags( stripslashes( $url ) ) );
+               }
+
+               // Delete post meta if new value is empty, else save.
+               if ( ! $url ) {
+                       delete_post_meta( $post->ID, $meta_key );
+               } else {
+                       update_post_meta( $post->ID, $meta_key, wp_slash( esc_url_raw( $url, [ 'http', 'https' ] ) ) );
+               }
+
+               if ( $fail ) {
+                       return new WP_Error( 'failed', __( 'The operation failed. Please try again.', 'wporg-themes' ) );
+               }
+
+               return new WP_REST_Response( [ $request_key => $url ], \WP_Http::OK );
+       }
+}
+
+new Theme_Categorization_Controller();
+
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/rest-api/class-theme-categorization.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectoryrestapiphp"></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/theme-directory/rest-api.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/theme-directory/rest-api.php     2022-12-15 16:57:48 UTC (rev 12334)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/rest-api.php       2022-12-15 17:55:50 UTC (rev 12335)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -53,5 +53,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">        include __DIR__ . '/rest-api/class-features-endpoint.php';
</span><span class="cx" style="display: block; padding: 0 10px">        include __DIR__ . '/rest-api/class-tags-endpoint.php';
</span><span class="cx" style="display: block; padding: 0 10px">        include __DIR__ . '/rest-api/class-themes-auto-review.php';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        include __DIR__ . '/rest-api/class-theme-categorization.php';
</ins><span class="cx" style="display: block; padding: 0 10px">         include __DIR__ . '/rest-api/class-theme-review-stats.php';
</span><span class="cx" style="display: block; padding: 0 10px"> } );
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsthemedirectorythemedirectoryphp"></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/theme-directory/theme-directory.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/theme-directory/theme-directory.php      2022-12-15 16:57:48 UTC (rev 12334)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php        2022-12-15 17:55:50 UTC (rev 12335)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -904,6 +904,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                'active_installs' => true,
</span><span class="cx" style="display: block; padding: 0 10px">                'requires' => true,
</span><span class="cx" style="display: block; padding: 0 10px">                'requires_php' => true,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                'is_commercial' => true,
+               'external_support_url' => true,
+               'is_community' => true,
+               'external_repository_url' => true,
+               'can_configure_categorization_options' => 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">        $api_result = wporg_themes_query_api( 'query_themes', $request );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -945,6 +950,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'active_installs' => true,
</span><span class="cx" style="display: block; padding: 0 10px">                        'requires' => true,
</span><span class="cx" style="display: block; padding: 0 10px">                        'requires_php' => true,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'is_commercial' => true,
+                       'external_support_url' => true,
+                       'is_community' => true,
+                       'external_repository_url' => true,
+                       'can_configure_categorization_model_options' => 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></span></pre>
</div>
</div>

</body>
</html>