| @@ -42,20 +42,20 @@ | ||
| 42 | 42 | ->setAction('Theme Activated') |
| 43 | 43 | ->setContext((is_object($new_theme) ? $new_theme->name : $new_theme)) |
| 44 | 44 | ->addMeta('Version', (is_object($new_theme) ? $new_theme->version : $new_theme)) |
| 45 | 45 | ->addMeta('Old Theme', (is_object($old_theme) ? $old_theme->name : $old_theme)) |
| 46 | + ->addInventory() | |
| 46 | 47 | ->send(); |
| 47 | 48 | } |
| 48 | 49 | |
| 49 | 50 | public function themeMaybeDeleted() |
| 50 | 51 | { |
| 51 | - $delete_theme_call = $this->getDeleteThemeCall(); | |
| 52 | + $slug = $this->getDeletedThemeSlug(); | |
| 52 | 53 | |
| 53 | - if (empty($delete_theme_call)) { | |
| 54 | + if (empty($slug)) { | |
| 54 | 55 | return; |
| 55 | 56 | } |
| 56 | 57 | |
| 57 | - $slug = $delete_theme_call['args'][0]; | |
| 58 | 58 | $theme = wp_get_theme($slug); |
| 59 | 59 | |
| 60 | 60 | Logtivity::log() |
| 61 | 61 | ->setAction('Theme Deleted') |
| @@ -61,8 +61,9 @@ | ||
| 61 | 61 | ->setAction('Theme Deleted') |
| 62 | 62 | ->setContext($theme->get('Name')) |
| 63 | 63 | ->addMeta('Version', $theme->get('Version')) |
| 64 | 64 | ->addMeta('URI', $theme->get('ThemeURI')) |
| 65 | + ->addInventory() | |
| 65 | 66 | ->send(); |
| 66 | 67 | } |
| 67 | 68 | |
| 68 | 69 | public function upgradeProcessComplete($upgrader_object, $options) |
| @@ -96,8 +97,9 @@ | ||
| 96 | 97 | ->setAction('Theme Updated') |
| 97 | 98 | ->setContext($theme->name) |
| 98 | 99 | ->addMeta('Version', $theme->version) |
| 99 | 100 | ->addMeta('Bulk Update', $bulk ? 'Yes' : 'No') |
| 101 | + ->addInventory() | |
| 100 | 102 | ->send(); |
| 101 | 103 | } |
| 102 | 104 | } |
| 103 | 105 | |
| @@ -116,28 +118,41 @@ | ||
| 116 | 118 | Logtivity::log() |
| 117 | 119 | ->setAction('Theme Installed') |
| 118 | 120 | ->setContext($theme->name) |
| 119 | 121 | ->addMeta('Version', $theme->version) |
| 122 | + ->addInventory() | |
| 120 | 123 | ->send(); |
| 121 | 124 | } |
| 122 | 125 | |
| 123 | 126 | public function themeFileModified($default_types, $theme) |
| 124 | 127 | { |
| 125 | - if (!isset($_POST['action']) || $_POST['action'] != 'edit-theme-plugin-file') { | |
| 128 | + // phpcs:disable WordPress.Security.NonceVerification.Missing -- Passive logger reads core theme-editor request after WordPress validates it. | |
| 129 | + $action = isset($_POST['action']) | |
| 130 | + ? sanitize_text_field(wp_unslash($_POST['action'])) | |
| 131 | + : null; | |
| 132 | + $themeSlug = isset($_POST['theme']) | |
| 133 | + ? sanitize_text_field(wp_unslash($_POST['theme'])) | |
| 134 | + : null; | |
| 135 | + $file = isset($_POST['file']) | |
| 136 | + ? sanitize_text_field(wp_unslash($_POST['file'])) | |
| 137 | + : null; | |
| 138 | + // phpcs:enable WordPress.Security.NonceVerification.Missing | |
| 139 | + | |
| 140 | + if ($action != 'edit-theme-plugin-file') { | |
| 126 | 141 | return $default_types; |
| 127 | 142 | } |
| 128 | 143 | |
| 129 | - if (!isset($_POST['theme'])) { | |
| 144 | + if (!$themeSlug) { | |
| 130 | 145 | return $default_types; |
| 131 | 146 | } |
| 132 | 147 | |
| 133 | 148 | $log = Logtivity::log('Theme File Edited'); |
| 134 | 149 | |
| 135 | - if (!empty($_POST['file']) && is_string($_POST['file'])) { | |
| 136 | - $log->addMeta('File', sanitize_text_field($_POST['file'])); | |
| 150 | + if ($file) { | |
| 151 | + $log->addMeta('File', $file); | |
| 137 | 152 | } |
| 138 | 153 | |
| 139 | - if (!empty($_POST['theme'])) { | |
| 154 | + if ($themeSlug) { | |
| 140 | 155 | $log->setContext($theme->display('Name')); |
| 141 | 156 | } |
| 142 | 157 | |
| 143 | 158 | $log->send(); |
| @@ -152,22 +167,17 @@ | ||
| 152 | 167 | ->setContext($obj->theme()->display('Name')) |
| 153 | 168 | ->send(); |
| 154 | 169 | } |
| 155 | 170 | |
| 156 | - private function getDeleteThemeCall() | |
| 171 | + private function getDeletedThemeSlug(): ?string | |
| 157 | 172 | { |
| 158 | - $backtrace = debug_backtrace(); | |
| 159 | - | |
| 160 | - $delete_theme_call = null; | |
| 161 | - | |
| 162 | - foreach ($backtrace as $call) { | |
| 173 | + foreach ((new Exception())->getTrace() as $call) { | |
| 163 | 174 | if (isset($call['function']) && 'delete_theme' === $call['function']) { |
| 164 | - $delete_theme_call = $call; | |
| 165 | - break; | |
| 175 | + return $call['args'][0] ?? null; | |
| 166 | 176 | } |
| 167 | 177 | } |
| 168 | 178 | |
| 169 | - return $delete_theme_call; | |
| 179 | + return null; | |
| 170 | 180 | } |
| 171 | 181 | } |
| 172 | 182 | |
| 173 | 183 | new Logtivity_Theme(); |