Skip to content

Add new sharing's variables #5404

Closed
yogasukma wants to merge 8 commits intoAutomattic:masterfrom
yogasukma:add/sharing-variables
Closed

Add new sharing's variables #5404
yogasukma wants to merge 8 commits intoAutomattic:masterfrom
yogasukma:add/sharing-variables

Conversation

@yogasukma
Copy link
Copy Markdown
Contributor

@yogasukma yogasukma commented Oct 24, 2016

Fixes #5184

Changes proposed in this Pull Request:

Adding new 3 variables for sharing purposes.

  1. %post_id% for getting post id
  2. %site_url% for getting root url
  3. %post_slug% for getting slug

Testing instructions:

  1. enable sharing modules.
  2. go to settings > sharings.
  3. click on "add new services"
  4. insert the custom format like %site_url%/read_offline/%post_slug% to get something like http://example.com/read_offline/hello-world

Screenshot when adding new services. notice all new variable are listed there.
screen shot 2016-10-24 at 9 39 33 pm

cc @jeherve

$url = str_replace( '%post_url%', rawurlencode( $this->get_share_url( $post->ID ) ), $url );
$url = str_replace( '%post_full_url%', rawurlencode( get_permalink( $post->ID ) ), $url );
$url = str_replace( '%post_title%', rawurlencode( $this->get_share_title( $post->ID ) ), $url );
$url = str_replace( '%site_url%', rawurlencode( site_url() ), $url );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd recommend using home_url() instead. site_url() returns the location of the WordPress files, not necessarily the site's home page.

<?php foreach ( $enabled['hidden'] as $id => $service ) {
$this->output_preview( $service );
}?>
}?>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This indentation doesn't seem correct.

<?php $br = true; endforeach; ?>
<?php if ( $br ) { echo '<br />';} ?><label><input type="checkbox"<?php checked( in_array( $show, $global['show'] ) ); ?> name="show[]" value="<?php echo esc_attr( $show ); ?>" /> <?php echo esc_html( $label ); ?></label>
<?php $br = true;
endforeach; ?>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Indentation seems off here.

@jeherve jeherve added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] Sharing Post sharing, sharing buttons [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Status] In Progress labels Oct 25, 2016
@jeherve jeherve added this to the 4.4 milestone Oct 25, 2016
@yogasukma
Copy link
Copy Markdown
Contributor Author

Ok @jeherve i changed to home_url rather than site_url and fixing indentation issues.

btw, how do you know and found for indentation issue? do you just manually quick read the code, or there is a tool for that?

I used phpcbf for fixing non wordpress standard code, and i thought it fixed the indentation too, but still some place need manual work to fix the indent.

@jeherve
Copy link
Copy Markdown
Member

jeherve commented Oct 25, 2016

Thank you!

btw, how do you know and found for indentation issue? do you just manually quick read the code, or there is a tool for that?

I checked manually.

@jeherve jeherve added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Oct 25, 2016
Copy link
Copy Markdown
Contributor

@zinigor zinigor left a comment

Choose a reason for hiding this comment

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

Tested the changes, everything works as expected, but I have added some minor code style comments. Can you please fix them so we can merge?
Thank you!

if ( ! empty( $query ) ) {
if ( false === stripos( $url, '?' ) ) {
$url .= '?' . $query;
} else { $url .= '&amp;' . $query;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor style issue: please carry the statement to the next line as with the first block.

$this->smart = true;
else
$this->smart = false;
} else { $this->smart = false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same thing as the previous else statement please: new line after curly brace.

<div class="response-title"><?php _e( 'This post has been shared!', 'jetpack' ); ?></div>
<div class="response-sub"><?php printf( __( 'You have shared this post with %s', 'jetpack' ), esc_html( $target_email ) ); ?></div>
<div class="response-close"><a href="#" class="sharing_cancel"><?php _e( 'Close', 'jetpack' ); ?></a></div>
<div class="response-sub"><?php printf( __( 'You have shared this post with %s', 'jetpack' ), esc_html( $target_email ) ); ?></div>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we're fixing indentation here, let's align these div elements on the same level because they are siblings.

<div class="response-close"><a href="#" class="sharing_cancel"><?php _e( 'Close', 'jetpack' ); ?></a></div>
</div>
<?php
} else { wp_safe_redirect( get_permalink( $post->ID ) . '?shared=email' );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Newline after curly brace please.

wp_safe_redirect( get_permalink( $post->ID ).'?shared=email' );

die();
} else { $error = 2; // Email check failed
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Newline after curly brace please.

s.type = "text/javascript";
s.async = true;
<?php if ( $jetpack_pinit_over ) echo "s.setAttribute('data-pin-hover', true);"; ?>
<?php if ( $jetpack_pinit_over ) { echo "s.setAttribute('data-pin-hover', true);";} ?>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's going to look better if that condition is split into three lines, don't you think?

</td>
<td class="services" id="share-drop-target">
<h2 id="drag-instructions" <?php if ( count( $enabled['visible'] ) > 0 ) echo ' style="display: none"'; ?>><?php _e( 'Drag and drop available services here.', 'jetpack' ); ?></h2>
<h2 id="drag-instructions" <?php if ( count( $enabled['visible'] ) > 0 ) { echo ' style="display: none"';} ?>><?php _e( 'Drag and drop available services here.', 'jetpack' ); ?></h2>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here, let's split the condition into several lines.

</td>
<td class="services">
<h2<?php if ( count( $enabled['all'] ) > 0 ) echo ' style="display: none"'; ?>><?php _e( 'Sharing is off. Add services above to enable.', 'jetpack' ); ?></h2>
<h2<?php if ( count( $enabled['all'] ) > 0 ) { echo ' style="display: none"';} ?>><?php _e( 'Sharing is off. Add services above to enable.', 'jetpack' ); ?></h2>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Condition into multiple lines please.

Copy link
Copy Markdown
Contributor Author

@yogasukma yogasukma Nov 9, 2016

Choose a reason for hiding this comment

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

@zinigor i think multiple line condition are not work here, since it will looks little mess. The context of condition are inside tag parameter. it will looks like this

`<h2

0 ) { echo ' style="display: none"'; } ?>>`

do you think it's ok?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fair enough, let's convert it all into ternary operators, what do you say? Like this:

$selected = 'selected="selected"';
$hidden = ' style="display: none"'; ?>
...
<h2 <?php echo count( $enabled['all'] ) > 0 ? $hidden : '' ?>
...
<option<?php echo 'icon-text' === $global['button_style']' ? $selected : '' ?>

<option<?php if ( $global['button_style'] == 'icon' ) echo ' selected="selected"';?> value="icon"><?php _e( 'Icon only', 'jetpack' ); ?></option>
<option<?php if ( $global['button_style'] == 'text' ) echo ' selected="selected"';?> value="text"><?php _e( 'Text only', 'jetpack' ); ?></option>
<option<?php if ( $global['button_style'] == 'official' ) echo ' selected="selected"';?> value="official"><?php _e( 'Official buttons', 'jetpack' ); ?></option>
<option<?php if ( $global['button_style'] == 'icon-text' ) { echo ' selected="selected"';}?> value="icon-text"><?php _e( 'Icon + text', 'jetpack' ); ?></option>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here, multiple lines for each conditional please.

Copy link
Copy Markdown
Contributor Author

@yogasukma yogasukma Nov 9, 2016

Choose a reason for hiding this comment

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

same as above, in this context, one liner conditional makes it easy to read, this is a gist when it converted into multiple lines https://gist.github.com/ysupr/c02065f3af3069ea3ee11212485bfe94 what do you think @zinigor

$label = $post_type_object->labels->name;
}
?>
<?php if ( $br ) { echo '<br />';} ?>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Multiple lines for the conditional please.

@yogasukma
Copy link
Copy Markdown
Contributor Author

yogasukma commented Nov 9, 2016

Ok will check it

@samhotchkiss samhotchkiss modified the milestones: Not Currently Planned, 4.4 Nov 9, 2016
@samhotchkiss
Copy link
Copy Markdown
Contributor

Removed from milestone until style updates are done

@jeherve jeherve added [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Nov 9, 2016
@yogasukma
Copy link
Copy Markdown
Contributor Author

@zinigor all code style feedback has been applied

@samhotchkiss samhotchkiss added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Nov 11, 2016
@samhotchkiss samhotchkiss removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Nov 11, 2016
@samhotchkiss samhotchkiss modified the milestones: 4.5, Not Currently Planned Nov 11, 2016
Copy link
Copy Markdown
Contributor

@ebinnion ebinnion left a comment

Choose a reason for hiding this comment

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

Throughout the file, there are now several places where the code is using spaces instead of tabs for indentation.

Would you mind fixing these @ysupr before me merge?

$url .= '?' . $query;
} else { $url .= '&amp;' . $query;
} else {
$url .= '&amp;' . $query;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We're using spaces instead of tabs here, so the formatting looks off.

<div class="response-title"><?php _e( 'This post has been shared!', 'jetpack' ); ?></div>
<div class="response-sub"><?php printf( __( 'You have shared this post with %s', 'jetpack' ), esc_html( $target_email ) ); ?></div>
<div class="response-close"><a href="#" class="sharing_cancel"><?php _e( 'Close', 'jetpack' ); ?></a></div>
<div class="response-sub"><?php printf( __( 'You have shared this post with %s', 'jetpack' ), esc_html( $target_email ) ); ?></div>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should use tabs instead of spaces here.

die();
} else { $error = 2; // Email check failed
} else {
$error = 2; // Email check failed
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's us tabes instead of spaces here.

<div class="response-sub"><?php printf( __( 'You have shared this post with %s', 'jetpack' ), esc_html( $target_email ) ); ?></div>
<div class="response-close"><a href="#" class="sharing_cancel"><?php _e( 'Close', 'jetpack' ); ?></a></div>
<div class="response-sub"><?php printf( __( 'You have shared this post with %s', 'jetpack' ), esc_html( $target_email ) ); ?></div>
<div class="response-close"><a href="#" class="sharing_cancel"><?php _e( 'Close', 'jetpack' ); ?></a></div>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here. Tabs instead of spaces.

$this->smart = true;
} else { $this->smart = false;
} else {
$this->smart = false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tabs instead of spaces.

$this->smart = true;
} else { $this->smart = false;
} else {
$this->smart = false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tabs instead of spaces.

s.type = "text/javascript";
s.async = true;
<?php if ( $jetpack_pinit_over ) { echo "s.setAttribute('data-pin-hover', true);";} ?>
<?php if ( $jetpack_pinit_over ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tabs instead of spaces.

Also, I believe the echo should be indented once more than the conditional.

Lastly, I prefer the following style, although yours works just as well.

<?php if ( $jetpack_pinit_over ):  
	echo "s.setAttribute('data-pin-hover', true);";
endif; ?>

$this->smart = true;
} else { $this->smart = false;
} else {
$this->smart = false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tabs instead of spaces.

</td>
<td class="services" id="share-drop-target">
<h2 id="drag-instructions" <?php if ( count( $enabled['visible'] ) > 0 ) { echo ' style="display: none"';} ?>><?php _e( 'Drag and drop available services here.', 'jetpack' ); ?></h2>
<h2 id="drag-instructions" <?php if ( count( $enabled['visible'] ) > 0 ) { echo ' style="display: none"';} ?>><?php _e( 'Drag and drop available services here.', 'jetpack' ); ?></h2>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tabs instead of spaces.

}
?>
<?php if ( $br ) { echo '<br />';} ?>
<?php
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tabs instead of spaces.

@samhotchkiss
Copy link
Copy Markdown
Contributor

Merged in #5832

Thanks @ysupr !

@samhotchkiss samhotchkiss removed the [Status] Needs Review This PR is ready for review. label Dec 8, 2016
@yogasukma yogasukma deleted the add/sharing-variables branch January 18, 2017 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] Sharing Post sharing, sharing buttons

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants