add_menu( array( 'id' => AFFIAI_PLUGIN_NAME, 'title' => '' . strtoupper(AFFIAI_PLUGIN_NAME) . ' Icon' . ' ' . strtoupper(AFFIAI_PLUGIN_NAME), 'href' => false, 'meta' => array( 'onclick' => 'thickbox_afx()', ) ) ); } /** * Display a modal with a shortcode generated by the plugin. * * @return void */ public function affiai_wprod_modal() { // Verify nonce for security. if ( ! current_user_can( 'edit_posts' ) || ! check_ajax_referer( 'afx-ajax-nonce', 'nonce', false ) ) { die( 'Error' ); } // Get search parameters from POST request. $type = ! empty( $_POST['stype'] ) ? sanitize_text_field( $_POST['stype'] ) : ''; $search = ! empty( $_POST['ksearch'] ) ? sanitize_text_field( $_POST['ksearch'] ) : ''; $promo = ! empty( $_POST['promo'] ) ? sanitize_text_field( $_POST['promo'] ) : ''; $price_min = ! empty( $_POST['price_min'] ) ? sanitize_text_field( $_POST['price_min'] ) : ''; $price_max = ! empty( $_POST['price_max'] ) ? sanitize_text_field( $_POST['price_max'] ) : ''; // Set filter based on search type. $filter = $type != 'pid' ? " merchants='amazon'" : ''; // Set promo filter. if ( ! empty( $promo ) ) { $promo = " promo='" . $promo . "'"; } else { $promo = ''; } // Set price filter. $price = ''; $price = ( ! empty( $price_min ) ) ? " price='" . $price_min : ''; if ( ! empty( $price_max ) ) { if ( $price != '' ) { $price .= '-' . $price_max . "'"; } else { $price = " price='0-" . $price_max . "'"; } } else { if ( $price != '' ) { $price .= "-100000'"; } else { $price = ''; } } // Generate shortcode with search parameters and display it. echo do_shortcode( "[" . AFFIAI_PLUGIN_NAME . " keyword='" . $search . "' template='select'" . $filter . $merch . $promo . $price . " count='9']" ); wp_die(); } /** * Add necessary JavaScript and CSS files for the plugin. * * @return void */ public function add_js() { // Enqueue ce_js script with dependencies and version. wp_enqueue_script( AFFIAI_PLUGIN_NAME . '-ce_js', AFFIAI_PLUGIN_URL . 'assets/js/gen.js', array( 'jquery' ), AFFIAI_PLUGIN_VER, true ); // If the current page is affiai, enqueue necessary media and scripts. if ( isset($_GET['page']) && $_GET['page'] == AFFIAI_PLUGIN_NAME ) { wp_enqueue_media(); wp_enqueue_script( 'thickbox' ); wp_enqueue_style( 'thickbox' ); // Register and enqueue fonticonpicker CSS and icon font. wp_register_style( 'affiai_fonticonpicker_css', AFFIAI_PLUGIN_URL . 'assets/css/jquery.fonticonpicker.min.css', array(), AFFIAI_PLUGIN_VER ); wp_register_style( 'affiai_fonticonpicker_theme_css', AFFIAI_PLUGIN_URL . 'assets/css/jquery.fonticonpicker.grey.min.css', array(), AFFIAI_PLUGIN_VER ); wp_register_style( 'affiai_icon_font', AFFIAI_PLUGIN_URL . 'assets/css/afx-icon.css', array(), AFFIAI_PLUGIN_VER ); wp_enqueue_style( 'affiai_fonticonpicker_css' ); wp_enqueue_style( 'affiai_fonticonpicker_theme_css' ); wp_enqueue_style( 'affiai_icon_font' ); // Register and enqueue select2 CSS and script. wp_register_style( 'affiai_select_css', AFFIAI_PLUGIN_URL . 'assets/css/select2.min.css', array(), AFFIAI_PLUGIN_VER ); wp_enqueue_style( 'affiai_select_css' ); wp_enqueue_script( 'affiai_select', AFFIAI_PLUGIN_URL . 'assets/js/select2.min.js', array( 'jquery' ), AFFIAI_PLUGIN_VER, false ); // Enqueue fonticonpicker script. // Source: https://github.com/farbelous/fontIconPicker wp_enqueue_script( 'affiai_fonticonpicker', AFFIAI_PLUGIN_URL . 'assets/js/jquery.fonticonpicker.min.js', array( 'jquery' ), AFFIAI_PLUGIN_VER, false ); } // If the current action is elementor, enqueue necessary CSS and scripts. if ( isset($_GET['action']) && $_GET['action'] == 'elementor' ) { // Register and enqueue fonticonpicker CSS and icon font. wp_register_style( 'affiai_fonticonpicker_css', AFFIAI_PLUGIN_URL . 'assets/css/jquery.fonticonpicker.min.css', array(), AFFIAI_PLUGIN_VER ); wp_register_style( 'affiai_fonticonpicker_theme_css', AFFIAI_PLUGIN_URL . 'assets/css/jquery.fonticonpicker.grey.min.css', array(), AFFIAI_PLUGIN_VER ); wp_register_style( 'affiai_icon_font', AFFIAI_PLUGIN_URL . 'assets/css/afx-icon.css', array(), AFFIAI_PLUGIN_VER ); wp_enqueue_style( 'affiai_fonticonpicker_css' ); wp_enqueue_style( 'affiai_fonticonpicker_theme_css' ); wp_enqueue_style( 'affiai_icon_font' ); // Register and enqueue select2 CSS and script. wp_register_style( 'affiai_select_css', AFFIAI_PLUGIN_URL . 'assets/css/select2.min.css', array(), AFFIAI_PLUGIN_VER ); wp_enqueue_style( 'affiai_select_css' ); wp_enqueue_script( 'affiai_select', AFFIAI_PLUGIN_URL . 'assets/js/select2.min.js', array( 'jquery' ), AFFIAI_PLUGIN_VER, false ); // Enqueue fonticonpicker script. // Source: https://github.com/farbelous/fontIconPicker wp_enqueue_script( 'affiai_fonticonpicker', AFFIAI_PLUGIN_URL . 'assets/js/jquery.fonticonpicker.min.js', array( 'jquery' ), AFFIAI_PLUGIN_VER, false ); } // Enqueue necessary CSS and script for color picker. wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker' ); // Localize ce_js script with necessary variables. wp_localize_script( AFFIAI_PLUGIN_NAME . '-ce_js', 'affiai_afxvar', array( 'plugin' => AFFIAI_PLUGIN_NAME, 'pid' => AFFIAI_PLUGIN_PROD_ID, 't1' => sprintf( /* translators: Product ID type. */ __( 'No value is indicated for the search (ASIN or %s or KEYWORD or LINK)', 'affiliate-ai-lite' ), AFFIAI_PLUGIN_PROD_ID ), 't3' => __( 'Convert to Tracked URL', 'affiliate-ai-lite' ), 't4' => __( 'Show price', 'affiliate-ai-lite' ), 't6' => __( 'here', 'affiliate-ai-lite' ), 't7' => __( 'Current Price', 'affiliate-ai-lite' ), 't8' => __( 'Please enter an URL in the Product URL field', 'affiliate-ai-lite' ), 't10' => __( 'Error: Change your URL or try again later', 'affiliate-ai-lite' ), 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'afx-ajax-nonce' ), ) ); // Enqueue modal_js script with dependencies and version. // Source: https://github.com/kirilkirkov/Simple-jQuery-Popup wp_enqueue_script( AFFIAI_PLUGIN_NAME . '-modal_js', AFFIAI_PLUGIN_URL . 'assets/js/jquery.simple-popup.min.js', array( 'jquery' ), AFFIAI_PLUGIN_VER, true ); } /** * Enqueues the necessary CSS files for the plugin to function properly. * * @return void */ public function add_styles() { wp_enqueue_style( 'afxshop', AFFIAI_PLUGIN_URL . 'assets/css/style.css', false, AFFIAI_PLUGIN_VER ); wp_enqueue_style( AFFIAI_PLUGIN_NAME . '-ce', AFFIAI_PLUGIN_URL . 'assets/css/gen.css', false, AFFIAI_PLUGIN_VER ); wp_enqueue_style( AFFIAI_PLUGIN_NAME . '-modal', AFFIAI_PLUGIN_URL . 'assets/css/jquery.simple-popup.min.css' ); } /** * Retrieves the attachment image for a given ID and returns it as a JSON response. * * @return void Returns a JSON response with the retrieved attachment image on success, or an error response on failure. */ public function affiai_get_cust_image() { if ( isset( $_GET['id'] ) ) { $image = wp_get_attachment_image( filter_input( INPUT_GET, 'id', FILTER_VALIDATE_INT ), 'medium', false, array( 'class' => 'afxcust-preview-image' ) ); $data = array( 'image' => $image, ); wp_send_json_success( $data ); } else { wp_send_json_error(); } } /** * Displays the popup for creating a product list. * * @return void */ public function affiai_popup() { // Displays the HTML content for the popup. ?> <?php esc_attr_e( 'Plugin Icon', 'affiliate-ai-lite' ); ?>