wpforms-lite
Last commit date
assets
1 month ago
includes
2 months ago
lite
2 months ago
src
1 month ago
templates
2 months ago
vendor
1 month ago
vendor_prefixed
2 months ago
changelog.txt
1 month ago
readme.txt
1 month ago
uninstall.php
11 months ago
wpforms.php
1 month ago
wpforms.php
252 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Name: WPForms Lite |
| 4 | * Plugin URI: https://wpforms.com |
| 5 | * Description: Beginner friendly WordPress contact form plugin. Use our Drag & Drop form builder to create your WordPress forms. |
| 6 | * Requires at least: 5.5 |
| 7 | * Requires PHP: 7.2 |
| 8 | * Author: WPForms |
| 9 | * Author URI: https://wpforms.com |
| 10 | * Version: 1.10.0.3 |
| 11 | * License: GPL v2 or later |
| 12 | * License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 13 | * Text Domain: wpforms-lite |
| 14 | * Domain Path: /assets/languages |
| 15 | * |
| 16 | * WPForms is free software: you can redistribute it and/or modify |
| 17 | * it under the terms of the GNU General Public License as published by |
| 18 | * the Free Software Foundation, either version 2 of the License, or |
| 19 | * any later version. |
| 20 | * |
| 21 | * WPForms is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with WPForms. If not, see <https://www.gnu.org/licenses/>. |
| 28 | */ |
| 29 | |
| 30 | // Exit if accessed directly. |
| 31 | use WPForms\Requirements\Requirements; |
| 32 | |
| 33 | if ( ! defined( 'ABSPATH' ) ) { |
| 34 | exit; |
| 35 | } |
| 36 | |
| 37 | if ( is_multisite() ) { |
| 38 | $is_pro = file_exists( __DIR__ . '/pro/wpforms-pro.php' ); |
| 39 | |
| 40 | if ( ! $is_pro ) { // <- is lite. |
| 41 | $lite_base = plugin_basename( __FILE__ ); |
| 42 | |
| 43 | $active_plugins = get_option( 'active_plugins', [] ); |
| 44 | $active_network_plugins = get_site_option( 'active_sitewide_plugins' ); |
| 45 | |
| 46 | if ( |
| 47 | isset( $active_network_plugins[ $lite_base ] ) |
| 48 | && in_array( 'wpforms/wpforms.php', $active_plugins, true ) |
| 49 | ) { |
| 50 | // Keep plugin active but silent. |
| 51 | return; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | if ( ! defined( 'WPFORMS_VERSION' ) ) { |
| 57 | /** |
| 58 | * Plugin version. |
| 59 | * |
| 60 | * @since 1.0.0 |
| 61 | */ |
| 62 | define( 'WPFORMS_VERSION', '1.10.0.3' ); // NOSONAR. |
| 63 | } |
| 64 | |
| 65 | if ( ! defined( 'WPFORMS_PLUGIN_DIR' ) ) { |
| 66 | /** |
| 67 | * Plugin Folder Path. |
| 68 | * |
| 69 | * @since 1.3.8 |
| 70 | */ |
| 71 | define( 'WPFORMS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 72 | } |
| 73 | |
| 74 | if ( ! defined( 'WPFORMS_PLUGIN_URL' ) ) { |
| 75 | /** |
| 76 | * Plugin Folder URL. |
| 77 | * |
| 78 | * @since 1.3.8 |
| 79 | */ |
| 80 | define( 'WPFORMS_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
| 81 | } |
| 82 | |
| 83 | if ( ! defined( 'WPFORMS_PLUGIN_FILE' ) ) { |
| 84 | /** |
| 85 | * Plugin Root File. |
| 86 | * |
| 87 | * @since 1.3.8 |
| 88 | */ |
| 89 | define( 'WPFORMS_PLUGIN_FILE', __FILE__ ); |
| 90 | } |
| 91 | |
| 92 | // Don't allow multiple versions to be active. |
| 93 | if ( function_exists( 'wpforms' ) ) { |
| 94 | if ( ! function_exists( 'wpforms_lite_just_activated' ) ) { |
| 95 | /** |
| 96 | * Store temporarily that the Lite version of the plugin was activated. |
| 97 | * This is needed because WP does a redirect after activation, |
| 98 | * and we need to preserve this state to know whether the user activated Lite or not. |
| 99 | * |
| 100 | * @since 1.5.8 |
| 101 | */ |
| 102 | function wpforms_lite_just_activated() { |
| 103 | |
| 104 | set_transient( 'wpforms_lite_just_activated', true ); |
| 105 | } |
| 106 | add_action( 'activate_wpforms-lite/wpforms.php', 'wpforms_lite_just_activated' ); |
| 107 | } |
| 108 | |
| 109 | if ( ! function_exists( 'wpforms_deactivate' ) ) { |
| 110 | /** |
| 111 | * Deactivate Lite if WPForms already activated. |
| 112 | * |
| 113 | * @since 1.0.0 |
| 114 | */ |
| 115 | function wpforms_deactivate() { |
| 116 | |
| 117 | $pro_file = wpforms()->is_pro() ? WPFORMS_PLUGIN_FILE : __FILE__; |
| 118 | $lite_file = wpforms()->is_pro() ? __FILE__ : WPFORMS_PLUGIN_FILE; |
| 119 | |
| 120 | $lite_base = plugin_basename( $lite_file ); |
| 121 | $pro_base = plugin_basename( $pro_file ); |
| 122 | |
| 123 | if ( |
| 124 | ! is_multisite() |
| 125 | || is_plugin_active_for_network( $pro_base ) |
| 126 | || ( ! is_plugin_active_for_network( $pro_base ) && ! is_plugin_active_for_network( $lite_base ) ) |
| 127 | ) { |
| 128 | deactivate_plugins( $lite_base ); |
| 129 | |
| 130 | /** |
| 131 | * Fires on plugin deactivation. |
| 132 | * |
| 133 | * @since 1.6.3.1 |
| 134 | * |
| 135 | * @param string $plugin_basename The plugin basename. |
| 136 | */ |
| 137 | do_action( 'wpforms_plugin_deactivated', $lite_base ); |
| 138 | |
| 139 | // Run the installation on the next admin visit. |
| 140 | add_option( 'wpforms_install', 1 ); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | add_action( 'admin_init', 'wpforms_deactivate' ); |
| 145 | |
| 146 | if ( ! function_exists( 'wpforms_lite_notice' ) ) { |
| 147 | /** |
| 148 | * Display the notice after deactivation when Pro is still active |
| 149 | * and user wanted to activate the Lite version of the plugin. |
| 150 | * |
| 151 | * @since 1.0.0 |
| 152 | * |
| 153 | * @noinspection HtmlUnknownTarget |
| 154 | */ |
| 155 | function wpforms_lite_notice() { |
| 156 | |
| 157 | $pro_file = wpforms()->is_pro() ? WPFORMS_PLUGIN_FILE : __FILE__; |
| 158 | $lite_file = wpforms()->is_pro() ? __FILE__ : WPFORMS_PLUGIN_FILE; |
| 159 | |
| 160 | $lite_base = plugin_basename( $lite_file ); |
| 161 | $pro_base = plugin_basename( $pro_file ); |
| 162 | |
| 163 | // Do not show the notice if upgrade from Lite to Pro. |
| 164 | if ( (bool) get_transient( 'wpforms_lite_just_activated' ) === false ) { |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | if ( |
| 169 | ! is_multisite() |
| 170 | || is_plugin_active_for_network( $pro_base ) |
| 171 | || ( ! is_plugin_active_for_network( $pro_base ) && ! is_plugin_active_for_network( $lite_base ) ) |
| 172 | ) { |
| 173 | $message = sprintf( |
| 174 | /* translators: %s - Path to installed plugins. */ |
| 175 | __( 'Your site already has WPForms Pro activated. If you want to switch to WPForms Lite, please first go to %s and deactivate WPForms. Then, you can activate WPForms Lite.', 'wpforms-lite' ), |
| 176 | is_multisite() ? __( 'Network Admin → Plugins → Installed Plugins', 'wpforms-lite' ) : __( 'Plugins → Installed Plugins', 'wpforms-lite' ) |
| 177 | ); |
| 178 | |
| 179 | // Currently tried to activate Lite with Pro still active, so display the message. |
| 180 | printf( |
| 181 | '<div class="notice wpforms-notice notice-warning wpforms-license-notice" id="wpforms-notice-pro-active"> |
| 182 | <h3 style="margin: .75em 0 0 0;"> |
| 183 | <img src="%1$s" alt="" style="vertical-align: text-top; width: 20px; margin-right: 7px;">%2$s |
| 184 | </h3> |
| 185 | <p>%3$s</p> |
| 186 | </div>', |
| 187 | esc_url( WPFORMS_PLUGIN_URL . 'assets/images/exclamation-triangle.svg' ), |
| 188 | esc_html__( 'Heads up!', 'wpforms-lite' ), |
| 189 | esc_html( $message ) |
| 190 | ); |
| 191 | |
| 192 | delete_transient( 'wpforms_lite_just_activated' ); |
| 193 | |
| 194 | if ( isset( $_GET['activate'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 195 | unset( $_GET['activate'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | add_action( 'admin_notices', 'wpforms_lite_notice' ); |
| 201 | add_action( 'network_admin_notices', 'wpforms_lite_notice' ); |
| 202 | |
| 203 | // Do not process the plugin code further. |
| 204 | return; |
| 205 | } |
| 206 | |
| 207 | if ( ! function_exists( 'wpforms_php52_notice' ) ) { |
| 208 | |
| 209 | /** |
| 210 | * Display the notice about incompatible PHP version after deactivation. |
| 211 | * |
| 212 | * @since 1.5.0 |
| 213 | * @deprecated 1.9.6 |
| 214 | */ |
| 215 | function wpforms_php52_notice() { |
| 216 | |
| 217 | _deprecated_function( __FUNCTION__, '1.9.6 of the WPForms plugin' ); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | if ( ! function_exists( 'wpforms_wp_notice' ) ) { |
| 222 | |
| 223 | /** |
| 224 | * Display the notice about incompatible WP version after deactivation. |
| 225 | * |
| 226 | * @since 1.7.3 |
| 227 | * @deprecated 1.9.6 |
| 228 | */ |
| 229 | function wpforms_wp_notice() { |
| 230 | |
| 231 | _deprecated_function( __FUNCTION__, '1.9.6 of the WPForms plugin' ); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | require_once WPFORMS_PLUGIN_DIR . 'src/Requirements/Requirements.php'; |
| 236 | require_once WPFORMS_PLUGIN_DIR . 'includes/functions.php'; |
| 237 | |
| 238 | $requirements = [ |
| 239 | 'file' => __FILE__, |
| 240 | ]; |
| 241 | |
| 242 | if ( ! Requirements::get_instance()->validate( $requirements ) ) { |
| 243 | return; |
| 244 | } |
| 245 | |
| 246 | // Define the class and the function. |
| 247 | require_once __DIR__ . '/src/WPForms.php'; |
| 248 | |
| 249 | if ( function_exists( 'wpforms' ) ) { |
| 250 | wpforms(); |
| 251 | } |
| 252 |