media_manager = new Samplesaz_Media_Manager(); $this->post_generator = new Samplesaz_Post_Generator( $this->media_manager ); $this->product_generator = new Samplesaz_Product_Generator( $this->media_manager ); $this->comment_generator = new Samplesaz_Comment_Generator(); $this->cleaner = new Samplesaz_Cleaner(); $this->metabox = new Samplesaz_Metabox(); $this->color_swatches = new Samplesaz_Color_Swatches(); $this->admin = new Samplesaz_Admin( $this ); $this->ajax = new Samplesaz_Ajax( $this ); $this->register_hooks(); } /** * Register WordPress hooks. * * @return void */ private function register_hooks() { if ( $this->is_woocommerce_active() ) { $this->color_swatches->register_hooks(); } if ( is_admin() ) { $this->admin->register_hooks(); $this->metabox->register_hooks(); $this->ajax->register_hooks(); } } /** * Check if WooCommerce is active. * * @return bool */ public function is_woocommerce_active() { return class_exists( 'WooCommerce' ) && function_exists( 'wc_get_product' ); } /** * Check if Yoast SEO is active. * * @return bool */ public function is_yoast_active() { return defined( 'WPSEO_VERSION' ) || class_exists( 'WPSEO_Options' ); } /** * Check if Rank Math SEO is active. * * @return bool */ public function is_rankmath_active() { return defined( 'RANK_MATH_VERSION' ) || class_exists( 'RankMath' ); } /** * Get active WooCommerce currency code or empty string. * * @return string */ public function get_wc_currency() { if ( $this->is_woocommerce_active() && function_exists( 'get_woocommerce_currency' ) ) { return (string) get_woocommerce_currency(); } return ''; } /** * Get default demo content language based on site locale / RTL. * * @return string 'fa' or 'en'. */ public function get_default_content_language() { $locale = function_exists( 'determine_locale' ) ? determine_locale() : get_locale(); if ( is_rtl() || 0 === strpos( (string) $locale, 'fa' ) ) { return 'fa'; } return 'en'; } /** * Get live counts of demo and preserved items. * * @return array */ public function get_demo_stats() { $demo_posts = $this->cleaner->get_demo_post_ids( 'post', false ); $demo_prods = $this->is_woocommerce_active() ? $this->cleaner->get_demo_post_ids( 'product', false ) : array(); $preserved = $this->cleaner->get_preserved_post_ids(); $comments = $this->cleaner->get_demo_comment_ids(); $media = $this->cleaner->get_demo_attachment_ids(); $trashed = $this->cleaner->get_trashed_items(); return array( 'posts' => count( $demo_posts ), 'products' => count( $demo_prods ), 'comments' => count( $comments ), 'media' => count( $media ), 'preserved' => count( $preserved ), 'trash' => count( $trashed ), ); } }