263263 <option value="read_write" <?php selected ( $ pmprodev_options ['performance_endpoints ' ], 'read_write ' ); ?> ><?php esc_html_e ( 'Read and Write ' , 'pmpro-toolkit ' ); ?> </option>
264264 </select>
265265 <p class="description">
266- <?php esc_html_e ( 'Enable performance testing REST API endpoint for testing purposes. ' , 'pmpro-toolkit ' ); ?>
267- <br>
268- <?php if ( ! empty ( $ pmprodev_options ['performance_endpoints ' ] ) && $ pmprodev_options ['performance_endpoints ' ] !== 'no ' ) : ?>
266+ <span><?php esc_html_e ( 'Enable performance testing REST API endpoint for testing purposes. ' , 'pmpro-toolkit ' ); ?> </span>
267+
268+ </p>
269+ </td>
270+ </tr>
271+ <tr>
272+ <th></th>
273+ <td id="pmprodev_options_performance_endpoints">
274+ <strong><?php esc_html_e ( 'Endpoint URLs ' , 'pmpro-toolkit ' ); ?> :</strong><br>
275+ <code><?php echo esc_url ( rest_url ( 'toolkit/v1/(endpoint-name) ' ) ); ?> </code><br>
276+ <em><?php esc_html_e ( 'Use GET for read-only tests, POST for read-write tests (if enabled). ' , 'pmpro-toolkit ' ); ?> </em>
277+
278+ <?php
279+ if ( !defined ( 'SAVEQUERIES ' ) || SAVEQUERIES === false ) { ?>
280+ <span class="dashicons dashicons-yes" style="margin-top:-3px;"></span><?php esc_html_e ( 'The SAVEQUERIES constant is enabled. ' , 'pmpro-toolkit ' ); ?>
281+ <?php } else { ?>
269282 <br><br>
270- <strong><?php esc_html_e ( 'Endpoint URLs: ' , 'pmpro-toolkit ' ); ?> </strong><br>
271- <code><?php echo esc_url ( rest_url ( 'toolkit/v1/(endpoint-name) ' ) ); ?> </code>
272- <br>
273- <em><?php esc_html_e ( 'Use GET for read-only tests, POST for read-write tests (if enabled). ' , 'pmpro-toolkit ' ); ?> </em>
283+ <strong><?php esc_html_e ( 'NOTE: ' , 'pmpro-toolkit ' ); ?> </strong>
284+ <?php printf (
285+ // translators: 1: define() code snippet, 2: wp-config.php filename
286+ esc_html__ ( 'To enable full testing capability, make sure to add %1$s to your %2$s file. ' , 'pmpro-toolkit ' ),
287+ '<code>define( \'SAVEQUERIES \', true );</code> ' ,
288+ '<code>wp-config.php</code> '
289+ ); ?>
274290 <br><br>
275- <?php
276- if ( !defined ( 'SAVEQUERIES ' ) || SAVEQUERIES === false ) { ?>
277- <span class="dashicons dashicons-yes" style="margin-top:-3px;"></span><?php esc_html_e ( 'The SAVEQUERIES constant is enabled. ' , 'pmpro-toolkit ' ); ?>
278- <?php } else { ?>
279- <strong><?php esc_html_e ( 'NOTE: ' , 'pmpro-toolkit ' ); ?> </strong>
280- <?php printf (
281- // translators: 1: define() code snippet, 2: wp-config.php filename
282- esc_html__ ( 'To enable full testing capability, make sure to add %1$s to your %2$s file. ' , 'pmpro-toolkit ' ),
283- '<code>define( \'SAVEQUERIES \', true );</code> ' ,
284- '<code>wp-config.php</code> '
285- ); ?>
286- <?php } ?>
287- <?php endif ; ?>
288- </p>
291+ <?php } ?>
292+ <p>
293+ <strong><?php esc_html_e ( 'Available Endpoints ' , 'pmpro-toolkit ' ); ?> :</strong><br>
294+ <ul style="margin: 0 0 0 1.5em; padding: 0; list-style: none;">
295+ <li><code>/wp-json/toolkit/v1/test-general</code></li>
296+ <li><code>/wp-json/toolkit/v1/test-login</code></li>
297+ <li><code>/wp-json/toolkit/v1/test-cancel-level</code></li>
298+ <li><code>/wp-json/toolkit/v1/test-checkout</code></li>
299+ <li><code>/wp-json/toolkit/v1/test-account-page</code></li>
300+ <li><code>/wp-json/toolkit/v1/test-report</code></li>
301+ <li><code>/wp-json/toolkit/v1/test-member-export</code></li>
302+ <li><code>/wp-json/toolkit/v1/test-search?query=test</code></li>
303+ <li><code>/wp-json/toolkit/v1/test-change-level</code></li>
304+ </ul>
305+ </p>
289306 </td>
290307 </tr>
291- <?php if ( ! empty ( $ pmprodev_options ['performance_endpoints ' ] ) && $ pmprodev_options ['performance_endpoints ' ] !== 'no ' ) : ?>
292308 <tr>
293309 <th scope="row" valign="top">
294310 <label for="pmprodev_options[ip_throttling]"> <?php esc_html_e ( 'Enable IP Throttling ' , 'pmpro-toolkit ' ); ?> </label>
298314 <label for="pmprodev_options[ip_throttling]"> <?php esc_html_e ( 'Enable IP-based request throttling on public endpoints. ' , 'pmpro-toolkit ' ); ?> </label>
299315 </td>
300316 </tr>
301- <?php endif ; ?>
302317 </tbody>
303318 </table>
304319 </div>
312327jQuery(document).ready(function($) {
313328 // Show additional warning when "Read and Write" is selected
314329 function togglePerformanceWarning() {
315- var selectedValue = $('#pmprodev_options[performance_endpoints]').val();
330+ var selectedValue = $('#pmprodev_options\\ [performance_endpoints\\ ]').val();
316331 var warningDiv = $('#performance-endpoint-warning');
317-
318332 if (selectedValue === 'read_write') {
319333 if (warningDiv.length === 0) {
320- $('#pmprodev_options[performance_endpoints]').next('p.description').append(
321- '<div id="performance-endpoint-warning"><br>' +
334+ // Add an ID to the first span if it doesn't exist
335+ var $span = $('#pmprodev_options\\[performance_endpoints\\]').closest('td').find('span').first();
336+ if (!$span.attr('id')) {
337+ $span.attr('id', 'performance-endpoint-span');
338+ }
339+ $span.append(
340+ '<div id="performance-endpoint-warning">' +
322341 '<strong style="color: #c3524f;"><?php esc_html_e ( 'CAUTION: ' , 'pmpro-toolkit ' ); ?> </strong> ' +
323342 '<?php esc_html_e ( '"Read and Write" mode will create and delete test data on your site. Only use this on development/testing sites. ' , 'pmpro-toolkit ' ); ?> ' +
324343 '</div>'
@@ -328,13 +347,28 @@ function togglePerformanceWarning() {
328347 warningDiv.remove();
329348 }
330349 }
350+
351+ function toggle_performance_endpoint_info() {
352+ var selectedValue = $('#pmprodev_options\\[performance_endpoints\\]').val();
353+ var endpoints_container = $('#pmprodev_options_performance_endpoints').closest('tr');
354+ var ip_throttling_row = $('#pmprodev_options\\[ip_throttling\\]').closest('tr');
355+ if (selectedValue === 'no') {
356+ endpoints_container.hide();
357+ ip_throttling_row.hide();
358+ } else {
359+ endpoints_container.show();
360+ ip_throttling_row.show();
361+ }
362+ }
331363
332364 // Check on page load
333365 togglePerformanceWarning();
334-
366+ toggle_performance_endpoint_info();
367+
335368 // Check when selection changes
336- $('#pmprodev_options[performance_endpoints]').change(function() {
369+ $('#pmprodev_options\\ [performance_endpoints\\ ]').change(function() {
337370 togglePerformanceWarning();
371+ toggle_performance_endpoint_info();
338372 });
339373});
340374</script>
0 commit comments