Нет описания

wpforms.php 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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: 4.9
  7. * Requires PHP: 5.5
  8. * Author: WPForms
  9. * Author URI: https://wpforms.com
  10. * Version: 1.7.1.2
  11. * Text Domain: wpforms-lite
  12. * Domain Path: assets/languages
  13. *
  14. * WPForms is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation, either version 2 of the License, or
  17. * any later version.
  18. *
  19. * WPForms is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with WPForms. If not, see <https://www.gnu.org/licenses/>.
  26. */
  27. // Exit if accessed directly.
  28. if ( ! defined( 'ABSPATH' ) ) {
  29. exit;
  30. }
  31. // Plugin version.
  32. if ( ! defined( 'WPFORMS_VERSION' ) ) {
  33. define( 'WPFORMS_VERSION', '1.7.1.2' );
  34. }
  35. // Plugin Folder Path.
  36. if ( ! defined( 'WPFORMS_PLUGIN_DIR' ) ) {
  37. define( 'WPFORMS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
  38. }
  39. // Plugin Folder URL.
  40. if ( ! defined( 'WPFORMS_PLUGIN_URL' ) ) {
  41. define( 'WPFORMS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
  42. }
  43. // Plugin Root File.
  44. if ( ! defined( 'WPFORMS_PLUGIN_FILE' ) ) {
  45. define( 'WPFORMS_PLUGIN_FILE', __FILE__ );
  46. }
  47. // Don't allow multiple versions to be active.
  48. if ( function_exists( 'wpforms' ) ) {
  49. if ( ! function_exists( 'wpforms_pro_just_activated' ) ) {
  50. /**
  51. * When we activate a Pro version, we need to do additional operations:
  52. * 1) deactivate a Lite version;
  53. * 2) register option which help to run all activation process for Pro version (custom tables creation, etc.).
  54. *
  55. * @since 1.6.2
  56. */
  57. function wpforms_pro_just_activated() {
  58. wpforms_deactivate();
  59. add_option( 'wpforms_install', 1 );
  60. }
  61. }
  62. add_action( 'activate_wpforms/wpforms.php', 'wpforms_pro_just_activated' );
  63. if ( ! function_exists( 'wpforms_lite_just_activated' ) ) {
  64. /**
  65. * Store temporarily that the Lite version of the plugin was activated.
  66. * This is needed because WP does a redirect after activation and
  67. * we need to preserve this state to know whether user activated Lite or not.
  68. *
  69. * @since 1.5.8
  70. */
  71. function wpforms_lite_just_activated() {
  72. set_transient( 'wpforms_lite_just_activated', true );
  73. }
  74. }
  75. add_action( 'activate_wpforms-lite/wpforms.php', 'wpforms_lite_just_activated' );
  76. if ( ! function_exists( 'wpforms_lite_just_deactivated' ) ) {
  77. /**
  78. * Store temporarily that Lite plugin was deactivated.
  79. * Convert temporary "activated" value to a global variable,
  80. * so it is available through the request. Remove from the storage.
  81. *
  82. * @since 1.5.8
  83. */
  84. function wpforms_lite_just_deactivated() {
  85. global $wpforms_lite_just_activated, $wpforms_lite_just_deactivated;
  86. $wpforms_lite_just_activated = (bool) get_transient( 'wpforms_lite_just_activated' );
  87. $wpforms_lite_just_deactivated = true;
  88. delete_transient( 'wpforms_lite_just_activated' );
  89. }
  90. }
  91. add_action( 'deactivate_wpforms-lite/wpforms.php', 'wpforms_lite_just_deactivated' );
  92. if ( ! function_exists( 'wpforms_deactivate' ) ) {
  93. /**
  94. * Deactivate Lite if WPForms already activated.
  95. *
  96. * @since 1.0.0
  97. */
  98. function wpforms_deactivate() {
  99. $plugin = 'wpforms-lite/wpforms.php';
  100. deactivate_plugins( $plugin );
  101. do_action( 'wpforms_plugin_deactivated', $plugin );
  102. }
  103. }
  104. add_action( 'admin_init', 'wpforms_deactivate' );
  105. if ( ! function_exists( 'wpforms_lite_notice' ) ) {
  106. /**
  107. * Display the notice after deactivation when Pro is still active
  108. * and user wanted to activate the Lite version of the plugin.
  109. *
  110. * @since 1.0.0
  111. */
  112. function wpforms_lite_notice() {
  113. global $wpforms_lite_just_activated, $wpforms_lite_just_deactivated;
  114. if (
  115. empty( $wpforms_lite_just_activated ) ||
  116. empty( $wpforms_lite_just_deactivated )
  117. ) {
  118. return;
  119. }
  120. // Currently tried to activate Lite with Pro still active, so display the message.
  121. printf(
  122. '<div class="notice notice-warning">
  123. <p>%1$s</p>
  124. <p>%2$s</p>
  125. </div>',
  126. esc_html__( 'Heads up!', 'wpforms-lite' ),
  127. esc_html__( 'Your site already has WPForms Pro activated. If you want to switch to WPForms Lite, please first go to Plugins → Installed Plugins and deactivate WPForms. Then, you can activate WPForms Lite.', 'wpforms-lite' )
  128. );
  129. if ( isset( $_GET['activate'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
  130. unset( $_GET['activate'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
  131. }
  132. unset( $wpforms_lite_just_activated, $wpforms_lite_just_deactivated );
  133. }
  134. }
  135. add_action( 'admin_notices', 'wpforms_lite_notice' );
  136. // Do not process the plugin code further.
  137. return;
  138. }
  139. // We require PHP 5.5+ for the whole plugin to work.
  140. if ( version_compare( phpversion(), '5.5', '<' ) ) {
  141. if ( ! function_exists( 'wpforms_php52_notice' ) ) {
  142. /**
  143. * Display the notice after deactivation.
  144. *
  145. * @since 1.5.0
  146. */
  147. function wpforms_php52_notice() {
  148. ?>
  149. <div class="notice notice-error">
  150. <p>
  151. <?php
  152. printf(
  153. wp_kses( /* translators: %s - WPBeginner URL for recommended WordPress hosting. */
  154. __( 'Your site is running an <strong>insecure version</strong> of PHP that is no longer supported. Please contact your web hosting provider to update your PHP version or switch to a <a href="%s" target="_blank" rel="noopener noreferrer">recommended WordPress hosting company</a>.', 'wpforms-lite' ),
  155. [
  156. 'a' => [
  157. 'href' => [],
  158. 'target' => [],
  159. 'rel' => [],
  160. ],
  161. 'strong' => [],
  162. ]
  163. ),
  164. 'https://www.wpbeginner.com/wordpress-hosting/'
  165. );
  166. ?>
  167. <br><br>
  168. <?php
  169. printf(
  170. wp_kses( /* translators: %s - WPForms.com URL for documentation with more details. */
  171. __( '<strong>Note:</strong> WPForms plugin is disabled on your site until you fix the issue. <a href="%s" target="_blank" rel="noopener noreferrer">Read more for additional information.</a>', 'wpforms-lite' ),
  172. [
  173. 'a' => [
  174. 'href' => [],
  175. 'target' => [],
  176. 'rel' => [],
  177. ],
  178. 'strong' => [],
  179. ]
  180. ),
  181. 'https://wpforms.com/docs/supported-php-version/'
  182. );
  183. ?>
  184. </p>
  185. </div>
  186. <?php
  187. // In case this is on plugin activation.
  188. if ( isset( $_GET['activate'] ) ) { //phpcs:ignore
  189. unset( $_GET['activate'] );
  190. }
  191. }
  192. }
  193. add_action( 'admin_notices', 'wpforms_php52_notice' );
  194. // Do not process the plugin code further.
  195. return;
  196. }
  197. // Define the class and the function.
  198. require_once dirname( __FILE__ ) . '/src/WPForms.php';
  199. wpforms();