| 1 |
<?php |
| 2 |
|
| 3 |
// Do not allow the file to be called directly. |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* This class is used to log any option change related action. |
| 10 |
*/ |
| 11 |
class P_Event_Options extends P_Event_Log { |
| 12 |
|
| 13 |
/** |
| 14 |
* Hook into the action so we can log it. |
| 15 |
* |
| 16 |
* @return void |
| 17 |
*/ |
| 18 |
public function __construct() { |
| 19 |
add_action( 'updated_option', array( &$this, 'updatedOption' ), 10, 3 ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* When an option is updated, determine which option is updated and log the action. |
| 24 |
* |
| 25 |
* @param string $option |
| 26 |
* @param string $old_value |
| 27 |
* @param string $new_value |
| 28 |
* @return void |
| 29 |
*/ |
| 30 |
public function updatedOption( $option, $old_value, $new_value ) { |
| 31 |
// No need to log if the values are the same. |
| 32 |
if ( $old_value === $new_value ) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
// If either options are an array for some reason, convert to a JSON object. |
| 37 |
if ( is_array( $old_value ) ) { |
| 38 |
$old_value = json_encode( $old_value ); |
| 39 |
} |
| 40 |
if ( is_array( $new_value ) ) { |
| 41 |
$new_value = json_encode ( $new_value ); |
| 42 |
} |
| 43 |
|
| 44 |
// Options that will be logged. |
| 45 |
if ( in_array( |
| 46 |
$option, |
| 47 |
array( |
| 48 |
// General |
| 49 |
'blogname', |
| 50 |
'blogdescription', |
| 51 |
'siteurl', |
| 52 |
'home', |
| 53 |
'admin_email', |
| 54 |
'users_can_register', |
| 55 |
'default_role', |
| 56 |
'timezone_string', |
| 57 |
'date_format', |
| 58 |
'time_format', |
| 59 |
'start_of_week', |
| 60 |
|
| 61 |
// Writing |
| 62 |
'use_smilies', |
| 63 |
'use_balanceTags', |
| 64 |
'default_category', |
| 65 |
'default_post_format', |
| 66 |
'mailserver_url', |
| 67 |
'mailserver_login', |
| 68 |
'mailserver_pass', |
| 69 |
'default_email_category', |
| 70 |
'ping_sites', |
| 71 |
|
| 72 |
// Reading |
| 73 |
'show_on_front', |
| 74 |
'page_on_front', |
| 75 |
'page_for_posts', |
| 76 |
'posts_per_page', |
| 77 |
'posts_per_rss', |
| 78 |
'rss_use_excerpt', |
| 79 |
'blog_public', |
| 80 |
|
| 81 |
// Discussion |
| 82 |
'default_pingback_flag', |
| 83 |
'default_ping_status', |
| 84 |
'default_comment_status', |
| 85 |
'require_name_email', |
| 86 |
'comment_registration', |
| 87 |
'close_comments_for_old_posts', |
| 88 |
'close_comments_days_old', |
| 89 |
'thread_comments', |
| 90 |
'thread_comments_depth', |
| 91 |
'page_comments', |
| 92 |
'comments_per_page', |
| 93 |
'default_comments_page', |
| 94 |
'comment_order', |
| 95 |
'comments_notify', |
| 96 |
'moderation_notify', |
| 97 |
'comment_moderation', |
| 98 |
'comment_whitelist', |
| 99 |
'comment_max_links', |
| 100 |
'moderation_keys', |
| 101 |
'blacklist_keys', |
| 102 |
'show_avatars', |
| 103 |
'avatar_rating', |
| 104 |
'avatar_default', |
| 105 |
|
| 106 |
// Media |
| 107 |
'thumbnail_size_w', |
| 108 |
'thumbnail_size_h', |
| 109 |
'thumbnail_crop', |
| 110 |
'medium_size_w', |
| 111 |
'medium_size_h', |
| 112 |
'large_size_w', |
| 113 |
'large_size_h', |
| 114 |
'uploads_use_yearmonth_folders', |
| 115 |
|
| 116 |
// Permalinks |
| 117 |
'permalink_structure', |
| 118 |
'category_base', |
| 119 |
'tag_base', |
| 120 |
|
| 121 |
// Widgets |
| 122 |
'sidebars_widgets', |
| 123 |
) |
| 124 |
) ) { |
| 125 |
$this->insert( |
| 126 |
array( |
| 127 |
'action' => 'updated', |
| 128 |
'object' => 'option', |
| 129 |
'object_name' => $option . ' from "' . $old_value . '" to "' . $new_value . '"', |
| 130 |
) |
| 131 |
); |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
} |
| 136 |
|