/membership.php

  1. <?php 
  2. /** 
  3. Plugin Name: Membership 2 
  4. Plugin URI: https://wordpress.org/plugins/membership 
  5. Version: 4.0.0.7 
  6. Description: The most powerful, easy to use and flexible membership plugin for WordPress sites available. 
  7. Author: WPMU DEV 
  8. Author URI: http://premium.wpmudev.org/ 
  9. WDP ID: 1003656 
  10. License: GNU General Public License (Version 2 - GPLv2) 
  11. Text Domain: membership2 
  12. */ 
  13.  
  14. /** 
  15. * @copyright Incsub (http://incsub.com/) 
  16. * 
  17. * Authors: Philipp Stracker, Fabio Jun Onishi, Victor Ivanov, Jack Kitterhing, Rheinard Korf 
  18. * Contributors: Joji Mori, Patrick Cohen 
  19. * 
  20. * @license http://opensource.org/licenses/GPL-2.0 GNU General Public License, version 2 (GPL-2.0) 
  21. * 
  22. * This program is free software; you can redistribute it and/or modify 
  23. * it under the terms of the GNU General Public License, version 2, as 
  24. * published by the Free Software Foundation. 
  25. * 
  26. * This program is distributed in the hope that it will be useful,  
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of 
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
  29. * GNU General Public License for more details. 
  30. * 
  31. * You should have received a copy of the GNU General Public License 
  32. * along with this program; if not, write to the Free Software 
  33. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,  
  34. * MA 02110-1301 USA 
  35. */ 
  36.  
  37. function membership2_init_old_app() { 
  38. require_once 'app_old/membership.php'; 
  39.  
  40. /** 
  41. * Initializes constants and create the main plugin object MS_Plugin. 
  42. * This function is called *instantly* when this file was loaded. 
  43. * 
  44. * @since 1.0.0 
  45. */ 
  46. function membership2_init_free_app() { 
  47. if ( defined( 'MS_PLUGIN' ) ) { 
  48. if ( is_admin() ) { 
  49. // Can happen in Multisite installs where a sub-site has activated the 
  50. // plugin and then the plugin is also activated in network-admin. 
  51. printf( 
  52. '<div class="notice error"><p><strong>%s</strong>: %s</p></div>',  
  53. sprintf( 
  54. __( 'Could not load the plugin %s, because another version of the plugin is already loaded', 'membership2' ),  
  55. 'Membership 2 (free)' 
  56. ),  
  57. MS_PLUGIN . ' (v' . MS_PLUGIN_VERSION . ')' 
  58. ); 
  59. return; 
  60.  
  61. /** 
  62. * Plugin version 
  63. * 
  64. * @since 1.0.0 
  65. */ 
  66. define( 'MS_PLUGIN_VERSION', '4.0.0.6' ); 
  67.  
  68. /** 
  69. * Plugin identifier constant. 
  70. * 
  71. * @since 1.0.0 
  72. */ 
  73. define( 'MS_PLUGIN', plugin_basename( __FILE__ ) ); 
  74.  
  75. /** 
  76. * Plugin name dir constant. 
  77. * 
  78. * @since 1.0.0 
  79. */ 
  80. define( 'MS_PLUGIN_NAME', dirname( MS_PLUGIN ) ); 
  81.  
  82. // WPMUDEV Dashboard is PRO ONLY! 
  83. $externals = array( 
  84. dirname( __FILE__ ) . '/lib/wpmu-lib/core.php',  
  85. dirname( __FILE__ ) . '/lib/wdev-frash/module.php',  
  86. ); 
  87.  
  88. foreach ( $externals as $path ) { 
  89. require_once $path; 
  90.  
  91. // Register the current plugin. 
  92. do_action( 
  93. 'wdev-register-plugin',  
  94. /** Plugin ID */ plugin_basename( __FILE__ ),  
  95. /** Plugin Title */ 'Membership 2',  
  96. /** https://wordpress.org */ '/plugins/membership/',  
  97. /** Email Button CTA */ __( 'Get Members!', 'membership2' ),  
  98. /** getdrip Plugin param */ 'Membership' 
  99. ); 
  100.  
  101. /** 
  102. * Translation. 
  103. * 
  104. * Tip: 
  105. * The translation files must have the filename [TEXT-DOMAIN]-[locale].mo 
  106. * Example: membership2-en_EN.mo / membership2-de_DE.mo 
  107. */ 
  108. function _membership2_translate_plugin() { 
  109. load_plugin_textdomain( 
  110. 'membership2',  
  111. false,  
  112. dirname( plugin_basename( __FILE__ ) ) . '/languages' 
  113. ); 
  114. add_action( 'plugins_loaded', '_membership2_translate_plugin' ); 
  115.  
  116. if ( defined( 'WP_DEBUG' ) && WP_DEBUG || WDEV_DEBUG ) { 
  117. // Load development/testing code before the plugin is initialized. 
  118. $testfile = dirname( __FILE__ ) . '/tests/wp/init.php'; 
  119. if ( file_exists( $testfile ) ) { include $testfile; } 
  120.  
  121. /** 
  122. * Create an instance of the plugin object. 
  123. * 
  124. * This is the primary entry point for the Membership plugin. 
  125. * 
  126. * @since 1.0.0 
  127. */ 
  128. MS_Plugin::instance(); 
  129.  
  130. /** 
  131. * Primary Membership plugin class. 
  132. * 
  133. * Initialises the autoloader and required plugin hooks. 
  134. * Control of plugin is passed to the MVC implementation found 
  135. * inside the /app/ folder. 
  136. * 
  137. * Note: Even all properties are marked private, they are made public via the 
  138. * magic __get() function. 
  139. * 
  140. * @since 1.0.0 
  141. * 
  142. * @return object Plugin instance. 
  143. */ 
  144. if ( ! class_exists( 'MS_Plugin' ) ) { 
  145. class MS_Plugin { 
  146.  
  147. /** 
  148. * Singletone instance of the plugin. 
  149. * 
  150. * @since 1.0.0 
  151. * 
  152. * @var MS_Plugin 
  153. */ 
  154. private static $instance = null; 
  155.  
  156. /** 
  157. * Modifier values. 
  158. * 
  159. * @since 1.0.0 
  160. * 
  161. * @var array 
  162. */ 
  163. private static $modifiers = array(); 
  164.  
  165. /** 
  166. * The WordPress internal plugin identifier. 
  167. * 
  168. * @since 1.0.0 
  169. * @var string 
  170. */ 
  171. private $id; 
  172.  
  173. /** 
  174. * The plugin name. 
  175. * 
  176. * @since 1.0.0 
  177. * @var string 
  178. */ 
  179. private $name; 
  180.  
  181. /** 
  182. * The plugin version. 
  183. * 
  184. * @since 1.0.0 
  185. * @var string 
  186. */ 
  187. private $version; 
  188.  
  189. /** 
  190. * The plugin file. 
  191. * 
  192. * @since 1.0.0 
  193. * @var string 
  194. */ 
  195. private $file; 
  196.  
  197. /** 
  198. * The plugin path. 
  199. * 
  200. * @since 1.0.0 
  201. * @var string 
  202. */ 
  203. private $dir; 
  204.  
  205. /** 
  206. * The plugin URL. 
  207. * 
  208. * @since 1.0.0 
  209. * @var string 
  210. */ 
  211. private $url; 
  212.  
  213. /** 
  214. * The plugin settings. 
  215. * 
  216. * @since 1.0.0 
  217. * @var MS_Model_Settings 
  218. */ 
  219. private $settings; 
  220.  
  221. /** 
  222. * The plugin add-on settings. 
  223. * 
  224. * @since 1.0.0 
  225. * @var MS_Model_Addon 
  226. */ 
  227. private $addon; 
  228.  
  229. /** 
  230. * The main controller of the plugin. 
  231. * 
  232. * @since 1.0.0 
  233. * @var MS_Controller_Plugin 
  234. */ 
  235. private $controller; 
  236.  
  237. /** 
  238. * The API controller (for convenience) 
  239. * 
  240. * @since 1.0.0 
  241. * @var MS_Controller_Api 
  242. */ 
  243. public static $api = null; 
  244.  
  245. /** 
  246. * Plugin constructor. 
  247. * 
  248. * Set properties, registers hooks and loads the plugin. 
  249. * 
  250. * @since 1.0.0 
  251. */ 
  252. public function __construct() { 
  253.  
  254. /** 
  255. * Actions to execute before the plugin construction starts. 
  256. * 
  257. * @since 1.0.0 
  258. * @param object $this The MS_Plugin object. 
  259. */ 
  260. do_action( 'ms_plugin_init', $this ); 
  261.  
  262. /** 
  263. * @since 1.0.0 
  264. * @deprecated since 2.0.0 
  265. */ 
  266. do_action( 'ms_plugin_construct_start', $this ); 
  267.  
  268. /** Setup plugin properties */ 
  269. $this->id = MS_PLUGIN; 
  270. $this->name = MS_PLUGIN_NAME; 
  271. $this->version = MS_PLUGIN_VERSION; 
  272. $this->file = __FILE__; 
  273. $this->dir = plugin_dir_path( __FILE__ ); 
  274. $this->url = plugin_dir_url( __FILE__ ); 
  275.  
  276. add_filter( 
  277. 'ms_class_path_overrides',  
  278. array( $this, 'ms_class_path_overrides' ) 
  279. ); 
  280.  
  281. // Creates the class autoloader. 
  282. spl_autoload_register( array( $this, 'class_loader' ) ); 
  283.  
  284. // Might refresh the Rewrite-Rules and reloads the page. 
  285. add_action( 
  286. 'wp_loaded',  
  287. array( $this, 'maybe_flush_rewrite_rules' ),  
  288. ); 
  289.  
  290. /** 
  291. * Hooks init to register custom post types. 
  292. */ 
  293. add_action( 
  294. 'init',  
  295. array( $this, 'register_custom_post_types' ),  
  296. ); 
  297.  
  298. /** 
  299. * Hooks init to add rewrite rules and tags (both work in conjunction). 
  300. */ 
  301. add_action( 'init', array( $this, 'add_rewrite_rules' ), 1 ); 
  302. add_action( 'init', array( $this, 'add_rewrite_tags' ), 1 ); 
  303.  
  304. // Plugin activation Hook 
  305. register_activation_hook( 
  306. __FILE__,  
  307. array( $this, 'plugin_activation' ) 
  308. ); 
  309.  
  310. /** 
  311. * Hooks init to create the primary plugin controller. 
  312. * 
  313. * We use the setup_theme hook because plugins_loaded is too early: 
  314. * wp_redirect (used by the update model) is initialized after 
  315. * plugins_loaded but before setup_theme. 
  316. */ 
  317. add_action( 
  318. 'setup_theme',  
  319. array( $this, 'ms_plugin_constructing' ) 
  320. ); 
  321.  
  322. /** 
  323. * Creates and Filters the Settings Model. 
  324. * 
  325. * @since 1.0.0 
  326. * @param object $this The MS_Plugin object. 
  327. */ 
  328. $this->settings = MS_Factory::load( 'MS_Model_Settings' ); 
  329.  
  330. /** 
  331. * Creates and Filters the Addon Model. 
  332. * 
  333. * @since 1.0.0 
  334. * @param object $this The MS_Plugin object. 
  335. */ 
  336. $this->addon = MS_Factory::load( 'MS_Model_Addon' ); 
  337.  
  338. add_filter( 
  339. 'plugin_action_links_' . MS_PLUGIN,  
  340. array( $this, 'plugin_settings_link' ) 
  341. ); 
  342.  
  343. add_filter( 
  344. 'network_admin_plugin_action_links_' . MS_PLUGIN,  
  345. array( $this, 'plugin_settings_link' ) 
  346. ); 
  347.  
  348. // Grab instance of self. 
  349. self::$instance = $this; 
  350.  
  351. /** 
  352. * Actions to execute when the Plugin object has successfully constructed. 
  353. * 
  354. * @since 1.0.0 
  355. * @param object $this The MS_Plugin object. 
  356. */ 
  357. do_action( 'ms_plugin_construct_end', $this ); 
  358.  
  359. /** 
  360. * Hooks 'ms_class_path_overrides'. 
  361. * 
  362. * Overrides plugin class paths to adhere to naming conventions 
  363. * where object names are separated by underscores or for special cases. 
  364. * 
  365. * @since 1.0.0 
  366. * 
  367. * @param array $overrides Array passed in by filter. 
  368. * @return array(class=>path) Classes with new file paths. 
  369. */ 
  370. public function ms_class_path_overrides( $overrides ) { 
  371. $models_base = 'app/model/'; 
  372. $models = array( 
  373. 'MS_Model_Communication_After_Finishes' => 'communication/class-ms-model-communication-after-finishes.php',  
  374. 'MS_Model_Communication_After_Payment_Due' => 'communication/class-ms-model-communication-after-payment-due.php',  
  375. 'MS_Model_Communication_Before_Finishes' => 'communication/class-ms-model-communication-before-finishes.php',  
  376. 'MS_Model_Communication_Before_Payment_Due' => 'communication/class-ms-model-communication-before-payment-due.php',  
  377. 'MS_Model_Communication_Before_Trial_Finishes' => 'communication/class-ms-model-communication-before-trial-finishes.php',  
  378. 'MS_Model_Communication_Credit_Card_Expire' => 'communication/class-ms-model-communication-credit-card-expire.php',  
  379. 'MS_Model_Communication_Failed_Payment' => 'communication/class-ms-model-communication-failed-payment.php',  
  380. 'MS_Model_Communication_Info_Update' => 'communication/class-ms-model-communication-info-update.php',  
  381. 'MS_Model_Communication_Registration_Free' => 'communication/class-ms-model-communication-registration-free.php',  
  382. ); 
  383.  
  384. foreach ( $models as $key => $path ) { 
  385. $overrides[ $key ] = $models_base . $path; 
  386.  
  387. return $overrides; 
  388.  
  389. /** 
  390. * Loads primary plugin controllers. 
  391. * 
  392. * Related Action Hooks: 
  393. * - setup_theme 
  394. * 
  395. * @since 1.0.0 
  396. */ 
  397. public function ms_plugin_constructing() { 
  398. /** 
  399. * Creates and Filters the Plugin Controller. 
  400. * 
  401. * ---> MAIN ENTRY POINT CONTROLLER FOR PLUGIN <--- 
  402. * 
  403. * @uses MS_Controller_Plugin 
  404. * @since 1.0.0 
  405. */ 
  406. $this->controller = MS_Factory::create( 'MS_Controller_Plugin' ); 
  407.  
  408. /** 
  409. * Register plugin custom post types. 
  410. * 
  411. * @since 1.0.0 
  412. */ 
  413. public function register_custom_post_types() { 
  414. do_action( 'ms_plugin_register_custom_post_types_before', $this ); 
  415.  
  416. $cpts = apply_filters( 
  417. 'ms_plugin_register_custom_post_types',  
  418. array( 
  419. MS_Model_Membership::get_post_type() => MS_Model_Membership::get_register_post_type_args(),  
  420. MS_Model_Relationship::get_post_type() => MS_Model_Relationship::get_register_post_type_args(),  
  421. MS_Model_Invoice::get_post_type() => MS_Model_Invoice::get_register_post_type_args(),  
  422. MS_Model_Communication::get_post_type() => MS_Model_Communication::get_register_post_type_args(),  
  423. MS_Model_Event::get_post_type() => MS_Model_Event::get_register_post_type_args(),  
  424. ); 
  425.  
  426. foreach ( $cpts as $cpt => $args ) { 
  427. MS_Helper_Utility::register_post_type( $cpt, $args ); 
  428.  
  429. /** 
  430. * Add rewrite rules. 
  431. * 
  432. * @since 1.0.0 
  433. */ 
  434. public function add_rewrite_rules() { 
  435. $settings = MS_Factory::load( 'MS_Model_Settings' ); 
  436.  
  437. // Gateway return - IPN. 
  438. add_rewrite_rule( 
  439. 'ms-payment-return/(.+)/?',  
  440. 'index.php?paymentgateway=$matches[1]',  
  441. 'top' 
  442. ); 
  443.  
  444. // Alternative payment return URL: Membership 
  445. if ( MS_Model_Import_Membership::did_import() ) { 
  446. add_rewrite_rule( 
  447. 'paymentreturn/(.+)/?',  
  448. 'index.php?paymentgateway=$matches[1]',  
  449. 'top' 
  450. ); 
  451.  
  452. // Media / download 
  453. $mmask = $settings->downloads['masked_url']; 
  454. $mtype = $settings->downloads['protection_type']; 
  455.  
  456. if ( MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_MEDIA ) && $mmask ) { 
  457. if ( MS_Rule_Media_Model::PROTECTION_TYPE_HYBRID == $mtype ) { 
  458. add_rewrite_rule( 
  459. sprintf( '^%1$s/?$', $mmask ),  
  460. 'index.php?protectedfile=0',  
  461. 'top' 
  462. ); 
  463. } else { 
  464. add_rewrite_rule( 
  465. sprintf( '^%1$s/([^/]+)', $mmask ),  
  466. 'index.php?protectedfile=$matches[1]',  
  467. 'top' 
  468. ); 
  469. // End: Media / download 
  470.  
  471. do_action( 'ms_plugin_add_rewrite_rules', $this ); 
  472.  
  473. /** 
  474. * Add rewrite tags. 
  475. * 
  476. * @since 1.0.0 
  477. */ 
  478. public function add_rewrite_tags() { 
  479. // Membership site pages. 
  480. add_rewrite_tag( '%ms_page%', '(.+)' ); 
  481.  
  482. // Gateway return - IPN. 
  483. add_rewrite_tag( '%paymentgateway%', '(.+)' ); 
  484.  
  485. // Media / download 
  486. add_rewrite_tag( '%protectedfile%', '(.+)' ); 
  487.  
  488. do_action( 'ms_plugin_add_rewrite_tags', $this ); 
  489.  
  490. /** 
  491. * Actions executed in plugin activation. 
  492. * 
  493. * @since 1.0.0 
  494. */ 
  495. public function plugin_activation() { 
  496. // Prevent recursion during plugin activation. 
  497. $refresh = lib3()->session->get( 'refresh_url_rules' ); 
  498. if ( $refresh ) { return; } 
  499.  
  500. // Update the Membership2 database entries after activation. 
  501. MS_Model_Upgrade::update( true ); 
  502.  
  503. do_action( 'ms_plugin_activation', $this ); 
  504.  
  505. /** 
  506. * Redirect page and request plugin to flush the WordPress rewrite rules 
  507. * on next request. 
  508. * 
  509. * @since 1.0.0 
  510. * @param string $url The URL to load after flushing the rewrite rules. 
  511. */ 
  512. static public function flush_rewrite_rules( $url = false ) { 
  513. if ( isset( $_GET['ms_flushed'] ) && 'yes' == $_GET['ms_flushed'] ) { 
  514. $refresh = true; 
  515. } else { 
  516. $refresh = lib3()->session->get( 'refresh_url_rules' ); 
  517.  
  518. if ( $refresh ) { return; } 
  519.  
  520. lib3()->session->add( 'refresh_url_rules', true ); 
  521.  
  522. // The URL param is only to avoid cache. 
  523. $url = esc_url_raw( 
  524. add_query_arg( 'ms_ts', time(), $url ) 
  525. ); 
  526. wp_safe_redirect( $url ); 
  527. exit; 
  528.  
  529. /** 
  530. * Flush the WordPress rewrite rules. 
  531. * 
  532. * @since 1.0.0 
  533. */ 
  534. public function maybe_flush_rewrite_rules() { 
  535. $refresh = lib3()->session->get_clear( 'refresh_url_rules' ); 
  536. if ( ! $refresh ) { return; } 
  537.  
  538. // Set up the plugin specific rewrite rules again. 
  539. $this->add_rewrite_rules(); 
  540. $this->add_rewrite_tags(); 
  541.  
  542. do_action( 'ms_plugin_flush_rewrite_rules', $this ); 
  543.  
  544. $url = remove_query_arg( 'ms_ts' ); 
  545. $url = esc_url_raw( add_query_arg( 'ms_flushed', 'yes', $url ) ); 
  546. wp_safe_redirect( $url ); 
  547. exit; 
  548.  
  549. /** 
  550. * Class autoloading callback function. 
  551. * 
  552. * Uses the **MS_** namespace to autoload classes when called. 
  553. * Avoids creating include functions for each file in the MVC structure. 
  554. * **MS_** namespace ONLY will be based on folder structure in /app/ 
  555. * 
  556. * @since 1.0.0 
  557. * 
  558. * @param string $class Uses PHP autoloader function. 
  559. * @return boolean 
  560. */ 
  561. private function class_loader( $class ) { 
  562. static $Path_overrides = null; 
  563.  
  564. /** 
  565. * Actions to execute before the autoloader loads a class. 
  566. * 
  567. * @since 1.0.0 
  568. * @param object $this The MS_Plugin object. 
  569. */ 
  570. do_action( 'ms_plugin_class_loader_pre_processing', $this ); 
  571.  
  572. $basedir = dirname( __FILE__ ); 
  573. $class = trim( $class ); 
  574.  
  575. if ( null === $Path_overrides ) { 
  576. /** 
  577. * Adds and Filters class path overrides. 
  578. * 
  579. * @since 1.0.0 
  580. * @param object $this The MS_Plugin object. 
  581. */ 
  582. $Path_overrides = apply_filters( 'ms_class_path_overrides', array(), $this ); 
  583.  
  584. if ( array_key_exists( $class, $Path_overrides ) ) { 
  585. /** 
  586. * Case 1: The class-path is explicitly defined in $Path_overrides. 
  587. * Simply use the defined path to load the class. 
  588. */ 
  589. $file_path = $basedir . '/' . $Path_overrides[ $class ]; 
  590.  
  591. /** 
  592. * Overrides the filename and path. 
  593. * 
  594. * @since 1.0.0 
  595. * @param object $this The MS_Plugin object. 
  596. */ 
  597. $file_path = apply_filters( 'ms_class_file_override', $file_path, $this ); 
  598.  
  599. if ( is_file( $file_path ) ) { 
  600. include_once $file_path; 
  601.  
  602. return true; 
  603. } elseif ( 'MS_' == substr( $class, 0, 3 ) ) { 
  604. /** 
  605. * Case 2: The class-path is not explicitely defined in $Path_overrides. 
  606. * Use /app/ path and class-name to build the file-name. 
  607. */ 
  608.  
  609. $path_array = explode( '_', $class ); 
  610. array_shift( $path_array ); 
  611. $alt_dir = array_pop( $path_array ); 
  612. $sub_path = implode( '/', $path_array ); 
  613.  
  614. $filename = str_replace( '_', '-', 'class-' . $class . '.php' ); 
  615. $file_path = $basedir . '/app/' . strtolower( $sub_path . '/' . $filename ); 
  616. $file_path_alt = $basedir . '/app/' . strtolower( $sub_path . '/' . $alt_dir . '/' . $filename ); 
  617.  
  618. /** 
  619. * Overrides the filename and path. 
  620. * 
  621. * @since 1.0.0 
  622. * @param object $this The MS_Plugin object. 
  623. */ 
  624. $file_path = apply_filters( 'ms_class_file_override', $file_path, $this ); 
  625. $file_path_alt = apply_filters( 'ms_class_file_override', $file_path_alt, $this ); 
  626.  
  627. if ( is_file( $file_path ) ) { 
  628. include_once $file_path; 
  629. } elseif ( is_file( $file_path_alt ) ) { 
  630. include_once $file_path_alt; 
  631.  
  632. return true; 
  633.  
  634. return false; 
  635.  
  636. /** 
  637. * Add link to settings page in plugins page. 
  638. * 
  639. * @since 1.0.0 
  640. * 
  641. * @param array $links WordPress default array of links. 
  642. * @return array Array of links with settings page links added. 
  643. */ 
  644. public function plugin_settings_link( $links ) { 
  645. if ( ! is_network_admin() ) { 
  646. $text = __( 'Settings', 'membership2' ); 
  647. $url = MS_Controller_Plugin::get_admin_url( 'settings' ); 
  648.  
  649. if ( $this->settings->initial_setup ) { 
  650. $url = MS_Controller_Plugin::get_admin_url(); 
  651.  
  652. /** 
  653. * Filter the plugin settings link. 
  654. * 
  655. * @since 1.0.0 
  656. * @param object $this The MS_Plugin object. 
  657. */ 
  658. $settings_link = apply_filters( 
  659. 'ms_plugin_settings_link',  
  660. sprintf( '<a href="%s">%s</a>', $url, $text ),  
  661. $this 
  662. ); 
  663. array_unshift( $links, $settings_link ); 
  664.  
  665. return $links; 
  666.  
  667. /** 
  668. * Returns singleton instance of the plugin. 
  669. * 
  670. * @since 1.0.0 
  671. * 
  672. * @static 
  673. * @access public 
  674. * 
  675. * @return MS_Plugin 
  676. */ 
  677. public static function instance() { 
  678. if ( ! self::$instance ) { 
  679. self::$instance = new MS_Plugin(); 
  680.  
  681. self::$instance = apply_filters( 
  682. 'ms_plugin_instance',  
  683. self::$instance 
  684. ); 
  685.  
  686. return self::$instance; 
  687.  
  688. /** 
  689. * Returns plugin enabled status. 
  690. * 
  691. * @since 1.0.0 
  692. * @access public 
  693. * 
  694. * @static 
  695. * 
  696. * @return bool The status. 
  697. */ 
  698. public static function is_enabled() { 
  699. return self::instance()->settings->plugin_enabled; 
  700.  
  701. /** 
  702. * Returns plugin wizard status. 
  703. * 
  704. * @since 1.0.0 
  705. * @access public 
  706. * 
  707. * @static 
  708. * 
  709. * @return bool The status. 
  710. */ 
  711. public static function is_wizard() { 
  712. return ! ! self::instance()->settings->initial_setup; 
  713.  
  714. /** 
  715. * Returns the network-wide protection status. 
  716. * 
  717. * This flag can be changed by setting the MS_PROTECT_NETWORK flag to true 
  718. * in wp-config.php 
  719. * 
  720. * @since 1.0.0 
  721. * @return bool False means that only the current site is protected. 
  722. * True means that memberships are shared among all network sites. 
  723. */ 
  724. public static function is_network_wide() { 
  725. // THIS IS A PRO FEATURE: 
  726. // IN THE FREE VERSION THIS FUNCTION MUST ALWAYS RETURN FALSE! 
  727. // ELSE YOUR PROTECTION SETTINGS WILL GET MESSED UP. 
  728. return false; 
  729.  
  730. /** 
  731. * Returns a modifier option. 
  732. * This is similar to a setting but more "advanced" in a way that there is 
  733. * no UI for it. A modifier can be set by the plugin (e.g. during Import 
  734. * the "no_messages" modifier is enabled) or via a const in wp-config.php 
  735. * 
  736. * A modifier is never saved in the database. 
  737. * It can be defined ONLY via MS_Plugin::set_modifier() or via wp-config.php 
  738. * The set_modifier() value will always take precedence over wp-config.php 
  739. * definitions. 
  740. * 
  741. * @since 1.0.0 
  742. * @api 
  743. * 
  744. * @param string $key Name of the modifier. 
  745. * @return mixed The modifier value or null. 
  746. */ 
  747. public static function get_modifier( $key ) { 
  748. $res = null; 
  749.  
  750. if ( isset( self::$modifiers[$key] ) ) { 
  751. $res = self::$modifiers[$key]; 
  752. } elseif ( defined( $key ) ) { 
  753. $res = constant( $key ); 
  754.  
  755. return $res; 
  756.  
  757. /** 
  758. * Changes a modifier option. 
  759. * @see get_modifier() for more details. 
  760. * 
  761. * @since 1.0.0 
  762. * @api 
  763. * 
  764. * @param string $key Name of the modifier. 
  765. * @param mixed $value Value of the modifier. `null` unsets the modifier. 
  766. */ 
  767. public static function set_modifier( $key, $value = null ) { 
  768. if ( null === $value ) { 
  769. unset( self::$modifiers[$key] ); 
  770. } else { 
  771. self::$modifiers[$key] = $value; 
  772.  
  773. /** 
  774. * This funciton initializes the api property for easy access to the plugin 
  775. * API. This function is *only* called by MS_Controller_Api::__construct()! 
  776. * 
  777. * @since 1.0.0 
  778. * @internal 
  779. * @param MS_Controller_Api $controller The initialized API controller. 
  780. */ 
  781. public static function set_api( $controller ) { 
  782. self::$api = $controller; 
  783.  
  784. /** 
  785. * Returns property associated with the plugin. 
  786. * 
  787. * @since 1.0.0 
  788. * 
  789. * @access public 
  790. * @param string $property The name of a property. 
  791. * @return mixed Returns mixed value of a property or NULL if a property doesn't exist. 
  792. */ 
  793. public function __get( $property ) { 
  794. if ( property_exists( $this, $property ) ) { 
  795. return $this->$property; 
  796. } // end: if ! class_exists 
  797.  
  798. function membership2_is_old_app() { 
  799. return true != get_option( 'm2_use_new_version' ); 
  800.  
  801. function membership2_use_m2() { 
  802. update_option( 'm2_use_new_version', true ); 
  803.  
  804. if ( membership2_is_old_app() ) { 
  805. membership2_init_old_app(); 
  806. } else { 
  807. membership2_init_free_app(); 
.