Make your WordPress site irresistible. Natural SEO attraction with: - robots.txt management - sitemap.xml generation - LLMs.txt support - Google integration (Analytics, Search Console, Tag Manager) - Schema.org structured data - Open Graph / Twitter Card meta tags - AMP support - Visual elements gallery - Built-in backup/restore module Includes build.sh and .distignore for WordPress-installable release ZIPs.
131 lines
3.6 KiB
PHP
131 lines
3.6 KiB
PHP
<?php
|
|
/**
|
|
* Utility functions for TigerStyle Heat
|
|
*/
|
|
|
|
// Prevent direct access
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class TigerStyleSEO_Utils {
|
|
|
|
/**
|
|
* Sanitize textarea field with line breaks preserved
|
|
*/
|
|
public static function sanitize_textarea($input) {
|
|
return sanitize_textarea_field($input);
|
|
}
|
|
|
|
/**
|
|
* Format bytes into human readable format
|
|
*/
|
|
public static function format_bytes($bytes, $precision = 2) {
|
|
$units = array('B', 'KB', 'MB', 'GB', 'TB');
|
|
|
|
for ($i = 0; $bytes > 1024 && $i < count($units) - 1; $i++) {
|
|
$bytes /= 1024;
|
|
}
|
|
|
|
return round($bytes, $precision) . ' ' . $units[$i];
|
|
}
|
|
|
|
/**
|
|
* Verify nonce for security
|
|
*/
|
|
public static function verify_nonce($nonce_name, $action) {
|
|
return isset($_POST[$nonce_name]) && wp_verify_nonce($_POST[$nonce_name], $action);
|
|
}
|
|
|
|
/**
|
|
* Check if user can manage options
|
|
*/
|
|
public static function current_user_can_manage() {
|
|
return current_user_can('manage_options');
|
|
}
|
|
|
|
/**
|
|
* Redirect with message
|
|
*/
|
|
public static function redirect_with_message($message, $page = 'tigerstyle-heat') {
|
|
wp_redirect(add_query_arg(array(
|
|
'page' => $page,
|
|
'message' => $message
|
|
), admin_url('admin.php')));
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Get option with prefix
|
|
*/
|
|
public static function get_option($option_name, $default = false) {
|
|
return get_option('tigerstyle_' . $option_name, $default);
|
|
}
|
|
|
|
/**
|
|
* Update option with prefix
|
|
*/
|
|
public static function update_option($option_name, $value) {
|
|
return update_option('tigerstyle_' . $option_name, $value);
|
|
}
|
|
|
|
/**
|
|
* Parse business days from shorthand to Schema.org format
|
|
*/
|
|
public static function parse_business_days($days_string) {
|
|
$day_mapping = array(
|
|
'Mo' => 'Monday',
|
|
'Tu' => 'Tuesday',
|
|
'We' => 'Wednesday',
|
|
'Th' => 'Thursday',
|
|
'Fr' => 'Friday',
|
|
'Sa' => 'Saturday',
|
|
'Su' => 'Sunday'
|
|
);
|
|
|
|
// Handle ranges like "Mo-Fr"
|
|
if (strpos($days_string, '-') !== false) {
|
|
$parts = explode('-', $days_string);
|
|
if (count($parts) === 2) {
|
|
$start_day = trim($parts[0]);
|
|
$end_day = trim($parts[1]);
|
|
|
|
$all_days = array_keys($day_mapping);
|
|
$start_index = array_search($start_day, $all_days);
|
|
$end_index = array_search($end_day, $all_days);
|
|
|
|
if ($start_index !== false && $end_index !== false) {
|
|
$result = array();
|
|
for ($i = $start_index; $i <= $end_index; $i++) {
|
|
$result[] = $day_mapping[$all_days[$i]];
|
|
}
|
|
return $result;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Handle individual days
|
|
$days = array_map('trim', explode(',', $days_string));
|
|
$result = array();
|
|
|
|
foreach ($days as $day) {
|
|
if (isset($day_mapping[$day])) {
|
|
$result[] = $day_mapping[$day];
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Log debug information
|
|
*/
|
|
public static function debug_log($message, $data = null) {
|
|
if (WP_DEBUG_LOG) {
|
|
if ($data !== null) {
|
|
$message .= ' Data: ' . print_r($data, true);
|
|
}
|
|
error_log('[TigerStyle Heat] ' . $message);
|
|
}
|
|
}
|
|
} |