Skip to content

Commit

Permalink
Revamped code upto Feature #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaled Mohammed committed Mar 25, 2017
1 parent 386e657 commit 694f2f2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
8 changes: 8 additions & 0 deletions templates/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
define( 'AMPFORWP_CUSTOM_POST_TYPE_PLUGIN', 'amp-custom-post-type/amp-custom-post-type.php' );
define( 'AMPFORWP_WOO_COMMERCE_PLUGIN', 'amp-woocommerce/amp-woocommerce.php' );

// Scripts Constants
define( 'AMPFORWP_FORM_SCRIPT', 'https://cdn.ampproject.org/v0/amp-form-0.1.js' );
define( 'AMPFORWP_SOCIAL_SHARE_SCRIPT', 'https://cdn.ampproject.org/v0/amp-social-share-0.1.js' );
define( 'AMPFORWP_ANALYTICS_SCRIPT', 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js' );
define( 'AMPFORWP_SIDE_BAR_SCRIPT', 'https://cdn.ampproject.org/v0/amp-sidebar-0.1.js' );

// Global Constants -- End Here --


Expand Down Expand Up @@ -61,8 +67,10 @@ function ampforwp_defining_constants() {
define( 'AMPFORWP_DESIGN_SPECIFIC_ARCHIVE_FILE', AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/archive.php');
define( 'AMPFORWP_DESIGN_SPECIFIC_SEARCH_FILE', AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/search.php');
define( 'AMPFORWP_DESIGN_SPECIFIC_SINGLE_FILE', AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/single.php');
define( 'AMPFORWP_DESIGN_SPECIFIC_HEADER_BAR_FILE', AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/header-bar.php');
define( 'AMPFORWP_INDEX_FILE', AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-3/index.php');
define( 'AMPFORWP_SINGLE_FILE', AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-3/single.php');
define( 'AMPFORWP_EMPTY_FILTER_FILE', AMPFORWP_PLUGIN_DIR . '/templates/design-manager/empty-filter.php');


// Constants Based on Filters
Expand Down
56 changes: 29 additions & 27 deletions templates/features.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,17 @@ function ampforwp_set_custom_style( $file, $type, $post ) {
add_filter( 'amp_post_template_file', 'ampforwp_empty_filter', 10, 3 );
function ampforwp_empty_filter( $file, $type, $post ) {
if ( 'empty-filter' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/empty-filter.php';
$file = AMPFORWP_EMPTY_FILTER_FILE;
}
return $file;
}


// 4. Custom Header files
add_filter( 'amp_post_template_file', 'ampforwp_custom_header', 10, 3 );
function ampforwp_custom_header( $file, $type, $post ) {
if ( 'header-bar' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/header-bar.php';
$file = AMPFORWP_DESIGN_SPECIFIC_HEADER_BAR_FILE;
}
return $file;
}
Expand All @@ -267,15 +268,15 @@ function ampforwp_custom_header( $file, $type, $post ) {
add_filter( 'amp_post_template_file', 'ampforwp_set_custom_meta_author', 10, 3 );
function ampforwp_set_custom_meta_author( $file, $type, $post ) {
if ( 'meta-author' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/empty-filter.php';
$file = AMPFORWP_EMPTY_FILTER_FILE;
}
return $file;
}
// 4.2 Custom Meta-Taxonomy files
add_filter( 'amp_post_template_file', 'ampforwp_set_custom_meta_taxonomy', 10, 3 );
function ampforwp_set_custom_meta_taxonomy( $file, $type, $post ) {
if ( 'meta-taxonomy' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . 'templates/design-manager/empty-filter.php';
$file = AMPFORWP_EMPTY_FILTER_FILE;
}
return $file;
}
Expand All @@ -290,52 +291,53 @@ function ampforwp_change_content_width( $content_max_width ) {
return 1000;
}


// 6. Add required Javascripts for extra AMP features
add_action('amp_post_template_head','ampforwp_register_additional_scripts', 20);
function ampforwp_register_additional_scripts() {
global $redux_builder_amp;
if( is_page() ) { ?>
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
<?php } ?>
<script async custom-element="amp-form" src="<?php echo AMPFORWP_FORM_SCRIPT; ?>"></script> <?php
}

<?php if( $redux_builder_amp['enable-single-social-icons'] == true || AMPFORWP_DM_SOCIAL_CHECK === 'true' ) { ?>
<?php if( is_singular() ) {
if( is_socialshare_or_socialsticky_enabled_in_ampforwp() ) { ?>
<script async custom-element="amp-social-share" src="https://cdn.ampproject.org/v0/amp-social-share-0.1.js"></script>
<?php }
}
} ?>
<?php if($redux_builder_amp['amp-frontpage-select-option'] == 1) { ?>
<?php if( $redux_builder_amp['enable-single-social-icons'] == true || AMPFORWP_DM_SOCIAL_CHECK === 'true' ) {
if( is_home() ) {
if( is_socialshare_or_socialsticky_enabled_in_ampforwp() ) { ?>
<script async custom-element="amp-social-share" src="https://cdn.ampproject.org/v0/amp-social-share-0.1.js"></script>
<?php }
}
}
}
if( $redux_builder_amp['enable-single-social-icons'] == true || AMPFORWP_DM_SOCIAL_CHECK === 'true' ) {
if( is_singular() ) {
if( is_socialshare_or_socialsticky_enabled_in_ampforwp() ) { ?>
<script async custom-element="amp-social-share" src="<?php echo AMPFORWP_SOCIAL_SHARE_SCRIPT; ?>"></script> <?php
}
}
}

if($redux_builder_amp['amp-frontpage-select-option'] == 1) {
if( $redux_builder_amp['enable-single-social-icons'] == true || AMPFORWP_DM_SOCIAL_CHECK === 'true' ) {
if( is_home() ) {
if( is_socialshare_or_socialsticky_enabled_in_ampforwp() ) { ?>
<script async custom-element="amp-social-share" src="<?php echo AMPFORWP_SOCIAL_SHARE_SCRIPT; ?>"></script> <?php
}
}
}
}
// Check if any of the ads are enabled then only load ads script
// moved this code to its own function and done the AMP way
}

// 6.1 Adding Analytics Scripts
add_action('amp_post_template_head','ampforwp_register_analytics_script', 20);
function ampforwp_register_analytics_script(){ ?>
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
<?php

<script async custom-element="amp-analytics" src="<?php echo AMPFORWP_ANALYTICS_SCRIPT; ?>"></script> <?php
}

add_filter( 'amp_post_template_data', 'ampforwp_add_amp_related_scripts', 20 );
function ampforwp_add_amp_related_scripts( $data ) {
global $redux_builder_amp;
// Adding Sidebar Script
if ( empty( $data['amp_component_scripts']['amp-sidebar'] ) ) {
$data['amp_component_scripts']['amp-sidebar'] = 'https://cdn.ampproject.org/v0/amp-sidebar-0.1.js';
$data['amp_component_scripts']['amp-sidebar'] = AMPFORWP_SIDE_BAR_SCRIPT;
}

return $data;
}


// 7. Footer for AMP Pages
add_filter( 'amp_post_template_file', 'ampforwp_custom_footer', 10, 3 );
function ampforwp_custom_footer( $file, $type, $post ) {
Expand Down

0 comments on commit 694f2f2

Please sign in to comment.