* @copyright Copyright (c) 2018-2019, Pixelative
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; } // Exit if accessed directly.
// Add Ads into AMP WP Ads Manager panel if that was available.
if ( is_amp_wp_ads_manager_plugin_active() ) {
amp_wp_template_part( 'amp-wp-ads-manager/ads' );
}
add_image_size( 'amp-wp-small', 100, 100, array( 'center', 'center' ) ); // Main Post Image In Small Width.
add_image_size( 'amp-wp-large', 738, 430, array( 'center', 'center' ) ); // Main Post Image In Full Width.
add_image_size( 'amp-wp-normal', 230, 160, array( 'center', 'center' ) ); // Main Post Image In Normal Width.
register_nav_menus( array( 'amp-wp-sidebar-nav' => __( 'AMP Sidebar', 'amp-wp' ) ) );
register_nav_menus( array( 'amp-wp-footer' => __( 'AMP Footer Menu', 'amp-wp' ) ) );
// Hook to enqueue style.
add_action( 'amp_wp_template_head', 'amp_wp_enqueue_styles', 0 );
if ( ! function_exists( 'amp_wp_language_attributes' ) ) :
/**
* Get the Language Attributes for the HTML Tag.
*
* @version 1.0.0
* @since 1.0.0
*/
function amp_wp_language_attributes() {
$attributes = array();
if ( function_exists( 'is_rtl' ) && is_rtl() ) {
$attributes[] = 'dir="rtl"';
}
if ( $lang = get_bloginfo( 'language' ) ) {
$attributes[] = "lang=\"$lang\"";
}
$output = implode( ' ', $attributes );
echo $output;
}
endif;
if ( ! function_exists( 'amp_wp_enqueue_styles' ) ) :
/**
* Enqueue Static File for AMP Version
*
* @version 1.0.0
* @since 1.0.0
*/
function amp_wp_enqueue_styles() {
amp_wp_enqueue_style( 'amp-wp-font-awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' );
amp_wp_enqueue_style( 'amp-wp-google-fonts', 'https://fonts.googleapis.com/css?family=Karla|Noto+Sans:700|Overpass+Mono' );
amp_wp_enqueue_block_style( 'global', AMP_WP_TEMPLATE_DIR_CSS . 'global/global' );
}
endif;
if ( ! function_exists( 'amp_wp_enqueue_static' ) ) :
/**
* Enqueue Static File for AMP Version
*
* @version 1.0.0
* @since 1.0.0
*/
function amp_wp_enqueue_static() {
$amp_wp_layout_settings = get_option( 'amp_wp_layout_settings' );
$is_show_sidebar = ( isset( $amp_wp_layout_settings['is_show_sidebar'] ) && ! empty( $amp_wp_layout_settings['is_show_sidebar'] ) ) ? $amp_wp_layout_settings['is_show_sidebar'] : '';
if ( '1' == $is_show_sidebar ) {
amp_wp_enqueue_script( 'amp-sidebar', 'https://cdn.ampproject.org/v0/amp-sidebar-0.1.js' );
}
}
endif;
// Enqueue Static File Hook.
add_action( 'amp_wp_template_enqueue_scripts', 'amp_wp_enqueue_static' );
if ( ! function_exists( 'amp_wp_custom_styles' ) ) :
/**
* Prints Custom Codes of AMP Theme After All Styles
*
* @version 1.0.0
* @since 1.0.0
*/
function amp_wp_custom_styles() {
$header_text_color = amp_wp_get_theme_mod( 'amp-wp-header-text-color', false );
$header_background_color = amp_wp_get_theme_mod( 'amp-wp-header-background-color', false );
$theme_color = amp_wp_get_theme_mod( 'amp-wp-color-theme', false );
$text_color = amp_wp_get_theme_mod( 'amp-wp-color-text', false );
ob_start();
?>
.site-header .logo a, .site-header .header-nav > li > a, .site-header .header-nav > li .navbar-toggle { color: ; }
.site-header { background: ; }
.pagination .nav-links .page-numbers.prev,
.pagination .nav-links .page-numbers.next,
.listing-item a.post-read-more,
.post-terms.cats .term-type,
.post-terms a:hover,
.search-form .search-submit,
.amp-wp-main-link a,
.post-categories li a,
.amp-btn,.amp-btn:active,.amp-btn:focus,.amp-btn:hover {
background: ;
}
.entry-content ul.amp-wp-shortcode-list li:before, a {
color: ;
}
.amp-btn,.amp-btn:active,.amp-btn:focus,.amp-btn:hover, .post-terms.tags a:hover,.post-terms.tags a:focus,.post-terms.tags a:active {
border-color: ;
}
body.body {
background:;
color: ;
}
.amp-wp-footer-nav {
background:;
}
.amp-wp-copyright {
background:;
}
'unknown',
'content' => '',
);
}
// Custom External Videos.
preg_match( '#^(http|https)://.+\.(mp4|m4v|webm|ogv|wmv|flv)$#i', $content, $matches );
if ( ! empty( $matches[0] ) ) {
return array(
'type' => 'external-video',
'content' => do_shortcode( '[video src="' . $matches[0] . '"]' ),
);
}
// Custom External Audio.
preg_match( '#^(http|https)://.+\.(mp3|m4a|ogg|wav|wma)$#i', $content, $matches );
if ( ! empty( $matches[0] ) ) {
return array(
'type' => 'external-audio',
'content' => do_shortcode( '[audio src="' . $matches[0] . '"]' ),
);
}
// Default Embeds and Other Registered.
global $wp_embed;
if ( ! is_object( $wp_embed ) ) {
return array(
'type' => 'unknown',
'content' => $content,
);
}
$embed = $wp_embed->autoembed( $content );
if ( $embed !== $content ) {
return array(
'type' => 'embed',
'content' => $embed,
);
}
// No Embed Detected!
return array(
'type' => 'unknown',
'content' => $content,
);
}
endif;
if ( ! function_exists( 'amp_wp_set_show_on_front' ) ) :
/**
* Setup show on front option value
*
* @since 1.0.0
* @return bool|string
*/
function amp_wp_set_show_on_front() {
return amp_wp_get_theme_mod( 'amp-wp-show-on-front' );
}
endif;
add_filter( 'amp_wp_template_show_on_front', 'amp_wp_set_show_on_front' );
if ( ! function_exists( 'amp_wp_set_page_on_front' ) ) :
/**
* Setup Page on Front Option Value
*
* @version 1.0.0
* @since 1.0.0
*
* @return bool|string
*/
function amp_wp_set_page_on_front() {
return amp_wp_get_theme_mod( 'amp-wp-page-on-front' );
}
endif;
add_filter( 'amp_wp_template_page_on_front', 'amp_wp_set_page_on_front' );
if ( is_amp_wp() ) :
$exclude_urls = '';
if ( get_option( 'amp_wp_general_settings' ) ) {
$amp_wp_general_settings = get_option( 'amp_wp_general_settings' );
if ( isset( $amp_wp_general_settings['exclude_urls'] ) && ! empty( $amp_wp_general_settings['exclude_urls'] ) ) {
$exclude_urls = $amp_wp_general_settings['exclude_urls'];
}
}
if ( isset( $exclude_urls ) && ! empty( $exclude_urls ) ) :
Amp_WP_Content_Sanitizer::set_non_amp_url( explode( "\n", trim( $exclude_urls ) ) );
endif;
endif;
if ( ! function_exists( 'amp_wp_custom_code_head' ) ) :
/**
* Prints Custom Codes Inside Head Tag
*
* @hooked amp_wp_template_head
*/
function amp_wp_custom_code_head() {
echo amp_wp_get_option( 'amp-wp-code-head', false );
}
endif;
add_action( 'amp_wp_template_head', 'amp_wp_custom_code_head' );
if ( ! function_exists( 'amp_wp_custom_code_body_start' ) ) :
/**
* Prints Custom Codes Right After Body Tag Start
*
* @hooked amp_wp_template_body_start
*/
function amp_wp_custom_code_body_start() {
echo amp_wp_get_option( 'amp-wp-code-body-start', false );
}
endif;
add_action( 'amp_wp_template_body_start', 'amp_wp_custom_code_body_start' );
if ( ! function_exists( 'amp_wp_custom_code_body_stop' ) ) :
/**
* Prints custom codes before body tag close
*
* @hooked amp_wp_template_footer
*/
function amp_wp_custom_code_body_stop() {
echo amp_wp_get_option( 'amp-wp-code-body-stop', false );
}
endif;
add_action( 'amp_wp_template_footer', 'amp_wp_custom_code_body_stop' );
if ( ! function_exists( 'amp_wp_auto_redirect_mobiles' ) ) :
/**
* Trigger Auto Redirect Option
*
* @version 1.0.0
* @since 1.0.0
*
* @return bool true If Active
*/
function amp_wp_auto_redirect_mobiles() {
$mobile_auto_redirect = '';
if ( get_option( 'amp_wp_general_settings' ) ) {
$amp_wp_general_settings = get_option( 'amp_wp_general_settings' );
if ( isset( $amp_wp_general_settings['mobile_auto_redirect'] ) && ! empty( $amp_wp_general_settings['mobile_auto_redirect'] ) ) {
$mobile_auto_redirect = intval( $amp_wp_general_settings['mobile_auto_redirect'] );
}
}
return $mobile_auto_redirect;
}
endif;
add_filter( 'amp_wp_template_auto_redirect', 'amp_wp_auto_redirect_mobiles' );
if ( ! function_exists( 'amp_wp_list_post_types' ) ) {
/**
* List available and public post types.
*
* @since 1.0.0
* @return array
*/
function amp_wp_list_post_types() {
$results = array();
foreach ( get_post_types(
array(
'public' => true,
'publicly_queryable' => true,
)
) as $post_type => $_ ) {
if ( ! $post_type_object = get_post_type_object( $post_type ) ) {
continue;
}
$results[ $post_type ] = $post_type_object->label;
}
return $results;
}
}
if ( ! function_exists( 'amp_wp_list_taxonomies' ) ) {
/**
* List Available and Public Taxonomies.
*
* @since 1.0.0
* @return array
*/
function amp_wp_list_taxonomies() {
$results = array();
$taxonomies = get_taxonomies( array( 'public' => true ) );
if ( $taxonomies ) {
unset( $taxonomies['post_format'] );
foreach ( $taxonomies as $id => $_ ) {
if ( $object = get_taxonomy( $id ) ) {
$results[ $id ] = $object->label;
}
}
}
return $results;
}
}
if ( ! function_exists( 'amp_wp_filter_config' ) ) {
/**
* @param array $filters
*
* @since 1.2.0
* @return array
*/
function amp_wp_filter_config( $filters ) {
$amp_on_home = '';
$amp_on_search = '';
$amp_on_post_types = array();
$amp_on_taxonomies = array();
if ( get_option( 'amp_wp_general_settings' ) ) {
$amp_wp_general_settings = get_option( 'amp_wp_general_settings' );
if ( isset( $amp_wp_general_settings['amp_on_home'] ) && ! empty( $amp_wp_general_settings['amp_on_home'] ) ) {
$amp_on_home = $amp_wp_general_settings['amp_on_home'];
}
if ( isset( $amp_wp_general_settings['amp_on_search'] ) && ! empty( $amp_wp_general_settings['amp_on_search'] ) ) {
$amp_on_search = $amp_wp_general_settings['amp_on_search'];
}
if ( isset( $amp_wp_general_settings['amp_on_post_types'] ) && ! empty( $amp_wp_general_settings['amp_on_post_types'] ) ) {
$amp_on_post_types = (array) $amp_wp_general_settings['amp_on_post_types'];
}
if ( isset( $amp_wp_general_settings['amp_on_taxonomies'] ) && ! empty( $amp_wp_general_settings['amp_on_taxonomies'] ) ) {
$amp_on_taxonomies = (array) $amp_wp_general_settings['amp_on_taxonomies'];
}
}
$filters['disabled_homepage'] = ! $amp_on_home;
$filters['disabled_search'] = ! $amp_on_search;
$filters['disabled_post_types'] = $amp_on_post_types;
$filters['disabled_taxonomies'] = $amp_on_taxonomies;
return $filters;
}
}
add_filter( 'amp_wp_filter_config_list', 'amp_wp_filter_config' );
if ( ! function_exists( 'amp_wp_set_url_format' ) ) {
/**
* Set default AMP URL structure.
*
* @hooked amp_wp_url_format_filter
*
* @param string $default
* @since 1.0.4
*
* @return string
*/
function amp_wp_set_url_format( $default ) {
$amp_wp_general_settings = get_option( 'amp_wp_general_settings' );
return ( isset( $amp_wp_general_settings['url_structure'] ) && ! empty( $amp_wp_general_settings['url_structure'] ) ) ? $amp_wp_general_settings['url_structure'] : 'start-point';
}
}
add_filter( 'amp_wp_url_format_filter', 'amp_wp_set_url_format' );
if ( ! function_exists( 'amp_wp_analytics_ga_callback' ) ) :
/**
* Prints Google Analytic Code
*
* @hooked amp_wp_analytics_ga
* @since 1.0.0
*/
function amp_wp_analytics_ga_callback() {
$ga_switch = '';
$ga_code = '';
if ( get_option( 'amp_wp_ga' ) ) {
$amp_wp_ga = get_option( 'amp_wp_ga' );
$ga_switch = $amp_wp_ga['ga_switch'];
$ga_code = $amp_wp_ga['ga'];
}
if ( $ga_switch && $ga_code ) :
amp_wp_enqueue_script( 'amp-analytics', 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js' );
?>
99999 ) {
$afs_server = 'www1';
}
if ( $afs_website_id > 199999 ) {
$afs_server = 'www2';
}
if ( $afs_website_id > 299999 ) {
$afs_server = 'www3';
}
if ( $afs_website_id > 399999 ) {
$afs_server = 'www4';
}
if ( $afs_website_id > 499999 ) {
$afs_server = 'www5';
}
if ( $afs_website_id > 599999 ) {
$afs_server = 'www6';
}
if ( $afs_website_id > 699999 ) {
$afs_server = 'www7';
}
if ( $afs_website_id > 799999 ) {
$afs_server = 'www8';
}
if ( $afs_website_id > 899999 ) {
$afs_server = 'www9';
}
if ( $afs_website_id > 999999 ) {
$afs_server = 'www10';
}
}
if ( $afs_switch && $afs_website_id ) :
amp_wp_enqueue_script( 'amp-analytics', 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js' );
?>
is_main_query() ) {
return $content;
}
$blocks_list = array(
'button',
'columns',
'cover',
'file',
'gallery',
'image',
'latest-comments',
'list',
'quote',
'separator',
'table',
'verse',
);
if ( preg_match_all(
'/).)*+)?}\s+)?(?\/)?-->/s',
$content,
$matches
) ) {
foreach ( array_unique( $matches[2] ) as $block ) {
if ( in_array( $block, $blocks_list ) ) {
amp_wp_enqueue_block_style( 'block-' . $block, AMP_WP_TEMPLATE_DIR_CSS . 'themes/' . AMP_WP_THEME_NAME . '/gutenberg/' . $block, false );
}
}
}
return $content;
}
}
add_filter( 'the_content', 'amp_wp_do_block_styles', 2 );