Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions includes/Ajax/Frontend_Form_Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public function submit_post() {
check_ajax_referer( 'wpuf_form_add' );
add_filter( 'wpuf_form_fields', [ $this, 'add_field_settings' ] );
@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );

Check warning on line 38 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Silencing errors is strongly discouraged. Use proper error checking instead. Found: @Header( 'Content-Type: application/json; charset=' ...

$form_id = isset( $_POST['form_id'] ) ? intval( wp_unslash( $_POST['form_id'] ) ) : 0;
$form = new Form( $form_id );
Expand Down Expand Up @@ -123,9 +123,9 @@
foreach ( $protected_shortcodes as $shortcode ) {
$search_for = '[' . $shortcode;
if ( strpos( $current_data, $search_for ) !== false ) {
wpuf()->ajax->send_error( sprintf(

Check failure on line 126 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Opening parenthesis of a multi-line function call must be the last content on the line
// translators: %s is shortcode
__( 'Using %s as shortcode is restricted', 'wp-user-frontend' ), $shortcode ) );

Check failure on line 128 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Closing parenthesis of a multi-line function call must be on a line by itself

Check failure on line 128 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Closing parenthesis of a multi-line function call must be on a line by itself

Check failure on line 128 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Multi-line function call not indented correctly; expected 20 spaces but found 24

Check failure on line 128 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Multi-line function call not indented correctly; expected 20 spaces but found 24
}
}
}
Expand Down Expand Up @@ -177,6 +177,24 @@
wpuf()->ajax->send_error( __( 'You must be logged in to submit posts.', 'wp-user-frontend' ) );
}

// Enforce the form's submission gate (mandatory subscription, pack ownership,
// post-count limit) for new posts. The renderer checks this before showing the
// form, but the AJAX handler must re-check server-side — otherwise a scraped
// site-wide guest nonce can be replayed against a subscription-gated form to
// create a post with no order and no pending-payment status.
if ( ! isset( $_POST['post_id'] ) ) {
[ $user_can_post, $submission_info ] = $form->is_submission_open( $form, $this->form_settings );
$user_can_post = apply_filters( 'wpuf_can_post', $user_can_post, $form_id, $this->form_settings );

if ( 'yes' !== $user_can_post ) {
wpuf()->ajax->send_error(
! empty( $submission_info )
? $submission_info
: __( 'You are not allowed to submit to this form.', 'wp-user-frontend' )
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

[ $post_vars, $taxonomy_vars, $meta_vars ] = $this->get_input_fields( $this->form_fields );

if ( ! isset( $_POST['post_id'] ) ) {
Expand All @@ -193,9 +211,9 @@
$this->on_edit_no_check_recaptcha( $post_vars );
}

$is_update = false;

Check warning on line 214 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Equals sign not aligned correctly; expected 1 space but found 11 spaces
// $default_post_author = wpuf_get_option( 'default_post_owner', 'wpuf_frontend_posting', 1 );

Check warning on line 215 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

This comment is 60% valid code; is this commented out code?
$post_author = $this->wpuf_get_post_user();

Check warning on line 216 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Equals sign not aligned correctly; expected 1 space but found 9 spaces

$allowed_tags = wp_kses_allowed_html( 'post' );
$postarr = [
Expand All @@ -207,7 +225,7 @@
'post_excerpt' => isset( $_POST['post_excerpt'] ) ? strip_shortcodes( wp_kses( wp_unslash( $_POST['post_excerpt'] ), $allowed_tags ) ) : '',
];

// $charging_enabled = wpuf_get_option( 'charge_posting', 'wpuf_payment' );

Check warning on line 228 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

This comment is 58% valid code; is this commented out code?
$charging_enabled = '';
$form = new Form( $form_id );
$payment_options = $form->is_charging_enabled();
Expand All @@ -228,7 +246,7 @@
//if date is set and assigned as publish date
if ( isset( $_POST['wpuf_is_publish_time'] ) ) {
if ( ! empty( $_POST[ $_POST['wpuf_is_publish_time'] ] ) ) {
// $postarr['post_date'] = date( 'Y-m-d H:i:s', strtotime( str_replace( array( ':', '/' ), '-', $_POST[$_POST['wpuf_is_publish_time']] ) ) );

Check warning on line 249 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

This comment is 64% valid code; is this commented out code?
$date_time = explode( ' ', sanitize_text_field( wp_unslash( ( $_POST[ $_POST['wpuf_is_publish_time'] ] ) ) ) );

if ( ! empty( $date_time[0] ) ) {
Expand Down Expand Up @@ -303,7 +321,7 @@
if ( 'pending' === get_post_meta( $post_id, '_wpuf_payment_status', true ) ) {
$postarr['post_status'] = 'pending';
}
} else {

Check failure on line 324 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

If control structure block found as the only statement within an "else" block. Use elseif instead.
if ( isset( $this->form_settings['comment_status'] ) ) {
$postarr['comment_status'] = $this->form_settings['comment_status'];
}
Expand Down Expand Up @@ -396,7 +414,7 @@
// find our if any images in post content and associate them
if ( ! empty( $postarr['post_content'] ) ) {
$dom = new DOMDocument();
@$dom->loadHTML( $postarr['post_content'] );

Check warning on line 417 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Silencing errors is strongly discouraged. Use proper error checking instead. Found: @$dom->loadHTML( ...
$images = $dom->getElementsByTagName( 'img' );

if ( $images->length ) {
Expand Down Expand Up @@ -452,7 +470,7 @@
} else {
$redirect_to = get_permalink( $post_id );
}
} else {

Check failure on line 473 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

If control structure block found as the only statement within an "else" block. Use elseif instead.
if ( $this->form_settings['redirect_to'] === 'page' ) {
$redirect_to = get_permalink( $this->form_settings['page_id'] );
} elseif ( $this->form_settings['redirect_to'] === 'url' ) {
Expand All @@ -465,8 +483,8 @@
}

if ( $charging_enabled === 'yes' && isset( $this->form_settings['payment_options'] )
&& 'enable_pay_per_post' === $this->form_settings['payment_options']

Check warning on line 486 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
&& ! $is_update

Check warning on line 487 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
) {
$redirect_to = add_query_arg(
[
Expand Down Expand Up @@ -528,13 +546,13 @@
$to = implode(
',',
array_filter(
array_map( static function ( $addr ) {

Check failure on line 549 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Opening parenthesis of a multi-line function call must be the last content on the line
$addr = trim( $addr );
return is_email( $addr ) ? $addr : null;
}, explode( ',', $to_raw ) )

Check failure on line 552 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Closing parenthesis of a multi-line function call must be on a line by itself
)
);
if ( empty( $to ) ) {

Check failure on line 555 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Empty IF statement detected
// Nothing valid to send to – skip mail sending
} else {
$subject = $this->prepare_mail_body( $edit_subject, $post_author, $post_id );
Expand Down Expand Up @@ -678,7 +696,7 @@

// 3) Very old separate fields (only for edit notifications)
if ( ! $enabled && 'edit' === $type && ! empty( $this->form_settings['notification_' . $type ] )
&& wpuf_is_checkbox_or_toggle_on( $this->form_settings['notification_' . $type ] ) ) {

Check warning on line 699 in includes/Ajax/Frontend_Form_Ajax.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
$enabled = true;
$body = isset( $this->form_settings['notification_' . $type . '_body' ] ) ? $this->form_settings['notification_' . $type . '_body' ] : '';
$to = isset( $this->form_settings['notification_' . $type . '_to' ] ) ? $this->form_settings['notification_' . $type . '_to' ] : '';
Expand Down
Loading