Helper = Helpers::getInstance(); $this->Cookie = CookiesHandler::getInstance(); // Load Onboarding Wizard only in admin area if ( is_admin() ) { new OnboardingWizard(); } // plugin activation hook register_activation_hook( ADQS_DIRECTORY_FILE, [ $this, 'plugin_activate' ] ); $this->init_appsero_sdk(); $this->update_setting(); add_action( 'activated_plugin', [ $this, 'plugin_activated' ] ); add_action( 'doing_it_wrong_trigger_error', [ $this, 'textdomain_notice' ], 10, 3 ); add_action( 'plugins_loaded', [ $this, 'init_plugin' ] ); add_action( 'init', [ $this, 'permalinks_flushed' ] ); add_action( 'init', [ $this, 'blocks_init' ], 10090 ); } public function plugin_activated( $plugin ) { if ( $plugin === plugin_basename( ADQS_DIRECTORY_FILE ) ) { wp_redirect( admin_url( 'admin.php?page=adirectory-setup' ) ); exit; } } public function init_appsero_sdk() { if ( ! class_exists( 'Appsero\Client' ) ) { require_once __DIR__ . '/appsero/src/Client.php'; } $client = new Appsero\Client( 'f5f86071-9f3d-43e2-b259-602b34155ffd', 'aDirectory - Directory Listing WordPress Plugin', ADQS_DIRECTORY_FILE ); $client->insights()->init(); } /** * Method blocks_init * * @return void */ public function blocks_init() { if ( ! get_option( 'adqs_admin_settings' ) ) { $adqs_settings_array = Setting::get_settings_fields(); $admin_setting = []; if ( is_array( $adqs_settings_array ) ) { foreach ( $adqs_settings_array as $single_setting ) { if ( isset( $single_setting['option_name'] ) ) { $admin_setting[ $single_setting['option_name'] ] = isset( $single_setting['value'] ) ? $single_setting['value'] : ''; } } update_option( 'adqs_admin_settings', $admin_setting ); } update_option( 'adqs_admin_settings', $admin_setting ); } } /** * Method plugin activate * * @return void */ public function plugin_activate() { update_option( 'adqs_permalinks_flushed', 0 ); $this->adqs_onborading_pages(); $this->create_default_directory(); } /** * Create a default Listing term on plugin activation * * @return void */ private function create_default_directory(): void { // Don't create default directory if onboarding is already completed if ( get_option( 'adqs_onboarding_completed' ) ) { return; } require_once ADQS_DIRECTORY_FUNCTIONS . '/directory-functions.php'; $directory_manager = new \ADQS_Directory\Database\Custom_Posts\Directory(); $directory_manager->register_taxonomy(); $directories = adqs_get_directories(); if ( empty( $directories ) ) { $directory_id = adqs_upsert_directory( [ 'singular_name' => 'Listing', 'plural_name' => 'Listings', 'slug' => 'listing', ] ); if ( ! is_wp_error( $directory_id ) ) { update_term_meta( $directory_id, 'adqs_metafields_types', DefaultDatas::builder() ); } } $directory_manager->register_post_types(); flush_rewrite_rules(); } public function update_setting() { $option = get_option( 'adqs_admin_settings', [] ); $adqs_email_templates = DefaultDatas::email_templates(); if ( ! array_key_exists( 'select_currency', $option ) ) { $option['select_currency'] = 'USD__$__before'; } if ( ! array_key_exists( 'adqs_admin_templates', $option ) ) { $option['adqs_admin_templates'] = $adqs_email_templates; } if ( ! array_key_exists( 'adqs_admin_emails_triggers', $option ) ) { $option['adqs_admin_emails_triggers'] = [ 'new_user_reg', 'new_listing_sub', 'new_listing_up', 'order_created', 'order_completed', ]; } if ( ! array_key_exists( 'adqs_user_emails_triggers', $option ) ) { $option['adqs_user_emails_triggers'] = [ 'new_user_reg', 'new_listing_sub', 'listing_is_approved', 'listing_about_expire', 'listing_expired', 'order_cancelled', 'order_failed', 'order_created', 'order_pending', 'order_completed', ]; } if ( ! array_key_exists( 'from_email_name', $option ) ) { $option['from_email_name'] = get_bloginfo( 'name' ); } if ( ! array_key_exists( 'from_email_address', $option ) ) { $option['from_email_address'] = get_option( 'admin_email' ); } if ( ! array_key_exists( 'enable_bank_transfer', $option ) ) { $option['enable_bank_transfer'] = 1; } if ( ! array_key_exists( 'enable_guest_listing', $option ) ) { $option['enable_guest_listing'] = 0; } if ( ! array_key_exists( 'listing_expiry_date', $option ) ) { $option['listing_expiry_date'] = 365; } if ( ! array_key_exists( 'enable_guest_listing_post_approv', $option ) ) { $option['enable_guest_listing_post_approv'] = 1; } // Default: enable review system by default if ( ! array_key_exists( 'enable_review', $option ) ) { $option['enable_review'] = 1; } if ( ! array_key_exists( 'enable_review_comment_reply', $option ) ) { $option['enable_review_comment_reply'] = 1; } // Default: allow guests to reply unless explicitly restricted if ( ! array_key_exists( 'enable_review_comment_reply_only_logged_in', $option ) ) { $option['enable_review_comment_reply_only_logged_in'] = 0; } // Default: allow guests to submit reviews unless explicitly restricted if ( ! array_key_exists( 'enable_review_comment_only_logged_in', $option ) ) { $option['enable_review_comment_only_logged_in'] = 0; } // Default expiry settings if ( ! array_key_exists( '_expiry_duration_type', $option ) ) { $option['_expiry_duration_type'] = ''; } if ( ! array_key_exists( '_expiry_notification', $option ) ) { $option['_expiry_notification'] = 7; } // Default permanent deletion settings if ( ! array_key_exists( '_permanent_delete_days', $option ) ) { $option['_permanent_delete_days'] = 15; } if ( ! array_key_exists( 'terms_condition_text', $option ) ) { $option['terms_condition_text'] = sprintf( /* translators: %s is a placeholder for the Terms and Conditions link text */ __( 'By clicking the "Sign Up" button you are agreeing to the %s.', 'adirectory' ), '' . esc_html__( 'Terms and Conditions', 'adirectory' ) . '' ); } if ( ! array_key_exists( 'default_preview_image', $option ) ) { $default_preview_image = plugins_url( 'assets/frontend/img/default-placeholder.jpg', ADQS_DIRECTORY_FILE ); $option['default_preview_image'] = $default_preview_image; } update_option( 'adqs_admin_settings', $option ); } /** * Method adqs_onborading_pages * * @return void */ public function adqs_onborading_pages() { $option_key = 'adqs_onboarding_pages'; if ( empty( get_option( $option_key ) ) ) { $insertPages = DefaultDatas::onborading_pages(); $allPages = []; if ( is_array( $insertPages ) && ! empty( $insertPages ) ) { foreach ( $insertPages as $insert ) { $get_page_id = wp_insert_post( [ 'post_title' => sprintf( esc_html__( '%s', 'adirectory' ), $insert['post_title'] ), 'post_content' => $insert['post_content'], 'post_status' => $insert['post_status'], 'post_type' => $insert['post_type'], ] ); if ( ! empty( $get_page_id ) ) { $allPages[ $insert['page_key'] ] = $get_page_id; } } } if ( ! empty( $allPages ) ) { update_option( $option_key, $allPages ); } } } /** * Method permalinks_flushed * * @return void */ public function permalinks_flushed() { $this->load_translation(); if ( ! get_option( 'adqs_permalinks_flushed' ) ) { flush_rewrite_rules( false ); update_option( 'adqs_permalinks_flushed', 1 ); } } /** * Initializes a singleton instance */ public static function instance() { static $instance = false; if ( ! $instance ) { $instance = new self(); } return $instance; } /** * Include Files */ public function include_files() { require_once ADQS_DIRECTORY_INC . '/Functions.php'; } public function textdomain_notice( $trigger, $function, $message ) { if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) { return $trigger; } $textDomain = 'adirectory'; if ( strpos( $function, '_load_textdomain_just_in_time' ) !== false && strpos( $message, 'Translation loading for the' ) !== false && strpos( $message, $textDomain ) !== false && strpos( $message, 'domain was triggered too early' ) !== false && strpos( $message, 'some code in the plugin or theme running too early' ) !== false && strpos( $message, 'Translations should be loaded at the' ) !== false && strpos( $message, 'init' ) !== false ) { return false; } return $trigger; } /** * Load translation for both server and client side */ public function load_translation() { load_plugin_textdomain( 'adirectory', false, dirname( ADQS_DIRECTORY_PLUGIN_BASE ) . '/languages' ); } /** * Initialize the plugin * * @return void */ public function init_plugin() { // load functions php files $this->include_files(); // loaded all required plugin new Database(); new Frontend(); new Addons(); new Formhandler(); if ( is_admin() ) { new Admin(); } } } /* ADQS_Directory Loder */ function AD() { return ADQS_Init::instance(); } AD();