| Server IP : 43.130.17.34 / Your IP : 216.73.217.6 Web Server : nginx/1.28.0 System : Linux VM-4-12-opencloudos 6.6.92-34.1.oc9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 25 21:32:13 CST 2025 x86_64 User : www ( 1000) PHP Version : 8.0.26 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/yespkg.com/wp-content/plugins/wpforms/src/Pro/Tasks/Actions/ |
Upload File : |
<?php
namespace WPForms\Pro\Tasks\Actions;
use WPForms\Tasks\Meta;
use WPForms\Tasks\Task;
/**
* Class PurgeTemplateEntryTask is responsible for purging the template entry.
*
* @since 1.8.8
*/
class PurgeTemplateEntryTask extends Task {
/**
* Action name for this task.
*
* @since 1.8.8
*/
const ACTION = 'wpforms_purge_template_entry';
/**
* Class constructor.
*
* @since 1.8.8
*/
public function __construct() {
parent::__construct( self::ACTION );
$this->init();
}
/**
* Initialize the task.
*
* @since 1.8.8
*/
public function init() {
$this->hooks();
}
/**
* Hooks.
*
* @since 1.8.8
*/
public function hooks() {
add_action( 'wpforms_process_entry_saved', [ $this, 'add_task' ], 10, 4 );
add_action( self::ACTION, [ $this, 'process' ] );
}
/**
* Add task to the queue.
*
* @since 1.8.8
*
* @param array $fields Form fields.
* @param array $entry Form entry.
* @param array $form_data Form data.
* @param int $entry_id Entry ID.
*/
public function add_task( $fields, $entry, $form_data, $entry_id ) {
$settings = $form_data['settings'] ?? [];
if ( ! isset( $settings['template_description'] ) ) {
return;
}
/**
* Filters the time interval for the task to be purged in, in seconds.
*
* @since 1.8.8
*
* @param int $delay Delay in seconds.
*/
$delay = (int) apply_filters( 'wpforms_pro_tasks_actions_purge_template_entry_task_delay', DAY_IN_SECONDS );
// Determine when the entry should be purged.
$purge_timestamp = time() + $delay;
$action_id = wpforms()->get( 'tasks' )
->create( self::ACTION )
->once( $purge_timestamp )
->params( $entry_id )
->register();
wpforms()->get( 'entry_meta' )->add(
[
'entry_id' => $entry_id,
'form_id' => $form_data['id'] ?? 0,
'type' => 'purge_template_entry_task',
'data' => wp_json_encode(
[
'task_id' => $action_id,
'timestamp' => $purge_timestamp,
]
),
],
'entry_meta'
);
}
/**
* Process the task.
*
* @since 1.8.8
*
* @param int $meta_id Meta ID.
*/
public function process( $meta_id ) { // phpcs:ignore WPForms.PHP.HooksMethod.InvalidPlaceForAddingHooks
$task_meta = new Meta();
$meta = $task_meta->get( (int) $meta_id );
if ( empty( $meta ) || empty( $meta->data ) ) {
return;
}
list( $entry_id ) = $meta->data;
// Allow the cron to delete the entry.
add_filter( 'wpforms_current_user_can', '__return_true' );
$this->process_before_delete( $entry_id );
// Delete the entry.
wpforms()->get( 'entry' )->delete( $entry_id );
}
/**
* Perform any additional actions before deleting the entry.
*
* For example, this allows us to delete the user created via User Registration addon.
* Form Template entries can only be created by logged-in admins with sufficient permissions,
* and they are considered test entries. Users created via User Registration addon are
* also considered test users and should be automatically deleted too.
*
* @since 1.8.8
*
* @param int $entry_id Entry ID.
*/
private function process_before_delete( int $entry_id ) {
$registered_user_id = wpforms()->get( 'entry_meta' )->get_meta(
[
'entry_id' => $entry_id,
'type' => 'registered_user_id',
'number' => 1,
]
);
$user_id = $registered_user_id[0]->data ?? 0;
if ( empty( $user_id ) ) {
return;
}
// Delete the user.
wp_delete_user( $user_id );
}
}