PluginProbe
Tag Groups is the Advanced Way to Display Your Taxonomy Terms / trunk
Tag Groups is the Advanced Way to Display Your Taxonomy Terms vtrunk
2.2.2 2.2.1 2.2.0 trunk 1.40.0 1.40.2 1.41.0 1.42.1 1.43.0 1.43.1 1.43.10 1.43.10.1 1.43.2 1.43.3 1.43.4 1.43.5 1.43.6 1.43.7 1.43.9 1.44.0 1.44.1 1.44.3 1.44.3.1 2.0.0 2.0.1 All 36 releases
tag-groups / include / admin / class.process.php

class.process.php in Tag Groups is the Advanced Way to Display Your Taxonomy Terms trunk, at include/admin/class.process.php

161 lines 8.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Tag Groups
5 *
6 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
7 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
8 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
9 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
10 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
11 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
12 * THE SOFTWARE.
13 * @package Tag Groups
14 *
15 * @author Christoph Amthor
16 * @copyright 2018 Christoph Amthor (@ Chatty Mango, chattymango.com)
17 * @license see official vendor website
18 *
19 * @since 1.24.0
20 */
21
22 if (! class_exists('TagGroups_Process')) {
23 /**
24 * Background workers for the progress bar
25 *
26 */
27 // phpcs:ignore PSR1.Classes.ClassDeclaration.MissingNamespace, Squiz.Classes.ValidClassName.NotCamelCaps -- Legacy class structure
28 class TagGroups_Process
29 {
30 /**
31 * Receives the Ajax call to process chunks of long tasks, to avoid timeouts
32 *
33 *
34 * @param void
35 * @return void
36 */
37 // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- Legacy method naming
38 public static function tg_ajax_process()
39 {
40
41 $affected = 0;
42 $error = false;
43 $nonce = '';
44 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verified below
45 if (isset($_REQUEST['nonce'])) {
46 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Recommended -- Nonce verified below
47 $nonce = sanitize_text_field(wp_unslash($_REQUEST['nonce']));
48 }
49
50 if (! current_user_can('manage_options')) {
51 die('Access denied.');
52 }
53
54 if (! wp_verify_nonce($nonce, 'tag-groups-process-nonce')) {
55 die('Access denied.');
56 }
57
58 if (isset($_REQUEST['task'])) {
59 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized in switch statement
60 $task = sanitize_key(wp_unslash($_REQUEST['task']));
61 } else {
62 $error = true;
63 }
64
65 if (isset($_REQUEST['offset'])) {
66 $offset = (int) $_REQUEST['offset'];
67 } else {
68 $error = true;
69 }
70
71 if (isset($_REQUEST['length'])) {
72 $length = (int) $_REQUEST['length'];
73 } else {
74 $error = true;
75 }
76
77 if (! $error) {
78 switch ($task) {
79 case 'migratetermmeta':
80 $affected = TagGroups_Term_Meta_Tools::convert_to_term_meta(false, $offset, $length);
81
82
83 break;
84 case 'fixgroups':
85 $affected = TagGroups_Group_Tools::check_fix_groups(false, $offset, $length);
86
87
88 break;
89 case 'fixmissinggroups':
90 $affected = TagGroups_Term_Meta_Tools::remove_missing_groups(false, $offset, $length);
91
92
93 break;
94 case 'sortgroups':
95 $affected = TagGroups_Term_Meta_Tools::sort_groups(false, false, $offset, $length);
96
97
98 break;
99 default:
100 $error = true;
101
102
103 break;
104 }
105 }
106
107 if ($error) {
108 echo wp_json_encode(array(
109 'data' => 'error',
110 'done' => 0,
111 'affected' => 0,
112 ));
113 TagGroups_Utilities::die();
114 }
115
116 echo wp_json_encode(array(
117 'data' => 'success',
118 'done' => 1,
119 'affected' => $affected,
120 ));
121 TagGroups_Utilities::die();
122 }
123
124 /**
125 * Gets the total number of things to do for a particular task
126 *
127 * @param string $task
128 * @return int
129 */
130 // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps -- Legacy method naming
131 public static function get_task_total($task, $language_code = null)
132 {
133
134 switch ($task) {
135 case 'migratetermmeta':
136 return TagGroups_Term_Meta_Tools::convert_to_term_meta(true);
137 case 'fixgroups':
138 return TagGroups_Group_Tools::check_fix_groups(true);
139 break;
140 case 'fixmissinggroups':
141 return TagGroups_Term_Meta_Tools::remove_missing_groups(true);
142 break;
143 case 'sortgroups':
144 return TagGroups_Term_Meta_Tools::sort_groups(true, true);
145 break;
146 break;
147 case 'fixmissinggroups':
148 return TagGroups_Term_Meta_Tools::remove_missing_groups(true);
149 break;
150 default:
151 return false;
152 break;
153 }
154
155 return 0;
156 }
157 }
158
159
160 }
161