| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 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,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.3/wp-content/plugins/wp-statistics/src/Service/CustomEvent/ |
Upload File : |
<?php
namespace WP_Statistics\Service\CustomEvent;
class CustomEventHelper
{
/**
* Retrieves registered custom events via code, if any.
* This is a filterable array to allow other plugins to add their own custom events.
*
* @return array
*/
public static function getCustomEvents()
{
$result = [];
// This is a filter to register internal WP Statistics events
$internalCustomEvents = apply_filters('wp_statistics_internal_custom_events', []);
// This is a filter to register custom events by other plugins, themes, etc
$customEvents = apply_filters('wp_statistics_custom_events', []);
foreach ($customEvents as $event) {
// Check if the event name is valid (not already defined or is reserved)
if (!self::isEventNameValid($event['machine_name'])) {
\WP_Statistics::log(esc_html__("An event with `{$event['machine_name']}` machine name is not allowed.", 'wp-statistics'), 'error');
continue;
}
$result[$event['machine_name']] = $event;
}
foreach ($internalCustomEvents as $event) {
$result[$event['machine_name']] = $event;
}
return $result;
}
/**
* Retrieves an array of active custom events.
*
* @return string[]
*/
public static function getActiveCustomEvents()
{
$activeCustomEvents = [];
foreach (self::getCustomEvents() as $event) {
if (!empty($event['status'])) {
$activeCustomEvents[] = $event['machine_name'];
}
}
return apply_filters('wp_statistics_active_custom_events', $activeCustomEvents);
}
/**
* Checks if a custom event is active.
*
* @param string $name The name of the custom event to check.
* @return bool True if the custom event is active, false otherwise.
*/
public static function isEventActive($name)
{
return in_array($name, self::getActiveCustomEvents());
}
/**
* Checks if the given name is a reserved name for custom events.
*
* @param string $name The name to check.
* @return bool True if the name is reserved, false otherwise.
*/
public static function isEventNameReserved($name)
{
return in_array($name, self::getReservedEventNames());
}
/**
* Checks if the given name is allowed to be used as a custom event name.
*
* The name is allowed if it is not reserved and is not already in use as a custom event name.
*
* @param string $name The name to check.
* @return bool True if the name is allowed, false otherwise.
*/
public static function isEventNameValid($name)
{
$isValid = ! self::isEventNameReserved($name) ? true : false;
return apply_filters('wp_statistics_custom_event_name_validation', $isValid, $name);
}
/**
* Gets a list of reserved event names that are not allowed to be used for custom events.
*
* @return string[]
*/
public static function getReservedEventNames()
{
return [
'page_view',
'video_start',
'custom_event',
'user_login',
'session_start',
'video_progress',
'analytics',
'view_search_results',
'user_engagement',
'video_complete',
'reserved_event',
'user_logout',
'scroll',
'add_to_cart',
'tracking_event',
'form_submit',
'click',
'purchase',
'system_event',
'file_download',
'notification_open',
'error_event'
];
}
}