<!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>[4024] sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory/inc: Translate, Theme Directory: Add trigger and listener to build theme language packs.</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 { 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/4024">4024</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/4024","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>ocean90</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-09-09 19:47:55 +0000 (Fri, 09 Sep 2016)</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'>Translate, Theme Directory: Add trigger and listener to build theme language packs.

The build event, which is delayed by 30 minutes after a translation change, is triggered by the Cron API (Cavalcade).
<a href="http://meta.trac.wordpress.org/changeset/3953">[3953]</a> introduced the WP-CLI command for this.

See <a href="http://meta.trac.wordpress.org/changeset/4015">[4015]</a> for plugins.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpthemedirectoryincclasspluginphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory/inc/class-plugin.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpthemedirectoryinccliclasssetthemeprojectphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory/inc/cli/class-set-theme-project.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory/inc/language-pack/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpthemedirectoryinclanguagepackclassbuildlistenerphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory/inc/language-pack/class-build-listener.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpthemedirectoryinclanguagepackclassbuildtriggerphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory/inc/language-pack/class-build-trigger.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpthemedirectoryincclasspluginphp"></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/wporg-gp-theme-directory/inc/class-plugin.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/wporg-gp-theme-directory/inc/class-plugin.php    2016-09-09 17:59:50 UTC (rev 4023)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory/inc/class-plugin.php      2016-09-09 19:47:55 UTC (rev 4024)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -12,10 +12,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">        private static $instance;
</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">-         *
-        * @var Sync\Translation_Sync
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Parent project for themes.
</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 $translation_sync = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ const GP_MASTER_PROJECT = 'wp-themes';
</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">         * Returns always the same instance of this plugin.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -42,6 +41,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function plugins_loaded() {
</span><span class="cx" style="display: block; padding: 0 10px">                add_action( 'wporg_translate_import_or_update_theme', array( $this, 'import_or_update_theme_on_status_change' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $language_pack_build_trigger = new Language_Pack\Build_Trigger();
+               $language_pack_build_trigger->register_events();
+
+               $language_pack_build_listener = new Language_Pack\Build_Listener(
+                       Language_Pack\Build_Trigger::HOOK
+               );
+               $language_pack_build_listener->register_events();
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( defined( 'WP_CLI' ) && WP_CLI ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->register_cli_commands();
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -93,6 +100,26 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Returns whether a project path belongs to the themes project.
+        *
+        * @param string $path Path of a project.
+        *
+        * @return bool True if it's a theme, false if not.
+        */
+       public static function project_is_theme( $path ) {
+               if ( empty( $path ) ) {
+                       return false;
+               }
+
+               $path = '/' . trim( $path, '/' ) . '/';
+               if ( false === strpos( $path, '/' . self::GP_MASTER_PROJECT . '/' ) ) {
+                       return false;
+               }
+
+               return true;
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Sends a notifcation to the the Slack channel.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param array $attachment The attachment of a notification.
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpthemedirectoryinccliclasssetthemeprojectphp"></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/wporg-gp-theme-directory/inc/cli/class-set-theme-project.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/wporg-gp-theme-directory/inc/cli/class-set-theme-project.php     2016-09-09 17:59:50 UTC (rev 4023)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory/inc/cli/class-set-theme-project.php       2016-09-09 19:47:55 UTC (rev 4024)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4,19 +4,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> use GP;
</span><span class="cx" style="display: block; padding: 0 10px"> use MakePOT;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use WordPressdotorg\GlotPress\Theme_Directory\Plugin;
</ins><span class="cx" style="display: block; padding: 0 10px"> use WP_CLI;
</span><span class="cx" style="display: block; padding: 0 10px"> use WP_CLI_Command;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> class Set_Theme_Project extends WP_CLI_Command {
</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">-         * Holds the path of the master project.
-        *
-        * @var string
-        */
-       private $master_project_path = 'wp-themes';
-
-       /**
</del><span class="cx" style="display: block; padding: 0 10px">          * Holds the path of the projects to copy translation sets from.
</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="lines" style="display: block; padding: 0 10px; color: #888">@@ -174,7 +168,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return \GP_Project|false GP project on success, false on failure.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        private function find_create_update_glotpress_project( $theme_slug, $theme_data ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $parent_project = GP::$project->by_path( $this->master_project_path );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $parent_project = GP::$project->by_path( Plugin::GP_MASTER_PROJECT );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $project_path = $parent_project->path . '/' . $theme_slug;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $project_args = array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -220,7 +214,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @param string $theme_slug The theme to mark inactive.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        private function mark_glotpress_project_inactive( $theme_slug ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $project = GP::$project->by_path( "{$this->master_project_path}/{$theme_slug}" );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $project = GP::$project->by_path( Plugin::GP_MASTER_PROJECT . "/{$theme_slug}" );
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( $project ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $project->save( array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'active' => 0,
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpthemedirectoryinclanguagepackclassbuildlistenerphp"></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/wporg-gp-theme-directory/inc/language-pack/class-build-listener.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/wporg-gp-theme-directory/inc/language-pack/class-build-listener.php                              (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory/inc/language-pack/class-build-listener.php        2016-09-09 19:47:55 UTC (rev 4024)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,89 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\GlotPress\Theme_Directory\Language_Pack;
+
+class Build_Listener {
+
+       /**
+        * The name of the scheduled action.
+        *
+        * @var string
+        */
+       private $hook;
+
+       /**
+        * Constructor.
+        *
+        * @param string $hook The name of the scheduled action.
+        */
+       public function __construct( $hook ) {
+               $this->hook = $hook;
+       }
+
+       /**
+        * Registers actions and filters.
+        */
+       public function register_events() {
+               add_action( $this->hook, [ $this, 'run_build' ] );
+       }
+
+       /**
+        * Runs the WP-CLI command to generate a theme language pack.
+        *
+        * @param array $args Arguments from the job. Should include the slug of a theme.
+        * @return bool False on failure, true on success.
+        */
+       public function run_build( $args ) {
+               if ( ! defined( 'WPORGTRANSLATE_WPCLI' ) ) {
+                       return false;
+               }
+
+               if ( ! isset( $args['theme'] ) ) {
+                       return false;
+               }
+
+               $time = date( 'r' );
+               $message = "_Time: {$time}_\nLanguage packs for {$args['theme']} in process...\n";
+
+               // Build in a separate process.
+               $cmd = WPORGTRANSLATE_WPCLI . ' wporg-translate language-pack generate theme ' . escapeshellarg( $args['theme'] ) . ' 2>&1';
+               exec( $cmd, $output, $return_var );
+               if ( $return_var ) {
+                       $message .= "\tFailure: " . implode( "\n\t", $output ) . "\n";
+               } else {
+                       $message .= "\t" . implode( "\n\t", $output ) . "\n";
+               }
+
+               $message .= "Language packs for {$args['theme']} processed.\n";
+
+               $attachment = [
+                       'title'      => "Language packs for {$args['theme']}",
+                       'title_link' => "https://translate.wordpress.org/projects/wp-themes/{$args['theme']}",
+                       'text'       => $message,
+                       'fallback'   => "Language packs for {$args['theme']} were processed.",
+                       'color'      => '#c32283',
+                       'mrkdwn_in'  => [ 'text' ],
+               ];
+               $this->slack( $attachment );
+
+               return true;
+       }
+
+       /**
+        * Sends a notifcation to the Slack channel.
+        *
+        * @param array $attachment The attachment of a notification.
+        */
+       private function slack( $attachment ) {
+               if ( ! defined( 'GLOTPRESS_SLACK_WEBHOOK' ) ) {
+                       return;
+               }
+
+               require_once API_WPORGPATH . 'includes/slack-config.php';
+               $send = new \Dotorg\Slack\Send( GLOTPRESS_SLACK_WEBHOOK );
+               $send->add_attachment( $attachment );
+               $send->set_username( 'Theme Language Packs' );
+               $send->set_icon( ':package:' );
+               $send->send( '#meta-language-packs' );
+       }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpthemedirectoryinclanguagepackclassbuildtriggerphp"></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/wporg-gp-theme-directory/inc/language-pack/class-build-trigger.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/wporg-gp-theme-directory/inc/language-pack/class-build-trigger.php                               (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory/inc/language-pack/class-build-trigger.php 2016-09-09 19:47:55 UTC (rev 4024)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,139 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\GlotPress\Theme_Directory\Language_Pack;
+
+use GP;
+use WordPressdotorg\GlotPress\Theme_Directory\Plugin;
+
+class Build_Trigger {
+
+       /**
+        * The name of the schedule hook.
+        */
+       const HOOK = 'wporg_translate_build_theme_language_pack';
+
+       /**
+        * The time delay in minutes before a build is triggered.
+        */
+       const TIME_DELAY = 30;
+
+       /**
+        * Array of theme slugs.
+        *
+        * @var array
+        */
+       private $queue = [];
+
+       /**
+        * Registers actions and filters.
+        */
+       public function register_events() {
+               add_action( 'gp_translation_created', [ $this, 'queue_project_on_translation_edit' ] );
+               add_action( 'gp_translation_saved', [ $this, 'queue_project_on_translation_edit' ] );
+               add_action( 'gp_originals_imported', [ $this, 'queue_project_on_originals_import' ], 10, 5 );
+
+               add_filter( 'schedule_event', [ $this, 'limit_duplicate_events' ] );
+
+               add_action( 'shutdown', [ $this, 'trigger_build' ] );
+       }
+
+       /**
+        * Adds a project to a queue when a translation was created
+        * or updated.
+        *
+        * @param \GP_Translation $translation Created/updated translation.
+        */
+       public function queue_project_on_translation_edit( $translation ) {
+               global $wpdb;
+
+               // Only current translations without warnings.
+               if ( 'current' !== $translation->status || ! empty( $translation->warnings ) ) {
+                       return;
+               }
+
+               $project = GP::$project->one(
+                       "SELECT p.* FROM {$wpdb->gp_projects} AS p JOIN {$wpdb->gp_originals} AS o ON o.project_id = p.id WHERE o.id = %d",
+                       $translation->original_id
+               );
+
+               if ( ! $project || ! Plugin::project_is_theme( $project->path ) ) {
+                       return;
+               }
+
+               $project_parts = explode( '/', $project->path ); // wp-themes/$theme_slug/
+
+               if ( isset( $project_parts[1] ) ) {
+                       $this->queue[ $project_parts[1] ] = true;
+               }
+       }
+
+       /**
+        * Adds a project to a queue when originals get imported.
+        *
+        * @param string $project_id          Project ID the import was made to.
+        * @param int    $originals_added     Number or total originals added.
+        * @param int    $originals_existing  Number of existing originals updated.
+        * @param int    $originals_obsoleted Number of originals that were marked as obsolete.
+        * @param int    $originals_fuzzied   Number of originals that were close matches of old ones and thus marked as fuzzy.
+        */
+       public function queue_project_on_originals_import( $project_id, $originals_added, $originals_existing, $originals_obsoleted, $originals_fuzzied ) {
+               if ( ! $originals_added && ! $originals_existing && ! $originals_fuzzied && ! $originals_obsoleted ) {
+                       return;
+               }
+
+               $project = GP::$project->get( $project_id );
+
+               if ( ! $project || ! Plugin::project_is_theme( $project->path ) ) {
+                       return;
+               }
+
+               $project_parts = explode( '/', $project->path ); // wp-themes/$theme_slug/
+
+               if ( isset( $project_parts[1] ) ) {
+                       $this->queue[ $project_parts[1] ] = true;
+               }
+       }
+
+       /**
+        * Schedules a build for a theme language pack.
+        */
+       public function trigger_build() {
+               if ( empty( $this->queue ) ) {
+                       return;
+               }
+
+               foreach ( array_keys( $this->queue ) as $theme_slug ) {
+                       wp_schedule_single_event( time() + self::TIME_DELAY * MINUTE_IN_SECONDS, self::HOOK, [
+                               [
+                                       'theme' => $theme_slug,
+                               ],
+                       ] );
+               }
+       }
+
+       /**
+        * Prevents scheduling a duplicate if there's already an identical event due within 30 minutes of it.
+        *
+        * @param stdClass $event {
+        *     An object containing an event's data.
+        *
+        *     @type string       $hook      Action hook to execute when event is run.
+        *     @type int          $timestamp Unix timestamp (UTC) for when to run the event.
+        *     @type string|false $schedule  How often the event should recur. See `wp_get_schedules()`.
+        *     @type array        $args      Arguments to pass to the hook's callback function.
+        * }
+        * @return bool|stdClass False if there is already an event, otherwise the original event data.
+        */
+       public function limit_duplicate_events( $event ) {
+               if ( self::HOOK !== $event->hook ) {
+                       return $event;
+               }
+
+               $next = wp_next_scheduled( $event->hook, $event->args );
+               if ( $next && abs( $next - $event->timestamp ) <= self::TIME_DELAY * MINUTE_IN_SECONDS ) {
+                       return false;
+               }
+
+               return $event;
+       }
+}
</ins></span></pre>
</div>
</div>

</body>
</html>