diff --git a/.gitattributes b/.gitattributes index 71b1dede..2477d8cd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -28,6 +28,7 @@ /assets/libs/fontawesome/scss export-ignore /docs export-ignore /tests export-ignore +/blocks-src export-ignore # Files /.bowerrc export-ignore diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml new file mode 100644 index 00000000..ab6245a4 --- /dev/null +++ b/.github/workflows/build-release.yml @@ -0,0 +1,68 @@ +name: Build Release + +on: + push: + branches: + - master + +permissions: + contents: write + +jobs: + generate-translations: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: WordPress .pot File Generator + uses: iamdharmesh/action-wordpress-pot-generator@main + with: + destination_path: './languages' + slug: 'ultimate-member' + text_domain: 'ultimate-member' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + build: + needs: generate-translations + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install PHP + uses: "shivammathur/setup-php@v2" + with: + php-version: "latest" + - name: Install Composer Dependencies + run: | + composer install --no-progress --no-dev --optimize-autoloader --ignore-platform-req=ext-exif --ignore-platform-req=ext-gd --ignore-platform-req=ext-tidy + - name: Commit files + run: | + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git rm .bowerrc + git rm .editorconfig + git rm .gitignore + git rm .jshintrc + git rm .travis.yml + git rm bower.json + git rm composer.json + git rm gulpfile.js + git rm hookdoc-conf.json + git rm manifest.json + git rm package.json + git rm package-lock.json + git rm phpcs.xml + git rm phpdoc.dist.xml + git rm webpack.mix.js + git rm -r .github + git rm -r docs + git rm -r blocks-src + git rm -r tests + git add vendor/\* + git add includes/lib/action-scheduler/\* + git commit -a -m "Composer Installed. Cleared release repo." + - name: Push changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: releases + repository: ultimatemember/ultimatemember + force: true diff --git a/.github/workflows/translations.yml b/.github/workflows/translations.yml deleted file mode 100644 index 0505af0a..00000000 --- a/.github/workflows/translations.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Generate POT file - -on: - push: - branches: - - master - -jobs: - WP_Generate_POT_File: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: WordPress .pot File Generator - uses: iamdharmesh/action-wordpress-pot-generator@main - with: - destination_path: './languages' - slug: 'ultimate-member' - text_domain: 'ultimate-member' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index a7597b20..95969446 100644 --- a/.gitignore +++ b/.gitignore @@ -220,6 +220,7 @@ assets/vendor/ package-lock.json .idea/ composer.lock +includes/lib/action-scheduler/ # exclude Composer installation composer.phar diff --git a/.wordpress-org/blueprints/blueprint.json b/.wordpress-org/blueprints/blueprint.json index 9f87ac24..0860d56d 100644 --- a/.wordpress-org/blueprints/blueprint.json +++ b/.wordpress-org/blueprints/blueprint.json @@ -15,7 +15,7 @@ "step": "installPlugin", "pluginZipFile": { "resource": "url", - "url": "https:\/\/downloads.wordpress.org\/plugin\/ultimate-member.2.8.9.zip" + "url": "https:\/\/downloads.wordpress.org\/plugin\/ultimate-member.2.9.0.zip" }, "options": { "activate": true diff --git a/README.md b/README.md index 720f7e42..11318199 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ GNU Version 2 or Any Later Version ### IMPORTANT: PLEASE UPDATE THE PLUGIN TO AT LEAST VERSION 2.6.7 IMMEDIATELY. VERSION 2.6.7 PATCHES SECURITY PRIVILEGE ESCALATION VULNERABILITY. PLEASE SEE [THIS ARTICLE](https://docs.ultimatemember.com/article/1866-security-incident-update-and-recommended-actions) FOR MORE INFORMATION -[Official Release Version: 2.8.9](https://github.com/ultimatemember/ultimatemember/releases/tag/2.8.9). +[Official Release Version: 2.9.0](https://github.com/ultimatemember/ultimatemember/releases/tag/2.9.0). ## Changelog diff --git a/assets/css/admin/users.css b/assets/css/admin/users.css index f4d527c3..22277fd8 100644 --- a/assets/css/admin/users.css +++ b/assets/css/admin/users.css @@ -1,15 +1,18 @@ -.um-admin.users-php .um_account_status { +.um-admin.users-php .um-filter-by-status { + padding: 0 8px 0 0; +} +.um-admin.users-php .um_account_status:not(.hidden) { display: flex; flex-direction: column; justify-content: flex-start; align-items: stretch; flex-wrap: nowrap; } -.um-admin.users-php .um_account_status span { +.um-admin.users-php .um_account_status:not(.hidden) span { margin: 0 0 2px 0; padding: 0; } -.um-admin.users-php .um_account_status ul { +.um-admin.users-php .um_account_status:not(.hidden) ul { display: flex; flex-direction: row; justify-content: flex-start; @@ -20,14 +23,14 @@ margin: 0 0 4px 0; padding: 0; } -.um-admin.users-php .um_account_status ul li { +.um-admin.users-php .um_account_status:not(.hidden) ul li { margin: 0; padding: 0; } -.um-admin.users-php .um_account_status ul li a.um-set-status-rejected, .um-admin.users-php .um_account_status ul li a.um-deactivate-user { +.um-admin.users-php .um_account_status:not(.hidden) ul li a.um-set-status-rejected, .um-admin.users-php .um_account_status:not(.hidden) ul li a.um-deactivate-user { color: #b32d2e; } -.um-admin.users-php .um_account_status ul li a.um-set-status-rejected:active, .um-admin.users-php .um_account_status ul li a.um-set-status-rejected:hover, .um-admin.users-php .um_account_status ul li a.um-deactivate-user:active, .um-admin.users-php .um_account_status ul li a.um-deactivate-user:hover { +.um-admin.users-php .um_account_status:not(.hidden) ul li a.um-set-status-rejected:active, .um-admin.users-php .um_account_status:not(.hidden) ul li a.um-set-status-rejected:hover, .um-admin.users-php .um_account_status:not(.hidden) ul li a.um-deactivate-user:active, .um-admin.users-php .um_account_status:not(.hidden) ul li a.um-deactivate-user:hover { color: #b32d2e; } diff --git a/assets/css/admin/users.min.css b/assets/css/admin/users.min.css index 1efe0289..df30e148 100644 --- a/assets/css/admin/users.min.css +++ b/assets/css/admin/users.min.css @@ -1 +1 @@ -.um-admin.users-php .um_account_status{display:flex;flex-direction:column;justify-content:flex-start;align-items:stretch;flex-wrap:nowrap}.um-admin.users-php .um_account_status span{margin:0 0 2px 0;padding:0}.um-admin.users-php .um_account_status ul{display:flex;flex-direction:row;justify-content:flex-start;align-items:baseline;flex-wrap:wrap;column-gap:4px;row-gap:0;margin:0 0 4px 0;padding:0}.um-admin.users-php .um_account_status ul li{margin:0;padding:0}.um-admin.users-php .um_account_status ul li a.um-deactivate-user,.um-admin.users-php .um_account_status ul li a.um-set-status-rejected{color:#b32d2e}.um-admin.users-php .um_account_status ul li a.um-deactivate-user:active,.um-admin.users-php .um_account_status ul li a.um-deactivate-user:hover,.um-admin.users-php .um_account_status ul li a.um-set-status-rejected:active,.um-admin.users-php .um_account_status ul li a.um-set-status-rejected:hover{color:#b32d2e}.um-admin.users-php .subsubsub li.subsep{display:block;visibility:hidden;height:0}.um-admin-modal .um-admin-infobox label{font-weight:700;display:block;color:#333;cursor:default}.um-admin-modal .um-admin-infobox p{color:#666;padding-top:15px}.um-admin-modal .um-admin-infobox>p:not(:first-child){border-top:1px solid #e5e5e5}.um-admin-modal .um-admin-infobox>p:first-child{margin-top:0;padding-top:0}.um-admin-modal .um-admin-infobox>.um-row>p{border-top:1px solid #e5e5e5}.um-admin-modal .um-admin-infobox>.um-row>p:last-child{margin-bottom:0}#UM_preview_registration .um-admin-modal-foot{display:none} \ No newline at end of file +.um-admin.users-php .um-filter-by-status{padding:0 8px 0 0}.um-admin.users-php .um_account_status:not(.hidden){display:flex;flex-direction:column;justify-content:flex-start;align-items:stretch;flex-wrap:nowrap}.um-admin.users-php .um_account_status:not(.hidden) span{margin:0 0 2px 0;padding:0}.um-admin.users-php .um_account_status:not(.hidden) ul{display:flex;flex-direction:row;justify-content:flex-start;align-items:baseline;flex-wrap:wrap;column-gap:4px;row-gap:0;margin:0 0 4px 0;padding:0}.um-admin.users-php .um_account_status:not(.hidden) ul li{margin:0;padding:0}.um-admin.users-php .um_account_status:not(.hidden) ul li a.um-deactivate-user,.um-admin.users-php .um_account_status:not(.hidden) ul li a.um-set-status-rejected{color:#b32d2e}.um-admin.users-php .um_account_status:not(.hidden) ul li a.um-deactivate-user:active,.um-admin.users-php .um_account_status:not(.hidden) ul li a.um-deactivate-user:hover,.um-admin.users-php .um_account_status:not(.hidden) ul li a.um-set-status-rejected:active,.um-admin.users-php .um_account_status:not(.hidden) ul li a.um-set-status-rejected:hover{color:#b32d2e}.um-admin.users-php .subsubsub li.subsep{display:block;visibility:hidden;height:0}.um-admin-modal .um-admin-infobox label{font-weight:700;display:block;color:#333;cursor:default}.um-admin-modal .um-admin-infobox p{color:#666;padding-top:15px}.um-admin-modal .um-admin-infobox>p:not(:first-child){border-top:1px solid #e5e5e5}.um-admin-modal .um-admin-infobox>p:first-child{margin-top:0;padding-top:0}.um-admin-modal .um-admin-infobox>.um-row>p{border-top:1px solid #e5e5e5}.um-admin-modal .um-admin-infobox>.um-row>p:last-child{margin-bottom:0}#UM_preview_registration .um-admin-modal-foot{display:none} \ No newline at end of file diff --git a/assets/css/admin/users.sass b/assets/css/admin/users.sass index 09b3756e..405e040b 100644 --- a/assets/css/admin/users.sass +++ b/assets/css/admin/users.sass @@ -2,7 +2,9 @@ @import "mixins" .#{$prefix}admin.users-php - .um_account_status + .um-filter-by-status + padding: 0 8px 0 0 + .um_account_status:not(.hidden) +flex( column, flex-start, stretch, nowrap ) span margin: 0 0 2px 0 diff --git a/blocks-src/um-account/block.json b/blocks-src/um-account/block.json new file mode 100644 index 00000000..8a5c803d --- /dev/null +++ b/blocks-src/um-account/block.json @@ -0,0 +1,15 @@ +{ + "apiVersion": 2, + "name": "um-block/um-account", + "title": "Account", + "description": "Displaying the account page of the current user", + "icon": "id", + "category": "um-blocks", + "attributes": { + "tab": { + "type": "string" + } + }, + "editorScript": "file:./src/index.js", + "textdomain": "ultimate-member" +} diff --git a/blocks-src/um-account/src/index.js b/blocks-src/um-account/src/index.js new file mode 100644 index 00000000..18345342 --- /dev/null +++ b/blocks-src/um-account/src/index.js @@ -0,0 +1,81 @@ +import { registerBlockType } from '@wordpress/blocks'; +import ServerSideRender from '@wordpress/server-side-render'; +import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; +import { PanelBody, SelectControl } from "@wordpress/components"; +import { useMemo, useCallback } from '@wordpress/element'; + +registerBlockType('um-block/um-account', { + edit: function (props) { + const { attributes, setAttributes } = props; + const { tab } = attributes; + const blockProps = useBlockProps(); + + const options = useMemo(() => { + const option = [{ label: wp.i18n.__('All', 'ultimate-member'), value: 'all' }]; + for (const key in um_account_settings) { + if (um_account_settings.hasOwnProperty(key) && um_account_settings[key]['enabled']) { + option.push({ + label: um_account_settings[key]['label'], + value: key + }); + } + } + return option; + }, []); + + const onTabChange = useCallback((value) => { + setAttributes({ tab: value }); + const shortcode = `[ultimatemember_account${value !== 'all' ? ` tab="${value}"` : ''}]`; + setAttributes({ content: shortcode }); + }, [setAttributes]); + + return ( +
+ + + + + + +
+ ); + }, + + save: () => null +}); + +jQuery(window).on( 'load', function($) { + let observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + + jQuery(mutation.addedNodes).find('.um.um-account').each(function() { + let current_tab = jQuery(this).find('.um-account-main').attr('data-current_tab'); + let wrapper = document.querySelector('.um-form'); + + if ( current_tab ) { + jQuery(this).find('.um-account-tab[data-tab="'+current_tab+'"]').show(); + jQuery(this).find('.um-account-tab:not(:visible)').find( 'input, select, textarea' ).not( ':disabled' ).addClass('um_account_inactive').prop( 'disabled', true ).attr( 'disabled', true ); + um_responsive(); + } + + if (wrapper) { + wrapper.addEventListener('click', (event) => { + if (event.target !== wrapper) { + event.preventDefault(); + event.stopPropagation(); + } + }); + } + }); + }); + }); + + observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true}); +}); diff --git a/blocks-src/um-forms/block.json b/blocks-src/um-forms/block.json new file mode 100644 index 00000000..2d5dce4a --- /dev/null +++ b/blocks-src/um-forms/block.json @@ -0,0 +1,15 @@ +{ + "apiVersion": 2, + "name": "um-block/um-forms", + "title": "Form", + "description": "Choose display form", + "icon": "forms", + "category": "um-blocks", + "attributes": { + "form_id": { + "type": "integer" + } + }, + "editorScript": "file:./src/index.js", + "textdomain": "ultimate-member" +} diff --git a/blocks-src/um-forms/src/index.js b/blocks-src/um-forms/src/index.js new file mode 100644 index 00000000..5c7852e2 --- /dev/null +++ b/blocks-src/um-forms/src/index.js @@ -0,0 +1,74 @@ +import { useSelect } from '@wordpress/data'; +import { PanelBody, SelectControl, Spinner } from '@wordpress/components'; +import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; +import ServerSideRender from '@wordpress/server-side-render'; +import { registerBlockType } from '@wordpress/blocks'; +import { useMemo } from '@wordpress/element'; + +registerBlockType('um-block/um-forms', { + edit: function (props) { + const blockProps = useBlockProps(); + const { attributes, setAttributes } = props; + const { form_id } = attributes; + + const posts = useSelect( + (select) => select('core').getEntityRecords('postType', 'um_form', { per_page: -1, _fields: ['id', 'title'] }), + [] + ); + + const options = useMemo(() => { + if (!posts) { + return [{ label: wp.i18n.__('Loading...', 'ultimate-member'), value: '' }]; + } + if (posts.length === 0) { + return [{ label: wp.i18n.__('No forms found.', 'ultimate-member'), value: '' }]; + } + return [{ label: wp.i18n.__('Select Form', 'ultimate-member'), value: '' }].concat( + posts.map((post) => ({ label: post.title.rendered, value: post.id })) + ); + }, [posts]); + + const onFormChange = (value) => setAttributes({ form_id: value }); + + return ( +
+ + + + + + +
+ ); + }, + + save: () => null +}); + +jQuery(window).on( 'load', function($) { + let observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + + jQuery(mutation.addedNodes).find('.um-form').each(function() { + let wrapper = document.querySelector('.um-form'); + + if (wrapper) { + wrapper.addEventListener('click', (event) => { + if (event.target !== wrapper) { + event.preventDefault(); + event.stopPropagation(); + } + }); + } + }); + }); + }); + + observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true}); +}); diff --git a/blocks-src/um-member-directories/block.json b/blocks-src/um-member-directories/block.json new file mode 100644 index 00000000..cdffceea --- /dev/null +++ b/blocks-src/um-member-directories/block.json @@ -0,0 +1,15 @@ +{ + "apiVersion": 2, + "name": "um-block/um-member-directories", + "title": "Member Directory", + "description": "Choose display directory", + "icon": "groups", + "category": "um-blocks", + "attributes": { + "member_id": { + "type": "integer" + } + }, + "editorScript": "file:./src/index.js", + "textdomain": "ultimate-member" +} diff --git a/blocks-src/um-member-directories/src/index.js b/blocks-src/um-member-directories/src/index.js new file mode 100644 index 00000000..c5415fff --- /dev/null +++ b/blocks-src/um-member-directories/src/index.js @@ -0,0 +1,107 @@ +import { useSelect } from '@wordpress/data'; +import { PanelBody, SelectControl, Spinner } from '@wordpress/components'; +import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; +import ServerSideRender from '@wordpress/server-side-render'; +import { registerBlockType } from "@wordpress/blocks"; +import { useMemo } from '@wordpress/element'; + +registerBlockType('um-block/um-member-directories', { + edit: function (props) { + const blockProps = useBlockProps(); + const { attributes, setAttributes } = props; + const { member_id } = attributes; + + const posts = useSelect((select) => { + return select('core').getEntityRecords('postType', 'um_directory', { + per_page: -1, + _fields: ['id', 'title'] + }); + }, []); + + const options = useMemo(() => { + if (!posts) { + return [{ label: wp.i18n.__('Loading...', 'ultimate-member'), value: '' }]; + } + if (posts.length === 0) { + return [{ label: wp.i18n.__('No posts found.', 'ultimate-member'), value: '' }]; + } + return [{ label: wp.i18n.__('Select Directory', 'ultimate-member'), value: '' }].concat( + posts.map((post) => ({ + label: post.title.rendered, + value: post.id + })) + ); + }, [posts]); + + const onMemberIdChange = (value) => setAttributes({ member_id: value }); + + if (!posts) { + return ( +

+ + {wp.i18n.__('Loading...', 'ultimate-member')} +

+ ); + } + + return ( +
+ + + + + + +
+ ); + }, + + save: () => null +}); + +jQuery(window).on( 'load', function($) { + let observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + + jQuery(mutation.addedNodes).find('.um.um-directory').each(function() { + let wrapper = document.querySelector('.um-directory'); + let directory = jQuery(this); + um_ajax_get_members( directory ); + um_slider_filter_init( directory ); + um_datepicker_filter_init( directory ); + um_timepicker_filter_init( directory ); + + if (wrapper) { + wrapper.addEventListener('click', (event) => { + if (event.target !== wrapper) { + event.preventDefault(); + event.stopPropagation(); + } + }); + } + }); + jQuery(mutation.addedNodes).find('.um-member').each(function() { + let wrapper = document.querySelector('.um-member'); + let directory = jQuery(this).parent(); + UM_Member_Grid(directory); + + if (wrapper) { + wrapper.addEventListener('click', (event) => { + if (event.target !== wrapper) { + event.preventDefault(); + event.stopPropagation(); + } + }); + } + }); + }); + }); + + observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true}); +}); diff --git a/blocks-src/um-password-reset/block.json b/blocks-src/um-password-reset/block.json new file mode 100644 index 00000000..2e1548c2 --- /dev/null +++ b/blocks-src/um-password-reset/block.json @@ -0,0 +1,10 @@ +{ + "apiVersion": 2, + "name": "um-block/um-password-reset", + "title": "Password Reset", + "description": "Displaying the password reset form", + "icon": "unlock", + "category": "um-blocks", + "editorScript": "file:./src/index.js", + "textdomain": "ultimate-member" +} diff --git a/blocks-src/um-password-reset/src/index.js b/blocks-src/um-password-reset/src/index.js new file mode 100644 index 00000000..74e89369 --- /dev/null +++ b/blocks-src/um-password-reset/src/index.js @@ -0,0 +1,17 @@ +import { registerBlockType } from '@wordpress/blocks'; +import ServerSideRender from '@wordpress/server-side-render'; +import { useBlockProps } from '@wordpress/block-editor'; + +registerBlockType('um-block/um-password-reset', { + edit: function () { + const blockProps = useBlockProps(); + + return ( +
+ +
+ ); + }, + + save: () => null +}); diff --git a/changelog.txt b/changelog.txt index 27e5aa73..49946b34 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,21 @@ == Changelog == += 2.9.0 November 12, 2024 = + +* Enhancements: + + - Added: Action Scheduler (version 3.8.1) for email sending. More info is [here](https://actionscheduler.org/) + - Added: Supporting new `wp_register_block_metadata_collection()` function for registering WP Blocks + +* Bugfixes: + + - Fixed: `ajax_image_upload()` and `ajax_resize_image()` handlers vulnerability. CVE ID: CVE-2024-10528 + - Fixed: Disabling user status column wp-admin > Users screen + - Fixed: User status filter on wp-admin > Users on mobile devices + - Fixed: Extra unwrapping of the WP Editor field's value + +* Cached and optimized/minified assets(JS/CSS) must be flushed/re-generated after upgrade + = 2.8.9 October 14, 2024 = * Enhancements: diff --git a/composer.json b/composer.json index 53cd7340..b46c44db 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "config": { "allow-plugins": { "symfony/flex": true, - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "composer/installers": true } }, "require": { @@ -22,7 +23,8 @@ "ext-curl": "*", "ext-iconv": "*", "ext-tidy": "*", - "woocommerce/action-scheduler": "3.2.1" + "composer/installers": "^2.3", + "woocommerce/action-scheduler": "3.8.1" }, "require-dev": { "roave/security-advisories": "dev-latest", @@ -36,7 +38,7 @@ }, "extra": { "installer-paths": { - "vendor/{$vendor}/{$name}/": ["woocommerce/action-scheduler"] + "includes/lib/{$name}/": ["woocommerce/action-scheduler"] } } } diff --git a/includes/action-scheduler/class-init.php b/includes/action-scheduler/class-init.php new file mode 100644 index 00000000..7850e81c --- /dev/null +++ b/includes/action-scheduler/class-init.php @@ -0,0 +1,299 @@ +can_be_active() ) { + UM()->admin()->notices()->add_notice( + 'um-action-scheduler', + array( + 'class' => 'notice-warning is-dismissible', + // translators: %1$s - Plugin name, %1$s - Plugin Version + 'message' => '

' . sprintf( __( '%1$s %2$s The file needed to enable the Action Scheduler is missing. The plugin will continue to function as it did before, but without the new benefits offered by the Action Scheduler.', 'ultimate-member' ), UM_PLUGIN_NAME, UM_VERSION ) . '

', + ) + ); + } else { + add_filter( 'um_settings_structure', array( $this, 'add_setting' ) ); + + if ( UM()->options()->get( 'enable_action_scheduler' ) ) { + $this->enabled = true; + } + } + } + + /** + * Adds the Action Scheduler setting to Ultimate Member feature settings + * + * @param array $settings + * + * @return array + */ + public function add_setting( $settings ) { + $settings['advanced']['sections']['features']['form_sections']['features']['fields'][] = array( + 'id' => 'enable_action_scheduler', + 'type' => 'checkbox', + 'label' => __( 'Action Scheduler', 'ultimate-member' ), + 'checkbox_label' => __( 'Enable Action Scheduler', 'ultimate-member' ), + 'description' => __( 'Check this box if you want to use the Ultimate Member action scheduler. By enabling it, certain tasks like sending system emails will be scheduled to run at optimal times, which can help reduce the load on your server', 'ultimate-member' ), + ); + + return $settings; + } + + /** + * Verifies whether WooCommerce is installed and activated, + * and checks for the existence of the WooCommerce Action Scheduler file. + * + * @return bool + */ + public function verify_wc_action_scheduler() { + if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) { + return false; + } + + $action_scheduler_file = WP_PLUGIN_DIR . '/woocommerce/packages/action-scheduler/action-scheduler.php'; + + return file_exists( $action_scheduler_file ); + } + + /** + * Tries to load Action Scheduler from Ultimate Member if file exists + * + * @return bool + */ + public function load_library() { + if ( file_exists( $this->lib_path ) ) { + require_once $this->lib_path; + + return true; + } + + return false; + } + + /** + * Checks whenever Action Scheduler can be active + * + * @return bool + */ + public function can_be_active() { + return $this->verify_wc_action_scheduler() || $this->load_library(); + } + + /** + * Enqueue an action to run one time, as soon as possible. + * If Action Scheduler is disabled then do_action_ref_array is called to run action right away. + * + * @param string $hook Required. Name of the action hook. + * @param array $args Arguments to pass to callbacks when the hook triggers. Default: array(). + * @param string $group The group to assign this job to. Default: ''. + * @param bool $unique Whether the action should be unique. Default: false. + * @param int $priority Lower values take precedence over higher values. Defaults to 10, with acceptable values falling in the range 0-255. + * + * @return int Еhe action’s ID. Zero if there was an error scheduling the action. The error will be sent to error_log + */ + public function enqueue_async_action( $hook, $args = array(), $group = '', $unique = false, $priority = 10 ) { + if ( $this->enabled ) { + $group = $this->set_group( $group ); + return as_enqueue_async_action( $hook, $args, $group, $unique, $priority ); + } + + do_action_ref_array( $hook, $args ); + return 0; + } + + /** + * Schedule an action to run one time at some defined point in the future. + * + * @param int $timestamp Required. The Unix timestamp representing the date you want the action to run. + * @param string $hook Required. Name of the action hook. + * @param array $args Arguments to pass to callbacks when the hook triggers. Default: array() + * @param string $group The group to assign this job to. Default: ''. + * @param bool $unique Whether the action should be unique. Default: false. + * @param int $priority Lower values take precedence over higher values. Defaults to 10, with acceptable values falling in the range 0-255.) + * + * @return int The action’s ID. Zero if there was an error scheduling the action. The error will be sent to error_log. + */ + public function schedule_single_action( $timestamp, $hook, $args = array(), $group = '', $unique = false, $priority = 10 ) { + if ( $this->enabled ) { + $group = $this->set_group( $group ); + return as_schedule_single_action( $timestamp, $hook, $args, $group, $unique, $priority ); + } + + do_action_ref_array( $hook, $args ); + return 0; + } + + /** + * Schedule an action to run repeatedly with a specified interval in seconds. + * + * @param int $timestamp Required. The Unix timestamp representing the date you want the action to run. + * @param int $interval_in_seconds Required. How long to wait between runs. + * @param string $hook Required. Name of the action hook. + * @param array $args Arguments to pass to callbacks when the hook triggers. Default: array(). + * @param string $group The group to assign this job to. Default: ''. + * @param bool $unique Whether the action should be unique. Default: false. + * @param int $priority Lower values take precedence over higher values. Defaults to 10, with acceptable values falling in the range 0-255. + * + * @return int The action’s ID. Zero if there was an error scheduling the action. The error will be sent to error_log. + */ + public function schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '', $unique = false, $priority = 10 ) { + $group = $this->set_group( $group ); + + return as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args, $group, $unique, $priority ); + } + + /** + * Schedule an action that recurs on a cron-like schedule. + * + * If execution of a cron-like action is delayed, the next attempt will still be scheduled according to the provided cron expression. + * + * @param int $timestamp Required. The Unix timestamp representing the date you want the action to run. + * @param string $schedule Required. A cron-like schedule string, see http://en.wikipedia.org/wiki/Cron. + * @param string $hook Required Name of the action hook. + * @param array $args Arguments to pass to callbacks when the hook triggers. Default: array(). + * @param string $group The group to assign this job to. Default: ''. + * @param bool $unique Whether the action should be unique. Default: false. + * @param int $priority Lower values take precedence over higher values. Defaults to 10, with acceptable values falling in the range 0-255. + * + * @return int The action’s ID. Zero if there was an error scheduling the action. The error will be sent to error_log. + */ + public function schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '', $unique = false, $priority = 10 ) { + $group = $this->set_group( $group ); + + return as_schedule_cron_action( $timestamp, $schedule, $hook, $args, $group, $unique, $priority ); + } + + /** + * Cancel the next occurrence of a scheduled action. + * + * @param string $hook Required. Name of the action hook. + * @param array $args Arguments passed to callbacks when the hook triggers. Default: array(). + * @param string $group The group the job is assigned to. Default: ''. + * + * @return int|null The scheduled action ID if a scheduled action was found, or null if no matching action found. + */ + public function unschedule_action( $hook, $args = array(), $group = '' ) { + $group = $this->set_group( $group ); + + return as_unschedule_action( $hook, $args, $group ); + } + + /** + * Cancel all occurrences of a scheduled action. + * + * @param string $hook The hook that the job will trigger. + * @param array $args Args that would have been passed to the job. + * @param string $group The group the job is assigned to. + */ + public function unschedule_all_actions( $hook, $args = array(), $group = '' ) { + $group = $this->set_group( $group ); + + as_unschedule_all_actions( $hook, $args, $group ); + } + + /** + * Returns the next timestamp for a scheduled action. + * + * @param string $hook Required. Name of the action hook. Default: none. + * @param array $args Arguments passed to callbacks when the hook triggers. Default: array(). + * @param string $group The group the job is assigned to. Default: ''. + * + * @return int|bool The timestamp for the next occurrence of a pending scheduled action, true for an async or in-progress action or false if there is no matching action. + */ + public function next_scheduled_action( $hook, $args = array(), $group = '' ) { + $group = $this->set_group( $group ); + + return as_next_scheduled_action( $hook, $args, $group ); + } + + /** + * Check if there is a scheduled action in the queue, but more efficiently than as_next_scheduled_action(). + * It’s recommended to use this function when you need to know whether a specific action is currently scheduled. + * + * @param string $hook Required. Name of the action hook. Default: none. + * @param array $args Arguments passed to callbacks when the hook triggers. Default: array(). + * @param string $group The group the job is assigned to. Default: ''. + * + * @return bool True if a matching action is pending or in-progress, false otherwise. + */ + public function has_scheduled_action( $hook, $args = array(), $group = '' ) { + $group = $this->set_group( $group ); + + return as_has_scheduled_action( $hook, $args, $group ); + } + + /** + * @param array $args Arguments to search and filter results by. Possible arguments, with their default values: + * 'hook' => '' - the name of the action that will be triggered + * 'args' => NULL - the args array that will be passed with the action + * 'date' => NULL - the scheduled date of the action. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). + * 'date_compare' => '<=' - operator for testing “date”. accepted values are ‘!=’, ‘>’, ‘>=’, ‘<’, ‘<=’, ‘=’ + * 'modified' => NULL - the date the action was last updated. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). + * 'modified_compare' => '<=' - operator for testing “modified”. accepted values are ‘!=’, ‘>’, ‘>=’, ‘<’, ‘<=’, ‘=’ + * 'group' => '' - the group the action belongs to + * 'status' => '' - ActionScheduler_Store::STATUS_COMPLETE or ActionScheduler_Store::STATUS_PENDING + * 'claimed' => NULL - TRUE to find claimed actions, FALSE to find unclaimed actions, a string to find a specific claim ID + * 'per_page' => 5 - Number of results to return + * 'offset' => 0 + * 'orderby' => 'date' - accepted values are ‘hook’, ‘group’, ‘modified’, or ‘date’ + * 'order' => 'ASC' + * + * @param string $return_format The format in which to return the scheduled actions: 'OBJECT', 'ARRAY_A', or 'ids'. Default: 'OBJECT'. + * + * @return array Array of action rows matching the criteria specified with $args. + */ + public function get_scheduled_actions( $args, $return_format = 'OBJECT' ) { + if ( ! empty( $args['group'] ) ) { + $args['group'] = $this->set_group( $args['group'] ); + } + return as_get_scheduled_actions( $args, $return_format ); + } + + public function set_group( $group ) { + if ( empty( $group ) ) { + return $this->default_group; + } + + return $this->default_group . '_' . $group; + } + } +} diff --git a/includes/admin/class-users-columns.php b/includes/admin/class-users-columns.php index d6d3c22b..81165829 100644 --- a/includes/admin/class-users-columns.php +++ b/includes/admin/class-users-columns.php @@ -360,7 +360,7 @@ if ( ! class_exists( 'um\admin\Users_Columns' ) ) { $statuses = $this->get_statuses_filter_options(); ?> -
+