| Server IP : 151.101.66.159 / Your IP : 216.73.216.66 Web Server : Flywheel/5.1.0 System : Linux wordpress 6.12.113+ #1 SMP Thu Oct 22 02:38:20 UTC 2026 x86_64 User : root ( ) PHP Version : 7.4.33.18 Disable Function : disk_free_space,diskfreespace,dl,exec,fpassthru,getmypid,getmyuid,highlight_file,link,opcache_compile_file,opcache_get_configuration,opcache_is_script_cached,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifcontinued,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,phpinfo,popen,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,socket_listen,source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/flywheel-config/plugins/flywheel/flywheel-activity-monitor/ |
Upload File : |
<?php
/**
* Plugin Name: Flywheel Event Logger
* Plugin URI: https://getflywheel.com
* Description: Logging Wordpress actions.
* Version: 1.0
* Author: Flywheel
* Author URI: http://www.getflywheel.com
*/
/**
* Log the given data array appending hook and user name
*
* @param array $data
* @return void
*/
function fw_event_logger( $data ) {
$hook_data = array (
'user_name' => esc_html( wp_get_current_user()->display_name ),
'hook_name' => current_filter(),
'processing' => processing_status(),
'purge_home' => force_purge_home(),
);
error_log( "FW_EVENT: " . json_encode( array_merge( $hook_data, $data ) ) );
}
/**
* Return if processing of logs is enabled or disabled
*/
function processing_status() {
if(defined('FW_EVENT_ENABLED') && FW_EVENT_ENABLED === true) {
return true;
} else {
return false;
}
}
/**
* Return if we want to force the homepage to be purged
*/
function force_purge_home() {
if(defined('FW_HOME_PURGE') && FW_HOME_PURGE === true) {
return true;
} else {
return false;
}
}
/**
* Hooks to watch
*/
add_action( 'save_post', 'fw_post_logger' );
add_action( 'trashed_post', 'fw_post_logger' ); // Both posts and pages
add_action( 'deleted_post', 'fw_post_logger' ); // Both posts and pages
add_action( 'future_to_publish', 'fw_post_logger' );
add_action( 'switch_theme', 'fw_theme_logger', 10, 2 );
add_action( 'activated_plugin', 'fw_plugins_logger', 10, 2 );
add_action( 'deactivated_plugin', 'fw_plugins_logger', 10, 2 );
/**
* Log creation/modification of a post or page
*
* @param int $post_id
* @return void
*/
function fw_post_logger( $post_id ) {
if ( wp_is_post_revision( $post_id ) ) {
return;
}
$post = get_post($post_id);
$permalink = get_permalink( $post );
$type = get_post_type($post);
$status = get_post_status($post);
$purge_urls = array($permalink);
$forced_purge = force_purge_home();
if ( !in_array($status, ["publish","trash"])) {
return;
}
if ( get_option( 'show_on_front' ) == 'page' ) {
// Static homepage, posts go to subpage. Set blogpath to subpage listed in 'page_for_posts'.
$page_option = get_option( 'page_for_posts' );
if( ! empty( $page_option ) ) {
$posts_page = get_post( $page_option );
if ( ! empty( $posts_page ) ) {
$blogpath = get_permalink( $posts_page );
}
}
} else {
$blogpath = home_url();
}
if ( ! empty( $blogpath ) ) {
array_push($purge_urls, $blogpath);
}
if ( $forced_purge === true ) {
array_push($purge_urls, home_url());
}
// Only log event if $type AND $permalink are present
if ( $permalink ) {
$data = array (
'post_id' => $post_id,
'status' => $status,
'purge_urls' => array_unique($purge_urls),
);
fw_event_logger($data);
}
}
/**
* Log plugin activations and deactivations.
*
* @param string $plugin
* @param bool $network_wide
* @return void
*/
function fw_plugins_logger( $plugin, $network_wide )
{
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
$date_format = get_option( 'date_format' ) . ' ยท ' . get_option( 'time_format' );
$data = array (
'plugin_name' => $plugin_data['Name'],
'plugin_slug' => $plugin_data['TextDomain'],
'network_wide' => $network_wide ? 'true' : 'false'
);
fw_event_logger($data);
}
/**
* Log switching the theme.
*
* @param string $theme_name
* @param WP_Theme $new_theme
* @return void
*/
function fw_theme_logger( $theme_name, $new_theme ) {
$data = array (
'name' => $new_theme['Name'],
'slug' => $new_theme->get('TextDomain'),
'version' => $new_theme->get('Version')
);
fw_event_logger($data);
}