_check_plugin_dependencies() ) { $this->_load_dependencies(); $this->_init(); $this->_exe(); } else { // Display notice that plugin dependency ( WooCommerce ) is not present. add_action( 'admin_notices' , array( $this , 'missing_plugin_dependencies_notice' ) ); } } /** * Ensure that only one instance of After Sale Surveys is loaded or can be loaded (Singleton Pattern). * * @since 1.0.0 * @access public * * @return After_Sale_Surveys */ public static function instance() { if ( !self::$_instance instanceof self ) self::$_instance = new self(); return self::$_instance; } /** * General code base to be always executed on plugin deactivation. * * @since 1.1.1 * @access public * * @param boolean $network_wide Flag that determines if the plugin is activated network wide. */ public function general_deactivation_code( $network_wide ) { global $wpdb; // check if it is a multisite network if ( is_multisite() ) { // check if the plugin has been activated on the network or on a single site if ( $network_wide ) { // get ids of all sites $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); foreach ( $blog_ids as $blog_id ) { switch_to_blog( $blog_id ); delete_option( 'ass_activation_code_triggered' ); } restore_current_blog(); } else { // activated on a single site, in a multi-site delete_option( 'ass_activation_code_triggered' ); } } else { // activated on a single site delete_option( 'ass_activation_code_triggered' ); } } /** * Check for plugin dependencies of After Sale Surveys plugin. * * @since 1.0.0 * @access private * * @return bool */ private function _check_plugin_dependencies() { // Makes sure the plugin is defined before trying to use it if ( !function_exists( 'is_plugin_active' ) ) include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); return is_plugin_active( 'woocommerce/woocommerce.php' ); } /** * Add notice to notify users that a required plugin dependency of After Sale Surveys plugin is missing. * * @since 1.0.0 * @access public */ public function missing_plugin_dependencies_notice() { $plugin_file = 'woocommerce/woocommerce.php'; $wc_file = trailingslashit( WP_PLUGIN_DIR ) . plugin_basename( $plugin_file ); $wc_install_text = '' . __( 'Click here to install from WordPress.org repo →' , 'after-sale-surveys' ) . ''; if ( file_exists( $wc_file ) ) $wc_install_text = '' . __( 'Click here to activate →' , 'after-sale-surveys' ) . ''; ?>

After Sale Surveys plugin missing dependency.

Please ensure you have the WooCommerce plugin installed and activated.
' , 'after-sale-surveys' ); ?>

constants = ASS_Constants::instance(); $common_deps = array( 'ASS_Constants' => $this->constants ); $this->i18n = ASS_I18n::instance( $common_deps ); $this->admin_status = ASS_Admin_Status::instance( $common_deps ); // Help Pointers $this->initial_guided_tour = ASS_Initial_Guided_Tour::instance( $common_deps ); $this->survey_entry_guided_tour = ASS_Survey_Entry_Guided_Tour::instance( $common_deps ); // Shop $this->product = ASS_Product::instance( $common_deps ); // Survey $this->survey_cpt = ASS_Survey_CPT::instance( $common_deps ); $this->survey = ASS_Survey::instance( $common_deps ); $this->survey_response_cpt = ASS_Survey_Response_CPT::instance( $common_deps ); $this->survey_report = ASS_Survey_Report::instance( $common_deps ); $this->script_loader = ASS_Script_Loader::instance( array( 'ASS_Constants' => $this->constants, 'ASS_Survey' => $this->survey, 'ASS_Initial_Guided_Tour' => $this->initial_guided_tour, 'ASS_Survey_Entry_Guided_Tour' => $this->survey_entry_guided_tour ) ); // AJAX $this->ajax_interface = ASS_AJAX_Interfaces::instance( array( 'ASS_Constants' => $this->constants, 'ASS_Survey_Report' => $this->survey_report ) ); $bootstrap_deps = array( 'ASS_Constants' => $this->constants, 'ASS_Survey_CPT' => $this->survey_cpt, 'ASS_Survey_Response_CPT' => $this->survey_response_cpt, 'ASS_Initial_Guided_Tour' => $this->initial_guided_tour, 'ASS_Survey_Entry_Guided_Tour' => $this->survey_entry_guided_tour ); $this->bootstrap = ASS_Bootstrap::instance( $bootstrap_deps ); } /** * Run the plugin. This is the main "method controller", this is where the various processes * are being routed to the appropriate models to handle them. * * @since 1.0.0 * @access private */ private function _exe() { /* |-------------------------------------------------------------------------- | Internationalization |-------------------------------------------------------------------------- */ add_action( 'plugins_loaded' , array( $this->i18n , 'load_plugin_textdomain' ) ); /* |-------------------------------------------------------------------------- | Bootstrap |-------------------------------------------------------------------------- */ register_activation_hook( __FILE__ , array( $this->bootstrap , 'activate_plugin' ) ); register_deactivation_hook( __FILE__ , array( $this->bootstrap , 'deactivate_plugin' ) ); // Execute plugin initialization ( plugin activation ) on every newly created site in a multi site set up add_action( 'wpmu_new_blog' , array( $this->bootstrap , 'new_mu_site_init' ) , 10 , 6 ); add_action( 'init' , array( $this->bootstrap , 'initialize' ) ); add_action( 'init' , array( $this , 'register_ajax_handlers' ) ); /* |-------------------------------------------------------------------------- | Load JS and CSS Scripts |-------------------------------------------------------------------------- */ add_action( 'admin_enqueue_scripts' , array( $this->script_loader , 'load_backend_scripts' ) , 10 , 1 ); add_action( 'wp_enqueue_scripts' , array( $this->script_loader , 'load_frontend_scripts' ) ); /* |-------------------------------------------------------------------------- | WP Integration |-------------------------------------------------------------------------- */ // Add custom action links for the plugin in the plugin listings add_filter( 'plugin_action_links' , array( $this->bootstrap , 'plugin_listing_custom_action_links' ) , 10 , 2 ); /* |-------------------------------------------------------------------------- | Survey |-------------------------------------------------------------------------- */ // Survey add_action( 'add_meta_boxes' , array( $this->survey_cpt , 'register_survey_cpt_custom_meta_boxes' ) ); add_action( 'save_post' , array( $this->survey_cpt , 'save_post' ) , 10 , 1 ); add_action( 'delete_post' , array( $this->survey_cpt , 'clean_up_survey_data' ) , 10 , 1 ); // Survey CPT Listing Mods add_filter( 'bulk_actions-edit-as_survey' , array( $this->survey_cpt , 'remove_bulk_edit_on_survey_listing' ) , 10 , 1 ); add_filter( 'post_row_actions' , array( $this->survey_cpt , 'remove_quick_edit_on_survey_listing' ) , 10 , 1 ); add_filter( 'manage_as_survey_posts_columns' , array( $this->survey_cpt , 'add_survey_listing_column' ) , 10 , 1 ); add_action( 'manage_as_survey_posts_custom_column' , array( $this->survey_cpt , 'add_survey_listing_column_data' ) , 11 , 2 ); // Survey CTA add_action( 'as_survey_before_survey', array( $this->survey , 'render_survey_cta' ) , 10 , 2 ); // Survey popup add_action( 'woocommerce_thankyou' , array( $this->survey , 'render_survey_popup' ) , 10 , 1 ); // Survey Thank You add_action( 'as_survey_after_survey' , array( $this->survey , 'render_survey_thank_you' ) , 10 , 2 ); /* |-------------------------------------------------------------------------- | Survey Response |-------------------------------------------------------------------------- */ // Custom Survey Response CPT Columns add_filter( 'manage_as_survey_response_posts_columns' , array( $this->survey_response_cpt , 'add_survey_listing_custom_columns' ) , 10 , 1 ); add_action( 'manage_as_survey_response_posts_custom_column' , array( $this->survey_response_cpt , 'add_survey_listing_custom_columns_data' ) , 10 , 2 ); // Survey Response add_action( 'add_meta_boxes' , array( $this->survey_response_cpt , 'register_survey_response_cpt_custom_meta_boxes' ) ); // Survey Report add_filter( 'woocommerce_admin_reports' , array( $this->survey_report , 'after_sale_survey_report' ) , 10 , 1 ); // Print Admin Notice On The Survey CPT Single Entry Admin Page If Survey Is On Read Only Mode ( Meaning Already Have Responses ) add_action( 'admin_notices' , array( $this->survey_cpt , 'survey_read_only_notice' ) ); /* |-------------------------------------------------------------------------- | Settings |-------------------------------------------------------------------------- */ // Register Settings Page add_filter( "woocommerce_get_settings_pages" , array( $this->bootstrap , 'initialize_plugin_settings_page' ) , 10 , 1 ); /* |-------------------------------------------------------------------------- | Admin Status |-------------------------------------------------------------------------- */ // Render Admin Status add_action( 'woocommerce_system_status_report' , array( $this->admin_status , 'render_ass_template_status' ) ); } /** * Register the various ajax interfaces the plugin exposes. This is the main controller for ajax interfaces. * * @since 1.0.0 * @access public */ public function register_ajax_handlers() { // TODO: Add nonces to ajax interfaces, specially form submission // Plugin Help Pointers add_action( 'wp_ajax_ass_close_initial_guided_tour' , array( $this->initial_guided_tour , 'ass_close_initial_guided_tour' ) ); add_action( 'wp_ajax_ass_close_survey_entry_guided_tour' , array( $this->survey_entry_guided_tour , 'ass_close_survey_entry_guided_tour' ) ); // Survey CPT add_action( 'wp_ajax_as_survey_save_survey_cta' , array( $this->survey_cpt , 'as_survey_save_survey_cta' ) ); add_action( 'wp_ajax_as_survey_save_survey_thankyou' , array( $this->survey_cpt , 'as_survey_save_survey_thankyou' ) ); add_action( 'wp_ajax_as_survey_load_survey_questions_on_datatables' , array( $this->survey_cpt , 'as_survey_load_survey_questions_on_datatables' ) ); add_action( 'wp_ajax_as_survey_get_new_question_order_number' , array( $this->survey_cpt , 'as_survey_get_new_question_order_number' ) ); add_action( 'wp_ajax_as_survey_load_survey_question_choices' , array( $this->survey_cpt , 'as_survey_load_survey_question_choices' ) ); add_action( 'wp_ajax_as_survey_get_question_data' , array( $this->survey_cpt , 'as_survey_get_question_data' ) ); add_action( 'wp_ajax_as_survey_save_survey_question' , array( $this->survey_cpt , 'as_survey_save_survey_question' ) ); add_action( 'wp_ajax_as_survey_delete_survey_question' , array( $this->survey_cpt , 'as_survey_delete_survey_question' ) ); // Survey Response CPT add_action( 'wp_ajax_as_survey_save_survey_response' , array( $this->survey_response_cpt , 'as_survey_save_survey_response' ) ); add_action( 'wp_ajax_nopriv_as_survey_save_survey_response' , array( $this->survey_response_cpt , 'as_survey_save_survey_response' ) ); // Survey Report add_action( 'wp_ajax_as_survey_record_survey_offer_attempt' , array( $this->ajax_interface , 'as_survey_record_survey_offer_attempt' ) ); add_action( 'wp_ajax_as_survey_record_survey_uptake' , array( $this->ajax_interface , 'as_survey_record_survey_uptake' ) ); add_action( 'wp_ajax_as_survey_record_survey_completion' , array( $this->ajax_interface , 'as_survey_record_survey_completion' ) ); add_action( 'wp_ajax_nopriv_as_survey_record_survey_offer_attempt' , array( $this->ajax_interface , 'as_survey_record_survey_offer_attempt' ) ); add_action( 'wp_ajax_nopriv_as_survey_record_survey_uptake' , array( $this->ajax_interface , 'as_survey_record_survey_uptake' ) ); add_action( 'wp_ajax_nopriv_as_survey_record_survey_completion' , array( $this->ajax_interface , 'as_survey_record_survey_completion' ) ); add_action( 'wp_ajax_as_survey_get_survey_responses_report' , array( $this->survey_report , 'as_survey_get_survey_responses_report' ) ); add_action( 'wp_ajax_as_survey_get_survey_responses_list' , array( $this->survey_report , 'as_survey_get_survey_responses_list' ) ); } } } /** * Main instance of After Sale Surveys. * * Returns the main instance of After Sale Surveys to prevent the need to use globals. * * @since 1.0.0 * @return After_Sale_Surveys */ function AS_Surveys() { return After_Sale_Surveys::instance(); } // Global for backwards compatibility. $GLOBALS[ 'after_sale_surveys' ] = AS_Surveys();