Advertisement
Guest User

Untitled

a guest
Feb 6th, 2018
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 51.17 KB | None | 0 0
  1. <?php
  2.  
  3. class WPUF_Frontend_Form_Post extends WPUF_Render_Form {
  4.  
  5. private static $_instance;
  6. private $post_expiration_date = 'wpuf-post_expiration_date';
  7. private $expired_post_status = 'wpuf-expired_post_status';
  8. private $post_expiration_message = 'wpuf-post_expiration_message';
  9.  
  10. function __construct() {
  11.  
  12. add_shortcode( 'wpuf_form', array( $this, 'add_post_shortcode' ) );
  13. add_shortcode( 'wpuf_edit', array( $this, 'edit_post_shortcode' ) );
  14.  
  15. // ajax requests
  16. add_action( 'wp_ajax_wpuf_submit_post', array( $this, 'submit_post' ) );
  17. add_action( 'wp_ajax_nopriv_wpuf_submit_post', array( $this, 'submit_post' ) );
  18. add_action( 'wp_ajax_make_media_embed_code', array( $this, 'make_media_embed_code' ) );
  19. add_action( 'wp_ajax_nopriv_make_media_embed_code', array( $this, 'make_media_embed_code' ) );
  20.  
  21. // draft
  22. add_action( 'wp_ajax_wpuf_draft_post', array( $this, 'draft_post' ) );
  23.  
  24. // guest post hook
  25. add_action( 'init', array( $this, 'publish_guest_post' ) );
  26.  
  27. // form preview
  28. add_action( 'wp_ajax_wpuf_form_preview', array( $this, 'preview_form' ) );
  29. }
  30.  
  31. public static function init() {
  32. if ( !self::$_instance ) {
  33. self::$_instance = new self;
  34. }
  35.  
  36. return self::$_instance;
  37. }
  38.  
  39. /**
  40. * Add post shortcode handler
  41. *
  42. * @param array $atts
  43. * @return string
  44. */
  45. function add_post_shortcode( $atts ) {
  46. // wpuf()->plugin_scripts();
  47. ?>
  48. <style>
  49. <?php //echo $custom_css = wpuf_get_option( 'custom_css', 'wpuf_general' ); ?>
  50. </style>
  51. <?php
  52. extract( shortcode_atts( array( 'id' => 0 ), $atts ) );
  53. ob_start();
  54.  
  55. $form = new WPUF_Form( $id );
  56. $form_settings = $form->get_settings( $id );
  57. $info = '';
  58. $user_can_post = 'yes';
  59. $current_user = wpuf_get_user();
  60. $guest_post_enabled = $form->guest_post();
  61.  
  62. if ( isset( $form_settings['message_restrict'] ) && !$guest_post_enabled && ! is_user_logged_in() ) {
  63. $user_can_post = 'no';
  64. $info = $form_settings['message_restrict'];
  65. }
  66.  
  67. if ( $form->is_charging_enabled() ) {
  68. $pay_per_post = $form->is_enabled_pay_per_post();
  69. $pay_per_post_cost = (float) $form->get_pay_per_post_cost();
  70. $force_pack = $form->is_enabled_force_pack();
  71. $fallback_enabled = $form->is_enabled_fallback_cost();
  72. $fallback_cost = $form->get_subs_fallback_cost();
  73. $has_post_count = $current_user->subscription()->has_post_count( $form_settings['post_type'] );
  74.  
  75. // guest post payment checking
  76. if ( ! is_user_logged_in() && isset( $form_settings['guest_post'] ) && $form_settings['guest_post'] == 'true' ) {
  77. if ( $form->is_charging_enabled() ) {
  78. if ( $force_pack ) {
  79. $user_can_post = 'no';
  80. $info = 'You need to buy a pack to post in this form.';
  81. } elseif ( $pay_per_post && !$force_pack ) {
  82. $user_can_post = 'yes';
  83. // $info = sprintf( __( 'There is a <strong>%s</strong> charge to add a new post.', 'wpuf' ), wpuf_format_price( $pay_per_post_cost ));
  84. // echo '<div class="wpuf-info">' . apply_filters( 'wpuf_ppp_notice', $info, $id, $form_settings ) . '</div>';
  85. } else {
  86. $user_can_post = 'no';
  87. $info = sprintf( __( 'Payment type not selected for this form. Please contact admin.', 'wpuf' ));
  88. }
  89. } else {
  90. $user_can_post = 'yes';
  91. }
  92.  
  93. } else {
  94. // regular payment checking
  95. if ( $force_pack ) {
  96. if ( is_user_logged_in() ) {
  97. $current_pack = $current_user->subscription()->current_pack();
  98.  
  99. if ( ! is_wp_error( $current_pack ) ) {
  100. // user has valid post count
  101. if ( $has_post_count ) {
  102. $user_can_post = 'yes';
  103. } else {
  104. if ( $fallback_enabled && !$has_post_count ) {
  105. $user_can_post = 'yes';
  106. } else {
  107. $user_can_post = 'no';
  108. $info = 'Post Limit Exceeded for your purchased subscription pack.';
  109. }
  110. }
  111. } else {
  112. $user_can_post = 'no';
  113. $info = $current_pack->get_error_message();
  114. }
  115. }
  116.  
  117. } elseif ( $pay_per_post && is_user_logged_in() && !$current_user->subscription()->has_post_count( $form_settings['post_type'] ) ) {
  118.  
  119. $user_can_post = 'yes';
  120. // $info = sprintf( __( 'There is a <strong>%s</strong> charge to add a new post.', 'wpuf' ), wpuf_format_price( $pay_per_post_cost ));
  121. // echo '<div class="wpuf-info">' . apply_filters( 'wpuf_ppp_notice', $info, $id, $form_settings ) . '</div>';
  122.  
  123. } elseif ( !$pay_per_post && !$current_user->subscription()->has_post_count( $form_settings['post_type'] ) ) {
  124.  
  125. $user_can_post = 'no';
  126. $info = sprintf( __( 'Payment type not selected for this form. Please contact admin.', 'wpuf' ));
  127.  
  128. } else {
  129. $user_can_post = 'no';
  130. if ( !is_user_logged_in() ) {
  131. $info = $form_settings['message_restrict'];
  132. } else {
  133. $info = sprintf( __( 'Payment type not selected for this form. Please contact admin.', 'wpuf' ));
  134. }
  135.  
  136. }
  137. }
  138. } else {
  139. if ( isset( $form_settings['guest_post'] ) && $form_settings['guest_post'] == 'true' && ! is_user_logged_in() ) {
  140. $user_can_post = 'yes';
  141. }
  142. }
  143.  
  144. $info = apply_filters( 'wpuf_addpost_notice', $info, $id, $form_settings );
  145. $user_can_post = apply_filters( 'wpuf_can_post', $user_can_post, $id, $form_settings );
  146.  
  147. if ( $user_can_post == 'yes' ) {
  148. $this->render_form( $id );
  149. } else {
  150. echo '<div class="wpuf-info">' . $info . '</div>';
  151. }
  152.  
  153. $content = ob_get_contents();
  154. ob_end_clean();
  155.  
  156. return $content;
  157. }
  158.  
  159. /**
  160. * Edit post shortcode handler
  161. *
  162. * @param array $atts
  163. * @return string
  164. */
  165. function edit_post_shortcode( $atts ) {
  166. global $userdata;
  167. // wpuf()->plugin_scripts();
  168. ?>
  169. <style>
  170. <?php //echo $custom_css = wpuf_get_option( 'custom_css', 'wpuf_general' ); ?>
  171. </style>
  172. <?php
  173. ob_start();
  174.  
  175. if ( !is_user_logged_in() ) {
  176. echo '<div class="wpuf-message">' . __( 'You are not logged in', 'wpuf' ) . '</div>';
  177. wp_login_form();
  178. return;
  179. }
  180.  
  181. $post_id = isset( $_GET['pid'] ) ? intval( $_GET['pid'] ) : 0;
  182.  
  183. if ( !$post_id ) {
  184. return '<div class="wpuf-info">' . __( 'Invalid post', 'wpuf' ) . '</div>';
  185. }
  186.  
  187. //is editing enabled?
  188. if ( wpuf_get_option( 'enable_post_edit', 'wpuf_dashboard', 'yes' ) != 'yes' ) {
  189. return '<div class="wpuf-info">' . __( 'Post Editing is disabled', 'wpuf' ) . '</div>';
  190. }
  191.  
  192. $curpost = get_post( $post_id );
  193.  
  194. if ( !$curpost ) {
  195. return '<div class="wpuf-info">' . __( 'Invalid post', 'wpuf' );
  196. }
  197.  
  198. // has permission?
  199. if ( !current_user_can( 'delete_others_posts' ) && ( $userdata->ID != $curpost->post_author ) ) {
  200. return '<div class="wpuf-info">' . __( 'You are not allowed to edit', 'wpuf' ) . '</div>';
  201. }
  202.  
  203. $form_id = get_post_meta( $post_id, self::$config_id, true );
  204. $form_settings = wpuf_get_form_settings( $form_id );
  205.  
  206. // fallback to default form
  207. if ( !$form_id ) {
  208. $form_id = wpuf_get_option( 'default_post_form', 'wpuf_frontend_posting' );
  209. }
  210.  
  211. if ( !$form_id ) {
  212. return '<div class="wpuf-info">' . __( "I don't know how to edit this post, I don't have the form ID", 'wpuf' ) . '</div>';
  213. }
  214.  
  215. $disable_pending_edit = wpuf_get_option( 'disable_pending_edit', 'wpuf_dashboard', 'on' );
  216.  
  217. if ( $curpost->post_status == 'pending' && $disable_pending_edit == 'on' ) {
  218. return '<div class="wpuf-info">' . __( 'You can\'t edit a post while in pending mode.', 'wpuf' );
  219. }
  220.  
  221. if ( isset( $_GET['msg'] ) && $_GET['msg'] == 'post_updated' ) {
  222. echo '<div class="wpuf-success">';
  223. echo str_replace( '%link%', get_permalink( $post_id ), $form_settings['update_message'] );
  224. echo '</div>';
  225. }
  226.  
  227. $this->render_form( $form_id, $post_id );
  228.  
  229. $content = ob_get_contents();
  230. ob_end_clean();
  231.  
  232. return $content;
  233. }
  234.  
  235. /**
  236. * New/Edit post submit handler
  237. *
  238. * @return void
  239. */
  240. function submit_post() {
  241.  
  242. check_ajax_referer( 'wpuf_form_add' );
  243.  
  244. @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
  245.  
  246. $form_id = isset( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : 0;
  247. $form_vars = $this->get_input_fields( $form_id );
  248. $form_settings = wpuf_get_form_settings( $form_id );
  249. $guest_mode = isset( $form_settings['guest_post'] ) ? $form_settings['guest_post'] : '';
  250. $guest_verify = isset( $form_settings['guest_email_verify'] ) ? $form_settings['guest_email_verify'] : 'false' ;
  251.  
  252. list( $post_vars, $taxonomy_vars, $meta_vars ) = $form_vars;
  253.  
  254. // don't check captcha on post edit
  255. if ( !isset( $_POST['post_id'] ) ) {
  256.  
  257. $has_limit = ( isset( $form_settings['limit_entries'] ) && $form_settings['limit_entries'] == 'true' ) ? true : false;
  258. $is_scheduled = ( isset( $form_settings['schedule_form'] ) && $form_settings['schedule_form'] == 'true' ) ? true : false;
  259.  
  260. if ( $has_limit ) {
  261.  
  262. $limit = (int) !empty( $form_settings['limit_number'] ) ? $form_settings['limit_number'] : 0;
  263. $form_entries = wpuf_form_posts_count( $form_id );
  264.  
  265. if ( $limit && $limit <= $form_entries ) {
  266. $this->send_error( $form_settings['limit_message'] );
  267. }
  268. }
  269.  
  270. if ( $is_scheduled ) {
  271.  
  272. $start_time = !empty( $form_settings['schedule_start'] ) ? strtotime( $form_settings['schedule_start'] ) : 0;
  273. $end_time = !empty( $form_settings['schedule_end'] ) ? strtotime( $form_settings['schedule_end'] ) : 0;
  274. $current_time = current_time( 'timestamp' );
  275.  
  276. // too early?
  277. if ( $current_time < $start_time ) {
  278. $this->send_error( $form_settings['form_pending_message'] );
  279. } elseif ( $current_time > $end_time ) {
  280. $this->send_error( $form_settings['form_expired_message'] );
  281. }
  282. }
  283.  
  284. // search if rs captcha is there
  285. if ( $this->search( $post_vars, 'input_type', 'really_simple_captcha' ) ) {
  286. $this->validate_rs_captcha();
  287. }
  288. $no_captcha = $invisible_captcha = '';
  289.  
  290. $check_recaptcha = $this->search( $post_vars, 'input_type', 'recaptcha' );
  291.  
  292. if ( !empty( $check_recaptcha ) ) {
  293. $recaptcha_type = $check_recaptcha[0]['recaptcha_type'];
  294. }
  295.  
  296. // check recaptcha
  297. if ( $check_recaptcha ) {
  298.  
  299. if ( isset ( $_POST["g-recaptcha-response"] ) ) {
  300. if ( empty( $_POST['g-recaptcha-response'] ) && $check_recaptcha[0]['recaptcha_type'] !== 'invisible_recaptcha') {
  301. $this->send_error( __( 'Empty reCaptcha Field', 'wpuf' ) );
  302. }
  303.  
  304. if ( $recaptcha_type == 'enable_no_captcha' ) {
  305. $no_captcha = 1;
  306. $invisible_captcha = 0;
  307. } elseif ( $recaptcha_type == 'invisible_recaptcha' ) {
  308. $invisible_captcha = 1;
  309. $no_captcha = 0;
  310. } else {
  311. $invisible_captcha = 0;
  312. $no_captcha = 0;
  313. }
  314. }
  315. $this->validate_re_captcha( $no_captcha, $invisible_captcha );
  316. }
  317. }
  318.  
  319. $is_update = false;
  320. $post_author = null;
  321. $default_post_author = wpuf_get_option( 'default_post_owner', 'wpuf_frontend_posting', 1 );
  322.  
  323. // Guest Stuffs: check for guest post
  324. if ( !is_user_logged_in() ) {
  325.  
  326. if ( isset( $form_settings['guest_post'] ) && $form_settings['guest_post'] == 'true' && $form_settings['guest_details'] == 'true' ) {
  327. $guest_name = trim( $_POST['guest_name'] );
  328. $guest_email = trim( $_POST['guest_email'] );
  329.  
  330. // is valid email?
  331. if ( !is_email( $guest_email ) ) {
  332. $this->send_error( __( 'Invalid email address.', 'wpuf' ) );
  333. }
  334.  
  335. // check if the user email already exists
  336. $user = get_user_by( 'email', $guest_email );
  337. if ( $user ) {
  338. // $post_author = $user->ID;
  339. wp_send_json( array(
  340. 'success' => false,
  341. 'error' => __( "You already have an account in our site. Please login to continue.\n\nClicking 'OK' will redirect you to the login page and you will lose the form data.\nClick 'Cancel' to stay at this page.", 'wpuf' ),
  342. 'type' => 'login',
  343. 'redirect_to' => wp_login_url( get_permalink( $_POST['page_id'] ) )
  344. ) );
  345. } else {
  346.  
  347. // user not found, lets register him
  348. // username from email address
  349. $username = $this->guess_username( $guest_email );
  350. $user_pass = wp_generate_password( 12, false );
  351.  
  352. $errors = new WP_Error();
  353. do_action( 'register_post', $username, $guest_email, $errors );
  354.  
  355. $user_id = wp_create_user( $username, $user_pass, $guest_email );
  356.  
  357. // if its a success and no errors found
  358. if ( $user_id && !is_wp_error( $user_id ) ) {
  359. update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag.
  360.  
  361. if ( class_exists( 'Theme_My_Login_Custom_Email' ) ) {
  362. do_action( 'tml_new_user_registered', $user_id, $user_pass );
  363. } else {
  364. wp_send_new_user_notifications( $user_id );
  365. }
  366.  
  367. // update display name to full name
  368. wp_update_user( array( 'ID' => $user_id, 'display_name' => $guest_name ) );
  369.  
  370. $post_author = $user_id;
  371. } else {
  372. //something went wrong creating the user, set post author to the default author
  373. $post_author = $default_post_author;
  374. }
  375. }
  376.  
  377. // guest post is enabled and details are off
  378. } elseif ( isset( $form_settings['guest_post'] ) && $form_settings['guest_post'] == 'true' && $form_settings['guest_details'] == 'false' ) {
  379. $post_author = $default_post_author;
  380. } elseif ( isset( $form_settings['guest_post'] ) && $form_settings['guest_post'] != 'true' ) {
  381. $this->send_error( $form_settings['message_restrict'] );
  382. }
  383.  
  384. // the user must be logged in already
  385. } elseif ( isset( $form_settings['role_base'] ) && $form_settings['role_base'] == 'true' ) {
  386.  
  387. $current_user = wp_get_current_user();
  388.  
  389. if ( !in_array( $current_user->roles[0], $form_settings['roles'] ) ) {
  390. $this->send_error( __( 'You do not have sufficient permissions to access this form.', 'wpuf' ) );
  391. }
  392.  
  393. } else {
  394. $post_author = get_current_user_id();
  395. }
  396.  
  397. $postarr = array(
  398. 'post_type' => $form_settings['post_type'],
  399. 'post_status' => isset( $form_settings['post_status'] ) ? $form_settings['post_status'] : 'publish',
  400. 'post_author' => $post_author,
  401. 'post_title' => isset( $_POST['post_title'] ) ? trim( $_POST['post_title'] ) : '',
  402. 'post_content' => isset( $_POST['post_content'] ) ? trim( $_POST['post_content'] ) : '',
  403. 'post_excerpt' => isset( $_POST['post_excerpt'] ) ? trim( $_POST['post_excerpt'] ) : '',
  404. );
  405.  
  406. // $charging_enabled = wpuf_get_option( 'charge_posting', 'wpuf_payment' );
  407. $charging_enabled = '';
  408. $form = new WPUF_Form( $form_id );
  409. $payment_options = $form->is_charging_enabled();
  410. $ppp_cost_enabled = $form->is_enabled_pay_per_post();
  411. $forcePack = $form->is_enabled_force_pack();
  412. $current_user = wpuf_get_user();
  413.  
  414. if ( !$payment_options || !is_user_logged_in() ) {
  415. $charging_enabled = 'no';
  416. } else {
  417. $charging_enabled = 'yes';
  418. }
  419. if ( $guest_mode == 'true' && $guest_verify == 'true' && !is_user_logged_in() && $charging_enabled == 'yes' ) {
  420. $postarr['post_status'] = wpuf_get_draft_post_status( $form_settings );
  421. } elseif ( $guest_mode == 'true' && $guest_verify == 'true' && !is_user_logged_in() ) {
  422. $postarr['post_status'] = 'draft';
  423. }
  424.  
  425. //if date is set and assigned as publish date
  426. if ( isset( $_POST['wpuf_is_publish_time'] ) ) {
  427.  
  428. if ( isset( $_POST[$_POST['wpuf_is_publish_time']] ) && !empty( $_POST[$_POST['wpuf_is_publish_time']] ) ) {
  429. $postarr['post_date'] = date( 'Y-m-d H:i:s', strtotime( str_replace( array( ':', '/' ), '-', $_POST[$_POST['wpuf_is_publish_time']] ) ) );
  430. }
  431. }
  432.  
  433. if ( isset( $_POST['category'] ) && '-1' != $_POST['category'][0] ) {
  434. $category = $_POST['category'];
  435. $postarr['post_category'] = is_array( $category ) ? $category : array( $category );
  436.  
  437. if ( !is_array( $category ) && is_string( $category ) ) {
  438. $category_strings = explode( ',', $category );
  439.  
  440. $cat_ids = array();
  441.  
  442. foreach ( $category_strings as $key => $each_cat_string ) {
  443. $cat_ids[] = get_cat_ID( trim( $each_cat_string ) );
  444. $postarr['post_category'] = $cat_ids;
  445. }
  446. }
  447. }
  448.  
  449. if ( isset( $_POST['tags'] ) ) {
  450. $postarr['tags_input'] = explode( ',', $_POST['tags'] );
  451. }
  452.  
  453. // if post_id is passed, we update the post
  454. if ( isset( $_POST['post_id'] ) ) {
  455.  
  456. $is_update = true;
  457. $postarr['ID'] = $_POST['post_id'];
  458. $postarr['post_date'] = $_POST['post_date'];
  459. $postarr['comment_status'] = $_POST['comment_status'];
  460. $postarr['post_author'] = $_POST['post_author'];
  461. $postarr['post_parent'] = get_post_field( 'post_parent', $_POST['post_id'] );
  462.  
  463. if ( $form_settings['edit_post_status'] == '_nochange' ) {
  464. $postarr['post_status'] = get_post_field( 'post_status', $_POST['post_id'] );
  465. } else {
  466. $postarr['post_status'] = $form_settings['edit_post_status'];
  467. }
  468. } else {
  469. if ( isset( $form_settings['comment_status'] ) ) {
  470. $postarr['comment_status'] = $form_settings['comment_status'];
  471. }
  472. }
  473.  
  474. // check the form status, it might be already a draft
  475. // in that case, it already has the post_id field
  476. // so, WPUF's add post action/filters won't work for new posts
  477. if ( isset( $_POST['wpuf_form_status'] ) && $_POST['wpuf_form_status'] == 'new' ) {
  478. $is_update = false;
  479. }
  480.  
  481. // set default post category if it's not been set yet and if post type supports
  482. if ( !isset( $postarr['post_category'] ) && isset( $form_settings['default_cat'] ) && is_object_in_taxonomy( $form_settings['post_type'], 'category' ) ) {
  483. if ( is_array( $form_settings['default_cat'] ) ) {
  484. $postarr['post_category'] = $form_settings['default_cat'];
  485. } else {
  486. $postarr['post_category'] = array( $form_settings['default_cat'] );
  487. }
  488. }
  489.  
  490. // validation filter
  491. if ( $is_update ) {
  492. $error = apply_filters( 'wpuf_update_post_validate', '' );
  493. } else {
  494. $error = apply_filters( 'wpuf_add_post_validate', '' );
  495. }
  496.  
  497. if ( !empty( $error ) ) {
  498. $this->send_error( $error );
  499. }
  500.  
  501. // ############ It's Time to Save the World ###############
  502. if ( $is_update ) {
  503. $postarr = apply_filters( 'wpuf_update_post_args', $postarr, $form_id, $form_settings, $form_vars );
  504. } else {
  505. $postarr = apply_filters( 'wpuf_add_post_args', $postarr, $form_id, $form_settings, $form_vars );
  506. }
  507.  
  508. $post_id = wp_insert_post( $postarr );
  509.  
  510. if ( $post_id ) {
  511.  
  512. self::update_post_meta( $meta_vars, $post_id );
  513.  
  514. // if user has a subscription pack
  515. $user_wpuf_subscription_pack = get_user_meta( get_current_user_id(), '_wpuf_subscription_pack', true );
  516.  
  517. if ( !empty( $user_wpuf_subscription_pack ) && isset( $user_wpuf_subscription_pack['_enable_post_expiration'] ) && isset( $user_wpuf_subscription_pack['expire'] ) && strtotime( $user_wpuf_subscription_pack['expire'] ) >= time()
  518. ) {
  519. $expire_date = date( 'Y-m-d', strtotime( "+" . $user_wpuf_subscription_pack['_post_expiration_time'] ) );
  520. update_post_meta( $post_id, $this->post_expiration_date, $expire_date );
  521.  
  522. // save post status after expiration
  523. $expired_post_status = $user_wpuf_subscription_pack['_expired_post_status'];
  524. update_post_meta( $post_id, $this->expired_post_status, $expired_post_status );
  525.  
  526. // if mail active
  527. if ( isset( $user_wpuf_subscription_pack['_enable_mail_after_expired'] ) && $user_wpuf_subscription_pack['_enable_mail_after_expired'] == 'on' ) {
  528. $post_expiration_message = $user_wpuf_subscription_pack['_post_expiration_message'];
  529. update_post_meta( $post_id, $this->post_expiration_message, $post_expiration_message );
  530. }
  531. } elseif ( !empty( $user_wpuf_subscription_pack ) && isset( $user_wpuf_subscription_pack['expire'] ) && strtotime( $user_wpuf_subscription_pack['expire'] ) <= time() ) {
  532.  
  533. if ( isset( $form_settings['expiration_settings']['enable_post_expiration'] ) ) {
  534.  
  535. $expire_date = date( 'Y-m-d', strtotime( "+" . $form_settings['expiration_settings']['expiration_time_value'] . ' ' . $form_settings['expiration_settings']['expiration_time_type'] . "" ) );
  536. update_post_meta( $post_id, $this->post_expiration_date, $expire_date );
  537.  
  538. // save post status after expiration
  539. $expired_post_status = $form_settings['expiration_settings']['expired_post_status'];
  540. update_post_meta( $post_id, $this->expired_post_status, $expired_post_status );
  541.  
  542. // if mail active
  543. if ( isset( $form_settings['expiration_settings']['enable_mail_after_expired'] ) && $form_settings['expiration_settings']['enable_mail_after_expired'] == 'on' ) {
  544. $post_expiration_message = $form_settings['expiration_settings']['post_expiration_message'];
  545. update_post_meta( $post_id, $this->post_expiration_message, $post_expiration_message );
  546. }
  547. }
  548. } elseif ( empty( $user_wpuf_subscription_pack ) ) {
  549.  
  550. if ( isset( $form_settings['expiration_settings']['enable_post_expiration'] ) ) {
  551. $expire_date = date( 'Y-m-d', strtotime( "+" . $form_settings['expiration_settings']['expiration_time_value'] . ' ' . $form_settings['expiration_settings']['expiration_time_type'] . "" ) );
  552. update_post_meta( $post_id, $this->post_expiration_date, $expire_date );
  553.  
  554. // save post status after expiration
  555. $expired_post_status = $form_settings['expiration_settings']['expired_post_status'];
  556. update_post_meta( $post_id, $this->expired_post_status, $expired_post_status );
  557.  
  558. // if mail active
  559. if ( isset( $form_settings['expiration_settings']['enable_mail_after_expired'] ) && $form_settings['expiration_settings']['enable_mail_after_expired'] == 'on' ) {
  560. $post_expiration_message = $form_settings['expiration_settings']['post_expiration_message'];
  561. update_post_meta( $post_id, $this->post_expiration_message, $post_expiration_message );
  562. }
  563. }
  564. }
  565.  
  566. // set the post form_id for later usage
  567. update_post_meta( $post_id, self::$config_id, $form_id );
  568.  
  569. // save post formats if have any
  570. if ( isset( $form_settings['post_format'] ) && $form_settings['post_format'] != '0' ) {
  571. if ( post_type_supports( $form_settings['post_type'], 'post-formats' ) ) {
  572. set_post_format( $post_id, $form_settings['post_format'] );
  573. }
  574. }
  575.  
  576. // find our if any images in post content and associate them
  577. if ( !empty( $postarr['post_content'] ) ) {
  578. $dom = new DOMDocument();
  579. @$dom->loadHTML( $postarr['post_content'] );
  580. $images = $dom->getElementsByTagName( 'img' );
  581.  
  582. if ( $images->length ) {
  583. foreach ( $images as $img ) {
  584. $url = $img->getAttribute( 'src' );
  585. $url = str_replace( array( '"', "'", "\\" ), '', $url );
  586. $attachment_id = wpuf_get_attachment_id_from_url( $url );
  587.  
  588. if ( $attachment_id ) {
  589. wpuf_associate_attachment( $attachment_id, $post_id );
  590. }
  591. }
  592. }
  593. }
  594.  
  595. // save any custom taxonomies
  596. $woo_attr = array();
  597.  
  598. foreach ( $taxonomy_vars as $taxonomy ) {
  599. if ( isset( $_POST[$taxonomy['name']] ) ) {
  600.  
  601. if ( is_object_in_taxonomy( $form_settings['post_type'], $taxonomy['name'] ) ) {
  602. $tax = $_POST[$taxonomy['name']];
  603.  
  604. // if it's not an array, make it one
  605. if ( !is_array( $tax ) ) {
  606. $tax = array( $tax );
  607. }
  608.  
  609. if ( $taxonomy['type'] == 'text' ) {
  610.  
  611. $hierarchical = array_map( 'trim', array_map( 'strip_tags', explode( ',', $_POST[$taxonomy['name']] ) ) );
  612.  
  613. wp_set_object_terms( $post_id, $hierarchical, $taxonomy['name'] );
  614.  
  615. // woocommerce check
  616. if ( isset( $taxonomy['woo_attr'] ) && $taxonomy['woo_attr'] == 'yes' && !empty( $_POST[$taxonomy['name']] ) ) {
  617. $woo_attr[sanitize_title( $taxonomy['name'] )] = $this->woo_attribute( $taxonomy );
  618. }
  619. } else {
  620.  
  621. if ( is_taxonomy_hierarchical( $taxonomy['name'] ) ) {
  622. wp_set_post_terms( $post_id, $_POST[$taxonomy['name']], $taxonomy['name'] );
  623.  
  624. // woocommerce check
  625. if ( isset( $taxonomy['woo_attr'] ) && $taxonomy['woo_attr'] == 'yes' && !empty( $_POST[$taxonomy['name']] ) ) {
  626. $woo_attr[sanitize_title( $taxonomy['name'] )] = $this->woo_attribute( $taxonomy );
  627. }
  628. } else {
  629. if ( $tax ) {
  630. $non_hierarchical = array();
  631.  
  632. foreach ( $tax as $value ) {
  633. $term = get_term_by( 'id', $value, $taxonomy['name'] );
  634. if ( $term && !is_wp_error( $term ) ) {
  635. $non_hierarchical[] = $term->name;
  636. }
  637. }
  638.  
  639. wp_set_post_terms( $post_id, $non_hierarchical, $taxonomy['name'] );
  640.  
  641. // woocommerce check
  642. if ( isset( $taxonomy['woo_attr'] ) && $taxonomy['woo_attr'] == 'yes' && !empty( $_POST[$taxonomy['name']] ) ) {
  643. $woo_attr[sanitize_title( $taxonomy['name'] )] = $this->woo_attribute( $taxonomy );
  644. }
  645.  
  646. }
  647. } // hierarchical
  648. } // is text
  649. } // is object tax
  650. } // isset tax
  651. }
  652.  
  653. // if a woocommerce attribute
  654. if ( $woo_attr ) {
  655. update_post_meta( $post_id, '_product_attributes', $woo_attr );
  656. }
  657.  
  658. //redirect URL
  659. $show_message = false;
  660. $redirect_to = false;
  661. $response = array();
  662.  
  663. if ( $is_update ) {
  664. if ( $form_settings['edit_redirect_to'] == 'page' ) {
  665. $redirect_to = get_permalink( $form_settings['edit_page_id'] );
  666. } elseif ( $form_settings['edit_redirect_to'] == 'url' ) {
  667. $redirect_to = $form_settings['edit_url'];
  668. } elseif ( $form_settings['edit_redirect_to'] == 'same' ) {
  669. $redirect_to = add_query_arg( array(
  670. 'pid' => $post_id,
  671. '_wpnonce' => wp_create_nonce( 'wpuf_edit' ),
  672. 'msg' => 'post_updated'
  673. ), get_permalink( $_POST['page_id'] )
  674. );
  675. } else {
  676. $redirect_to = get_permalink( $post_id );
  677. }
  678. } else {
  679. if ( $form_settings['redirect_to'] == 'page' ) {
  680. $redirect_to = get_permalink( $form_settings['page_id'] );
  681. } elseif ( $form_settings['redirect_to'] == 'url' ) {
  682. $redirect_to = $form_settings['url'];
  683. } elseif ( $form_settings['redirect_to'] == 'same' ) {
  684. $show_message = true;
  685. } else {
  686. $redirect_to = get_permalink( $post_id );
  687. }
  688. }
  689.  
  690. $response = array(
  691. 'success' => true,
  692. 'redirect_to' => $redirect_to,
  693. 'show_message' => $show_message,
  694. 'message' => $form_settings['message']
  695. );
  696.  
  697. // Now Send the mail to guests
  698. global $wp;
  699.  
  700. if ( $guest_mode == 'true' && $guest_verify == 'true' && !is_user_logged_in() && $charging_enabled != 'yes') {
  701. $post_id_encoded = wpuf_encryption( $post_id ) ;
  702. $form_id_encoded = wpuf_encryption( $form_id ) ;
  703. wpuf_send_mail_to_guest ( $post_id_encoded, $form_id_encoded, 'no', 1 );
  704. $response['show_message'] = true;
  705. $response['redirect_to'] = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
  706. $response['message'] = 'Thank you for posting on our site. We have sent you an confirmation email. Please check your inbox!';
  707.  
  708. } elseif ( $guest_mode == 'true' && $guest_verify == 'true' && !is_user_logged_in() && $charging_enabled == 'yes' ) {
  709. $post_id_encoded = wpuf_encryption( $post_id ) ;
  710. $form_id_encoded = wpuf_encryption( $form_id ) ;
  711. $response['show_message'] = true;
  712. $response['redirect_to'] = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
  713. $response['message'] = 'Thank you for posting on our site. We have sent you an confirmation email. Please check your inbox!';
  714. update_post_meta ( $post_id, '_wpuf_payment_status', 'pending' );
  715. wpuf_send_mail_to_guest ( $post_id_encoded, $form_id_encoded, 'yes', 2 );
  716. }
  717.  
  718.  
  719. if ( $guest_mode == 'true' && $guest_verify == 'true' && !is_user_logged_in() ) {
  720.  
  721. $response = apply_filters( 'wpuf_edit_post_redirect', $response, $post_id, $form_id, $form_settings );
  722.  
  723. } elseif ( $is_update ) {
  724.  
  725. //send mail notification
  726. if ( isset( $form_settings['notification'] ) && $form_settings['notification']['edit'] == 'on' ) {
  727. $mail_body = $this->prepare_mail_body( $form_settings['notification']['edit_body'], $post_author, $post_id );
  728. $to = $this->prepare_mail_body( $form_settings['notification']['edit_to'], $post_author, $post_id );
  729. $subject = $this->prepare_mail_body( $form_settings['notification']['edit_subject'], $post_author, $post_id );
  730. $subject = wp_strip_all_tags( $subject );
  731. $headers = array('Content-Type: text/html; charset=UTF-8');
  732.  
  733. wp_mail( $to, $subject, $mail_body, $headers );
  734. }
  735.  
  736. //now redirect the user
  737. $response = apply_filters( 'wpuf_edit_post_redirect', $response, $post_id, $form_id, $form_settings );
  738.  
  739. //now perform some post related actions
  740. do_action( 'wpuf_edit_post_after_update', $post_id, $form_id, $form_settings, $form_vars ); // plugin API to extend the functionality
  741.  
  742. } else {
  743.  
  744. // send mail notification
  745. if ( isset( $form_settings['notification'] ) && $form_settings['notification']['new'] == 'on' ) {
  746. $mail_body = $this->prepare_mail_body( $form_settings['notification']['new_body'], $post_author, $post_id );
  747. $to = $this->prepare_mail_body( $form_settings['notification']['new_to'], $post_author, $post_id );
  748. $subject = $this->prepare_mail_body( $form_settings['notification']['new_subject'], $post_author, $post_id );
  749. $subject = wp_strip_all_tags( $subject );
  750.  
  751. wp_mail( $to, $subject, $mail_body );
  752. }
  753.  
  754. //redirect the user
  755. $response = apply_filters( 'wpuf_add_post_redirect', $response, $post_id, $form_id, $form_settings );
  756.  
  757. //now perform some post related actions
  758. do_action( 'wpuf_add_post_after_insert', $post_id, $form_id, $form_settings, $form_vars ); // plugin API to extend the functionality
  759. }
  760.  
  761. wpuf_clear_buffer();
  762. wp_send_json( $response );
  763.  
  764. }
  765.  
  766. $this->send_error( __( 'Something went wrong', 'wpuf' ) );
  767. }
  768.  
  769. /**
  770. * this will embed media to the editor
  771. */
  772. function make_media_embed_code() {
  773. if ( $embed_code = wp_oembed_get( $_POST['content'] ) ) {
  774. echo $embed_code;
  775. } else {
  776. echo '';
  777. }
  778.  
  779. exit;
  780. }
  781.  
  782. function draft_post() {
  783. check_ajax_referer( 'wpuf_form_add' );
  784.  
  785. @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
  786.  
  787. $form_id = isset( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : 0;
  788. $form_vars = $this->get_input_fields( $form_id );
  789. $form_settings = wpuf_get_form_settings( $form_id );
  790. $post_content = isset( $_POST[ 'post_content' ] ) ? $_POST[ 'post_content' ] : '';
  791.  
  792. list( $post_vars, $taxonomy_vars, $meta_vars ) = $form_vars;
  793.  
  794. $postarr = array(
  795. 'post_type' => $form_settings['post_type'],
  796. 'post_status' => wpuf_get_draft_post_status( $form_settings ),
  797. 'post_author' => get_current_user_id(),
  798. 'post_title' => isset( $_POST['post_title'] ) ? trim( $_POST['post_title'] ) : '',
  799. 'post_content' => $post_content,
  800. 'post_excerpt' => isset( $_POST['post_excerpt'] ) ? trim( $_POST['post_excerpt'] ) : '',
  801. );
  802.  
  803. if ( isset( $_POST['category'] ) ) {
  804. $category = $_POST['category'];
  805. $postarr['post_category'] = is_array( $category ) ? $category : array( $category );
  806. }
  807.  
  808. if ( isset( $_POST['tags'] ) ) {
  809. $postarr['tags_input'] = explode( ',', $_POST['tags'] );
  810. }
  811.  
  812. // if post_id is passed, we update the post
  813. if ( isset( $_POST['post_id'] ) ) {
  814. $is_update = true;
  815. $postarr['ID'] = $_POST['post_id'];
  816. $postarr['comment_status'] = 'open';
  817. }
  818.  
  819. $post_id = wp_insert_post( $postarr );
  820.  
  821. if ( $post_id ) {
  822.  
  823. self::update_post_meta( $meta_vars, $post_id );
  824.  
  825. // set the post form_id for later usage
  826. update_post_meta( $post_id, self::$config_id, $form_id );
  827.  
  828. // save post formats if have any
  829. if ( isset( $form_settings['post_format'] ) && $form_settings['post_format'] != '0' ) {
  830. if ( post_type_supports( $form_settings['post_type'], 'post-formats' ) ) {
  831. set_post_format( $post_id, $form_settings['post_format'] );
  832. }
  833. }
  834.  
  835. // save any custom taxonomies
  836. $woo_attr = array();
  837.  
  838. foreach ( $taxonomy_vars as $taxonomy ) {
  839. if ( isset( $_POST[$taxonomy['name']] ) ) {
  840.  
  841. if ( is_object_in_taxonomy( $form_settings['post_type'], $taxonomy['name'] ) ) {
  842. $tax = $_POST[$taxonomy['name']];
  843.  
  844. // if it's not an array, make it one
  845. if ( !is_array( $tax ) ) {
  846. $tax = array( $tax );
  847. }
  848.  
  849. if ( $taxonomy['type'] == 'text' ) {
  850.  
  851. $hierarchical = array_map( 'trim', array_map( 'strip_tags', explode( ',', $_POST[$taxonomy['name']] ) ) );
  852.  
  853. wp_set_object_terms( $post_id, $hierarchical, $taxonomy['name'] );
  854.  
  855. // woocommerce check
  856. if ( isset( $taxonomy['woo_attr'] ) && $taxonomy['woo_attr'] == 'yes' && !empty( $_POST[$taxonomy['name']] ) ) {
  857. $woo_attr[sanitize_title( $taxonomy['name'] )] = $this->woo_attribute( $taxonomy );
  858. }
  859. } else {
  860.  
  861. if ( is_taxonomy_hierarchical( $taxonomy['name'] ) ) {
  862. wp_set_post_terms( $post_id, $_POST[$taxonomy['name']], $taxonomy['name'] );
  863.  
  864. // woocommerce check
  865. if ( isset( $taxonomy['woo_attr'] ) && $taxonomy['woo_attr'] == 'yes' && !empty( $_POST[$taxonomy['name']] ) ) {
  866. $woo_attr[sanitize_title( $taxonomy['name'] )] = $this->woo_attribute( $taxonomy );
  867. }
  868. } else {
  869. if ( $tax ) {
  870. $non_hierarchical = array();
  871.  
  872. foreach ( $tax as $value ) {
  873. $term = get_term_by( 'id', $value, $taxonomy['name'] );
  874. if ( $term && !is_wp_error( $term ) ) {
  875. $non_hierarchical[] = $term->name;
  876. }
  877. }
  878.  
  879. wp_set_post_terms( $post_id, $non_hierarchical, $taxonomy['name'] );
  880.  
  881. // woocommerce check
  882. if ( isset( $taxonomy['woo_attr'] ) && $taxonomy['woo_attr'] == 'yes' && !empty( $_POST[$taxonomy['name']] ) ) {
  883. $woo_attr[sanitize_title( $taxonomy['name'] )] = $this->woo_attribute( $taxonomy );
  884. }
  885.  
  886. }
  887. } // hierarchical
  888. } // is text
  889. } // is object tax
  890. } // isset tax
  891. }
  892.  
  893. // if a woocommerce attribute
  894. if ( $woo_attr ) {
  895. update_post_meta( $post_id, '_product_attributes', $woo_attr );
  896. }
  897.  
  898. }
  899.  
  900. //used to add code to run when the post is going to draft
  901. do_action( 'wpuf_draft_post_after_insert', $post_id, $form_id, $form_settings, $form_vars );
  902.  
  903.  
  904. wpuf_clear_buffer();
  905.  
  906. echo json_encode( array(
  907. 'post_id' => $post_id,
  908. 'action' => $_POST['action'],
  909. 'date' => current_time( 'mysql' ),
  910. 'post_author' => get_current_user_id(),
  911. 'comment_status' => get_option( 'default_comment_status' ),
  912. 'url' => add_query_arg( 'preview', 'true', get_permalink( $post_id ) )
  913. ) );
  914.  
  915. exit;
  916. }
  917.  
  918. public static function update_post_meta( $meta_vars, $post_id ) {
  919.  
  920. // prepare the meta vars
  921. list( $meta_key_value, $multi_repeated, $files ) = self::prepare_meta_fields( $meta_vars );
  922.  
  923. // set featured image if there's any
  924. if ( isset( $_POST['wpuf_files']['featured_image'] ) ) {
  925. $attachment_id = $_POST['wpuf_files']['featured_image'][0];
  926.  
  927. wpuf_associate_attachment( $attachment_id, $post_id );
  928. set_post_thumbnail( $post_id, $attachment_id );
  929.  
  930. $file_data = isset( $_POST['wpuf_files_data'][$attachment_id] ) ? $_POST['wpuf_files_data'][$attachment_id] : false;
  931. if ( $file_data ) {
  932. $args = array(
  933. 'ID' => $attachment_id,
  934. 'post_title' => $file_data['title'],
  935. 'post_content' => $file_data['desc'],
  936. 'post_excerpt' => $file_data['caption'],
  937. );
  938. wpuf_update_post( $args );
  939.  
  940. update_post_meta( $attachment_id, '_wp_attachment_image_alt', $file_data['title'] );
  941. }
  942. }
  943.  
  944. // save all custom fields
  945. foreach ( $meta_key_value as $meta_key => $meta_value ) {
  946. update_post_meta( $post_id, $meta_key, $meta_value );
  947. }
  948.  
  949. // save any multicolumn repeatable fields
  950. foreach ( $multi_repeated as $repeat_key => $repeat_value ) {
  951. // first, delete any previous repeatable fields
  952. delete_post_meta( $post_id, $repeat_key );
  953.  
  954. // now add them
  955. foreach ( $repeat_value as $repeat_field ) {
  956. add_post_meta( $post_id, $repeat_key, $repeat_field );
  957. }
  958. }
  959.  
  960. // save any files attached
  961. foreach ( $files as $file_input ) {
  962. // delete any previous value
  963. delete_post_meta( $post_id, $file_input['name'] );
  964.  
  965. //to track how many files are being uploaded
  966. $file_numbers = 0;
  967.  
  968. foreach ( $file_input['value'] as $attachment_id ) {
  969.  
  970. //if file numbers are greated than allowed number, prevent it from being uploaded
  971. if ( $file_numbers >= $file_input['count'] ) {
  972. wp_delete_attachment( $attachment_id );
  973. continue;
  974. }
  975.  
  976. wpuf_associate_attachment( $attachment_id, $post_id );
  977. add_post_meta( $post_id, $file_input['name'], $attachment_id );
  978.  
  979. // file title, caption, desc update
  980. $file_data = isset( $_POST['wpuf_files_data'][$attachment_id] ) ? $_POST['wpuf_files_data'][$attachment_id] : false;
  981. if ( $file_data ) {
  982. $args = array(
  983. 'ID' => $attachment_id,
  984. 'post_title' => $file_data['title'],
  985. 'post_content' => $file_data['desc'],
  986. 'post_excerpt' => $file_data['caption'],
  987. );
  988. wpuf_update_post( $args );
  989.  
  990. update_post_meta( $attachment_id, '_wp_attachment_image_alt', $file_data['title'] );
  991. }
  992. $file_numbers++;
  993. }
  994. }
  995. }
  996.  
  997. function prepare_mail_body( $content, $user_id, $post_id ) {
  998. $user = get_user_by( 'id', $user_id );
  999. $post = get_post( $post_id );
  1000.  
  1001. $post_field_search = array( '%post_title%', '%post_content%', '%post_excerpt%', '%tags%', '%category%',
  1002. '%author%', '%author_email%', '%author_bio%', '%sitename%', '%siteurl%', '%permalink%', '%editlink%' );
  1003.  
  1004. $post_field_replace = array(
  1005. $post->post_title,
  1006. $post->post_content,
  1007. $post->post_excerpt,
  1008. get_the_term_list( $post_id, 'post_tag', '', ', ' ),
  1009. get_the_term_list( $post_id, 'category', '', ', ' ),
  1010. $user->display_name,
  1011. $user->user_email,
  1012. ($user->description) ? $user->description : 'not available',
  1013. get_bloginfo( 'name' ),
  1014. home_url(),
  1015. get_permalink( $post_id ),
  1016. admin_url( 'post.php?action=edit&post=' . $post_id )
  1017. );
  1018.  
  1019. $content = str_replace( $post_field_search, $post_field_replace, $content );
  1020.  
  1021. // custom fields
  1022. preg_match_all( '/%custom_([\w-]*)\b%/', $content, $matches );
  1023. list( $search, $replace ) = $matches;
  1024.  
  1025. if ( $replace ) {
  1026. foreach ( $replace as $index => $meta_key ) {
  1027. $value = get_post_meta( $post_id, $meta_key, false );
  1028. $new_value = implode( '; ', $value );
  1029.  
  1030. $original_value = '';
  1031. $meta_val = '';
  1032. if ( count( $value ) > 1 ) {
  1033. $isFirst = true;
  1034. foreach ($value as $val) {
  1035. if ( $isFirst ) {
  1036. if ( get_post_mime_type( (int) $val ) ) {
  1037. $meta_val = wp_get_attachment_url( $val );
  1038. } else {
  1039. $meta_val = $val;
  1040. }
  1041. $isFirst = false;
  1042. } else {
  1043. if ( get_post_mime_type( (int) $val ) ) {
  1044. $meta_val = $meta_val . ', ' . wp_get_attachment_url( $val );
  1045. } else {
  1046. $meta_val = $meta_val . ', ' . $val;
  1047. }
  1048. }
  1049. if ( get_post_mime_type( (int) $val ) ) {
  1050. $meta_val = $meta_val . ',' . wp_get_attachment_url( $val );
  1051. } else {
  1052. $meta_val = $meta_val . ',' . $val;
  1053. }
  1054. }
  1055. $original_value = $original_value . $meta_val ;
  1056. } else {
  1057. if ( get_post_mime_type( (int) $new_value ) ) {
  1058. $original_value = wp_get_attachment_url( $new_value );
  1059. } else {
  1060. $original_value = $new_value;
  1061. }
  1062. }
  1063.  
  1064. $content = str_replace( $search[$index], $original_value, $content );
  1065. }
  1066. }
  1067.  
  1068. return $content;
  1069. }
  1070.  
  1071. function woo_attribute( $taxonomy ) {
  1072. return array(
  1073. 'name' => $taxonomy['name'],
  1074. 'value' => $_POST[$taxonomy['name']],
  1075. 'is_visible' => $taxonomy['woo_attr_vis'] == 'yes' ? 1 : 0,
  1076. 'is_variation' => 0,
  1077. 'is_taxonomy' => 1
  1078. );
  1079. }
  1080.  
  1081. /**
  1082. * Hook to publish verified guest post with payment
  1083. *
  1084. * @since 2.5.8
  1085. */
  1086.  
  1087. function publish_guest_post () {
  1088.  
  1089. if ( isset($_GET['post_msg']) && $_GET['post_msg'] == 'verified' ) {
  1090. $response = array();
  1091.  
  1092. $post_id = wpuf_decryption ( $_GET['p_id'] );
  1093. $form_id = wpuf_decryption ( $_GET['f_id'] );
  1094. $form_settings = wpuf_get_form_settings( $form_id );
  1095. $post_author_id = get_post_field( 'post_author', $post_id );
  1096. $payment_status = new WPUF_Subscription();
  1097.  
  1098. $form = new WPUF_Form( $form_id );
  1099. $pay_per_post = $form->is_enabled_pay_per_post();
  1100. $force_pack = $form->is_enabled_force_pack();
  1101.  
  1102. if ( $form->is_charging_enabled() && $pay_per_post ) {
  1103. if ( ($payment_status->get_payment_status( $post_id ) ) == 'pending') {
  1104.  
  1105. $response['show_message'] = true;
  1106. $response['redirect_to'] = add_query_arg( array(
  1107. 'action' => 'wpuf_pay',
  1108. 'type' => 'post',
  1109. 'post_id' => $post_id
  1110. ), get_permalink( wpuf_get_option( 'payment_page', 'wpuf_payment' ) ) );
  1111.  
  1112. wp_redirect( $response['redirect_to'] );
  1113. wpuf_clear_buffer();
  1114. wpuf_send_json ( $response );
  1115. }
  1116. } else {
  1117. $p_status = get_post_status( $post_id );
  1118. if ( $p_status ) {
  1119. wp_update_post(array(
  1120. 'ID' => $post_id,
  1121. 'post_status' => isset( $form_settings['post_status'] ) ? $form_settings['post_status'] : 'publish'
  1122. ));
  1123. echo "<div class='wpuf-success' style='text-align:center'>" . __( 'Email successfully verified. Please Login.', 'wpuf' ) ."</div>";
  1124. }
  1125.  
  1126. }
  1127. }
  1128. }
  1129.  
  1130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement