/membership.php

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