| @@ -18,9 +18,9 @@ | ||
| 18 | 18 | return; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | $label = __( 'Add-Ons', 'formidable' ); |
| 22 | - $label = '<span style="color:#fe5a1d">' . $label . '</span>'; | |
| 22 | + $label = '<span style="color:#1da867">' . $label . '</span>'; | |
| 23 | 23 | |
| 24 | 24 | add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), $label, 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' ); |
| 25 | 25 | |
| 26 | 26 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| @@ -297,12 +297,13 @@ | ||
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
| 300 | 300 | * @since 4.08 |
| 301 | + * @since 6.7 This is public. | |
| 301 | 302 | * |
| 302 | 303 | * @return array|false |
| 303 | 304 | */ |
| 304 | - protected static function get_primary_license_info() { | |
| 305 | + public static function get_primary_license_info() { | |
| 305 | 306 | $installed_addons = apply_filters( 'frm_installed_addons', array() ); |
| 306 | 307 | if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) { |
| 307 | 308 | return false; |
| 308 | 309 | } |
| @@ -351,15 +352,16 @@ | ||
| 351 | 352 | // don't show an update if the plugin isn't installed |
| 352 | 353 | continue; |
| 353 | 354 | } |
| 354 | 355 | |
| 355 | - $wp_plugin = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array(); | |
| 356 | - $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0'; | |
| 356 | + $wp_plugin = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array(); | |
| 357 | + $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0'; | |
| 358 | + $plugin->slug = explode( '/', $folder )[0]; | |
| 357 | 359 | |
| 358 | 360 | if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) { |
| 359 | - $slug = explode( '/', $folder ); | |
| 360 | - $plugin->slug = $slug[0]; | |
| 361 | 361 | $transient->response[ $folder ] = $plugin; |
| 362 | + } else { | |
| 363 | + $transient->no_update[ $folder ] = $plugin; | |
| 362 | 364 | } |
| 363 | 365 | |
| 364 | 366 | $transient->checked[ $folder ] = $wp_version; |
| 365 | 367 | |
| @@ -1012,10 +1014,9 @@ | ||
| 1012 | 1014 | * @return bool |
| 1013 | 1015 | */ |
| 1014 | 1016 | public static function url_is_allowed( $download_url ) { |
| 1015 | 1017 | return ( |
| 1016 | - FrmAppHelper::validate_url_is_in_s3_bucket( $download_url, 'zip' ) || | |
| 1017 | - ( strpos( $download_url, 'https://downloads.wordpress.org/plugin' ) === 0 && substr_compare( $download_url, '.zip', -4 ) === 0 ) | |
| 1018 | + FrmAppHelper::validate_url_is_in_s3_bucket( $download_url, 'zip' ) || in_array( $download_url, self::allowed_external_urls(), true ) | |
| 1018 | 1019 | ); |
| 1019 | 1020 | } |
| 1020 | 1021 | |
| 1021 | 1022 | /** |
| @@ -1076,10 +1077,12 @@ | ||
| 1076 | 1077 | */ |
| 1077 | 1078 | private static function get_addon_activation_response() { |
| 1078 | 1079 | $activating_page = self::get_activating_page(); |
| 1079 | 1080 | |
| 1081 | + $message = $activating_page ? __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ) : __( 'Your plugin has been activated.', 'formidable' ); | |
| 1082 | + | |
| 1080 | 1083 | $response = array( |
| 1081 | - 'message' => __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ), | |
| 1084 | + 'message' => $message, | |
| 1082 | 1085 | 'saveAndReload' => $activating_page, |
| 1083 | 1086 | ); |
| 1084 | 1087 | |
| 1085 | 1088 | return $response; |
| @@ -1180,9 +1183,9 @@ | ||
| 1180 | 1183 | // Verify params present (auth & download link). |
| 1181 | 1184 | $post_auth = FrmAppHelper::get_param( 'token', '', 'request', 'sanitize_text_field' ); |
| 1182 | 1185 | $post_url = FrmAppHelper::get_param( 'file_url', '', 'request', 'sanitize_text_field' ); |
| 1183 | 1186 | |
| 1184 | - if ( empty( $post_auth ) || empty( $post_url ) ) { | |
| 1187 | + if ( ! $post_auth || ! $post_url ) { | |
| 1185 | 1188 | return false; |
| 1186 | 1189 | } |
| 1187 | 1190 | |
| 1188 | 1191 | // Verify auth. |
| @@ -1253,9 +1256,19 @@ | ||
| 1253 | 1256 | } |
| 1254 | 1257 | |
| 1255 | 1258 | $addon = self::get_addon( $plugin ); |
| 1256 | 1259 | $upgrade_link = FrmAppHelper::admin_upgrade_link( $upgrade_link_args ); |
| 1257 | - self::addon_upgrade_link( $addon, $upgrade_link ); | |
| 1260 | + | |
| 1261 | + if ( ! is_array( $upgrade_link_args ) ) { | |
| 1262 | + // A string $upgrade_link_args is used for the utm-medium value when calling | |
| 1263 | + // FrmAppHelper::admin_upgrade_link above. | |
| 1264 | + // For self::addon_upgrade_link, we'll pass just an empty array with the link key (set below). | |
| 1265 | + $upgrade_link_args = array(); | |
| 1266 | + } | |
| 1267 | + | |
| 1268 | + $upgrade_link_args['link'] = $upgrade_link; | |
| 1269 | + | |
| 1270 | + self::addon_upgrade_link( $addon, $upgrade_link_args ); | |
| 1258 | 1271 | } |
| 1259 | 1272 | |
| 1260 | 1273 | /** |
| 1261 | 1274 | * Render a conditional action button for an add on |
| @@ -1277,13 +1290,17 @@ | ||
| 1277 | 1290 | |
| 1278 | 1291 | /** |
| 1279 | 1292 | * @since 4.09.01 |
| 1280 | 1293 | * |
| 1281 | - * @param array|false $addon | |
| 1294 | + * @param array|false $addon | |
| 1295 | + * @param string|array $upgrade_link | |
| 1282 | 1296 | * |
| 1283 | 1297 | * @return void |
| 1284 | 1298 | */ |
| 1285 | 1299 | protected static function addon_upgrade_link( $addon, $upgrade_link ) { |
| 1300 | + $atts = is_array( $upgrade_link ) ? $upgrade_link : array(); | |
| 1301 | + $upgrade_link = is_array( $upgrade_link ) ? $upgrade_link['link'] : $upgrade_link; | |
| 1302 | + | |
| 1286 | 1303 | if ( $addon ) { |
| 1287 | 1304 | $upgrade_link .= '&utm_content=' . $addon['slug']; |
| 1288 | 1305 | } |
| 1289 | 1306 | |
| @@ -1290,10 +1307,15 @@ | ||
| 1290 | 1307 | if ( $addon && isset( $addon['categories'] ) && in_array( 'Solution', $addon['categories'], true ) ) { |
| 1291 | 1308 | // Solutions will go to a separate page. |
| 1292 | 1309 | $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] ); |
| 1293 | 1310 | } |
| 1311 | + | |
| 1312 | + $class = ! empty( $atts['class'] ) ? $atts['class'] : ''; | |
| 1313 | + if ( strpos( $class, 'frm-button' ) === false ) { | |
| 1314 | + $class .= ' frm-button-secondary frm-button-sm'; | |
| 1315 | + } | |
| 1294 | 1316 | ?> |
| 1295 | - <a class="install-now button frm-button-secondary frm-button-sm" href="<?php echo esc_url( $upgrade_link ); ?>" target="_blank" rel="noopener" aria-label="<?php esc_attr_e( 'Upgrade Now', 'formidable' ); ?>"> | |
| 1317 | + <a class="install-now button <?php echo esc_attr( $class ); ?>" href="<?php echo esc_url( $upgrade_link ); ?>" target="_blank" rel="noopener" aria-label="<?php esc_attr_e( 'Upgrade Now', 'formidable' ); ?>"> | |
| 1296 | 1318 | <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?> |
| 1297 | 1319 | </a> |
| 1298 | 1320 | <?php |
| 1299 | 1321 | } |
| @@ -1313,8 +1335,63 @@ | ||
| 1313 | 1335 | } |
| 1314 | 1336 | |
| 1315 | 1337 | echo json_encode( self::get_addon_activation_response() ); |
| 1316 | 1338 | wp_die(); |
| 1339 | + } | |
| 1340 | + | |
| 1341 | + /** | |
| 1342 | + * Allowed URLs used for internal source of plugins installation. | |
| 1343 | + * | |
| 1344 | + * @since 6.3.1 | |
| 1345 | + * | |
| 1346 | + * @return array | |
| 1347 | + */ | |
| 1348 | + private static function allowed_external_urls() { | |
| 1349 | + $allowed_url_list = array( | |
| 1350 | + 'https://downloads.wordpress.org/plugin/formidable-gravity-forms-importer.zip', | |
| 1351 | + 'https://downloads.wordpress.org/plugin/formidable-import-pirate-forms.zip', | |
| 1352 | + 'https://downloads.wordpress.org/plugin/wp-mail-smtp.zip', | |
| 1353 | + ); | |
| 1354 | + | |
| 1355 | + /** | |
| 1356 | + * List of URLs used in plugin formidable internal installation. | |
| 1357 | + * | |
| 1358 | + * @since 6.3.1 | |
| 1359 | + * | |
| 1360 | + * @param array $allowed_url_list List of URLs. | |
| 1361 | + */ | |
| 1362 | + $allowed_url_list = apply_filters( 'frm_allowed_external_urls', $allowed_url_list ); | |
| 1363 | + | |
| 1364 | + if ( ! is_array( $allowed_url_list ) ) { | |
| 1365 | + _doing_it_wrong( __METHOD__, 'Only an array of URLs could be used within this filter.', '6.3.1' ); | |
| 1366 | + | |
| 1367 | + return array(); | |
| 1368 | + } | |
| 1369 | + | |
| 1370 | + return $allowed_url_list; | |
| 1371 | + } | |
| 1372 | + | |
| 1373 | + /** | |
| 1374 | + * Gets required plan for an addon. | |
| 1375 | + * | |
| 1376 | + * @since 6.4.2 | |
| 1377 | + * | |
| 1378 | + * @return string Empty string if no plan is required for active license. | |
| 1379 | + */ | |
| 1380 | + public static function get_addon_required_plan( $addon_id ) { | |
| 1381 | + $api = new FrmFormApi(); | |
| 1382 | + $addons = $api->get_api_info(); | |
| 1383 | + | |
| 1384 | + if ( is_array( $addons ) && array_key_exists( $addon_id, $addons ) ) { | |
| 1385 | + $dates = $addons[ $addon_id ]; | |
| 1386 | + $requires = FrmFormsHelper::get_plan_required( $dates ); | |
| 1387 | + } | |
| 1388 | + | |
| 1389 | + if ( ! isset( $requires ) || ! is_string( $requires ) ) { | |
| 1390 | + $requires = ''; | |
| 1391 | + } | |
| 1392 | + | |
| 1393 | + return $requires; | |
| 1317 | 1394 | } |
| 1318 | 1395 | |
| 1319 | 1396 | /** |
| 1320 | 1397 | * @since 4.06.02 |