/membership.php

  1. <?php 
  2.  
  3.  
  4. /** 
  5. * Plugin Name: Membership 2 
  6. * Plugin URI: https://wordpress.org/plugins/membership 
  7. * Version: 4.0.1.0 
  8. * Build Stamp: 2016-06-16T14:06:26.352Z 
  9. * Description: The most powerful, easy to use and flexible membership plugin for WordPress sites available. 
  10. * Author: WPMU DEV 
  11. * Author URI: http://premium.wpmudev.org/ 
  12. * WDP ID: 1003656 
  13. * License: GPL2 
  14. * License URI: http://opensource.org/licenses/GPL-2.0 
  15. * Text Domain: membership2 
  16. * 
  17. * @package Membership2 
  18. */ 
  19.  
  20.  
  21. /** 
  22. * Copyright notice 
  23. * 
  24. * @copyright Incsub (http://incsub.com/) 
  25. * 
  26. * Authors: Philipp Stracker, Fabio Jun Onishi, Victor Ivanov, Jack Kitterhing, Rheinard Korf, Ashok Kumar Nath 
  27. * Contributors: Joji Mori, Patrick Cohen 
  28. * 
  29. * @license http://opensource.org/licenses/GPL-2.0 GNU General Public License, version 2 (GPL-2.0) 
  30. * 
  31. * This program is free software; you can redistribute it and/or modify 
  32. * it under the terms of the GNU General Public License, version 2, as 
  33. * published by the Free Software Foundation. 
  34. * 
  35. * This program is distributed in the hope that it will be useful,  
  36. * but WITHOUT ANY WARRANTY; without even the implied warranty of 
  37. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
  38. * GNU General Public License for more details. 
  39. * 
  40. * You should have received a copy of the GNU General Public License 
  41. * along with this program; if not, write to the Free Software 
  42. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,  
  43. * MA 02110-1301 USA 
  44. */ 
  45.  
  46. /** 
  47. * Initializes constants and create the main plugin object MS_Plugin. 
  48. * This function is called *instantly* when this file was loaded. 
  49. * 
  50. * @since 1.0.0 
  51. */ 
  52.  
  53. function membership2_init_app() { 
  54. if ( defined( 'MS_PLUGIN' ) ) { 
  55.  
  56. $plugin_name = 'Membership 2 (Free)'; 
  57. if ( is_admin() ) { 
  58. // Can happen in Multisite installs where a sub-site has activated the 
  59. // plugin and then the plugin is also activated in network-admin. 
  60. printf( 
  61. '<div class="notice error"><p><strong>%s</strong>: %s</p></div>',  
  62. sprintf( 
  63. esc_html__( 'Could not load the plugin %s, because another version of the plugin is already loaded', 'membership2' ),  
  64. $plugin_name 
  65. ),  
  66. esc_html( MS_PLUGIN . ' (v' . MS_PLUGIN_VERSION . ')' ) 
  67. ); 
  68. return; 
  69.  
  70. /** 
  71. * Plugin version 
  72. * 
  73. * @since 1.0.0 
  74. */ 
  75. define( 
  76. 'MS_PLUGIN_VERSION' 
  77.  
  78. , '4.0.1.0' 
  79. ); 
  80.  
  81. /** 
  82. * Plugin main-file. 
  83. * 
  84. * @since 1.0.3.0 
  85. */ 
  86. define( 'MS_PLUGIN_FILE', __FILE__ ); 
  87.  
  88. /** 
  89. * Plugin identifier constant. 
  90. * 
  91. * @since 1.0.0 
  92. */ 
  93. define( 'MS_PLUGIN', plugin_basename( __FILE__ ) ); 
  94.  
  95. /** 
  96. * Plugin name dir constant. 
  97. * 
  98. * @since 1.0.0 
  99. */ 
  100. define( 'MS_PLUGIN_NAME', dirname( MS_PLUGIN ) ); 
  101.  
  102. /** 
  103. * Plugin name dir constant. 
  104. * 
  105. * @since 1.0.3 
  106. */ 
  107. define( 'MS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 
  108.  
  109. $externals = array( 
  110. dirname( __FILE__ ) . '/lib/wpmu-lib/core.php',  
  111. dirname( __FILE__ ) . '/lib/wdev-frash/module.php',  
  112. ); 
  113.  
  114.  
  115. // Free-version configuration 
  116. $cta_label = __( 'Get Members!', 'membership2' ); 
  117. $drip_param = 'Membership'; 
  118.  
  119.  
  120.  
  121.  
  122. foreach ( $externals as $path ) { 
  123. if ( file_exists( $path ) ) { require_once $path; } 
  124.  
  125. // Register the current plugin, for pro and free plugins! 
  126. do_action( 
  127. 'wdev-register-plugin',  
  128. /** Plugin ID */ plugin_basename( __FILE__ ),  
  129. /** Plugin Title */ 'Membership 2',  
  130. /** https://wordpress.org */ '/plugins/membership/',  
  131. /** Email Button CTA */ $cta_label,  
  132. /** getdrip Plugin param */ $drip_param 
  133. ); 
  134.  
  135. /** 
  136. * Prepare rating message. 
  137. * 
  138. * @return string Message to display. 
  139. */ 
  140. function _membership2_rating_message() { 
  141. return __( "Hey %s, you've been using %s for a while now, and we hope you're happy with it.", 'membership2' ) . 
  142. '<br />' . 
  143. __( "We're constantly working to improve our plugins, and it helps a lot when members just like you share feedback!", 'membership2' ); 
  144. add_filter( 
  145. 'wdev-rating-message-' . plugin_basename( __FILE__ ),  
  146. '_membership2_rating_message' 
  147. ); 
  148.  
  149. /** 
  150. * Translation. 
  151. * 
  152. * Tip: 
  153. * The translation files must have the filename [TEXT-DOMAIN]-[locale].mo 
  154. * Example: membership2-en_EN.mo / membership2-de_DE.mo 
  155. */ 
  156. function _membership2_translate_plugin() { 
  157. load_plugin_textdomain( 
  158. 'membership2',  
  159. false,  
  160. dirname( plugin_basename( __FILE__ ) ) . '/languages' 
  161. ); 
  162. add_action( 'plugins_loaded', '_membership2_translate_plugin' ); 
  163.  
  164. if ( (defined( 'WP_DEBUG' ) && WP_DEBUG) || (defined( 'WDEV_DEBUG' ) && WDEV_DEBUG) ) { 
  165. // Load development/testing code before the plugin is initialized. 
  166. $testfile = dirname( __FILE__ ) . '/tests/wp/init.php'; 
  167. if ( file_exists( $testfile ) ) { include $testfile; } 
  168.  
  169. // Initialize the M2 class loader. 
  170. $loader = new MS_Loader(); 
  171.  
  172. /** 
  173. * Create an instance of the plugin object. 
  174. * 
  175. * This is the primary entry point for the Membership plugin. 
  176. * 
  177. * @since 1.0.0 
  178. */ 
  179. MS_Plugin::instance(); 
  180.  
  181. /** 
  182. * Class-Loader code. 
  183. * Initialises the autoloader and required plugin hooks. 
  184. * 
  185. * @since 1.0.0 
  186. */ 
  187. class MS_Loader { 
  188.  
  189. /** 
  190. * Plugin constructor. 
  191. * 
  192. * @since 1.0.0 
  193. */ 
  194. public function __construct() { 
  195. add_filter( 
  196. 'ms_class_path_overrides',  
  197. array( $this, 'ms_class_path_overrides' ) 
  198. ); 
  199.  
  200. // Creates the class autoloader. 
  201. // Special: Method `class_loader` can be private and it will work here! 
  202. spl_autoload_register( array( $this, 'class_loader' ) ); 
  203.  
  204. /** 
  205. * Hooks 'ms_class_path_overrides'. 
  206. * 
  207. * Overrides plugin class paths to adhere to naming conventions 
  208. * where object names are separated by underscores or for special cases. 
  209. * 
  210. * @since 1.0.0 
  211. * 
  212. * @param array $overrides Array passed in by filter. 
  213. * @return array(class=>path) Classes with new file paths. 
  214. */ 
  215. public function ms_class_path_overrides( $overrides ) { 
  216. $models_base = 'app/model/'; 
  217. $models = array( 
  218. 'MS_Model_Communication_After_Finishes' => 'communication/class-ms-model-communication-after-finishes.php',  
  219. 'MS_Model_Communication_After_Payment_Due' => 'communication/class-ms-model-communication-after-payment-due.php',  
  220. 'MS_Model_Communication_Before_Finishes' => 'communication/class-ms-model-communication-before-finishes.php',  
  221. 'MS_Model_Communication_Before_Payment_Due' => 'communication/class-ms-model-communication-before-payment-due.php',  
  222. 'MS_Model_Communication_Before_Trial_Finishes' => 'communication/class-ms-model-communication-before-trial-finishes.php',  
  223. 'MS_Model_Communication_Credit_Card_Expire' => 'communication/class-ms-model-communication-credit-card-expire.php',  
  224. 'MS_Model_Communication_Failed_Payment' => 'communication/class-ms-model-communication-failed-payment.php',  
  225. 'MS_Model_Communication_Info_Update' => 'communication/class-ms-model-communication-info-update.php',  
  226. 'MS_Model_Communication_Registration_Free' => 'communication/class-ms-model-communication-registration-free.php',  
  227. ); 
  228.  
  229. foreach ( $models as $key => $path ) { 
  230. $overrides[ $key ] = $models_base . $path; 
  231.  
  232. return $overrides; 
  233.  
  234. /** 
  235. * Class autoloading callback function. 
  236. * 
  237. * Uses the **MS_** namespace to autoload classes when called. 
  238. * Avoids creating include functions for each file in the MVC structure. 
  239. * **MS_** namespace ONLY will be based on folder structure in /app/ 
  240. * 
  241. * @since 1.0.0 
  242. * 
  243. * @param string $class Uses PHP autoloader function. 
  244. * @return boolean 
  245. */ 
  246. private function class_loader( $class ) { 
  247. static $Path_overrides = null; 
  248.  
  249. /** 
  250. * Actions to execute before the autoloader loads a class. 
  251. * 
  252. * @since 1.0.0 
  253. * @param object $this The MS_Plugin object. 
  254. */ 
  255. do_action( 'ms_plugin_class_loader_pre_processing', $this ); 
  256.  
  257. $basedir = dirname( __FILE__ ); 
  258. $class = trim( $class ); 
  259.  
  260. if ( null === $Path_overrides ) { 
  261. /** 
  262. * Adds and Filters class path overrides. 
  263. * 
  264. * @since 1.0.0 
  265. * @param object $this The MS_Plugin object. 
  266. */ 
  267. $Path_overrides = apply_filters( 'ms_class_path_overrides', array(), $this ); 
  268.  
  269. if ( array_key_exists( $class, $Path_overrides ) ) { 
  270. /** 
  271. * Case 1: The class-path is explicitly defined in $Path_overrides. 
  272. * Simply use the defined path to load the class. 
  273. */ 
  274. $file_path = $basedir . '/' . $Path_overrides[ $class ]; 
  275.  
  276. /** 
  277. * Overrides the filename and path. 
  278. * 
  279. * @since 1.0.0 
  280. * @param object $this The MS_Plugin object. 
  281. */ 
  282. $file_path = apply_filters( 'ms_class_file_override', $file_path, $this ); 
  283.  
  284. if ( is_file( $file_path ) ) { 
  285. include_once $file_path; 
  286.  
  287. return true; 
  288. } elseif ( 'MS_' == substr( $class, 0, 3 ) ) { 
  289. /** 
  290. * Case 2: The class-path is not explicitely defined in $Path_overrides. 
  291. * Use /app/ path and class-name to build the file-name. 
  292. */ 
  293.  
  294. $path_array = explode( '_', $class ); 
  295. array_shift( $path_array ); // Remove the 'MS' prefix from path. 
  296. $alt_dir = array_pop( $path_array ); 
  297. $sub_path = implode( '/', $path_array ); 
  298.  
  299. $filename = str_replace( '_', '-', 'class-' . $class . '.php' ); 
  300. $file_path = strtolower( $sub_path . '/' . $filename ); 
  301. $file_path_alt = strtolower( $sub_path . '/' . $alt_dir . '/' . $filename ); 
  302.  
  303.  
  304.  
  305. // If no premium class is found check for default app class. 
  306. $file_path1 = $basedir . '/app/' . $file_path; 
  307. $file_path2 = $basedir . '/app/' . $file_path_alt; 
  308.  
  309. if ( is_file( $file_path1 ) ) { 
  310. include_once $file_path1; 
  311. return true; 
  312. } elseif ( is_file( $file_path2 ) ) { 
  313. include_once $file_path2; 
  314. return true; 
  315.  
  316. return false; 
  317. }; 
  318.  
  319.  
  320. /** 
  321. * This is a hack to prevent cookie issue in IE11 and EDGE 
  322. * Need to refactor in later 
  323. * 
  324. * @since 1.0.2.8 
  325. * @todo Move this code into a different class. Simply call here via MS_TheClass::check_ms_ajax() 
  326. */ 
  327. if ( isset( $_REQUEST['ms_ajax'] ) ) { 
  328. if ( 1 == $_REQUEST['ms_ajax'] ) { 
  329. add_action( 'wp_ajax_ms_login', 'ms_ajax_login' ); 
  330. add_action( 'wp_ajax_nopriv_ms_login', 'ms_ajax_login' ); 
  331.  
  332. function ms_ajax_login() { 
  333. $resp = array(); 
  334. check_ajax_referer( 'ms-ajax-login' ); 
  335.  
  336. if ( empty( $_POST['username'] ) && ! empty( $_POST['log'] ) ) { 
  337. $_POST['username'] = $_POST['log']; 
  338. if ( empty( $_POST['password'] ) && ! empty( $_POST['pwd'] ) ) { 
  339. $_POST['password'] = $_POST['pwd']; 
  340. if ( empty( $_POST['remember'] ) && ! empty( $_POST['rememberme'] ) ) { 
  341. $_POST['remember'] = $_POST['rememberme']; 
  342.  
  343. // Nonce is checked, get the POST data and sign user on 
  344. $info = array( 
  345. 'user_login' => $_POST['username'],  
  346. 'user_password' => $_POST['password'],  
  347. 'remember' => (bool) isset( $_POST['remember'] ) ? $_POST['remember'] : false,  
  348. ); 
  349.  
  350. $user_signon = wp_signon( $info, false ); 
  351.  
  352. if ( is_wp_error( $user_signon ) ) { 
  353. $resp['error'] = __( 'Wrong username or password', 'membership2' ); 
  354. } else { 
  355. $resp['loggedin'] = true; 
  356. $resp['success'] = __( 'Logging in...', 'membership2' ); 
  357.  
  358. /** 
  359. * Allows a custom redirection after login. 
  360. * Empty value will use the default redirect option of the login form. 
  361. */ 
  362.  
  363. // TODO: These filters are never called! 
  364. // This code is too early to allow any other plugin to register a filter handler... 
  365. $enforce = false; 
  366. if ( isset( $_POST['redirect_to'] ) ) { 
  367. $resp['redirect'] = apply_filters( 
  368. 'ms-ajax-login-redirect',  
  369. $_POST['redirect_to'],  
  370. $user_signon->ID 
  371. ); 
  372. } else { 
  373. $resp['redirect'] = apply_filters( 
  374. 'ms_url_after_login',  
  375. $_POST['redirect_to'],  
  376. $enforce 
  377. ); 
  378.  
  379. echo json_encode( $resp ); 
  380. exit(); 
  381.  
  382.  
  383.  
  384. function membership2_init_old_app() { 
  385. require_once 'app_old/membership.php'; 
  386.  
  387. function membership2_is_old_app() { 
  388. return true != get_option( 'm2_use_new_version' ); 
  389.  
  390. function membership2_use_m2() { 
  391. update_option( 'm2_use_new_version', true ); 
  392.  
  393. if ( membership2_is_old_app() ) { 
  394. membership2_init_old_app(); 
  395. } else { 
  396. membership2_init_app(); 
.