PHP Class SimpleHistory

Afficher le fichier Open project: bonny/wordpress-simple-history Class Usage Examples

Méthodes publiques

Свойство Type Description
$gettextLatestTranslations Used to store latest translations used by __() Required to automagically determine orginal text and text domain for calls like this SimpleLogger()->log( __("My translated message") );

Méthodes publiques

Méthode Description
__construct ( )
addWelcomeLogMessage ( ) Greet users to version 2! Is only called after database has been upgraded, so only on first install (or upgrade).
add_admin_bar_menu_item ( $wp_admin_bar ) Adds a "View history" item/shortcut to the admin bar
add_admin_bar_network_menu_item ( $wp_admin_bar ) Adds a "View history" item/shortcut to the network admin, on blogs where Simple History is installed
add_admin_pages ( ) Add pages (history page and settings page)
add_dashboard_widget ( ) Maybe add a dashboard widget, requires current user to have view history capability and a setting to show dashboard to be set
add_default_settings_tabs ( ) Adds default tabs to settings
add_js_templates ( $hook ) Output JS templated into footer
add_settings ( ) * Add setting sections and settings for the settings page Also maybe save some settings before outputing them
api ( ) Base url is: wp-admin/admin-ajax.php?action=simple_history_api
check_for_upgrade ( ) Check if plugin version have changed, i.e. has been upgraded If upgrade is detected then maybe modify database and so on for that version
clear_log ( ) Removes all items from the log
dashboard_widget_output ( ) Output html for the dashboard widget
does_database_have_data ( ) : boolean Check if the database has data/rows
ends_with ( string $haystack, string $needle ) Returns true if $haystack ends with $needle
enqueue_admin_scripts ( $hook ) Enqueue styles and scripts for Simple History but only to our own pages.
filter_gettext ( $translated_text, $untranslated_text, $domain ) During the load of info for a logger we want to get a reference to the untranslated text too, because that's the version we want to store in the database.
filter_gettext_storeLatestTranslations ( $translation, $text, $domain )
filter_gettext_with_context ( $translated_text, $untranslated_text, $context, $domain ) Store messages with context
filter_option_page_capability ( $capability )
getInstantiatedDropins ( )
getInstantiatedLoggerBySlug ( $slug = "" )
getInstantiatedLoggers ( )
getLogLevelTranslated ( string $loglevel ) : string Return translated loglevel
getLogRowDetailsOutput ( $row )
getLogRowHTMLOutput ( array $oneLogRow, $args ) : string Returns the HTML output for a log row, to be used in the GUI/Activity Feed
getLogRowHeaderOutput ( array $row ) : string Return header output for a log row Uses the getLogRowHeaderOutput of the logger that logged the row with fallback to SimpleLogger if logger is not available
getLogRowPlainTextOutput ( array $row ) : string Return plain text output for a log row Uses the getLogRowPlainTextOutput of the logger that logged the row with fallback to SimpleLogger if logger is not available
getLoggersThatUserCanRead ( integer $user_id = "", string $format = "array" ) : array Check which loggers a user has the right to read and return an array with all loggers they are allowed to read
getSettingsTabs ( )
get_avatar ( string $email, integer $size = '96', string $default = '', string $alt = false ) : string Retrieve the avatar for a user who provided a user ID or email address.
get_cache_incrementor ( $refresh = false ) : string https://www.tollmanz.com/invalidation-schemes/
get_clear_history_interval ( ) : integer How old log entried are allowed to be.
get_instance ( ) : SimpleHistory Get singleton intance
get_num_events_last_n_days ( $period_days = 28 ) Number of rows the last n days
get_num_events_per_day_last_n_days ( $period_days = 28 ) get_num_events_last_n_days
get_pager_size ( ) : integer Gets the pager size, i.e. the number of items to show on each page in the history
get_pager_size_dashboard ( ) : integer Gets the pager size, i.e. the number of items to show on each page in the history
get_unique_events_for_days ( $days = 7 ) Number of unique events the last n days
get_view_history_capability ( ) : string Return capability required to view history = for who will the History page be added
get_view_settings_capability ( ) : string Return capability required to view settings
history_page_output ( ) Output for page with the history
init ( )
is_on_our_own_pages ( $hook = "" )
json_encode ( $value ) Works like json_encode, but adds JSON_PRETTY_PRINT if the current php version supports it i.e. PHP is 5.4.0 or greated
load_dropins ( ) Load built in dropins from all files in /dropins and instantiates them
load_loggers ( ) Load built in loggers from all files in /loggers and instantiates them
load_plugin_textdomain ( ) Load language files.
maybe_purge_db ( ) Runs the purge_db() method sometimes We don't want to call it each time because it performs SQL queries
onAdminFooter ( )
onAdminHead ( )
on_filter_simple_history_log ( $message = null, array $context = null, string $level = "info" ) Log a message
output_quick_stats ( ) Quick stats above the log Uses filter "simple_history/history_page/before_gui" to output its contents
plugin_action_links ( $actions, $b, $c, $d ) Show a link to our settings page on the Plugins -> Installed Plugins screen
purge_db ( ) Removes old entries from the db
registerSettingsTab ( $arr_tab_settings )
register_dropin ( $dropinClassName ) Register an external dropin so Simple History knows about it.
register_logger ( $loggerClassName ) Register an external logger so Simple History knows about it.
setting_show_as_page ( ) : boolean Should simple history be shown as a page Defaults to true
setting_show_on_dashboard ( ) : boolean Get setting if plugin should be visible on dasboard.
settings_field_clear_log ( ) Settings section to clear database
settings_field_number_of_items ( ) Settings field for how many rows/items to show in log on the log page
settings_field_number_of_items_dashboard ( ) Settings field for how many rows/items to show in log on the dashboard
settings_field_where_to_show ( ) Settings field for where to show the log, page or dashboard
settings_output_general ( )
settings_output_log ( )
settings_output_styles_example ( )
settings_page_output ( ) Output HTML for the settings page Called from add_options_page
settings_section_output ( ) Content for section intro. Leave it be, even if empty.
setup_cron ( )
setup_variables ( ) Setup variables and things
testlog_old ( )

Private Methods

Méthode Description
add_admin_actions ( )
getLogRowSenderImageOutput ( array $row ) : string

Method Details

__construct() public méthode

public __construct ( )

addWelcomeLogMessage() public méthode

Not called after only plugin activation.

add_admin_bar_menu_item() public méthode

Useful because Simple History is something at least the author of this plugin often use on a site :)
Since: 2.7.1
public add_admin_bar_menu_item ( $wp_admin_bar )

add_admin_bar_network_menu_item() public méthode

Useful because Simple History is something at least the author of this plugin often use on a site :)
Since: 2.7.1
public add_admin_bar_network_menu_item ( $wp_admin_bar )

add_admin_pages() public méthode

Add pages (history page and settings page)
public add_admin_pages ( )

add_dashboard_widget() public méthode

Maybe add a dashboard widget, requires current user to have view history capability and a setting to show dashboard to be set

add_default_settings_tabs() public méthode

Adds default tabs to settings

add_js_templates() public méthode

Output JS templated into footer
public add_js_templates ( $hook )

add_settings() public méthode

* Add setting sections and settings for the settings page Also maybe save some settings before outputing them
public add_settings ( )

api() public méthode

Examples: http://playground-root.ep/wp-admin/admin-ajax.php?action=simple_history_api&posts_per_page=5&paged=1&format=html
public api ( )

check_for_upgrade() public méthode

Check if plugin version have changed, i.e. has been upgraded If upgrade is detected then maybe modify database and so on for that version
public check_for_upgrade ( )

clear_log() public méthode

Removes all items from the log
public clear_log ( )

dashboard_widget_output() public méthode

Output html for the dashboard widget

does_database_have_data() public méthode

Check if the database has data/rows
Since: 2.1.6
public does_database_have_data ( ) : boolean
Résultat boolean True if database is not empty, false if database is empty = contains no data

ends_with() public static méthode

Returns true if $haystack ends with $needle
public static ends_with ( string $haystack, string $needle )
$haystack string
$needle string

enqueue_admin_scripts() public méthode

Only adds scripts to pages where the log is shown or the settings page.
public enqueue_admin_scripts ( $hook )

filter_gettext() public méthode

During the load of info for a logger we want to get a reference to the untranslated text too, because that's the version we want to store in the database.
public filter_gettext ( $translated_text, $untranslated_text, $domain )

filter_gettext_storeLatestTranslations() public méthode

public filter_gettext_storeLatestTranslations ( $translation, $text, $domain )

filter_gettext_with_context() public méthode

Store messages with context
public filter_gettext_with_context ( $translated_text, $untranslated_text, $context, $domain )

filter_option_page_capability() public méthode

public filter_option_page_capability ( $capability )

getInstantiatedDropins() public méthode

getInstantiatedLoggerBySlug() public méthode

public getInstantiatedLoggerBySlug ( $slug = "" )

getInstantiatedLoggers() public méthode

getLogLevelTranslated() public méthode

Return translated loglevel
Since: 2.0.14
public getLogLevelTranslated ( string $loglevel ) : string
$loglevel string
Résultat string translated loglevel

getLogRowDetailsOutput() public méthode

public getLogRowDetailsOutput ( $row )

getLogRowHTMLOutput() public méthode

Returns the HTML output for a log row, to be used in the GUI/Activity Feed
public getLogRowHTMLOutput ( array $oneLogRow, $args ) : string
$oneLogRow array SimpleHistoryLogQuery array with data from SimpleHistoryLogQuery
Résultat string

getLogRowHeaderOutput() public méthode

Loggers are discouraged to override this in the loggers, because the output should be the same for all items in the gui
public getLogRowHeaderOutput ( array $row ) : string
$row array
Résultat string

getLogRowPlainTextOutput() public méthode

Return plain text output for a log row Uses the getLogRowPlainTextOutput of the logger that logged the row with fallback to SimpleLogger if logger is not available
public getLogRowPlainTextOutput ( array $row ) : string
$row array
Résultat string

getLoggersThatUserCanRead() public méthode

Check which loggers a user has the right to read and return an array with all loggers they are allowed to read
public getLoggersThatUserCanRead ( integer $user_id = "", string $format = "array" ) : array
$user_id integer Id of user to get loggers for. Defaults to current user id.
$format string format to return loggers in. Default is array. Can also be "sql"
Résultat array

getSettingsTabs() public méthode

public getSettingsTabs ( )

get_avatar() public méthode

A modified version of the function that comes with WordPress, but we want to allow/show gravatars even if they are disabled in discussion settings
Since: 2.0
public get_avatar ( string $email, integer $size = '96', string $default = '', string $alt = false ) : string
$email string email address
$size integer Size of the avatar image
$default string URL to a default image to use if no avatar is available
$alt string Alternative text to use in image tag. Defaults to blank
Résultat string tag for the user's avatar

get_cache_incrementor() public static méthode

https://www.tollmanz.com/invalidation-schemes/
public static get_cache_incrementor ( $refresh = false ) : string
$refresh bool
Résultat string

get_clear_history_interval() public méthode

0 = don't delete old entries.
public get_clear_history_interval ( ) : integer
Résultat integer Number of days.

get_instance() public static méthode

Get singleton intance
public static get_instance ( ) : SimpleHistory
Résultat SimpleHistory instance

get_num_events_last_n_days() public méthode

Number of rows the last n days
public get_num_events_last_n_days ( $period_days = 28 )

get_num_events_per_day_last_n_days() public méthode

get_num_events_last_n_days
public get_num_events_per_day_last_n_days ( $period_days = 28 )

get_pager_size() public méthode

Gets the pager size, i.e. the number of items to show on each page in the history
public get_pager_size ( ) : integer
Résultat integer

get_pager_size_dashboard() public méthode

Gets the pager size, i.e. the number of items to show on each page in the history
Since: 2.12
public get_pager_size_dashboard ( ) : integer
Résultat integer

get_unique_events_for_days() public méthode

Number of unique events the last n days
public get_unique_events_for_days ( $days = 7 )

get_view_history_capability() public méthode

Return capability required to view history = for who will the History page be added
Since: 2.1.5
public get_view_history_capability ( ) : string
Résultat string capability

get_view_settings_capability() public méthode

Return capability required to view settings
Since: 2.1.5
public get_view_settings_capability ( ) : string
Résultat string capability

history_page_output() public méthode

Output for page with the history
public history_page_output ( )

init() public méthode

Since: 2.5.2
public init ( )

is_on_our_own_pages() public méthode

public is_on_our_own_pages ( $hook = "" )

json_encode() public static méthode

Works like json_encode, but adds JSON_PRETTY_PRINT if the current php version supports it i.e. PHP is 5.4.0 or greated
public static json_encode ( $value )
$value array|object|string|whatever that is json_encode'able

load_dropins() public méthode

Load built in dropins from all files in /dropins and instantiates them
public load_dropins ( )

load_loggers() public méthode

Load built in loggers from all files in /loggers and instantiates them
public load_loggers ( )

load_plugin_textdomain() public méthode

Uses the method described here: http://geertdedeckere.be/article/loading-wordpress-language-files-the-right-way
Since: 2.0

maybe_purge_db() public méthode

Runs the purge_db() method sometimes We don't want to call it each time because it performs SQL queries
Since: 2.0.17
public maybe_purge_db ( )

onAdminFooter() public méthode

public onAdminFooter ( )

onAdminHead() public méthode

public onAdminHead ( )

on_filter_simple_history_log() public méthode

Function called when running filter "simple_history_log"
Since: 2.13
public on_filter_simple_history_log ( $message = null, array $context = null, string $level = "info" )
$context array Optional context to add to the logged data
$level string The loglevel. Must be one of the existing ones. Defaults to "info".

output_quick_stats() public méthode

Quick stats above the log Uses filter "simple_history/history_page/before_gui" to output its contents
public output_quick_stats ( )

purge_db() public méthode

Removes old entries from the db
public purge_db ( )

registerSettingsTab() public méthode

public registerSettingsTab ( $arr_tab_settings )

register_dropin() public méthode

Does not load the dropin, so file with dropin class must be loaded already. See example-dropin.php for an example on how to use this.
Since: 2.1
public register_dropin ( $dropinClassName )

register_logger() public méthode

Does not load the logger, so file with logger class must be loaded already. See example-logger.php for an example on how to use this.
Since: 2.1
public register_logger ( $loggerClassName )

setting_show_as_page() public méthode

Should simple history be shown as a page Defaults to true
public setting_show_as_page ( ) : boolean
Résultat boolean

setting_show_on_dashboard() public méthode

Defaults to true
public setting_show_on_dashboard ( ) : boolean
Résultat boolean

settings_field_clear_log() public méthode

Settings section to clear database

settings_field_number_of_items() public méthode

Settings field for how many rows/items to show in log on the log page

settings_field_number_of_items_dashboard() public méthode

Settings field for how many rows/items to show in log on the dashboard

settings_field_where_to_show() public méthode

Settings field for where to show the log, page or dashboard

settings_output_general() public méthode

settings_output_log() public méthode

public settings_output_log ( )

settings_output_styles_example() public méthode

settings_page_output() public méthode

Output HTML for the settings page Called from add_options_page

settings_section_output() public méthode

Called from add_sections_setting.

setup_cron() public méthode

public setup_cron ( )

setup_variables() public méthode

Setup variables and things
public setup_variables ( )

testlog_old() public méthode

public testlog_old ( )

Property Details

$gettextLatestTranslations public_oe property

Used to store latest translations used by __() Required to automagically determine orginal text and text domain for calls like this SimpleLogger()->log( __("My translated message") );
public $gettextLatestTranslations