Repository navigation
Expand file tree
/
Copy pathsettings.php
More file actions
142 lines (124 loc) · 4.68 KB
/
Copy pathsettings.php
File metadata and controls
142 lines (124 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* Settings page for Simple Custom Post Order plugin.
*
* Uses WordPress Settings API for proper integration with core admin UI.
*
* @package SimpleCustomPostOrder
*/
// Prevent direct access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<div class="wrap">
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<?php settings_errors( 'scporder_options' ); ?>
<form method="post" action="options.php">
<?php
settings_fields( 'scporder_settings' );
do_settings_sections( 'scporder-settings' );
submit_button( __( 'Save Changes', 'simple-custom-post-order' ) );
?>
</form>
<hr />
<h2><?php esc_html_e( 'Reset Post Order', 'simple-custom-post-order' ); ?></h2>
<p><?php esc_html_e( 'Select post types to reset their custom order back to default (by date for posts, alphabetical for pages).', 'simple-custom-post-order' ); ?></p>
<p class="description"><?php esc_html_e( 'This sets the order number of every item of the selected types to 0 — including any values entered under Page Attributes → Order — and turns sorting off for those types. It cannot be undone.', 'simple-custom-post-order' ); ?></p>
<form id="scpo-reset-form">
<table class="form-table" role="presentation">
<tbody>
<tr>
<th scope="row"><?php esc_html_e( 'Post Types to Reset', 'simple-custom-post-order' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php esc_html_e( 'Post Types to Reset', 'simple-custom-post-order' ); ?></span></legend>
<?php
// $this is the SCPO_Engine instance — this file is included from admin_page().
foreach ( $this->resettable_post_types() as $post_type_name ) {
$post_type = get_post_type_object( $post_type_name );
if ( ! $post_type ) {
continue;
}
printf(
'<label><input type="checkbox" name="scpo_reset_types[]" value="%s" /> %s</label><br />',
esc_attr( $post_type->name ),
esc_html( $post_type->label )
);
}
?>
</fieldset>
</td>
</tr>
</tbody>
</table>
<p class="submit">
<button type="submit" id="scpo-reset-button" class="button button-secondary">
<?php esc_html_e( 'Reset Order', 'simple-custom-post-order' ); ?>
</button>
<span id="scpo-reset-message" class="description" style="margin-left: 10px;"></span>
</p>
</form>
<hr />
<h2><?php esc_html_e( 'Support', 'simple-custom-post-order' ); ?></h2>
<p>
<?php
printf(
/* translators: 1: link to reviews, 2: link to Colorlib */
esc_html__( 'Enjoying this plugin? Please %1$s on WordPress.org! For support, visit %2$s.', 'simple-custom-post-order' ),
'<a href="https://wordpress.org/support/plugin/simple-custom-post-order/reviews/" target="_blank" rel="noopener noreferrer">' . esc_html__( 'leave a review', 'simple-custom-post-order' ) . '</a>',
'<a href="https://colorlib.com/" target="_blank" rel="noopener noreferrer">Colorlib.com</a>'
);
?>
</p>
</div>
<script>
(function($) {
'use strict';
$('#scpo-reset-form').on('submit', function(e) {
e.preventDefault();
var $form = $(this);
var $button = $('#scpo-reset-button');
var $message = $('#scpo-reset-message');
var checkedItems = $form.find('input[name="scpo_reset_types[]"]:checked');
if (checkedItems.length === 0) {
$message.text('<?php echo esc_js( __( 'Please select at least one post type to reset.', 'simple-custom-post-order' ) ); ?>');
return;
}
var items = [];
checkedItems.each(function() {
items.push($(this).val());
});
$button.prop('disabled', true);
$message.text('<?php echo esc_js( __( 'Resetting...', 'simple-custom-post-order' ) ); ?>');
$.ajax({
// Root-relative, so the request stays same-origin on any host/port/scheme.
url: <?php echo wp_json_encode( $this->get_ajax_url() ); ?>,
type: 'POST',
data: {
action: 'scpo_reset_order',
scpo_security: '<?php echo esc_js( wp_create_nonce( 'scpo-reset-order' ) ); ?>',
items: items
},
success: function(response) {
if (response && response.success) {
$message.text(response.data.message);
setTimeout(function() {
location.reload();
}, 1500);
} else if (response && response.data && response.data.message) {
$message.text(response.data.message);
} else {
$message.text('<?php echo esc_js( __( 'An error occurred.', 'simple-custom-post-order' ) ); ?>');
}
$button.prop('disabled', false);
},
error: function(xhr) {
var data = xhr.responseJSON && xhr.responseJSON.data;
$message.text(data && typeof data.message === 'string' ? data.message : '<?php echo esc_js( __( 'An error occurred.', 'simple-custom-post-order' ) ); ?>');
$button.prop('disabled', false);
}
});
});
})(jQuery);
</script>