File: /var/www/chaharrah.tv/root/wp-content/themes/chaharrah/functions.php
<?php
// $shomalgan_includes = TEMPLATEPATH . '/includes/';
// require_once ($shomalgan_includes . 'theme-hacks.php');
if (!taxonomy_exists('mohtava')) {
register_taxonomy (
'mohtava',
'post',
array(
'show_in_rest' => true,
'hierarchical' => true,
'show_ui' => true,
'label' => __('جنس محتویات'),
'query_var' => 'mohtava',
'rewrite' => array( 'slug' => 'mohtava')
)
);
wp_insert_term('پی دی اف', 'mohtava', array('description'=> '', 'slug' => 'pdf'));
wp_insert_term('پاورپوینت', 'mohtava', array('description'=> '', 'slug' => 'powerpint'));
wp_insert_term('فایل صوتی', 'mohtava', array('description'=> '', 'slug' => 'audio'));
wp_insert_term('فایل تصویری', 'mohtava', array('description'=> '', 'slug' => 'video'));
}
if (!taxonomy_exists('options')) {
register_taxonomy(
'options',
'post',
array(
'show_in_rest' => true,
'hierarchical' => true,
'show_ui' => true,
'label' => __('خصوصیات'),
'query_var' => 'options',
'rewrite' => array('slug' => 'options')
)
);
wp_insert_term('برود به اسلایدر', 'options', array('description'=> '', 'slug' => 'slider'));
wp_insert_term('توصیه می شود', 'options', array('description'=> '', 'slug' => 'recomanded'));
}
if (!taxonomy_exists('lecturer'))
register_taxonomy(
'lecturer',
'post',
array(
'show_in_rest' => true,
'hierarchical' => false,
'show_ui' => true,
'label' => __('سخنران'),
// 'query_var' => 'lecturer'
'rewrite' => array('slug' => 'lecturer')
)
);
if (!taxonomy_exists('organizer'))
register_taxonomy(
'organizer',
'post',
array(
'show_in_rest' => true,
'hierarchical' => false,
'show_ui' => true,
'label' => __('برگزار کننده'),
// 'query_var' => 'sazmanz',
'rewrite' => array('slug' => 'organizer')
)
);
if (!taxonomy_exists('events'))
register_taxonomy(
'events',
'post',
array(
'show_in_rest' => true,
'hierarchical' => false,
'show_ui' => true,
'label' => __('رویدادها'),
// 'query_var' => 'events',
'rewrite' => array( 'slug' => 'events')
)
);
if(!post_type_exists('anounce')) {
register_post_type('anounce',
array(
'labels' => array(
'name' => 'آگهیها',
'singular_name' => 'آگهی'
),
'public' => true,
'has_archive' => true,
'description' => 'آگهی سخنرانیهای پیشرو',
'taxonomies' => array('post_tag'),
)
);
}
add_action('init', 'anounce_add_default_boxes');
function anounce_add_default_boxes() {
register_taxonomy_for_object_type('post_tag', 'anounce');
}
function chaharrah_widgets_init() {
// register_sidebar( array(
// 'name' => 'زیر فیلم',
// 'id' => 'sub_player',
// 'before_widget' => '<div class="sub-player-widget">',
// 'after_widget' => '</div>',
// ) );
}
add_action( 'widgets_init', 'chaharrah_widgets_init' );
// This theme uses wp_nav_menu() in one location.
add_theme_support( 'menus' );
register_nav_menus(array(
'top' => 'منوی نوار بالا',
'main' => 'منوی اصلی',
'footer' => 'فوتر',
'anounce_page' => 'منوی صفحه آگهیها'
));
/**
* Conditional function to check if post belongs to term in a custom taxonomy.
*
* @param tax string taxonomy to which the term belons
* @param term int|string|array attributes of shortcode
* @param _post int post id to be checked
* @return BOOL True if term is matched, false otherwise
*/
function pa_in_taxonomy($tax, $term, $_post = NULL) {
// if neither tax nor term are specified, return false
if ( !$tax || !$term ) { return FALSE; }
// if post parameter is given, get it, otherwise use $GLOBALS to get post
if ( $_post ) {
$_post = get_post( $_post );
} else {
$_post =& $GLOBALS['post'];
}
// if no post return false
if ( !$_post ) { return FALSE; }
// check whether post matches term belongin to tax
$return = is_object_in_term( $_post->ID, $tax, $term );
// if error returned, then return false
if ( is_wp_error( $return ) ) { return FALSE; }
return $return;
}
function ip_check_callback() {
if (defined('LSCWP_V')){
do_action( 'litespeed_control_set_nocache', 'nocache due to logged in' );
}
$data = array(
'remote_ip' => $_SERVER['REMOTE_ADDR'] ?? 'Null',
'x_forwarded_for' => $_SERVER['HTTP_X_FORWARDED_FOR'] ?? 'Null',
'proxy_remote_addr' => $_SERVER['PROXY_REMOTE_ADDR'] ?? 'Null'
);
return rest_ensure_response($data);
}
function register_ip_check_route() {
register_rest_route('lscwp', '/ip-check', array(
'methods' => 'GET',
'callback' => 'ip_check_callback'
));
}
add_action('rest_api_init', 'register_ip_check_route');