<?php

if ( !defined('ABSPATH') ) exit;

if ( SITECOOKIEPATH != COOKIEPATH ) {
    setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
}
/**/
function load_media_files() {
    wp_enqueue_media();
}

add_action( 'admin_enqueue_scripts', 'load_media_files' );

add_filter('delay_js_exclude_list_front_page', function($exclusion_list) {
	    $exclusion_list[] = 'lazysizes';
	    $exclusion_list[] = '/slider-blocks/';
	    return $exclusion_list;
	});

/*
add_filter( 'aos_init', function($aos_init) {
    return '
    var aoswp_params = {
        "offset":"-100",
        "duration":"850",
        "easing":"ease-in-quart",
        "delay":"300",
		"throttleDelay": "300",
        "once": true
	};
    ';
} );
*/
/**/
add_filter( 'lpam_extra_exclude_list', function( $lpam_extra_exclude_list ) {
    return array( 
		' author-ava',
	);
} );

function add_custom_script_to_footer() {
    if (is_page(972)) { // Check if the current page has ID 972
        ?>
        
        <?php
    }
}
//add_action('wp_footer', 'add_custom_script_to_footer');


/*
add_filter('use_lightbox_css', function () {
   return true;
});


function disable_wc_blocks() {
    $wc_styles = array(
        'wc-blocks-style',
        'wc-blocks-style-active-filters',
        'wc-blocks-style-add-to-cart-form',
        'wc-blocks-packages-style',
        'wc-blocks-style-all-products',
        'wc-blocks-style-all-reviews',
        'wc-blocks-style-attribute-filter',
        'wc-blocks-style-breadcrumbs',
        'wc-blocks-style-catalog-sorting',
        'wc-blocks-style-customer-account',
        'wc-blocks-style-featured-category',
        'wc-blocks-style-featured-product',
        'wc-blocks-style-mini-cart',
        'wc-blocks-style-price-filter',
        'wc-blocks-style-product-add-to-cart',
        'wc-blocks-style-product-button',
        'wc-blocks-style-product-categories',
        'wc-blocks-style-product-image',
        'wc-blocks-style-product-image-gallery',
        'wc-blocks-style-product-query',
        'wc-blocks-style-product-results-count',
        'wc-blocks-style-product-reviews',
        'wc-blocks-style-product-sale-badge',
        'wc-blocks-style-product-search',
        'wc-blocks-style-product-sku',
        'wc-blocks-style-product-stock-indicator',
        'wc-blocks-style-product-summary',
        'wc-blocks-style-product-title',
        'wc-blocks-style-rating-filter',
        'wc-blocks-style-reviews-by-category',
        'wc-blocks-style-reviews-by-product',
        'wc-blocks-style-product-details',
        'wc-blocks-style-single-product',
        'wc-blocks-style-stock-filter',
        'wc-blocks-style-cart',
        'wc-blocks-style-checkout',
        'wc-blocks-style-mini-cart-contents',
    );

    foreach ( $wc_styles as $wc_style ) {
        wp_deregister_style( $wc_style );
    }

    $wscripts = array(
        'wc-blocks-middleware',
        'wc-blocks-data-store'
    );

    foreach ( $wscripts as $wscript ) {
        wp_deregister_script( $wscript );  
    }
}

add_action( 'init', 'disable_wc_blocks', 100 );
*/

/* remove empty p(s) when using shortcode
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop', 11 );
add_filter( 'the_content', 'shortcode_unautop', 12 );
 */
/*
// Set the language of pages to en-US
function set_custom_language($lang) {
    $page_ids = array( 3387, 3489 ); // seperate IDs with comma if multiple
    $enLang = 'en-US';
    if ( is_page( $page_ids ) ) {
        return 'lang="'.$enLang.'" ';
    }
    return $lang;
}
add_filter( 'language_attributes', 'set_custom_language', PHP_INT_MAX );
*/
	

add_filter( 'om_delay_css_time', function($om_delay_css_time) {
   if ( is_page( '1929' ) ) { return '0'; }
    else { return $om_delay_css_time; }
} );

add_filter( 'om_delay_js_time', function($om_delay_js_time) {
   if (  is_post_type_archive() || is_archive() || is_home() && !is_front_page() ) { return '0'; }
    else { return $om_delay_js_time; }
} );

/* change seotm excerpt length */
add_filter('seotm_excerpt_limit', function($limit) {
    // Modify the excerpt limit to your desired value
    return 330; // Change this value as needed
});

/*
//remove_filter('the_content', 'wpautop');
remove_filter ('the_excerpt', 'wpautop');
//add_filter('the_content', 'wpautop', 12);
add_filter('the_excerpt', 'wpautop', 12);
*/

/*
function notify_search_engine() {
	// notify search engines
    $url = get_site_url() . '/sitemap.xml';
    $ping_urls = array(
        'http://www.google.com/webmasters/sitemaps/ping?sitemap=' . $url,
        'http://www.bing.com/webmaster/ping.aspx?siteMap=' . $url,
		'http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=YahooDemo&url=' . $url
    );
    foreach ($ping_urls as $ping_url) {
        $response = wp_remote_get($ping_url);
    }
}
add_action('publish_post', 'notify_search_engine');
add_action('publish_page', 'notify_search_engine');
add_action('publish_product', 'notify_search_engine');
add_action('edit_post', 'notify_search_engine');
add_action('edit_page', 'notify_search_engine');
add_action('edit_product', 'notify_search_engine');
add_action('delete_post', 'notify_search_engine');
add_action('delete_page', 'notify_search_engine');
add_action('delete_product', 'notify_search_engine');
add_action('wp_insert_post', 'notify_search_engine');
add_action('wp_insert_page', 'notify_search_engine');
add_action('wp_insert_product', 'notify_search_engine');
add_action('wp_trash_post', 'notify_search_engine');
add_action('wp_trash_page', 'notify_search_engine');
add_action('wp_trash_product', 'notify_search_engine');
add_action('wp_untrash_post', 'notify_search_engine');
add_action('wp_untrash_page', 'notify_search_engine');
add_action('wp_untrash_product', 'notify_search_engine');
add_action('create_term', 'notify_search_engine');
add_action('edit_term', 'notify_search_engine');
add_action('delete_term', 'notify_search_engine');
add_action('wp_insert_term', 'notify_search_engine');
add_action('wp_trash_term', 'notify_search_engine');
add_action('wp_untrash_term', 'notify_search_engine');
*/
/*
function instant_google_indexing() {
    $url = get_permalink();
    $url = urlencode($url);
    $google_url = 'http://www.google.com/ping?sitemap='.$url;
    $response = wp_remote_get($google_url);
    if ( is_wp_error( $response ) ) {
        return false;
    }
    return true;
}
add_action('publish_post', 'instant_google_indexing');
add_action('edit_post', 'instant_google_indexing');
add_action('publish_page', 'instant_google_indexing');
add_action('edit_page', 'instant_google_indexing');
*/
/*
function json_schema_for_post() {
    if ( is_singular( 'post' ) ) {
        global $post;
        $image = get_the_post_thumbnail_url( $post->ID, 'full' );
        $author = get_the_modified_author();
        $author_url = get_author_posts_url( $post->post_author );
        $date_modified = get_the_modified_date( 'c' );
        $date_published = get_the_date( 'c' );
        $schema = '{
      "@context": "https://schema.org",
      "@type": "Article",
      "mainEntityOfPage": {
        "@type": "WebPage",
        "@id": "'.wp_get_canonical_url().'"
        },
      "headline": "'.get_the_title().'",
      "image": [
        "'.$image.'"
       ],
      "datePublished": "'.$date_published.'",
      "dateModified": "'.$date_modified.'",
      "author": {
          "@type": "Organization",
          "name": "'.$author.'",
          "url": "'.$author_url.'"
        }
    }';
        
        $json_schema_tag = '<script type="application/ld+json">%s</script>'. PHP_EOL;
		printf( htmlspecialchars_decode(esc_attr($json_schema_tag)), htmlspecialchars_decode(wp_kses_data( $schema ) ));
    }
}
add_action( 'wp_footer', 'json_schema_for_post' );
*/
/*
function my_image_alt_text( $attr, $attachment ) {
    if ( empty( $attr['alt'] ) ) {
        $attr['alt'] = get_the_title( $attachment->ID );
    }
    return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'my_image_alt_text', 10, 2 );
*/

// require_once(TWSP_CUSTOM_DIR . 'php/inc/extra-wp-simple-extra-post-type.php'); // add simple extra post type
// require_once(TWSP_CUSTOM_DIR . 'php/inc/extra-wp-disable-comments.php'); // disable all default wp comment feature
/*
function tw_unload_files_except_single_post() {
 
	if ( !is_singular('post') ) {
		wp_dequeue_style ( 'wp-block-library' );
	}
 
 }
 add_action( 'wp_enqueue_scripts', 'tw_unload_files_except_single_post', PHP_INT_MAX );
*/
/**/
function tdg_load_files_sitewide() {
 
	//wp_enqueue_style('bg-charcoal', STARTERPACKCUSTOM_URL . 'css/bg-charcoal.css', [], STARTERPACKCUSTOM_VERSION);
	//wp_enqueue_script( 'jquery' );
 
 }
 add_action( 'wp_enqueue_scripts', 'tdg_load_files_sitewide', PHP_INT_MAX );
 add_action( 'enqueue_block_editor_assets', 'tdg_load_files_sitewide', PHP_INT_MAX );

/*
function stpwp_unload_files_sitewide() {
 
	wp_dequeue_style ( 'woo-extra-floating' );
	wp_dequeue_style ( 'ct-woocommerce-styles' );
 
 }
 add_action( 'wp_enqueue_scripts', 'stpwp_unload_files_sitewide', PHP_INT_MAX );
*/
//remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
//remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );

/* disable wp compress when uploading imgs */
add_filter('jpeg_quality', function($arg){return 100;});


/* keep infinite scrolling in the media library */
add_filter( 'media_library_infinite_scrolling', '__return_true' );


/* enable svg upload
function cc_mime_types($mimes) {
  $mimes['svg'] = 'image/svg+xml';
  return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
*/

/* enable excerpt box on pages

add_post_type_support( 'page', 'excerpt' );

add_filter( 'generateblocks_defaults', function( $defaults ) {
    $defaults['container']['containerWidth'] = '1290px';

    return $defaults;
} );
 */

/* remove image sizes except thumbnails
// disable generated image sizes
function tw_disable_image_sizes($sizes) {
	
	unset($sizes['thumbnail']);    // disable thumbnail size
	unset($sizes['medium']);       // disable medium size
	unset($sizes['large']);        // disable large size
	unset($sizes['medium_large']); // disable medium-large size
	unset($sizes['1536x1536']);    // disable 2x medium-large size
	unset($sizes['2048x2048']);    // disable 2x large size
	
	return $sizes;
	
}
add_action('intermediate_image_sizes_advanced', 'tw_disable_image_sizes');

// disable scaled image size
add_filter('big_image_size_threshold', '__return_false');

// disable other image sizes
function tw_disable_other_image_sizes() {
	
	remove_image_size('post-thumbnail'); // disable images added via set_post_thumbnail_size() 
	//remove_image_size('another-size');   // disable any other added image sizes
	
}
add_action('init', 'tw_disable_other_image_sizes');

 */
/* disable srcset on frontend
function disable_wp_responsive_images() {
	return 1;
}
add_filter('max_srcset_image_width', 'disable_wp_responsive_images');

 */

/* wp mail fixes 

function tw_change_from_email( $original ) {
	return 'hrd@intiberkatjaya.com';
}
add_filter( 'wp_mail_from', 'tw_change_from_email' );

add_filter( 'wp_mail_from_name', 'my_mail_from_name' );
function my_mail_from_name( $name ) {
    return "Inti Berkat Jaya";
}

add_filter( 'wp_mail_from', 'my_mail_from' );
function my_mail_from( $email ) {
    return "hrd@intiberkatjaya.com";
}

add_action( 'phpmailer_init', 'phpmailerSMTP' );
function phpmailerSMTP( $phpmailer ) {
    $phpmailer->Port       = 587;    // SMTP Port - 587 is for GMail
}

*/


/* use old widgets appearance
add_filter( 'use_widgets_block_editor', '__return_false' );


add_filter( 'document_title_separator', 'cyb_document_title_separator' );
function cyb_document_title_separator( $sep ) {
    $sep = "•";
    return $sep;
}
 */
/*
function skip_lazy_class_first_featured_image($attr) {
  global $wp_query;
  if ( 0 == $wp_query->current_post ) {
      $attr['loading'] = 'auto';
  }
  return $attr;
}
add_filter('wp_get_attachment_image_attributes', 'skip_lazy_class_first_featured_image' );
*/
/*
add_filter( 'om_delay_js_time', function($om_delay_js_time) {
    if (is_front_page()) {
        return '3*1000';
    }
    else {
        return $om_delay_js_time;
    }
} );
*/
/*
add_filter( 'om_delay_js_time', function($om_delay_js_time) {
    return '3*1000';
} );
add_filter( 'om_delay_css_time', function($om_delay_css_time) {
   if (is_front_page()) { return '2*1000'; }
    else { return $om_delay_css_time; }
} );
*/

/*
add_filter( 'aos_init', function($aos_init) {
    return '
    var aoswp_params = {
	"offset":"240",
	"duration":"800",
	"easing":"ease-in-out",
	"delay":"0",
	"once": false};
    ';
} );
*/

/*
add_filter( 'wp_resource_hints', function( $urls ) {

    foreach ($urls as $key => $url) {
        // Remove dns-prefetch that we really don't need it
        // See https://core.trac.wordpress.org/ticket/40426 for details 
        if ( 'cdn.jsdelivr.net' === $url ) {
            unset( $urls[ $key ] );
        }
    }

    return $urls;
} );
*/