-
-
Save juanfra/117a3c5815caa862f9600661e4887930 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Smart by NiceThemes. | |
* | |
* Visual composer integration init. | |
* | |
* @package Smart | |
* @author NiceThemes <hello@nicethemes.com> | |
* @license GPL-2.0+ | |
* @link http://nicethemes.com/product/smart | |
* @copyright 2017 NiceThemes | |
* @since 1.0.0 | |
*/ | |
// If this file is called directly, abort. | |
if ( ! defined( 'WPINC' ) ) { | |
die; | |
} | |
if ( ! function_exists( 'nice_vc_integration_disable_updater' ) ) : | |
add_action( 'vc_before_init', 'nice_vc_integration_disable_updater' ); | |
/** | |
* Disable VC Updater. | |
* | |
* @since 1.0.0 | |
*/ | |
function nice_vc_integration_disable_updater() { | |
if ( ! function_exists( 'vc_manager' ) || ! method_exists( 'Vc_Manager', 'disableUpdater' ) ) { | |
return; | |
} | |
vc_manager()->disableUpdater(); | |
} | |
endif; | |
if ( ! function_exists( 'nice_vc_get_post_types' ) ) : | |
/** | |
* Enable VC for a list of post types. | |
* | |
* @since 1.0.0 | |
* | |
* @return array | |
*/ | |
function nice_vc_get_post_types() { | |
static $nice_vc_post_types = null; | |
if ( is_null( $nice_vc_post_types ) ) { | |
$nice_vc_post_types = array( | |
'page', | |
'post', | |
); | |
/** | |
* @hook nice_vc_post_types | |
* | |
* Hook in here to modify the list of post types we need to have | |
* enabled by default. | |
* | |
* @since 1.0.0 | |
*/ | |
$nice_vc_post_types = apply_filters( 'nice_vc_post_types', $nice_vc_post_types ); | |
} | |
return $nice_vc_post_types; | |
} | |
endif; | |
if ( ! function_exists( 'nice_vc_add_post_types_maybe' ) ) : | |
add_action( 'init', 'nice_vc_add_post_types_maybe' ); | |
/** | |
* Enable default VC post types. | |
* | |
* This function makes sure all post types returned by `nice_vc_get_post_types()` | |
* are set as editable by default for all user roles. After set as editable by | |
* default, a post type can be deselected for any user role without being | |
* forced to be editable again. This is necessary to make the list of post | |
* types flexible, and not force it to always be the same disregarding settings. | |
* | |
* @see nice_vc_get_post_types() | |
* @see Vc_Manager::setEditorPostTypes() | |
* | |
* @since 1.0.3 | |
*/ | |
function nice_vc_add_post_types_maybe() { | |
// Bail in public context. | |
if ( ! is_admin() ) { | |
return; | |
} | |
$vc_manager = vc_manager(); | |
$post_types = nice_vc_get_post_types(); | |
$added_post_types = get_option( '_nice_vc_added_post_types' ) ?: array(); // Get stored post type data. | |
$add_post_types = false; | |
$editable_roles = function_exists( 'get_editable_roles' ) ? get_editable_roles() : array(); | |
// Merge post types that are already in DB with our list. | |
$vc_manager->editor_post_types = array_values( array_unique( array_merge( vc_editor_post_types(), $post_types ) ) ); | |
// Set permissions over post types for all available roles. | |
foreach ( $editable_roles as $role => $settings ) { | |
$part = vc_role_access()->who( $role )->part( 'post_types' ); | |
if ( ! isset( $added_post_types[ $role ] ) ) { | |
$added_post_types[ $role ] = array(); | |
} | |
foreach ( $vc_manager->editor_post_types as $post_type ) { | |
// No need to add the post type if it was already set. | |
if ( in_array( $post_type, $added_post_types[ $role ], true ) ) { | |
continue; | |
} | |
// Set post as type checked by default. | |
$part->setCapRule( $post_type ); | |
$added_post_types[ $role ][] = $post_type; | |
$add_post_types = true; | |
} | |
} | |
// Update the list of added post types if needed. | |
if ( $add_post_types ) { | |
update_option( '_nice_vc_added_post_types', $added_post_types ); | |
} | |
} | |
endif; | |
if ( ! function_exists( 'nice_vc_body_class' ) ) : | |
add_filter( 'body_class', 'nice_vc_body_class' ); | |
/** | |
* Add body classes if VC is being used. | |
* | |
* @since 1.0.0 | |
* | |
* @param array $classes | |
* | |
* @return array | |
*/ | |
function nice_vc_body_class( array $classes ) { | |
if ( nice_vc_is_used() && ! nice_is_blog() ) { | |
$classes[] = 'uses-vc'; | |
$classes[] = 'vc-active'; | |
if ( nice_vc_integration_override_content_width() ) { | |
$classes[] = 'vc-default-content-width'; | |
} | |
/** | |
* @hook nice_vc_integration_styles_compat | |
* | |
* Allow loading VC compatibility file for overall layout. This should only | |
* be used in case updating to 1.1 from a previous version breaks your | |
* styles. | |
* | |
* @since 1.1 | |
*/ | |
$use_compat_file = apply_filters( 'nice_vc_integration_styles_compat', false ); | |
if ( $use_compat_file ) { | |
$class[] = 'vc-compat'; | |
} | |
} | |
return $classes; | |
} | |
endif; | |
if ( ! function_exists( 'nice_vc_integration_unset_blog_content' ) ) : | |
add_action( 'nice_blog_post_content', 'nice_vc_integration_unset_blog_content', 0 ); | |
/** | |
* Unset default blog content if the current post is using VC. | |
* | |
* @since 1.0.0 | |
*/ | |
function nice_vc_integration_unset_blog_content() { | |
if ( nice_vc_is_used() ) { | |
add_filter( 'nice_blog_content', '__return_false' ); | |
} | |
} | |
endif; | |
if ( ! function_exists( 'nice_vc_integration_hide_post_thumbnail' ) ) : | |
add_action( 'the_post', 'nice_vc_integration_hide_post_thumbnail' ); | |
/** | |
* Don't show featured image for single posts using VC. | |
* | |
* @since 1.0.2.4 | |
*/ | |
function nice_vc_integration_hide_post_thumbnail() { | |
if ( ! nice_vc_is_used() ) { | |
return; | |
} | |
if ( ! is_single() ) { | |
return; | |
} | |
add_filter( 'nice_post_thumbnail_display', '__return_false' ); | |
} | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment