: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Main class for WP-Admin hooks
* This class loads all of our backend hooks and sets up admin interfaces
* @subpackage Admin interfaces
* @var version - plugin version
* @var opts - plugin options
* Meks TA Admin constructor
* Constructor first checks for the plugin version, and if this is the first activation, plugin adds version info in the DB with autoload option set to false.
* That way we can easily update across versions, if we decide to add options to the plugin, or change plugin settings and defaults
public function __construct() {
if ( $ta_ver = get_option( 'meks_ta_ver' ) ) {
$this->version = $ta_ver;
add_option( 'meks_ta_ver', $ta_ver, '', 'no' );
'active' => array( 'date' => true, 'time' => true, 'modified_date' => false, 'modified_time' => false ),
'time' => array( 'number' => '12', 'type' => 'months' ),
$default_opts = apply_filters( 'meks_ta_modify_default_opts', $default_opts );
$this->opts = get_option( 'meks_ta_opts', $default_opts );
$this->opts = $this->parse_args( $this->opts, $default_opts);
add_action( 'admin_init', array( $this, 'register_settings' ) );
add_filter( 'plugin_action_links_'.MEKS_TA_BASENAME, array( &$this, 'add_settings_link' ) );
* Function that is hooked into the admin initialisation and registers settings
public function register_settings() {
add_settings_section( 'meks_ta_opts', 'Meks Time Ago Options', array( &$this, 'settings_section_info' ), 'general' );
add_settings_field( 'meks_ta_opts[active]', __( 'Apply "time ago" format to', 'meks-time-ago' ), array( &$this, 'active_callback' ), 'general', 'meks_ta_opts', $this->opts['active'] );
add_settings_field( 'meks_ta_opts[time]', __( 'Apply to posts not older than', 'meks-time-ago' ), array( &$this, 'time_callback' ), 'general', 'meks_ta_opts', $this->opts['time'] );
add_settings_field( 'meks_ta_opts[position]', __( 'Place "ago" word', 'meks-time-ago' ), array( &$this, 'position_callback' ), 'general', 'meks_ta_opts', $this->opts['position'] );
add_settings_field( 'meks_ta_opts[ago_label]', __( 'Rewrite "ago" word', 'meks-time-ago' ), array( &$this, 'ago_label_callback' ), 'general', 'meks_ta_opts', $this->opts['ago_label'] );
register_setting( 'general', 'meks_ta_opts', array( &$this, 'sanitize_opts' ) );
* Function that displays the section heading information
public function settings_section_info() {
echo '<div id="mkstimeago"></div>';
* Function that displays the plugin activation checkbox
public function active_callback( $active ) {
$checked_date = checked( $active['date'], 1, false );
$checked_time = checked( $active['time'], 1, false );
$checked_modified_date = checked( $active['modified_date'], 1, false );
$checked_modified_time = checked( $active['modified_time'], 1, false );
echo "<input type=\"checkbox\" name=\"meks_ta_opts[active][date]\" ${checked_date}>".__( 'Date', 'meks-time-ago' ).' ';
echo "<input type=\"checkbox\" name=\"meks_ta_opts[active][time]\" ${checked_time}>".__( 'Time', 'meks-time-ago' ).' ';
echo "<input type=\"checkbox\" name=\"meks_ta_opts[active][modified_date]\" ${checked_modified_date}>".__( 'Date (modified)', 'meks-time-ago' ).' ';
echo "<input type=\"checkbox\" name=\"meks_ta_opts[active][modified_time]\" ${checked_modified_time}>".__( 'Time (modified)', 'meks-time-ago' );
* Function that displays the string position select box
public function position_callback( $position ) {
$positions = apply_filters( 'meks_ta_position_opts', array( 'after' => __( 'After (1 hour ago)', 'meks-time-ago' ), 'before' => __( 'Before (ago 1 hour)', 'meks-time-ago' ) ) );
$html = '<select name="meks_ta_opts[position]">';
foreach ( $positions as $value => $label ) {
$selected = selected( $position, $value, false );
$html.= '<option value="'.$value.'" '.$selected.'>'.$label.'</option>';
* Function that displays the hours input
public function time_callback( $time ) {
$minutes = $hours = $days = $months = '';
echo "<input type=\"number\" name=\"meks_ta_opts[time][number]\" value=\"${time}\" class=\"small-text\" style=\"height: 28px; vertical-align: top;\">";
echo sprintf( '<select name="meks_ta_opts[time][type]"><option value="minutes" %1$s>%2$s</option><option value="hours" %3$s>%4$s</option><option value="days" %5$s>%6$s</option><option value="months" %7$s>%8$s</option>',
__( 'Minutes', 'meks-time-ago' ),
__( 'Hours', 'meks-time-ago' ),
__( 'Days', 'meks-time-ago' ),
__( 'Months', 'meks-time-ago' )
* Display ago label setting
public function ago_label_callback( $ago_label ) {
echo '<input type="text" name="meks_ta_opts[ago_label]" value="'.esc_attr($ago_label).'"/>';
* Function that sanitizes plugin options on save
* @param array $opts Meks Time Ago options
* @return array $opts Sanitized options array
public function sanitize_opts( $opts ) {
$options_active = array('date', 'time', 'modified_date', 'modified_time');
foreach ($options_active as $option_active) {
if ( isset( $opts['active'][$option_active] )) {
$opts['active'][$option_active] = true;
$opts['active'][$option_active] = false;
$opts['ago_label'] = esc_html( $opts['ago_label'] );
public function add_settings_link( $links ) {
$admin_url = admin_url();
$link = array( '<a href="'.$admin_url.'options-general.php#mkstimeago">Settings</a>' );
return array_merge( $links, $link );
* Parse args ( merge arrays )
* Similar to wp_parse_args() but extended to also merge multidimensional arrays
* @param array $a - set of values to merge
* @param array $b - set of default values
* @return array Merged set of elements
function parse_args( &$a, $b ) {
foreach ( $a as $k => &$v ) {
if ( is_array( $v ) && isset( $r[ $k ] ) ) {
$r[ $k ] = $this->parse_args( $v, $r[ $k ] );