Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: post description image for block theme #1490

Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 21 additions & 0 deletions includes/Fields/Form_Field_Post_Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ public function __construct() {
$this->name = __( 'Post Content', 'wp-user-frontend' );
$this->input_type = 'post_content';
$this->icon = 'text-width';

// check if block theme is active
if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
add_filter( 'format_for_editor', [ $this, 'format_for_editor' ], 10, 2 );
}
}

/**
* Format the content for editor. Need to do this for block theme support
*
* @param string $content
* @param string $default_editor
*
* @return string
*/
public function format_for_editor( $content, $default_editor ) {
if ( 'tinymce' !== $default_editor ) {
return $content;
}

return htmlspecialchars_decode( $content, ENT_NOQUOTES );
}

/**
Expand Down
13 changes: 9 additions & 4 deletions includes/Frontend/Frontend_Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function __construct() {
*
* @param array $atts
*
* @return
**/
* @return false|string
*/
Comment on lines +36 to +37
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding a return type declaration to the method.

The docblock specifies @return false|string, but the method signature does not include the return type declaration. Adding the return type enhances type safety and keeps the code consistent with modern PHP practices.

Apply this diff to include the return type declaration:

 public function edit_post_shortcode( $atts )
+ : false|string {

Committable suggestion was skipped due to low confidence.

public function edit_post_shortcode( $atts ) {
add_filter( 'wpuf_form_fields', [ $this, 'add_field_settings' ] );
// @codingStandardsIgnoreStart
Expand All @@ -52,7 +52,13 @@ public function edit_post_shortcode( $atts ) {

wp_login_form();

return;
return '';
}

$nonce = isset( $_GET['_wpnonce'] ) ? sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ) : '';

if ( ! wp_verify_nonce( $nonce, 'wpuf_edit' ) ) {
return '<div class="wpuf-info">' . __( 'Please re-open the post', 'wp-user-frontend' ) . '</div>';
Comment on lines +58 to +61
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Use sanitize_text_field for proper nonce sanitization.

Using sanitize_key may alter the nonce value and cause verification to fail. To preserve the integrity of the nonce, consider using sanitize_text_field instead.

Apply this diff to fix the sanitization:

 $nonce = isset( $_GET['_wpnonce'] ) ? 
-    sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ) : '';
+    sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ) : '';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$nonce = isset( $_GET['_wpnonce'] ) ? sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ) : '';
if ( ! wp_verify_nonce( $nonce, 'wpuf_edit' ) ) {
return '<div class="wpuf-info">' . __( 'Please re-open the post', 'wp-user-frontend' ) . '</div>';
$nonce = isset( $_GET['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ) : '';
if ( ! wp_verify_nonce( $nonce, 'wpuf_edit' ) ) {
return '<div class="wpuf-info">' . __( 'Please re-open the post', 'wp-user-frontend' ) . '</div>';

}

$post_id = isset( $_GET['pid'] ) ? intval( wp_unslash( $_GET['pid'] ) ) : 0;
Expand Down Expand Up @@ -110,7 +116,6 @@ public function edit_post_shortcode( $atts ) {
$form = new Form( $form_id );

$this->form_fields = $form->get_fields();
// $form_settings = wpuf_get_form_settings( $form_id );
$this->form_settings = $form->get_settings();

$disable_pending_edit = wpuf_get_option( 'disable_pending_edit', 'wpuf_dashboard', 'on' );
Expand Down
6 changes: 3 additions & 3 deletions includes/Frontend_Render_Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use WeDevs\Wpuf\Admin\Subscription;

class Frontend_Render_Form {
private static $_instance;

Check warning on line 8 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Property name "$_instance" should not be prefixed with an underscore to indicate visibility

public static $meta_key = 'wpuf_form';

Expand All @@ -27,7 +27,7 @@
* @param string $error
*/
public function send_error( $error ) {
echo json_encode(

Check warning on line 30 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

json_encode() is discouraged. Use wp_json_encode() instead.
[
'success' => false,
'error' => $error,
Expand All @@ -39,13 +39,13 @@


/**
* render submit button

Check failure on line 42 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Doc comment short description must start with a capital letter
*
* @param [type] $form_id [description]
* @param [type] $form_settings [description]
* @param [type] $post_id [description]
*/
public function submit_button( $form_id, $form_settings, $post_id = null ) { ?>

Check failure on line 48 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Opening brace must be the last content on the line

<li class="wpuf-submit">
<div class="wpuf-label">
Expand Down Expand Up @@ -75,7 +75,7 @@
<input type="submit" class="wpuf-submit-button wpuf_submit_<?php echo esc_attr( $form_id ); ?>" name="submit" value="<?php echo esc_attr( $form_settings['submit_text'] ); ?>" />
<?php } ?>

<?php if ( isset( $form_settings['draft_post'] ) && $form_settings['draft_post'] == 'true' ) { ?>

Check warning on line 78 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="
<a href="#" class="btn" id="wpuf-post-draft"><?php esc_html_e( 'Save Draft', 'wp-user-frontend' ); ?></a>
<?php } ?>
</li>
Expand All @@ -84,7 +84,7 @@
}

/**
* guest post field

Check failure on line 87 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Doc comment short description must start with a capital letter
*
* @param [type] $form_settings [description]
*/
Expand Down Expand Up @@ -118,7 +118,7 @@
* @return void
*/
public function preview_form() {
$form_id = isset( $_GET['form_id'] ) ? intval( wp_unslash( $_GET['form_id'] ) ) : 0;

Check warning on line 121 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.

Check warning on line 121 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.

if ( $form_id ) {
?>
Expand All @@ -128,7 +128,7 @@
<head>
<meta charset="UTF-8">
<title>__( 'Form Preview', 'wp-user-frontend' )</title>
<link rel="stylesheet" href="<?php echo esc_url( plugins_url( 'assets/css/frontend-forms.css', __DIR__ ) ); ?>">

Check failure on line 131 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Stylesheets must be registered/enqueued via wp_enqueue_style()

<style type="text/css">
body {
Expand All @@ -149,7 +149,7 @@
}
</style>

<script type="text/javascript" src="<?php echo esc_url( includes_url( 'js/jquery/jquery.js' ) ); ?>"></script>

Check failure on line 152 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Scripts must be registered/enqueued via wp_enqueue_script()
</head>
<body>
<div class="container">
Expand All @@ -167,7 +167,7 @@
}

/**
* render form

Check failure on line 170 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Doc comment short description must start with a capital letter
*
* @param [type] $form_id [description]
* @param [type] $post_id [description]
Expand All @@ -183,7 +183,7 @@
return;
}

if ( $form_status != 'publish' ) {
if ( 'publish' !== $form_status ) {
echo wp_kses_post( '<div class="wpuf-message">' . __( "Please make sure you've published your form.", 'wp-user-frontend' ) . '</div>' );

return;
Expand Down Expand Up @@ -222,9 +222,9 @@
if ( $this->form_fields ) {
?>

<form class="wpuf-form-add wpuf-form-<?php echo esc_attr( $layout ); ?> <?php echo ( $layout == 'layout1' ) ? esc_html( $theme_css ) : 'wpuf-style'; ?>" action="" method="post">
<form class="wpuf-form-add wpuf-form-<?php echo esc_attr( $layout ); ?> <?php echo ( 'layout1' === $layout ) ? esc_html( $theme_css ) : 'wpuf-style'; ?>" action="" method="post">

<script type="text/javascript">
<script type="text/javascript">
if ( typeof wpuf_conditional_items === 'undefined' ) {
wpuf_conditional_items = [];
}
Expand All @@ -250,7 +250,7 @@
do_action( 'wpuf_edit_post_form_top', $form_id, $post_id, $this->form_settings );
}

if ( ! is_user_logged_in() && $this->form_settings['guest_post'] == 'true' && $this->form_settings['guest_details'] == 'true' ) {

Check warning on line 253 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="

Check warning on line 253 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="
$this->guest_fields( $this->form_settings );
}

Expand Down Expand Up @@ -300,8 +300,8 @@
</div>
<div >
<label >
<input type="checkbox" class="wpuf_is_featured" name="is_featured_item" value="1" <?php echo $is_featured ? 'checked' : ''; ?> >

Check warning on line 303 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
<span class="wpuf-items-table-containermessage-box" id="remaining-feature-item"> <?php echo sprintf( __( 'Mark the %s as featured (remaining %d)', 'wp-user-frontend' ), $post_type, $featured_item ); ?></span>

Check warning on line 304 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.

Check failure on line 304 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Unnecessary "echo sprintf(...)" found. Use "printf(...)" instead.

Check failure on line 304 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

A function call to __() with texts containing placeholders was found, but was not accompanied by a "translators:" comment on the line above to clarify the meaning of the placeholders.

Check failure on line 304 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Multiple placeholders in translatable strings should be ordered. Expected "%1$s, %2$d", but got "%s, %d" in 'Mark the %s as featured (remaining %d)'.
</label>
</div>
</li>
Expand All @@ -323,7 +323,7 @@
}

/**
* get Input fields

Check failure on line 326 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Doc comment short description must start with a capital letter
*
* @param array $form_vars
*
Expand All @@ -335,7 +335,7 @@

foreach ( $form_vars as $key => $value ) {
// get column field input fields
if ( $value['input_type'] == 'column_field' ) {

Check warning on line 338 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="
$inner_fields = $value['inner_fields'];

foreach ( $inner_fields as $column_key => $column_fields ) {
Expand Down
Loading