Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions inc/global-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,29 @@
die( 'Access Denied.' );
}

function mailrelay_new_user_auto_sync( $user_id ) {
function mailrelay_user_register_hook( $user_id ) {
if ( '1' !== get_option( 'mailrelay_auto_sync' ) ) {
// Autosync isn't enabled
return;
}

$user = new WP_User( $user_id );
// Schedule the sync to run in the background
as_enqueue_async_action(
'mailrelay_sync_user_background',
array( $user_id ),
'mailrelay',
true
);
}
add_action( 'user_register', 'mailrelay_user_register_hook' );

/**
* Background handler for syncing users with Mailrelay
*
* @param int $user_id The WordPress user ID to sync.
*/
function mailrelay_sync_user_background( $user_id ) {
$user = new WP_User( $user_id );
$groups = get_option( 'mailrelay_auto_sync_groups' );

if ( ! empty( $groups ) ) {
Expand All @@ -22,4 +37,4 @@ function mailrelay_new_user_auto_sync( $user_id ) {
}
}
}
add_action( 'user_register', 'mailrelay_new_user_auto_sync' );
add_action( 'mailrelay_sync_user_background', 'mailrelay_sync_user_background', 10, 1 );
24 changes: 24 additions & 0 deletions libraries/action-scheduler/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
tab_width = 4
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true

[*.txt]
trim_trailing_whitespace = false

[*.{md,json,yml}]
trim_trailing_whitespace = false
indent_style = space
indent_size = 2
14 changes: 14 additions & 0 deletions libraries/action-scheduler/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
docs export-ignore
tests export-ignore
codecov.yml export-ignore
.editorconfig export-ignore
.github export-ignore
.travis.yml export-ignore
.gitattributes export-ignore
.gitignore export-ignore
composer.* export-ignore
Gruntfile.js export-ignore
package.json export-ignore
package-lock.json export-ignore
phpcs.xml export-ignore
phpunit.* export-ignore
15 changes: 15 additions & 0 deletions libraries/action-scheduler/.github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
template: |
## next release – date

<!-- Move the individual changes below into the appropriate section -->

$CHANGES

**Added**
**Changed**
**Deprecated**
**Removed**
**Fixed**
**Security**

change-template: '* $TITLE (PR #$NUMBER)'
97 changes: 97 additions & 0 deletions libraries/action-scheduler/.github/workflows/pr-unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Run unit tests on PR
on:
pull_request
jobs:
test:
name: PHP ${{ matrix.php }} WP ${{ matrix.wp }} MU ${{ matrix.multisite }}
timeout-minutes: 15
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# We test against the earliest and latest PHP versions for each major supported version.
php: [ '7.1', '7.4', '8.0', '8.3' ]
wp: [ '6.4', '6.5', '6.6', 'latest', 'nightly' ]
multisite: [ '0', '1' ]
exclude:
# WordPress 6.6+ requires PHP 7.2+
- php: 7.1
wp: 6.6
- php: 7.1
wp: latest
- php: 7.1
wp: nightly
services:
database:
image: mysql:5.6
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer
extensions: mysql
coverage: none

- name: Tool versions
run: |
php --version
composer --version

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist

- name: Setup PHPUnit
run: |
# PHPUnit 7.5 when using PHP 7.1 - 7.4.
if [ "$(php -r "echo version_compare( PHP_VERSION, '8.0', '<' );")" ]; then
curl -L https://phar.phpunit.de/phpunit-7.5.phar -o /tmp/phpunit
OVERWRITE=1
# PHPUnit 7.5 (Custom Fork) when using PHP 8.0+.
else
curl -L https://github.com/woocommerce/phpunit/archive/add-compatibility-with-php8-to-phpunit-7.zip -o /tmp/phpunit-7.5-fork.zip
unzip -d /tmp/phpunit-fork /tmp/phpunit-7.5-fork.zip
composer --working-dir=/tmp/phpunit-fork/phpunit-add-compatibility-with-php8-to-phpunit-7 install
rm ./vendor/bin/phpunit
ln -sf /tmp/phpunit-fork/phpunit-add-compatibility-with-php8-to-phpunit-7/phpunit ./vendor/bin/phpunit
fi

if [ $OVERWRITE ]; then
rm ./vendor/bin/phpunit
chmod +x /tmp/phpunit
mv /tmp/phpunit ./vendor/bin/phpunit
fi

- name: Install Subversion
run: sudo apt-get update && sudo apt-get install -y subversion

- name: Init DB and WP
run: ./tests/bin/install.sh woo_test root root 127.0.0.1 ${{ matrix.wp }}

- name: Run tests
run: |
./vendor/bin/phpunit --version
WP_MULTISITE=${{ matrix.multisite }} ./vendor/bin/phpunit -c ./tests/phpunit.xml.dist

- name: Code Coverage
run: |
bash <(curl -s https://codecov.io/bash)
25 changes: 25 additions & 0 deletions libraries/action-scheduler/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Operating System files
.DS_Store
Thumbs.db

# IDE files
.idea
.vscode/*
project.xml
project.properties
.project
.settings*
*.sublime-project
*.sublime-workspace
.sublimelinterrc

# Project files
node_modules/
vendor/

#PHP Unit
.phpunit.result.cache
phpunit.xml

# Build files
action-scheduler.zip
57 changes: 57 additions & 0 deletions libraries/action-scheduler/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module.exports = function( grunt ) {
'use strict';

grunt.initConfig({
// Check textdomain errors.
checktextdomain: {
options:{
text_domain: 'action-scheduler',
keywords: [
'__:1,2d',
'_e:1,2d',
'_x:1,2c,3d',
'esc_html__:1,2d',
'esc_html_e:1,2d',
'esc_html_x:1,2c,3d',
'esc_attr__:1,2d',
'esc_attr_e:1,2d',
'esc_attr_x:1,2c,3d',
'_ex:1,2c,3d',
'_n:1,2,4d',
'_nx:1,2,4c,5d',
'_n_noop:1,2,3d',
'_nx_noop:1,2,3c,4d'
]
},
files: {
src: [
'**/*.php',
'!node_modules/**',
'!tests/**',
'!vendor/**',
'!tmp/**'
],
expand: true
}
},

// PHP Code Sniffer.
phpcs: {
options: {
bin: 'vendor/bin/phpcs'
},
dist: {
src: [
'**/*.php', // Include all php files.
'!deprecated/**',
'!node_modules/**',
'!vendor/**'
]
}
}
});

// Load NPM tasks to be used here.
grunt.loadNpmTasks( 'grunt-phpcs' );
grunt.loadNpmTasks( 'grunt-checktextdomain' );
};
35 changes: 35 additions & 0 deletions libraries/action-scheduler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Action Scheduler - Job Queue for WordPress [![Build Status](https://travis-ci.org/woocommerce/action-scheduler.png?branch=master)](https://travis-ci.org/woocommerce/action-scheduler) [![codecov](https://codecov.io/gh/woocommerce/action-scheduler/branch/master/graph/badge.svg)](https://codecov.io/gh/woocommerce/action-scheduler)

Action Scheduler is a scalable, traceable job queue for background processing large sets of actions in WordPress. It's specially designed to be distributed in WordPress plugins.

Action Scheduler works by triggering an action hook to run at some time in the future. Each hook can be scheduled with unique data, to allow callbacks to perform operations on that data. The hook can also be scheduled to run on one or more occasions.

Think of it like an extension to `do_action()` which adds the ability to delay and repeat a hook.

## Battle-Tested Background Processing

Every month, Action Scheduler processes millions of payments for [Subscriptions](https://woocommerce.com/products/woocommerce-subscriptions/), webhooks for [WooCommerce](https://wordpress.org/plugins/woocommerce/), as well as emails and other events for a range of other plugins.

It's been seen on live sites processing queues in excess of 50,000 jobs and doing resource intensive operations, like processing payments and creating orders, at a sustained rate of over 10,000 / hour without negatively impacting normal site operations.

This is all on infrastructure and WordPress sites outside the control of the plugin author.

If your plugin needs background processing, especially of large sets of tasks, Action Scheduler can help.

## Learn More

To learn more about how to Action Scheduler works, and how to use it in your plugin, check out the docs on [ActionScheduler.org](https://actionscheduler.org).

There you will find:

* [Usage guide](https://actionscheduler.org/usage/): instructions on installing and using Action Scheduler
* [WP CLI guide](https://actionscheduler.org/wp-cli/): instructions on running Action Scheduler at scale via WP CLI
* [API Reference](https://actionscheduler.org/api/): complete reference guide for all API functions
* [Administration Guide](https://actionscheduler.org/admin/): guide to managing scheduled actions via the administration screen
* [Guide to Background Processing at Scale](https://actionscheduler.org/perf/): instructions for running Action Scheduler at scale via the default WP Cron queue runner

## Credits

Action Scheduler is developed and maintained by [Automattic](http://automattic.com/) with significant early development completed by [Flightless](https://flightless.us/).

Collaboration is cool. We'd love to work with you to improve Action Scheduler. [Pull Requests](https://github.com/woocommerce/action-scheduler/pulls) welcome.
70 changes: 70 additions & 0 deletions libraries/action-scheduler/action-scheduler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Plugin Name: Action Scheduler
* Plugin URI: https://actionscheduler.org
* Description: A robust scheduling library for use in WordPress plugins.
* Author: Automattic
* Author URI: https://automattic.com/
* Version: 3.9.2
* License: GPLv3
* Requires at least: 6.5
* Tested up to: 6.7
* Requires PHP: 7.1
*
* Copyright 2019 Automattic, Inc. (https://automattic.com/contact/)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @package ActionScheduler
*/

if ( ! function_exists( 'action_scheduler_register_3_dot_9_dot_2' ) && function_exists( 'add_action' ) ) { // WRCS: DEFINED_VERSION.

if ( ! class_exists( 'ActionScheduler_Versions', false ) ) {
require_once __DIR__ . '/classes/ActionScheduler_Versions.php';
add_action( 'plugins_loaded', array( 'ActionScheduler_Versions', 'initialize_latest_version' ), 1, 0 );
}

add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_9_dot_2', 0, 0 ); // WRCS: DEFINED_VERSION.

// phpcs:disable Generic.Functions.OpeningFunctionBraceKernighanRitchie.ContentAfterBrace
/**
* Registers this version of Action Scheduler.
*/
function action_scheduler_register_3_dot_9_dot_2() { // WRCS: DEFINED_VERSION.
$versions = ActionScheduler_Versions::instance();
$versions->register( '3.9.2', 'action_scheduler_initialize_3_dot_9_dot_2' ); // WRCS: DEFINED_VERSION.
}

// phpcs:disable Generic.Functions.OpeningFunctionBraceKernighanRitchie.ContentAfterBrace
/**
* Initializes this version of Action Scheduler.
*/
function action_scheduler_initialize_3_dot_9_dot_2() { // WRCS: DEFINED_VERSION.
// A final safety check is required even here, because historic versions of Action Scheduler
// followed a different pattern (in some unusual cases, we could reach this point and the
// ActionScheduler class is already defined—so we need to guard against that).
if ( ! class_exists( 'ActionScheduler', false ) ) {
require_once __DIR__ . '/classes/abstracts/ActionScheduler.php';
ActionScheduler::init( __FILE__ );
}
}

// Support usage in themes - load this version if no plugin has loaded a version yet.
if ( did_action( 'plugins_loaded' ) && ! doing_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler', false ) ) {
action_scheduler_initialize_3_dot_9_dot_2(); // WRCS: DEFINED_VERSION.
do_action( 'action_scheduler_pre_theme_init' );
ActionScheduler_Versions::initialize_latest_version();
}
}
Loading
Loading