/membership.php

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