From ae511d2efa6a0188019e85bd451201a507a4a38a Mon Sep 17 00:00:00 2001 From: Erick Hitter <services@ethitter.com> Date: Sun, 20 Mar 2016 20:55:52 -0700 Subject: [PATCH] Improve how shortlink popup is added for row actions, allowing it to work for non-JS too. --- eth-simple-shortlinks.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/eth-simple-shortlinks.php b/eth-simple-shortlinks.php index 5da7a3d..24c3244 100644 --- a/eth-simple-shortlinks.php +++ b/eth-simple-shortlinks.php @@ -71,6 +71,7 @@ class ETH_Simple_Shortlinks { // Shortlink add_filter( 'get_shortlink', array( $this, 'filter_get_shortlink' ), 10, 2 ); + add_action( 'admin_head-edit.php', array( $this, 'add_admin_header_assets' ) ); add_filter( 'post_row_actions', array( $this, 'filter_row_actions' ), 10, 2 ); add_filter( 'page_row_actions', array( $this, 'filter_row_actions' ), 10, 2 ); } @@ -144,6 +145,29 @@ class ETH_Simple_Shortlinks { return $this->get_shortlink( $id ); } + /** + * Header assets for shortlink in row actions + */ + public function add_admin_header_assets() { + global $typenow; + if ( ! in_array( $typenow, $this->supported_post_types ) ) { + return; + } + + ?> + <script type="text/javascript"> + + jQuery( document ) .ready( function( $ ) { + $( '.row-actions .shortlink a' ).click( function( e ) { + e.preventDefault(); + + prompt( 'URL:', $( this ).attr('href') ); + } ); + } ); + </script> + <?php + } + /** * Provide the shortlink in row actions for easy access */ @@ -152,7 +176,7 @@ class ETH_Simple_Shortlinks { return $actions; } - $actions['shortlink'] = '<a style="cursor: pointer;" onclick="prompt( \'URL:\', \'' . esc_js( $this->get_shortlink( $post->ID ) ) . '\' );return false;">Shortlink</a>'; + $actions['shortlink'] = '<a href="' . esc_js( $this->get_shortlink( $post->ID ) ) . '">Shortlink</a>'; return $actions; } -- GitLab