plugin install

This commit is contained in:
Tony Volpe
2024-06-18 17:29:05 -04:00
parent e1aaedd1ae
commit 41f50eacc4
5880 changed files with 1057631 additions and 39681 deletions

View File

@@ -0,0 +1,100 @@
<?php
/**
* Service provider for async (background) processors.
*
* @package Gravity_Forms\Gravity_Forms
*/
namespace Gravity_Forms\Gravity_Forms\Async;
use Gravity_Forms\Gravity_Forms\GF_Service_Container;
use Gravity_Forms\Gravity_Forms\GF_Service_Provider;
use Gravity_Forms\Gravity_Forms\Telemetry\GF_Telemetry_Processor;
use GFForms;
use GF_Background_Process;
use GF_Background_Upgrader;
use GF_Feed_Processor;
if ( ! class_exists( 'GFForms' ) ) {
die();
}
/**
* Class GF_Background_Processing_Service_Provider
*
* @since 2.6.9
*/
class GF_Background_Process_Service_Provider extends GF_Service_Provider {
const UPGRADER = 'upgrade_processor';
const FEEDS = 'feeds_processor';
const NOTIFICATIONS = 'notifications_processor';
const TELEMETRY = 'telemetry_processor';
/**
* The names and classes of the async (background) processors.
*
* @since 2.6.9
*
* @var string[]
*/
protected $processors = array(
self::UPGRADER => GF_Background_Upgrader::class,
self::FEEDS => GF_Feed_Processor::class,
self::NOTIFICATIONS => GF_Notifications_Processor::class,
self::TELEMETRY => GF_Telemetry_Processor::class,
);
/**
* Initializing the processors and adding them to the container as services.
*
* @since 2.6.9
*
* @param GF_Service_Container $container
*/
public function register( GF_Service_Container $container ) {
GFForms::init_background_upgrader();
require_once GF_PLUGIN_DIR_PATH . 'includes/addon/class-gf-feed-processor.php';
require_once GF_PLUGIN_DIR_PATH . 'includes/async/class-gf-notifications-processor.php';
require_once GF_PLUGIN_DIR_PATH . 'includes/telemetry/class-gf-telemetry-processor.php';
foreach ( $this->processors as $name => $class ) {
$container->add( $name, function () use ( $name, $class ) {
if ( $name === self::UPGRADER ) {
return GFForms::$background_upgrader;
}
$callback = array( $class, 'get_instance' );
if ( is_callable( $callback ) ) {
return call_user_func( $callback );
}
return new $class();
} );
}
}
/**
* Initializing hooks.
*
* @since 2.6.9
*
* @param GF_Service_Container $container
*/
public function init( GF_Service_Container $container ) {
$processors = array_keys( $this->processors );
add_action( 'gform_uninstalling', function () use ( $processors, $container ) {
foreach ( $processors as $name ) {
/**
* @var GF_Background_Process $processor
*/
$processor = $container->get( $name );
$processor->clear_scheduled_events();
$processor->clear_queue( true );
$processor->unlock_process();
}
} );
}
}

View File

@@ -0,0 +1,135 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Async;
use GF_Background_Process;
use GFCommon;
use GFAPI;
if ( ! class_exists( 'GFForms' ) ) {
die();
}
if ( ! class_exists( 'GF_Background_Process' ) ) {
require_once GF_PLUGIN_DIR_PATH . 'includes/libraries/gf-background-process.php';
}
/**
* GF_Notifications_Processor Class.
*
* @since 2.6.9
*/
class GF_Notifications_Processor extends GF_Background_Process {
/**
* The action name.
*
* @since 2.6.9
*
* @var string
*/
protected $action = 'gf_notifications_processor';
/**
* Processes the task.
*
* @since 2.6.9
*
* @param array $item The task arguments.
*
* @return bool
*/
protected function task( $item ) {
$notifications = rgar( $item, 'notifications' );
if ( empty( $notifications ) || ! is_array( $notifications ) ) {
return false;
}
$entry = GFAPI::get_entry( rgar( $item, 'entry_id' ) );
if ( is_wp_error( $entry ) ) {
GFCommon::log_debug( __METHOD__ . sprintf( '(): Aborting; Entry #%d not found.', rgar( $item, 'entry_id' ) ) );
return false;
}
$form = GFAPI::get_form( rgar( $item, 'form_id' ) );
if ( empty( $form ) ) {
GFCommon::log_debug( __METHOD__ . sprintf( '(): Aborting; Form #%d not found.', rgar( $item, 'form_id' ) ) );
return false;
}
$form = $this->filter_form( $form, $entry );
$event = rgar( $item, 'event', 'form_submission' );
$data = rgar( $item, 'data' );
if ( ! is_array( $data ) ) {
$data = array();
}
/**
* Allows custom actions to be performed before notifications are sent asynchronously.
*
* @since 2.7.1
*
* @param string $event The event being processed.
* @param array $notifications An array containing the IDs of the notifications being processed.
* @param array $form The form being processed.
* @param array $entry The entry being processed.
* @param array $data An array of data which can be used in the notifications via the generic {object:property} merge tag. Defaults to empty array.
*/
do_action( 'gform_pre_process_async_notifications', $event, $notifications, $form, $entry, $data );
GFCommon::send_notifications( $notifications, $form, $entry, true, $event, $data );
/**
* Allows custom actions to be performed after notifications are sent asynchronously.
*
* @since 2.7.1
*
* @param string $event The event being processed.
* @param array $notifications An array containing the IDs of the notifications being processed.
* @param array $form The form being processed.
* @param array $entry The entry being processed.
* @param array $data An array of data which can be used in the notifications via the generic {object:property} merge tag. Defaults to empty array.
*/
do_action( 'gform_post_process_async_notifications', $event, $notifications, $form, $entry, $data );
return false;
}
/**
* Determines if async (background) processing of notifications is enabled.
*
* @since 2.7.1
*
* @param array $notifications An array containing the IDs of the notifications to be sent.
* @param array $form The form being processed.
* @param array $entry The entry being processed.
* @param string $event The event being processed.
* @param array $data An array of data which can be used in the notifications via the generic {object:property} merge tag. Defaults to empty array.
*
* @return bool
*/
public function is_enabled( $notifications, $form, $entry, $event = 'form_submission', $data = array() ) {
$form_id = absint( rgar( $form, 'id' ) );
$is_enabled = false;
/**
* Allows async (background) processing of notifications to be enabled or disabled.
*
* @since 2.6.9
*
* @param bool $is_enabled Is async (background) processing of notifications enabled? Default is false.
* @param string $event The event the notifications are to be sent for.
* @param array $notifications An array containing the IDs of the notifications to be sent.
* @param array $form The form currently being processed.
* @param array $entry The entry currently being processed.
* @param array $data An array of data which can be used in the notifications via the generic {object:property} merge tag. Defaults to empty array.
*/
return gf_apply_filters( array(
'gform_is_asynchronous_notifications_enabled',
$form_id,
), $is_enabled, $event, $notifications, $form, $entry, $data );
}
}