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: integrations not loading properly #1486

Merged
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
4 changes: 4 additions & 0 deletions includes/Ajax/Frontend_Form_Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class Frontend_Form_Ajax {
private $expired_post_status = 'wpuf-expired_post_status';

private $post_expiration_message = 'wpuf-post_expiration_message';
/**
* @var array
*/
private $form_fields;

/**
* New/Edit post submit handler
Expand Down
5 changes: 1 addition & 4 deletions includes/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
|| wpuf_has_shortcode( 'weforms' )
|| wpuf_has_shortcode( 'wpuf_account' )
|| wpuf_has_shortcode( 'wpuf_sub_pack' )
|| ( isset( $post->ID ) && ( $pay_page == $post->ID ) )

Check warning on line 54 in includes/Frontend.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="
|| isset( $_GET['wpuf_preview'] )

Check warning on line 55 in includes/Frontend.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.
|| class_exists( '\Elementor\Plugin' )
|| $this->dokan_is_seller_dashboard() ) {
wp_enqueue_style( 'wpuf-layout1' );
Expand Down Expand Up @@ -180,12 +180,9 @@
private function dokan_is_seller_dashboard() {
return class_exists( 'WeDevs_Dokan' )
&& function_exists( 'dokan_is_seller_dashboard' )
&& dokan_is_seller_dashboard()
&& ! empty( $wp->query_vars['posts'] );
&& dokan_is_seller_dashboard();
}



/**
* Show/hide admin bar to the permitted user level
*
Expand All @@ -203,7 +200,7 @@
$current_user = wp_get_current_user();

if ( ! empty( $current_user->roles ) && ! empty( $current_user->roles[0] ) ) {
if ( ! in_array( $current_user->roles[0], $roles ) ) {

Check failure on line 203 in includes/Frontend.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Not using strict comparison for in_array; supply true for $strict argument.
return false;
}
}
Expand Down
1 change: 0 additions & 1 deletion 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' ) {

Check warning on line 186 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "!=="; Found: "!="
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,10 +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">

Check warning on line 225 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

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


<script type="text/javascript">

Check warning on line 227 in includes/Frontend_Render_Form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 3 spaces.
if ( typeof wpuf_conditional_items === 'undefined' ) {
wpuf_conditional_items = [];
}
Expand Down Expand Up @@ -302,7 +301,7 @@
<div >
<label >
<input type="checkbox" class="wpuf_is_featured" name="is_featured_item" value="1" <?php echo $is_featured ? 'checked' : ''; ?> >
<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 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 Down
56 changes: 56 additions & 0 deletions includes/Integrations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace WeDevs\Wpuf;

/**
* The integration class to handle all integrations with our plugin
*
* @since WPUF_SINCE
*/
class Integrations {
/**
* Holds various class instances
*
* @since WPUF_SINCE
*
* @var array
*/
public $container = [];

private $integrations = [
'WeDevs_Dokan' => 'WPUF_Dokan_Integration',
'WC_Vendors' => 'WPUF_WC_Vendors_Integration',
'WCMp' => 'WPUF_WCMp_Integration',
'ACF' => 'WPUF_ACF_Compatibility',
];

public function __construct() {
foreach ( $this->integrations as $external_class => $integration_class ) {
if ( class_exists( $external_class ) ) {
$full_class_name = __NAMESPACE__ . '\\Integrations\\' . $integration_class;
try {
$this->container[ strtolower( $external_class ) ] = new $full_class_name();
} catch ( \Exception $e ) {
\WP_User_Frontend::log( 'integration', print_r( $external_class . ' integration failed', true ) );
}
}
}
}

/**
* Magic getter to bypass referencing objects
*
* @since WPUF_SINCE
*
* @param string $prop
*
* @return null|object Class Instance
*/
public function __get( $prop ) {
if ( array_key_exists( $prop, $this->container ) ) {
return $this->container[ $prop ];
}

return null;
}
}
Comment on lines +1 to +56
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 methods for enhanced flexibility and utility.

While the current implementation is solid, consider the following enhancements:

  1. Add methods to dynamically add or remove integrations at runtime.
  2. Implement a method to check if a specific integration is available.

These additions would further improve the flexibility and utility of the Integrations class.

Here's a potential implementation:

public function addIntegration($externalClass, $integrationClass) {
    $this->integrations[$externalClass] = $integrationClass;
    // Attempt to initialize the new integration if the external class exists
    if (class_exists($externalClass)) {
        $fullClassName = __NAMESPACE__ . '\\Integrations\\' . $integrationClass;
        try {
            $this->container[strtolower($externalClass)] = new $fullClassName();
        } catch (\Exception $e) {
            \WP_User_Frontend::log('integration', print_r($externalClass . ' integration failed', true));
        }
    }
}

public function removeIntegration($externalClass) {
    unset($this->integrations[$externalClass]);
    unset($this->container[strtolower($externalClass)]);
}

public function hasIntegration($externalClass) {
    return isset($this->container[strtolower($externalClass)]);
}

3 changes: 1 addition & 2 deletions templates/dokan/new-post.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

$access = dokan_get_option( 'allow_wpuf_post', 'dokan_general' );
$access = dokan_get_option( 'allow_wpuf_post', 'dokan_general' );
$selected_form = dokan_get_option( 'wpuf_post_forms', 'dokan_general' );

if ( $access != 'on' ) {
Expand Down
1 change: 1 addition & 0 deletions wpuf.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public function instantiate() {
$this->container['bank'] = new WeDevs\Wpuf\Lib\Gateway\Bank();
$this->container['paypal'] = new WeDevs\Wpuf\Lib\Gateway\Paypal();
$this->container['api'] = new WeDevs\Wpuf\API();
$this->container['integrations'] = new WeDevs\Wpuf\Integrations();
sapayth marked this conversation as resolved.
Show resolved Hide resolved

if ( is_admin() ) {
$this->container['admin'] = new WeDevs\Wpuf\Admin();
Expand Down
Loading