| @@ -1,72 +1,30 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - die( 'You are not allowed to call this page directly.' ); | |
| 4 | -} | |
| 5 | 2 | |
| 6 | 3 | class FrmAddonsController { |
| 7 | 4 | |
| 8 | - /** | |
| 9 | - * @var string $plugin | |
| 10 | - */ | |
| 11 | - protected static $plugin; | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * @return void | |
| 15 | - */ | |
| 16 | 5 | public static function menu() { |
| 17 | 6 | if ( ! current_user_can( 'activate_plugins' ) ) { |
| 18 | 7 | return; |
| 19 | 8 | } |
| 20 | 9 | |
| 21 | - $label = __( 'Add-Ons', 'formidable' ); | |
| 22 | - $label = '<span style="color:#fe5a1d">' . $label . '</span>'; | |
| 10 | + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), __( 'Add-Ons', 'formidable' ), 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' ); | |
| 23 | 11 | |
| 24 | - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), $label, 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' ); | |
| 25 | - | |
| 26 | 12 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 27 | - add_submenu_page( | |
| 28 | - 'formidable', | |
| 29 | - 'Formidable | ' . __( 'Upgrade', 'formidable' ), | |
| 30 | - '<span class="frm-upgrade-submenu">' . __( 'Upgrade', 'formidable' ) . '</span>', | |
| 31 | - 'frm_view_forms', | |
| 32 | - 'formidable-pro-upgrade', | |
| 33 | - 'FrmAddonsController::upgrade_to_pro' | |
| 34 | - ); | |
| 35 | - } elseif ( 'formidable-pro-upgrade' === FrmAppHelper::get_param( 'page' ) ) { | |
| 36 | - wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) ); | |
| 37 | - exit; | |
| 13 | + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Upgrade to Pro', 'formidable' ), __( 'Upgrade to Pro', 'formidable' ), 'frm_view_forms', 'formidable-pro-upgrade', 'FrmAddonsController::upgrade_to_pro' ); | |
| 38 | 14 | } |
| 39 | 15 | } |
| 40 | 16 | |
| 41 | - /** | |
| 42 | - * @return void | |
| 43 | - */ | |
| 44 | 17 | public static function list_addons() { |
| 45 | - FrmAppHelper::include_svg(); | |
| 46 | 18 | $installed_addons = apply_filters( 'frm_installed_addons', array() ); |
| 47 | - $license_type = ''; | |
| 48 | 19 | |
| 49 | 20 | $addons = self::get_api_addons(); |
| 50 | 21 | $errors = array(); |
| 51 | - | |
| 52 | 22 | if ( isset( $addons['error'] ) ) { |
| 53 | 23 | $api = new FrmFormApi(); |
| 54 | 24 | $errors = $api->get_error_from_response( $addons ); |
| 55 | - $license_type = isset( $addons['error']['type'] ) ? $addons['error']['type'] : ''; | |
| 56 | 25 | unset( $addons['error'] ); |
| 57 | 26 | } |
| 58 | - | |
| 59 | - $pro = array( | |
| 60 | - 'pro' => array( | |
| 61 | - 'title' => 'Formidable Forms Pro', | |
| 62 | - 'slug' => 'formidable-pro', | |
| 63 | - 'released' => '2011-02-05', | |
| 64 | - 'docs' => 'knowledgebase/', | |
| 65 | - 'excerpt' => 'Create calculators, surveys, smart forms, and data-driven applications. Build directories, real estate listings, job boards, and much more.', | |
| 66 | - ), | |
| 67 | - ); | |
| 68 | - $addons = $pro + $addons; | |
| 69 | 27 | self::prepare_addons( $addons ); |
| 70 | 28 | |
| 71 | 29 | $pricing = FrmAppHelper::admin_upgrade_link( 'addons' ); |
| 72 | 30 | |
| @@ -72,16 +30,12 @@ | ||
| 72 | 30 | |
| 73 | 31 | include( FrmAppHelper::plugin_path() . '/classes/views/addons/list.php' ); |
| 74 | 32 | } |
| 75 | 33 | |
| 76 | - /** | |
| 77 | - * @return void | |
| 78 | - */ | |
| 79 | 34 | public static function license_settings() { |
| 80 | 35 | $plugins = apply_filters( 'frm_installed_addons', array() ); |
| 81 | 36 | if ( empty( $plugins ) ) { |
| 82 | 37 | esc_html_e( 'There are no plugins on your site that require a license', 'formidable' ); |
| 83 | - | |
| 84 | 38 | return; |
| 85 | 39 | } |
| 86 | 40 | |
| 87 | 41 | ksort( $plugins ); |
| @@ -88,13 +42,10 @@ | ||
| 88 | 42 | |
| 89 | 43 | include( FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php' ); |
| 90 | 44 | } |
| 91 | 45 | |
| 92 | - /** | |
| 93 | - * @return array | |
| 94 | - */ | |
| 95 | - protected static function get_api_addons() { | |
| 96 | - $api = new FrmFormApi(); | |
| 46 | + private static function get_api_addons() { | |
| 47 | + $api = new FrmFormApi(); | |
| 97 | 48 | $addons = $api->get_api_info(); |
| 98 | 49 | |
| 99 | 50 | if ( empty( $addons ) ) { |
| 100 | 51 | $addons = self::fallback_plugin_list(); |
| @@ -114,98 +65,79 @@ | ||
| 114 | 65 | * |
| 115 | 66 | * @since 3.04.03 |
| 116 | 67 | * @return array |
| 117 | 68 | */ |
| 118 | - protected static function fallback_plugin_list() { | |
| 119 | - $list = array( | |
| 69 | + private static function fallback_plugin_list() { | |
| 70 | + return array( | |
| 120 | 71 | 'formidable-pro' => array( |
| 121 | - 'title' => 'Formidable Forms Pro', | |
| 72 | + 'title' => 'Formidable Pro', | |
| 122 | 73 | 'link' => 'pricing/', |
| 123 | 74 | 'docs' => '', |
| 124 | 75 | 'excerpt' => 'Enhance your basic Formidable forms with a plethora of Pro field types and features. Create advanced forms and data-driven applications in minutes.', |
| 125 | 76 | ), |
| 126 | - 'mailchimp' => array( | |
| 127 | - 'title' => 'Mailchimp Forms', | |
| 128 | - 'excerpt' => 'Get on the path to more sales and leads in a matter of minutes. Add leads to a Mailchimp mailing list when they submit forms and update their information along with the entry.', | |
| 77 | + 'mailchimp' => array( | |
| 78 | + 'title' => 'MailChimp Forms', | |
| 79 | + 'excerpt' => 'Get on the path to more sales and leads in a matter of minutes. Add leads to a MailChimp mailing list when they submit forms and update their information along with the entry.', | |
| 129 | 80 | ), |
| 130 | - 'registration' => array( | |
| 81 | + 'registration' => array( | |
| 131 | 82 | 'title' => 'User Registration Forms', |
| 132 | 83 | 'link' => 'downloads/user-registration/', |
| 133 | 84 | 'excerpt' => 'Give new users access to your site as quickly and painlessly as possible. Allow users to register, edit and be able to login to their profiles on your site from the front end in a clean, customized registration form.', |
| 134 | 85 | ), |
| 135 | - 'paypal' => array( | |
| 86 | + 'paypal' => array( | |
| 136 | 87 | 'title' => 'PayPal Standard Forms', |
| 137 | 88 | 'link' => 'downloads/paypal-standard/', |
| 138 | 89 | 'excerpt' => 'Automate your business by collecting instant payments from your clients. Collect information, calculate a total, and send them on to PayPal. Require a payment before publishing content on your site.', |
| 139 | 90 | ), |
| 140 | - 'stripe' => array( | |
| 91 | + 'stripe' => array( | |
| 141 | 92 | 'title' => 'Stripe Forms', |
| 142 | 93 | 'docs' => 'knowledgebase/stripe/', |
| 143 | 94 | 'excerpt' => 'Any Formidable forms on your site can accept credit card payments without users ever leaving your site.', |
| 144 | 95 | ), |
| 145 | - 'authorize-net' => array( | |
| 96 | + 'authorize-net' => array( | |
| 146 | 97 | 'title' => 'Authorize.net AIM Forms', |
| 147 | 98 | 'link' => 'downloads/authorize-net-aim/', |
| 148 | 99 | 'docs' => 'knowledgebase/authorize-net-aim/', |
| 149 | 100 | 'excerpt' => 'Accept one-time payments directly on your site, using Authorize.net AIM.', |
| 150 | 101 | ), |
| 151 | - 'woocommerce' => array( | |
| 102 | + 'woocommerce' => array( | |
| 152 | 103 | 'title' => 'WooCommerce Forms', |
| 153 | 104 | 'excerpt' => 'Use a Formidable form on your WooCommerce product pages.', |
| 154 | 105 | ), |
| 155 | - 'autoresponder' => array( | |
| 106 | + 'autoresponder' => array( | |
| 156 | 107 | 'title' => 'Form Action Automation', |
| 157 | 108 | 'docs' => 'knowledgebase/schedule-autoresponder/', |
| 158 | 109 | 'excerpt' => 'Schedule email notifications, SMS messages, and API actions.', |
| 159 | 110 | ), |
| 160 | - 'modal' => array( | |
| 111 | + 'modal' => array( | |
| 161 | 112 | 'title' => 'Bootstrap Modal Forms', |
| 162 | 113 | 'link' => 'downloads/bootstrap-modal/', |
| 163 | 114 | 'docs' => 'knowledgebase/bootstrap-modal/', |
| 164 | 115 | 'excerpt' => 'Open a view or form in a Bootstrap popup.', |
| 165 | 116 | ), |
| 166 | - 'bootstrap' => array( | |
| 117 | + 'bootstrap' => array( | |
| 167 | 118 | 'title' => 'Bootstrap Style Forms', |
| 168 | 119 | 'excerpt' => 'Instantly add Bootstrap styling to all your Formidable forms.', |
| 169 | 120 | ), |
| 170 | - 'zapier' => array( | |
| 121 | + 'zapier' => array( | |
| 171 | 122 | 'title' => 'Zapier Forms', |
| 172 | 123 | 'excerpt' => 'Connect with hundreds of different applications through Zapier. Insert a new row in a Google docs spreadsheet, post on Twitter, or add a new Dropbox file with your form.', |
| 173 | 124 | ), |
| 174 | - 'signature' => array( | |
| 125 | + 'signature' => array( | |
| 175 | 126 | 'title' => 'Digital Signature Forms', |
| 176 | 127 | 'excerpt' => 'Add a signature field to your form. The user may write their signature with a trackpad/mouse or just type it.', |
| 177 | 128 | ), |
| 178 | - 'api' => array( | |
| 129 | + 'api' => array( | |
| 179 | 130 | 'title' => 'Formidable Forms API', |
| 180 | 131 | 'link' => 'downloads/formidable-api/', |
| 181 | 132 | 'excerpt' => 'Send entry results to any other site that has a Rest API. This includes the option of sending entries from one Formidable site to another.', |
| 182 | 133 | ), |
| 183 | - 'twilio' => array( | |
| 134 | + 'twilio' => array( | |
| 184 | 135 | 'title' => 'Twilio SMS Forms', |
| 185 | 136 | 'docs' => 'knowledgebase/twilio-add-on/', |
| 186 | 137 | 'excerpt' => 'Allow users to text their votes for polls created by Formidable Forms, or send SMS notifications when entries are submitted or updated.', |
| 187 | 138 | ), |
| 188 | - 'views' => array( | |
| 189 | - 'title' => 'Formidable Views', | |
| 190 | - 'excerpt' => 'Add the power of views to your Formidable Forms to display your form submissions in listings, tables, calendars, and more.', | |
| 191 | - ), | |
| 192 | - 'quiz_maker' => array( | |
| 193 | - 'title' => 'Quiz Maker', | |
| 194 | - 'link' => 'downloads/quiz-maker/', | |
| 195 | - 'excerpt' => 'Make quizzes, automatically score them and show user scores.', | |
| 196 | - ), | |
| 197 | 139 | ); |
| 198 | - | |
| 199 | - $defaults = array( | |
| 200 | - 'released' => '', | |
| 201 | - ); | |
| 202 | - | |
| 203 | - foreach ( $list as $k => $info ) { | |
| 204 | - $info['slug'] = $k; | |
| 205 | - $list[ $k ] = array_merge( $defaults, $info ); | |
| 206 | - } | |
| 207 | - return $list; | |
| 208 | 140 | } |
| 209 | 141 | |
| 210 | 142 | /** |
| 211 | 143 | * If Pro is missing but has been authenticated, include a download URL |
| @@ -213,22 +145,10 @@ | ||
| 213 | 145 | * @since 3.04.03 |
| 214 | 146 | * @return string |
| 215 | 147 | */ |
| 216 | 148 | public static function get_pro_download_url() { |
| 217 | - $license = self::get_pro_license(); | |
| 218 | - $api = new FrmFormApi( $license ); | |
| 219 | - $downloads = $api->get_api_info(); | |
| 220 | - $pro = self::get_pro_from_addons( $downloads ); | |
| 221 | - | |
| 222 | - return isset( $pro['url'] ) ? $pro['url'] : ''; | |
| 223 | - } | |
| 224 | - | |
| 225 | - /** | |
| 226 | - * @since 4.08 | |
| 227 | - */ | |
| 228 | - public static function get_pro_license() { | |
| 229 | - $pro_cred_store = 'frmpro-credentials'; | |
| 230 | - $pro_wpmu_store = 'frmpro-wpmu-sitewide'; | |
| 149 | + $pro_cred_store = 'frmpro-credentials'; | |
| 150 | + $pro_wpmu_store = 'frmpro-wpmu-sitewide'; | |
| 231 | 151 | if ( is_multisite() && get_site_option( $pro_wpmu_store ) ) { |
| 232 | 152 | $creds = get_site_option( $pro_cred_store ); |
| 233 | 153 | } else { |
| 234 | 154 | $creds = get_option( $pro_cred_store ); |
| @@ -246,83 +166,20 @@ | ||
| 246 | 166 | if ( strpos( $license, '-' ) ) { |
| 247 | 167 | // this is a fix for licenses saved in the past |
| 248 | 168 | $license = strtoupper( $license ); |
| 249 | 169 | } |
| 250 | - return $license; | |
| 251 | - } | |
| 252 | 170 | |
| 253 | - /** | |
| 254 | - * @since 4.08 | |
| 255 | - * | |
| 256 | - * @param array $addons | |
| 257 | - * @return array | |
| 258 | - */ | |
| 259 | - protected static function get_pro_from_addons( $addons ) { | |
| 260 | - return isset( $addons['93790'] ) ? $addons['93790'] : array(); | |
| 261 | - } | |
| 171 | + $api = new FrmFormApi( $license ); | |
| 172 | + $downloads = $api->get_api_info(); | |
| 173 | + $pro = isset( $downloads['93790'] ) ? $downloads['93790'] : array(); | |
| 262 | 174 | |
| 263 | - /** | |
| 264 | - * @since 4.06 | |
| 265 | - */ | |
| 266 | - public static function license_type() { | |
| 267 | - if ( is_callable( 'FrmProAddonsController::license_type' ) ) { | |
| 268 | - return FrmProAddonsController::license_type(); | |
| 269 | - } | |
| 270 | - | |
| 271 | - return 'free'; | |
| 175 | + return isset( $pro['url'] ) ? $pro['url'] : ''; | |
| 272 | 176 | } |
| 273 | 177 | |
| 274 | 178 | /** |
| 275 | - * @since 4.0.01 | |
| 276 | - */ | |
| 277 | - public static function is_license_expired() { | |
| 278 | - $version_info = self::get_primary_license_info(); | |
| 279 | - if ( ! isset( $version_info['error'] ) ) { | |
| 280 | - return false; | |
| 281 | - } | |
| 282 | - | |
| 283 | - return $version_info['error']; | |
| 284 | - } | |
| 285 | - | |
| 286 | - /** | |
| 287 | - * @since 4.08 | |
| 288 | - * | |
| 289 | - * @return boolean|int false or the number of days until expiration. | |
| 290 | - */ | |
| 291 | - public static function is_license_expiring() { | |
| 292 | - if ( is_callable( 'FrmProAddonsController::is_license_expiring' ) ) { | |
| 293 | - return FrmProAddonsController::is_license_expiring(); | |
| 294 | - } | |
| 295 | - | |
| 296 | - return false; | |
| 297 | - } | |
| 298 | - | |
| 299 | - /** | |
| 300 | - * @since 4.08 | |
| 301 | - * | |
| 302 | - * @return array|false | |
| 303 | - */ | |
| 304 | - protected static function get_primary_license_info() { | |
| 305 | - $installed_addons = apply_filters( 'frm_installed_addons', array() ); | |
| 306 | - if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) { | |
| 307 | - return false; | |
| 308 | - } | |
| 309 | - $installed_addons = array( | |
| 310 | - 'formidable_pro' => $installed_addons['formidable_pro'], | |
| 311 | - ); | |
| 312 | - | |
| 313 | - return self::fill_update_addon_info( $installed_addons ); | |
| 314 | - } | |
| 315 | - | |
| 316 | - /** | |
| 317 | 179 | * @since 3.04.03 |
| 318 | 180 | */ |
| 319 | 181 | public static function check_update( $transient ) { |
| 320 | - if ( ! FrmAppHelper::pro_is_installed() ) { | |
| 321 | - // Don't make any changes if only Lite is installed. | |
| 322 | - return $transient; | |
| 323 | - } | |
| 324 | - | |
| 325 | 182 | if ( ! is_object( $transient ) ) { |
| 326 | 183 | $transient = new stdClass(); |
| 327 | 184 | } |
| 328 | 185 | |
| @@ -330,12 +187,14 @@ | ||
| 330 | 187 | if ( empty( $installed_addons ) ) { |
| 331 | 188 | return $transient; |
| 332 | 189 | } |
| 333 | 190 | |
| 334 | - $version_info = self::fill_update_addon_info( $installed_addons ); | |
| 191 | + $version_info = self::fill_update_addon_info( $installed_addons ); | |
| 192 | + | |
| 335 | 193 | $transient->last_checked = time(); |
| 336 | - $wp_plugins = self::get_plugins(); | |
| 337 | 194 | |
| 195 | + $wp_plugins = get_plugins(); | |
| 196 | + | |
| 338 | 197 | foreach ( $version_info as $id => $plugin ) { |
| 339 | 198 | $plugin = (object) $plugin; |
| 340 | 199 | |
| 341 | 200 | if ( ! isset( $plugin->new_version ) || ! isset( $plugin->package ) ) { |
| @@ -355,10 +214,10 @@ | ||
| 355 | 214 | $wp_plugin = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array(); |
| 356 | 215 | $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0'; |
| 357 | 216 | |
| 358 | 217 | if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) { |
| 359 | - $slug = explode( '/', $folder ); | |
| 360 | - $plugin->slug = $slug[0]; | |
| 218 | + $slug = explode( '/', $folder ); | |
| 219 | + $plugin->slug = $slug[0]; | |
| 361 | 220 | $transient->response[ $folder ] = $plugin; |
| 362 | 221 | } |
| 363 | 222 | |
| 364 | 223 | $transient->checked[ $folder ] = $wp_version; |
| @@ -368,33 +227,20 @@ | ||
| 368 | 227 | return $transient; |
| 369 | 228 | } |
| 370 | 229 | |
| 371 | 230 | /** |
| 372 | - * Copy of FrmAppHelper::get_plugins. | |
| 373 | - * Because this gets called on "pre_set_site_transient_update_plugins" an old version of FrmAppHelper may be loaded on plugin update. | |
| 374 | - * This means that trying to access FrmAppHelper::get_plugins when upgrading from a Lite version before v5.5 results in a one-off error. | |
| 231 | + * Check if a plugin is installed before showing an update for it | |
| 375 | 232 | * |
| 376 | - * @since 5.5.2 | |
| 377 | - * @return array | |
| 233 | + * @since 3.05 | |
| 234 | + * @param string $plugin - the folder/filename.php for a plugin | |
| 235 | + * @return bool - True if installed | |
| 378 | 236 | */ |
| 379 | - protected static function get_plugins() { | |
| 237 | + private static function is_installed( $plugin ) { | |
| 380 | 238 | if ( ! function_exists( 'get_plugins' ) ) { |
| 381 | 239 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 382 | 240 | } |
| 383 | - return get_plugins(); | |
| 384 | - } | |
| 385 | 241 | |
| 386 | - /** | |
| 387 | - * Check if a plugin is installed before showing an update for it | |
| 388 | - * | |
| 389 | - * @since 3.05 | |
| 390 | - * | |
| 391 | - * @param string $plugin - the folder/filename.php for a plugin | |
| 392 | - * | |
| 393 | - * @return bool - True if installed | |
| 394 | - */ | |
| 395 | - protected static function is_installed( $plugin ) { | |
| 396 | - $all_plugins = self::get_plugins(); | |
| 242 | + $all_plugins = get_plugins(); | |
| 397 | 243 | return isset( $all_plugins[ $plugin ] ); |
| 398 | 244 | } |
| 399 | 245 | |
| 400 | 246 | /** |
| @@ -403,9 +249,9 @@ | ||
| 403 | 249 | * @param array $installed_addons |
| 404 | 250 | * |
| 405 | 251 | * @return array |
| 406 | 252 | */ |
| 407 | - protected static function fill_update_addon_info( $installed_addons ) { | |
| 253 | + private static function fill_update_addon_info( $installed_addons ) { | |
| 408 | 254 | $checked_licenses = array(); |
| 409 | 255 | $version_info = array(); |
| 410 | 256 | |
| 411 | 257 | foreach ( $installed_addons as $addon ) { |
| @@ -453,16 +299,22 @@ | ||
| 453 | 299 | /** |
| 454 | 300 | * Get the action link for an addon that isn't active. |
| 455 | 301 | * |
| 456 | 302 | * @since 3.06.03 |
| 457 | - * @param string $plugin The plugin slug | |
| 303 | + * @param string $addon The plugin slug | |
| 458 | 304 | * @return array |
| 459 | 305 | */ |
| 460 | 306 | public static function install_link( $plugin ) { |
| 461 | - $link = array(); | |
| 462 | - $addon = self::get_addon( $plugin ); | |
| 307 | + $link = array(); | |
| 308 | + $addons = self::get_api_addons(); | |
| 309 | + self::prepare_addons( $addons ); | |
| 463 | 310 | |
| 464 | - if ( $addon ) { | |
| 311 | + foreach ( $addons as $addon ) { | |
| 312 | + $slug = explode( '/', $addon['plugin'] ); | |
| 313 | + if ( $slug[0] !== 'formidable-' . $plugin ) { | |
| 314 | + continue; | |
| 315 | + } | |
| 316 | + | |
| 465 | 317 | if ( $addon['status']['type'] === 'installed' && ! empty( $addon['activate_url'] ) ) { |
| 466 | 318 | $link = array( |
| 467 | 319 | 'url' => $addon['plugin'], |
| 468 | 320 | 'class' => 'frm-activate-addon', |
| @@ -471,68 +323,23 @@ | ||
| 471 | 323 | $link = array( |
| 472 | 324 | 'url' => $addon['url'], |
| 473 | 325 | 'class' => 'frm-install-addon', |
| 474 | 326 | ); |
| 475 | - } elseif ( isset( $addon['categories'] ) && ! empty( $addon['categories'] ) ) { | |
| 476 | - $link = array( | |
| 477 | - 'categories' => $addon['categories'], | |
| 478 | - ); | |
| 479 | 327 | } |
| 480 | 328 | |
| 481 | - if ( ! empty( $link ) ) { | |
| 482 | - $link['status'] = $addon['status']['type']; | |
| 483 | - } | |
| 484 | - } elseif ( current_user_can( 'activate_plugins' ) && self::is_installed( 'formidable-' . $plugin . '/formidable-' . $plugin . '.php' ) ) { | |
| 485 | - $link = array( | |
| 486 | - 'url' => 'formidable-' . $plugin . '/formidable-' . $plugin . '.php', | |
| 487 | - 'class' => 'frm-activate-addon', | |
| 488 | - ); | |
| 329 | + return $link; | |
| 489 | 330 | } |
| 490 | - | |
| 491 | - return $link; | |
| 492 | 331 | } |
| 493 | 332 | |
| 494 | 333 | /** |
| 495 | - * @since 4.09 | |
| 496 | - * @param string $plugin The plugin slug | |
| 497 | - * @return array|false | |
| 498 | - */ | |
| 499 | - protected static function get_addon( $plugin ) { | |
| 500 | - $addons = self::get_api_addons(); | |
| 501 | - self::prepare_addons( $addons ); | |
| 502 | - foreach ( $addons as $addon ) { | |
| 503 | - $slug = explode( '/', $addon['plugin'] ); | |
| 504 | - if ( $slug[0] === 'formidable-' . $plugin ) { | |
| 505 | - return $addon; | |
| 506 | - } | |
| 507 | - } | |
| 508 | - return false; | |
| 509 | - } | |
| 510 | - | |
| 511 | - /** | |
| 512 | - * @since 4.09 | |
| 513 | - * @return string | |
| 514 | - */ | |
| 515 | - protected static function get_license_type() { | |
| 516 | - $license_type = ''; | |
| 517 | - $addons = self::get_api_addons(); | |
| 518 | - if ( isset( $addons['error'] ) && isset( $addons['error']['type'] ) ) { | |
| 519 | - $license_type = $addons['error']['type']; | |
| 520 | - } | |
| 521 | - return $license_type; | |
| 522 | - } | |
| 523 | - | |
| 524 | - /** | |
| 525 | 334 | * @since 3.04.03 |
| 526 | - * | |
| 527 | 335 | * @param array $addons |
| 528 | 336 | * @param object $license The FrmAddon object |
| 529 | - * | |
| 530 | 337 | * @return array |
| 531 | 338 | */ |
| 532 | 339 | public static function get_addon_for_license( $addons, $license ) { |
| 533 | 340 | $download_id = $license->download_id; |
| 534 | - $plugin = array(); | |
| 341 | + $plugin = array(); | |
| 535 | 342 | if ( empty( $download_id ) && ! empty( $addons ) ) { |
| 536 | 343 | foreach ( $addons as $addon ) { |
| 537 | 344 | if ( strtolower( $license->plugin_name ) == strtolower( $addon['title'] ) ) { |
| 538 | 345 | return $addon; |
| @@ -544,12 +351,9 @@ | ||
| 544 | 351 | |
| 545 | 352 | return $plugin; |
| 546 | 353 | } |
| 547 | 354 | |
| 548 | - /** | |
| 549 | - * @return void | |
| 550 | - */ | |
| 551 | - protected static function prepare_addons( &$addons ) { | |
| 355 | + private static function prepare_addons( &$addons ) { | |
| 552 | 356 | $activate_url = ''; |
| 553 | 357 | if ( current_user_can( 'activate_plugins' ) ) { |
| 554 | 358 | $activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) ); |
| 555 | 359 | } |
| @@ -556,9 +360,9 @@ | ||
| 556 | 360 | |
| 557 | 361 | $loop_addons = $addons; |
| 558 | 362 | foreach ( $loop_addons as $id => $addon ) { |
| 559 | 363 | if ( is_numeric( $id ) ) { |
| 560 | - $slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] ); | |
| 364 | + $slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] ); | |
| 561 | 365 | $file_name = $addon['plugin']; |
| 562 | 366 | } else { |
| 563 | 367 | $slug = $id; |
| 564 | 368 | if ( isset( $addon['file'] ) ) { |
| @@ -566,28 +370,18 @@ | ||
| 566 | 370 | } else { |
| 567 | 371 | $base_file = 'formidable-' . $slug; |
| 568 | 372 | } |
| 569 | 373 | $file_name = $base_file . '/' . $base_file . '.php'; |
| 570 | - if ( ! isset( $addon['plugin'] ) ) { | |
| 571 | - $addon['plugin'] = $file_name; | |
| 572 | - } | |
| 573 | 374 | } |
| 574 | 375 | |
| 575 | - $addon['installed'] = self::is_installed( $file_name ); | |
| 576 | - if ( $addon['installed'] && 'formidable-views/formidable-views.php' === $file_name ) { | |
| 577 | - $active_views_version = self::get_active_views_version(); | |
| 578 | - if ( false !== $active_views_version && $slug !== $active_views_version ) { | |
| 579 | - $addon['installed'] = false; | |
| 580 | - } | |
| 581 | - } | |
| 582 | - | |
| 376 | + $addon['installed'] = self::is_installed( $file_name ); | |
| 583 | 377 | $addon['activate_url'] = ''; |
| 584 | 378 | |
| 585 | - if ( $addon['installed'] && ! empty( $activate_url ) && ! self::is_plugin_active( $file_name, $slug ) ) { | |
| 379 | + if ( $addon['installed'] && ! empty( $activate_url ) && ! is_plugin_active( $file_name ) ) { | |
| 586 | 380 | $addon['activate_url'] = add_query_arg( |
| 587 | 381 | array( |
| 588 | - '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ), | |
| 589 | - 'plugin' => $file_name, | |
| 382 | + '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ), | |
| 383 | + 'plugin' => $file_name, | |
| 590 | 384 | ), |
| 591 | 385 | $activate_url |
| 592 | 386 | ); |
| 593 | 387 | } |
| @@ -607,45 +401,22 @@ | ||
| 607 | 401 | } |
| 608 | 402 | } |
| 609 | 403 | |
| 610 | 404 | /** |
| 611 | - * @return bool | |
| 612 | - */ | |
| 613 | - private static function is_plugin_active( $file_name, $slug ) { | |
| 614 | - if ( 'formidable-views/formidable-views.php' === $file_name ) { | |
| 615 | - return self::get_active_views_version() === $slug; | |
| 616 | - } | |
| 617 | - return is_plugin_active( $file_name ); | |
| 618 | - } | |
| 619 | - | |
| 620 | - /** | |
| 621 | - * @return string|false either 'visual-views' or 'views', false if one is not found. | |
| 622 | - */ | |
| 623 | - private static function get_active_views_version() { | |
| 624 | - if ( ! is_callable( 'FrmViewsAppHelper::plugin_version' ) ) { | |
| 625 | - return false; | |
| 626 | - } | |
| 627 | - $plugin_version = FrmViewsAppHelper::plugin_version(); | |
| 628 | - return version_compare( $plugin_version, '5.0', '>=' ) ? 'visual-views' : 'views'; | |
| 629 | - } | |
| 630 | - | |
| 631 | - /** | |
| 632 | 405 | * @since 3.04.02 |
| 633 | - * | |
| 634 | - * @return void | |
| 635 | 406 | */ |
| 636 | - protected static function prepare_addon_link( &$link ) { | |
| 407 | + private static function prepare_addon_link( &$link ) { | |
| 637 | 408 | $site_url = 'https://formidableforms.com/'; |
| 638 | 409 | if ( strpos( $link, 'http' ) !== 0 ) { |
| 639 | 410 | $link = $site_url . $link; |
| 640 | 411 | } |
| 641 | - $link = FrmAppHelper::make_affiliate_url( $link ); | |
| 412 | + $link = FrmAppHelper::make_affiliate_url( $link ); | |
| 642 | 413 | $query_args = array( |
| 643 | 414 | 'utm_source' => 'WordPress', |
| 644 | 415 | 'utm_medium' => 'addons', |
| 645 | 416 | 'utm_campaign' => 'liteplugin', |
| 646 | 417 | ); |
| 647 | - $link = add_query_arg( $query_args, $link ); | |
| 418 | + $link = add_query_arg( $query_args, $link ); | |
| 648 | 419 | } |
| 649 | 420 | |
| 650 | 421 | /** |
| 651 | 422 | * Add the status to the addon array. Status options are: |
| @@ -651,12 +422,10 @@ | ||
| 651 | 422 | * Add the status to the addon array. Status options are: |
| 652 | 423 | * installed, active, not installed |
| 653 | 424 | * |
| 654 | 425 | * @since 3.04.02 |
| 655 | - * | |
| 656 | - * @return void | |
| 657 | 426 | */ |
| 658 | - protected static function set_addon_status( &$addon ) { | |
| 427 | + private static function set_addon_status( &$addon ) { | |
| 659 | 428 | if ( ! empty( $addon['activate_url'] ) ) { |
| 660 | 429 | $addon['status'] = array( |
| 661 | 430 | 'type' => 'installed', |
| 662 | 431 | 'label' => __( 'Installed', 'formidable' ), |
| @@ -673,13 +442,10 @@ | ||
| 673 | 442 | ); |
| 674 | 443 | } |
| 675 | 444 | } |
| 676 | 445 | |
| 677 | - /** | |
| 678 | - * @return void | |
| 679 | - */ | |
| 680 | 446 | public static function upgrade_to_pro() { |
| 681 | - FrmAppHelper::include_svg(); | |
| 447 | + $pro_pricing = self::prepare_pro_info(); | |
| 682 | 448 | |
| 683 | 449 | $link_parts = array( |
| 684 | 450 | 'medium' => 'upgrade', |
| 685 | 451 | 'content' => 'button', |
| @@ -690,9 +456,9 @@ | ||
| 690 | 456 | array( |
| 691 | 457 | 'label' => 'Display form data with virtually limitless views', |
| 692 | 458 | 'link' => array( |
| 693 | 459 | 'content' => 'views', |
| 694 | - 'param' => 'views-display-form-data', | |
| 460 | + 'anchor' => 'feature-display-form-data-views', | |
| 695 | 461 | ), |
| 696 | 462 | 'lite' => false, |
| 697 | 463 | ), |
| 698 | 464 | array( |
| @@ -698,9 +464,9 @@ | ||
| 698 | 464 | array( |
| 699 | 465 | 'label' => 'Generate graphs and stats based on your submitted data', |
| 700 | 466 | 'link' => array( |
| 701 | 467 | 'content' => 'graphs', |
| 702 | - 'param' => 'statistics-graphs-wordpress-forms', | |
| 468 | + 'anchor' => 'feature-create-a-graph-wordpress-forms', | |
| 703 | 469 | ), |
| 704 | 470 | 'lite' => false, |
| 705 | 471 | ), |
| 706 | 472 | ), |
| @@ -708,9 +474,9 @@ | ||
| 708 | 474 | array( |
| 709 | 475 | 'label' => 'Import entries from a CSV', |
| 710 | 476 | 'link' => array( |
| 711 | 477 | 'content' => 'import-entries', |
| 712 | - 'param' => 'importing-exporting-wordpress-forms', | |
| 478 | + 'anchor' => 'feature-importing-exporting-wordpress-forms', | |
| 713 | 479 | ), |
| 714 | 480 | 'lite' => false, |
| 715 | 481 | ), |
| 716 | 482 | array( |
| @@ -716,9 +482,9 @@ | ||
| 716 | 482 | array( |
| 717 | 483 | 'label' => 'Logged-in users can save drafts and return later', |
| 718 | 484 | 'link' => array( |
| 719 | 485 | 'content' => 'save-drafts', |
| 720 | - 'param' => 'save-drafts-wordpress-form', | |
| 486 | + 'anchor' => 'feature-save-and-continue-partial-submissions', | |
| 721 | 487 | ), |
| 722 | 488 | 'lite' => false, |
| 723 | 489 | ), |
| 724 | 490 | array( |
| @@ -724,9 +490,9 @@ | ||
| 724 | 490 | array( |
| 725 | 491 | 'label' => 'Flexibly and powerfully view, edit, and delete entries from anywhere on your site', |
| 726 | 492 | 'link' => array( |
| 727 | 493 | 'content' => 'front-edit', |
| 728 | - 'param' => 'wordpress-front-end-editing', | |
| 494 | + 'anchor' => 'feature-front-end-editing-wordpress', | |
| 729 | 495 | ), |
| 730 | 496 | 'lite' => false, |
| 731 | 497 | ), |
| 732 | 498 | array( |
| @@ -742,9 +508,9 @@ | ||
| 742 | 508 | array( |
| 743 | 509 | 'label' => 'Save a calculated value into a field', |
| 744 | 510 | 'link' => array( |
| 745 | 511 | 'content' => 'calculations', |
| 746 | - 'param' => 'field-calculations-wordpress-form', | |
| 512 | + 'anchor' => 'feature-wordpress-calculated-fields-form', | |
| 747 | 513 | ), |
| 748 | 514 | 'lite' => false, |
| 749 | 515 | ), |
| 750 | 516 | array( |
| @@ -750,9 +516,9 @@ | ||
| 750 | 516 | array( |
| 751 | 517 | 'label' => 'Allow multiple file uploads', |
| 752 | 518 | 'link' => array( |
| 753 | 519 | 'content' => 'file-uploads', |
| 754 | - 'param' => 'wordpress-multi-file-upload-fields', | |
| 520 | + 'anchor' => 'feature-wordpress-multiple-file-upload-form', | |
| 755 | 521 | ), |
| 756 | 522 | 'lite' => false, |
| 757 | 523 | ), |
| 758 | 524 | array( |
| @@ -758,9 +524,9 @@ | ||
| 758 | 524 | array( |
| 759 | 525 | 'label' => 'Repeat sections of fields', |
| 760 | 526 | 'link' => array( |
| 761 | 527 | 'content' => 'repeaters', |
| 762 | - 'param' => 'repeatable-sections-forms', | |
| 528 | + 'anchor' => 'feature-dynamically-add-form-fields', | |
| 763 | 529 | ), |
| 764 | 530 | 'lite' => false, |
| 765 | 531 | ), |
| 766 | 532 | array( |
| @@ -766,9 +532,9 @@ | ||
| 766 | 532 | array( |
| 767 | 533 | 'label' => 'Hide and show fields conditionally based on other fields or the user\'s role', |
| 768 | 534 | 'link' => array( |
| 769 | 535 | 'content' => 'conditional-logic', |
| 770 | - 'param' => 'conditional-logic-wordpress-forms', | |
| 536 | + 'anchor' => 'feature-conditional-logic-wordpress-forms', | |
| 771 | 537 | ), |
| 772 | 538 | 'lite' => false, |
| 773 | 539 | ), |
| 774 | 540 | array( |
| @@ -774,9 +540,9 @@ | ||
| 774 | 540 | array( |
| 775 | 541 | 'label' => 'Confirmation fields', |
| 776 | 542 | 'link' => array( |
| 777 | 543 | 'content' => 'confirmation-fields', |
| 778 | - 'param' => 'confirmation-fields-wordpress-forms', | |
| 544 | + 'anchor' => 'feature-confirm-email-address-password-wordpress-form', | |
| 779 | 545 | ), |
| 780 | 546 | 'lite' => false, |
| 781 | 547 | ), |
| 782 | 548 | array( |
| @@ -782,9 +548,9 @@ | ||
| 782 | 548 | array( |
| 783 | 549 | 'label' => 'Multi-paged forms', |
| 784 | 550 | 'link' => array( |
| 785 | 551 | 'content' => 'page-breaks', |
| 786 | - 'param' => 'wordpress-multi-page-forms', | |
| 552 | + 'anchor' => 'feature-wordpress-multi-step-form', | |
| 787 | 553 | ), |
| 788 | 554 | 'lite' => false, |
| 789 | 555 | ), |
| 790 | 556 | array( |
| @@ -798,9 +564,9 @@ | ||
| 798 | 564 | array( |
| 799 | 565 | 'label' => 'Drag & Drop Form building', |
| 800 | 566 | 'link' => array( |
| 801 | 567 | 'content' => 'drag-drop', |
| 802 | - 'param' => 'drag-drop-forms', | |
| 568 | + 'anchor' => 'feature-drag-drop-form-builder', | |
| 803 | 569 | ), |
| 804 | 570 | 'lite' => true, |
| 805 | 571 | ), |
| 806 | 572 | array( |
| @@ -806,9 +572,9 @@ | ||
| 806 | 572 | array( |
| 807 | 573 | 'label' => 'Create forms from Templates', |
| 808 | 574 | 'link' => array( |
| 809 | 575 | 'content' => 'form-templates', |
| 810 | - 'param' => 'wordpress-form-templates', | |
| 576 | + 'anchor' => 'feature-wordpress-form-templates', | |
| 811 | 577 | ), |
| 812 | 578 | 'lite' => true, |
| 813 | 579 | ), |
| 814 | 580 | array( |
| @@ -814,9 +580,9 @@ | ||
| 814 | 580 | array( |
| 815 | 581 | 'label' => 'Import and export forms with XML', |
| 816 | 582 | 'link' => array( |
| 817 | 583 | 'content' => 'import', |
| 818 | - 'param' => 'importing-exporting-wordpress-forms', | |
| 584 | + 'anchor' => 'feature-importing-exporting-wordpress-forms', | |
| 819 | 585 | ), |
| 820 | 586 | 'lite' => true, |
| 821 | 587 | ), |
| 822 | 588 | array( |
| @@ -828,8 +594,9 @@ | ||
| 828 | 594 | array( |
| 829 | 595 | 'label' => 'Conditionally send your email notifications based on values in your form', |
| 830 | 596 | 'link' => array( |
| 831 | 597 | 'content' => 'conditional-emails', |
| 598 | + 'anchor' => 'feature-conditional-logic-wordpress-forms', | |
| 832 | 599 | ), |
| 833 | 600 | 'lite' => false, |
| 834 | 601 | ), |
| 835 | 602 | array( |
| @@ -835,9 +602,9 @@ | ||
| 835 | 602 | array( |
| 836 | 603 | 'label' => 'Create and edit WordPress posts or custom posts from the front-end', |
| 837 | 604 | 'link' => array( |
| 838 | 605 | 'content' => 'create-posts', |
| 839 | - 'param' => 'create-posts-pages-wordpress-forms', | |
| 606 | + 'anchor' => 'feature-user-submitted-posts-wordpress-forms', | |
| 840 | 607 | ), |
| 841 | 608 | 'lite' => false, |
| 842 | 609 | ), |
| 843 | 610 | array( |
| @@ -843,9 +610,9 @@ | ||
| 843 | 610 | array( |
| 844 | 611 | 'label' => 'Send multiple emails and autoresponders', |
| 845 | 612 | 'link' => array( |
| 846 | 613 | 'content' => 'multiple-emails', |
| 847 | - 'param' => 'virtually-unlimited-emails', | |
| 614 | + 'anchor' => 'feature-email-autoresponders-wordpress', | |
| 848 | 615 | ), |
| 849 | 616 | 'lite' => true, |
| 850 | 617 | ), |
| 851 | 618 | ), |
| @@ -853,9 +620,9 @@ | ||
| 853 | 620 | array( |
| 854 | 621 | 'label' => 'Create Multiple styles for different forms', |
| 855 | 622 | 'link' => array( |
| 856 | 623 | 'content' => 'multiple-styles', |
| 857 | - 'param' => 'wordpress-visual-form-styler', | |
| 624 | + 'anchor' => 'feature-wordpress-visual-form-styler', | |
| 858 | 625 | ), |
| 859 | 626 | 'lite' => false, |
| 860 | 627 | ), |
| 861 | 628 | array( |
| @@ -861,9 +628,9 @@ | ||
| 861 | 628 | array( |
| 862 | 629 | 'label' => 'Customizable layout with CSS classes', |
| 863 | 630 | 'link' => array( |
| 864 | 631 | 'content' => 'form-layout', |
| 865 | - 'param' => 'wordpress-mobile-friendly-forms', | |
| 632 | + 'anchor' => 'feature-wordpress-mobile-friendly-responsive-forms', | |
| 866 | 633 | ), |
| 867 | 634 | 'lite' => true, |
| 868 | 635 | ), |
| 869 | 636 | array( |
| @@ -869,9 +636,9 @@ | ||
| 869 | 636 | array( |
| 870 | 637 | 'label' => 'Customize the HTML for your forms', |
| 871 | 638 | 'link' => array( |
| 872 | 639 | 'content' => 'custom-html', |
| 873 | - 'param' => 'customizable-html-wordpress-form', | |
| 640 | + 'anchor' => 'feature-customize-form-html-wordpress', | |
| 874 | 641 | ), |
| 875 | 642 | 'lite' => true, |
| 876 | 643 | ), |
| 877 | 644 | array( |
| @@ -883,103 +650,70 @@ | ||
| 883 | 650 | |
| 884 | 651 | include( FrmAppHelper::plugin_path() . '/classes/views/addons/upgrade_to_pro.php' ); |
| 885 | 652 | } |
| 886 | 653 | |
| 887 | - /** | |
| 888 | - * Install Pro after connection with Formidable. | |
| 889 | - * | |
| 890 | - * @since 4.02.05 | |
| 891 | - * | |
| 892 | - * @return void | |
| 893 | - */ | |
| 894 | - public static function connect_pro() { | |
| 895 | - FrmAppHelper::permission_check( 'install_plugins' ); | |
| 896 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 897 | - | |
| 898 | - $url = self::get_current_plugin(); | |
| 899 | - if ( FrmAppHelper::pro_is_installed() || empty( $url ) ) { | |
| 900 | - wp_die(); | |
| 901 | - } | |
| 902 | - | |
| 903 | - $response = array(); | |
| 904 | - | |
| 905 | - // It's already installed and active. | |
| 906 | - $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true ); | |
| 907 | - if ( is_wp_error( $active ) ) { | |
| 908 | - // The plugin was installed, but not active. Download it now. | |
| 909 | - self::ajax_install_addon(); | |
| 910 | - } else { | |
| 911 | - $response['active'] = true; | |
| 912 | - $response['success'] = true; | |
| 913 | - } | |
| 914 | - | |
| 915 | - echo json_encode( $response ); | |
| 916 | - wp_die(); | |
| 654 | + private static function prepare_pro_info() { | |
| 655 | + return array( | |
| 656 | + 'personal' => array( | |
| 657 | + 'id' => 2, | |
| 658 | + 'download' => 19367654, | |
| 659 | + 'price' => '49.00', | |
| 660 | + 'name' => 'Personal', | |
| 661 | + ), | |
| 662 | + 'professional' => array( | |
| 663 | + 'id' => 0, | |
| 664 | + 'download' => 19367001, | |
| 665 | + 'price' => '99.00', | |
| 666 | + 'name' => 'Creator', | |
| 667 | + ), | |
| 668 | + 'smallbusiness' => array( | |
| 669 | + 'id' => 0, | |
| 670 | + 'download' => 19366995, | |
| 671 | + 'price' => '199.00', | |
| 672 | + 'name' => 'Business', | |
| 673 | + ), | |
| 674 | + 'enterprise' => array( | |
| 675 | + 'id' => 0, | |
| 676 | + 'download' => 19366992, | |
| 677 | + 'price' => '399.00', | |
| 678 | + 'name' => 'Elite', | |
| 679 | + ), | |
| 680 | + ); | |
| 917 | 681 | } |
| 918 | 682 | |
| 919 | 683 | /** |
| 920 | - * @since 5.5.2 | |
| 921 | - * | |
| 922 | - * @param string $plugin | |
| 923 | - * @param string $redirect | |
| 924 | - * @param bool $network_wide | |
| 925 | - * @param bool $silent | |
| 926 | - * @return null|WP_Error Null on success, WP_Error on invalid file. | |
| 684 | + * @since 3.04.02 | |
| 927 | 685 | */ |
| 928 | - protected static function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) { | |
| 929 | - if ( ! function_exists( 'activate_plugin' ) ) { | |
| 930 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 931 | - } | |
| 932 | - return activate_plugin( $plugin, $redirect, $network_wide, $silent ); | |
| 933 | - } | |
| 686 | + public static function ajax_install_addon() { | |
| 934 | 687 | |
| 935 | - /** | |
| 936 | - * @since 5.0.10 | |
| 937 | - * | |
| 938 | - * @return string | |
| 939 | - */ | |
| 940 | - protected static function get_current_plugin() { | |
| 941 | - if ( ! isset( self::$plugin ) ) { | |
| 942 | - self::$plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'esc_url_raw' ); | |
| 943 | - } | |
| 944 | - return self::$plugin; | |
| 945 | - } | |
| 688 | + self::install_addon_permissions(); | |
| 946 | 689 | |
| 947 | - /** | |
| 948 | - * @since 4.08 | |
| 949 | - */ | |
| 950 | - protected static function download_and_activate() { | |
| 951 | - if ( is_admin() ) { | |
| 952 | - FrmAppHelper::set_current_screen_and_hook_suffix(); | |
| 953 | - } | |
| 690 | + // Set the current screen to avoid undefined notices. | |
| 691 | + global $hook_suffix; | |
| 692 | + set_current_screen(); | |
| 954 | 693 | |
| 955 | 694 | self::maybe_show_cred_form(); |
| 956 | 695 | |
| 957 | 696 | $installed = self::install_addon(); |
| 958 | - if ( is_array( $installed ) && isset( $installed['message'] ) ) { | |
| 959 | - return $installed; | |
| 960 | - } | |
| 961 | 697 | self::maybe_activate_addon( $installed ); |
| 698 | + | |
| 699 | + // Send back a response. | |
| 700 | + echo json_encode( __( 'Your plugin has been installed. Please reload the page to see more options.', 'formidable' ) ); | |
| 701 | + wp_die(); | |
| 962 | 702 | } |
| 963 | 703 | |
| 964 | 704 | /** |
| 965 | 705 | * @since 3.04.02 |
| 966 | - * | |
| 967 | - * @return void | |
| 968 | 706 | */ |
| 969 | - protected static function maybe_show_cred_form() { | |
| 970 | - if ( ! function_exists( 'request_filesystem_credentials' ) ) { | |
| 971 | - include_once( ABSPATH . 'wp-admin/includes/file.php' ); | |
| 972 | - } | |
| 973 | - | |
| 707 | + private static function maybe_show_cred_form() { | |
| 974 | 708 | // Start output bufferring to catch the filesystem form if credentials are needed. |
| 975 | 709 | ob_start(); |
| 976 | 710 | |
| 977 | 711 | $show_form = false; |
| 978 | - $method = ''; | |
| 979 | - $url = add_query_arg( array( 'page' => 'formidable-settings' ), admin_url( 'admin.php' ) ); | |
| 980 | - $url = esc_url_raw( $url ); | |
| 981 | - $creds = request_filesystem_credentials( $url, $method, false, false, null ); | |
| 712 | + $method = ''; | |
| 713 | + $url = add_query_arg( array( 'page' => 'formidable-settings' ), admin_url( 'admin.php' ) ); | |
| 714 | + $url = esc_url_raw( $url ); | |
| 715 | + $creds = request_filesystem_credentials( $url, $method, false, false, null ); | |
| 982 | 716 | |
| 983 | 717 | if ( false === $creds ) { |
| 984 | 718 | $show_form = true; |
| 985 | 719 | } elseif ( ! WP_Filesystem( $creds ) ) { |
| @@ -987,17 +721,12 @@ | ||
| 987 | 721 | $show_form = true; |
| 988 | 722 | } |
| 989 | 723 | |
| 990 | 724 | if ( $show_form ) { |
| 991 | - $form = ob_get_clean(); | |
| 992 | - $message = __( 'Sorry, your site requires FTP authentication. Please download plugins from FormidableForms.com and install them manually.', 'formidable' ); | |
| 993 | - $data = $form; | |
| 994 | - $response = array( | |
| 995 | - 'success' => false, | |
| 996 | - 'message' => $message, | |
| 997 | - 'form' => $form, | |
| 998 | - ); | |
| 999 | - wp_send_json( $response ); | |
| 725 | + $form = ob_get_clean(); | |
| 726 | + //TODO: test this: echo json_encode( array( 'form' => $form ) ); | |
| 727 | + echo json_encode( array( 'form' => __( 'Sorry, you\'re site requires FTP authentication. Please install plugins manaully.', 'formidable' ) ) ); | |
| 728 | + wp_die(); | |
| 1000 | 729 | } |
| 1001 | 730 | |
| 1002 | 731 | ob_end_clean(); |
| 1003 | 732 | } |
| @@ -1002,42 +731,18 @@ | ||
| 1002 | 731 | ob_end_clean(); |
| 1003 | 732 | } |
| 1004 | 733 | |
| 1005 | 734 | /** |
| 1006 | - * Checks if an addon download url is allowed. | |
| 1007 | - * | |
| 1008 | - * @since 6.2 | |
| 1009 | - * | |
| 1010 | - * @param string $download_url | |
| 1011 | - * | |
| 1012 | - * @return bool | |
| 1013 | - */ | |
| 1014 | - public static function url_is_allowed( $download_url ) { | |
| 1015 | - return ( | |
| 1016 | - FrmAppHelper::validate_url_is_in_s3_bucket( $download_url, 'zip' ) || in_array( $download_url, self::allowed_external_urls(), true ) | |
| 1017 | - ); | |
| 1018 | - } | |
| 1019 | - | |
| 1020 | - /** | |
| 1021 | 735 | * We do not need any extra credentials if we have gotten this far, |
| 1022 | 736 | * so let's install the plugin. |
| 1023 | 737 | * |
| 1024 | 738 | * @since 3.04.02 |
| 1025 | 739 | */ |
| 1026 | - protected static function install_addon() { | |
| 1027 | - FrmAppHelper::permission_check( 'install_plugins' ); | |
| 740 | + private static function install_addon() { | |
| 741 | + require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); | |
| 1028 | 742 | |
| 1029 | - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | |
| 743 | + $download_url = esc_url_raw( $_POST['plugin'] ); | |
| 1030 | 744 | |
| 1031 | - $download_url = self::get_current_plugin(); | |
| 1032 | - | |
| 1033 | - if ( ! self::url_is_allowed( $download_url ) ) { | |
| 1034 | - return array( | |
| 1035 | - 'message' => 'Plugin URL is not valid', | |
| 1036 | - 'success' => false, | |
| 1037 | - ); | |
| 1038 | - } | |
| 1039 | - | |
| 1040 | 745 | // Create the plugin upgrader with our custom skin. |
| 1041 | 746 | $installer = new Plugin_Upgrader( new FrmInstallerSkin() ); |
| 1042 | 747 | $installer->install( $download_url ); |
| 1043 | 748 | |
| @@ -1042,92 +747,45 @@ | ||
| 1042 | 747 | $installer->install( $download_url ); |
| 1043 | 748 | |
| 1044 | 749 | // Flush the cache and return the newly installed plugin basename. |
| 1045 | 750 | wp_cache_flush(); |
| 1046 | - | |
| 1047 | - $plugin = $installer->plugin_info(); | |
| 1048 | - if ( ! $plugin ) { | |
| 1049 | - return array( | |
| 1050 | - 'message' => 'Plugin was not installed. ' . $installer->result, | |
| 1051 | - 'success' => false, | |
| 1052 | - ); | |
| 1053 | - } | |
| 1054 | - return $plugin; | |
| 751 | + return $installer->plugin_info(); | |
| 1055 | 752 | } |
| 1056 | 753 | |
| 1057 | 754 | /** |
| 1058 | 755 | * @since 3.06.03 |
| 1059 | - * | |
| 1060 | - * @return void | |
| 1061 | 756 | */ |
| 1062 | 757 | public static function ajax_activate_addon() { |
| 1063 | 758 | |
| 1064 | 759 | self::install_addon_permissions(); |
| 1065 | 760 | |
| 1066 | - FrmAppHelper::set_current_screen_and_hook_suffix(); | |
| 761 | + // Set the current screen to avoid undefined notices. | |
| 762 | + global $hook_suffix; | |
| 763 | + set_current_screen(); | |
| 1067 | 764 | |
| 1068 | 765 | $plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' ); |
| 1069 | 766 | self::maybe_activate_addon( $plugin ); |
| 1070 | 767 | |
| 1071 | - echo json_encode( self::get_addon_activation_response() ); | |
| 768 | + // Send back a response. | |
| 769 | + echo json_encode( __( 'Your plugin has been activated. Please reload the page to see more options.', 'formidable' ) ); | |
| 1072 | 770 | wp_die(); |
| 1073 | 771 | } |
| 1074 | 772 | |
| 1075 | 773 | /** |
| 1076 | - * @return array | |
| 1077 | - */ | |
| 1078 | - private static function get_addon_activation_response() { | |
| 1079 | - $activating_page = self::get_activating_page(); | |
| 1080 | - | |
| 1081 | - $response = array( | |
| 1082 | - 'message' => __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ), | |
| 1083 | - 'saveAndReload' => $activating_page, | |
| 1084 | - ); | |
| 1085 | - | |
| 1086 | - return $response; | |
| 1087 | - } | |
| 1088 | - | |
| 1089 | - /** | |
| 1090 | - * Return a string that reflects the page from which the addon is being activated on, | |
| 1091 | - * if it is from settings or form builder, otherwise return empty string. | |
| 1092 | - * | |
| 1093 | - * @return string | |
| 1094 | - */ | |
| 1095 | - private static function get_activating_page() { | |
| 1096 | - $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' ); | |
| 1097 | - if ( false !== strpos( $referer, 'frm_action=settings' ) ) { | |
| 1098 | - return 'settings'; | |
| 1099 | - } | |
| 1100 | - | |
| 1101 | - if ( false !== strpos( $referer, 'frm_action=edit' ) ) { | |
| 1102 | - return 'form_builder'; | |
| 1103 | - } | |
| 1104 | - | |
| 1105 | - return ''; | |
| 1106 | - } | |
| 1107 | - | |
| 1108 | - /** | |
| 1109 | 774 | * @since 3.04.02 |
| 1110 | - * | |
| 1111 | 775 | * @param string $installed The plugin folder name with file name |
| 1112 | 776 | */ |
| 1113 | - protected static function maybe_activate_addon( $installed ) { | |
| 777 | + private static function maybe_activate_addon( $installed ) { | |
| 1114 | 778 | if ( ! $installed ) { |
| 1115 | 779 | return; |
| 1116 | 780 | } |
| 1117 | 781 | |
| 1118 | - $activate = self::activate_plugin( $installed ); | |
| 782 | + $activate = activate_plugin( $installed ); | |
| 1119 | 783 | if ( is_wp_error( $activate ) ) { |
| 1120 | 784 | // Ignore the invalid header message that shows with nested plugins. |
| 1121 | 785 | if ( $activate->get_error_code() !== 'no_plugin_header' ) { |
| 1122 | - if ( wp_doing_ajax() ) { | |
| 1123 | - echo json_encode( array( 'error' => $activate->get_error_message() ) ); | |
| 1124 | - wp_die(); | |
| 1125 | - } | |
| 1126 | - return array( | |
| 1127 | - 'message' => $activate->get_error_message(), | |
| 1128 | - 'success' => false, | |
| 1129 | - ); | |
| 786 | + echo json_encode( array( 'error' => $activate->get_error_message() ) ); | |
| 787 | + wp_die(); | |
| 1130 | 788 | } |
| 1131 | 789 | } |
| 1132 | 790 | } |
| 1133 | 791 | |
| @@ -1134,15 +792,13 @@ | ||
| 1134 | 792 | /** |
| 1135 | 793 | * Run security checks before installing |
| 1136 | 794 | * |
| 1137 | 795 | * @since 3.04.02 |
| 1138 | - * | |
| 1139 | - * @return void | |
| 1140 | 796 | */ |
| 1141 | - protected static function install_addon_permissions() { | |
| 797 | + private static function install_addon_permissions() { | |
| 1142 | 798 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 1143 | 799 | |
| 1144 | - if ( ! current_user_can( 'activate_plugins' ) || ! self::get_current_plugin() ) { | |
| 800 | + if ( ! current_user_can( 'activate_plugins' ) || ! isset( $_POST['plugin'] ) ) { | |
| 1145 | 801 | echo json_encode( true ); |
| 1146 | 802 | wp_die(); |
| 1147 | 803 | } |
| 1148 | 804 | } |
| @@ -1147,225 +803,8 @@ | ||
| 1147 | 803 | } |
| 1148 | 804 | } |
| 1149 | 805 | |
| 1150 | 806 | /** |
| 1151 | - * @since 4.08 | |
| 1152 | - * | |
| 1153 | - * @return string | |
| 1154 | - */ | |
| 1155 | - public static function connect_link() { | |
| 1156 | - $auth = get_option( 'frm_connect_token' ); | |
| 1157 | - if ( empty( $auth ) ) { | |
| 1158 | - $auth = hash( 'sha512', wp_rand() ); | |
| 1159 | - update_option( 'frm_connect_token', $auth ); | |
| 1160 | - } | |
| 1161 | - $link = FrmAppHelper::admin_upgrade_link( 'connect', 'api-connect' ); | |
| 1162 | - $args = array( | |
| 1163 | - 'v' => 2, | |
| 1164 | - 'siteurl' => FrmAppHelper::site_url(), | |
| 1165 | - 'url' => get_rest_url(), | |
| 1166 | - 'token' => $auth, | |
| 1167 | - 'l' => self::get_pro_license(), | |
| 1168 | - ); | |
| 1169 | - | |
| 1170 | - return add_query_arg( $args, $link ); | |
| 1171 | - } | |
| 1172 | - | |
| 1173 | - /** | |
| 1174 | - * Check the auth value for install permission. | |
| 1175 | - * | |
| 1176 | - * @since 4.08 | |
| 1177 | - * | |
| 1178 | - * @return bool | |
| 1179 | - */ | |
| 1180 | - public static function can_install_addon_api() { | |
| 1181 | - if ( ! current_user_can( 'activate_plugins' ) ) { | |
| 1182 | - return false; | |
| 1183 | - } | |
| 1184 | - | |
| 1185 | - // Verify params present (auth & download link). | |
| 1186 | - $post_auth = FrmAppHelper::get_param( 'token', '', 'request', 'sanitize_text_field' ); | |
| 1187 | - $post_url = FrmAppHelper::get_param( 'file_url', '', 'request', 'sanitize_text_field' ); | |
| 1188 | - | |
| 1189 | - if ( empty( $post_auth ) || empty( $post_url ) ) { | |
| 1190 | - return false; | |
| 1191 | - } | |
| 1192 | - | |
| 1193 | - // Verify auth. | |
| 1194 | - $auth = get_option( 'frm_connect_token' ); | |
| 1195 | - if ( empty( $auth ) || ! hash_equals( $auth, $post_auth ) ) { | |
| 1196 | - return false; | |
| 1197 | - } | |
| 1198 | - | |
| 1199 | - return true; | |
| 1200 | - } | |
| 1201 | - | |
| 1202 | - /** | |
| 1203 | - * Install and/or activate the add-on file. | |
| 1204 | - * | |
| 1205 | - * @since 4.08 | |
| 1206 | - */ | |
| 1207 | - public static function install_addon_api() { | |
| 1208 | - self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' ); | |
| 1209 | - | |
| 1210 | - $error = esc_html__( 'Could not install an upgrade. Please download from formidableforms.com and install manually.', 'formidable' ); | |
| 1211 | - | |
| 1212 | - // Delete so cannot replay. | |
| 1213 | - delete_option( 'frm_connect_token' ); | |
| 1214 | - | |
| 1215 | - // It's already installed and active. | |
| 1216 | - $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true ); | |
| 1217 | - if ( is_wp_error( $active ) ) { | |
| 1218 | - // Download plugin now. | |
| 1219 | - $response = self::download_and_activate(); | |
| 1220 | - if ( is_array( $response ) && isset( $response['success'] ) ) { | |
| 1221 | - return $response; | |
| 1222 | - } | |
| 1223 | - } | |
| 1224 | - | |
| 1225 | - // If empty license, save it now. | |
| 1226 | - if ( empty( self::get_pro_license() ) && function_exists( 'load_formidable_pro' ) ) { | |
| 1227 | - load_formidable_pro(); | |
| 1228 | - $license = stripslashes( FrmAppHelper::get_param( 'key', '', 'request', 'sanitize_text_field' ) ); | |
| 1229 | - if ( ! $license ) { | |
| 1230 | - return array( | |
| 1231 | - 'success' => false, | |
| 1232 | - 'error' => 'That site does not have a valid license key.', | |
| 1233 | - ); | |
| 1234 | - } | |
| 1235 | - | |
| 1236 | - $response = FrmAddon::activate_license_for_plugin( $license, 'formidable_pro' ); | |
| 1237 | - if ( ! $response['success'] ) { | |
| 1238 | - // Could not activate license. | |
| 1239 | - return $response; | |
| 1240 | - } | |
| 1241 | - } | |
| 1242 | - | |
| 1243 | - return array( | |
| 1244 | - 'success' => true, | |
| 1245 | - ); | |
| 1246 | - } | |
| 1247 | - | |
| 1248 | - /** | |
| 1249 | - * Render a conditional action button for a specified plugin | |
| 1250 | - * | |
| 1251 | - * @param string $plugin | |
| 1252 | - * @param array|string $upgrade_link_args | |
| 1253 | - * @since 4.09 | |
| 1254 | - */ | |
| 1255 | - public static function conditional_action_button( $plugin, $upgrade_link_args ) { | |
| 1256 | - if ( is_callable( 'FrmProAddonsController::conditional_action_button' ) ) { | |
| 1257 | - return FrmProAddonsController::conditional_action_button( $plugin, $upgrade_link_args ); | |
| 1258 | - } | |
| 1259 | - | |
| 1260 | - $addon = self::get_addon( $plugin ); | |
| 1261 | - $upgrade_link = FrmAppHelper::admin_upgrade_link( $upgrade_link_args ); | |
| 1262 | - self::addon_upgrade_link( $addon, $upgrade_link ); | |
| 1263 | - } | |
| 1264 | - | |
| 1265 | - /** | |
| 1266 | - * Render a conditional action button for an add on | |
| 1267 | - * | |
| 1268 | - * @since 4.09.01 | |
| 1269 | - * | |
| 1270 | - * @param array $addon | |
| 1271 | - * @param string|false $license_type | |
| 1272 | - * @param string $plan_required | |
| 1273 | - * @param string $upgrade_link | |
| 1274 | - */ | |
| 1275 | - public static function show_conditional_action_button( $atts ) { | |
| 1276 | - if ( is_callable( 'FrmProAddonsController::show_conditional_action_button' ) ) { | |
| 1277 | - return FrmProAddonsController::show_conditional_action_button( $atts ); | |
| 1278 | - } | |
| 1279 | - | |
| 1280 | - self::addon_upgrade_link( $atts['addon'], $atts['upgrade_link'] ); | |
| 1281 | - } | |
| 1282 | - | |
| 1283 | - /** | |
| 1284 | - * @since 4.09.01 | |
| 1285 | - * | |
| 1286 | - * @param array|false $addon | |
| 1287 | - * | |
| 1288 | - * @return void | |
| 1289 | - */ | |
| 1290 | - protected static function addon_upgrade_link( $addon, $upgrade_link ) { | |
| 1291 | - if ( $addon ) { | |
| 1292 | - $upgrade_link .= '&utm_content=' . $addon['slug']; | |
| 1293 | - } | |
| 1294 | - | |
| 1295 | - if ( $addon && isset( $addon['categories'] ) && in_array( 'Solution', $addon['categories'], true ) ) { | |
| 1296 | - // Solutions will go to a separate page. | |
| 1297 | - $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] ); | |
| 1298 | - } | |
| 1299 | - ?> | |
| 1300 | - <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' ); ?>"> | |
| 1301 | - <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?> | |
| 1302 | - </a> | |
| 1303 | - <?php | |
| 1304 | - } | |
| 1305 | - | |
| 1306 | - /** | |
| 1307 | - * @since 3.04.02 | |
| 1308 | - * | |
| 1309 | - * @return void | |
| 1310 | - */ | |
| 1311 | - public static function ajax_install_addon() { | |
| 1312 | - self::install_addon_permissions(); | |
| 1313 | - | |
| 1314 | - $result = self::download_and_activate(); | |
| 1315 | - if ( isset( $result['success'] ) && ! $result['success'] ) { | |
| 1316 | - echo json_encode( $result ); | |
| 1317 | - wp_die(); | |
| 1318 | - } | |
| 1319 | - | |
| 1320 | - echo json_encode( self::get_addon_activation_response() ); | |
| 1321 | - wp_die(); | |
| 1322 | - } | |
| 1323 | - | |
| 1324 | - /** | |
| 1325 | - * Allowed URLs used for internal source of plugins installation. | |
| 1326 | - * | |
| 1327 | - * @since 6.3.1 | |
| 1328 | - * | |
| 1329 | - * @return array | |
| 1330 | - */ | |
| 1331 | - private static function allowed_external_urls() { | |
| 1332 | - $allowed_url_list = array( | |
| 1333 | - 'https://downloads.wordpress.org/plugin/formidable-gravity-forms-importer.zip', | |
| 1334 | - 'https://downloads.wordpress.org/plugin/formidable-import-pirate-forms.zip', | |
| 1335 | - 'https://downloads.wordpress.org/plugin/wp-mail-smtp.zip', | |
| 1336 | - ); | |
| 1337 | - | |
| 1338 | - /** | |
| 1339 | - * List of URLs used in plugin formidable internal installation. | |
| 1340 | - * | |
| 1341 | - * @since 6.3.1 | |
| 1342 | - * | |
| 1343 | - * @param array $allowed_url_list List of URLs. | |
| 1344 | - */ | |
| 1345 | - $allowed_url_list = apply_filters( 'frm_allowed_external_urls', $allowed_url_list ); | |
| 1346 | - | |
| 1347 | - if ( ! is_array( $allowed_url_list ) ) { | |
| 1348 | - _doing_it_wrong( __METHOD__, 'Only an array of URLs could be used within this filter.', '6.3.1' ); | |
| 1349 | - | |
| 1350 | - return array(); | |
| 1351 | - } | |
| 1352 | - | |
| 1353 | - return $allowed_url_list; | |
| 1354 | - } | |
| 1355 | - | |
| 1356 | - /** | |
| 1357 | - * @since 4.06.02 | |
| 1358 | - * | |
| 1359 | - * @deprecated 4.09.01 | |
| 1360 | - * | |
| 1361 | - * @return void | |
| 1362 | - */ | |
| 1363 | - public static function ajax_multiple_addons() { | |
| 1364 | - FrmDeprecated::ajax_multiple_addons(); | |
| 1365 | - } | |
| 1366 | - | |
| 1367 | - /** | |
| 1368 | 807 | * @since 3.04.03 |
| 1369 | 808 | * @deprecated 3.06 |
| 1370 | 809 | * @codeCoverageIgnore |
| 1371 | 810 | * @return array |
| @@ -1406,14 +845,10 @@ | ||
| 1406 | 845 | } |
| 1407 | 846 | |
| 1408 | 847 | /** |
| 1409 | 848 | * @since 3.04.03 |
| 1410 | - * | |
| 1411 | 849 | * @deprecated 3.06 |
| 1412 | - * | |
| 1413 | 850 | * @codeCoverageIgnore |
| 1414 | - * | |
| 1415 | - * @return void | |
| 1416 | 851 | */ |
| 1417 | 852 | public static function reset_cached_addons( $license = '' ) { |
| 1418 | 853 | FrmDeprecated::reset_cached_addons( $license ); |
| 1419 | 854 | } |
| @@ -1447,12 +882,9 @@ | ||
| 1447 | 882 | } |
| 1448 | 883 | |
| 1449 | 884 | /** |
| 1450 | 885 | * @deprecated 3.04.03 |
| 1451 | - * | |
| 1452 | 886 | * @codeCoverageIgnore |
| 1453 | - * | |
| 1454 | - * @return void | |
| 1455 | 887 | */ |
| 1456 | 888 | public static function get_licenses() { |
| 1457 | 889 | FrmDeprecated::get_licenses(); |
| 1458 | 890 | } |