Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Open Graph Ingestion Flow #643

Merged
merged 16 commits into from
May 30, 2017
Merged

Open Graph Ingestion Flow #643

merged 16 commits into from
May 30, 2017

Conversation

diegoquinteiro
Copy link
Collaborator

@diegoquinteiro diegoquinteiro commented Mar 16, 2017

This PR is a clean/rebased version of #548

  • Creates a new Ingestion flow for instant articles
  • Simplifies the configuration on the WordPress plugin, since only page ID is needed
  • Removed the configuration wizard, since the new ingestion flow covers all features we had on the API

Copy link
Collaborator

@everton-rosario everton-rosario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What an amazing cleanup!
Just mind the small observations I've made thru this diff.

@@ -342,20 +334,47 @@ function inject_url_claiming_meta_tag() {
$publishing_settings = Instant_Articles_Option_Publishing::get_option_decoded();
$fb_page_settings = Instant_Articles_Option_FB_Page::get_option_decoded();

if ( isset( $fb_page_settings['page_id'] ) ) {
if ( isset( $fb_page_settings[ 'page_id' ] ) ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch 💅

?>
<meta property="fb:pages" content="<?php echo esc_attr( $fb_page_settings['page_id'] ); ?>" />
<meta property="fb:pages" content="<?php echo esc_attr( $fb_page_settings[ 'page_id' ] ); ?>" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch 💅

// Transform the post to an Instant Article.
$adapter = new Instant_Articles_Post( $post );
$url = $adapter->get_canonical_url();
$url = add_query_arg( 'op', '1', $url );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we removed the op: ("Open publisher") thing. Shouldn't we change this op=1 thing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will replace "op" by "ia_markup"

<meta property="ia:markup_url" content="<?php echo esc_attr( $url ); ?>" />
<?php
}
add_action( 'wp_head', 'inject_op_markup_meta_tag' );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing about "op" usage. Maybe we should drop this OP from everywhere.

function op_markup_version( ) {
$post = get_post();

if (isset($_GET['op']) && $_GET['op']) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 things:

  • Formating nit, should be if ( isset( $_GET[ 'op' ] ) && $_GET[ 'op' ] ) {
  • Same thing about "op" usage. Maybe we should drop this OP from everywhere.

// Transform the post to an Instant Article.
$adapter = new Instant_Articles_Post( $post );
$article = $adapter->to_instant_article();
echo $article->render(null, true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💅
echo $article->render( null, true );

die();
}
}
add_action( 'wp', 'op_markup_version' );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing about "op" usage. Maybe we should drop this OP from everywhere.

@@ -1,135 +0,0 @@
function instant_articles_wizard_load ( data ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good code cleanup! 👍

@@ -73,6 +73,7 @@ public function testTransformerLikeWPContent()

$this->assertEquals($expected, $result);
// there must be 3 warnings related to <img> inside <li> that is not supported by IA
// And 1 warning related to the getter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this comment should be added?
If there are 3 related to img + 1, the test assertion should be 4.
I guess this came from some dirty merge.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense =) I'll remove it.

@diegoquinteiro diegoquinteiro changed the title Og ingestion flow Open Graph Ingestion Flow Mar 16, 2017
@diegoquinteiro diegoquinteiro force-pushed the og_ingestion_flow branch 2 times, most recently from dec8fdd to cd9b2ce Compare March 16, 2017 16:52
Copy link
Collaborator

@everton-rosario everton-rosario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Burning code!

Copy link
Contributor

@sakatam sakatam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Great work, @diegoquinteiro!

Copy link
Collaborator

@everton-rosario everton-rosario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just rebase before landing

everton-rosario and others added 12 commits May 29, 2017 17:26
This ingestion flow takes in consideration how is the current status of the setup.

 If setup is already complete on API, it means a migration,
   set the configuration as API and the flow goes that way
 otherwise
   set the configuration as Open Graph and flow goes this way
 - [x] Edit doesn't erase content
 - [x] Fixed issue on Advanced Settings
 - [x] Removed extra code
* Removed the wizard
* Added a page_id field on the settings
* Removed unused pages, javascripts and templates
@diegoquinteiro diegoquinteiro changed the base branch from master to v4.0 May 29, 2017 20:38
Copy link
Collaborator Author

@diegoquinteiro diegoquinteiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We (I and @vkama) agreed to merge it to v4.0 then fix the issues on a new PR.

</b>
</p>
<hr>
<?php elseif ( ! $should_submit_post ) : ?>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this variable

</b>
</p>
<hr>
<?php elseif ( ! $article->getHeader() || ! $article->getHeader()->getTitle() ) : ?>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to a warning on the SDK

<p>
<b>
<span class="dashicons dashicons-no-alt"></span>
This post will not be submitted to Instant Articles because it is missings content.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo (missings)

</b>
</p>
<hr>
<?php elseif ( count( $article->getChildren() ) === 0 ) : ?>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to a warning on the SDK

@vkama vkama self-requested a review May 30, 2017 11:49
Copy link
Collaborator

@vkama vkama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice work! Excited to see such a huge clean up and improved user experience through not having to deal with tokens and other stuff!

Great job!

@@ -102,7 +102,7 @@ function instant_articles_activate() {
add_action( 'network_admin_notices', 'instant_articles_setup_admin_notice' ); // also show message on multisite
function instant_articles_setup_admin_notice() {
global $pagenow;
if ( $pagenow === 'plugins.php' && Instant_Articles_Wizard_State::get_current_state() !== Instant_Articles_Wizard_State::STATE_REVIEW_SUBMISSION ) {
if ( $pagenow === 'plugins.php' && ! Instant_Articles_Option_FB_Page::get_option_decoded()[ "page_id" ] ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this possibly throw a warning if no 'page_id' is set? Also, maybe using single quotes.

@@ -96,7 +96,7 @@ public static function render_meta_box() {
$published = ( 'publish' === $post->post_status );
$dev_mode = false;
$force_submit = get_post_meta( $post_id, IA_PLUGIN_FORCE_SUBMIT_KEY, true );
$should_submit_post = apply_filters( 'instant_articles_should_submit_post', true, $adapter );
$instant_articles_should_submit_post_filter = apply_filters( 'instant_articles_should_submit_post', true, $adapter );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am seeing this a lot in the code (lines 92 to 99), maybe we should think of a better solution so this boilerplate gets reused? Good for now, but lets aim for this refactor.

60
);
foreach ( $old_slugs as $slug ) {
$clone_post = clone $post;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this clonning really be inside the foreach? since only the post name is getting changed, maybe you can clone it once, outside, if at all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, I'll create a PR for improving the performance here

$old_slugs = get_post_meta( $post_id, '_wp_old_slug' );
if ( $adapter->should_submit_post() ) {
try {
$client = Facebook\HttpClients\HttpClientsFactory::createHttpClient( null );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this now the only time we use the graph-sdk? if so, maybe we should consider either using builtin functions for a simple post or actually copying the class and dropping it as a dep?

@@ -404,4 +404,44 @@ function ia_markup_version( ) {
add_action( 'wp', 'ia_markup_version' );

Instant_Articles_Wizard::init();

function rescrape_article( $post_id, $post ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the $post_id required? isnt that the same as $post->ID?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not required, but these are the parameters passed to the hook by WordPress.

@diegoquinteiro diegoquinteiro merged commit 39dc2d1 into v4.0 May 30, 2017
@diegoquinteiro diegoquinteiro deleted the og_ingestion_flow branch May 30, 2017 12:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants