Skip to content

Instantly share code, notes, and snippets.

@thomasmery
Last active December 14, 2019 20:35
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save thomasmery/d9e6119bd74bc13b7f5d to your computer and use it in GitHub Desktop.
Save thomasmery/d9e6119bd74bc13b7f5d to your computer and use it in GitHub Desktop.
<?php
/*
Extends Visual Composer
More information can be found here: http://kb.wpbakery.com/index.php?title=Category:Visual_Composer
*/
// don't load directly
if (!defined('ABSPATH')) die('-1');
class VCExtendAddonClass {
function __construct() {
// We safely integrate with VC with this hook
add_action( 'init', array( $this, 'integrateWithVC' ) );
// Register CSS and JS
add_action( 'wp_enqueue_scripts', array( $this, 'loadCssAndJs' ) );
}
public function integrateWithVC() {
// Check if Visual Composer is installed
if ( ! defined( 'WPB_VC_VERSION' ) ) {
// Display notice that Visual Compser is required
add_action('admin_notices', array( $this, 'showVcVersionNotice' ));
return;
}
/*
Add your Visual Composer logic here.
Lets call vc_map function to "register" our custom shortcode within Visual Composer interface.
More info: http://kb.wpbakery.com/index.php?title=Vc_map
*/
/**
* Add Post Content Shortcode
* https://wordpress.org/plugins/post-content-shortcodes/
*/
vc_map( array(
"name" => __("Post Content [Single]", 'vc_extend'),
"description" => __("Add the content from another post", 'vc_extend'),
"base" => "post_content",
"class" => "post_content",
"controls" => "full",
"content_element" => true,
"show_settings_on_create" => true,
"icon" => '', // or css class name which you can reffer in your css file later. Example: "vc_extend_my_class"
"category" => __('Content', 'js_composer'),
//'admin_enqueue_js' => array(plugins_url('assets/vc_extend.js', __FILE__)), // This will load js file in the VC backend editor
'admin_enqueue_css' => array(get_stylesheet_directory_uri() . '/assets/css/vc_extend_admin.min.css'), // This will load css file in the VC backend editor
"params" => array(
array(
"type" => "textfield",
"holder" => "div",
"class" => "",
"heading" => __("Post ID"),
"param_name" => "id",
"admin_label" => true,
"value" => "",
"description" => __("the ID of the post you want to include")
),
array(
"type" => "checkbox",
"holder" => "div",
"class" => "",
"heading" => __("Show title"),
"param_name" => "show_title",
"admin_label" => true,
"value" => array( 'Yes please' => 1),
"description" => __("Whether to show the post title")
),
array(
"type" => "checkbox",
"holder" => "div",
"class" => "",
"heading" => __("Process shortcodes"),
"param_name" => "shortcodes",
"admin_label" => true,
"value" => array( 'Yes please' => 1),
"description" => __("Whether to process the shorcodes taht the post may contain")
)
)
) );
}
/*
Load plugin css and javascript files which you may need on front end of your site
*/
public function loadCssAndJs() {
// wp_register_style( 'vc_extend_style', plugins_url('assets/vc_extend.css', __FILE__) );
// wp_enqueue_style( 'vc_extend_style' );
// If you need any javascript files on front end, here is how you can load them.
// wp_enqueue_script( 'vc_extend_js', plugins_url('assets/vc_extend.js', __FILE__), array('jquery') );
}
/*
Show notice if your plugin is activated but Visual Composer is not
*/
public function showVcVersionNotice() {
$plugin_data = get_plugin_data(__FILE__);
echo '
<div class="updated">
<p>'.sprintf(__('<strong>%s</strong> requires <strong><a href="http://bit.ly/vcomposer" target="_blank">Visual Composer</a></strong> plugin to be installed and activated on your site.', 'vc_extend'), $plugin_data['Name']).'</p>
</div>';
}
}
// Finally initialize code
new VCExtendAddonClass();
if ( class_exists( 'WPBakeryShortCode' ) ) {
class WPBakeryShortCode_post_content extends WPBakeryShortCode {
public function contentAdmin( $atts, $content = null ) {
return parent::contentAdmin( $atts, $content );
}
protected function outputTitle( $title ) {
return '<h4 class="wpb_element_title">My Shortcode title [testing]</h4>';
}
}
}
@JaakkoKarhu
Copy link

For some reason this plugin affects the theme font and color. Occured after updating WordPress and the theme. Current version of my WP is 4.0.

EDIT:

Getting the following error to console, if pkugin installed: The stylesheet /dev/?load=custom-style.css&post_id=2&ver=4.0 was not loaded because its MIME type, "text/html", is not "text/css".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment