* @copyright Copyright (c) 2018, Pixelative
*/
// Add Ads into AMPWP Ads Manager panel if that was available
if( is_amp_wp_ads_manager_plugin_active() ) {
amp_wp_template_part( 'ads' );
}
if( !defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly.
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-font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
amp_wp_enqueue_style( 'amp-google-fonts', '//fonts.googleapis.com/css?family=Karla|Noto+Sans:700|Overpass+Mono');
amp_wp_enqueue_block_style( 'normalize', '../css/normalize', FALSE ); // Normalize without RTL
amp_wp_enqueue_block_style( 'style', '../css/style' );
}
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() {
if( amp_wp_get_theme_mod( 'amp-wp-sidebar-show' ) ) {
amp_wp_enqueue_script( 'amp-sidebar', 'https://cdn.ampproject.org/v0/amp-sidebar-0.1.js' );
}
if(
amp_wp_get_theme_mod( 'amp-wp-ga-switch' ) ||
amp_wp_get_theme_mod( 'amp-wp-fbp-switch' ) ||
amp_wp_get_theme_mod( 'amp-wp-sa-switch' ) ||
amp_wp_get_theme_mod( 'amp-wp-qc-switch' )
) {
amp_wp_enqueue_script( 'amp-analytics', 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js' );
}
if( amp_wp_get_theme_mod( 'amp-wp-notifications' ) ) {
amp_wp_enqueue_script( 'amp-user-notification', 'https://cdn.ampproject.org/v0/amp-user-notification-0.1.js' );
}
if( amp_wp_get_theme_mod( 'amp-wp-gdpr-compliance' ) ) {
amp_wp_enqueue_script( 'amp-consent', 'https://cdn.ampproject.org/v0/amp-consent-0.1.js' );
amp_wp_enqueue_script( 'amp-geo', 'https://cdn.ampproject.org/v0/amp-geo-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() {
$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();
?>
.pagination .nav-links .page-numbers.prev:hover,
.pagination .nav-links .page-numbers.next:hover,
.listing-item a.post-read-more:hover,
.post-terms.cats .term-type,
.post-terms a:hover,
.search-form .search-submit,
.amp-wp-main-link a {
background: ;
}
.post-categories li a {
background: ;
}
.entry-content ul.amp-wp-shortcode-list li:before,
a {
color: ;
}
body.body {
background:;
color: ;
}
.amp-wp-wrapper {
background:;
}
.amp-wp-footer-nav {
background:;
}
.amp-wp-footer {
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_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() ) :
if( $exclude_urls = amp_wp_get_theme_mod( 'amp-wp-exclude-urls' ) ) :
Amp_WP_Content_Sanitizer::set_none_amp_url( explode( "\n", $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( 'google-amp-for-wordpess-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() {
return amp_wp_get_theme_mod( 'amp-wp-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.0.0
* @return array
*/
function amp_wp_filter_config( $filters ) {
$filters['disabled_post_types'] = (array) amp_wp_get_theme_mod( 'amp-wp-filter-post-types' );
$filters['disabled_taxonomies'] = (array) amp_wp_get_theme_mod( 'amp-wp-filter-taxonomies' );
$filters['disabled_homepage'] = !amp_wp_get_theme_mod( 'amp-wp-on-home' );
$filters['disabled_search'] = !amp_wp_get_theme_mod( 'amp-wp-on-search' );
return $filters;
}
}
add_filter( 'amp_wp_filter_config_list', 'amp_wp_filter_config' );
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() {
if(
( amp_wp_get_option( 'amp-wp-ga-switch', amp_wp_get_default_theme_setting( 'amp-wp-ga-switch' ) ) ) &&
( $ga_code = amp_wp_get_theme_mod( 'amp-wp-ga-analytic' ) )
) :
?>