← All changes
|
includes/admin/charitable-core-admin-functions.php
+47
-4
1.8.11
→
1.8.13.1
View file →
| @@ -1133,10 +1133,10 @@ | ||
| 1133 | 1133 | if ( isset( $_POST['plugin'] ) ) { |
| 1134 | 1134 | $download_url = esc_url_raw( wp_unslash( $_POST['plugin'] ) ); |
| 1135 | 1135 | global $hook_suffix; |
| 1136 | 1136 | |
| 1137 | - // If the url doesn't start with 'https://www.wpcharitable.com', then return an error. | |
| 1138 | - if ( 0 !== intval( strpos( $download_url, 'https://www.wpcharitable.com' ) ) ) { | |
| 1137 | + // If the url doesn't start with 'https://www.wpcharitable.com/', then return an error. | |
| 1138 | + if ( strpos( $download_url, 'https://www.wpcharitable.com/' ) !== 0 ) { | |
| 1139 | 1139 | wp_send_json_error( |
| 1140 | 1140 | array( |
| 1141 | 1141 | 'basename' => $download_url, |
| 1142 | 1142 | 'is_activated' => false, |
| @@ -1349,8 +1349,12 @@ | ||
| 1349 | 1349 | $versions = get_transient( '_charitable_plugin_versions' ); |
| 1350 | 1350 | |
| 1351 | 1351 | if ( false === $versions ) { |
| 1352 | 1352 | |
| 1353 | + if ( get_transient( '_charitable_plugin_versions_failed' ) ) { | |
| 1354 | + return false; | |
| 1355 | + } | |
| 1356 | + | |
| 1353 | 1357 | if ( false === $licenses ) { |
| 1354 | 1358 | |
| 1355 | 1359 | $licenses = array(); |
| 1356 | 1360 | |
| @@ -1360,8 +1364,17 @@ | ||
| 1360 | 1364 | } |
| 1361 | 1365 | } |
| 1362 | 1366 | } |
| 1363 | 1367 | |
| 1368 | + /* | |
| 1369 | + * No licence means the response cannot be acted on: `install` is a licence-keyed download URL | |
| 1370 | + * and `license` is plan-tier data used only to pick an upgrade prompt. Serve the static | |
| 1371 | + * catalogue instead, which costs no licence key and no home_url() on the wire. | |
| 1372 | + */ | |
| 1373 | + if ( empty( $licenses ) ) { | |
| 1374 | + return Charitable_Addons_Catalogue::get_instance()->get(); | |
| 1375 | + } | |
| 1376 | + | |
| 1364 | 1377 | $response = wp_remote_post( |
| 1365 | 1378 | $update_url . '/edd-api/versions-v3/', |
| 1366 | 1379 | array( |
| 1367 | 1380 | 'sslverify' => false, |
| @@ -1375,10 +1388,13 @@ | ||
| 1375 | 1388 | |
| 1376 | 1389 | $response_body = wp_remote_retrieve_body( $response ); |
| 1377 | 1390 | $response_code = wp_remote_retrieve_response_code( $response ); |
| 1378 | 1391 | |
| 1379 | - // Bail out early if there are any errors. | |
| 1392 | + // Bail out early if there are any errors. Cached briefly, because the campaign builder calls | |
| 1393 | + // this once per payment and marketing panel and a failure sets no transient to short-circuit | |
| 1394 | + // them: at a 15 second timeout an outage meant ~30 serial requests on one page load. | |
| 1380 | 1395 | if ( (int) $response_code !== 200 || is_wp_error( $response_body ) ) { |
| 1396 | + set_transient( '_charitable_plugin_versions_failed', 1, 15 * MINUTE_IN_SECONDS ); | |
| 1381 | 1397 | return false; |
| 1382 | 1398 | } |
| 1383 | 1399 | |
| 1384 | 1400 | $versions = json_decode( $response_body, true ); |
| @@ -1383,8 +1399,9 @@ | ||
| 1383 | 1399 | |
| 1384 | 1400 | $versions = json_decode( $response_body, true ); |
| 1385 | 1401 | |
| 1386 | 1402 | set_transient( '_charitable_plugin_versions', $versions, DAY_IN_SECONDS ); |
| 1403 | + delete_transient( '_charitable_plugin_versions_failed' ); | |
| 1387 | 1404 | |
| 1388 | 1405 | } // end if |
| 1389 | 1406 | |
| 1390 | 1407 | return $versions; |
| @@ -1616,8 +1633,34 @@ | ||
| 1616 | 1633 | } |
| 1617 | 1634 | return $wpchar_site_token; |
| 1618 | 1635 | } |
| 1619 | 1636 | |
| 1637 | +if ( ! function_exists( 'charitable_onboarding_app_url' ) ) : | |
| 1638 | + | |
| 1639 | + /** | |
| 1640 | + * Base URL of the centrally hosted onboarding wizard, without a trailing slash. | |
| 1641 | + * | |
| 1642 | + * Filterable so a development site can be pointed at a local instance of the | |
| 1643 | + * wizard. The wizard has no staging environment, so without this the only way | |
| 1644 | + * to exercise the hand-off between it and a site is against production. | |
| 1645 | + * | |
| 1646 | + * add_filter( 'charitable_onboarding_app_url', function () { | |
| 1647 | + * return 'http://127.0.0.1:8131'; | |
| 1648 | + * } ); | |
| 1649 | + * | |
| 1650 | + * Unfiltered the return value is unchanged from the previously hardcoded | |
| 1651 | + * literal, so this is a no-op in production. | |
| 1652 | + * | |
| 1653 | + * @since 1.8.12.4 | |
| 1654 | + * | |
| 1655 | + * @return string | |
| 1656 | + */ | |
| 1657 | + function charitable_onboarding_app_url() { | |
| 1658 | + return untrailingslashit( apply_filters( 'charitable_onboarding_app_url', 'https://app.wpcharitable.com' ) ); | |
| 1659 | + } | |
| 1660 | + | |
| 1661 | +endif; | |
| 1662 | + | |
| 1620 | 1663 | if ( ! function_exists( 'charitable_get_onboarding_url' ) ) : |
| 1621 | 1664 | |
| 1622 | 1665 | /** |
| 1623 | 1666 | * Get the URL for the first screen of the onboarding process. |
| @@ -1642,9 +1685,9 @@ | ||
| 1642 | 1685 | base64_encode( get_admin_url( null, 'admin.php') ) // phpcs:ignore |
| 1643 | 1686 | ), |
| 1644 | 1687 | 'update_to_pro_url' => 'https://app.charitable.com/upgrade-free-to-pro?api_token=REPLACE_API_TOKEN&license_key=REPLACE_LICENSE_KEY&oth=11ecbadab9561202d33b5ffb8405f9cb9b783af17b52c4b16e16bd8fbbd6cdccbd2a5445c2cb456cb11cdd555471c19e5e2ad446450df2f4e0fc70e410a814d4&endpoint=&siteurl=' . $current_site_url . '/wp-admin/', |
| 1645 | 1688 | ), |
| 1646 | - 'https://app.wpcharitable.com/setup-wizard-charitable_lite' | |
| 1689 | + charitable_onboarding_app_url() . '/setup-wizard-charitable_lite' | |
| 1647 | 1690 | ); |
| 1648 | 1691 | } |
| 1649 | 1692 | |
| 1650 | 1693 | endif; |