Press This: Backwards compatibility enhancements.

* Add missing actions for printing styles/scripts.
* Since `$hook_suffix` is null, hardcode `press-this.php`.
* Restore body classes, add filter.
* Use boolean value instead of `__return_false()`.
* Use `wp_json_encode()`.
* Update docs for filters in script-loader.php.
* Make `<a href="%1$s">%2$s</a>` not translatable.

see #31373.

git-svn-id: https://develop.svn.wordpress.org/trunk@31588 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90) 2015-02-28 10:35:27 +00:00
parent d258490653
commit 91694337df
2 changed files with 41 additions and 21 deletions

View File

@ -52,7 +52,7 @@ class WP_Press_This {
* *
* @param bool $redir_in_parent Whether to redirect in parent window or not. Default false. * @param bool $redir_in_parent Whether to redirect in parent window or not. Default false.
*/ */
'redir_in_parent' => apply_filters( 'press_this_redirect_in_parent', __return_false() ), 'redir_in_parent' => apply_filters( 'press_this_redirect_in_parent', false ),
); );
} }
@ -377,7 +377,7 @@ class WP_Press_This {
$data['_meta'] = array(); $data['_meta'] = array();
} }
if ( preg_match_all( '/<meta ([^>]+)[\s]?\/?>/ ', $source_content, $matches ) ) { if ( preg_match_all( '/<meta ([^>]+)[\s]?\/?>/', $source_content, $matches ) ) {
if ( ! empty( $matches[0] ) ) { if ( ! empty( $matches[0] ) ) {
foreach ( $matches[0] as $key => $value ) { foreach ( $matches[0] as $key => $value ) {
if ( preg_match( '/<meta[^>]+(property|name)="(.+)"[^>]+content="(.+)"/', $value, $new_matches ) ) { if ( preg_match( '/<meta[^>]+(property|name)="(.+)"[^>]+content="(.+)"/', $value, $new_matches ) ) {
@ -665,7 +665,7 @@ class WP_Press_This {
* @access public * @access public
*/ */
public function html() { public function html() {
global $wp_locale, $hook_suffix; global $wp_locale, $wp_version;
// Get data, new (POST) and old (GET). // Get data, new (POST) and old (GET).
$data = $this->merge_or_fetch_data(); $data = $this->merge_or_fetch_data();
@ -698,8 +698,8 @@ class WP_Press_This {
<title><?php esc_html_e( 'Press This!' ) ?></title> <title><?php esc_html_e( 'Press This!' ) ?></title>
<script> <script>
window.wpPressThisData = <?php echo json_encode( $data ) ?>; window.wpPressThisData = <?php echo wp_json_encode( $data ) ?>;
window.wpPressThisConfig = <?php echo json_encode( $site_settings ) ?>; window.wpPressThisConfig = <?php echo wp_json_encode( $site_settings ) ?>;
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
@ -709,7 +709,7 @@ class WP_Press_This {
adminpage = 'press-this-php', adminpage = 'press-this-php',
thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>', thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>', decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
isRtl = <?php echo esc_js( (int) is_rtl() ); ?>; isRtl = <?php echo (int) is_rtl(); ?>;
</script> </script>
<?php <?php
@ -738,17 +738,39 @@ class WP_Press_This {
} }
/** This action is documented in wp-admin/admin-header.php */ /** This action is documented in wp-admin/admin-header.php */
do_action( 'admin_enqueue_scripts', $hook_suffix ); do_action( 'admin_enqueue_scripts', 'press-this.php' );
/** This action is documented in wp-admin/admin-header.php */
do_action( 'admin_print_styles-press-this.php' );
/** This action is documented in wp-admin/admin-header.php */ /** This action is documented in wp-admin/admin-header.php */
do_action( 'admin_print_styles' ); do_action( 'admin_print_styles' );
/** This action is documented in wp-admin/admin-header.php */
do_action( 'admin_print_scripts-press-this.php' );
/** This action is documented in wp-admin/admin-header.php */ /** This action is documented in wp-admin/admin-header.php */
do_action( 'admin_print_scripts' ); do_action( 'admin_print_scripts' );
/** This action is documented in wp-admin/admin-header.php */
do_action( 'admin_head-press-this.php' );
/** This action is documented in wp-admin/admin-header.php */
do_action( 'admin_head' );
?> ?>
</head> </head>
<body> <?php
$admin_body_class = 'press-this';
$admin_body_class .= ( is_rtl() ) ? ' rtl' : '';
$admin_body_class .= ' branch-' . str_replace( array( '.', ',' ), '-', floatval( $wp_version ) );
$admin_body_class .= ' version-' . str_replace( '.', '-', preg_replace( '/^([.0-9]+).*/', '$1', $wp_version ) );
$admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
/** This filter is documented in wp-admin/admin-header.php */
$admin_body_classes = apply_filters( 'admin_body_class', '' );
?>
<body class="wp-admin wp-core-ui <?php echo $admin_body_classes . ' ' . $admin_body_class; ?>">
<div id="adminbar" class="adminbar"> <div id="adminbar" class="adminbar">
<h1 id="current-site" class="current-site"> <h1 id="current-site" class="current-site">
<span class="dashicons dashicons-wordpress"></span> <span class="dashicons dashicons-wordpress"></span>
@ -894,8 +916,12 @@ class WP_Press_This {
<?php <?php
/** This action is documented in wp-admin/admin-footer.php */ /** This action is documented in wp-admin/admin-footer.php */
do_action( 'admin_footer' ); do_action( 'admin_footer' );
/** This action is documented in wp-admin/admin-footer.php */ /** This action is documented in wp-admin/admin-footer.php */
do_action( 'admin_print_footer_scripts' ); do_action( 'admin_print_footer_scripts' );
/** This action is documented in wp-admin/admin-footer.php */
do_action( 'admin_footer-press-this.php' );
?> ?>
</body> </body>
</html> </html>

View File

@ -473,28 +473,22 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'press-this', "/wp-admin/js/press-this$suffix.js", array( 'jquery', 'tags-box' ), false, 1 ); $scripts->add( 'press-this', "/wp-admin/js/press-this$suffix.js", array( 'jquery', 'tags-box' ), false, 1 );
did_action( 'init' ) && $scripts->localize( 'press-this', 'pressThisL10n', array( did_action( 'init' ) && $scripts->localize( 'press-this', 'pressThisL10n', array(
/** /**
* press_this_source_string: string displayed before the source attribution string, defaults to "Source:". * Filter the string displayed before the source attribution string in Press This.
* *
* @since 4.2 * @since 4.2.0
* @see https://github.com/MichaelArestad/Press-This/issues/25
* *
* @param string $string Internationalized source string * @param string $string Internationalized source string.
*
* @return string Source string
*/ */
'source' => apply_filters( 'press_this_source_string', __( 'Source:' ) ), 'source' => apply_filters( 'press_this_source_string', __( 'Source:' ) ),
/** /**
* press_this_source_link: HTML link format for the source attribution, can control target, class, etc * Filter the HTML link format for the Press This source attribution, can control target, class, etc.
* *
* @since 4.2 * @since 4.2.0
* @see https://github.com/MichaelArestad/Press-This/issues/25
* *
* @param string $link_format Internationalized link format, %1$s is link href, %2$s is link text * @param string $link_format Link format, %1$s is link href, %2$s is link text.
*
* @return string Link markup
*/ */
'sourceLink' => apply_filters( 'press_this_source_link', __( '<a href="%1$s">%2$s</a>' ) ), 'sourceLink' => apply_filters( 'press_this_source_link', '<a href="%1$s">%2$s</a>' ),
'newPost' => __( 'Title' ), 'newPost' => __( 'Title' ),
'unexpectedError' => __( 'Sorry, but an unexpected error occurred.' ), 'unexpectedError' => __( 'Sorry, but an unexpected error occurred.' ),
'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ),