Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick Edit and Bulk edit #350

Merged
merged 21 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6eae772
Quick and Bulk edit
dhanendran Sep 8, 2023
a2845da
Merge branch 'develop' into feat/issue-98
github-actions[bot] Sep 8, 2023
8bc3360
internationalization, using const and strict comparison
dhanendran Sep 14, 2023
1959d09
Merge branch 'develop' into feat/issue-98
github-actions[bot] Oct 27, 2023
a5517e2
Merge branch 'develop' into feat/issue-98
github-actions[bot] Jan 2, 2024
7470b68
Merge branch 'develop' into feat/issue-98
github-actions[bot] Jan 2, 2024
9950049
Merge branch 'develop' into feat/issue-98
github-actions[bot] Jan 2, 2024
309f2dd
Merge branch 'develop' into feat/issue-98
github-actions[bot] Jan 4, 2024
3e18820
Merge branch 'develop' into feat/issue-98
github-actions[bot] Jan 5, 2024
a5a63e6
Merge branch 'develop' into feat/issue-98
github-actions[bot] Jan 8, 2024
67d79f6
Merge branch 'develop' into feat/issue-98
github-actions[bot] Jan 22, 2024
a5c2412
Merge branch 'develop' into feat/issue-98
github-actions[bot] Jan 31, 2024
085220d
Merge branch 'develop' into feat/issue-98
github-actions[bot] Feb 15, 2024
30911e5
Merge branch 'develop' into feat/issue-98
github-actions[bot] Feb 23, 2024
319721f
using string for comparison, plugin uri
dhanendran Jun 14, 2024
71b5e58
Merge branch 'develop' into feat/issue-98
mehul0810 Jun 28, 2024
02b2cdf
add some constants
mehul0810 Jun 28, 2024
00e5e4b
updated paths for scripts
mehul0810 Jun 28, 2024
65fd64d
add bulk select js
mehul0810 Jun 28, 2024
07306c6
removed extra line
mehul0810 Jul 8, 2024
f1926de
fix e2e tests
mehul0810 Jul 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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( 'redirect-css', 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( 'redirect-js', 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
3 changes: 3 additions & 0 deletions safe-redirect-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ 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 ) );

mehul0810 marked this conversation as resolved.
Show resolved Hide resolved

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