get_table_submissions(); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $results = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT form_name, element_id, post_id FROM %i WHERE form_name IS NOT NULL AND form_name != '' ORDER BY form_name ASC", $table_name ) ); $forms = []; foreach ( $results as $result ) { $element_id = $result->element_id; $form_name = $result->form_name; // Get post title if available. $post_title = ''; if ( ! empty( $result->post_id ) ) { $post = get_post( $result->post_id ); if ( $post ) { $post_title = $post->post_title; } } // Use element_id as the unique identifier. $forms[ $element_id ] = [ 'id' => $element_id, 'name' => $form_name, 'element_id' => $element_id, 'post_id' => $result->post_id, 'post_title' => $post_title, ]; } // Cache the results for 1 hour. wp_cache_set( $cache_key, $forms, $cache_group, HOUR_IN_SECONDS ); set_transient( $cache_key, $forms, HOUR_IN_SECONDS ); return $forms; } /** * Return a single form by ID. * * @param string $id Form name/ID. * * @return mixed */ public function get_form( $id ) { $forms = $this->get_forms(); return isset( $forms[ $id ] ) ? $forms[ $id ] : null; } /** * Returns an array of options for a select list. * * Should be in the format of $formId => $formLabel * * @return array */ public function get_form_selectlist() { $forms = $this->get_forms(); $form_selectlist = [ 'any' => __( 'Any Elementor Form', 'popup-maker' ) ]; foreach ( $forms as $form ) { // Use element_id as the unique identifier (system adds provider prefix). $location = ! empty( $form['post_title'] ) ? $form['post_title'] : __( 'Unknown Page', 'popup-maker' ); $form_selectlist[ $form['element_id'] ] = sprintf( '%s (in %s)', $form['name'], $location ); } return $form_selectlist; } /** * Hooks in a success functions specific to this provider for non AJAX submission handling. * * @param \ElementorPro\Modules\Forms\Classes\Form_Record $record Form submission record. * @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajax_handler Ajax handler instance. */ public function on_success( $record, $ajax_handler ) { if ( ! $this->should_process_submission() ) { return; } // Get element_id to match form selector configuration. $current_form = $ajax_handler->get_current_form(); $element_id = isset( $current_form['id'] ) ? $current_form['id'] : null; $popup_id = $this->get_popup_id(); if ( $popup_id ) { $this->increase_conversion( $popup_id ); } pum_integrated_form_submission( [ 'popup_id' => $popup_id, 'form_provider' => $this->key, 'form_id' => $element_id ? $element_id : 'unknown', ] ); } /** * Clear cached forms list when new form is submitted. * Only clears in admin context to avoid performance impact on frontend. * * @since 1.21.6 */ public function clear_forms_cache() { // Only clear cache in admin to avoid unnecessary queries on frontend. if ( ! is_admin() ) { return; } wp_cache_delete( 'pum_elementor_forms', 'popup_maker' ); delete_transient( 'pum_elementor_forms' ); } /** * Load a custom script file to handle AJAX based submissions or other integrations with Popup Maker frontend. * * @param array $js JavaScript files array. * * @return array */ public function custom_scripts( $js = [] ) { return $js; } /** * Load custom styles for hacking some elements specifically inside popups, such as datepickers. * * @param array $css CSS files array. * * @return array */ public function custom_styles( $css = [] ) { return $css; } }