Skip to content

Commit

Permalink
Merge pull request #1149 from Automattic/try/deprecate-jetpack-helper
Browse files Browse the repository at this point in the history
Deprecate Jetpack helper and some parts of WPCOM helper
  • Loading branch information
westonruter committed May 18, 2018
2 parents adc8fed + 192bcb2 commit 927b07c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 146 deletions.
2 changes: 1 addition & 1 deletion amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function amp_init() {
// Redirect the old url of amp page to the updated url.
add_filter( 'old_slug_redirect_url', 'amp_redirect_old_slug_to_new_url' );

if ( class_exists( 'Jetpack' ) && ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ) {
if ( class_exists( 'Jetpack' ) && ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) && version_compare( JETPACK__VERSION, '6.2-alpha', '<' ) ) {
require_once AMP__DIR__ . '/jetpack-helper.php';
}

Expand Down
145 changes: 0 additions & 145 deletions wpcom-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,154 +6,9 @@
* @package AMP
*/

add_action( 'pre_amp_render_post', 'jetpack_amp_disable_the_content_filters' );

// Disable admin menu.
add_filter( 'amp_options_menu_is_enabled', '__return_false', 9999 );

/**
* Disable the_content filters for Jetpack.
*
* @since 0.3
*/
function jetpack_amp_disable_the_content_filters() {
add_filter( 'post_flair_disable', '__return_true', 99 );
add_filter( 'videopress_show_2015_player', '__return_true' );
add_filter( 'protected_embeds_use_form_post', '__return_false' );

remove_filter( 'the_title', 'widont' );

remove_filter( 'pre_kses', array( 'Filter_Embedded_HTML_Objects', 'filter' ), 11 );
remove_filter( 'pre_kses', array( 'Filter_Embedded_HTML_Objects', 'maybe_create_links' ), 100 );
}

add_action( 'amp_post_template_head', 'jetpack_amp_add_og_tags' );

/**
* Add Open Graph tags.
*
* @since 0.3
*/
function jetpack_amp_add_og_tags() {
if ( function_exists( 'jetpack_og_tags' ) ) {
jetpack_og_tags();
}
}

add_filter( 'amp_post_template_metadata', 'jetpack_amp_post_template_metadata', 10, 2 );

/**
* Add publisher and image metadata.
*
* @since 0.3
*
* @param array $metadata Metadata array.
* @param WP_Post $post Post.
* @return array Modified metadata array.
*/
function jetpack_amp_post_template_metadata( $metadata, $post ) {
if ( isset( $metadata['publisher'] ) && ! isset( $metadata['publisher']['logo'] ) ) {
$metadata = wpcom_amp_add_blavatar_to_metadata( $metadata );
}

if ( ! isset( $metadata['image'] ) ) {
$metadata = wpcom_amp_add_image_to_metadata( $metadata, $post );
}

return $metadata;
}

/**
* Add blavatar to metadata.
*
* @since 0.3
*
* @param array $metadata Metadata.
* @return array Metadata.
*/
function wpcom_amp_add_blavatar_to_metadata( $metadata ) {
if ( ! function_exists( 'blavatar_domain' ) ) {
return $metadata;
}

$size = 60;

$metadata['publisher']['logo'] = array(
'@type' => 'ImageObject',
'url' => blavatar_url( blavatar_domain( site_url() ), 'img', $size, staticize_subdomain( 'https://wordpress.com/i/favicons/apple-touch-icon-60x60.png' ) ),
'width' => $size,
'height' => $size,
);

return $metadata;
}

/**
* Add image to metadata.
*
* @since 0.3.2
*
* @param array $metadata Metadata.
* @param WP_Post $post Post.
* @return array Metadata.
*/
function wpcom_amp_add_image_to_metadata( $metadata, $post ) {
if ( ! class_exists( 'Jetpack_PostImages' ) ) {
return wpcom_amp_add_fallback_image_to_metadata( $metadata );
}

$image = Jetpack_PostImages::get_image( $post->ID, array(
'fallback_to_avatars' => true,
'avatar_size' => 200,
// AMP already attempts these.
'from_thumbnail' => false,
'from_attachment' => false,
) );

if ( empty( $image ) ) {
return wpcom_amp_add_fallback_image_to_metadata( $metadata );
}

if ( ! isset( $image['src_width'] ) ) {
$dimensions = wpcom_amp_extract_image_dimensions_from_getimagesize( array(
$image['src'] => false,
) );

if ( false !== $dimensions[ $image['src'] ] ) {
$image['src_width'] = $dimensions['width'];
$image['src_height'] = $dimensions['height'];
}
}

$metadata['image'] = array(
'@type' => 'ImageObject',
'url' => $image['src'],
'width' => $image['src_width'],
'height' => $image['src_height'],
);

return $metadata;
}

/**
* Add fallback image to metadata.
*
* @since 0.3.2
*
* @param array $metadata Metadata.
* @return array Metadata.
*/
function wpcom_amp_add_fallback_image_to_metadata( $metadata ) {
$metadata['image'] = array(
'@type' => 'ImageObject',
'url' => staticize_subdomain( 'https://wordpress.com/i/blank.jpg' ),
'width' => 200,
'height' => 200,
);

return $metadata;
}

add_action( 'amp_extract_image_dimensions_batch_callbacks_registered', 'wpcom_amp_extract_image_dimensions_batch_add_custom_callbacks' );

/**
Expand Down

0 comments on commit 927b07c

Please sign in to comment.