Skip to content

Commit

Permalink
Merge pull request #350 from 10up/feat/issue-98
Browse files Browse the repository at this point in the history
Quick Edit and Bulk edit
  • Loading branch information
jeffpaul committed Jul 9, 2024
2 parents 5f0ca06 + f1926de commit 0980ab8
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 20 deletions.
4 changes: 3 additions & 1 deletion assets/css/redirect.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@
padding: 8px 16px;
}


.margin-top-0 {
margin-top: 0 !important;
}
11 changes: 11 additions & 0 deletions assets/js/bulk-select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(function ($) {
$('[id^="cb-select-all-"]').on('click', function () {
var isChecked = $(this).prop('checked');

// Check or uncheck all row checkboxes.
$('tbody .check-column input[type="checkbox"]').prop('checked', isChecked);

// Synchronize all the bulk select checkboxes.
$('[id^="cb-select-all-"]').prop('checked', isChecked);
});
}(jQuery));
28 changes: 28 additions & 0 deletions assets/js/quick-bulk-edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
( function ($) {
$( function () {
const wpInlineEditor = inlineEditPost.edit;

inlineEditPost.edit = function (id) {

wpInlineEditor.apply(this, arguments);

var postId = 0;
if (typeof (id) === 'object') {
postId = parseInt(this.getId(id));
}

if (postId != 0) {
var editRow = $('#edit-' + postId);
var postRow = $('#post-' + postId);

var statusCode = $('.srm_redirect_rule_status_code', postRow).text();
var forceHttps = $('.srm_redirect_rule_force_https', postRow).text();

$('select[name="srm_redirect_rule_status_code"]', editRow).val(statusCode);
if ('x' !== forceHttps) {
$('input[name="srm_redirect_rule_force_https"]', editRow).prop('checked', true);
}
}
}
} );
}(jQuery) );
95 changes: 76 additions & 19 deletions inc/classes/class-srm-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ public function setup() {
add_filter( 'manage_redirect_rule_posts_columns', array( $this, 'filter_redirect_columns' ) );
add_filter( 'manage_edit-redirect_rule_sortable_columns', array( $this, 'filter_redirect_sortable_columns' ) );
add_action( 'manage_redirect_rule_posts_custom_column', array( $this, 'action_custom_redirect_columns' ), 10, 2 );
add_action( 'quick_edit_custom_box', array( $this, 'action_quick_edit_custom_redirect_columns' ), 10, 2 );
add_action( 'bulk_edit_custom_box', array( $this, 'action_quick_edit_custom_redirect_columns' ), 10, 2 );
add_action( 'transition_post_status', array( $this, 'action_transition_post_status' ), 10, 3 );
add_filter( 'post_updated_messages', array( $this, 'filter_redirect_updated_messages' ) );
add_action( 'admin_notices', array( $this, 'action_redirect_chain_alert' ) );
add_filter( 'the_title', array( $this, 'filter_admin_title' ), 100, 2 );
add_filter( 'bulk_actions-edit-redirect_rule', array( $this, 'filter_bulk_actions' ) );
add_action( 'admin_print_styles-edit.php', array( $this, 'action_print_logo_css' ), 10, 1 );
add_action( 'admin_print_styles-post.php', array( $this, 'action_print_logo_css' ), 10, 1 );
add_action( 'admin_print_styles-post-new.php', array( $this, 'action_print_logo_css' ), 10, 1 );
Expand Down Expand Up @@ -108,7 +109,6 @@ public function filter_hidden_columns( $hidden ) {
*/
public function filter_disable_quick_edit( $actions, $post ) {
if ( 'redirect_rule' === get_post_type( $post ) && isset( $actions['inline hide-if-no-js'] ) ) {
unset( $actions['inline hide-if-no-js'] );
unset( $actions['view'] );
}

Expand Down Expand Up @@ -193,21 +193,6 @@ public function action_print_logo_css() {
}
}

/**
* Limit the bulk actions available in the Manage Redirects view
*
* @param array $actions Array of actions
* @since 1.0
* @return array
*/
public function filter_bulk_actions( $actions ) {

// No bulk editing at this time
unset( $actions['edit'] );

return $actions;
}

/**
* Whether or not this is an admin page specific to the plugin
*
Expand Down Expand Up @@ -396,6 +381,8 @@ public function action_custom_redirect_columns( $column, $post_id ) {
echo esc_html( get_post_meta( $post_id, '_redirect_rule_to', true ) );
} elseif ( 'srm_redirect_rule_status_code' === $column ) {
echo absint( get_post_meta( $post_id, '_redirect_rule_status_code', true ) );
} elseif ( 'srm_redirect_rule_force_https' === $column ) {
echo absint( get_post_meta( $post_id, '_force_https', true ) ) ? '✓' : 'x';
} elseif ( 'menu_order' === $column ) {
global $post;
echo esc_html( $post->menu_order );
Expand All @@ -412,6 +399,7 @@ public function action_custom_redirect_columns( $column, $post_id ) {
public function filter_redirect_columns( $columns ) {
$columns['srm_redirect_rule_to'] = esc_html__( 'Redirect To', 'safe-redirect-manager' );
$columns['srm_redirect_rule_status_code'] = esc_html__( 'HTTP Status Code', 'safe-redirect-manager' );
$columns['srm_redirect_rule_force_https'] = esc_html__( 'Force https', 'safe-redirect-manager' );
$columns['menu_order'] = esc_html__( 'Order', 'safe-redirect-manager' );

// Change the title column
Expand All @@ -436,6 +424,56 @@ public function filter_redirect_sortable_columns( $columns ) {
return $columns;
}

/**
* Add custom fileds to the qucik edit screen.
*
* @param string $column_name Name of the column to edit.
* @param string $post_type The post type slug, or current screen name if this is a taxonomy list table.
*
* @return void
*/
public function action_quick_edit_custom_redirect_columns( $column_name, $post_type ) {
if ( 'redirect_rule' !== $post_type ) {
return;
}

if ( 'srm_redirect_rule_status_code' === $column_name ) :
wp_nonce_field( 'srm-save-redirect-ajax-meta', 'srm_redirect_ajax_nonce' );
?>
<fieldset class="inline-edit-col-right margin-top-0">
<div class="inline-edit-col">
<div class="inline-edit-group wp-clearfix">
<label class="inline-edit-status alignleft">
<span class="title"><?php esc_html_e( 'HTTP Status Code', 'safe-redirect-manager' ); ?></span>
<select name="srm_redirect_rule_status_code">
<option value="-1"><?php esc_html_e( '— No Change —', 'safe-redirect-manager' ); ?></option>
<?php foreach ( srm_get_valid_status_codes() as $code ) : ?>
<option value="<?php echo esc_attr( $code ); ?>"><?php echo esc_html( $code . ' ' . $this->status_code_labels[ $code ] ); ?></option>
<?php endforeach; ?>
</select>
</label>
</div>
</div>
</fieldset>
<?php
endif;

if ( 'srm_redirect_rule_force_https' === $column_name ) :
?>
<fieldset class="inline-edit-col-right margin-top-0">
<div class="inline-edit-col">
<div class="inline-edit-group wp-clearfix">
<label class="inline-edit-status alignleft">
<span class="title"><?php esc_html_e( 'Force https', 'safe-redirect-manager' ); ?></span>
<input type="checkbox" name="srm_redirect_rule_force_https" value="1"/>
</label>
</div>
</div>
</fieldset>
<?php
endif;
}

/**
* Saves meta info for redirect rules
*
Expand Down Expand Up @@ -503,6 +541,23 @@ public function action_save_post( $post_id ) {
*/
srm_flush_cache();
}

if ( ! empty( $_REQUEST['srm_redirect_ajax_nonce'] )
&& wp_verify_nonce( $_REQUEST['srm_redirect_ajax_nonce'], 'srm-save-redirect-ajax-meta' )
&& current_user_can( 'edit_post', $post_id )
) {
if ( ! empty( $_REQUEST['srm_redirect_rule_status_code'] ) && '-1' !== $_REQUEST['srm_redirect_rule_status_code'] ) {
update_post_meta( $post_id, '_redirect_rule_status_code', absint( $_REQUEST['srm_redirect_rule_status_code'] ) );
} elseif ( '-1' !== $_REQUEST['srm_redirect_rule_status_code'] ) {
delete_post_meta( $post_id, '_redirect_rule_status_code' );
}

if ( ! empty( $_REQUEST['srm_redirect_rule_force_https'] ) ) {
update_post_meta( $post_id, '_force_https', true );
} else {
delete_post_meta( $post_id, '_force_https' );
}
}
}

/**
Expand Down Expand Up @@ -744,8 +799,10 @@ public static function factory() {
*/
public function load_resources() {
if ( 'redirect_rule' === get_post_type() ) {
wp_enqueue_style( 'redirectjs', plugin_dir_url( 'safe-redirect-manager/safe-redirect-manager.php' ) . 'assets/css/redirect.css', array(), SRM_VERSION );
wp_enqueue_script( 'redirectjs', plugin_dir_url( 'safe-redirect-manager/safe-redirect-manager.php' ) . 'assets/js/redirect.js', array( 'jquery' ), SRM_VERSION );
wp_enqueue_style( 'redirectjs', SRM_PLUGIN_URL . 'assets/css/redirect.css', array(), SRM_VERSION );
wp_enqueue_script( 'bulk-select', SRM_PLUGIN_URL . 'assets/js/bulk-select.js', array( 'jquery' ), SRM_VERSION, true );
wp_enqueue_script( 'redirectjs', SRM_PLUGIN_URL . 'assets/js/redirect.js', array( 'jquery' ), SRM_VERSION );
wp_enqueue_script( 'quick-bulk-editjs', SRM_PLUGIN_URL . 'assets/js/quick-bulk-edit.js', array( 'jquery', 'inline-edit-post' ), SRM_VERSION );
wp_localize_script(
'redirectjs',
'redirectValidation',
Expand Down
2 changes: 2 additions & 0 deletions safe-redirect-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ function() {
require_once dirname( __FILE__ ) . '/inc/classes/class-srm-loop-detection.php';

define( 'SRM_VERSION', '2.1.2' );
define( 'SRM_PLUGIN_FULL_FILE', __FILE__ );
define( 'SRM_PLUGIN_URL', plugin_dir_url( SRM_PLUGIN_FULL_FILE ) );

if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once dirname( __FILE__ ) . '/inc/classes/class-srm-wp-cli.php';
Expand Down

0 comments on commit 0980ab8

Please sign in to comment.