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

Fix a few minor code issues #149

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 1 addition & 9 deletions assets/js/src/simple-page-ordering.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ function update_simple_ordering_callback(response) {
nextid: changes.next.nextid,
start: changes.next.start,
_wpnonce: window.simple_page_ordering_localized_data._wpnonce,
screen_id: window.simple_page_ordering_localized_data.screen_id,
excluded: JSON.stringify(changes.next.excluded),
},
update_simple_ordering_callback,
Expand Down Expand Up @@ -158,7 +157,6 @@ sortable_post_table.sortable({
previd: prevpostid,
nextid: nextpostid,
_wpnonce: window.simple_page_ordering_localized_data._wpnonce,
screen_id: window.simple_page_ordering_localized_data.screen_id,
},
update_simple_ordering_callback,
);
Expand All @@ -183,20 +181,14 @@ jQuery(function () {
const post_type = jQuery(this).data('posttype');
if (
// eslint-disable-next-line no-alert
window.confirm(
window.simple_page_ordering_localized_data.confirmation_msg.replace(
`{post_type}`,
post_type,
),
)
window.confirm(window.simple_page_ordering_localized_data.confirmation_msg)
) {
jQuery.post(
window.ajaxurl,
{
action: 'reset_simple_page_ordering',
post_type,
_wpnonce: window.simple_page_ordering_localized_data._wpnonce,
screen_id: window.simple_page_ordering_localized_data.screen_id,
},
function () {
window.location.reload();
Expand Down
19 changes: 12 additions & 7 deletions simple-page-ordering.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ public static function load_edit_screen() {
* when we load up our posts query, if we're actually sorting by menu order, initialize sorting scripts
*/
public static function wp() {
$orderby = get_query_var( 'orderby' );
$screen = get_current_screen();
$orderby = get_query_var( 'orderby' );
$screen = get_current_screen();
$post_type = $screen->post_type ?? 'post';

if ( ( is_string( $orderby ) && 0 === strpos( $orderby, 'menu_order' ) ) || ( isset( $orderby['menu_order'] ) && 'ASC' === $orderby['menu_order'] ) ) {

$script_name = 'dist/js/simple-page-ordering.js';
Expand All @@ -141,7 +143,8 @@ public static function wp() {
'simple_page_ordering_localized_data',
array(
'_wpnonce' => wp_create_nonce( 'simple-page-ordering-nonce' ),
'confirmation_msg' => __( 'Are you sure you want to reset the ordering of the "{post_type}" post type?', 'simple-page-ordering' ),
/* translators: %1$s is replaced with the post type name */
'confirmation_msg' => sprintf( esc_html__( 'Are you sure you want to reset the ordering of the "%1$s" post type?', 'simple-page-ordering' ), $post_type ),
)
);

Expand All @@ -165,17 +168,19 @@ function () {
* Add page ordering help to the help tab
*/
public static function admin_head() {
$reset_order = sprintf( '<a href="#" id="simple-page-ordering-reset" data-posttype="%s">%s</a>', get_query_var( 'post_type' ), __( 'Reset post order', 'simple-page-ordering' ) );
$screen = get_current_screen();
$screen = get_current_screen();
$post_type = $screen->post_type ?? 'post';

$screen->add_help_tab(
array(
'id' => 'simple_page_ordering_help_tab',
'title' => esc_html__( 'Simple Page Ordering', 'simple-page-ordering' ),
'content' => sprintf(
'<p>%s</p><a href="#" id="simple-page-ordering-reset" data-posttype="%s">%s</a>',
esc_html__( 'To reposition an item, simply drag and drop the row by "clicking and holding" it anywhere (outside of the links and form controls) and moving it to its new position.', 'simple-page-ordering' ),
get_query_var( 'post_type' ),
esc_html__( 'Reset post order', 'simple-page-ordering' )
esc_attr( get_query_var( 'post_type' ) ),
/* translators: %1$s is replaced with the post type name */
sprintf( esc_html__( 'Reset %1$s order', 'simple-page-ordering' ), $post_type )
),
)
);
Expand Down