Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
896 changes: 895 additions & 1 deletion assets/css/admin/form-builder.css

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions assets/js/wpuf-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,74 @@ jQuery(function($) {
$('.wpuf-fields input[type="radio"][name="_downloadable"][value="no"]').prop('checked', true);
}
});

// AI Provider change event listener to filter AI Models
$('#wpuf_ai\\[ai_provider\\]').on('change', function() {
var selectedProvider = $(this).val();
var aiModelSelect = $('#wpuf_ai\\[ai_model\\]');
var $this = $(this);

// If no provider selected, show all models
if (!selectedProvider) {
// Restore all options if stored
if (aiModelSelect.data('all-options')) {
aiModelSelect.empty().append(aiModelSelect.data('all-options'));
}
return;
}

// Store all options for restoration if needed
if (!aiModelSelect.data('all-options')) {
aiModelSelect.data('all-options', aiModelSelect.find('option').clone());
}

// Get provider configuration via AJAX
$.ajax({
url: wpuf_admin_script.ajaxurl,
type: 'POST',
data: {
action: 'wpuf_get_ai_provider_configs',
nonce: wpuf_admin_script.nonce
},
success: function(response) {
if (response.success && response.data) {
var providerConfigs = response.data;
var selectedProviderConfig = providerConfigs[selectedProvider];

if (selectedProviderConfig && selectedProviderConfig.models) {
// Clear current options
aiModelSelect.empty();

// Add default option
aiModelSelect.append('<option value="">Select AI Model</option>');

// Add models for the selected provider
$.each(selectedProviderConfig.models, function(modelKey, modelName) {
aiModelSelect.append('<option value="' + modelKey + '">' + modelName + '</option>');
});

// Try to preserve current selection if it's valid for the selected provider
var currentDbValue = aiModelSelect.attr('data-current-value') || aiModelSelect.val();
if (currentDbValue && selectedProviderConfig.models[currentDbValue]) {
aiModelSelect.val(currentDbValue);
} else {
// Set first available model as default
var firstModelKey = Object.keys(selectedProviderConfig.models)[0];
if (firstModelKey) {
aiModelSelect.val(firstModelKey);
}
}
}
} else {
console.error('Failed to load AI provider configurations');
}
},
error: function() {
console.error('AJAX error loading AI provider configurations');
}
});
});

// Trigger change event on page load to filter models based on pre-selected provider
$('#wpuf_ai\\[ai_provider\\]').trigger('change');
});
7 changes: 1 addition & 6 deletions includes/Admin/Posting.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,6 @@ public function render_form( $form_id, $post_id = null ) {
if ( typeof wpuf_map_items === 'undefined' ) {
wpuf_map_items = [];
}

// Test if field initialization script is loaded
console.log('Admin metabox script loaded');
console.log('WPUF_Field_Initializer available:', typeof WPUF_Field_Initializer !== 'undefined');
</script>

<?php
Expand Down Expand Up @@ -692,10 +688,9 @@ public function scripts_styles() {
// Initialize fields after the form is rendered with a delay to ensure DOM is ready
setTimeout(function() {
if (typeof WPUF_Field_Initializer !== 'undefined') {
console.log('Calling WPUF_Field_Initializer.init() from admin metabox');
WPUF_Field_Initializer.init();
} else {
console.log('WPUF_Field_Initializer is not defined');
// console.log('WPUF_Field_Initializer is not defined');
}
}, 500);
});
Expand Down
1 change: 1 addition & 0 deletions includes/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function __construct() {
$this->register_ajax( 'wpuf_ajax_address', 'wpuf_ajax_get_states_field' );
$this->register_ajax( 'wpuf_update_billing_address', 'wpuf_update_billing_address' );
$this->register_ajax( 'wpuf_clear_schedule_lock', 'wpuf_clear_schedule_lock', $this->logged_in_only );
$this->register_ajax( 'wpuf_get_ai_provider_configs', 'wpuf_get_ai_provider_configs_ajax', $this->logged_in_only );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/class-frontend-render-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ public function render_featured_field( $post_id = null ) {
<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(
<span class="wpuf-items-table-containermessage-box" id="remaining-feature-item"> <?php echo sprintf(
// translators: %1$s is Post type and %2$s is total feature item
wp_kses_post(__( 'Mark the %1$s as featured (remaining %2$d)', 'wp-user-frontend' ), esc_html ($this->form_settings['post_type'] ), esc_html( $user_sub['total_feature_item'] ) )); ?></span>
</label>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix fatal sprintf/escaping misuse and broken selector for counter.

  • wp_kses_post() is called with extra args (PHP ArgumentCountError). Also, sprintf args are passed to wp_kses_post instead of sprintf.
  • The counter selector in JS looks for .wpuf-message-box, but the span has class="wpuf-items-table-containermessage-box" → the live counter won’t update.

Apply this diff to fix both issues and harden types:

-                         <span class="wpuf-items-table-containermessage-box" id="remaining-feature-item"> <?php echo sprintf(
-                            // translators: %1$s is Post type and %2$s is total feature item
-                            wp_kses_post(__( 'Mark the %1$s as featured (remaining %2$d)', 'wp-user-frontend' ), esc_html ($this->form_settings['post_type'] ), esc_html( $user_sub['total_feature_item'] ) )); ?></span>
+                         <span class="wpuf-message-box" id="remaining-feature-item">
+                             <?php
+                             // translators: %1$s is Post type and %2$d is total feature item
+                             printf(
+                                 esc_html__( 'Mark the %1$s as featured (remaining %2$d)', 'wp-user-frontend' ),
+                                 esc_html( $this->form_settings['post_type'] ),
+                                 absint( $user_sub['total_feature_item'] )
+                             );
+                             ?>
+                         </span>
📝 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
<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(
<span class="wpuf-items-table-containermessage-box" id="remaining-feature-item"> <?php echo sprintf(
// translators: %1$s is Post type and %2$s is total feature item
wp_kses_post(__( 'Mark the %1$s as featured (remaining %2$d)', 'wp-user-frontend' ), esc_html ($this->form_settings['post_type'] ), esc_html( $user_sub['total_feature_item'] ) )); ?></span>
</label>
<input
type="checkbox"
class="wpuf_is_featured"
name="is_featured_item"
value="1"
<?php echo $is_featured ? 'checked' : ''; ?>
>
<span class="wpuf-message-box" id="remaining-feature-item">
<?php
// translators: %1$s is Post type and %2$d is total feature item
printf(
esc_html__( 'Mark the %1$s as featured (remaining %2$d)', 'wp-user-frontend' ),
esc_html( $this->form_settings['post_type'] ),
absint( $user_sub['total_feature_item'] )
);
?>
</span>
</label>

Expand Down
32 changes: 32 additions & 0 deletions includes/functions/settings-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
'title' => __( 'Privacy Options', 'wp-user-frontend' ),
'icon' => 'dashicons-shield-alt',
],
[
'id' => 'wpuf_ai',
'title' => __( 'AI Settings', 'wp-user-frontend' ),
'icon' => 'dashicons-admin-network',
],
];

return apply_filters( 'wpuf_settings_sections', $sections );
Expand Down Expand Up @@ -82,7 +87,7 @@
}

$settings_fields = [
'wpuf_general' => apply_filters( 'wpuf_options_others', [

Check failure on line 90 in includes/functions/settings-options.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
[
'name' => 'show_admin_bar',
'label' => __( 'Show Admin Bar', 'wp-user-frontend' ),
Expand All @@ -99,8 +104,8 @@
[
'name' => 'admin_access',
'label' => __( 'Admin area access', 'wp-user-frontend' ),
'desc' => __( 'Allow you to block specific user role to Ajax request and Media upload.',

Check failure on line 107 in includes/functions/settings-options.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
'wp-user-frontend' ),

Check failure on line 108 in includes/functions/settings-options.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 108 in includes/functions/settings-options.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Multi-line function call not indented correctly; expected 16 spaces but found 33

Check warning on line 108 in includes/functions/settings-options.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
'type' => 'select',
'default' => 'read',
'options' => [
Expand All @@ -114,8 +119,8 @@
[
'name' => 'override_editlink',
'label' => __( 'Override the post edit link', 'wp-user-frontend' ),
'desc' => __( 'Users see the edit link in post if s/he is capable to edit the post/page. Selecting <strong>Yes</strong> will override the default WordPress edit post link in frontend',

Check failure on line 122 in includes/functions/settings-options.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
'wp-user-frontend' ),

Check failure on line 123 in includes/functions/settings-options.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 123 in includes/functions/settings-options.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Multi-line function call not indented correctly; expected 16 spaces but found 33

Check warning on line 123 in includes/functions/settings-options.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
'type' => 'select',
'default' => 'no',
'options' => [
Expand Down Expand Up @@ -156,8 +161,8 @@
[
'name' => 'recaptcha_private',
'label' => __( 'reCAPTCHA Secret Key', 'wp-user-frontend' ),
'desc' => __( '<a target="_blank" href="https://www.google.com/recaptcha/">Register here</a> to get reCaptcha Site and Secret keys.',

Check failure on line 164 in includes/functions/settings-options.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
'wp-user-frontend' ),

Check failure on line 165 in includes/functions/settings-options.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 165 in includes/functions/settings-options.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Multi-line function call not indented correctly; expected 16 spaces but found 31

Check warning on line 165 in includes/functions/settings-options.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 3 spaces.
],
[
'name' => 'enable_turnstile',
Expand Down Expand Up @@ -186,7 +191,7 @@
'name' => 'custom_css',
'label' => __( 'Custom CSS codes', 'wp-user-frontend' ),
'desc' => __( 'If you want to add your custom CSS code, it will be added on page header wrapped with style tag',
'wp-user-frontend' ),

Check warning on line 194 in includes/functions/settings-options.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 3 spaces.
'type' => 'textarea',
],
] ),
Expand All @@ -202,7 +207,7 @@
'name' => 'default_post_owner',
'label' => __( 'Default Post Owner', 'wp-user-frontend' ),
'desc' => __( 'If guest post is enabled and user details are OFF, the posts are assigned to this user',
'wp-user-frontend' ),

Check warning on line 210 in includes/functions/settings-options.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
'type' => 'select',
'options' => $users,
'default' => '1',
Expand All @@ -218,7 +223,7 @@
'name' => 'insert_photo_size',
'label' => __( 'Insert Photo image size', 'wp-user-frontend' ),
'desc' => __( 'Default image size of "<strong>Insert Photo</strong>" button in post content area',
'wp-user-frontend' ),

Check warning on line 226 in includes/functions/settings-options.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
'type' => 'select',
'options' => wpuf_get_image_sizes(),
'default' => 'thumbnail',
Expand All @@ -227,7 +232,7 @@
'name' => 'insert_photo_type',
'label' => __( 'Insert Photo image type', 'wp-user-frontend' ),
'desc' => __( 'Default image type of "<strong>Insert Photo</strong>" button in post content area',
'wp-user-frontend' ),

Check warning on line 235 in includes/functions/settings-options.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
'type' => 'select',
'options' => [
'image' => __( 'Image only', 'wp-user-frontend' ),
Expand All @@ -239,7 +244,7 @@
'name' => 'image_caption',
'label' => __( 'Enable Image Caption', 'wp-user-frontend' ),
'desc' => __( 'Allow users to update image/video title, caption and description',
'wp-user-frontend' ),

Check warning on line 247 in includes/functions/settings-options.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
'type' => 'checkbox',
'default' => 'off',
],
Expand Down Expand Up @@ -340,7 +345,7 @@
'name' => 'account_page',
'label' => __( 'Account Page', 'wp-user-frontend' ),
'desc' => __( 'Select the page which contains <code>[wpuf_account]</code> shortcode',
'wp-user-frontend' ),

Check warning on line 348 in includes/functions/settings-options.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
'type' => 'select',
'options' => $pages,
],
Expand All @@ -355,7 +360,7 @@
'name' => 'account_page_active_tab',
'label' => __( 'Active Tab', 'wp-user-frontend' ),
'desc' => __( 'Which tab should be set as active by default when opening the account page',
'wp-user-frontend' ),

Check warning on line 363 in includes/functions/settings-options.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
'type' => 'select',
'options' => wpuf_get_account_sections_list(),
],
Expand Down Expand Up @@ -632,6 +637,33 @@
'options' => $post_types,
],
] ),
'wpuf_ai' => apply_filters( 'wpuf_ai_options', [
[
'name' => 'ai_provider',
'label' => __( 'AI Provider', 'wp-user-frontend' ),
'desc' => __( 'Select the AI service provider you want to use.', 'wp-user-frontend' ),
'type' => 'select',
'options' => wpuf_get_ai_provider_options(),
'default' => 'openai',
'class' => 'ai-provider-select',
],
[
'name' => 'ai_model',
'label' => __( 'AI Model', 'wp-user-frontend' ),
'desc' => __( 'Select the AI model to use for content generation.', 'wp-user-frontend' ),
'type' => 'select',
'options' => wpuf_get_ai_model_options(),
'default' => 'gpt-3.5-turbo',
'class' => 'ai-model-select',
],
[
'name' => 'ai_api_key',
'label' => __( 'API Key', 'wp-user-frontend' ),
'desc' => __( 'Enter your AI service API key. Keep this secure and never share it publicly.', 'wp-user-frontend' ),
'type' => 'text',
'default' => '',
],
] ),
];

return apply_filters( 'wpuf_settings_fields', $settings_fields );
Expand Down
Loading
Loading