<!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>[10803] sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php: Plugin Directory: Tools: Standardise all the `Tools::*` methods to consistently accept a WP_Post plugin instance in addition to a plugin slug.</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/10803">10803</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/10803","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dd32</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-03-10 05:42:56 +0000 (Wed, 10 Mar 2021)</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: Tools: Standardise all the `Tools::*` methods to consistently accept a WP_Post plugin instance in addition to a plugin slug.
This also applies some other code standards and unrolls some complex if statements.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclasstoolsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclasstoolsphp"></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-tools.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-tools.php 2021-03-10 05:34:15 UTC (rev 10802)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php 2021-03-10 05:42:56 UTC (rev 10803)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,6 +1,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> namespace WordPressdotorg\Plugin_Directory;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use WP_Query;
</ins><span class="cx" style="display: block; padding: 0 10px"> use WP_User;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Email\Committer_Added as Committer_Added_Email;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Email\Support_Rep_Added as Support_Rep_Added_Email;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -44,16 +45,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @todo Populate with review title/content.
</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 string $plugin_slug The plugin slug.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $post The plugin slug, WP_Post, or ID.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return array|false
</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 get_plugin_reviews( $plugin_slug, $number = 6 ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function get_plugin_reviews( $post, $number = 6 ) {
+ $post = Plugin_Directory::get_plugin_post( $post );
+ if ( ! $post ) {
+ return false;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $number = absint( $number );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $number < 1 || $number > 100 ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $number = 2;
</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">- $reviews = wp_cache_get( "{$plugin_slug}_last{$number}", 'plugin-reviews' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $reviews = wp_cache_get( "{$post->post_name}_last{$number}", 'plugin-reviews' );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) && false === $reviews ) {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -66,11 +72,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> WHERE r.object_type = 'plugin' AND r.object_slug = %s AND p.post_status = 'publish'
</span><span class="cx" style="display: block; padding: 0 10px"> ORDER BY r.review_id DESC
</span><span class="cx" style="display: block; padding: 0 10px"> LIMIT %d",
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $plugin_slug,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post->post_name,
</ins><span class="cx" style="display: block; padding: 0 10px"> $number
</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">- wp_cache_set( "{$plugin_slug}_last{$number}", $reviews, 'plugin-reviews', HOUR_IN_SECONDS );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_cache_set( "{$post->post_name}_last{$number}", $reviews, 'plugin-reviews', HOUR_IN_SECONDS );
</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 $reviews;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -82,21 +88,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @static
</span><span class="cx" style="display: block; padding: 0 10px"> * @global \wpdb $wpdb WordPress database abstraction object.
</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 string $plugin_slug The plugin slug.
- * @param bool $use_cache If we should use the cache, or fetch new data.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $post The plugin slug, WP_Post, or ID.
+ * @param bool $use_cache If we should use the cache, or fetch new data.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return array The list of user_login's which have commit.
</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 get_plugin_committers( $plugin_slug, $use_cache = true ) {
- if ( ! $plugin_slug ) {
- return array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function get_plugin_committers( $post, $use_cache = true ) {
+ $post = Plugin_Directory::get_plugin_post( $post );
+ if ( ! $post ) {
+ return [];
</ins><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">- if ( ! $use_cache || false === ( $committers = wp_cache_get( $plugin_slug, 'plugin-committers' ) ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $committers = wp_cache_get( $post->post_name, 'plugin-committers' );
+
+ if ( false === $committers || ! $use_cache ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $committers = $wpdb->get_col( $wpdb->prepare( 'SELECT user FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE path = %s', "/{$plugin_slug}" ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $committers = $wpdb->get_col( $wpdb->prepare(
+ 'SELECT user FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE path = %s',
+ '/' . $post->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">- wp_cache_set( $plugin_slug, $committers, 'plugin-committers', 12 * HOUR_IN_SECONDS );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_cache_set( $post->post_name, $committers, 'plugin-committers', 12 * HOUR_IN_SECONDS );
</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 $committers;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -112,10 +124,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array The list of plugins the user has commit to.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function get_users_write_access_plugins( $user ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $user instanceof \WP_User ) {
- $user = new \WP_User( $user );
- }
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $user = new WP_User( $user );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $user->exists() ) {
</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">@@ -123,7 +132,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( false === ( $plugins = wp_cache_get( $user->user_login, 'committer-plugins' ) ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $plugins = $wpdb->get_col( $wpdb->prepare( 'SELECT path FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE user = %s', $user->user_login ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $plugins = $wpdb->get_col( $wpdb->prepare(
+ 'SELECT path FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE user = %s',
+ $user->user_login
+ ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> $plugins = array_map( function ( $plugin ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return trim( $plugin, '/' );
</span><span class="cx" style="display: block; padding: 0 10px"> }, $plugins );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -141,16 +153,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Syncs the list of committers from the svn_access table to a taxonomy.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @static
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $plugin_slug The Plugin Slug to sync.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $post The plugin slug, WP_Post, or ID.
</ins><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 sync_plugin_committers_with_taxonomy( $plugin_slug ) {
- $post = Plugin_Directory::get_plugin_post( $plugin_slug );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function sync_plugin_committers_with_taxonomy( $post ) {
+ $post = Plugin_Directory::get_plugin_post( $post );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $post ) {
</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="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $committer_slugs = array();
- foreach ( Tools::get_plugin_committers( $plugin_slug, false /* Do not use the cache */ ) as $committer ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $committer_slugs = [];
+ foreach ( Tools::get_plugin_committers( $post, false /* Do not use the cache */ ) as $committer ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $user = get_user_by( 'login', $committer );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $user ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $committer_slugs[] = $user->user_nicename;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -166,37 +178,37 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @static
</span><span class="cx" style="display: block; padding: 0 10px"> * @global \wpdb $wpdb WordPress database abstraction object.
</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 string $plugin_slug The plugin slug.
- * @param string|\WP_User $user The user to grant access to.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $post The plugin slug, WP_Post, or ID.
+ * @param string|\WP_User $user The user to grant access to.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return bool
</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 grant_plugin_committer( $plugin_slug, $user ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function grant_plugin_committer( $post, $user ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $user instanceof \WP_User ) {
- $user = new \WP_User( $user );
- }
-
- if ( ! $user->exists() || ! $plugin_slug || ! Plugin_Directory::get_plugin_post( $plugin_slug ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post = Plugin_Directory::get_plugin_post( $post );
+ $user = new WP_User( $user );
+ if ( ! $post || ! $user->exists() ) {
</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">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $existing_committers = self::get_plugin_committers( $plugin_slug );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $existing_committers = Tools::get_plugin_committers( $post );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( in_array( $user->user_login, $existing_committers, true ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> // User already has write access.
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</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">- $result = (bool) $wpdb->insert( PLUGINS_TABLE_PREFIX . 'svn_access', array(
- 'path' => "/{$plugin_slug}",
- 'user' => $user->user_login,
- 'access' => 'rw',
- ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result = (bool) $wpdb->insert(
+ PLUGINS_TABLE_PREFIX . 'svn_access',
+ [
+ 'path' => '/' . $post->post_name,
+ 'user' => $user->user_login,
+ 'access' => 'rw',
+ ]
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_cache_delete( $plugin_slug, 'plugin-committers' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_cache_delete( $post->post_name, 'plugin-committers' );
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_cache_delete( $user->user_login, 'committer-plugins' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- Tools::sync_plugin_committers_with_taxonomy( $plugin_slug );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ Tools::sync_plugin_committers_with_taxonomy( $post );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> Tools::audit_log(
</span><span class="cx" style="display: block; padding: 0 10px"> sprintf(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -204,7 +216,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> esc_url( 'https://profiles.wordpress.org/' . $user->user_nicename . '/' ),
</span><span class="cx" style="display: block; padding: 0 10px"> $user->user_login
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $plugin_slug
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post
</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"> // Only notify if the current process is interactive - a user is logged in.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -218,7 +230,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $existing_committers[] = $user->user_login;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $email = new Committer_Added_Email(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $plugin_slug,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post,
</ins><span class="cx" style="display: block; padding: 0 10px"> $existing_committers,
</span><span class="cx" style="display: block; padding: 0 10px"> [
</span><span class="cx" style="display: block; padding: 0 10px"> 'committer' => $user,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -236,29 +248,30 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @static
</span><span class="cx" style="display: block; padding: 0 10px"> * @global \wpdb $wpdb WordPress database abstraction object.
</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 string $plugin_slug The plugin slug.
- * @param string|\WP_User $user The user to revoke access of.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $post The plugin slug, WP_Post, or ID.
+ * @param string|\WP_User $user The user to revoke access of.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return bool
</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 revoke_plugin_committer( $plugin_slug, $user ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function revoke_plugin_committer( $post, $user ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $user instanceof \WP_User ) {
- $user = new \WP_User( $user );
- }
-
- if ( ! $user->exists() || ! $plugin_slug || ! Plugin_Directory::get_plugin_post( $plugin_slug ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post = Plugin_Directory::get_plugin_post( $post );
+ $user = new WP_User( $user );
+ if ( ! $post || ! $user->exists() ) {
</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">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $result = (bool) $wpdb->delete( PLUGINS_TABLE_PREFIX . 'svn_access', array(
- 'path' => "/{$plugin_slug}",
- 'user' => $user->user_login,
- ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result = (bool) $wpdb->delete(
+ PLUGINS_TABLE_PREFIX . 'svn_access',
+ [
+ 'path' => '/' . $post->post_name,
+ 'user' => $user->user_login,
+ ]
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_cache_delete( $plugin_slug, 'plugin-committers' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_cache_delete( $post->post_name, 'plugin-committers' );
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_cache_delete( $user->user_login, 'committer-plugins' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- Tools::sync_plugin_committers_with_taxonomy( $plugin_slug );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ Tools::sync_plugin_committers_with_taxonomy( $post );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> Tools::audit_log(
</span><span class="cx" style="display: block; padding: 0 10px"> sprintf(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -266,7 +279,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> esc_url( 'https://profiles.wordpress.org/' . $user->user_nicename . '/' ),
</span><span class="cx" style="display: block; padding: 0 10px"> $user->user_login
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $plugin_slug
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post
</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 $result;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -284,14 +297,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public static function get_support_rep_plugins( $user ) {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $user instanceof \WP_User ) {
- $user = new \WP_User( $user );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $user = new WP_User( $user );
+ if ( ! $user->exists() ) {
+ return [];
</ins><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">- $plugins = [];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $plugins = wp_cache_get( $user->user_nicename, 'support-rep-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">- if ( $user->exists() && ( false === ( $plugins = wp_cache_get( $user->user_nicename, 'support-rep-plugins' ) ) ) ) {
- $query = new \WP_Query( [
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( false === $plugins ) {
+ $plugins = get_posts( [
+ 'fields' => 'ids',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'post_type' => 'plugin',
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_status' => 'publish',
</span><span class="cx" style="display: block; padding: 0 10px"> 'posts_per_page' => 250,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -305,11 +320,14 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $plugins = $query->have_posts() ? $query->posts : [];
-
</del><span class="cx" style="display: block; padding: 0 10px"> wp_cache_set( $user->user_nicename, $plugins, 'support-rep-plugins', 12 * HOUR_IN_SECONDS );
</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">+ // ID's to objects.
+ if ( $plugins && is_int( $plugins[0] ) ) {
+ $plugins = array_map( 'get_post', $plugins );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $plugins;
</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">@@ -318,19 +336,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @static
</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 string $plugin_slug The plugin slug.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $post The plugin slug, WP_Post, or ID.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return array The list of user_nicename's which are support reps.
</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 get_plugin_support_reps( $plugin_slug ) {
- if ( ! $plugin_slug ) {
- return array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function get_plugin_support_reps( $post ) {
+ $post = Plugin_Directory::get_plugin_post( $post );
+ if ( ! $post ) {
+ return [];
</ins><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">- if ( false === ( $support_reps = wp_cache_get( $plugin_slug, 'plugin-support-reps' ) ) ) {
- $post = Plugin_Directory::get_plugin_post( $plugin_slug );
- $support_reps = wp_get_object_terms( $post->ID, 'plugin_support_reps', array( 'fields' => 'names' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $support_reps = wp_cache_get( $post->post_name, 'plugin-support-reps' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_cache_set( $plugin_slug, $support_reps, 'plugin-support-reps', 12 * HOUR_IN_SECONDS );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( false === $support_reps ) {
+ $support_reps = wp_get_object_terms( $post->ID, 'plugin_support_reps', [ 'fields' => 'names' ] );
+
+ wp_cache_set( $post->post_name, $support_reps, 'plugin-support-reps', 12 * HOUR_IN_SECONDS );
</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 $support_reps;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -341,28 +361,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @static
</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 string $plugin_slug The plugin slug.
- * @param string|\WP_User $user The user to add.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $post The plugin slug, WP_Post, or ID.
+ * @param string|\WP_User $user The user to add.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return bool
</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 add_plugin_support_rep( $plugin_slug, $user ) {
- if ( ! $user instanceof \WP_User ) {
- $user = new \WP_User( $user );
- }
-
- if ( ! $user->exists() || ! $plugin_slug ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function add_plugin_support_rep( $post, $user ) {
+ $post = Plugin_Directory::get_plugin_post( $post );
+ $user = new WP_User( $user );
+ if ( ! $post || ! $user->exists() ) {
</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">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $post = Plugin_Directory::get_plugin_post( $plugin_slug );
-
- if ( ! $post ) {
- return false;
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> $result = wp_add_object_terms( $post->ID, $user->user_nicename, 'plugin_support_reps' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_cache_delete( $plugin_slug, 'plugin-support-reps' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_cache_delete( $post->post_name, 'plugin-support-reps' );
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_cache_delete( $user->user_nicename, 'support-rep-plugins' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> Tools::audit_log(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -371,10 +383,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> esc_url( 'https://profiles.wordpress.org/' . $user->user_nicename . '/' ),
</span><span class="cx" style="display: block; padding: 0 10px"> $user->user_login
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $plugin_slug
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post
</ins><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">- $committers = self::get_plugin_committers( $plugin_slug );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $committers = Tools::get_plugin_committers( $post );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Only notify if the current process is interactive - a user is logged in.
</span><span class="cx" style="display: block; padding: 0 10px"> $should_notify = (bool) get_current_user_id();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -385,7 +397,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $should_notify ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $email = new Support_Rep_Added_Email(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $plugin_slug,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post,
</ins><span class="cx" style="display: block; padding: 0 10px"> $committers,
</span><span class="cx" style="display: block; padding: 0 10px"> [
</span><span class="cx" style="display: block; padding: 0 10px"> 'rep' => $user,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -402,28 +414,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @static
</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 string $plugin_slug The plugin slug.
- * @param string|\WP_User $user The user to remove.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $post The plugin slug, WP_Post, or ID.
+ * @param string|\WP_User $user The user to remove.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return bool
</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 remove_plugin_support_rep( $plugin_slug, $user ) {
- if ( ! $user instanceof \WP_User ) {
- $user = new \WP_User( $user );
- }
-
- if ( ! $user->exists() || ! $plugin_slug ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function remove_plugin_support_rep( $post, $user ) {
+ $post = Plugin_Directory::get_plugin_post( $post );
+ $user = new WP_User( $user );
+ if ( ! $post || ! $user->exists() ) {
</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">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $post = Plugin_Directory::get_plugin_post( $plugin_slug );
-
- if ( ! $post ) {
- return false;
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> $result = wp_remove_object_terms( $post->ID, $user->user_nicename, 'plugin_support_reps' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_cache_delete( $plugin_slug, 'plugin-support-reps' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_cache_delete( $post->post_name, 'plugin-support-reps' );
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_cache_delete( $user->user_nicename, 'support-rep-plugins' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> Tools::audit_log(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -432,7 +436,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> esc_url( 'https://profiles.wordpress.org/' . $user->user_nicename . '/' ),
</span><span class="cx" style="display: block; padding: 0 10px"> $user->user_login
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $plugin_slug
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post
</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 $result;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -446,24 +450,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @static
</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 string $plugin_slug The plugin to subscribe to.
- * @param int|WP_User $user Optional. The user to subscribe. Default current user.
- * @param bool $subscribe Optional. Whether to subscribe (true) or unsubscribe (false).
- * Default: true.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $post The plugin slug, WP_Post, or ID.
+ * @param int|WP_User $user The user to subscribe. Optional. Default current user.
+ * @param bool $subscribe Whether to subscribe (true) or unsubscribe (false).
+ * Optional. Default: true.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return bool Whether the user is subscribed.
</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 subscribe_to_plugin_commits( $plugin_slug, $user = 0, $subscribe = true ) {
- $post = Plugin_Directory::get_plugin_post( $plugin_slug );
- if ( ! $post ) {
- return false;
- }
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function subscribe_to_plugin_commits( $post, $user = 0, $subscribe = true ) {
+ $post = Plugin_Directory::get_plugin_post( $post );
</ins><span class="cx" style="display: block; padding: 0 10px"> $user = new WP_User( $user ?: get_current_user_id() );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $user->exists() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $post || ! $user->exists() ) {
</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">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $users = get_post_meta( $post->ID, '_commit_subscribed', true ) ?: array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $users = get_post_meta( $post->ID, '_commit_subscribed', true ) ?: [];
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $subscribe ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $users[] = $user->ID;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -476,7 +476,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> update_post_meta( $post->ID, '_commit_subscribed', $users );
</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 self::subscribed_to_plugin_commits( $plugin_slug, $user->ID );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return Tools::subscribed_to_plugin_commits( $post, $user->ID );
</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">@@ -487,22 +487,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @static
</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 string $plugin_slug The plugin to subscribe to.
- * @param int|WP_User $user Optional. The user to check. Default current user.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $post The plugin slug, WP_Post, or ID.
+ * @param int|WP_User $user The user to check. Optional. Default current user.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return bool Whether the specified user is subscribed to commits.
</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 subscribed_to_plugin_commits( $plugin_slug, $user = 0 ) {
- $post = Plugin_Directory::get_plugin_post( $plugin_slug );
- if ( ! $post ) {
- return false;
- }
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function subscribed_to_plugin_commits( $post, $user = 0 ) {
+ $post = Plugin_Directory::get_plugin_post( $post );
</ins><span class="cx" style="display: block; padding: 0 10px"> $user = new WP_User( $user ?: get_current_user_id() );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $user->exists() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $post || ! $user->exists() ) {
</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">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $users = get_post_meta( $post->ID, '_commit_subscribed', true ) ?: array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $users = get_post_meta( $post->ID, '_commit_subscribed', true ) ?: [];
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return in_array( $user->ID, $users, true );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -510,22 +506,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Determine if a plugin has been favorited by a user.
</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 string $plugin_slug The plugin to check.
- * @param mixed $user The user to check.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $post The plugin to check.
+ * @param mixed $user The user to check.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return bool
</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 favorited_plugin( $plugin_slug, $user = 0 ) {
- $post = Plugin_Directory::get_plugin_post( $plugin_slug );
- if ( ! $post ) {
- return false;
- }
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function favorited_plugin( $post, $user = 0 ) {
+ $post = Plugin_Directory::get_plugin_post( $post );
</ins><span class="cx" style="display: block; padding: 0 10px"> $user = new WP_User( $user ?: get_current_user_id() );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $user->exists() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $post || ! $user->exists() ) {
</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">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $users_favorites = get_user_meta( $user->ID, 'plugin_favorites', true ) ?: array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $users_favorites = get_user_meta( $user->ID, 'plugin_favorites', true ) ?: [];
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return in_array( $post->post_name, $users_favorites, true );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -533,23 +525,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Favorite a plugin
</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 string $plugin_slug The plugin to favorite
- * @param mixed $user The user favorite
- * @param bool $favorite Whether it's a favorite, or unfavorite.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $post The plugin to favorite
+ * @param mixed $user The user favoriting. Optional. Default current user.
+ * @param bool $favorite Whether it's a favorite, or unfavorite. Optional. Default true
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return bool
</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 favorite_plugin( $plugin_slug, $user = 0, $favorite = true ) {
- $post = Plugin_Directory::get_plugin_post( $plugin_slug );
- if ( ! $post ) {
- return false;
- }
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function favorite_plugin( $post, $user = 0, $favorite = true ) {
+ $post = Plugin_Directory::get_plugin_post( $post );
</ins><span class="cx" style="display: block; padding: 0 10px"> $user = new WP_User( $user ?: get_current_user_id() );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $user->exists() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $post || ! $user->exists() ) {
</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">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $users_favorites = get_user_meta( $user->ID, 'plugin_favorites', true ) ?: array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $users_favorites = get_user_meta( $user->ID, 'plugin_favorites', true ) ?: [];
</ins><span class="cx" style="display: block; padding: 0 10px"> $already_favorited = in_array( $post->post_name, $users_favorites, true );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $favorite && $already_favorited ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -571,17 +559,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Retrieve a list of users who are subscribed to plugin commits.
</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 string $plugin_slug The plugin to retrieve subscribers for.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $post The plugin to retrieve subscribers for.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param bool $include_committers Whether to include Plugin Committers in the list. Default false.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array Array of \WP_User's who are subscribed.
</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 get_plugin_subscribers( $plugin_slug, $include_committers = false ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function get_plugin_subscribers( $post, $include_committers = false ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post = Plugin_Directory::get_plugin_post( $post );
+ if ( ! $post ) {
+ return [];
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $users = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $users = [];
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Plugin Committers are always subscrived to plugin commits.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $committers = self::get_plugin_committers( $plugin_slug );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $committers = Tools::get_plugin_committers( $post );
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $committers as $committer ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $committer && $user = get_user_by( 'login', $committer ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $users[] = $user;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -588,13 +580,8 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $post = Plugin_Directory::get_plugin_post( $plugin_slug );
- if ( ! $post ) {
- return $users;
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> // These users are subscribed the plugin commits.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $subscribers = get_post_meta( $post->ID, '_commit_subscribed', true ) ?: array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $subscribers = get_post_meta( $post->ID, '_commit_subscribed', true ) ?: [];
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $subscribers as $subscriber_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $subscriber_id && $user = get_user_by( 'id', $subscriber_id ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $users[] = $user;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -626,18 +613,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Add an Audit Internal Note for a plugin.
</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|string|WP_Post $plugin A Post ID, Plugin Slug or, WP_Post object.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $post A Post ID, Plugin Slug or, WP_Post object.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $note The note to audit log entry to add.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_User $user The user which performed the action. Optional.
</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 audit_log( $note, $plugin = null, $user = false ) {
- if ( is_string( $plugin ) && ! is_numeric( $plugin ) ) {
- $plugin = Plugin_Directory::get_plugin_post( $plugin );
- } else {
- $plugin = get_post( $plugin );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function audit_log( $note, $post = null, $user = false ) {
+ $post = Plugin_Directory::get_plugin_post( $post );
</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 ( ! $note || ! $plugin ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $note || ! $post ) {
</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"> if ( ! $user || ! ( $user instanceof \WP_User ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -650,7 +633,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'comment_author_url' => $user->user_url,
</span><span class="cx" style="display: block; padding: 0 10px"> 'comment_author_IP' => $_SERVER['REMOTE_ADDR'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'comment_type' => 'internal-note',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'comment_post_ID' => $plugin->ID,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'comment_post_ID' => $post->ID,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'user_id' => $user->ID,
</span><span class="cx" style="display: block; padding: 0 10px"> 'comment_content' => $note,
</span><span class="cx" style="display: block; padding: 0 10px"> ] );
</span></span></pre>
</div>
</div>
</body>
</html>