'Ref_Source', 'utm_medium' => 'Ref_Medium', 'utm_campaign' => 'Ref_Name', 'utm_term' => 'Ref_Term', 'utm_content' => 'Ref_Content', ]; public static function get_curr_lang() { $lang = apply_filters( 'wpml_current_language', null ); if ( !$lang ) { $lang = self::DEFAULT_LANGUAGE; } return $lang; } public static function get_lang_list() { $list = apply_filters( 'wpml_active_languages', null, 'orderby=id&order=desc' ); if ( !$list ) { $list = [ self::DEFAULT_LANGUAGE => [ 'code' => self::DEFAULT_LANGUAGE, 'id' => null, 'native_name' => self::DEFAULT_LANGUAGE_TITLE, 'major' => null, 'active' => null, 'default_locale' => self::DEFAULT_LANGUAGE_LOCALE, 'encode_url' => null, 'tag' => self::DEFAULT_LANGUAGE, 'translated_name' => self::DEFAULT_LANGUAGE_TITLE, 'url' => null, 'country_flag_url' => null, 'language_code' => self::DEFAULT_LANGUAGE, ] ]; } return $list; } public function bootstrap() { register_activation_hook( FQP_PLUGIN_BASE_NAME, [ $this, 'activate' ] ); add_action( 'init', [ $this, 'start_session' ] ); add_action( 'init', [ $this, 'check_referrer' ] ); add_action( 'init', [ $this, 'load_textdomain' ] ); add_action( 'init', [ $this, 'register_post_type' ] ); add_action( 'init', [ $this, 'add_shortcodes' ] ); $settings = new Settings(); add_action( 'admin_init', [ $settings, 'register_settings' ] ); add_action( 'admin_menu', [ $settings, 'admin_menu' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] ); add_action( 'admin_post_fqp_export_csv', function () { ( new SubmissionsExport() )->export(); } ); add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); add_action( 'save_post', [ $this, 'set_quote_post_id' ], 10, 2 ); Bank::init(); Product::init(); ZOHO::init_actions(); } public function activate() { //DB::init_database(); } public function start_session() { if ( headers_sent() ) { // nothing to do } else if ( !session_id() ) { session_start(); } } public function register_post_type() { register_post_type( self::PARTNER_POST_TYPE, [ 'labels' => array( 'name' => 'Partners', 'singular_name' => 'Partner', 'add_new' => 'Add New Partner', 'add_new_item' => 'New Partner', 'edit_item' => 'Edit Partner', 'new_item' => 'New Partner', 'view_item' => 'View Partner', 'search_items' => 'Search Partner', 'not_found' => 'Partner was not found', 'not_found_in_trash' => 'No Partner was found in Trash', 'parent_item_colon' => '', 'menu_name' => 'Partners', ), 'description' => '', 'public' => true, 'show_ui' => true, 'show_in_menu' => false, 'capability_type' => 'post', 'hierarchical' => false, 'supports' => ['title', 'editor', 'thumbnail', 'excerpt', 'revisions', 'page-attributes'], // 'title','editor','author','thumbnail','excerpt','trackbacks','custom-fields','comments','revisions','page-attributes','post-formats' 'taxonomies' => [], 'has_archive' => false, 'rewrite' => [ 'slug' => 'partner', ], 'query_var' => true, 'menu_icon' => plugins_url( 'img/icon.png', FQP_PLUGIN_BASE_NAME ), ] ); } public function load_textdomain() { $path = FQP_PLUGIN_DIR_PATH . 'languages/'; $langs = self::get_lang_list(); $lang = self::get_curr_lang(); if ( array_key_exists( $lang, $langs ) ) { $locale = $langs[$lang]['default_locale']; } else { $locale = get_locale(); } $mo_file = self::TEXT_DOMAIN . '-' . $locale . '.mo'; if ( $loaded = load_textdomain( self::TEXT_DOMAIN, $path . $mo_file ) ) { return $loaded; } return load_textdomain( self::TEXT_DOMAIN, WP_LANG_DIR . '/plugins/' . $mo_file ); } public function admin_enqueue_scripts( $hook ) { $is_prices_page = ( dirname( FQP_PLUGIN_BASE_NAME ) . '/admin/prices.php' == $hook ); wp_enqueue_style( 'fasoon_quote', plugins_url( '/css/admin.css', FQP_PLUGIN_BASE_NAME ) ); if ( $is_prices_page ) { wp_enqueue_script( 'auto_numeric', plugins_url( '/js/autoNumeric/autoNumeric-min.js', FQP_PLUGIN_BASE_NAME ), [ 'jquery' ] ); wp_enqueue_script( 'fasoon', plugins_url( '/js/fasoon-quote.js', FQP_PLUGIN_BASE_NAME ), [ 'auto_numeric' ] ); } } public function enqueue_scripts() { global $post; if ( is_a( $post, 'WP_Post' ) && ( has_shortcode( $post->post_content, 'fasoon_short_pricing' ) || has_shortcode( $post->post_content, 'fasoon_full_pricing' ) || has_shortcode( $post->post_content, 'fasoon_quote_price' ) ) ) { wp_enqueue_style( 'fasoon_quote_price', plugins_url( '/css/user.css', FQP_PLUGIN_BASE_NAME ) ); } } public function add_shortcodes() { new Shortcode\ShortPricing(); new Shortcode\FullPricing(); new Shortcode\QuotePrice(); } public function set_quote_post_id( $post_id, $post ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $post_id; } if ( !is_a( $post, 'WP_Post' ) || !has_shortcode( $post->post_content, 'fasoon_quote_price' ) ) { return $post_id; } if ( !current_user_can( 'edit_page', $post_id ) ) { return $post_id; } $value = get_option( self::QUOTE_FORM_PAGE_ID_OPTION ); if ( !is_array( $value ) ) { $value = []; } $value[self::get_curr_lang()] = $post_id; update_option( self::QUOTE_FORM_PAGE_ID_OPTION, $value ); return $post_id; } public function check_referrer() { if ( ! empty( @$_GET['utm_source'] ) && ! empty( @$_GET['utm_medium'] ) && ! empty( @$_GET['utm_campaign'] ) ) { self::set_referrer(); } } public static function set_referrer() { foreach ( array_keys( self::get_referrer_fields_map() ) as $field ) { $key = self::$_utm_referrer_fields_map[$field]; $default = ( in_array( $field, [ 'utm_term', 'utm_content' ] ) ) ? '' : 'UNDEFINED'; $_SESSION[self::UTM_SESSION_VAR][$key] = @$_GET[$field] ?: $default; } } public static function get_referrer() { if ( array_key_exists( self::UTM_SESSION_VAR, $_SESSION ) && is_array( $_SESSION[self::UTM_SESSION_VAR] ) ) { return $_SESSION[self::UTM_SESSION_VAR]; } return []; } public static function clear_referrer() { unset($_SESSION[self::UTM_SESSION_VAR]); } public static function get_referrer_fields_map() { return self::$_utm_referrer_fields_map; } }