Skip to content
Open
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
873 changes: 871 additions & 2 deletions 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
@@ -1,7 +1,7 @@
<?php

class WPUF_Frontend_Render_Form {
private static $_instance;

Check warning on line 4 in includes/class-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 Down Expand Up @@ -46,11 +46,11 @@
*
* @return array
*/
public function search( $array, $key, $value ) {

Check warning on line 49 in includes/class-frontend-render-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

It is recommended not to use reserved keyword "array" as function parameter name. Found: $array
$results = [];

if ( is_array( $array ) ) {
if ( isset( $array[ $key ] ) && $array[ $key ] == $value ) {

Check warning on line 53 in includes/class-frontend-render-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="
$results[] = $array;
}

Expand Down Expand Up @@ -90,7 +90,7 @@
}

/**
* reCaptcha Validation

Check failure on line 93 in includes/class-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
*
* @return void
*/
Expand All @@ -104,15 +104,15 @@
$remote_addr = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
$g_recaptcha_response = isset( $_POST['g-recaptcha-response'] ) ? sanitize_text_field( wp_unslash( $_POST['g-recaptcha-response'] ) ) : '';

if ( $no_captcha == 1 && 0 == $invisible ) {

Check warning on line 107 in includes/class-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 107 in includes/class-frontend-render-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="
if ( ! class_exists( 'WPUF_ReCaptcha' ) ) {
require_once WPUF_ROOT . '/lib/recaptchalib_noCaptcha.php';
}

$response = null;
$reCaptcha = new WPUF_ReCaptcha( $private_key );

Check failure on line 113 in includes/class-frontend-render-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Variable "$reCaptcha" is not in valid snake_case format, try "$re_captcha"

$resp = $reCaptcha->verifyResponse(

Check failure on line 115 in includes/class-frontend-render-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Variable "$reCaptcha" is not in valid snake_case format, try "$re_captcha"
$remote_addr,
$g_recaptcha_response
);
Expand All @@ -120,7 +120,7 @@
if ( ! $resp->success ) {
$this->send_error( __( 'noCaptcha reCAPTCHA validation failed', 'wp-user-frontend' ) );
}
} elseif ( $no_captcha == 0 && 0 == $invisible ) {

Check warning on line 123 in includes/class-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 123 in includes/class-frontend-render-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="
$recap_challenge = isset( $_POST['recaptcha_challenge_field'] ) ? sanitize_text_field( wp_unslash( $_POST['recaptcha_challenge_field'] ) ) : '';
$recap_response = isset( $_POST['recaptcha_response_field'] ) ? sanitize_text_field( wp_unslash( $_POST['recaptcha_response_field'] ) ) : '';

Expand All @@ -129,27 +129,27 @@
if ( ! $resp->is_valid ) {
$this->send_error( __( 'reCAPTCHA validation failed', 'wp-user-frontend' ) );
}
} elseif ( $no_captcha == 0 && 1 == $invisible ) {

Check warning on line 132 in includes/class-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 132 in includes/class-frontend-render-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="
$response = null;
$recaptcha = isset( $_POST['g-recaptcha-response'] ) ? sanitize_text_field( wp_unslash( $_POST['g-recaptcha-response'] ) ) : '';
$object = new Invisible_Recaptcha( $site_key, $private_key );

$response = $object->verifyResponse( $recaptcha );

if ( isset( $response['success'] ) and $response['success'] != true ) {

Check warning on line 139 in includes/class-frontend-render-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

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

Check failure on line 139 in includes/class-frontend-render-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Logical operator "and" is prohibited; use "&&" instead
$this->send_error( __( 'Invisible reCAPTCHA validation failed', 'wp-user-frontend' ) );
}
}
}

/**
* render submit button

Check failure on line 146 in includes/class-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 152 in includes/class-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 @@ -188,7 +188,7 @@
}

/**
* guest post field

Check failure on line 191 in includes/class-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 @@ -275,7 +275,7 @@
}

/**
* render form

Check failure on line 278 in includes/class-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 Down Expand Up @@ -401,7 +401,7 @@
}

/**
* add post field setting on form builder

Check failure on line 404 in includes/class-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 $field_settings
*/
Expand Down Expand Up @@ -489,7 +489,7 @@
$taxonomies = get_object_taxonomies( $post_type, 'object' );

foreach ( $taxonomies as $tax_name => $taxonomy ) {
if ( ! in_array( $tax_name, $ignore_taxonomies ) ) {

Check failure on line 492 in includes/class-frontend-render-form.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Not using strict comparison for in_array; supply true for $strict argument.
$this->wp_post_types[ $post_type ][ $tax_name ] = [
'title' => $taxonomy->label,
'hierarchical' => $taxonomy->hierarchical,
Expand Down Expand Up @@ -930,7 +930,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(
<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>
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 @@ function wpuf_settings_sections() {
'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 @@ -632,6 +637,33 @@ function wpuf_settings_fields() {
'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