PluginProbe
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity / 1.15.0
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity v1.15.0
3.3.9 3.3.8 trunk 1.0 1.1.0 1.10.0 1.11.0 1.11.1 1.12.0 1.13.0 1.14.0 1.15.0 1.16.0 1.17.0 1.17.1 1.18.0 1.19.0 1.2.0 1.20.0 1.20.1 1.3.0 1.3.1 1.4.0 1.5.0 1.6.0 All 67 releases
logtivity / Logs / Core / Logtivity_Theme.php

Logtivity_Theme.php in Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity 1.15.0, at Logs/Core/Logtivity_Theme.php

148 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Logtivity_Theme extends Logtivity_Abstract_Logger
4 {
5 public function registerHooks()
6 {
7 add_action( 'switch_theme', [$this, 'themeSwitched'], 10, 3 );
8 add_action( 'upgrader_process_complete', [$this, 'upgradeProcessComplete'], 10, 2);
9 add_filter( 'wp_theme_editor_filetypes', [$this, 'themeFileModified'], 10, 2 );
10 add_action( 'customize_save', [$this, 'themeCustomizerModified'], 10, 2 );
11 add_action( 'delete_site_transient_update_themes', [$this, 'themeMaybeDeleted'] );
12 }
13
14 public function themeSwitched($new_name, $new_theme, $old_theme)
15 {
16 return Logtivity_Logger::log()
17 ->setAction("Theme Activated")
18 ->setContext((is_object($new_theme) ? $new_theme->name : $new_theme))
19 ->addMeta('Old Theme', ( is_object($old_theme) ? $old_theme->name : $old_theme))
20 ->send();
21 }
22
23 public function themeMaybeDeleted()
24 {
25 $delete_theme_call = $this->getDeleteThemeCall();
26
27 if ( empty( $delete_theme_call ) ) {
28 return;
29 }
30
31 $slug = $delete_theme_call['args'][0];
32 $theme = wp_get_theme( $slug );
33
34 return Logtivity_Logger::log()
35 ->setAction("Theme Deleted")
36 ->setContext($theme->get('Name'))
37 ->addMeta('Version', $theme->get('Version'))
38 ->addMeta('URI', $theme->get('ThemeURI'))
39 ->send();
40 }
41
42 public function upgradeProcessComplete($upgrader_object, $options)
43 {
44 if ( $options['type'] != 'theme' ) {
45 return;
46 }
47
48 if ($options['action'] == 'update') {
49 return $this->themeUpdated($upgrader_object, $options);
50 }
51
52 if ($options['action'] == 'install') {
53 return $this->themeInstalled($upgrader_object, $options);
54 }
55 }
56
57 public function themeUpdated($upgrader_object, $options)
58 {
59 if ( isset( $options['bulk'] ) && true == $options['bulk'] ) {
60 $slugs = $options['themes'];
61 }
62 else {
63 $slugs = array( $upgrader->skin->theme );
64 }
65
66 foreach ( $slugs as $slug )
67 {
68 $theme = wp_get_theme($slug);
69
70 Logtivity_Logger::log()
71 ->setAction('Theme Updated')
72 ->setContext($theme->name)
73 ->addMeta('Version', $theme->version)
74 ->addMeta('Bulk Update', $options['bulk'])
75 ->send();
76 }
77 }
78
79 public function themeInstalled($upgrader_object, $options)
80 {
81 $slug = $upgrader_object->theme_info();
82
83 if ( ! $slug ) {
84 return;
85 }
86
87 wp_clean_themes_cache();
88
89 $theme = wp_get_theme( $slug );
90
91 return Logtivity_Logger::log()
92 ->setAction('Theme Installed')
93 ->setContext($theme->name)
94 ->addMeta('Version', $theme->version)
95 ->send();
96 }
97
98 public function themeFileModified( $default_types, $theme )
99 {
100 if ( ! isset($_POST['action']) || $_POST['action'] != 'edit-theme-plugin-file' ) {
101 return $default_types;
102 }
103
104 if (!isset($_POST['theme'])) {
105 return $default_types;
106 }
107
108 $log = Logtivity_Logger::log()->setAction('Theme File Edited');
109
110 if ( ! empty( $_POST['file'] ) && is_string($_POST['file']) ) {
111 $log->addMeta('File', sanitize_text_field($_POST['file']));
112 }
113
114 if ( ! empty( $_POST['theme'] ) ) {
115 $log->setContext($theme->display( 'Name' ));
116 }
117
118 $log->send();
119
120 return $default_types;
121 }
122
123 public function themeCustomizerModified( WP_Customize_Manager $obj )
124 {
125 return Logtivity_Logger::log()
126 ->setAction('Theme Customizer Updated')
127 ->setContext($obj->theme()->display('Name'))
128 ->send();
129 }
130
131 private function getDeleteThemeCall()
132 {
133 $backtrace = debug_backtrace();
134
135 $delete_theme_call = null;
136
137 foreach ( $backtrace as $call ) {
138 if ( isset( $call['function'] ) && 'delete_theme' === $call['function'] ) {
139 $delete_theme_call = $call;
140 break;
141 }
142 }
143
144 return $delete_theme_call;
145 }
146 }
147
148 $Logtivity_Theme = new Logtivity_Theme;