Ejemplo n.º 1
0
/**
 * Update logs primarily from twl_send_sms() function
 * @param  string $log String of new-line separated log entries to be added
 * @param  int/boolean $enabled Whether to update logs or skip
 * @return void
 */
function twl_update_logs($log, $enabled = 1)
{
    $options = twl_get_options();
    if ($enabled == 1) {
        $current_logs = get_option(TWL_LOGS_OPTION);
        $new_logs = $log . $current_logs;
        $logs_array = explode("\n", $new_logs);
        if (count($logs_array) > 100) {
            $logs_array = array_slice($logs_array, 0, 100);
            $new_logs = implode("\n", $logs_array);
        }
        update_option(TWL_LOGS_OPTION, $new_logs);
    }
}
Ejemplo n.º 2
0
/**
 * Process URL via Google URL Shortener API
 * @param  string $url URL to be shortened
 * @return string Shortened URL in http://goo.gl/xxx format
 */
function twl_url_shorten($url)
{
    $options = twl_get_options();
    $result = wp_remote_post(add_query_arg('key', apply_filters('twl_google_api_key', $options['url_shorten_api_key']), 'https://www.googleapis.com/urlshortener/v1/url'), array('body' => json_encode(array('longUrl' => esc_url_raw($url))), 'headers' => array('Content-Type' => 'application/json')));
    // Return the URL if the request got an error.
    if (is_wp_error($result)) {
        return $url;
    }
    $result = json_decode($result['body']);
    $shortlink = $result->id;
    if ($shortlink) {
        return $shortlink;
    }
    return $url;
}
Ejemplo n.º 3
0
/**
 * Display the Logs tab
 * @return void
 */
function twl_display_logs($tab, $page_url)
{
    if ($tab != 'logs') {
        return;
    }
    if (isset($_GET['clear_logs']) && $_GET['clear_logs'] == '1') {
        check_admin_referer('clear_logs');
        update_option(TWL_LOGS_OPTION, '');
        $logs_cleared = true;
    }
    if (isset($logs_cleared) && $logs_cleared) {
        ?>
		<div id="setting-error-settings_updated" class="updated settings-error"><p><strong><?php 
        _e('Logs Cleared', TWL_TD);
        ?>
</strong></p></div>
	<?php 
    }
    $options = twl_get_options();
    if (!$options['logging']) {
        printf('<div class="error"> <p> %s </p> </div>', esc_html__('Logging currently disabled.', TWL_TD));
    }
    $clear_log_url = esc_url(wp_nonce_url(add_query_arg(array('tab' => $tab, 'clear_logs' => 1), $page_url), 'clear_logs'));
    ?>
	<p><a class="button gray" href="<?php 
    echo $clear_log_url;
    ?>
"><?php 
    _e('Clear Logs', TWL_TD);
    ?>
</a></p>
	<h3><?php 
    _e('Logs', TWL_TD);
    ?>
</h3>
<pre>
<?php 
    echo get_option(TWL_LOGS_OPTION);
    ?>
</pre>
	<?php 
}
Ejemplo n.º 4
0
 /**
  * Original get_options unifier
  * @return array List of options
  * @access public
  */
 public function get_options()
 {
     return twl_get_options();
 }