*/ class Rtwalwm_Wp_Wc_Affiliate_Program_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $rtwalwm_plugin_name The ID of this plugin. */ private $rtwalwm_plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $rtwalwm_version The current version of this plugin. */ private $rtwalwm_version; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $rtwalwm_plugin_name The name of this plugin. * @param string $rtwalwm_version The version of this plugin. */ public function __construct( $rtwalwm_plugin_name, $rtwalwm_version ) { $this->rtwalwm_plugin_name = $rtwalwm_plugin_name; $this->rtwalwm_version = $rtwalwm_version; // $rtwalwm_generate_aff_csv = isset($_GET['affiliate_csv_download'])? sanitize_text_field($_GET['affiliate_csv_download']): ''; // if(!empty($rtwalwm_generate_aff_csv)) // { // add_action('init', array($this, 'rtwalwm_download_affiliate_csv')); // } } // public function rtwalwm_download_affiliate_csv(){ // require_once( WP_PLUGIN_DIR."/wp-wc-affiliate-program/third_party/csv-9.8.0/autoload.php"); // $rtwalwm_file_name = sanitize_text_field($_GET['affiliate_csv_download']); // if(empty($rtwalwm_file_name )){ // wp_die(esc_html__('Invalid file name.','affiliaa-affiliate-program-with-mlm')); // } // $rtwalwm_file_path = RTWALWM_DIR.'assets/csv/'.$rtwalwm_file_name; // if (!file_exists($rtwalwm_file_path) || strpos(realpath($rtwalwm_file_path), realpath(RTWALWM_DIR . 'assets/csv/')) !== 0) { // wp_die(esc_html__('File does not exist or invalid file path.', 'affiliaa-affiliate-program-with-mlm')); // } // header('Content-Type: text/csv; charset=UTF-8'); // header('Content-Description: File Transfer'); // header('Content-Disposition: attachment; filename="'.$rtwalwm_file_name.'"'); // $reader = Reader::createFromPath(RTWALWM_DIR.'assets/csv/'.$rtwalwm_file_name, 'r'); // $reader->output(); // wp_die(); // } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function rtwalwm_enqueue_styles() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Rtwalwm_Wp_Wc_Affiliate_Program_Loader as all of the hooks are defined * in that particular class. * * The Rtwalwm_Wp_Wc_Affiliate_Program_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_media(); $rtwalwm_css_allowed_pages = array( 'edit-product', 'toplevel_page_rtwalwm', 'product', 'user-edit', 'users', 'user', 'profile', 'download' ); $rtwalwm_screen = function_exists( 'get_current_screen' ) ? get_current_screen() : ''; $rtwalwm_screen_id = ( isset( $rtwalwm_screen->id ) ) ? $rtwalwm_screen->id : ''; if( in_array( $rtwalwm_screen_id, $rtwalwm_css_allowed_pages ) ){ wp_enqueue_style( $this->rtwalwm_plugin_name, plugin_dir_url( __FILE__ ) . 'css/rtwalwm-wp-wc-affiliate-program-admin.css', array(), $this->rtwalwm_version, 'all' ); // wp_enqueue_style( "banner-css", plugin_dir_url( __FILE__ ) . 'css/rtwalwm-wp-wc-affiliate-banner.css', array(), $this->rtwalwm_version, 'all' ); wp_enqueue_style( "select2", RTWALWM_URL. '/assets/Datatables/css/rtwalwm-wp-select2.min.css', array(), $this->rtwalwm_version, 'all' ); wp_enqueue_style( "datatable", RTWALWM_URL. '/assets/Datatables/css/jquery.dataTables.min.css', array(), $this->rtwalwm_version, 'all' ); wp_enqueue_style( "rowReorder", RTWALWM_URL. '/assets/Datatables/css/rowReorder.dataTables.min.css', array( 'datatable' ), $this->rtwalwm_version, 'all' ); wp_enqueue_style( "jquery-ui", RTWALWM_URL. '/assets/Datatables/css/rtwalwm-jquery-ui.css', array(), $this->rtwalwm_version, 'all' ); wp_enqueue_style( "orgchart", RTWALWM_URL. '/assets/orgChart/jquery.orgchart.css', array(), $this->rtwalwm_version, 'all' ); wp_enqueue_style( 'dashicons' ); } } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function rtwalwm_enqueue_scripts() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Rtwalwm_Wp_Wc_Affiliate_Program_Loader as all of the hooks are defined * in that particular class. * * The Rtwalwm_Wp_Wc_Affiliate_Program_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ $rtwalwm_js_allowed_pages = array( 'product', 'edit-product', 'toplevel_page_rtwalwm', 'users', 'user-edit', 'user', 'profile', 'edit-download' ); $rtwalwm_screen = function_exists( 'get_current_screen' ) ? get_current_screen() : ''; $rtwalwm_screen_id = ( isset( $rtwalwm_screen->id ) ) ? $rtwalwm_screen->id : ''; if( in_array( $rtwalwm_screen_id, $rtwalwm_js_allowed_pages ) ){ wp_enqueue_script( "datatable", RTWALWM_URL. '/assets/Datatables/js/jquery.dataTables.min.js', array( 'jquery' ), $this->rtwalwm_version, false ); wp_enqueue_script( "rowReorder", RTWALWM_URL. '/assets/Datatables/js/dataTables.rowReorder.min.js', array( 'jquery', 'datatable' ), $this->rtwalwm_version, false ); wp_enqueue_script( "select2", RTWALWM_URL. '/assets/Datatables/js/rtwalwm-wp-select2.min.js', array( 'jquery' ), $this->rtwalwm_version, false ); wp_enqueue_script( 'jquery-ui-dialog', '', array( 'jquery' ), $this->rtwalwm_version, false ); wp_enqueue_script( "blockUI", RTWALWM_URL. '/assets/Datatables/js/rtwalwm-wp-blockui.js', array( 'jquery' ), $this->rtwalwm_version, false ); wp_register_script( $this->rtwalwm_plugin_name, plugin_dir_url( __FILE__ ) . 'js/rtwalwm-wp-wc-affiliate-program-admin.js', array( 'jquery', 'select2', 'datatable', 'rowReorder' ), $this->rtwalwm_version, false ); wp_enqueue_script( "orgchart", RTWALWM_URL. '/assets/orgChart/jquery.orgchart.js', array( 'jquery' ), $this->rtwalwm_version, false ); wp_enqueue_script( 'wp-color-picker', admin_url( 'js/color-picker.min.js' ), array( 'iris' ), $this->rtwalwm_version, true ); $rtwalwm_colorpicker_l10n = array( 'clear' => esc_html__( 'Clear', 'affiliaa-affiliate-program-with-mlm' ), 'defaultString' => esc_html__( 'Default', 'affiliaa-affiliate-program-with-mlm' ), 'pick' => esc_html__( 'Select Color', 'affiliaa-affiliate-program-with-mlm' ), 'current' => esc_html__( 'Current Color', 'affiliaa-affiliate-program-with-mlm' ) ); wp_localize_script( 'wp-color-picker', 'wpColorPickerL10n', $rtwalwm_colorpicker_l10n ); $rtwalwm_ajax_nonce = wp_create_nonce( "rtwalwm-admin-ajax-string" ); $rtwalwm_translation_array = array( 'rtwalwm_ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ), 'rtwalwm_nonce' => $rtwalwm_ajax_nonce, 'rtwalwm_digit' => esc_html__( 'Digits Only', 'affiliaa-affiliate-program-with-mlm' ), 'rtwalwm_bank_det' => esc_html__( 'Details not filled', 'affiliaa-affiliate-program-with-mlm' ), 'rtwalwm_bank_sent' => esc_html__( 'Are you sure that you have completed this bank transfer?', 'affiliaa-affiliate-program-with-mlm' ), 'rtwalwm_nothing_marked' => esc_html__( 'Nothing Marked', 'affiliaa-affiliate-program-with-mlm' ), 'rtwalwm_approval_sure' => esc_html__( 'Are you sure to approve this Referral? It can\'t be reverted back once approved', 'affiliaa-affiliate-program-with-mlm' ), 'rtwalwm_approval_sure_all' => esc_html__( 'Are you sure to approve all the Referrals? It can\'t be reverted back once approved', 'affiliaa-affiliate-program-with-mlm' ), 'rtwalwm_reject_sure' => esc_html__( 'Are you sure to reject this Referral? It can\'t be reverted back once rejected', 'affiliaa-affiliate-program-with-mlm' ), 'rtwalwm_reject_message_blank' => esc_html__( 'Please input some text in message box', 'affiliaa-affiliate-program-with-mlm' ), 'rtwalwm_reject_sure_all' => esc_html__( 'Are you sure to reject all the Referrals? It can\'t be reverted back once rejected', 'affiliaa-affiliate-program-with-mlm' ), 'rtwalwm_target_link' => esc_html__( 'Please Enter Target URL', 'affiliaa-affiliate-program-with-mlm' ), 'rtwalwm_image_id' => esc_html__( 'Please Select Image', 'affiliaa-affiliate-program-with-mlm' ), 'rtwalwm_image_parameter_not_match' => esc_html__( 'Image width or height is not matching with selected Image WIDTH x HEIGHT', 'affiliaa-affiliate-program-with-mlm' ) ); wp_localize_script( $this->rtwalwm_plugin_name, 'rtwalwm_global_params', $rtwalwm_translation_array ); wp_enqueue_script( $this->rtwalwm_plugin_name ); wp_enqueue_script( 'jquery.validate', plugin_dir_url( __FILE__ ) . 'js/jquery.validate/jquery.validate.js', array( 'jquery' ), $this->rtwalwm_version, false ); } } /* * Function to show settings link */ function rtwalwm_add_setting_links( $rtwalwm_links ){ $rtwalwm_links[] = ''.esc_html__( 'Settings', 'affiliaa-affiliate-program-with-mlm' ).''; return $rtwalwm_links; } /* * Function to add submenu in WooCommerce menu tab */ function rtwalwm_add_submenu() { $rtwalwm_menu_position = '80'; // Same audience as the referral handlers: administrators, and store managers when WooCommerce grants manage_woocommerce. $rtwalwm_capability = current_user_can( 'manage_options' ) ? 'manage_options' : 'manage_woocommerce'; add_menu_page( esc_html__( 'Affiliaa - WordPress & WooCommerce Affiliate Program', 'affiliaa-affiliate-program-with-mlm' ), esc_html__( 'Affiliaa Lite', 'affiliaa-affiliate-program-with-mlm' ), $rtwalwm_capability, 'rtwalwm', array( $this, 'rtwalwm_admin_setting' ), RTWALWM_URL.'assets/images/affiliate-menu-icon.png', $rtwalwm_menu_position ); } function rtwalwm_admin_setting() { include_once( RTWALWM_DIR.'admin/partials/rtwalwm-wp-wc-affiliate-program-admin-display.php'); } /* * Function to register settings */ function rtwalwm_settings_init() { register_setting( 'rtwwwap_commission_settings', 'rtwwwap_commission_settings_opt', array( $this, 'rtwalwm_save_comm' ) ); register_setting( 'rtwwwap_extra_features', 'rtwwwap_extra_features_opt', array( $this, 'rtwalwm_save_extra' ) ); register_setting( 'rtwwwap_mlm', 'rtwwwap_mlm_opt', array( $this, 'rtwwwap_save_mlm' ) ); } /* * Function to save commission settings */ function rtwalwm_save_comm( $rtwalwm_option ) { // Merge into the stored (shared) option so keys saved by other screens or PRO are preserved. $rtwalwm_saved = get_option( 'rtwwwap_commission_settings_opt' ); $rtwalwm_out = is_array( $rtwalwm_saved ) ? $rtwalwm_saved : array(); $rtwalwm_option = is_array( $rtwalwm_option ) ? $rtwalwm_option : array(); foreach ( $rtwalwm_option as $rtwalwm_key => $rtwalwm_value ) { $rtwalwm_key = sanitize_key( $rtwalwm_key ); if ( 'comm_base' === $rtwalwm_key ) { $rtwalwm_out[ $rtwalwm_key ] = in_array( (string) $rtwalwm_value, array( '1', '2' ), true ) ? (string) $rtwalwm_value : '1'; } elseif ( 'all_commission_type' === $rtwalwm_key ) { $rtwalwm_out[ $rtwalwm_key ] = ( 'fixed' === $rtwalwm_value ) ? 'fixed' : 'percentage'; } elseif ( 'per_prod_mode' === $rtwalwm_key ) { $rtwalwm_out[ $rtwalwm_key ] = in_array( (string) $rtwalwm_value, array( '1', '2' ), true ) ? (string) $rtwalwm_value : ''; } elseif ( in_array( $rtwalwm_key, array( 'all_commission', 'max_commission', 'withdraw_commission' ), true ) ) { $rtwalwm_number = Rtwalwm_Wp_Wc_Affiliate_Program_Helper::rtwalwm_decimal_or_empty( $rtwalwm_value ); if ( null === $rtwalwm_number ) { add_settings_error( 'rtwwwap_commission_settings_opt', 'rtwalwm_invalid_' . $rtwalwm_key, esc_html__( 'Commission amounts must be numbers of 0 or more. The previous value was kept.', 'affiliaa-affiliate-program-with-mlm' ) ); continue; } $rtwalwm_out[ $rtwalwm_key ] = $rtwalwm_number; } else { $rtwalwm_out[ $rtwalwm_key ] = Rtwalwm_Wp_Wc_Affiliate_Program_Helper::rtwalwm_sanitize_recursive( $rtwalwm_value ); } } if ( isset( $rtwalwm_out['all_commission'], $rtwalwm_out['all_commission_type'] ) && 'percentage' === $rtwalwm_out['all_commission_type'] && '' !== $rtwalwm_out['all_commission'] && (float) $rtwalwm_out['all_commission'] > 100 ) { $rtwalwm_out['all_commission'] = '100'; add_settings_error( 'rtwwwap_commission_settings_opt', 'rtwalwm_percentage_cap', esc_html__( 'A percentage commission cannot exceed 100. It was set to 100.', 'affiliaa-affiliate-program-with-mlm' ) ); } return $rtwalwm_out; } /* * Function to save extra settings */ function rtwalwm_save_extra( $rtwalwm_option ) { $rtwalwm_saved = get_option( 'rtwwwap_extra_features_opt' ); $rtwalwm_out = is_array( $rtwalwm_saved ) ? $rtwalwm_saved : array(); $rtwalwm_option = is_array( $rtwalwm_option ) ? $rtwalwm_option : array(); foreach ( $rtwalwm_option as $rtwalwm_key => $rtwalwm_value ) { $rtwalwm_key = sanitize_key( $rtwalwm_key ); if ( 'page' === $rtwalwm_key ) { // Same behaviour as PRO: the selected page becomes the shared affiliate page option and is not stored here. $rtwalwm_page_id = absint( $rtwalwm_value ); if ( $rtwalwm_page_id && 'page' === get_post_type( $rtwalwm_page_id ) ) { update_option( 'rtwwwap_affiliate_page_id', $rtwalwm_page_id ); } continue; } if ( 'aff_benefits' === $rtwalwm_key ) { $rtwalwm_out[ $rtwalwm_key ] = wp_kses_post( $rtwalwm_value ); } elseif ( 'css' === $rtwalwm_key ) { // Custom CSS is printed inside a