Plugin / Blog Time

Scott Reilly

Description

Description

This plugin adds a dynamic, functional clock to the the admin bar (at top of all admin pages) to show the server time for the blog. The clock automatically updates as time passes, as you would expect of a digital clock.

This plugin also supports a static mode which puts a timestamp string at the top of all admin pages instead of the dynamic clock. This static admin time widget is AJAX-ified so that if you click the timestamp, it updates in place (without a page reload) to show the new current server time.

Also provided is a “Blog Time” widget providing the same functionality as the admin widget, but for your sidebars. You may also utilize the plugin’s functionality directly within a theme template via use of the template tag c2c_blog_time().

NOTE: For the front-end widget, if the “Use dynamic clock?” configuration option is unchecked, this plugin generates a timestamp and NOT a clock. The time being displayed is the time of the page load, or if clicked, the time when the widget last retrieved the time. It won’t actively increment time on the display. By default the widget displays a dynamic clock that does increment time.

This is most useful to see the server/blog time to judge when a time sensitive post, comment, or action would be dated by the blog (i.e. such as monitoring for when to close comments on a contest post, or just accounting for the server being hosted in a different timezone). Or, when used statically as a timestamp and not a clock, it can indicate/preserve when the page was loaded.

Thanks to Moment.js for the JavaScript date handling library.

Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage

Template Tags

The plugin provides one template tag for use in your theme templates, functions.php, or plugins.

Functions

  • <?php function c2c_blog_time( $time_format = '', $echo = true ) ?>
    Gets the formatted time for the site.

Arguments

  • $time_format (string)
    Optional. PHP-style time format string. See https://php.net/date for more info. Default is ” (which, unless otherwise modified, uses the default time forat: ‘g:i A’).

  • $echo (bool)
    Optional. Echo the template info? Default is true.

Examples

  • <?php // Output the site's current time.
    c2c_blog_time();
    ?>

  • <?php // Retrieve the value for use in code, so don't display/echo it.
    $site_date = c2c_blog_time( 'M d, Y', false );
    ?>

Hooks

The plugin exposes four filters for hooking. Code using these filters should ideally be put into a mu-plugin or site-specific plugin (which is beyond the scope of this readme to explain). Less ideally, you could put them in your active theme’s functions.php file.

c2c_blog_time (filter)

The ‘c2c_blog_time’ hook allows you to use an alternative approach to safely invoke c2c_blog_time() in such a way that if the plugin were deactivated or deleted, then your calls to the function won’t cause errors in your site.

Arguments:

  • same as for c2c_blog_time()

Example:

Instead of:

<?php c2c_blog_time(); ?>

Do:

<?php echo apply_filters( 'c2c_blog_time', '' ); ?>

c2c_blog_time_format (filter)

The ‘c2c_blog_time_format’ hook allows you to customize the default format for the blog time. By default this is ‘g:i A’ (though this may be different if modified by localization).

Arguments:

  • $format (string): The default format for the blog time.

Example:

/**
 * Change the default blog time string
 *
 * @param string $format The default time format.
 * @return string
 */
function change_blog_time_format( $format ) {
    return 'b, g:i A';
}
add_filter( 'c2c_blog_time_format', 'change_blog_time_format' );

c2c_blog_time_toolbar_widget_for_user (filter)

The ‘c2c_blog_time_toolbar_widget_for_user’ hook allows you to control if the admin toolbar clock widget should be shown, on a per-user basis. By default the admin toolbar clock is shown to everyone who can see the admin toolbar.

Arguments:

  • $shown (boolean): Whether the admin toolbar clock widget should be shown. Default of true.

Example:

/**
 * Only show the admin toolbar clock for the 'boss' user.
 *
 * @param $show bool Status of whether the admin toolbar clock should be shown.
 * @return bool
 */
function restrict_blog_time_widget_appearance( $show ) {
    return 'boss' == get_current_user()->user_login;
}
add_filter( 'c2c_blog_time_toolbar_widget_for_user', 'restrict_blog_time_widget_appearance' );

c2c_blog_time_active_clock (filter)

The ‘c2c_blog_time_active_clock’ hook returns the boolean value indicating if the Javascript-powered dynamic clock introduced in v2.0 should be enabled or if instead the v1.x era behavior of a static timestamp that can be clicked to update the timestamp via AJAX should be enabled. By default the dynamic clock is enabled.

Arguments:

  • $allow (boolean): Boolean indicating if the admin widget should be a dynamic clock. Default is true.

Example:

// Disable the dynamic clock and use the static timestamp (whcih can be clicked to update the time via AJAX) instead.
add_filter( 'c2c_blog_time_active_clock', '__return_false' );

Ratings

3.4
7 reviews

Rating breakdown

Details Information

Version

3.6

First Released

28 May, 2009

Total Downloads

15,099

Wordpress Version

4.6 or higher

Tested up to:

5.1.3

Require PHP Version:

-

Tags

Contributors

Languages

The plugin hasn't been transalated in any language other than English.

DIRECTORY DISCLAIMER

The information provided in this THEME/PLUGIN DIRECTORY is made available for information purposes only, and intended to serve as a resource to enable visitors to select a relevant theme or plugin. wpSocket gives no warranty of any kind, express or implied with regard to the information, including without limitation any warranty that the particular theme or plugin that you select is qualified on your situation.

The information in the individual theme or plugin displayed in the Directory is provided by the owners and contributors themselves. wpSocket gives no warranty as to the accuracy of the information and will not be liable to you for any loss or damage suffered by you as a consequence of your reliance on the information.

Links to respective sites are offered to assist in accessing additional information. The links may be outdated or broken. Connect to outside sites at your own risk. The Theme/Plugin Directory does not endorse the content or accuracy of any listing or external website.

While information is made available, no guarantee is given that the details provided are correct, complete or up-to-date.

wpSocket is not related to the theme or plugin, and also not responsible and expressly disclaims all liability for, damages of any kind, arising out of the use, reference to, or reliance on, any information or business listed throughout our site.

Keep Leading Your Followers!
Share it for them.