Skip to content

Commit

Permalink
Merge pull request #1435 from sapayth/fix/subscription_posting_restri…
Browse files Browse the repository at this point in the history
…ction_not_working

fix: subscription posting restriction not working
  • Loading branch information
sapayth authored Feb 9, 2024
2 parents 09f923c + d07eaa1 commit 995cc8c
Show file tree
Hide file tree
Showing 15 changed files with 6,225 additions and 8,095 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<?php

if ( class_exists( 'WPUF_Subscription' ) ) {
$subscriptions = (new \WeDevs\Wpuf\Admin\Subscription())->get_subscriptions();
$subscriptions = wpuf()->subscription->get_subscriptions();

if ( $subscriptions ) {
foreach ( $subscriptions as $pack ) {
Expand Down
2 changes: 1 addition & 1 deletion assets/js-templates/form-components.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ class="option-chooser-radio"
<?php

if ( class_exists( 'WPUF_Subscription' ) ) {
$subscriptions = (new \WeDevs\Wpuf\Admin\Subscription())->get_subscriptions();
$subscriptions = wpuf()->subscription->get_subscriptions();

if ( $subscriptions ) {
foreach ( $subscriptions as $pack ) {
Expand Down
2 changes: 1 addition & 1 deletion class/subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct() {
add_filter( 'wpuf_add_post_redirect', [ $this, 'post_redirect' ], 10, 4 );

add_filter( 'wpuf_addpost_notice', [ $this, 'force_pack_notice' ], 20, 3 );
add_filter( 'wpuf_can_post', [ $this, 'force_pack_permission' ], 20, 3 );
// add_filter( 'wpuf_can_post', [ $this, 'force_pack_permission' ], 20, 3 );
add_action( 'wpuf_add_post_form_top', [ $this, 'add_post_info' ], 10, 2 );

add_action( 'wpuf_add_post_after_insert', [ $this, 'monitor_new_post' ], 10, 3 );
Expand Down
1 change: 0 additions & 1 deletion includes/Admin/Forms/Field_Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use WeDevs\Wpuf\Fields\Form_Field_Image;
use WeDevs\Wpuf\Fields\Form_Field_MultiDropdown;
use WeDevs\Wpuf\Fields\Form_Field_Post_Content;
use WeDevs\Wpuf\Fields\Form_Field_Post_Excerpt;
use WeDevs\Wpuf\Fields\Form_Field_Post_Tags;
use WeDevs\Wpuf\Fields\Form_Field_Post_Taxonomy;
use WeDevs\Wpuf\Fields\Form_Field_Post_Title;
Expand Down
17 changes: 14 additions & 3 deletions includes/Admin/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,26 @@ public function is_submission_open( $form, $form_settings ) {
if ( isset( $this->form_settings['message_restrict'] ) && ! $guest_post_enabled && ! is_user_logged_in() ) {
$user_can_post = 'no';
$info = $this->form_settings['message_restrict'];

return [ $user_can_post, $info ];
}

$has_post_count = $current_user->subscription()->has_post_count( $form_settings['post_type'] );

if ( ! $has_post_count ) {
$user_can_post = 'no';
$info = __( 'Post Limit Exceeded for your purchased subscription pack.', 'wp-user-frontend' );

return [ $user_can_post, $info ];
}


if ( $this->is_charging_enabled() ) {
$pay_per_post = $this->is_enabled_pay_per_post();
$pay_per_post_cost = (float) $this->get_pay_per_post_cost();
// $pay_per_post_cost = (float) $this->get_pay_per_post_cost();
$force_pack = $this->is_enabled_force_pack();
$fallback_enabled = $this->is_enabled_fallback_cost();
$fallback_cost = $this->get_subs_fallback_cost();
$has_post_count = $current_user->subscription()->has_post_count( $form_settings['post_type'] );
// $fallback_cost = $this->get_subs_fallback_cost();

// guest post payment checking
if ( ! is_user_logged_in() && isset( $form_settings['guest_post'] ) && $form_settings['guest_post'] === 'true' ) {
Expand Down
10 changes: 8 additions & 2 deletions includes/Admin/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __construct() {
add_action( 'wpuf_add_post_form_top', [ $this, 'add_post_info' ], 10, 2 );

add_action( 'wpuf_add_post_after_insert', [ $this, 'monitor_new_post' ], 10, 3 );
add_action( 'wpuf_add_post_after_insert', [ $this, 'reset_user_subscription_data' ], 10, 4 );
add_action( 'wpuf_draft_post_after_insert', [ $this, 'monitor_new_draft_post' ], 10, 3 );
add_action( 'wpuf_payment_received', [ $this, 'payment_received' ], 10, 2 );

Expand Down Expand Up @@ -63,7 +64,7 @@ public static function subscriber_cancel( $user_id, $pack_id ) {
);
$result = $wpdb->get_row( $sql );

$transaction_id = $result ? $result->transaction_id : 0;
$transaction_id = $result ? $result->transaction_id : 'Free';

$wpdb->update(
$wpdb->prefix . 'wpuf_subscribers', [ 'subscribtion_status' => 'cancel' ], [
Expand Down Expand Up @@ -531,7 +532,8 @@ public function set_pending( $postdata, $form_id, $form_settings, $form_vars ) {
* @param int $post_id
*/
public function monitor_new_post( $post_id, $form_id, $form_settings ) {
global $wpdb, $userdata;
global $userdata;

$post = get_post( $post_id );

// bail out if charging is not enabled
Expand Down Expand Up @@ -1108,6 +1110,10 @@ public function force_pack_permission( $perm, $id, $form_settings ) {
$current_pack = $current_user->subscription()->current_pack();
$has_post_count = isset( $form_settings['post_type'] ) ? $current_user->subscription()->has_post_count( $form_settings['post_type'] ) : false;

if ( !$has_post_count ) {
return 'no';
}

if ( is_user_logged_in() ) {
if ( wpuf_get_user()->post_locked() ) {
return 'no';
Expand Down
16 changes: 0 additions & 16 deletions includes/Ajax/Frontend_Form_Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,6 @@ public function submit_post() {
}
}

// check each form field for restricted shortcodes
foreach ( $this->form_fields as $single_field ) {
if ( empty( $single_field['rich'] ) || 'yes' !== $single_field['rich'] ) {
continue;
}

$current_data = ! empty( $_POST[ $single_field['name'] ] ) ? sanitize_textarea_field( wp_unslash( $_POST[ $single_field['name'] ] ) ) : '';

foreach ( $protected_shortcodes as $shortcode ) {
$search_for = '[' . $shortcode;
if ( strpos( $current_data, $search_for ) !== false ) {
wpuf()->ajax->send_error( sprintf( __( 'Using %s as shortcode is restricted', 'wp-user-frontend' ), $shortcode ) );
}
}
}

foreach ( $attachments_to_delete as $attach_id ) {
wp_delete_attachment( $attach_id, true );
}
Expand Down
10 changes: 9 additions & 1 deletion includes/Frontend/Frontend_Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,15 @@ public function subscription_section( $sections, $current_section ) {

return;
}
$pack = Subscription::get_subscription( $sub_id );
$pack = wpuf()->subscription->get_subscription( $sub_id );

if ( ! $pack ) {
echo wp_kses_post( sprintf( __( '%sYour subscription pack is not exists. Please contact admin.%s', 'wp-user-frontend' ), '<p>', '</p>' ) );

return;
}


$details_meta['payment_page'] = get_permalink( wpuf_get_option( 'payment_page', 'wpuf_payment' ) );
$details_meta['onclick'] = '';
$details_meta['symbol'] = wpuf_get_currency( 'symbol' );
Expand Down
2 changes: 1 addition & 1 deletion includes/Frontend/Frontend_Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function add_post_shortcode( $atts ) {
$this->form_fields = $form->get_fields();
$this->form_settings = $form->get_settings();
$this->generate_auth_link(); // Translate tag %login% %registration% to login registartion url
[ $user_can_post, $info ] = $form->is_submission_open( $form, $this->form_settings );
[ $user_can_post, $info ] = $form->is_submission_open( $form, $this->form_settings );
$info = apply_filters( 'wpuf_addpost_notice', $info, $id, $this->form_settings );
$user_can_post = apply_filters( 'wpuf_can_post', $user_can_post, $id, $this->form_settings );

Expand Down
2 changes: 1 addition & 1 deletion includes/Frontend/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function payment_page( $content ) {
$pack_id = isset( $_REQUEST['pack_id'] ) ? intval( wp_unslash( $_REQUEST['pack_id'] ) ) : 0;
$is_free = false;
if ( $pack_id ) {
$pack_detail = Admin\Subscription::get_subscription( $pack_id );
$pack_detail = wpuf()->subscription->get_subscription( $pack_id );
if ( ! $pack_detail ) {
?>
<div class="wpuf-info"><?php esc_html_e( 'No subscription pack found.',
Expand Down
6 changes: 0 additions & 6 deletions includes/Frontend_Render_Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
namespace WeDevs\Wpuf;

use WeDevs\Wpuf\Admin\Subscription;
use WeDevs\Wpuf\Fields\Form_Field_Featured_Image;
use WeDevs\Wpuf\Fields\Form_Field_Post_Content;
use WeDevs\Wpuf\Fields\Form_Field_Post_Excerpt;
use WeDevs\Wpuf\Fields\Form_Field_Post_Tags;
use WeDevs\Wpuf\Fields\Form_Field_Post_Taxonomy;
use WeDevs\Wpuf\Fields\Form_Field_Post_Title;

class Frontend_Render_Form {
private static $_instance;
Expand Down
10 changes: 5 additions & 5 deletions includes/User_Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function add_pack( $pack_id, $profile_id, $recurring, $status = null ) {
}
global $wpdb;
$result = '';
$subscription = ( new Admin\Subscription() )->get_subscription( $pack_id );
$subscription = wpuf()->subscription->get_subscription( $pack_id );

if ( $this->user->id && $subscription ) {
$user_meta = [
Expand Down Expand Up @@ -307,9 +307,9 @@ public function pack_info( $form_id ) {
return;
}

$pack = Admin\Subscription::get_subscription( $this->current_pack_id() );
$pack = wpuf()->subscription->get_subscription( $this->current_pack_id() );

$details_meta = Admin\Subscription::init()->get_details_meta_value();
$details_meta = wpuf()->subscription->get_details_meta_value();

$billing_amount = ( intval( $pack->meta_value['billing_amount'] ) > 0 ) ? $details_meta['symbol'] . $pack->meta_value['billing_amount'] : __( 'Free', 'wp-user-frontend' );

Expand Down Expand Up @@ -488,7 +488,7 @@ public function has_error( $form_settings = null ) {
* @return bool
*/
public static function is_free_pack( $pack_id ) {
$subs = new Admin\Subscription();
$subs = wpuf()->subscription;
$pack = $subs->get_subscription( $pack_id );
$billing_amount = ( $pack->meta_value['billing_amount'] >= 0 && ! empty( $pack->meta_value['billing_amount'] ) ) ? $pack->meta_value['billing_amount'] : false;

Expand All @@ -509,7 +509,7 @@ public static function is_free_pack( $pack_id ) {
* @return string
*/
public function get_subscription_exp_msg( $pack_id ) {
$sub_pack = Admin\Subscription::get_subscription( $pack_id );
$sub_pack = wpuf()->subscription->get_subscription( $pack_id );
$sub_info = $this->pack;

$exp_message = ! empty( $sub_pack->meta_value['_post_expiration_message'] ) ? $sub_pack->meta_value['_post_expiration_message'] : $sub_info['_post_expiration_message'];
Expand Down
Loading

0 comments on commit 995cc8c

Please sign in to comment.