class.swpm-settings.php 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  1. <?php
  2. class SwpmSettings {
  3. private static $_this;
  4. private $settings;
  5. public $current_tab;
  6. private $tabs;
  7. private function __construct() {
  8. $this->settings = (array) get_option( 'swpm-settings' );
  9. }
  10. public function init_config_hooks() {
  11. //This function is called from "admin_init"
  12. //It sets up the various tabs and the fields for the settings admin page.
  13. if ( is_admin() ) { // for frontend just load settings but dont try to render settings page.
  14. //Read the value of tab query arg.
  15. $tab = isset( $_REQUEST['tab'] ) ? sanitize_text_field( $_REQUEST['tab'] ) : 1;
  16. $this->current_tab = empty( $tab ) ? 1 : $tab;
  17. //Setup the available settings tabs array.
  18. $this->tabs = array(
  19. 1 => SwpmUtils::_( 'General Settings' ),
  20. 2 => SwpmUtils::_( 'Payment Settings' ),
  21. 3 => SwpmUtils::_( 'Email Settings' ),
  22. 4 => SwpmUtils::_( 'Tools' ),
  23. 5 => SwpmUtils::_( 'Advanced Settings' ),
  24. 6 => SwpmUtils::_( 'Addons Settings' ),
  25. );
  26. //Register the draw tab action hook. It will be triggered using do_action("swpm-draw-settings-nav-tabs")
  27. add_action( 'swpm-draw-settings-nav-tabs', array( &$this, 'draw_tabs' ) );
  28. //Register the various settings fields for the current tab.
  29. $method = 'tab_' . $this->current_tab;
  30. if ( method_exists( $this, $method ) ) {
  31. $this->$method();
  32. }
  33. }
  34. }
  35. private function tab_1() {
  36. //Register settings sections and fileds for the general settings tab.
  37. register_setting( 'swpm-settings-tab-1', 'swpm-settings', array( &$this, 'sanitize_tab_1' ) );
  38. //This settings section has no heading
  39. add_settings_section( 'swpm-general-post-submission-check', '', array( &$this, 'swpm_general_post_submit_check_callback' ), 'simple_wp_membership_settings' );
  40. add_settings_section( 'swpm-documentation', SwpmUtils::_( 'Plugin Documentation' ), array( &$this, 'swpm_documentation_callback' ), 'simple_wp_membership_settings' );
  41. add_settings_section( 'general-settings', SwpmUtils::_( 'General Settings' ), array( &$this, 'general_settings_callback' ), 'simple_wp_membership_settings' );
  42. add_settings_field(
  43. 'enable-free-membership',
  44. SwpmUtils::_( 'Enable Free Membership' ),
  45. array( &$this, 'checkbox_callback' ),
  46. 'simple_wp_membership_settings',
  47. 'general-settings',
  48. array(
  49. 'item' => 'enable-free-membership',
  50. 'message' => SwpmUtils::_( 'Enable/disable registration for free membership level. When you enable this option, make sure to specify a free membership level ID in the field below.' ),
  51. )
  52. );
  53. add_settings_field(
  54. 'free-membership-id',
  55. SwpmUtils::_( 'Free Membership Level ID' ),
  56. array( &$this, 'textfield_small_callback' ),
  57. 'simple_wp_membership_settings',
  58. 'general-settings',
  59. array(
  60. 'item' => 'free-membership-id',
  61. 'message' => SwpmUtils::_( 'Assign free membership level ID' ),
  62. )
  63. );
  64. add_settings_field(
  65. 'enable-moretag',
  66. SwpmUtils::_( 'Enable More Tag Protection' ),
  67. array( &$this, 'checkbox_callback' ),
  68. 'simple_wp_membership_settings',
  69. 'general-settings',
  70. array(
  71. 'item' => 'enable-moretag',
  72. 'message' => SwpmUtils::_( 'Enables or disables "more" tag protection in the posts and pages. Anything after the More tag is protected. Anything before the more tag is teaser content.' ),
  73. )
  74. );
  75. add_settings_field(
  76. 'hide-adminbar',
  77. SwpmUtils::_( 'Hide Adminbar' ),
  78. array( &$this, 'checkbox_callback' ),
  79. 'simple_wp_membership_settings',
  80. 'general-settings',
  81. array(
  82. 'item' => 'hide-adminbar',
  83. 'message' => SwpmUtils::_( 'WordPress shows an admin toolbar to the logged in users of the site. Check this if you want to hide that admin toolbar in the frontend of your site.' ),
  84. )
  85. );
  86. add_settings_field(
  87. 'show-adminbar-admin-only',
  88. SwpmUtils::_( 'Show Adminbar to Admin' ),
  89. array( &$this, 'checkbox_callback' ),
  90. 'simple_wp_membership_settings',
  91. 'general-settings',
  92. array(
  93. 'item' => 'show-adminbar-admin-only',
  94. 'message' => SwpmUtils::_( 'Use this option if you want to show the admin toolbar to admin users only. The admin toolbar will be hidden for all other users.' ),
  95. )
  96. );
  97. add_settings_field(
  98. 'disable-access-to-wp-dashboard',
  99. SwpmUtils::_( 'Disable Access to WP Dashboard' ),
  100. array( &$this, 'checkbox_callback' ),
  101. 'simple_wp_membership_settings',
  102. 'general-settings',
  103. array(
  104. 'item' => 'disable-access-to-wp-dashboard',
  105. 'message' => SwpmUtils::_( 'WordPress allows a standard wp user to be able to go to the wp-admin URL and access his profile from the wp dashbaord. Using this option will prevent any non admin users from going to the wp dashboard.' ),
  106. )
  107. );
  108. add_settings_field(
  109. 'default-account-status',
  110. SwpmUtils::_( 'Default Account Status' ),
  111. array( &$this, 'selectbox_callback' ),
  112. 'simple_wp_membership_settings',
  113. 'general-settings',
  114. array(
  115. 'item' => 'default-account-status',
  116. 'options' => SwpmUtils::get_account_state_options(),
  117. 'default' => 'active',
  118. 'message' => SwpmUtils::_( 'Select the default account status for newly registered users. If you want to manually approve the members then you can set the status to "Pending".' ),
  119. )
  120. );
  121. add_settings_field(
  122. 'members-login-to-comment',
  123. SwpmUtils::_( 'Members Must be Logged in to Comment' ),
  124. array( &$this, 'checkbox_callback' ),
  125. 'simple_wp_membership_settings',
  126. 'general-settings',
  127. array(
  128. 'item' => 'members-login-to-comment',
  129. 'message' => SwpmUtils::_( 'Enable this option if you only want the members of the site to be able to post a comment.' ),
  130. )
  131. );
  132. /*
  133. add_settings_field('protect-everything', SwpmUtils::_('Protect Everything'),
  134. array(&$this, 'checkbox_callback'), 'simple_wp_membership_settings', 'general-settings',
  135. array('item' => 'protect-everything',
  136. 'message'=>SwpmUtils::_('Check this box if you want to protect all posts/pages by default.')));
  137. */
  138. add_settings_section( 'pages-settings', SwpmUtils::_( 'Pages Settings' ), array( &$this, 'pages_settings_callback' ), 'simple_wp_membership_settings' );
  139. add_settings_field(
  140. 'login-page-url',
  141. SwpmUtils::_( 'Login Page URL' ),
  142. array( &$this, 'textfield_long_callback' ),
  143. 'simple_wp_membership_settings',
  144. 'pages-settings',
  145. array(
  146. 'item' => 'login-page-url',
  147. 'message' => '',
  148. )
  149. );
  150. add_settings_field(
  151. 'registration-page-url',
  152. SwpmUtils::_( 'Registration Page URL' ),
  153. array( &$this, 'textfield_long_callback' ),
  154. 'simple_wp_membership_settings',
  155. 'pages-settings',
  156. array(
  157. 'item' => 'registration-page-url',
  158. 'message' => '',
  159. )
  160. );
  161. add_settings_field(
  162. 'join-us-page-url',
  163. SwpmUtils::_( 'Join Us Page URL' ),
  164. array( &$this, 'textfield_long_callback' ),
  165. 'simple_wp_membership_settings',
  166. 'pages-settings',
  167. array(
  168. 'item' => 'join-us-page-url',
  169. 'message' => '',
  170. )
  171. );
  172. add_settings_field(
  173. 'profile-page-url',
  174. SwpmUtils::_( 'Edit Profile Page URL' ),
  175. array( &$this, 'textfield_long_callback' ),
  176. 'simple_wp_membership_settings',
  177. 'pages-settings',
  178. array(
  179. 'item' => 'profile-page-url',
  180. 'message' => '',
  181. )
  182. );
  183. add_settings_field(
  184. 'reset-page-url',
  185. SwpmUtils::_( 'Password Reset Page URL' ),
  186. array( &$this, 'textfield_long_callback' ),
  187. 'simple_wp_membership_settings',
  188. 'pages-settings',
  189. array(
  190. 'item' => 'reset-page-url',
  191. 'message' => '',
  192. )
  193. );
  194. add_settings_section( 'debug-settings', SwpmUtils::_( 'Test & Debug Settings' ), array( &$this, 'testndebug_settings_callback' ), 'simple_wp_membership_settings' );
  195. $debug_field_help_text = SwpmUtils::_( 'Check this option to enable debug logging.' );
  196. $debug_field_help_text .= SwpmUtils::_( ' This can be useful when troubleshooting an issue. Turn it off and reset the log files after the troubleshooting is complete.' );
  197. $debug_field_help_text .= '<br />';
  198. $debug_field_help_text .= '<br />- ' . SwpmUtils::_( 'View general debug log file by clicking ' ) . '<a href="' . SIMPLE_WP_MEMBERSHIP_URL . '/log.txt" target="_blank">' . SwpmUtils::_( 'here' ) . '</a>.';
  199. $debug_field_help_text .= '<br />- ' . SwpmUtils::_( 'View login related debug log file by clicking ' ) . '<a href="' . SIMPLE_WP_MEMBERSHIP_URL . '/log-auth.txt" target="_blank">' . SwpmUtils::_( 'here' ) . '</a>.';
  200. $debug_field_help_text .= '<br />- ' . SwpmUtils::_( 'Reset debug log files by clicking ' ) . '<a href="admin.php?page=simple_wp_membership_settings&swmp_reset_log=1" target="_blank">' . SwpmUtils::_( 'here' ) . '</a>.';
  201. add_settings_field(
  202. 'enable-debug',
  203. SwpmUtils::_( 'Enable Debug' ),
  204. array( &$this, 'checkbox_callback' ),
  205. 'simple_wp_membership_settings',
  206. 'debug-settings',
  207. array(
  208. 'item' => 'enable-debug',
  209. 'message' => $debug_field_help_text,
  210. )
  211. );
  212. add_settings_field(
  213. 'enable-sandbox-testing',
  214. SwpmUtils::_( 'Enable Sandbox Testing' ),
  215. array( &$this, 'checkbox_callback' ),
  216. 'simple_wp_membership_settings',
  217. 'debug-settings',
  218. array(
  219. 'item' => 'enable-sandbox-testing',
  220. 'message' => SwpmUtils::_( 'Enable this option if you want to do sandbox payment testing.' ),
  221. )
  222. );
  223. }
  224. private function tab_2() {
  225. //Register settings sections and fileds for the payment settings tab.
  226. register_setting( 'swpm-settings-tab-2', 'swpm-settings', array( $this, 'sanitize_tab_2' ) );
  227. add_settings_section( 'stripe-global-settings', SwpmUtils::_( 'Stripe Global Settings' ), null, 'simple_wp_membership_settings' );
  228. add_settings_field(
  229. 'stripe-prefill-member-email',
  230. SwpmUtils::_( 'Pre-fill Member Email Address' ),
  231. array( $this, 'checkbox_callback' ),
  232. 'simple_wp_membership_settings',
  233. 'stripe-global-settings',
  234. array(
  235. 'item' => 'stripe-prefill-member-email',
  236. 'message' => SwpmUtils::_( 'Pre-fills the email address of the logged-in member on the Stripe checkout form when possible' ),
  237. )
  238. );
  239. add_settings_field(
  240. 'stripe-test-public-key',
  241. SwpmUtils::_( 'Test Publishable Key' ),
  242. array( $this, 'textfield_callback' ),
  243. 'simple_wp_membership_settings',
  244. 'stripe-global-settings',
  245. array(
  246. 'item' => 'stripe-test-public-key',
  247. 'message' => SwpmUtils::_( 'Stripe API Test publishable key' ),
  248. )
  249. );
  250. add_settings_field(
  251. 'stripe-test-secret-key',
  252. SwpmUtils::_( 'Test Secret Key' ),
  253. array( $this, 'textfield_callback' ),
  254. 'simple_wp_membership_settings',
  255. 'stripe-global-settings',
  256. array(
  257. 'item' => 'stripe-test-secret-key',
  258. 'message' => SwpmUtils::_( 'Stripe API Test secret key' ),
  259. )
  260. );
  261. add_settings_field(
  262. 'stripe-live-public-key',
  263. SwpmUtils::_( 'Live Publishable Key' ),
  264. array( $this, 'textfield_callback' ),
  265. 'simple_wp_membership_settings',
  266. 'stripe-global-settings',
  267. array(
  268. 'item' => 'stripe-live-public-key',
  269. 'message' => SwpmUtils::_( 'Stripe API Live publishable key' ),
  270. )
  271. );
  272. add_settings_field(
  273. 'stripe-live-secret-key',
  274. SwpmUtils::_( 'Live Secret Key' ),
  275. array( $this, 'textfield_callback' ),
  276. 'simple_wp_membership_settings',
  277. 'stripe-global-settings',
  278. array(
  279. 'item' => 'stripe-live-secret-key',
  280. 'message' => SwpmUtils::_( 'Stripe API Live secret key' ),
  281. )
  282. );
  283. }
  284. private function tab_3() {
  285. //Register settings sections and fileds for the email settings tab.
  286. register_setting( 'swpm-settings-tab-3', 'swpm-settings', array( &$this, 'sanitize_tab_3' ) );
  287. add_settings_section( 'email-settings-overview', SwpmUtils::_( 'Email Settings Overview' ), array( &$this, 'email_settings_overview_callback' ), 'simple_wp_membership_settings' );
  288. add_settings_section( 'email-misc-settings', SwpmUtils::_( 'Email Misc. Settings' ), array( &$this, 'email_misc_settings_callback' ), 'simple_wp_membership_settings' );
  289. add_settings_field(
  290. 'email-misc-from',
  291. SwpmUtils::_( 'From Email Address' ),
  292. array( &$this, 'textfield_callback' ),
  293. 'simple_wp_membership_settings',
  294. 'email-misc-settings',
  295. array(
  296. 'item' => 'email-from',
  297. 'message' => 'This value will be used as the sender\'s address for the emails. Example value: Your Name &lt;sales@your-domain.com&gt;',
  298. )
  299. );
  300. add_settings_field(
  301. 'email-enable-html',
  302. SwpmUtils::_( 'Allow HTML in Emails' ),
  303. array( $this, 'checkbox_callback' ),
  304. 'simple_wp_membership_settings',
  305. 'email-misc-settings',
  306. array(
  307. 'item' => 'email-enable-html',
  308. 'message' => 'Enables HTML support in emails. We recommend using plain text (non HTML) email as it has better email delivery rate.',
  309. )
  310. );
  311. //Prompt to complete registration email settings
  312. add_settings_section( 'reg-prompt-email-settings', SwpmUtils::_( 'Email Settings (Prompt to Complete Registration )' ), array( &$this, 'reg_prompt_email_settings_callback' ), 'simple_wp_membership_settings' );
  313. add_settings_field(
  314. 'reg-prompt-complete-mail-subject',
  315. SwpmUtils::_( 'Email Subject' ),
  316. array( &$this, 'textfield_callback' ),
  317. 'simple_wp_membership_settings',
  318. 'reg-prompt-email-settings',
  319. array(
  320. 'item' => 'reg-prompt-complete-mail-subject',
  321. 'message' => '',
  322. )
  323. );
  324. add_settings_field(
  325. 'reg-prompt-complete-mail-body',
  326. SwpmUtils::_( 'Email Body' ),
  327. array( &$this, 'wp_editor_callback' ),
  328. 'simple_wp_membership_settings',
  329. 'reg-prompt-email-settings',
  330. array(
  331. 'item' => 'reg-prompt-complete-mail-body',
  332. 'message' => '',
  333. )
  334. );
  335. //Registration complete email settings
  336. $msg_for_admin_notify_email_field = SwpmUtils::_( 'Enter the email address where you want the admin notification email to be sent to.' );
  337. $msg_for_admin_notify_email_field .= SwpmUtils::_( ' You can put multiple email addresses separated by comma (,) in the above field to send the notification to multiple email addresses.' );
  338. $msg_for_admin_notify_email_subj = SwpmUtils::_( 'Enter the subject for the admin notification email.' );
  339. $admin_notify_email_body_msg = SwpmUtils::_( 'This email will be sent to the admin when a new user completes the membership registration. Only works if you have enabled the "Send Notification to Admin" option above.' );
  340. add_settings_section( 'reg-email-settings', SwpmUtils::_( 'Email Settings (Registration Complete)' ), array( &$this, 'reg_email_settings_callback' ), 'simple_wp_membership_settings' );
  341. add_settings_field(
  342. 'reg-complete-mail-subject',
  343. SwpmUtils::_( 'Email Subject' ),
  344. array( &$this, 'textfield_callback' ),
  345. 'simple_wp_membership_settings',
  346. 'reg-email-settings',
  347. array(
  348. 'item' => 'reg-complete-mail-subject',
  349. 'message' => '',
  350. )
  351. );
  352. add_settings_field(
  353. 'reg-complete-mail-body',
  354. SwpmUtils::_( 'Email Body' ),
  355. array( &$this, 'wp_editor_callback' ),
  356. 'simple_wp_membership_settings',
  357. 'reg-email-settings',
  358. array(
  359. 'item' => 'reg-complete-mail-body',
  360. 'message' => '',
  361. )
  362. );
  363. add_settings_field(
  364. 'enable-admin-notification-after-reg',
  365. SwpmUtils::_( 'Send Notification to Admin' ),
  366. array( &$this, 'checkbox_callback' ),
  367. 'simple_wp_membership_settings',
  368. 'reg-email-settings',
  369. array(
  370. 'item' => 'enable-admin-notification-after-reg',
  371. 'message' => SwpmUtils::_( 'Enable this option if you want the admin to receive a notification when a member registers.' ),
  372. )
  373. );
  374. add_settings_field(
  375. 'admin-notification-email',
  376. SwpmUtils::_( 'Admin Email Address' ),
  377. array( &$this, 'textfield_callback' ),
  378. 'simple_wp_membership_settings',
  379. 'reg-email-settings',
  380. array(
  381. 'item' => 'admin-notification-email',
  382. 'message' => $msg_for_admin_notify_email_field,
  383. )
  384. );
  385. add_settings_field(
  386. 'reg-complete-mail-subject-admin',
  387. SwpmUtils::_( 'Admin Notification Email Subject' ),
  388. array( &$this, 'textfield_callback' ),
  389. 'simple_wp_membership_settings',
  390. 'reg-email-settings',
  391. array(
  392. 'item' => 'reg-complete-mail-subject-admin',
  393. 'message' => $msg_for_admin_notify_email_subj,
  394. )
  395. );
  396. add_settings_field(
  397. 'reg-complete-mail-body-admin',
  398. SwpmUtils::_( 'Admin Notification Email Body' ),
  399. array( &$this, 'wp_editor_callback' ),
  400. 'simple_wp_membership_settings',
  401. 'reg-email-settings',
  402. array(
  403. 'item' => 'reg-complete-mail-body-admin',
  404. 'message' => $admin_notify_email_body_msg,
  405. )
  406. );
  407. add_settings_field(
  408. 'enable-notification-after-manual-user-add',
  409. SwpmUtils::_( 'Send Email to Member When Added via Admin Dashboard' ),
  410. array( &$this, 'checkbox_callback' ),
  411. 'simple_wp_membership_settings',
  412. 'reg-email-settings',
  413. array(
  414. 'item' => 'enable-notification-after-manual-user-add',
  415. 'message' => '',
  416. )
  417. );
  418. //Password reset email settings
  419. add_settings_section( 'reset-password-settings', SwpmUtils::_( 'Email Settings (Password Reset)' ), array( &$this, 'reset_password_settings_callback' ), 'simple_wp_membership_settings' );
  420. add_settings_field(
  421. 'reset-mail-subject',
  422. SwpmUtils::_( 'Email Subject' ),
  423. array( &$this, 'textfield_callback' ),
  424. 'simple_wp_membership_settings',
  425. 'reset-password-settings',
  426. array(
  427. 'item' => 'reset-mail-subject',
  428. 'message' => '',
  429. )
  430. );
  431. add_settings_field(
  432. 'reset-mail-body',
  433. SwpmUtils::_( 'Email Body' ),
  434. array( &$this, 'wp_editor_callback' ),
  435. 'simple_wp_membership_settings',
  436. 'reset-password-settings',
  437. array(
  438. 'item' => 'reset-mail-body',
  439. 'message' => '',
  440. )
  441. );
  442. //Account upgrade email settings
  443. add_settings_section( 'upgrade-email-settings', SwpmUtils::_( ' Email Settings (Account Upgrade Notification)' ), array( &$this, 'upgrade_email_settings_callback' ), 'simple_wp_membership_settings' );
  444. add_settings_field(
  445. 'upgrade-complete-mail-subject',
  446. SwpmUtils::_( 'Email Subject' ),
  447. array( &$this, 'textfield_callback' ),
  448. 'simple_wp_membership_settings',
  449. 'upgrade-email-settings',
  450. array(
  451. 'item' => 'upgrade-complete-mail-subject',
  452. 'message' => '',
  453. )
  454. );
  455. add_settings_field(
  456. 'upgrade-complete-mail-body',
  457. SwpmUtils::_( 'Email Body' ),
  458. array( &$this, 'wp_editor_callback' ),
  459. 'simple_wp_membership_settings',
  460. 'upgrade-email-settings',
  461. array(
  462. 'item' => 'upgrade-complete-mail-body',
  463. 'message' => '',
  464. )
  465. );
  466. add_settings_field(
  467. 'disable-email-after-upgrade',
  468. SwpmUtils::_( 'Disable Email Notification After Upgrade' ),
  469. array( &$this, 'checkbox_callback' ),
  470. 'simple_wp_membership_settings',
  471. 'upgrade-email-settings',
  472. array(
  473. 'item' => 'disable-email-after-upgrade',
  474. 'message' => SwpmUtils::_( 'You can use this option to disable the email notification that gets sent to the members when they make a payment for upgrade or renewal.' ),
  475. )
  476. );
  477. //Bulk account activate and notify email settings.
  478. add_settings_section( 'bulk-activate-email-settings', SwpmUtils::_( ' Email Settings (Bulk Account Activate Notification)' ), array( &$this, 'bulk_activate_email_settings_callback' ), 'simple_wp_membership_settings' );
  479. add_settings_field(
  480. 'bulk-activate-notify-mail-subject',
  481. SwpmUtils::_( 'Email Subject' ),
  482. array( &$this, 'textfield_callback' ),
  483. 'simple_wp_membership_settings',
  484. 'bulk-activate-email-settings',
  485. array(
  486. 'item' => 'bulk-activate-notify-mail-subject',
  487. 'message' => '',
  488. )
  489. );
  490. add_settings_field(
  491. 'bulk-activate-notify-mail-body',
  492. SwpmUtils::_( 'Email Body' ),
  493. array( &$this, 'wp_editor_callback' ),
  494. 'simple_wp_membership_settings',
  495. 'bulk-activate-email-settings',
  496. array(
  497. 'item' => 'bulk-activate-notify-mail-body',
  498. 'message' => '',
  499. )
  500. );
  501. //Email activation email settings.
  502. add_settings_section( 'email-activation-email-settings', SwpmUtils::_( ' Email Settings (Email Activation)' ), array( &$this, 'email_activation_email_settings_callback' ), 'simple_wp_membership_settings' );
  503. add_settings_field(
  504. 'email-activation-mail-subject',
  505. SwpmUtils::_( 'Email Subject' ),
  506. array( &$this, 'textfield_callback' ),
  507. 'simple_wp_membership_settings',
  508. 'email-activation-email-settings',
  509. array(
  510. 'item' => 'email-activation-mail-subject',
  511. 'message' => '',
  512. )
  513. );
  514. add_settings_field(
  515. 'email-activation-mail-body',
  516. SwpmUtils::_( 'Email Body' ),
  517. array( &$this, 'wp_editor_callback' ),
  518. 'simple_wp_membership_settings',
  519. 'email-activation-email-settings',
  520. array(
  521. 'item' => 'email-activation-mail-body',
  522. 'message' => '',
  523. )
  524. );
  525. }
  526. private function tab_4() {
  527. //Register settings sections and fileds for the tools tab.
  528. }
  529. private function tab_5() {
  530. //Register settings sections and fileds for the advanced settings tab.
  531. register_setting( 'swpm-settings-tab-5', 'swpm-settings', array( &$this, 'sanitize_tab_5' ) );
  532. add_settings_section( 'advanced-settings', SwpmUtils::_( 'Advanced Settings' ), array( &$this, 'advanced_settings_callback' ), 'simple_wp_membership_settings' );
  533. add_settings_field(
  534. 'enable-expired-account-login',
  535. SwpmUtils::_( 'Enable Expired Account Login' ),
  536. array( &$this, 'checkbox_callback' ),
  537. 'simple_wp_membership_settings',
  538. 'advanced-settings',
  539. array(
  540. 'item' => 'enable-expired-account-login',
  541. 'message' => SwpmUtils::_( "When enabled, expired members will be able to log into the system but won't be able to view any protected content. This allows them to easily renew their account by making another payment." ),
  542. )
  543. );
  544. add_settings_field(
  545. 'renewal-page-url',
  546. SwpmUtils::_( 'Membership Renewal URL' ),
  547. array( &$this, 'textfield_long_callback' ),
  548. 'simple_wp_membership_settings',
  549. 'advanced-settings',
  550. array(
  551. 'item' => 'renewal-page-url',
  552. 'message' => SwpmUtils::_( 'You can create a renewal page for your site. Read <a href="https://simple-membership-plugin.com/creating-membership-renewal-button/" target="_blank">this documentation</a> to learn how to create a renewal page.' ),
  553. )
  554. );
  555. add_settings_field(
  556. 'after-rego-redirect-page-url',
  557. SwpmUtils::_( 'After Registration Redirect URL' ),
  558. array( &$this, 'textfield_long_callback' ),
  559. 'simple_wp_membership_settings',
  560. 'advanced-settings',
  561. array(
  562. 'item' => 'after-rego-redirect-page-url',
  563. 'message' => SwpmUtils::_( 'You can enter an URL here to redirect the members to this page after they submit the registration form. Read <a href="https://simple-membership-plugin.com/configure-after-registration-redirect-for-members/" target="_blank">this documentation</a> to learn how to setup after registration redirect.' ),
  564. )
  565. );
  566. add_settings_field(
  567. 'auto-login-after-rego',
  568. SwpmUtils::_( 'Enable Auto Login After Registration' ),
  569. array( &$this, 'checkbox_callback' ),
  570. 'simple_wp_membership_settings',
  571. 'advanced-settings',
  572. array(
  573. 'item' => 'auto-login-after-rego',
  574. 'message' => SwpmUtils::_( 'Use this option if you want the members to be automatically logged into your site right after they complete the registration. This option will override any after registration redirection and instead it will trigger the after login redirection. Read <a href="https://simple-membership-plugin.com/configure-auto-login-after-registration-members/" target="_blank">this documentation</a> to learn more.' ),
  575. )
  576. );
  577. add_settings_field(
  578. 'hide-rego-form-to-logged-users',
  579. SwpmUtils::_( 'Hide Registration Form to Logged Users' ),
  580. array( &$this, 'checkbox_callback' ),
  581. 'simple_wp_membership_settings',
  582. 'advanced-settings',
  583. array(
  584. 'item' => 'hide-rego-form-to-logged-users',
  585. 'message' => SwpmUtils::_( 'Use this option if you want to hide the registration form to the logged-in members. If logged-in members visit the registration page, they will see a message instead of the registration form.' ),
  586. )
  587. );
  588. add_settings_field(
  589. 'after-logout-redirection-url',
  590. SwpmUtils::_( 'After Logout Redirect URL' ),
  591. array( &$this, 'textfield_long_callback' ),
  592. 'simple_wp_membership_settings',
  593. 'advanced-settings',
  594. array(
  595. 'item' => 'after-logout-redirection-url',
  596. 'message' => SwpmUtils::_( 'You can enter an URL here to redirect the members to this page after they click the logout link to logout from your site.' ),
  597. )
  598. );
  599. add_settings_field(
  600. 'logout-member-on-browser-close',
  601. SwpmUtils::_( 'Logout Member on Browser Close' ),
  602. array( &$this, 'checkbox_callback' ),
  603. 'simple_wp_membership_settings',
  604. 'advanced-settings',
  605. array(
  606. 'item' => 'logout-member-on-browser-close',
  607. 'message' => SwpmUtils::_( 'Enable this option if you want the member to be logged out of the account when he closes the browser.' ),
  608. )
  609. );
  610. add_settings_field(
  611. 'allow-account-deletion',
  612. SwpmUtils::_( 'Allow Account Deletion' ),
  613. array( &$this, 'checkbox_callback' ),
  614. 'simple_wp_membership_settings',
  615. 'advanced-settings',
  616. array(
  617. 'item' => 'allow-account-deletion',
  618. 'message' => SwpmUtils::_( 'Allow users to delete their accounts.' ),
  619. )
  620. );
  621. add_settings_field(
  622. 'force-strong-passwords',
  623. SwpmUtils::_( 'Force Strong Password for Members' ),
  624. array( &$this, 'checkbox_callback' ),
  625. 'simple_wp_membership_settings',
  626. 'advanced-settings',
  627. array(
  628. 'item' => 'force-strong-passwords',
  629. 'message' => SwpmUtils::_( 'Enable this if you want the users to be forced to use a strong password for their accounts.' ),
  630. )
  631. );
  632. add_settings_field(
  633. 'delete-pending-account',
  634. SwpmUtils::_( 'Auto Delete Pending Account' ),
  635. array( &$this, 'selectbox_callback' ),
  636. 'simple_wp_membership_settings',
  637. 'advanced-settings',
  638. array(
  639. 'item' => 'delete-pending-account',
  640. 'options' => array(
  641. 0 => 'Do not delete',
  642. 1 => 'Older than 1 month',
  643. 2 => 'Older than 2 months',
  644. ),
  645. 'default' => '0',
  646. 'message' => SwpmUtils::_( 'Select how long you want to keep "pending" account.' ),
  647. )
  648. );
  649. add_settings_field(
  650. 'admin-dashboard-access-permission',
  651. SwpmUtils::_( 'Admin Dashboard Access Permission' ),
  652. array( &$this, 'selectbox_callback' ),
  653. 'simple_wp_membership_settings',
  654. 'advanced-settings',
  655. array(
  656. 'item' => 'admin-dashboard-access-permission',
  657. 'options' => array(
  658. 'manage_options' => translate_user_role( 'Administrator' ),
  659. 'edit_pages' => translate_user_role( 'Editor' ),
  660. 'edit_published_posts' => translate_user_role( 'Author' ),
  661. 'edit_posts' => translate_user_role( 'Contributor' ),
  662. ),
  663. 'default' => 'manage_options',
  664. 'message' => SwpmUtils::_( 'SWPM admin dashboard is accessible to admin users only (just like any other plugin). You can allow users with other WP user role to access the SWPM admin dashboard by selecting a value here. Note that this option cannot work if you enabled the "Disable Access to WP Dashboard" option in General Settings.' ),
  665. )
  666. );
  667. add_settings_field(
  668. 'force-wp-user-sync',
  669. SwpmUtils::_( 'Force WP User Synchronization' ),
  670. array( &$this, 'checkbox_callback' ),
  671. 'simple_wp_membership_settings',
  672. 'advanced-settings',
  673. array(
  674. 'item' => 'force-wp-user-sync',
  675. 'message' => SwpmUtils::_( 'Enable this option if you want to force the member login to be synchronized with WP user account. This can be useful if you are using another plugin that uses WP user records. For example: bbPress plugin.' ),
  676. )
  677. );
  678. //Auto create SWPM user related settings section
  679. add_settings_section( 'auto-create-swpm-user-settings', SwpmUtils::_( 'Create Member Accounts for New WP Users' ), array( &$this, 'advanced_settings_auto_create_swpm_uses_settings_callback' ), 'simple_wp_membership_settings' );
  680. add_settings_field(
  681. 'enable-auto-create-swpm-members',
  682. SwpmUtils::_( 'Enable Auto Create Member Accounts' ),
  683. array( &$this, 'checkbox_callback' ),
  684. 'simple_wp_membership_settings',
  685. 'auto-create-swpm-user-settings',
  686. array(
  687. 'item' => 'enable-auto-create-swpm-members',
  688. 'message' => SwpmUtils::_( 'Enable this option to automatically create member accounts for any new WP user that is created by another plugin.' ),
  689. )
  690. );
  691. $levels_array = SwpmMembershipLevelUtils::get_all_membership_levels_in_array();
  692. add_settings_field(
  693. 'auto-create-default-membership-level',
  694. SwpmUtils::_( 'Default Membership Level' ),
  695. array( &$this, 'selectbox_callback' ),
  696. 'simple_wp_membership_settings',
  697. 'auto-create-swpm-user-settings',
  698. array(
  699. 'item' => 'auto-create-default-membership-level',
  700. 'options' => $levels_array,
  701. 'default' => '',
  702. 'message' => SwpmUtils::_( 'When automatically creating a member account using this feature, the membership level of the user will be set to the one you specify here.' ),
  703. )
  704. );
  705. $status_array = SwpmUtils::get_account_state_options();
  706. add_settings_field(
  707. 'auto-create-default-account-status',
  708. SwpmUtils::_( 'Default Account Status' ),
  709. array( &$this, 'selectbox_callback' ),
  710. 'simple_wp_membership_settings',
  711. 'auto-create-swpm-user-settings',
  712. array(
  713. 'item' => 'auto-create-default-account-status',
  714. 'options' => $status_array,
  715. 'default' => '',
  716. 'message' => SwpmUtils::_( 'When automatically creating a member account using this feature, the membership account status of the user will be set to the one you specify here.' ),
  717. )
  718. );
  719. add_settings_field(
  720. 'payment-notification-forward-url',
  721. SwpmUtils::_( 'Payment Notification Forward URL' ),
  722. array( &$this, 'textfield_long_callback' ),
  723. 'simple_wp_membership_settings',
  724. 'advanced-settings',
  725. array(
  726. 'item' => 'payment-notification-forward-url',
  727. 'message' => SwpmUtils::_( 'You can enter an URL here to forward the payment notification after the membership payment has been processed by this plugin. Useful if you want to forward the payment notification to an external script for further processing.' ),
  728. )
  729. );
  730. //Terms and conditions section
  731. add_settings_section( 'terms-and-conditions', SwpmUtils::_( 'Terms and Conditions' ), array( &$this, 'advanced_settings_terms_and_conditions_callback' ), 'simple_wp_membership_settings' );
  732. add_settings_field(
  733. 'enable-terms-and-conditions',
  734. SwpmUtils::_( 'Enable Terms and Conditions' ),
  735. array( &$this, 'checkbox_callback' ),
  736. 'simple_wp_membership_settings',
  737. 'terms-and-conditions',
  738. array(
  739. 'item' => 'enable-terms-and-conditions',
  740. 'message' => SwpmUtils::_( 'Users must accept the terms before they can complete the registration.' ),
  741. )
  742. );
  743. add_settings_field(
  744. 'terms-and-conditions-page-url',
  745. SwpmUtils::_( 'Terms and Conditions Page URL' ),
  746. array( &$this, 'textfield_long_callback' ),
  747. 'simple_wp_membership_settings',
  748. 'terms-and-conditions',
  749. array(
  750. 'item' => 'terms-and-conditions-page-url',
  751. 'message' => SwpmUtils::_( 'Enter the URL of your terms and conditions page. You can create a WordPress page and specify your terms in there then specify the URL of that page in the above field.' ),
  752. )
  753. );
  754. add_settings_field(
  755. 'enable-privacy-policy',
  756. SwpmUtils::_( 'Enable Privacy Policy' ),
  757. array( &$this, 'checkbox_callback' ),
  758. 'simple_wp_membership_settings',
  759. 'terms-and-conditions',
  760. array(
  761. 'item' => 'enable-privacy-policy',
  762. 'message' => SwpmUtils::_( 'Users must accept it before they can complete the registration.' ),
  763. )
  764. );
  765. add_settings_field(
  766. 'privacy-policy-page-url',
  767. SwpmUtils::_( 'Privacy Policy Page URL' ),
  768. array( &$this, 'textfield_long_callback' ),
  769. 'simple_wp_membership_settings',
  770. 'terms-and-conditions',
  771. array(
  772. 'item' => 'privacy-policy-page-url',
  773. 'message' => SwpmUtils::_( 'Enter the URL of your privacy policy page.' ),
  774. )
  775. );
  776. }
  777. private function tab_6() {
  778. //Register settings sections and fileds for the addon settings tab.
  779. }
  780. public static function get_instance() {
  781. self::$_this = empty( self::$_this ) ? new SwpmSettings() : self::$_this;
  782. return self::$_this;
  783. }
  784. public function selectbox_callback( $args ) {
  785. $item = $args['item'];
  786. $options = $args['options'];
  787. $default = $args['default'];
  788. $msg = isset( $args['message'] ) ? $args['message'] : '';
  789. $selected = esc_attr( $this->get_value( $item, $default ) );
  790. echo "<select name='swpm-settings[" . $item . "]' >";
  791. foreach ( $options as $key => $value ) {
  792. $is_selected = ( $key == $selected ) ? 'selected="selected"' : '';
  793. echo '<option ' . $is_selected . ' value="' . esc_attr( $key ) . '">' . esc_attr( $value ) . '</option>';
  794. }
  795. echo '</select>';
  796. echo '<br/><i>' . $msg . '</i>';
  797. }
  798. public function checkbox_callback( $args ) {
  799. $item = $args['item'];
  800. $msg = isset( $args['message'] ) ? $args['message'] : '';
  801. $is = esc_attr( $this->get_value( $item ) );
  802. echo "<input type='checkbox' $is name='swpm-settings[" . $item . "]' value=\"checked='checked'\" />";
  803. echo '<br/><i>' . $msg . '</i>';
  804. }
  805. public function textarea_callback( $args ) {
  806. $item = $args['item'];
  807. $msg = isset( $args['message'] ) ? $args['message'] : '';
  808. $text = esc_attr( $this->get_value( $item ) );
  809. echo "<textarea name='swpm-settings[" . $item . "]' rows='6' cols='60' >" . $text . '</textarea>';
  810. echo '<br/><i>' . $msg . '</i>';
  811. }
  812. public function textfield_small_callback( $args ) {
  813. $item = $args['item'];
  814. $msg = isset( $args['message'] ) ? $args['message'] : '';
  815. $text = esc_attr( $this->get_value( $item ) );
  816. echo "<input type='text' name='swpm-settings[" . $item . "]' size='5' value='" . $text . "' />";
  817. echo '<br/><i>' . $msg . '</i>';
  818. }
  819. public function textfield_callback( $args ) {
  820. $item = $args['item'];
  821. $msg = isset( $args['message'] ) ? $args['message'] : '';
  822. $text = $this->get_value( $item );
  823. echo sprintf( '<input type="text" name="swpm-settings[%s]" size="50" value="%s" />', esc_attr( $item ), esc_attr( $text ) );
  824. echo sprintf( '<p class="description">%s</p>', $msg );
  825. }
  826. public function textfield_long_callback( $args ) {
  827. $item = $args['item'];
  828. $msg = isset( $args['message'] ) ? $args['message'] : '';
  829. $text = esc_attr( $this->get_value( $item ) );
  830. echo "<input type='text' name='swpm-settings[" . $item . "]' size='100' value='" . $text . "' />";
  831. echo '<br/><i>' . $msg . '</i>';
  832. }
  833. public function set_default_editor( $r ) {
  834. $r = 'html';
  835. return $r;
  836. }
  837. public function wp_editor_callback( $args ) {
  838. $item = $args['item'];
  839. $msg = isset( $args['message'] ) ? $args['message'] : '';
  840. $text = $this->get_value( $item );
  841. $html_enabled = $this->get_value( 'email-enable-html' );
  842. add_filter( 'wp_default_editor', array( $this, 'set_default_editor' ) );
  843. echo '<style>#wp-' . esc_attr( sprintf( '%s', $item ) ) . '-wrap{max-width:40em;}</style>';
  844. wp_editor(
  845. html_entity_decode( $text ),
  846. $item,
  847. array(
  848. 'textarea_name' => 'swpm-settings[' . $item . ']',
  849. 'teeny' => true,
  850. 'default_editor' => ! empty( $html_enabled ) ? 'QuickTags' : '',
  851. 'textarea_rows' => 15,
  852. )
  853. );
  854. remove_filter( 'wp_default_editor', array( $this, 'set_default_editor' ) );
  855. echo "<p class=\"description\">{$msg}</p>";
  856. }
  857. public function swpm_documentation_callback() {
  858. ?>
  859. <div class="swpm-orange-box">
  860. <?php printf( SwpmUtils::_( 'Visit the %s to read setup and configuration documentation.' ), '<a target="_blank" href="https://simple-membership-plugin.com/">' . SwpmUtils::_( 'Simple Membership Plugin Site' ) . '</a>' ); ?>
  861. <?php printf( SwpmUtils::_( 'Please %s if you like the plugin.' ), '<a href="https://wordpress.org/support/view/plugin-reviews/simple-membership?filter=5" target="_blank">' . SwpmUtils::_( 'give us a rating' ) . '</a>' ); ?>
  862. </div>
  863. <?php
  864. }
  865. public function swpm_general_post_submit_check_callback() {
  866. //Log file reset handler
  867. if ( isset( $_REQUEST['swmp_reset_log'] ) ) {
  868. if ( SwpmLog::reset_swmp_log_files() ) {
  869. echo '<div id="message" class="updated fade"><p>Debug log files have been reset!</p></div>';
  870. } else {
  871. echo '<div id="message" class="updated fade"><p>Debug log files could not be reset!</p></div>';
  872. }
  873. }
  874. //Show settings updated message
  875. if ( isset( $_REQUEST['settings-updated'] ) ) {
  876. echo '<div id="message" class="updated fade"><p>' . SwpmUtils::_( 'Settings updated!' ) . '</p></div>';
  877. }
  878. }
  879. public function general_settings_callback() {
  880. SwpmUtils::e( 'General Plugin Settings.' );
  881. }
  882. public function pages_settings_callback() {
  883. SwpmUtils::e( 'Page Setup and URL Related settings.' );
  884. echo '<p>';
  885. SwpmUtils::e( 'The following pages are required for the plugin to function correctly. These pages were automatically created by the plugin at install time.' );
  886. echo '</p>';
  887. }
  888. public function testndebug_settings_callback() {
  889. SwpmUtils::e( 'Testing and Debug Related Settings.' );
  890. }
  891. public function reg_email_settings_callback() {
  892. SwpmUtils::e( 'This email will be sent to your users when they complete the registration and become a member.' );
  893. }
  894. public function reset_password_settings_callback() {
  895. SwpmUtils::e( 'This email will be sent to your users when they use the password reset functionality.' );
  896. }
  897. public function email_settings_overview_callback() {
  898. echo '<div class="swpm-grey-box">';
  899. echo '<p>';
  900. SwpmUtils::e( 'This interface lets you custsomize the various emails that gets sent to your members for various actions. The default settings should be good to get your started.' );
  901. echo '</p>';
  902. echo '<p>';
  903. echo '<a href="https://simple-membership-plugin.com/email-merge-tags-email-shortcodes-for-email-customization/" target="_blank">' . SwpmUtils::_( 'This documentation' ) . '</a>';
  904. SwpmUtils::e( ' explains what email merge tags you can use in the email body field to customize it (if you want to).' );
  905. echo '</p>';
  906. echo '</div>';
  907. }
  908. public function email_misc_settings_callback() {
  909. //Show settings updated message when it is updated
  910. if ( isset( $_REQUEST['settings-updated'] ) ) {
  911. //This status message need to be in the callback function to prevent header sent warning
  912. echo '<div id="message" class="updated fade"><p>' . SwpmUtils::_( 'Settings updated!' ) . '</p></div>';
  913. }
  914. SwpmUtils::e( 'Settings in this section apply to all emails.' );
  915. }
  916. public function upgrade_email_settings_callback() {
  917. SwpmUtils::e( 'This email will be sent to your users after account upgrade (when an existing member pays for a new membership level).' );
  918. }
  919. public function bulk_activate_email_settings_callback() {
  920. SwpmUtils::e( 'This email will be sent to your members when you use the bulk account activate and notify action.' );
  921. SwpmUtils::e( ' You cannot use email merge tags in this email. You can only use generic text.' );
  922. }
  923. public function email_activation_email_settings_callback() {
  924. SwpmUtils::e( 'This email will be sent if Email Activation is enabled for a Membership Level.' );
  925. }
  926. public function reg_prompt_email_settings_callback() {
  927. SwpmUtils::e( 'This email will be sent to prompt users to complete registration after the payment.' );
  928. }
  929. public function advanced_settings_callback() {
  930. //Show settings updated message when it is updated
  931. if ( isset( $_REQUEST['settings-updated'] ) ) {
  932. //This status message need to be in the callback function to prevent header sent warning
  933. echo '<div id="message" class="updated fade"><p>' . SwpmUtils::_( 'Settings updated!' ) . '</p></div>';
  934. /* Check if any conflicting setting options have been enabled together. */
  935. $disable_wp_dashboard_for_non_admins = $this->get_value('disable-access-to-wp-dashboard');
  936. if ($disable_wp_dashboard_for_non_admins) {
  937. //The disable wp dashboard option is enabled.
  938. //Check to make sure the "Admin Dashboard Access Permission" option is not being used for other roles.
  939. $admin_dashboard_permission = $this->get_value( 'admin-dashboard-access-permission' );
  940. if ( empty( $admin_dashboard_permission ) || $admin_dashboard_permission == 'manage_options' ) {
  941. //This is fine.
  942. } else {
  943. //Conflicting options enabled.
  944. //Show warning and reset the option value to default.
  945. $this->set_value('admin-dashboard-access-permission', 'manage_options');
  946. $this->save();
  947. echo '<div id="message" class="error"><p>' . SwpmUtils::_( 'Note: You cannot enable both the "Disable Access to WP Dashboard" and "Admin Dashboard Access Permission" options at the same time. Only use one of those options.' ) . '</p></div>';
  948. }
  949. }
  950. /* End of conflicting options check */
  951. }
  952. SwpmUtils::e( 'This page allows you to configure some advanced features of the plugin.' );
  953. }
  954. public function advanced_settings_auto_create_swpm_uses_settings_callback() {
  955. SwpmUtils::e( 'This section allows you to configure automatic creation of member accounts when new WP User records are created by another plugin. It can be useful if you are using another plugin that creates WP user records and you want them to be recognized in the membership plugin.' );
  956. }
  957. public function advanced_settings_terms_and_conditions_callback() {
  958. SwpmUtils::e( 'This section allows you to configure terms and conditions and privacy policy that users must accept at registration time.' );
  959. }
  960. public function sanitize_tab_1( $input ) {
  961. if ( empty( $this->settings ) ) {
  962. $this->settings = (array) get_option( 'swpm-settings' );
  963. }
  964. $output = $this->settings;
  965. //general settings block
  966. $output['hide-adminbar'] = isset( $input['hide-adminbar'] ) ? esc_attr( $input['hide-adminbar'] ) : '';
  967. $output['show-adminbar-admin-only'] = isset( $input['show-adminbar-admin-only'] ) ? esc_attr( $input['show-adminbar-admin-only'] ) : '';
  968. $output['disable-access-to-wp-dashboard'] = isset( $input['disable-access-to-wp-dashboard'] ) ? esc_attr( $input['disable-access-to-wp-dashboard'] ) : '';
  969. $output['protect-everything'] = isset( $input['protect-everything'] ) ? esc_attr( $input['protect-everything'] ) : '';
  970. $output['enable-free-membership'] = isset( $input['enable-free-membership'] ) ? esc_attr( $input['enable-free-membership'] ) : '';
  971. $output['enable-moretag'] = isset( $input['enable-moretag'] ) ? esc_attr( $input['enable-moretag'] ) : '';
  972. $output['enable-debug'] = isset( $input['enable-debug'] ) ? esc_attr( $input['enable-debug'] ) : '';
  973. $output['enable-sandbox-testing'] = isset( $input['enable-sandbox-testing'] ) ? esc_attr( $input['enable-sandbox-testing'] ) : '';
  974. $output['free-membership-id'] = ( $input['free-membership-id'] != 1 ) ? absint( $input['free-membership-id'] ) : '';
  975. $output['login-page-url'] = esc_url( $input['login-page-url'] );
  976. $output['registration-page-url'] = esc_url( $input['registration-page-url'] );
  977. $output['profile-page-url'] = esc_url( $input['profile-page-url'] );
  978. $output['reset-page-url'] = esc_url( $input['reset-page-url'] );
  979. $output['join-us-page-url'] = esc_url( $input['join-us-page-url'] );
  980. $output['default-account-status'] = esc_attr( $input['default-account-status'] );
  981. $output['members-login-to-comment'] = isset( $input['members-login-to-comment'] ) ? esc_attr( $input['members-login-to-comment'] ) : '';
  982. return $output;
  983. }
  984. public function sanitize_tab_2( $input ) {
  985. if ( empty( $this->settings ) ) {
  986. $this->settings = (array) get_option( 'swpm-settings' );
  987. }
  988. $output = $this->settings;
  989. $output['stripe-test-public-key'] = sanitize_text_field( $input['stripe-test-public-key'] );
  990. $output['stripe-test-secret-key'] = sanitize_text_field( $input['stripe-test-secret-key'] );
  991. $output['stripe-live-public-key'] = sanitize_text_field( $input['stripe-live-public-key'] );
  992. $output['stripe-live-secret-key'] = sanitize_text_field( $input['stripe-live-secret-key'] );
  993. $output['stripe-prefill-member-email'] = isset( $input['stripe-prefill-member-email'] ) ? esc_attr( $input['stripe-prefill-member-email'] ) : 0;
  994. return $output;
  995. }
  996. public function sanitize_tab_3( $input ) {
  997. if ( empty( $this->settings ) ) {
  998. $this->settings = (array) get_option( 'swpm-settings' );
  999. }
  1000. $output = $this->settings;
  1001. $output['reg-complete-mail-subject'] = sanitize_text_field( $input['reg-complete-mail-subject'] );
  1002. $output['reg-complete-mail-body'] = $input['reg-complete-mail-body'];
  1003. $output['reg-complete-mail-subject-admin'] = sanitize_text_field( $input['reg-complete-mail-subject-admin'] );
  1004. $output['reg-complete-mail-body-admin'] = $input['reg-complete-mail-body-admin'];
  1005. $output['reset-mail-subject'] = sanitize_text_field( $input['reset-mail-subject'] );
  1006. $output['reset-mail-body'] = $input['reset-mail-body'];
  1007. $output['upgrade-complete-mail-subject'] = sanitize_text_field( $input['upgrade-complete-mail-subject'] );
  1008. $output['upgrade-complete-mail-body'] = $input['upgrade-complete-mail-body'];
  1009. $output['disable-email-after-upgrade'] = isset( $input['disable-email-after-upgrade'] ) ? esc_attr( $input['disable-email-after-upgrade'] ) : '';
  1010. $output['bulk-activate-notify-mail-subject'] = sanitize_text_field( $input['bulk-activate-notify-mail-subject'] );
  1011. $output['bulk-activate-notify-mail-body'] = $input['bulk-activate-notify-mail-body'];
  1012. $output['email-activation-mail-subject'] = sanitize_text_field( $input['email-activation-mail-subject'] );
  1013. $output['email-activation-mail-body'] = $input['email-activation-mail-body'];
  1014. $output['reg-prompt-complete-mail-subject'] = sanitize_text_field( $input['reg-prompt-complete-mail-subject'] );
  1015. $output['reg-prompt-complete-mail-body'] = $input['reg-prompt-complete-mail-body'];
  1016. $output['email-from'] = trim( $input['email-from'] );
  1017. $output['email-enable-html'] = isset( $input['email-enable-html'] ) ? esc_attr( $input['email-enable-html'] ) : '';
  1018. $output['enable-admin-notification-after-reg'] = isset( $input['enable-admin-notification-after-reg'] ) ? esc_attr( $input['enable-admin-notification-after-reg'] ) : '';
  1019. $output['admin-notification-email'] = sanitize_text_field( $input['admin-notification-email'] );
  1020. $output['enable-notification-after-manual-user-add'] = isset( $input['enable-notification-after-manual-user-add'] ) ? esc_attr( $input['enable-notification-after-manual-user-add'] ) : '';
  1021. return $output;
  1022. }
  1023. public function sanitize_tab_5( $input ) {
  1024. if ( empty( $this->settings ) ) {
  1025. $this->settings = (array) get_option( 'swpm-settings' );
  1026. }
  1027. $output = $this->settings;
  1028. $output['enable-expired-account-login'] = isset( $input['enable-expired-account-login'] ) ? esc_attr( $input['enable-expired-account-login'] ) : '';
  1029. $output['logout-member-on-browser-close'] = isset( $input['logout-member-on-browser-close'] ) ? esc_attr( $input['logout-member-on-browser-close'] ) : '';
  1030. $output['allow-account-deletion'] = isset( $input['allow-account-deletion'] ) ? esc_attr( $input['allow-account-deletion'] ) : '';
  1031. $output['delete-pending-account'] = isset( $input['delete-pending-account'] ) ? esc_attr( $input['delete-pending-account'] ) : 0;
  1032. $output['admin-dashboard-access-permission'] = isset( $input['admin-dashboard-access-permission'] ) ? esc_attr( $input['admin-dashboard-access-permission'] ) : '';
  1033. $output['renewal-page-url'] = esc_url( $input['renewal-page-url'] );
  1034. $output['after-rego-redirect-page-url'] = esc_url( $input['after-rego-redirect-page-url'] );
  1035. $output['after-logout-redirection-url'] = esc_url( $input['after-logout-redirection-url'] );
  1036. $output['force-strong-passwords'] = isset( $input['force-strong-passwords'] ) ? esc_attr( $input['force-strong-passwords'] ) : '';
  1037. $output['auto-login-after-rego'] = isset( $input['auto-login-after-rego'] ) ? esc_attr( $input['auto-login-after-rego'] ) : '';
  1038. $output['hide-rego-form-to-logged-users'] = isset( $input['hide-rego-form-to-logged-users'] ) ? esc_attr( $input['hide-rego-form-to-logged-users'] ) : '';
  1039. $output['force-wp-user-sync'] = isset( $input['force-wp-user-sync'] ) ? esc_attr( $input['force-wp-user-sync'] ) : '';
  1040. $output['payment-notification-forward-url'] = esc_url( $input['payment-notification-forward-url'] );
  1041. //Auto create swpm user related settings
  1042. $output['enable-auto-create-swpm-members'] = isset( $input['enable-auto-create-swpm-members'] ) ? esc_attr( $input['enable-auto-create-swpm-members'] ) : '';
  1043. $output['auto-create-default-membership-level'] = isset( $input['auto-create-default-membership-level'] ) ? esc_attr( $input['auto-create-default-membership-level'] ) : '';
  1044. $output['auto-create-default-account-status'] = isset( $input['auto-create-default-account-status'] ) ? esc_attr( $input['auto-create-default-account-status'] ) : '';
  1045. //Terms and conditions related settings
  1046. $output['enable-terms-and-conditions'] = isset( $input['enable-terms-and-conditions'] ) ? esc_attr( $input['enable-terms-and-conditions'] ) : '';
  1047. $output['terms-and-conditions-page-url'] = esc_url( $input['terms-and-conditions-page-url'] );
  1048. $output['enable-privacy-policy'] = isset( $input['enable-privacy-policy'] ) ? esc_attr( $input['enable-privacy-policy'] ) : '';
  1049. $output['privacy-policy-page-url'] = esc_url( $input['privacy-policy-page-url'] );
  1050. return $output;
  1051. }
  1052. public function get_value( $key, $default = '' ) {
  1053. if ( isset( $this->settings[ $key ] ) ) {
  1054. return $this->settings[ $key ];
  1055. }
  1056. return $default;
  1057. }
  1058. public function set_value( $key, $value ) {
  1059. $this->settings[ $key ] = $value;
  1060. return $this;
  1061. }
  1062. public function save() {
  1063. update_option( 'swpm-settings', $this->settings );
  1064. }
  1065. public function draw_tabs() {
  1066. $current = $this->current_tab;
  1067. ?>
  1068. <h2 class="nav-tab-wrapper">
  1069. <?php foreach ( $this->tabs as $id => $label ) { ?>
  1070. <a class="nav-tab <?php echo ( $current == $id ) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_settings&tab=<?php echo $id; ?>"><?php echo $label; ?></a>
  1071. <?php } ?>
  1072. </h2>
  1073. <?php
  1074. }
  1075. public function handle_main_settings_admin_menu() {
  1076. do_action( 'swpm_settings_menu_start' );
  1077. //Check current_user_can() or die.
  1078. SwpmMiscUtils::check_user_permission_and_is_admin( 'Main Settings Menu' );
  1079. ?>
  1080. <div class="wrap swpm-admin-menu-wrap"><!-- start wrap -->
  1081. <h1><?php echo SwpmUtils::_( 'Simple WP Membership::Settings' ); ?></h1><!-- page title -->
  1082. <!-- start nav menu tabs -->
  1083. <?php do_action( 'swpm-draw-settings-nav-tabs' ); ?>
  1084. <!-- end nav menu tabs -->
  1085. <?php
  1086. do_action( 'swpm_settings_menu_after_nav_tabs' );
  1087. //Switch to handle the body of each of the various settings pages based on the currently selected tab
  1088. $current_tab = $this->current_tab;
  1089. switch ( $current_tab ) {
  1090. case 1:
  1091. //General settings
  1092. include SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_settings.php';
  1093. break;
  1094. case 2:
  1095. //Payment settings
  1096. include SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/admin_payment_settings.php';
  1097. break;
  1098. case 3:
  1099. //Email settings
  1100. include SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_settings.php';
  1101. break;
  1102. case 4:
  1103. //Tools
  1104. include SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_tools_settings.php';
  1105. break;
  1106. case 5:
  1107. //Advanced settings
  1108. include SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_settings.php';
  1109. break;
  1110. case 6:
  1111. //Addon settings
  1112. include SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_addon_settings.php';
  1113. break;
  1114. default:
  1115. //The default fallback (general settings)
  1116. include SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_settings.php';
  1117. break;
  1118. }
  1119. echo '</div>'; //<!-- end of wrap -->
  1120. }
  1121. }