Making WordPress.org

Ticket #1405: 1405-tggr.diff

File 1405-tggr.diff, 1.8 KB (added by coreymckrill, 7 years ago)

Patch for Tagregator plugin

  • classes/tggr-shortcode-tagregator.php

     
    258258                 * @param string $rate_limit 'respect' to enforce the rate limit, or 'ignore' to ignore it
    259259                 */
    260260                protected function import_new_items( $hashtags, $rate_limit = 'respect' ) {
     261                        if ( ! $this->is_within_date_range() ) {
     262                                return;
     263                        }
     264
    261265                        $semaphore_key = (int) base_convert( substr( md5( __METHOD__ . site_url() ), 0, 8 ), 16, 10 );
    262266                        $semaphore_id  = function_exists( 'sem_get' ) ? sem_get( $semaphore_key ) : false;
    263267
     
    339343                                }
    340344                        }
    341345                }
     346
     347                /**
     348                 * Check if the current date is within an optionally specified date range.
     349                 *
     350                 * @return bool True if the current date is within the date range, or if no date range is specified.
     351                 */
     352                protected function is_within_date_range() {
     353                        $blog_id = get_current_blog_id();
     354
     355                        /**
     356                         * Filter: Optionally set a date on which Tagregator will begin importing new items.
     357                         *
     358                         * @param DateTime|null $start_date The date that Tagregator should start importing items. Default null.
     359                         */
     360                        $start_date = apply_filters( Tagregator::PREFIX . 'start_date', null );
     361
     362                        /**
     363                         * Filter: Optionally set a date on which Tagregator will stop importing new items.
     364                         *
     365                         * @param DateTime|null $end_date The date that Tagregator should stop importing items. Default null.
     366                         */
     367                        $end_date = apply_filters( Tagregator::PREFIX . 'end_date', null );
     368
     369                        $now = new DateTime( 'now' );
     370
     371                        if ( $start_date instanceof DateTime && $now < $start_date ) {
     372                                return false;
     373                        }
     374
     375                        if ( $end_date instanceof DateTime && $now > $end_date ) {
     376                                return false;
     377                        }
     378
     379                        return true;
     380                }
    342381        } // end TGGRShortcodeTagregator
    343382}