/home/bdqbpbxa/dev-subdomains/precisai-dev.goodface.com.ua/wp-content/themes/precisai/functions.php
<?php
add_filter( 'auto_update_plugin', '__return_false' );
add_filter( 'auto_update_theme', '__return_false' );
add_filter( 'wp_default_scripts', 'remove_jquery_migrate' );
function remove_jquery_migrate( &$scripts){
if(!is_admin()){
$scripts->remove( 'jquery' );
}
}
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'rsd_link' );
remove_action('wp_head', 'wp_shortlink_wp_head');
remove_action('wp_head','adjacent_posts_rel_link_wp_head');
remove_action('wp_head','feed_links_extra', 3);
remove_action('xmlrpc_rsd_apis', 'rest_output_rsd');
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
remove_action( 'wp_head', 'wp_oembed_add_host_js');
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action( 'wp_head', 'wp_resource_hints', 2 );
if( 'Disable REST API' ){
remove_action( 'xmlrpc_rsd_apis', 'rest_output_rsd' );
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'template_redirect', 'rest_output_link_header', 11 );
remove_action( 'auth_cookie_malformed', 'rest_cookie_collect_status' );
remove_action( 'auth_cookie_expired', 'rest_cookie_collect_status' );
remove_action( 'auth_cookie_bad_username', 'rest_cookie_collect_status' );
remove_action( 'auth_cookie_bad_hash', 'rest_cookie_collect_status' );
remove_action( 'auth_cookie_valid', 'rest_cookie_collect_status' );
remove_filter( 'rest_authentication_errors', 'rest_cookie_check_errors', 100 );
remove_action( 'rest_api_init', 'rest_api_default_filters', 10 );
remove_action( 'rest_api_init', 'wp_oembed_register_route' );
remove_filter( 'rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
remove_action( 'wp_head', 'wp_oembed_add_host_js' );
}
add_filter( 'term_description', 'shortcode_unautop');
add_filter( 'term_description', 'do_shortcode' );
function wpassist_remove_block_library_css(){
wp_dequeue_style( 'wp-block-library' );
}
add_action( 'wp_enqueue_scripts', 'wpassist_remove_block_library_css' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'title-tag' );
register_nav_menus( array(
'head_menu' => 'Header area',
'foot_menu' => 'Footer area',
'foot_privacy_policy' => 'Footer privacy policy',
) );
// Define theme version
define('THEME_VERSION', '?v=' . time());
function register_styles_scripts() {
// wp_enqueue_style( 'font-style', get_stylesheet_directory_uri() . '/fonts/fonts.css' );
// wp_enqueue_style( 'main-style', get_stylesheet_uri() );
// wp_enqueue_script( 'main-js', get_stylesheet_directory_uri() . '/main.js' . THEME_VERSION, array('jquery'), null, true );
}
add_action('wp_enqueue_scripts', 'register_styles_scripts');
function pmp_custom_upload_mimes($existing_mimes = array()) {
$existing_mimes['webp'] = 'image/webp';
$existing_mimes['ico'] = 'image/x-icon';
$existing_mimes['svg'] = 'image/svg+xml';
return $existing_mimes;
}
add_filter('mime_types', 'pmp_custom_upload_mimes');
add_filter('wpcf7_autop_or_not', '__return_false');
function read_time_estimate($content){
$word_count = str_word_count(strip_tags($content));
$words_per_minute = 200;
$minutes = ceil($word_count / $words_per_minute);
return $minutes . " min read";
}
function precisai_register_post_types() {
// register_post_type('press-releases',
// array(
// 'label' => null,
// 'labels' => array(
// 'name' => 'Press Releases', // основное название для типа записи
// 'singular_name' => 'Press Releases', // название для одной записи этого типа
// ),
// 'public' => true,
// 'menu_position' => 6,
// 'menu_icon' => 'dashicons-calendar',
// 'hierarchical' => true,
// 'supports' => array('title', 'editor', 'thumbnail', 'excerpt'), // 'title','editor','author','thumbnail','excerpt','trackbacks','custom-fields','comments','revisions','page-attributes','post-formats'
// 'has_archive' => true,
//// 'taxonomies' => array('post_tag')
// )
// );
//
// register_post_type('press-releases',
// array(
// 'label' => null,
// 'labels' => array(
// 'name' => 'Press Releases', // основное название для типа записи
// 'singular_name' => 'Press Releases', // название для одной записи этого типа
// ),
// 'public' => true,
// 'menu_position' => 6,
// 'menu_icon' => 'dashicons-calendar',
// 'hierarchical' => true,
// 'supports' => array('title', 'editor', 'thumbnail', 'excerpt'), // 'title','editor','author','thumbnail','excerpt','trackbacks','custom-fields','comments','revisions','page-attributes','post-formats'
// 'has_archive' => true,
//// 'taxonomies' => array('post_tag')
// )
// );
register_post_type('glossary-term',
array(
'labels' => array(
'name' => 'Glossaries',
'singular_name' => 'Glossary Term',
),
'public' => true,
'menu_position' => 6,
'menu_icon' => 'dashicons-book-alt',
'hierarchical' => false,
'supports' => array('title', 'editor', 'thumbnail', 'excerpt'),
'has_archive' => true,
'rewrite' => array(
'slug' => 'glossary-term',
'with_front' => false,
),
)
);
}
add_action( 'init', 'precisai_register_post_types' );
function modify_menu_link_for_specific_page( $items, $args ) {
if( is_page(682) ) {
$items = str_replace( '<a href="#drop-us-line">Contact Us</a>', '<a href="/#drop-us-line">Contact Us</a>', $items );
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'modify_menu_link_for_specific_page', 10, 2 );
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Theme General Settings',
'menu_title' => 'Theme Settings',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
acf_add_options_sub_page(array(
'page_title' => 'Header',
'menu_title' => 'Header',
'parent_slug' => 'theme-general-settings',
));
acf_add_options_sub_page(array(
'page_title' => 'News Page',
'menu_title' => 'News Page',
'parent_slug' => 'theme-general-settings',
));
}
add_filter('wpcf7_autop_or_not', '__return_false');
function showCategoryIconSrc($name) {
$icons = [
'Blogs' => '/wp-content/uploads/2025/01/i-creation-hub.svg',
'Glossary' => '/wp-content/uploads/2025/01/i-glossary.svg',
'Press Releases' => '/wp-content/uploads/2025/01/i-press-release.svg',
];
$name = ucfirst(strtolower($name));
return $icons[$name] ?? '/wp-content/uploads/2025/01/i-press-release.svg';
}
// Force-download PDF via same-origin proxy to avoid inline/open and CORS issues
add_action('template_redirect', function () {
if (empty($_GET['precis_download_pdf'])) {
return;
}
$pdf_url = isset($_GET['pdf']) ? esc_url_raw($_GET['pdf']) : '';
if (!$pdf_url) {
status_header(400);
exit;
}
// Map URL to local uploads path securely
$uploads = wp_upload_dir();
$baseurl = rtrim($uploads['baseurl'], '/');
$basedir = rtrim($uploads['basedir'], DIRECTORY_SEPARATOR);
$filepath = '';
// Case 1: Direct same baseurl
if (strpos($pdf_url, $baseurl) === 0) {
$relative = substr($pdf_url, strlen($baseurl));
$filepath = $basedir . str_replace('/', DIRECTORY_SEPARATOR, $relative);
} else {
// Case 2: Different host/protocol (CDN/http/https) → map by /uploads/
$parsed = wp_parse_url($pdf_url);
$path = isset($parsed['path']) ? $parsed['path'] : '';
$pos = strpos($path, '/uploads/');
if ($pos !== false) {
$after = substr($path, $pos + strlen('/uploads/'));
$filepath = trailingslashit($basedir) . str_replace('/', DIRECTORY_SEPARATOR, $after);
}
}
if (!$filepath) {
status_header(403);
exit;
}
if (!file_exists($filepath) || !is_readable($filepath)) {
status_header(404);
exit;
}
// Send headers forcing download
nocache_headers();
header('X-Robots-Tag: noindex, nofollow', true);
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . basename($filepath) . '"');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');
header('Content-Length: ' . filesize($filepath));
readfile($filepath);
exit;
});