';
} else {
echo '
";
}
function acf_vc_integrator_showAdminMessages()
{
if ( !class_exists('Vc_Manager') and !is_plugin_active( 'advanced-custom-fields/acf.php' ) AND !is_plugin_active( 'advanced-custom-fields-pro/acf.php' )) {
acf_vc_integrator_showMessage("ACF-VC Integrator require both WPBakery Page Builder and Advanced Custom Fields plugins installed and activated.", "error");
} elseif ( !class_exists('Vc_Manager') ) {
acf_vc_integrator_showMessage("ACF-VC Integrator require WPBakery Page Builder plugin installed and activated.", "error");
} elseif ( !is_plugin_active( 'advanced-custom-fields/acf.php' ) AND !is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) ) {
acf_vc_integrator_showMessage("ACF-VC Integrator require Advanced Custom Fields or Advanced Custom Fields Pro plugin installed and activated.", "error");
}
if(is_plugin_active( 'advanced-custom-fields-pro/acf.php' )) {
$screen = get_current_screen();
if( $screen->parent_base === "acf-vc-integrator" ) {
// acf_vc_integrator_showMessage("ACF-VC Integrator version 1.2 supports the Repeater field in ACF-Pro, as well as fields also found in ACF.", "info");
} elseif($screen->parent_base === "plugins") {
// acf_vc_integrator_showMessage("ACF-VC Integrator version 1.2 supports the Repeater field in ACF-Pro, as well as fields also found in ACF.", "info", "is-dismissible");
}
}
}
add_action('admin_notices', 'acf_vc_integrator_showAdminMessages');
}
//Check for ACF and VC plugins
add_action('admin_init', 'acf_vc_integrator_check_for_dependancy');
//Get acf OR acf pro version number
function get_acf_version_number() {
if ( ! function_exists( 'get_plugins' ) )
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( !is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) ) {
$plugin_folder = get_plugins( '/' . 'advanced-custom-fields' );
} else {
$plugin_folder = get_plugins( '/' . 'advanced-custom-fields-pro' );
}
$plugin_file = 'acf.php';
if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) {
return $plugin_folder[$plugin_file]['Version'];
} else {
return NULL;
}
}
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'acfvc_add_action_links' );
function acfvc_add_action_links ( $links ) {
$settings_link = '
' . __( 'Settings' ) . '';
array_unshift( $links, $settings_link );
return $links;
}
function is_acf_repeater_active() {
if( is_plugin_active( 'acf-repeater/acf-repeater.php' ) AND !is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) ) {
return true;
} else {
return false;
}
}
//Adding dashboard page.
/*function acf_vc_integrator_admin() {
include('acf_vc_integrator_admin.php');
}*/
function acf_vc_load_custom_wp_admin_style($hook) {
if($hook != 'settings_page_acf-vc-integrator') {
return;
}
wp_enqueue_style( 'acf_vc_admin_style', plugins_url('css/admin-style.css', __FILE__) );
}
add_action( 'admin_enqueue_scripts', 'acf_vc_load_custom_wp_admin_style' );
function acf_vc_integrator_admin_actions() {
add_options_page("ACF-VC Integrator", "ACF-VC Integrator", "manage_options", "acf-vc-integrator", "acf_vc_integrator_admin");
}
add_action('admin_menu', 'acf_vc_integrator_admin_actions');
require_once dirname(__FILE__).'/admin/acf-vc-integrator-admin.php';
add_action( 'vc_before_init', 'acf_vc_integrator_elem' );
function acf_vc_integrator_elem() {
if ( class_exists('Vc_Manager') ) {
$groups = function_exists( 'acf_get_field_groups' ) ? acf_get_field_groups() : apply_filters( 'acf/get_field_groups', array() );
$groups_param_values = $fields_params = array();
if (is_array( $groups )) {
foreach ( $groups as $group ) {
$flg = 1;
$id = isset( $group['id'] ) ? 'id' : ( isset( $group['ID'] ) ? 'ID' : 'id' );
$groups_param_values[ $group['title'] ] = $group[ $id ];
$fields = function_exists( 'acf_get_fields' ) ? acf_get_fields( $group[ $id ] ) : apply_filters( 'acf/field_group/get_fields', array(), $group[ $id ] );
$fields_param_value = array();
if ($fields != false) :
foreach ( $fields as $field ) {
$fields_param_value[ $field['label'] ] = (string) $field['key'];
}
endif;
$fields_params[] = array(
'type' => 'dropdown',
'heading' => __( 'Field name', 'acf-vc-integrator' ),
'param_name' => 'field_from_' . $group[ $id ],
'value' => $fields_param_value,
'save_always' => true,
'description' => __( 'Select field from group.', 'acf-vc-integrator' ),
'dependency' => array(
'element' => 'field_group',
'value' => array( (string) $group[ $id ] ),
)
);
}
}
$wp_image_sizes = get_intermediate_image_sizes();
$wp_image_sizes_array = array();
$wp_image_sizes_array["Default"] = "";
foreach ($wp_image_sizes as $key => $value) {
$wp_image_sizes_array[$value] = $value;
}
wp_enqueue_style( 'acf-vc-integrator-style', plugin_dir_url( __FILE__ ).'css/acf-vc-integrator-style.css');
include_once('inc/acf_vc_helper.php');
include_once('inc/acf_vc_helper_pro.php');
vc_map( array(
'name' => __( 'ACF-VC Integrator', 'acf-vc-integrator' ),
'base' => 'acf_vc_integrator',
'icon' => plugin_dir_url( __FILE__ )."images/acf_icon1.png",
'category' => __( 'Content', 'acf-vc-integrator' ),
'description' => __( 'Advanced Custom Field - Visual Composer Integrator', 'acf-vc-integrator' ),
'php_class_name' => 'Acf_vc_integrator_Shortcode',
'admin_enqueue_css' => plugin_dir_url( __FILE__ ).'css/acf-vc-integrator-style.css',
'params' => array_merge(
array(
array(
'type' => 'dropdown',
'heading' => __( 'Field group', 'acf-vc-integrator' ),
'param_name' => 'field_group',
'admin_label' => true,
'value' => $groups_param_values,
'save_always' => true,
'description' => __( 'Select field group.', 'acf-vc-integrator' ),
),
),
$fields_params,
array(
array(
'type' => 'css_editor',
'heading' => __( 'Css', 'acf-vc-integrator' ),
'param_name' => 'css',
'group' => __( 'Design options', 'acf-vc-integrator' ),
),
array(
'type' => 'dropdown',
'heading' => __( 'Show label', 'acf-vc-integrator' ),
'param_name' => 'show_label',
'value' => array(
"Default" => "default",
__( 'No', 'acf-vc-integrator' ) => 'No',
__( 'Yes', 'acf-vc-integrator' ) => 'yes',
__( 'Yes and hide if no result', 'acf-vc-integrator' ) => 'yes_no'
),
'save_always' => true,
'description' => __( 'Enter label to display before key value.', 'acf-vc-integrator' ),
),
array(
'type' => 'dropdown',
'heading' => __( 'Align', 'acf-vc-integrator' ),
'param_name' => 'align',
'value' => array(
"Default" => "default",
__( 'left', 'acf-vc-integrator' ) => 'left',
__( 'right', 'acf-vc-integrator' ) => 'right',
__( 'center', 'acf-vc-integrator' ) => 'center',
__( 'justify', 'acf-vc-integrator' ) => 'justify',
),
'save_always' => true,
'description' => __( 'Select alignment.', 'acf-vc-integrator' ),
),
array(
'type' => 'textfield',
'heading' => __( 'Extra class name', 'acf-vc-integrator' ),
'param_name' => 'el_class',
'description' => __( 'Style particular content element differently - add a class name and refer to it in custom CSS.', 'acf-vc-integrator' ),
),
array(
'type' => 'textfield',
'heading' => __( 'Custom Link Text', 'acf-vc-integrator' ),
'param_name' => 'link_text',
'description' => __( 'Applicable only for File Objects and Page Links', 'acf-vc-integrator' ),
),
array(
'type' => 'dropdown',
'heading' => __( 'Columns', 'acf-vc-integrator' ),
'param_name' => 'gallery_columns',
'value' => array(
"Default" => "",
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
),
'description' => __( 'Select number of columns.', 'acf-vc-integrator' ),
'group' => __( 'Gallery field', 'acf-vc-integrator' ),
),
array(
'type' => 'dropdown',
'heading' => __( 'Image size', 'acf-vc-integrator' ),
'param_name' => 'gallery_image_size',
'value' => $wp_image_sizes_array,
'description' => __( 'Select a iamge size.', 'acf-vc-integrator' ),
'group' => __( 'Gallery field', 'acf-vc-integrator' ),
),
array(
'type' => 'dropdown',
'heading' => __( 'Order by', 'acf-vc-integrator' ),
'param_name' => 'gallery_order_by',
'value' => array(
"Default" => "",
"ID" => "ID",
"Menu order" => "menu_order",
"Title" => "title",
"Post date" => "post_date",
"Random" => "rand",
),
'description' => __( 'Order image by', 'acf-vc-integrator' ),
'group' => __( 'Gallery field', 'acf-vc-integrator' ),
),
array(
'type' => 'dropdown',
'heading' => __( 'Order', 'acf-vc-integrator' ),
'param_name' => 'gallery_order',
'value' => array(
"Default" => "",
"ASC" => "ASC",
"DESC" => "DESC",
),
'description' => __( 'Order image', 'acf-vc-integrator' ),
'group' => __( 'Gallery field', 'acf-vc-integrator' ),
),
array(
'type' => 'dropdown',
'heading' => __( 'Itemtag', 'acf-vc-integrator' ),
'param_name' => 'gallery_itemtag_dropdown',
'value' => array(
"Default" => "",
"Custom" => "custom",
),
'description' => __( 'The name of the XHTML tag used to enclose each item in the gallery.', 'acf-vc-integrator' ),
'group' => __( 'Gallery field', 'acf-vc-integrator' ),
),
array(
'type' => 'textfield',
'heading' => __( 'Custom itemtag', 'acf-vc-integrator' ),
'param_name' => 'gallery_itemtag',
'dependency'=>array(
'element'=>'gallery_itemtag_dropdown',
'value'=>array('custom'),
),
'group' => __( 'Gallery field', 'acf-vc-integrator' ),
),
array(
'type' => 'dropdown',
'heading' => __( 'Icontag', 'acf-vc-integrator' ),
'param_name' => 'gallery_icontag_dropdown',
'value' => array(
"Default" => "",
"Custom" => "custom",
),
'description' => __( 'The name of the XHTML tag used to enclose each thumbnail icon in the gallery.', 'acf-vc-integrator' ),
'group' => __( 'Gallery field', 'acf-vc-integrator' ),
),
array(
'type' => 'textfield',
'heading' => __( 'Custom icontag', 'acf-vc-integrator' ),
'param_name' => 'gallery_icontag',
'dependency'=>array(
'element'=>'gallery_icontag_dropdown',
'value'=>array('custom'),
),
'group' => __( 'Gallery field', 'acf-vc-integrator' ),
),
array(
'type' => 'dropdown',
'heading' => __( 'Captiontag', 'acf-vc-integrator' ),
'param_name' => 'gallery_captiontag_dropdown',
'value' => array(
"Default" => "",
"Custom" => "custom",
),
'description' => __( 'The name of the XHTML tag used to enclose each caption.', 'acf-vc-integrator' ),
'group' => __( 'Gallery field', 'acf-vc-integrator' ),
),
array(
'type' => 'textfield',
'heading' => __( 'Custom captiontag', 'acf-vc-integrator' ),
'param_name' => 'gallery_captiontag',
'dependency'=>array(
'element'=>'gallery_captiontag_dropdown',
'value'=>array('custom'),
),
'group' => __( 'Gallery field', 'acf-vc-integrator' ),
),
array(
'type' => 'dropdown',
'heading' => __( 'Link', 'acf-vc-integrator' ),
'param_name' => 'gallery_link',
'value' => array(
"Default" => "",
"None" => "none",
"File" => "file",
),
'description' => __( 'Specify where you want the image to link.', 'acf-vc-integrator' ),
'group' => __( 'Gallery field', 'acf-vc-integrator' ),
),
)
),
));
class Acf_vc_integrator_Shortcode extends WPBakeryShortCode {
/**
* @param $atts
* @param null $content
*
* @return mixed|void
*/
protected function content( $atts, $content = null ) {
$field_key = $label = '';
$clone_field_key = "";
/**
* @var string $el_class
* @var string $show_label
* @var string $align
* @var string $field_group
* @var string $link_text
* @var string $gallery_columns
* @var string $gallery_image_size
* @var string $gallery_order_by
* @var string $gallery_order
* @var string $gallery_itemtag_dropdown
* @var string $gallery_itemtag
* @var string $gallery_icontag_dropdown
* @var string $gallery_icontag
* @var string $gallery_captiontag_dropdown
* @var string $gallery_captiontag
* @var string $gallery_link
*/
extract( shortcode_atts( array(
'el_class' => '',
'field_group' => '',
'show_label' => '',
'align' => '',
'link_text' => '',
'gallery_columns' => '',
'gallery_image_size' => '',
'gallery_order_by' => '',
'gallery_order' => '',
'gallery_itemtag_dropdown' => '',
'gallery_itemtag' => '',
'gallery_icontag_dropdown' => '',
'gallery_icontag' => '',
'gallery_captiontag_dropdown' => '',
'gallery_captiontag' => '',
'gallery_link' => '',
), $atts ) );
$acf_version = get_acf_version_number();
if (!get_option('acfvc_default')) {
acfvc_add_default_options();
}
if ( 0 === strlen( $field_group ) ) {
$groups = function_exists( 'acf_get_field_groups' ) ? acf_get_field_groups() : apply_filters( 'acf/get_field_groups', array() );
if ( is_array( $groups ) && isset( $groups[0] ) ) {
$key = isset( $groups[0]['id'] ) ? 'id' : ( isset( $groups[0]['ID'] ) ? 'ID' : 'id' );
$field_group = $groups[0][ $key ];
}
}
if ( ! empty( $field_group ) ) {
$field_key = ! empty( $atts[ 'field_from_' . $field_group ] ) ? $atts[ 'field_from_' . $field_group ] : 'field_from_group_' . $field_group;
}
/*Get the page/post id when using Templatera*/
if(get_queried_object_id() != get_the_ID()) {
$post_id = get_queried_object_id();
} else {
$post_id = get_the_ID();
}
$output = "";
$field_key_array = explode("_field_",$field_key);
if ( count($field_key_array) == 1 ) {
$field_key = $field_key_array[0];
} else {
$field_key = $field_key_array[0];
$clone_field_key = "field_".$field_key_array[1];
}
$custom_field = get_field_object($field_key,$post_id);
// print_r($field_key2);
if ( empty($align) OR $align == "default" ) {
$acfvc_option = get_option('acfvc_default');
if ( !array_key_exists('align',$acfvc_option['general']) ) {
$acfvc_option["general"]["align"] = "left";
}
$align = $acfvc_option["general"]["align"];
}
$css_class = 'vc_sw-acf' . ( strlen( $el_class ) ? ' ' . $el_class : '' ) . ( strlen( $align ) ? ' vc_sw-align-' . $align : '' ) . ( strlen( $field_key ) ? ' ' . $field_key : '' );
$link_text = ( strlen( $link_text ) ? $link_text : 'Link' );
$gallery_options["columns"] = $gallery_columns;
$gallery_options["image_size"] = $gallery_image_size;
$gallery_options["order_by"] = $gallery_order_by;
$gallery_options["order"] = $gallery_order;
if (empty($gallery_itemtag_dropdown)) {
$gallery_options["itemtag"] = 'default';
} else {
$gallery_options["itemtag"] = $gallery_itemtag;
}
if (empty($gallery_itemtag_dropdown)) {
$gallery_options["icontag"] = 'default';
} else {
$gallery_options["icontag"] = $gallery_icontag;
}
if (empty($gallery_itemtag_dropdown)) {
$gallery_options["captiontag"] = 'default';
} else {
$gallery_options["captiontag"] = $gallery_captiontag;
}
$gallery_options["link"] = $gallery_link;
$args = array (
"field_key" => $field_key,
"clone_field_key" => $clone_field_key,
"acf_version" => $acf_version,
"link_text" => $link_text,
"gallery_options" => $gallery_options,
);
$acf_vc_helper = new acf_vc_helper();
$output_empty = false;
if (empty($custom_field["value"])) {
$output_empty = true;
} elseif('text' === $custom_field["type"]) {
$output = $acf_vc_helper->text($custom_field, $acf_version, $post_id);
} elseif('textarea' === $custom_field["type"]) {
$output = $acf_vc_helper->textarea($custom_field, $acf_version, $post_id);
} elseif('wysiwyg' === $custom_field["type"]) {
$output = $acf_vc_helper->wysiwyg($custom_field, $acf_version, $post_id);
} elseif('number' === $custom_field["type"]) {
$output = $acf_vc_helper->number($custom_field, $acf_version, $post_id);
} elseif('email' === $custom_field["type"]) {
$output = $acf_vc_helper->email($custom_field, $acf_version, $post_id);
} elseif('password' === $custom_field["type"]) {
$output = $acf_vc_helper->password($custom_field, $acf_version, $post_id);
} elseif('image' === $custom_field["type"]) {
$output = $acf_vc_helper->image($custom_field, $acf_version, $post_id);
} elseif('file' === $custom_field["type"]) {
$output = $acf_vc_helper->file($custom_field, $acf_version, $link_text, $post_id);
} elseif('checkbox' === $custom_field["type"]) {
$output = $acf_vc_helper->checkbox($custom_field, $acf_version, $post_id);
} elseif('radio' === $custom_field["type"]) {
$output = $acf_vc_helper->radio($custom_field, $acf_version, $post_id);
} elseif('user' === $custom_field["type"]) {
$output = $acf_vc_helper->user($custom_field, $acf_version, $post_id);
} elseif('page_link' === $custom_field["type"]) {
$output = $acf_vc_helper->page_link($custom_field, $acf_version, $link_text, $post_id);
} elseif('google_map' === $custom_field["type"]) {
$output = $acf_vc_helper->google_map($custom_field, $acf_version, $post_id);
} elseif('date_picker' === $custom_field["type"]) {
$output = $acf_vc_helper->date_picker($custom_field, $acf_version, $post_id);
} elseif('color_picker' === $custom_field["type"]) {
$output = $acf_vc_helper->color_picker($custom_field, $acf_version, $post_id);
} elseif('true_false' === $custom_field["type"]) {
$output = $acf_vc_helper->true_false($custom_field, $acf_version, $post_id);
} elseif('taxonomy' === $custom_field["type"]) {
$output = $acf_vc_helper->taxonomy($custom_field, $acf_version, $post_id);
} elseif('post_object' === $custom_field["type"]) {
$output = $acf_vc_helper->post_object($custom_field, $acf_version, $post_id);
} elseif('relationship' === $custom_field["type"]) {
$output = $acf_vc_helper->relationship($custom_field, $acf_version, $post_id);
} elseif('url' === $custom_field["type"]) {
$output = $acf_vc_helper->url($custom_field, $acf_version, $post_id);
} elseif('select' === $custom_field["type"]) {
$output = $acf_vc_helper->select($custom_field, $acf_version, $post_id);
} elseif('oembed' === $custom_field["type"]) {
$output = $acf_vc_helper->oembed($custom_field, $acf_version, $post_id);
} elseif('gallery' === $custom_field["type"]) {
$output = $acf_vc_helper->gallery($custom_field, $acf_version, $gallery_options, $post_id);
} elseif('repeater' === $custom_field["type"]) {
$output = $acf_vc_helper->repeater($custom_field,$args,$post_id);
} else {
$output = apply_filters( "acf_vc_add_on_fields",$custom_field,$args,$post_id );
}
if($output == "data-mismatch") {
// set the mismatch error message here.
$output = 'Data mismatch error. Custom field value doesn\'t match the field type. Please set the field value again.';
}
if ( $show_label == "default" ) {
$acfvc_option = get_option('acfvc_default');
$show_label = $acfvc_option["general"]["show_label"];
}
if ( 'yes' === $show_label OR 'yes_no' === $show_label AND $output_empty === false) {
if(!isset($output)) {
$output = '
'.$custom_field["label"].': '.$custom_field["value"];
} else {
$output = '
'.$custom_field["label"].': '.$output;
}
} elseif ( 'yes_no' === $show_label AND $output_empty === true) {
$output = "";
} else {
if(!isset($output) OR empty($output)) $output = $custom_field["value"];
}
$css = '';
extract(shortcode_atts(array(
'css' => ''
), $atts));
$css_class_vc = apply_filters( VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, vc_shortcode_custom_css_class( $css, ' ' ), $this->settings['base'], $atts );
return '
'.$output. '
';
/*return '<< Working on retrieving the data from ACF. >>';*/
}
}
}
}
?>