cache = new Prodigy_Cache(); $this->sync = new Prodigy_Synchronization(); $this->process_factory = new Prodigy_Process_Factory(); add_action( 'admin_menu', array( $this, 'add_prodigy_settings_menu' ), 11 ); add_action( 'admin_enqueue_scripts', array( $this, 'prodigy_meta_box_load_style' ) ); add_action( 'wp_ajax_update-store-info', array( $this, 'update_info_store' ) ); add_action( 'wp_ajax_prodigy-settings-start-manual-sync-process', array( $this, 'prodigy_start_manual_sync_process' ) ); add_action( 'wp_ajax_prodigy-cache-clear', array( $this, 'prodigy_cache_clear' ) ); add_action( 'wp_ajax_prodigy-get-pages', array( $this, 'prodigy_get_pages_autoload' ) ); add_action( 'wp_ajax_prodigy-cart-rules-product-search', array( $this, 'prodigy_cart_rules_product_search' ) ); } /** * Search hosted-system products for the Cart Rules product picker. * * @return void */ public function prodigy_cart_rules_product_search(): void { if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['nonce'] ), 'ajax-nonce' ) ) { return; } if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( 'You don\'t have access', \WP_Http::FORBIDDEN ); } $search = isset( $_GET['search'] ) ? sanitize_text_field( wp_unslash( $_GET['search'] ) ) : ''; $page_number = isset( $_GET['page'] ) ? max( 1, absint( $_GET['page'] ) ) : 1; wp_send_json( self::get_cart_rules_search_payload( $search, $page_number ) ); } /** * Build the Cart Rules product picker payload for a search term. * * The hosted `search` parameter matches product name and SKU only, so for * a numeric term an additional `product_ids[]` lookup is issued (first * page only) and its match is prepended to the search results. * * @param string $search Search term. * @param int $page_number Requested results page (1-based). * * @return array */ private static function get_cart_rules_search_payload( string $search, int $page_number ): array { $params = array( 'page' => array( 'size' => self::CART_RULES_PRODUCTS_PER_PAGE, 'number' => $page_number, ), 'sort' => '-created_at', 'admin' => true, ); if ( '' !== $search ) { $params['search'] = $search; } $query = urldecode( preg_replace( '/%5B(?:[0-9]|[1-9][0-9]+)%5D/', '[]', http_build_query( $params ) ) ); $products = Prodigy_Request_Maker::get_instance()->do_admin_products_request( $query ); $id_match_products = array(); if ( 1 === $page_number && '' !== $search && ctype_digit( $search ) ) { $id_query = 'product_ids[]=' . absint( $search ) . '&page[size]=1&page[number]=1&sort=-created_at&admin=1'; $id_response = Prodigy_Request_Maker::get_instance()->do_admin_products_request( $id_query ); if ( ! array_key_exists( 'error', $id_response ) ) { $id_match_products = $id_response['data'] ?? array(); } } $total_count = (int) ( $products['data'][0]['attributes']['products-count'] ?? 0 ); $results = array(); $seen_ids = array(); foreach ( array_merge( $id_match_products, $products['data'] ?? array() ) as $product ) { $product_id = (int) ( $product['id'] ?? 0 ); if ( isset( $seen_ids[ $product_id ] ) ) { continue; } $seen_ids[ $product_id ] = true; $results[] = array( 'id' => $product_id, 'text' => self::get_cart_rules_product_text( $product ), ); } return array( 'results' => $results, 'pagination' => array( 'more' => ( $page_number * self::CART_RULES_PRODUCTS_PER_PAGE ) < $total_count, ), ); } /** * Build the option text for the Cart Rules product picker. * * @param array $product * * @return string */ private static function get_cart_rules_product_text( array $product ): string { $attributes = $product['attributes'] ?? array(); $min_price = $attributes['price-range']['min_price'] ?? null; $max_price = $attributes['price-range']['max_price'] ?? null; $price = Prodigy_Formatting::display_price( (string) $min_price ); if ( $min_price !== null && $max_price !== null && (float) $min_price !== (float) $max_price ) { $price .= ' - ' . Prodigy_Formatting::display_price( (string) $max_price ); } return sprintf( '%s (ID: %d) — %s', $attributes['name'] ?? '', (int) $product['id'], $price ); } /** * Get the stored mandatory cart product from the hosted system. * * @param int $product_id * * @return array */ private static function get_cart_rules_product( int $product_id ): array { $query = 'product_ids[]=' . $product_id . '&page[size]=1&page[number]=1&admin=1'; $products = Prodigy_Request_Maker::get_instance()->do_admin_products_request( $query ); if ( array_key_exists( 'error', $products ) ) { return array( // translators: %d: product ID number. 'text' => sprintf( __( 'Product ID: %d', 'prodigy-commerce' ), $product_id ), 'exists' => true, ); } $product = $products['data'][0] ?? array(); if ( empty( $product ) || (int) $product['id'] !== $product_id ) { return array( 'text' => '', 'exists' => false, ); } return array( 'text' => self::get_cart_rules_product_text( $product ), 'exists' => true, ); } /** * @return void */ public function prodigy_get_pages_autoload(): void { global $wpdb; if ( ! isset( $_GET['q'], $_GET['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['nonce'] ), 'ajax-nonce' ) ) { return; } $search_parameter = sanitize_key( wp_unslash( $_GET['q'] ) ); $pages = $wpdb->get_results( $wpdb->prepare( "SELECT wp.id, wp.post_title FROM $wpdb->posts wp WHERE post_type='page' and post_status='publish' and post_title like %s LIMIT 50", '%' . $search_parameter . '%' ) ); foreach ( $pages as $key => $page ) { $pages['items'][ $key ]['id'] = $page->id; $pages['items'][ $key ]['text'] = $page->post_title . ' (' . $page->id . ')'; } wp_send_json_success( $pages ); } /** * Clear cache completely. */ public function prodigy_cache_clear(): void { if ( ! isset( $_POST['is_clear'], $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'ajax-nonce' ) ) { return; } $this->cache->clear(); wp_send_json_success(); } /** * @return void * @throws Prodigy_Demo_Content_Exception */ public function prodigy_start_manual_sync_process(): void { if ( ! isset( $_POST['sync'], $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'ajax-nonce' ) ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } $this->process_factory->start_process->purge_queue(); Prodigy_Synchronization::reset_sync_state(); $is_save_sync_options = $this->sync->run_sync_process( Prodigy_Api_Client::SYNC_CONTENT_URL, Prodigy_Synchronization::PRODIGY_MANUAL_PROCESS ); if ( ! $is_save_sync_options && PRODIGY_DEBUG_MODE ) { do_action( 'logger', __LINE__ . __METHOD__ . __CLASS__ . ' Sync settings saving error', 'error' ); } } /** * Load common scripts for meta boxes */ public function prodigy_meta_box_load_style(): void { $screen = get_current_screen(); $current_page = $screen->id ?? ''; if ( in_array( $current_page, Prodigy::get_pages_list(), true ) ) { wp_enqueue_media(); wp_enqueue_script( 'media-upload' ); wp_enqueue_script( 'jquery.inputmask.bundle.min', dirname( plugin_dir_url( __FILE__ ) ) . '/web/libraries/inputmask/js/jquery.inputmask.bundle.min.js', array( 'jquery' ), PRODIGY_VERSION, false ); wp_enqueue_style( 'inputmask', dirname( plugin_dir_url( __FILE__ ) ) . '/web/libraries/inputmask/css/inputmask.css', array(), PRODIGY_VERSION ); } wp_enqueue_script( 'tag-it.min', dirname( plugin_dir_url( __FILE__ ) ) . '/web/admin/js/tag-it.min.js', array( 'jquery', 'jquery-ui-widget', 'jquery-ui-autocomplete' ), PRODIGY_VERSION, false ); wp_enqueue_style( 'wp-jquery-ui-dialog' ); wp_enqueue_script( 'jquery-ui-dialog' ); wp_enqueue_script( 'jquery-ui-datepicker' ); } /** * Update info store from hosted system */ public function update_info_store(): void { if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( 'You don\'t have access', \WP_Http::FORBIDDEN ); } $subdomain = Prodigy_Url_Helper::get_hs_store_subdomain(); if ( empty( $subdomain ) ) { wp_send_json_error( esc_html__( 'No connection', 'prodigy-commerce' ), \WP_Http::UNPROCESSABLE_ENTITY ); } $request_store = Prodigy_Request_Maker::get_instance()->do_get_platform_info(); if ( array_key_exists( 'error', $request_store ) ) { wp_send_json_error( $request_store['message'], $request_store['code'] ); } if ( \WP_Http::OK === $request_store['code'] ) { $result_body = json_decode( wp_remote_retrieve_body( $request_store ), false ); update_option( Prodigy_Admin_Setup_Wizard::NAME_TOKEN_HOSTED_SYSTEM, $result_body->data->attributes->subdomain ); $data['pg_domain_hosted_system'] = get_option( 'pg_domain_hosted_system' ); $data['pg_url_domain_hosted_system'] = esc_url( Prodigy_Url_Helper::get_url_home() ); $data['message'] = esc_html__( 'Data updated successfully', 'prodigy-commerce' ); wp_send_json_success( $data ); } else { $errors = Prodigy_Request_Maker::get_instance()->get_list_errors( $request_store ); $message = wp_remote_retrieve_response_message( $request_store ) . '. ' . implode( ', ', $errors ); wp_send_json_error( $message, $request_store['code'] ); } wp_die(); } /** * Create settings submenu */ public function add_prodigy_settings_menu(): void { $menu_setting_page = add_submenu_page( 'edit.php?post_type=' . Prodigy::get_prodigy_product_type(), esc_html__( 'Prodigy Settings', 'prodigy-commerce' ), esc_html__( 'Settings', 'prodigy-commerce' ), 'edit_pages', self::SETTINGS_PAGE, array( $this, 'display_page' ) ); add_action( 'load-' . $menu_setting_page, array( $this, 'save_settings' ) ); } /** * Render view for page */ public static function display_page(): void { $settings = array( 'current_tab' => self::get_current_tab(), 'tabs' => self::get_settings_fields(), ); extract( $settings ); require_once PRODIGY_PLUGIN_PATH . 'admin/partials/prodigy-admin-settings-page.php'; } /** * @return void */ public function save_settings(): void { if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'admin-settings' ) ) { return; } $request_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; if ( ! empty( $_POST ) && $request_page === self::SETTINGS_PAGE ) { if ( self::get_current_tab() === self::ACTION_CART_RULES ) { if ( $this->save_cart_rules_fields() ) { Prodigy_Admin_Notification::display_success( esc_html__( 'Your settings have been saved', 'prodigy-commerce' ) ); } return; } if ( $this->save_fields() ) { Prodigy_Admin_Notification::display_success( esc_html__( 'Your settings have been saved', 'prodigy-commerce' ) ); } } } /** * Save Cart Rules settings. * * @return bool */ private function save_cart_rules_fields(): bool { if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'admin-settings' ) ) { return false; } if ( ! current_user_can( 'manage_options' ) ) { return false; } $is_enabled = isset( $_POST[ Prodigy_Cart_Rules::ENABLE_OPTION ] ) ? intval( 'on' === sanitize_key( wp_unslash( $_POST[ Prodigy_Cart_Rules::ENABLE_OPTION ] ) ) ) : 0; $product_id = isset( $_POST[ Prodigy_Cart_Rules::PRODUCT_OPTION ] ) ? absint( wp_unslash( $_POST[ Prodigy_Cart_Rules::PRODUCT_OPTION ] ) ) : 0; $result = true; if ( $is_enabled && ! $product_id ) { $is_enabled = 0; $result = false; Prodigy_Admin_Notification::display_error( esc_html__( 'Select a mandatory cart product to enable this option. The option has been kept disabled.', 'prodigy-commerce' ) ); } $old_is_enabled = (int) get_option( Prodigy_Cart_Rules::ENABLE_OPTION, 0 ); $old_product_id = absint( get_option( Prodigy_Cart_Rules::PRODUCT_OPTION, 0 ) ); // When the rule is disabled without a new product selection, keep the // stored product id: it is harmless while disabled and preserves the // admin's previous selection when the rule is re-enabled. if ( ! $is_enabled && ! $product_id && $old_product_id > 0 ) { $product_id = $old_product_id; } update_option( Prodigy_Cart_Rules::ENABLE_OPTION, $is_enabled ); update_option( Prodigy_Cart_Rules::PRODUCT_OPTION, $product_id ); if ( $old_is_enabled !== $is_enabled || $old_product_id !== $product_id ) { if ( $old_product_id > 0 && $old_product_id !== $product_id ) { Prodigy_Cart_Rules::remember_retired_mandatory_product( $old_product_id ); } $this->cache->clear(); } return $result; } /** * @param array $field * * @return void */ private function save_field( array $field ): void { if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'admin-settings' ) ) { return; } $is_checkbox = $field['type'] === 'checkbox'; $is_page_multiselect = $field['type'] === 'page_multiselect'; $name = $field['name'] ?? $field['id']; $post_name = $is_page_multiselect ? $field['id'] : $name; if ( $is_page_multiselect ) { $raw = isset( $_POST[ $post_name ] ) ? wp_unslash( $_POST[ $post_name ] ) : array(); $raw = is_array( $raw ) ? $raw : array( $raw ); $raw = array_values( array_filter( $raw, function ( $v ) { $id = absint( $v ); return $id > 0; } ) ); $value = array_map( 'absint', $raw ); update_option( $field['id'], $value ); return; } $value = isset( $_POST[ $post_name ] ) ? sanitize_key( wp_unslash( $_POST[ $post_name ] ) ) : ''; if ( ! isset( $_POST[ $post_name ] ) && ! $is_checkbox ) { return; } if ( $is_checkbox ) { $value = intval( 'on' === $value ); } $value = Prodigy_Formatting::prodigy_sanitize_field( $value, $field['type'] ); update_option( $field['id'], $value ); if ( isset( $field['fields'] ) && is_array( $field['fields'] ) ) { foreach ( $field['fields'] as $field ) { $this->save_field( $field ); } } } /** * Save Settings * * @return bool */ public function save_fields(): bool { if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'admin-settings' ) ) { return false; } $result = false; $tab_current = self::get_current_tab(); $settings_fields = self::get_settings_fields(); $settings_fields = $settings_fields[ $tab_current ]; if ( ! isset( $settings_fields['fields'] ) ) { return false; } $settings_fields = $settings_fields['fields']; foreach ( $settings_fields as $field ) { $this->save_field( $field ); $result = true; } wp_cache_flush(); $current_product_type = Prodigy::get_prodigy_product_type(); $new_product_type = get_option( 'pg_product_type_slug' ); $current_category_type = Prodigy::get_prodigy_category_type(); $new_category_type = get_option( 'pg_category_type_slug' ); $current_tag_type = Prodigy::get_prodigy_tag_type(); $new_tag_type = get_option( 'pg_tag_type_slug' ); $redirect_setting = false; if ( isset( $_POST['prodigy_cart_page_id'], $_POST['prodigy_thank_page_id'] ) ) { if ( $_POST['prodigy_thank_page_id'] === $_POST['prodigy_cart_page_id'] ) { update_option( 'prodigy_cart_page_id', '' ); $redirect_setting = true; } } if ( Prodigy::normalize_prodigy_page_assignments() ) { $redirect_setting = true; } if ( ! empty( $new_product_type ) && $current_product_type !== $new_product_type ) { wp_cache_flush(); update_option( 'pg_product_type_slug', $new_product_type ); $redirect_setting = true; } if ( ! empty( $new_category_type ) && $current_category_type !== $new_category_type ) { wp_cache_flush(); update_option( 'pg_category_type_slug', $new_category_type ); $redirect_setting = true; } if ( ! empty( $new_tag_type ) && $current_tag_type !== $new_tag_type ) { wp_cache_flush(); update_option( 'pg_tag_type_slug', $new_tag_type ); $redirect_setting = true; } update_option( 'prodigy_queue_flush_rewrite_rules', 'no' ); flush_rewrite_rules( false ); if ( $redirect_setting ) { self::redirect_to_settings( isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : $new_product_type ); } return $result; } /** * @param string $tab * * @return void */ public static function redirect_to_settings( string $tab ): void { Prodigy_Admin_Notification::display_success( esc_html__( 'Your settings have been saved', 'prodigy-commerce' ) ); $admin_url = prodigy_get_admin_url( 'edit.php', array( 'post_type' => Prodigy::get_prodigy_product_type(), 'page' => self::SETTINGS_PAGE, 'tab' => $tab, '_wpnonce' => wp_create_nonce( 'admin-tab' ), ) ); wp_safe_redirect( $admin_url ); exit; } /** * List of pages for setting store display * * @return array|false */ public static function get_post_pages() { return get_pages(); } /** * @return string */ public static function get_current_tab(): string { global $tab_current; if ( $tab_current ) { return $tab_current; } if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ), 'admin-tab' ) ) { $request_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : ''; $tab_current = ! in_array( $request_tab, self::SETTING_TABS, true ) ? self::ACTION_GENERAL : sanitize_title( wp_unslash( $request_tab ), true ); } else { $tab_current = self::ACTION_GENERAL; } return $tab_current; } /** * * @return int[] */ public static function get_excluded_page_ids(): array { $ids = get_option( 'prodigy_excluded_page_ids', array() ); if ( ! is_array( $ids ) ) { return array(); } $ids = array_map( 'absint', array_filter( $ids ) ); return array_values( array_filter( $ids, function ( $id ) { return $id > 0; } ) ); } /** * Get page option. * * @param string $page_id * * @return array */ public static function get_page_option( string $page_id ): array { $page = get_post( $page_id ); if ( ! empty( $page ) && ( $page->post_status === 'publish' || $page->post_status === 'draft' ) ) { $page_title = $page->post_title ?? ''; return array( $page_id => esc_html( $page_title ) . ' (' . (int) $page_id . ')' ); } return array(); } /** * * @param int[] $page_ids * @return array */ public static function get_page_labels_by_ids( array $page_ids ): array { $page_ids = array_filter( array_map( 'absint', $page_ids ), function ( $id ) { return $id > 0; } ); if ( empty( $page_ids ) ) { return array(); } $posts = get_posts( array( 'post_type' => 'page', 'post__in' => $page_ids, 'post_status' => 'any', 'posts_per_page' => -1, 'orderby' => 'post__in', 'no_found_rows' => true, ) ); $options = array(); foreach ( $posts as $post ) { $title = $post->post_title ?? ''; // translators: %d: page ID number. $label = $title ? $title . ' (' . (int) $post->ID . ')' : sprintf( __( 'Page #%d', 'prodigy-commerce' ), (int) $post->ID ); $options[ (string) $post->ID ] = esc_html( $label ); } foreach ( $page_ids as $pid ) { if ( ! isset( $options[ (string) $pid ] ) ) { // translators: %d: page ID number. $options[ (string) $pid ] = sprintf( __( 'Page #%d', 'prodigy-commerce' ), $pid ); } } return $options; } /** * @return array[] */ private static function get_settings_fields(): array { $cart_page_id = Prodigy_Page::prodigy_get_page_id( Page::PAGE_TYPE_CART ); $cart_page_option = self::get_page_option( $cart_page_id ); $thank_page_id = Prodigy_Page::prodigy_get_page_id( Page::PAGE_TYPE_THANK ); $thank_page_option = self::get_page_option( $thank_page_id ); $excluded_page_ids = self::get_excluded_page_ids(); $excluded_page_options = self::get_page_labels_by_ids( $excluded_page_ids ); $shop_page_id = Prodigy_Page::prodigy_get_page_id( Page::PAGE_TYPE_SHOP ); $shop_page_option = self::get_page_option( $shop_page_id ); $cart_rules_product_id = Prodigy_Cart_Rules::get_mandatory_product_id(); $cart_rules_product = array( 'text' => '', 'exists' => false, ); if ( self::get_current_tab() === self::ACTION_CART_RULES && $cart_rules_product_id ) { $cart_rules_product = self::get_cart_rules_product( $cart_rules_product_id ); } return array( self::ACTION_GENERAL => array( 'title' => esc_html__( 'General', 'prodigy-commerce' ), 'template' => array( 'is_connected' => (bool) get_option( Prodigy_Admin_Setup_Wizard::OPTION_STORE_KEY ), 'domain_hosted_system' => get_option( 'pg_domain_hosted_system', 'Store name domain hosted' ), ), ), self::ACTION_PRODUCTS => array( 'title' => esc_html__( 'Products', 'prodigy-commerce' ), 'fields' => array( array( 'type' => 'section_title', 'label' => esc_html__( 'Shop pages', 'prodigy-commerce' ), 'id' => 'prodigy_shop_section_title', ), array( 'label' => esc_html__( 'Shop page', 'prodigy-commerce' ), 'type' => 'dropdown', 'id' => 'prodigy_shop_page_id', 'class' => 'prodigy-init-page-select', 'value' => $shop_page_id, 'options' => $shop_page_option, ), array( 'label' => esc_html__( 'Customize Product page URL', 'prodigy-commerce' ), 'type' => 'text', 'class' => 'prodigy-type-slug-js', 'id' => 'pg_product_type_slug', 'value' => Prodigy::get_prodigy_product_slug(), 'placeholder' => Prodigy::get_prodigy_product_type(), ), array( 'label' => esc_html__( 'Customize Category page URL', 'prodigy-commerce' ), 'type' => 'text', 'class' => 'prodigy-type-slug-js', 'id' => 'pg_category_type_slug', 'value' => Prodigy::get_prodigy_category_slug(), 'placeholder' => Prodigy::get_prodigy_category_type(), ), array( 'label' => esc_html__( 'Customize Tag page URL', 'prodigy-commerce' ), 'type' => 'text', 'class' => 'prodigy-type-slug-js', 'id' => 'pg_tag_type_slug', 'value' => Prodigy::get_prodigy_tag_slug(), 'placeholder' => Prodigy::get_prodigy_tag_type(), ), array( 'label' => esc_html__( 'Add to cart behaviour', 'prodigy-commerce' ), 'type' => 'radio', 'class' => 'prodigy-main-radio', 'id' => 'pg_add_cart_behaviour', 'options' => array( 'redirect_to_cart' => esc_html__( 'Redirect to the cart page after successful addition', 'prodigy-commerce' ), 'current_page' => esc_html__( 'Update cart widget and remain on current page', 'prodigy-commerce' ), ), ), array( 'label' => esc_html__( 'Cart expiration time', 'prodigy-commerce' ), 'type' => 'dropdown', 'class' => 'prodigy-plugin-settings__select mb-12 expiration-time-js', 'id' => 'pg_cart_expiration_time', 'options' => array( '1' => esc_html__( '1 hour', 'prodigy-commerce' ), '5' => esc_html__( '5 hour', 'prodigy-commerce' ), '24' => esc_html__( '24 hour', 'prodigy-commerce' ), '48' => esc_html__( '48 hour', 'prodigy-commerce' ), '168' => esc_html__( '1 week (168h)', 'prodigy-commerce' ), '672' => esc_html__( '4 weeks (672h)', 'prodigy-commerce' ), 'custom' => esc_html__( 'Custom value', 'prodigy-commerce' ), ), 'fields' => array( array( 'label' => '', 'type' => 'text', 'class' => 'prodigy-plugin-settings__input expiration-custom-js hidden', 'id' => 'pg_custom_expiration_time', 'placeholder' => esc_attr__( 'from 1h to 9999h', 'prodigy-commerce' ), ), ), ), array( 'type' => 'section_title', 'label' => esc_html__( 'Reviews', 'prodigy-commerce' ), 'id' => 'prodigy_reviews_section_title', ), array( 'label' => esc_html__( 'Enable reviews', 'prodigy-commerce' ), 'text' => esc_html__( 'Enable product reviews', 'prodigy-commerce' ), 'type' => 'checkbox', 'class' => 'main-checkbox__input', 'id' => 'pg_product_review', ), array( 'label' => esc_html__( 'Product ratings', 'prodigy-commerce' ), 'text' => esc_html__( 'Enable star rating on reviews', 'prodigy-commerce' ), 'type' => 'checkbox', 'class' => 'main-checkbox__input', 'id' => 'pg_product_rating', ), array( 'label' => esc_html__( 'Captcha comments', 'prodigy-commerce' ), 'text' => esc_html__( 'Enable captcha comments', 'prodigy-commerce' ), 'type' => 'checkbox', 'class' => 'main-checkbox__input captcha-launch-js', 'id' => 'pg_captcha_launch', ), array( 'label' => esc_html__( 'Captcha site key', 'prodigy-commerce' ), 'type' => 'text', 'wrapper-class' => 'captcha-block-js', 'id' => 'pg_captcha_site_key', ), array( 'label' => esc_html__( 'Captcha secret key', 'prodigy-commerce' ), 'description' => esc_html__( 'Please make sure you accurately copy and paste the Captcha site key and secret key into the fields above', 'prodigy-commerce' ), 'type' => 'text', 'wrapper-class' => 'captcha-block-js', 'id' => 'pg_captcha_secret_key', ), ), ), self::ACTION_CACHE => array( 'title' => esc_html__( 'Cache', 'prodigy-commerce' ), 'fields' => array( array( 'type' => 'section_title', 'label' => esc_html__( 'Plugin cache', 'prodigy-commerce' ), 'id' => 'prodigy_cache_section_title', ), array( 'label' => esc_html__( 'Enable caching', 'prodigy-commerce' ), 'text' => esc_html__( 'Enable caching', 'prodigy-commerce' ), 'type' => 'checkbox', 'class' => 'main-checkbox__input', 'id' => Prodigy_Cache::CACHE_STATE_OPTION, ), array( 'label' => esc_html__( 'Cache expiration time', 'prodigy-commerce' ), 'type' => 'dropdown', 'class' => 'prodigy-plugin-settings__select mb-12 pg-cache-expiration-time-js ', 'id' => Prodigy_Cache::EXPIRATION_TIME_OPTION, 'options' => array( '60' => esc_html__( '1 minute', 'prodigy-commerce' ), '300' => esc_html__( '5 minutes', 'prodigy-commerce' ), '900' => esc_html__( '15 minutes', 'prodigy-commerce' ), '1800' => esc_html__( '30 minutes', 'prodigy-commerce' ), '3600' => esc_html__( '1 hour', 'prodigy-commerce' ), 'custom' => esc_html__( 'Custom value', 'prodigy-commerce' ), ), 'value' => get_option( Prodigy_Cache::EXPIRATION_TIME_OPTION ), 'fields' => array( array( 'label' => '', 'type' => 'text', 'class' => 'prodigy-plugin-settings__input pg-cache-expiration-custom-js hidden', 'id' => Prodigy_Cache::CUSTOM_EXPIRATION_TIME_OPTION, 'placeholder' => esc_attr__( 'from 1h to 9999h', 'prodigy-commerce' ), ), ), ), ), ), self::ACTION_PAGES => array( 'title' => esc_html__( 'Pages', 'prodigy-commerce' ), 'fields' => array( array( 'type' => 'section_title', 'label' => esc_html__( 'Pages setup', 'prodigy-commerce' ), 'id' => 'prodigy_pages_section_title', ), array( 'label' => esc_html__( 'Cart page', 'prodigy-commerce' ), 'type' => 'dropdown', 'class' => 'prodigy-init-page-select', 'id' => 'prodigy_cart_page_id', 'value' => $cart_page_id, 'options' => $cart_page_option, ), array( 'label' => esc_html__( 'Thank you page', 'prodigy-commerce' ), 'type' => 'dropdown', 'class' => 'prodigy-init-page-select', 'id' => 'prodigy_thank_page_id', 'value' => $thank_page_id, 'options' => $thank_page_option, ), array( 'label' => esc_html__( 'Exclude pages', 'prodigy-commerce' ), 'type' => 'page_multiselect', 'class' => array( 'prodigy-init-page-multiselect' ), 'id' => 'prodigy_excluded_page_ids', 'value' => $excluded_page_ids, 'options' => $excluded_page_options, 'description' => esc_html__( 'Select WordPress pages to exclude from Prodigy.', 'prodigy-commerce' ), ), ), ), self::ACTION_CART_RULES => array( 'title' => esc_html__( 'Cart Rules', 'prodigy-commerce' ), 'template' => array( 'is_enabled' => (bool) get_option( Prodigy_Cart_Rules::ENABLE_OPTION ), 'product_id' => $cart_rules_product_id, 'product_option_text' => $cart_rules_product['text'], 'is_product_missing' => $cart_rules_product_id > 0 && ! $cart_rules_product['exists'], ), ), self::ACTION_APPS => array( 'title' => esc_html__( 'Apps', 'prodigy-commerce' ), 'fields' => array( array( 'type' => 'section_title', 'label' => esc_html__( 'Google Analytics', 'prodigy-commerce' ), 'id' => 'prodigy_apps_section_title', ), array( 'label' => esc_html__( 'Enable GA', 'prodigy-commerce' ), 'text' => esc_html__( 'Enable Google Analytics', 'prodigy-commerce' ), 'type' => 'checkbox', 'class' => 'main-checkbox__input', 'id' => 'pg_enable_google_analytics', ), array( 'type' => 'hidden', 'id' => 'pg_enable_google_analytics_hidden', 'value' => '1', ), ), ), ); } }