parent_theme ); } $theme_version = $theme_info->display( 'Version' ); return $theme_version; } /** * Register the required plugins for this theme. * * @link https://github.com/TGMPA/TGM-Plugin-Activation */ function befold_register_required_plugins() { // Required plugin. $plugins = array( array( 'name' => 'Bethememe Plugin', 'slug' => 'bethemesme', 'required' => false, 'version' => '1.0.0' ), array( 'name' => 'Elementor', 'slug' => 'elementor', ), array( 'name' => 'Redux Framework', 'slug' => 'redux-framework', ), array( 'name' => 'One Click Importer', 'slug' => 'one-click-demo-import', ), ); // Array of configuration settings. $config = array( 'id' => 'befold_tgmpa', 'default_path' => '', 'menu' => 'befold-install-plugins', 'parent_slug' => 'themes.php', 'capability' => 'edit_theme_options', 'has_notices' => true, 'dismissable' => true, 'is_automatic' => true ); tgmpa( $plugins, $config ); } add_action( 'tgmpa_register', 'befold_register_required_plugins' ); /** * The notification to upgrade to Pro version. * * @return string $output The upgrade notification. */ if (!function_exists('bethemes_premium_info')){ function bethemes_premium_info() { $output = sprintf ( '%1$s BeFold Pro %3$s %5$s %6$s.', esc_html__( 'Upgrade to', 'befold' ), esc_url( 'http://betheme.me/themes/befold/' ), esc_html__( 'to enjoy', 'befold' ), esc_url( 'http://betheme.me/themes/befold/?TB_iframe=true&width=1024&height=800' ), esc_html__( 'Premium Features', 'befold' ), esc_html__( 'and support continued development', 'befold' ) ); return $output; } } /** * Only show blog posts in search results. * * @param array $query The WP_Query object. */ function befold_search_filter( $query ) { if ( ! is_admin() && $query->is_main_query() ) { if ( $query->is_search ) { $query->set( 'post_type', array( 'post' ) ); } } } add_filter( 'pre_get_posts', 'befold_search_filter' ); /** * Get the current URL of the page being viewed. * * @global object $wp * @return string $current_url Current URL. */ function befold_get_current_url() { global $wp; if ( empty( $_SERVER['QUERY_STRING'] ) ) $current_url = trailingslashit( home_url( $wp->request ) ); else $current_url = add_query_arg( $_SERVER['QUERY_STRING'], '', trailingslashit( home_url( $wp->request ) ) ); return $current_url; } /** * Filter to remove thumbnail image dimension attributes. * * @return string $html The HTML codes without width and height attributes. */ function befold_remove_thumbnail_dimensions( $html, $post_id, $post_image_id ) { $html = preg_replace( '/(width|height)=\"\d*\"\s/', '', $html ); return $html; } add_filter( 'post_thumbnail_html', 'befold_remove_thumbnail_dimensions', 10, 3 ); /** * Change the excerpt length. */ function befold_custom_excerpt_length( $length ) { return 60; } add_filter( 'excerpt_length', 'befold_custom_excerpt_length', 999 ); /** * Apply Themes Slug Filter */ apply_filters( 'betm_get_theme_slug' , 'befold'); /** * Change the excerpt more string at the end. */ function befold_new_excerpt_more( $more ) { return ' …'; } add_filter( 'excerpt_more', 'befold_new_excerpt_more' ); /** * Include the Portfolio details template. */ function befold_ajax_portfolio() { get_template_part( 'template-parts/content', 'ajax-portfolio' ); wp_die(); } add_action( 'wp_ajax_ajax_portfolio', 'befold_ajax_portfolio' ); add_action( 'wp_ajax_nopriv_ajax_portfolio', 'befold_ajax_portfolio' ); /** * Set/unset post as image post type if post has thumbnail. * * @param int $post_id The post ID. */ function befold_set_post_type( $post_id ) { global $pagenow; if ( in_array( $pagenow, array( 'post.php', 'post-new.php' ) ) ) { if ( get_post_type( $post_id ) == 'post' ) { if ( has_post_thumbnail( $post_id ) ) { set_post_format( $post_id, 'image' ); } if ( ! has_post_thumbnail( $post_id ) ) { set_post_format( $post_id, '' ); } } } } add_action( 'save_post', 'befold_set_post_type', 10, 3 ); /** * Remove Recent Comments Widget style from header. */ function befold_remove_recent_comments_style() { global $wp_widget_factory; remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) ); } add_action( 'widgets_init', 'befold_remove_recent_comments_style' ); /** * Change the font size for Tag Cloud widget. */ function befold_custom_tag_cloud_font( $args ) { $custom_args = array( 'smallest' => 10, 'largest' => 10 ); $args = wp_parse_args( $args, $custom_args ); return $args; } add_filter( 'widget_tag_cloud_args', 'befold_custom_tag_cloud_font' ); /** * Update option after Customizer save. */ function befold_customize_save_after() { update_option( 'blogname', BeFold_ReduxOption::get_option( 'general_site_title' ) ); } add_action( 'customize_save_after', 'befold_customize_save_after' ); /** * Set option data when Customizer controls are initialized. */ function befold_customize_controls_init() { set_theme_mod( 'general_site_title', get_bloginfo( 'name' ) ); set_theme_mod( 'general_front_page', get_option( 'page_on_front' ) ); set_theme_mod( 'general_posts_page', get_option( 'page_for_posts' ) ); } add_action( 'customize_controls_init', 'befold_customize_controls_init' ); /** * Enqueue scripts and styles for admin pages. */ function befold_admin_scripts() { global $pagenow; if ( ! is_admin() ) { return; } if ( in_array( $pagenow, array( 'post.php', 'post-new.php', 'themes.php', 'update-core.php' ) ) ) { wp_enqueue_script( 'befold-admin-script', get_template_directory_uri() . '/assets/js/admin.js', array(), befold_get_version(), true ); } // Localize the script with new data. wp_localize_script( 'befold-admin-script', 'be_admin_vars', array( 'upgrade_available' => esc_html__( 'Upgrade to Pro Version', 'befold' ), 'upgrade_info' => bethemes_premium_info() ) ); } add_action( 'admin_enqueue_scripts', 'befold_admin_scripts' ); /** * Get font icons list. * * @return array $font_icons */ function befold_menu_fallback( $args ) { if ( current_user_can( 'manage_options' ) ) { extract( $args ); $fb_output = null; if ( $container ) { $fb_output = '<' . $container; if ( $container_id ) $fb_output .= ' id="' . $container_id . '"'; if ( $container_class ) $fb_output .= ' class="' . $container_class . '"'; $fb_output .= '>'; } $fb_output .= '