Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Jetpack helper and some parts of WPCOM helper #1149

Merged
merged 3 commits into from May 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion amp.php
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
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