load_hooks(); $this->register_upgrader(); } /** * Load initial hooks. */ private function load_hooks() { // actions. add_action( 'init', array( $this, 'add_theme_templates' ) ); add_action( 'after_setup_theme', array( $this, 'theme_setup' ) ); add_action( 'after_theme_setup', array( $this, 'content_width' ), 0 ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'admin_notices', array( $this, 'notice_install_plugin' ) ); add_action( 'wp_ajax_accountra_set_admin_notice_viewed', array( $this, 'notice_closed' ) ); add_action( 'admin_init', array( $this, 'load_editor_styles' ) ); add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'init', array( $this, 'register_block_patterns' ), 9 ); add_action( 'init', array( $this, 'register_block_styles' ), 9 ); add_action( 'admin_enqueue_scripts', array( $this, 'dashboard_scripts' ) ); // filters. add_filter( 'excerpt_length', array( $this, 'excerpt_length' ) ); add_filter( 'excerpt_more', array( $this, 'excerpt_elipsis' ) ); add_filter( 'gutenverse_template_path', array( $this, 'template_path' ), null, 3 ); add_filter( 'gutenverse_themes_template', array( $this, 'add_template' ), 10, 2 ); add_filter( 'gutenverse_block_config', array( $this, 'default_font' ), 10 ); add_filter( 'gutenverse_font_header', array( $this, 'default_header_font' ) ); add_filter( 'gutenverse_global_css', array( $this, 'global_header_style' ) ); } /** * Generate Global Font * * @param string $value Value of the option. * * @return string */ public function global_header_style( $value ) { $theme_name = get_stylesheet(); $global_variable = get_option( 'gutenverse-global-variable-font-' . $theme_name ); if ( empty( $global_variable ) && function_exists( 'gutenverse_global_font_style_generator' ) ) { $font_variable = $this->default_font_variable(); $value .= \gutenverse_global_font_style_generator( $font_variable ); } return $value; } /** * Header Font. * * @param mixed $value Value of the option. * * @return mixed Value of the option. */ public function default_header_font( $value ) { if ( ! $value ) { $value = array( array( 'value' => 'Alfa Slab One', 'type' => 'google', 'weight' => 'bold', ), ); } return $value; } /** * Alter Default Font. * * @param array $config Array of Config. * * @return array */ public function default_font( $config ) { if ( empty( $config['globalVariable']['fonts'] ) ) { $config['globalVariable']['fonts'] = $this->default_font_variable(); return $config; } if ( ! empty( $config['globalVariable']['fonts'] ) ) { // Handle existing fonts. $theme_name = get_stylesheet(); $initial_font = get_option( 'gutenverse-font-init-' . $theme_name ); if ( ! $initial_font ) { $config['globalVariable']['fonts'] = array_merge( $config['globalVariable']['fonts'], $this->default_font_variable() ); update_option( 'gutenverse-font-init-' . $theme_name, true ); } } return $config; } /** * Default Font Variable. * * @return array */ public function default_font_variable() { return array( array( 'id' => 'h1-font', 'name' => 'H1 Font', 'font' => array( 'font' => array( 'label' => 'Poppins', 'value' => 'Poppins', 'type' => 'google', ), 'size' => array( 'Desktop' => array( 'unit' => 'px', 'point' => '52', ), 'Tablet' => array( 'unit' => 'px', 'point' => '42', ), 'Mobile' => array( 'unit' => 'px', 'point' => '32', ), ), 'lineHeight' => array( 'Desktop' => array( 'unit' => 'em', 'point' => '1.3', ), ), 'weight' => '500', ), ), array( 'id' => 'h2-font', 'name' => 'H2 Font', 'font' => array( 'font' => array( 'label' => 'Poppins', 'value' => 'Poppins', 'type' => 'google', ), 'size' => array( 'Desktop' => array( 'unit' => 'px', 'point' => '32', ), 'Tablet' => array( 'unit' => 'px', 'point' => '32', ), 'Mobile' => array( 'unit' => 'px', 'point' => '24', ), ), 'lineHeight' => array( 'Desktop' => array( 'unit' => 'em', 'point' => '1.2', ), ), 'weight' => '500', 'transform' => 'default', ), ), array( 'id' => 'h3-font', 'name' => 'H3 Font', 'font' => array( 'font' => array( 'label' => 'Poppins', 'value' => 'Poppins', 'type' => 'google', ), 'size' => array( 'Desktop' => array( 'unit' => 'px', 'point' => '20', ), 'Tablet' => array( 'unit' => 'px', 'point' => '20', ), 'Mobile' => array( 'unit' => 'px', 'point' => '18', ), ), 'lineHeight' => array( 'Desktop' => array( 'unit' => 'em', 'point' => '1.2', ), ), 'weight' => '500', ), ), array( 'id' => 'h4-font', 'name' => 'H4 Font', 'font' => array( 'font' => array( 'label' => 'Heebo', 'value' => 'Heebo', 'type' => 'google', ), 'size' => array( 'Desktop' => array( 'unit' => 'px', 'point' => '16', ), 'Tablet' => array( 'unit' => 'px', 'point' => '16', ), 'Mobile' => array( 'unit' => 'px', 'point' => '16', ), ), 'lineHeight' => array( 'Desktop' => array( 'unit' => 'em', 'point' => '1.2', ), ), 'weight' => '400', ), ), array( 'id' => 'h5-font', 'name' => 'H5 Font', 'font' => array( 'font' => array( 'label' => 'Poppins', 'value' => 'Poppins', 'type' => 'google', ), 'size' => array( 'Desktop' => array( 'unit' => 'px', 'point' => '18', ), 'Tablet' => array( 'unit' => 'px', 'point' => '18', ), 'Mobile' => array( 'unit' => 'px', 'point' => '16', ), ), 'lineHeight' => array( 'Desktop' => array( 'unit' => 'em', 'point' => '1.2', ), ), 'weight' => '400', 'transform' => 'default', ), ), array( 'id' => 'h6-font', 'name' => 'H6 Font', 'font' => array( 'font' => array( 'label' => 'Poppins', 'value' => 'Poppins', 'type' => 'google', ), 'size' => array( 'Desktop' => array( 'unit' => 'px', 'point' => '20', ), 'Tablet' => array( 'unit' => 'px', 'point' => '20', ), 'Mobile' => array( 'unit' => 'px', 'point' => '20', ), ), 'lineHeight' => array( 'Desktop' => array( 'unit' => 'em', 'point' => '1.2', ), ), 'weight' => '400', 'transform' => 'default', ), ), array( 'id' => 'body-text', 'name' => 'Body Text', 'font' => array( 'font' => array( 'label' => 'Heebo', 'value' => 'Heebo', 'type' => 'google', ), 'size' => array( 'Desktop' => array( 'unit' => 'px', 'point' => '16', ), 'Tablet' => array( 'unit' => 'px', 'point' => '16', ), 'Mobile' => array( 'unit' => 'px', 'point' => '14', ), ), 'lineHeight' => array( 'Desktop' => array( 'unit' => 'em', 'point' => '1.7', ), ), 'weight' => '300', ), ), array( 'id' => 'button1-font', 'name' => 'Button1 Font', 'font' => array( 'font' => array( 'label' => 'Poppins', 'value' => 'Poppins', 'type' => 'google', ), 'size' => array( 'Desktop' => array( 'unit' => 'px', 'point' => '16', ), 'Tablet' => array( 'unit' => 'px', 'point' => '16', ), 'Mobile' => array( 'unit' => 'px', 'point' => '12', ), ), 'lineHeight' => array( 'Desktop' => array( 'unit' => 'em', 'point' => '1', ), ), 'spacing' => array( 'Desktop' => '0.1', ), 'weight' => '500', 'transform' => 'uppercase', 'spacing' => 'uppercase', ), ), array( 'id' => 'button2-font', 'name' => 'Button2 Font', 'font' => array( 'font' => array( 'label' => 'Poppins', 'value' => 'Poppins', 'type' => 'google', ), 'size' => array( 'Desktop' => array( 'unit' => 'px', 'point' => '14', ), 'Tablet' => array( 'unit' => 'px', 'point' => '14', ), 'Mobile' => array( 'unit' => 'px', 'point' => '14', ), ), 'lineHeight' => array( 'Desktop' => array( 'unit' => 'em', 'point' => '1', ), ), 'spacing' => array( 'Desktop' => '0.1', ), 'weight' => '500', 'transform' => 'uppercase', ), ), array( 'id' => 'iconlist1-font', 'name' => 'Iconlist1 Font', 'font' => array( 'font' => array( 'label' => 'Heebo', 'value' => 'heebo', 'type' => 'google', ), 'size' => array( 'Desktop' => array( 'unit' => 'px', 'point' => '16', ), 'Tablet' => array( 'unit' => 'px', 'point' => '16', ), 'Mobile' => array( 'unit' => 'px', 'point' => '14', ), ), 'lineHeight' => array( 'Desktop' => array( 'unit' => 'em', 'point' => '1.7', ), ), 'weight' => '400', ), ), array( 'id' => 'iconlist2-font', 'name' => 'Iconlist2 Font', 'font' => array( 'font' => array( 'label' => 'Heebo', 'value' => 'heebo', 'type' => 'google', ), 'size' => array( 'Desktop' => array( 'unit' => 'px', 'point' => '16', ), 'Tablet' => array( 'unit' => 'px', 'point' => '16', ), 'Mobile' => array( 'unit' => 'px', 'point' => '16', ), ), 'lineHeight' => array( 'Desktop' => array( 'unit' => 'em', 'point' => '1.7', ), ), 'weight' => '300', ), ), ); } /** * Add Template to Editor. * * @param array $template_files Path to Template File. * @param array $template_type Template Type. * * @return array */ public function add_template( $template_files, $template_type ) { $directory = get_template_directory(); if ( 'wp_template' === $template_type ) { $new_templates = array( 'about', 'blog', 'cases', 'contact', 'faq', 'pricing', 'service', ); foreach ( $new_templates as $template ) { $template_files[] = array( 'slug' => $template, 'path' => $directory . "/gutenverse-templates/templates/{$template}.html", 'theme' => get_template(), 'type' => 'wp_template', ); } } return $template_files; } /** * Use gutenverse template file instead. * * @param string $template_file Path to Template File. * @param string $theme_slug Theme Slug. * @param string $template_slug Template Slug. * * @return string */ public function template_path( $template_file, $theme_slug, $template_slug ) { $directory = get_template_directory(); switch ( $template_slug ) { case '404': return $directory . '/gutenverse-templates/templates/404.html'; case 'about': return $directory . '/gutenverse-templates/templates/about.html'; case 'archive': return $directory . '/gutenverse-templates/templates/archive.html'; case 'blog': return $directory . '/gutenverse-templates/templates/blog.html'; case 'cases': return $directory . '/gutenverse-templates/templates/cases.html'; case 'contact': return $directory . '/gutenverse-templates/templates/contact.html'; case 'faq': return $directory . '/gutenverse-templates/templates/faq.html'; case 'front-page': return $directory . '/gutenverse-templates/templates/front-page.html'; case 'index': return $directory . '/gutenverse-templates/templates/index.html'; case 'page': return $directory . '/gutenverse-templates/templates/page.html'; case 'pricing': return $directory . '/gutenverse-templates/templates/pricing.html'; case 'search': return $directory . '/gutenverse-templates/templates/search.html'; case 'service': return $directory . '/gutenverse-templates/templates/service.html'; case 'single': return $directory . '/gutenverse-templates/templates/single.html'; case 'header': return $directory . '/gutenverse-templates/parts/header.html'; case 'footer': return $directory . '/gutenverse-templates/parts/footer.html'; } return $template_file; } /** * Register Block Pattern. */ public function register_block_patterns() { new Block_Patterns(); } /** * Register Block Style. */ public function register_block_styles() { new Block_Styles(); } /** * Register Upgrader. */ public function register_upgrader() { new Upgrader(); } /** * Excerpt Elipsis. * * @param string $more . * * @return string */ public function excerpt_elipsis( $more ) { if ( is_admin() ) { return $more; } return ''; } /** * Excerpt Length. * * @param int $length . * * @return int */ public function excerpt_length( $length ) { if ( is_admin() ) { return $length; } return 100; } /** * Notice Closed */ public function notice_closed() { update_user_meta( get_current_user_id(), 'gutenverse_install_notice', 'true' ); die; } /** * Show notification to install Gutenverse Plugin. */ public function notice_install_plugin() { // Skip if gutenverse block activated. if ( defined( 'GUTENVERSE' ) ) { return; } // Skip if gutenverse pro activated. if ( defined( 'GUTENVERSE_PRO' ) ) { return; } $screen = get_current_screen(); if ( isset( $screen->parent_file ) && 'plugins.php' === $screen->parent_file && 'update' === $screen->id ) { return; } if ( 'true' === get_user_meta( get_current_user_id(), 'gutenverse_install_notice', true ) ) { return; } $button_text = __( 'Check it Now!', 'accountra' ); $button_link = wp_nonce_url( self_admin_url( 'themes.php?page=accountra-dashboard' ), 'install-plugin_gutenverse' ); ?>