Add new sharing's variables #5404
Add new sharing's variables #5404yogasukma wants to merge 8 commits intoAutomattic:masterfrom yogasukma:add/sharing-variables
Conversation
| $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 ); |
There was a problem hiding this comment.
I'd recommend using home_url() instead. site_url() returns the location of the WordPress files, not necessarily the site's home page.
modules/sharedaddy/sharing.php
Outdated
| <?php foreach ( $enabled['hidden'] as $id => $service ) { | ||
| $this->output_preview( $service ); | ||
| }?> | ||
| }?> |
There was a problem hiding this comment.
This indentation doesn't seem correct.
modules/sharedaddy/sharing.php
Outdated
| <?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; ?> |
|
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. |
|
Thank you!
I checked manually. |
zinigor
left a comment
There was a problem hiding this comment.
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 .= '&' . $query; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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' ); |
There was a problem hiding this comment.
Newline after curly brace please.
| wp_safe_redirect( get_permalink( $post->ID ).'?shared=email' ); | ||
|
|
||
| die(); | ||
| } else { $error = 2; // Email check failed |
There was a problem hiding this comment.
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);";} ?> |
There was a problem hiding this comment.
It's going to look better if that condition is split into three lines, don't you think?
modules/sharedaddy/sharing.php
Outdated
| </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> |
There was a problem hiding this comment.
Same here, let's split the condition into several lines.
modules/sharedaddy/sharing.php
Outdated
| </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> |
There was a problem hiding this comment.
Condition into multiple lines please.
There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
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 : '' ?>
modules/sharedaddy/sharing.php
Outdated
| <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> |
There was a problem hiding this comment.
Same here, multiple lines for each conditional please.
There was a problem hiding this comment.
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
modules/sharedaddy/sharing.php
Outdated
| $label = $post_type_object->labels->name; | ||
| } | ||
| ?> | ||
| <?php if ( $br ) { echo '<br />';} ?> |
There was a problem hiding this comment.
Multiple lines for the conditional please.
|
Ok will check it |
|
Removed from milestone until style updates are done |
|
@zinigor all code style feedback has been applied |
| $url .= '?' . $query; | ||
| } else { $url .= '&' . $query; | ||
| } else { | ||
| $url .= '&' . $query; |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
We should use tabs instead of spaces here.
| die(); | ||
| } else { $error = 2; // Email check failed | ||
| } else { | ||
| $error = 2; // Email check failed |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
Same here. Tabs instead of spaces.
| $this->smart = true; | ||
| } else { $this->smart = false; | ||
| } else { | ||
| $this->smart = false; |
| $this->smart = true; | ||
| } else { $this->smart = false; | ||
| } else { | ||
| $this->smart = false; |
| s.type = "text/javascript"; | ||
| s.async = true; | ||
| <?php if ( $jetpack_pinit_over ) { echo "s.setAttribute('data-pin-hover', true);";} ?> | ||
| <?php if ( $jetpack_pinit_over ) { |
There was a problem hiding this comment.
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; |
| </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> |
| } | ||
| ?> | ||
| <?php if ( $br ) { echo '<br />';} ?> | ||
| <?php |
Fixes #5184
Changes proposed in this Pull Request:
Adding new 3 variables for sharing purposes.
Testing instructions:
Screenshot when adding new services. notice all new variable are listed there.

cc @jeherve