PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/wp-user-frontend/wpuf.php

https://gitlab.com/Gashler/sg
PHP | 398 lines | 215 code | 72 blank | 111 comment | 27 complexity | 327cb3c4c6618f3b12847dd8ad40d3cc MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name: WP User Frontend
  4. Plugin URI: https://wordpress.org/plugins/wp-user-frontend/
  5. Description: Create, edit, delete, manages your post, pages or custom post types from frontend. Create registration forms, frontend profile and more...
  6. Author: Tareq Hasan
  7. Version: 2.3.6
  8. Author URI: http://tareq.weDevs.com
  9. License: GPL2
  10. TextDomain: wpuf
  11. */
  12. define( 'WPUF_VERSION', '2.3.6' );
  13. define( 'WPUF_FILE', __FILE__ );
  14. define( 'WPUF_ROOT', dirname( __FILE__ ) );
  15. define( 'WPUF_ROOT_URI', plugins_url( '', __FILE__ ) );
  16. define( 'WPUF_ASSET_URI', WPUF_ROOT_URI . '/assets' );
  17. /**
  18. * Autoload class files on demand
  19. *
  20. * `WPUF_Form_Posting` becomes => form-posting.php
  21. * `WPUF_Dashboard` becomes => dashboard.php
  22. *
  23. * @param string $class requested class name
  24. */
  25. function wpuf_autoload( $class ) {
  26. if ( stripos( $class, 'WPUF_' ) !== false ) {
  27. $admin = ( stripos( $class, '_Admin_' ) !== false ) ? true : false;
  28. if ( $admin ) {
  29. $class_name = str_replace( array('WPUF_Admin_', '_'), array('', '-'), $class );
  30. $filename = dirname( __FILE__ ) . '/admin/' . strtolower( $class_name ) . '.php';
  31. } else {
  32. $class_name = str_replace( array('WPUF_', '_'), array('', '-'), $class );
  33. $filename = dirname( __FILE__ ) . '/class/' . strtolower( $class_name ) . '.php';
  34. }
  35. if ( file_exists( $filename ) ) {
  36. require_once $filename;
  37. }
  38. }
  39. }
  40. spl_autoload_register( 'wpuf_autoload' );
  41. /**
  42. * Main bootstrap class for WP User Frontend
  43. *
  44. * @package WP User Frontend
  45. */
  46. class WP_User_Frontend {
  47. private static $_instance;
  48. private $is_pro = false;
  49. function __construct() {
  50. $this->includes();
  51. $this->instantiate();
  52. register_activation_hook( __FILE__, array($this, 'install') );
  53. register_deactivation_hook( __FILE__, array($this, 'uninstall') );
  54. // set schedule event
  55. add_action( 'wpuf_remove_expired_post_hook', array( $this, 'action_to_remove_exipred_post' ) );
  56. add_action( 'admin_init', array($this, 'block_admin_access') );
  57. add_action( 'show_admin_bar', array($this, 'show_admin_bar') );
  58. add_action( 'init', array($this, 'load_textdomain') );
  59. add_action( 'wp_enqueue_scripts', array($this, 'enqueue_scripts') );
  60. // do plugin upgrades
  61. add_action( 'plugins_loaded', array($this, 'plugin_upgrades') );
  62. add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'plugin_action_links' ) );
  63. }
  64. /**
  65. * Schedules the post expiry event
  66. *
  67. * @since 2.2.7
  68. */
  69. public function set_schedule_events(){
  70. wp_schedule_event( time(), 'daily', 'wpuf_remove_expired_post_hook' );
  71. }
  72. /**
  73. * Action when posts expiration date is passed
  74. *
  75. * @since 2.2.7
  76. */
  77. public function action_to_remove_exipred_post(){
  78. $args = array(
  79. 'meta_key' => 'wpuf-post_expiration_date',
  80. 'meta_value' => date('Y-m-d'),
  81. 'post_type' => get_post_types(),
  82. 'post_status' => 'publish',
  83. 'posts_per_page' => -1
  84. );
  85. $mail_subject = apply_filters( 'wpuf_post_expiry_mail_subject', sprintf( '[%s] %s', get_bloginfo( 'name' ), __( 'Your Post Has Been Expired', 'wpuf' ) ) );
  86. $posts = get_posts( $args );
  87. foreach ($posts as $each_post) {
  88. $post_to_update = array(
  89. 'ID' => $each_post->ID,
  90. 'post_status' => get_post_meta( $each_post->ID, 'wpuf-expired_post_status', true ) ? get_post_meta( $each_post->ID, 'wpuf-expired_post_status', true ) : 'draft'
  91. );
  92. wp_update_post( $post_to_update );
  93. if ( $message = get_post_meta( $each_post->ID, 'wpuf-post_expiration_message', true ) ) {
  94. wp_mail( $each_post->post_author, $mail_subject, $message );
  95. }
  96. }
  97. }
  98. public static function init() {
  99. if ( !self::$_instance ) {
  100. self::$_instance = new WP_User_Frontend();
  101. }
  102. return self::$_instance;
  103. }
  104. public function includes() {
  105. require_once dirname( __FILE__ ) . '/wpuf-functions.php';
  106. require_once dirname( __FILE__ ) . '/lib/gateway/paypal.php';
  107. require_once dirname( __FILE__ ) . '/lib/gateway/bank.php';
  108. if ( file_exists( dirname( __FILE__ ) . '/includes/pro/loader.php' ) ) {
  109. include dirname( __FILE__ ) . '/includes/pro/loader.php';
  110. $this->is_pro = true;
  111. } else {
  112. include dirname( __FILE__ ) . '/includes/free/loader.php';
  113. }
  114. if ( is_admin() ) {
  115. require_once dirname( __FILE__ ) . '/admin/settings-options.php';
  116. }
  117. // add reCaptcha library if not found
  118. if ( !function_exists( 'recaptcha_get_html' ) ) {
  119. require_once dirname( __FILE__ ) . '/lib/recaptchalib.php';
  120. }
  121. }
  122. /**
  123. * Instantiate the classes
  124. *
  125. * @return void
  126. */
  127. function instantiate() {
  128. new WPUF_Upload();
  129. new WPUF_Payment();
  130. WPUF_Frontend_Form_Post::init(); // requires for form preview
  131. WPUF_Subscription::init();
  132. if ( is_admin() ) {
  133. WPUF_Admin_Settings::init();
  134. new WPUF_Admin_Form();
  135. new WPUF_Admin_Posting();
  136. new WPUF_Admin_Subscription();
  137. new WPUF_Admin_Installer();
  138. } else {
  139. new WPUF_Frontend_Dashboard();
  140. }
  141. }
  142. /**
  143. * Create tables on plugin activation
  144. *
  145. * @global object $wpdb
  146. */
  147. function install() {
  148. global $wpdb;
  149. $this->set_schedule_events();
  150. flush_rewrite_rules( false );
  151. $sql_transaction = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpuf_transaction (
  152. `id` mediumint(9) NOT NULL AUTO_INCREMENT,
  153. `user_id` bigint(20) DEFAULT NULL,
  154. `status` varchar(255) NOT NULL DEFAULT 'pending_payment',
  155. `cost` varchar(255) DEFAULT '',
  156. `post_id` varchar(20) DEFAULT NULL,
  157. `pack_id` bigint(20) DEFAULT NULL,
  158. `payer_first_name` longtext,
  159. `payer_last_name` longtext,
  160. `payer_email` longtext,
  161. `payment_type` longtext,
  162. `payer_address` longtext,
  163. `transaction_id` longtext,
  164. `created` datetime NOT NULL,
  165. PRIMARY KEY (`id`)
  166. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
  167. require_once ABSPATH . 'wp-admin/includes/upgrade.php';
  168. dbDelta( $sql_transaction );
  169. update_option( 'wpuf_version', WPUF_VERSION );
  170. }
  171. /**
  172. * Do plugin upgrades
  173. *
  174. * @since 2.2
  175. * @return void
  176. */
  177. function plugin_upgrades() {
  178. if ( ! is_admin() && ! current_user_can( 'manage_options' ) ) {
  179. return;
  180. }
  181. new WPUF_Upgrades( WPUF_VERSION );
  182. }
  183. /**
  184. * Manage task on plugin deactivation
  185. *
  186. * @return void
  187. */
  188. function uninstall() {
  189. wp_clear_scheduled_hook( 'wpuf_remove_expired_post_hook' );
  190. }
  191. /**
  192. * Enqueues Styles and Scripts when the shortcodes are used only
  193. *
  194. * @uses has_shortcode()
  195. * @since 0.2
  196. */
  197. function enqueue_scripts() {
  198. $scheme = is_ssl() ? 'https' : 'http';
  199. wp_enqueue_script( 'google-maps', $scheme . '://maps.google.com/maps/api/js?sensor=true' );
  200. wp_enqueue_script( 'wpuf-form', WPUF_ASSET_URI . '/js/frontend-form.js', array('jquery') );
  201. wp_enqueue_script( 'wpuf-conditional-logic', WPUF_ASSET_URI . '/js/conditional-logic.js', array('jquery'), false, true );
  202. wp_enqueue_script( 'wpuf-subscriptions', WPUF_ASSET_URI . '/js/subscriptions.js', array('jquery'), false, true );
  203. wp_enqueue_style( 'wpuf-css', WPUF_ASSET_URI . '/css/frontend-forms.css' );
  204. if ( wpuf_get_option( 'load_script', 'wpuf_general', 'on') == 'on') {
  205. $this->plugin_scripts();
  206. } else if ( wpuf_has_shortcode( 'wpuf_form' ) || wpuf_has_shortcode( 'wpuf_edit' ) || wpuf_has_shortcode( 'wpuf_profile' ) || wpuf_has_shortcode( 'wpuf_dashboard' ) ) {
  207. $this->plugin_scripts();
  208. }
  209. }
  210. function plugin_scripts() {
  211. wp_enqueue_style( 'jquery-ui', WPUF_ASSET_URI . '/css/jquery-ui-1.9.1.custom.css' );
  212. wp_enqueue_script( 'jquery' );
  213. wp_enqueue_script( 'jquery-ui-datepicker' );
  214. wp_enqueue_script( 'jquery-ui-autocomplete' );
  215. wp_enqueue_script( 'suggest' );
  216. wp_enqueue_script( 'jquery-ui-slider' );
  217. wp_enqueue_script( 'plupload-handlers' );
  218. wp_enqueue_script( 'jquery-ui-timepicker', WPUF_ASSET_URI . '/js/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker') );
  219. wp_enqueue_script( 'wpuf-upload', WPUF_ASSET_URI . '/js/upload.js', array('jquery', 'plupload-handlers') );
  220. wp_localize_script( 'wpuf-form', 'wpuf_frontend', array(
  221. 'ajaxurl' => admin_url( 'admin-ajax.php' ),
  222. 'error_message' => __( 'Please fix the errors to proceed', 'wpuf' ),
  223. 'nonce' => wp_create_nonce( 'wpuf_nonce' )
  224. ) );
  225. wp_localize_script( 'wpuf-upload', 'wpuf_frontend_upload', array(
  226. 'confirmMsg' => __( 'Are you sure?', 'wpuf' ),
  227. 'nonce' => wp_create_nonce( 'wpuf_nonce' ),
  228. 'ajaxurl' => admin_url( 'admin-ajax.php' ),
  229. 'plupload' => array(
  230. 'url' => admin_url( 'admin-ajax.php' ) . '?nonce=' . wp_create_nonce( 'wpuf_featured_img' ),
  231. 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
  232. 'filters' => array(array('title' => __( 'Allowed Files' ), 'extensions' => '*')),
  233. 'multipart' => true,
  234. 'urlstream_upload' => true,
  235. )
  236. ));
  237. }
  238. /**
  239. * Block user access to admin panel for specific roles
  240. *
  241. * @global string $pagenow
  242. */
  243. function block_admin_access() {
  244. global $pagenow;
  245. // bail out if we are from WP Cli
  246. if ( defined( 'WP_CLI' ) ) {
  247. return;
  248. }
  249. $access_level = wpuf_get_option( 'admin_access', 'wpuf_general', 'read' );
  250. $valid_pages = array('admin-ajax.php', 'admin-post.php', 'async-upload.php', 'media-upload.php');
  251. if ( ! current_user_can( $access_level ) && !in_array( $pagenow, $valid_pages ) ) {
  252. // wp_die( __( 'Access Denied. Your site administrator has blocked your access to the WordPress back-office.', 'wpuf' ) );
  253. wp_redirect( home_url() );
  254. exit;
  255. }
  256. }
  257. /**
  258. * Show/hide admin bar to the permitted user level
  259. *
  260. * @since 2.2.3
  261. * @return void
  262. */
  263. function show_admin_bar() {
  264. $access_level = wpuf_get_option( 'admin_access', 'wpuf_general', 'read' );
  265. return current_user_can( $access_level );
  266. }
  267. /**
  268. * Load the translation file for current language.
  269. *
  270. * @since version 0.7
  271. * @author Tareq Hasan
  272. */
  273. function load_textdomain() {
  274. load_plugin_textdomain( 'wpuf', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
  275. }
  276. /**
  277. * The main logging function
  278. *
  279. * @uses error_log
  280. * @param string $type type of the error. e.g: debug, error, info
  281. * @param string $msg
  282. */
  283. public static function log( $type = '', $msg = '' ) {
  284. if ( WP_DEBUG == true ) {
  285. $msg = sprintf( "[%s][%s] %s\n", date( 'd.m.Y h:i:s' ), $type, $msg );
  286. error_log( $msg, 3, dirname( __FILE__ ) . '/log.txt' );
  287. }
  288. }
  289. /**
  290. * Returns if the plugin is in PRO version
  291. *
  292. * @since 2.3.2
  293. *
  294. * @return boolean
  295. */
  296. public function is_pro() {
  297. return $this->is_pro;
  298. }
  299. /**
  300. * Plugin action links
  301. *
  302. * @param array $links
  303. *
  304. * @since 2.3.3
  305. *
  306. * @return array
  307. */
  308. function plugin_action_links( $links ) {
  309. if ( ! $this->is_pro() ) {
  310. $links[] = '<a href="https://wedevs.com/products/plugins/wp-user-frontend-pro/" target="_blank">Get PRO</a>';
  311. }
  312. $links[] = '<a href="' . admin_url( 'admin.php?page=wpuf-settings' ) . '">Settings</a>';
  313. $links[] = '<a href="http://docs.wedevs.com/category/plugins/wp-user-frontend-pro/" target="_blank">Documentation</a>';
  314. return $links;
  315. }
  316. }
  317. /**
  318. * Returns the singleton instance
  319. *
  320. * @return \WP_User_Frontend
  321. */
  322. function wpuf() {
  323. return WP_User_Frontend::init();
  324. }
  325. // kickoff the plugin
  326. wpuf();