← All changes
|
includes/core/rest-api/Controllers/class-automation-controller.php
+62
-0
3.12.10
→
3.13.3
View file →
| @@ -57,8 +57,36 @@ | ||
| 57 | 57 | ], |
| 58 | 58 | ] |
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | + // Listing for the automations screen: the funnel-sourced automations | |
| 62 | + // with their contact counts, paginated. Deliberately separate from | |
| 63 | + // get_items(), which hands back Mail Mint's own unfiltered list and is | |
| 64 | + // what the MCP automation tools already read. | |
| 65 | + register_rest_route( | |
| 66 | + $this->namespace, | |
| 67 | + '/' . $this->rest_base . '/list', | |
| 68 | + [ | |
| 69 | + [ | |
| 70 | + 'methods' => WP_REST_Server::READABLE, | |
| 71 | + 'callback' => [$this, 'get_list'], | |
| 72 | + 'permission_callback' => [$this, 'get_items_permissions_check'], | |
| 73 | + 'args' => [ | |
| 74 | + 'page' => [ | |
| 75 | + 'description' => __('Current page of the collection.', 'wpfnl'), | |
| 76 | + 'type' => 'integer', | |
| 77 | + 'default' => 1, | |
| 78 | + ], | |
| 79 | + 'per_page' => [ | |
| 80 | + 'description' => __('Maximum number of items to be returned in the result set.', 'wpfnl'), | |
| 81 | + 'type' => 'integer', | |
| 82 | + 'default' => 10, | |
| 83 | + ], | |
| 84 | + ], | |
| 85 | + ], | |
| 86 | + ] | |
| 87 | + ); | |
| 88 | + | |
| 61 | 89 | // Get, update, delete single automation |
| 62 | 90 | register_rest_route( |
| 63 | 91 | $this->namespace, |
| 64 | 92 | '/' . $this->rest_base . '/(?P<id>[\d]+)', |
| @@ -137,8 +165,42 @@ | ||
| 137 | 165 | 'total_pages' => 0, |
| 138 | 166 | 'per_page' => $per_page |
| 139 | 167 | ], 200); |
| 140 | 168 | } |
| 169 | + | |
| 170 | + /** | |
| 171 | + * List the automations belonging to WPFunnels. | |
| 172 | + * | |
| 173 | + * Same data the legacy automations screen rendered server-side: the | |
| 174 | + * funnel-sourced automations only, each with the contact counts the list | |
| 175 | + * shows, wrapped in pagination. The query itself lives behind | |
| 176 | + * `wpfunnels/retrieve_all_automations`, which WPFunnels Pro implements, so | |
| 177 | + * without Pro this answers with an empty page rather than an error. | |
| 178 | + * | |
| 179 | + * @param WP_REST_Request $request Request object. | |
| 180 | + * @return WP_REST_Response | |
| 181 | + * @since 3.13.3 | |
| 182 | + */ | |
| 183 | + public function get_list($request) | |
| 184 | + { | |
| 185 | + $page = max(1, (int) $request->get_param('page')); | |
| 186 | + $per_page = max(1, (int) $request->get_param('per_page')); | |
| 187 | + | |
| 188 | + $result = \WPFunnels\Wpfnl_functions::retrieve_all_automations($page, $per_page); | |
| 189 | + | |
| 190 | + return new WP_REST_Response( | |
| 191 | + [ | |
| 192 | + 'success' => true, | |
| 193 | + 'data' => isset($result['data']) ? array_values($result['data']) : [], | |
| 194 | + 'total' => isset($result['total']) ? (int) $result['total'] : 0, | |
| 195 | + 'total_pages' => isset($result['total_pages']) ? (int) $result['total_pages'] : 0, | |
| 196 | + 'page' => $page, | |
| 197 | + 'per_page' => $per_page, | |
| 198 | + ], | |
| 199 | + 200 | |
| 200 | + ); | |
| 201 | + } | |
| 202 | + | |
| 141 | 203 | |
| 142 | 204 | /** |
| 143 | 205 | * Check permissions for creating item |
| 144 | 206 | * |