This commit is contained in:
KhaiNguyen
2020-02-13 10:39:37 +07:00
commit 59401cb805
12867 changed files with 4646216 additions and 0 deletions

View File

@@ -0,0 +1,222 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
// Part BC: Post types
// =========================
/**
* @param $state
* @return bool|string
*/
function vc_bc_access_rule_48_post_type_get_state( $state ) {
if ( null === $state ) {
$content_types = vc_settings()->get( 'content_types' );
if ( empty( $content_types ) ) {
$state = true;
} else {
$state = 'custom';
}
}
return $state;
}
/**
* @param $value
* @param $role
* @param $rule
* @return bool
* @throws \Exception
*/
function vc_bc_access_rule_48_post_type_rule( $value, $role, $rule ) {
if ( ! $role ) {
return $value;
}
global $vc_bc_access_rule_48_editor_post_types;
$part = vc_role_access()->who( $role->name )->part( 'post_types' );
if ( ! isset( $part->getRole()->capabilities[ $part->getStateKey() ] ) ) {
if ( is_null( $vc_bc_access_rule_48_editor_post_types ) ) {
$pt_array = vc_settings()->get( 'content_types' );
$vc_bc_access_rule_48_editor_post_types = $pt_array ? $pt_array : vc_default_editor_post_types();
}
return in_array( $rule, $vc_bc_access_rule_48_editor_post_types, true );
}
return $value;
}
// Part BC: shortcodes
// =========================
/**
* @param $state
* @param $role
* @return bool|string
*/
function vc_bc_access_rule_48_shortcodes_get_state( $state, $role ) {
if ( ! $role ) {
return $state;
}
if ( null === $state ) {
$group_access_settings = vc_settings()->get( 'groups_access_rules' );
if ( ! isset( $group_access_settings[ $role->name ]['shortcodes'] ) ) {
$state = true;
} else {
$state = 'custom';
}
}
return $state;
}
/**
* @param $value
* @param $role
* @param $rule
* @return bool
* @throws \Exception
*/
function vc_bc_access_rule_48_shortcodes_rule( $value, $role, $rule ) {
if ( ! $role ) {
return $value;
}
if ( ! vc_bc_access_get_shortcodes_state_is_set( $role ) ) {
if ( preg_match( '/_edit$/', $rule ) ) {
return false;
}
$group_access_settings = vc_settings()->get( 'groups_access_rules' );
if ( isset( $group_access_settings[ $role->name ]['shortcodes'] ) && ! empty( $group_access_settings[ $role->name ]['shortcodes'] ) ) {
$rule = preg_replace( '/_all$/', '', $rule );
return 'vc_row' === $rule || ( isset( $group_access_settings[ $role->name ]['shortcodes'][ $rule ] ) && 1 === (int) $group_access_settings[ $role->name ]['shortcodes'][ $rule ] );
} else {
return true;
}
}
return $value;
}
/**
* Check is state set
*
* @param $role
*
* @return bool
* @throws \Exception
*/
function vc_bc_access_get_shortcodes_state_is_set( $role ) {
if ( ! $role ) {
return false;
}
$part = vc_role_access()->who( $role->name )->part( 'shortcodes' );
return isset( $part->getRole()->capabilities[ $part->getStateKey() ] );
}
// Part BC: backened editor
// ===========================
/**
* @param $state
* @param $role
* @return bool|string
*/
function vc_bc_access_rule_48_backend_editor_get_state( $state, $role ) {
if ( ! $role ) {
return $state;
}
if ( null === $state ) {
$group_access_settings = vc_settings()->get( 'groups_access_rules' );
if ( ! isset( $group_access_settings[ $role->name ]['show'] ) || 'all' === $group_access_settings[ $role->name ]['show'] ) {
$state = true;
} elseif ( 'no' === $group_access_settings[ $role->name ]['show'] ) {
$state = false;
} else {
$state = 'default';
}
}
return $state;
}
/**
* @param $state
* @param $role
* @return bool
*/
function vc_bc_access_rule_48_frontend_editor_get_state( $state, $role ) {
if ( ! $role ) {
return $state;
}
if ( null === $state ) {
$group_access_settings = vc_settings()->get( 'groups_access_rules' );
if ( isset( $group_access_settings[ $role->name ]['show'] ) && 'no' === $group_access_settings[ $role->name ]['show'] ) {
$state = false;
} else {
$state = true;
}
}
return $state;
}
/**
* @param $value
* @param $role
* @return bool
* @throws \Exception
*/
function vc_bc_access_rule_48_backend_editor_can_disabled_ce_editor_rule( $value, $role ) {
if ( ! $role ) {
return $value;
}
$part = vc_role_access()->who( $role->name )->part( 'backend_editor' );
if ( ! isset( $part->getRole()->capabilities[ $part->getStateKey() ] ) ) {
$group_access_settings = vc_settings()->get( 'groups_access_rules' );
return isset( $group_access_settings[ $role->name ]['show'] ) && 'only' === $group_access_settings[ $role->name ]['show'];
}
return $value;
}
/**
* @param $role
* @return mixed
* @throws \Exception
*/
function vc_bc_access_rule_48_backend_editor_add_cap_disabled_ce_editor( $role ) {
if ( ! $role ) {
return $role;
}
$part = vc_role_access()->who( $role->name )->part( 'backend_editor' );
if ( ! isset( $part->getRole()->capabilities[ $part->getStateKey() ] ) ) {
$group_access_settings = vc_settings()->get( 'groups_access_rules' );
if ( isset( $group_access_settings[ $role->name ]['show'] ) && 'only' === $group_access_settings[ $role->name ]['show'] ) {
$role->capabilities[ $part->getStateKey() . '/disabled_ce_editor' ] = true;
}
}
return $role;
}
function vc_bc_access_rule_48() {
add_filter( 'vc_role_access_with_post_types_get_state', 'vc_bc_access_rule_48_post_type_get_state' );
add_filter( 'vc_role_access_with_post_types_can', 'vc_bc_access_rule_48_post_type_rule', 10, 3 );
add_filter( 'vc_role_access_with_shortcodes_get_state', 'vc_bc_access_rule_48_shortcodes_get_state', 10, 3 );
add_filter( 'vc_role_access_with_shortcodes_can', 'vc_bc_access_rule_48_shortcodes_rule', 10, 3 );
add_filter( 'vc_role_access_with_backend_editor_get_state', 'vc_bc_access_rule_48_backend_editor_get_state', 10, 3 );
add_filter( 'vc_role_access_with_backend_editor_can_disabled_ce_editor', 'vc_bc_access_rule_48_backend_editor_can_disabled_ce_editor_rule', 10, 2 );
add_filter( 'vc_role_access_with_frontend_editor_get_state', 'vc_bc_access_rule_48_frontend_editor_get_state', 10, 3 );
add_filter( 'vc_role_access_all_caps_role', 'vc_bc_access_rule_48_backend_editor_add_cap_disabled_ce_editor' );
}
// BC function for shortcode
add_action( 'vc_before_init', 'vc_bc_access_rule_48' );

View File

@@ -0,0 +1,22 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
add_action( 'vc_activation_hook', 'vc_bc_multisite_options', 9 );
/**
* @param $networkWide
*/
function vc_bc_multisite_options( $networkWide ) {
global $current_site;
if ( ! is_multisite() || empty( $current_site ) || ! $networkWide || get_site_option( 'vc_bc_options_called', false ) || get_site_option( 'wpb_js_js_composer_purchase_code', false ) ) {
return;
}
// Now we need to check BC with license keys
$is_main_blog_activated = get_blog_option( (int) $current_site->id, 'wpb_js_js_composer_purchase_code' );
if ( $is_main_blog_activated ) {
update_site_option( 'wpb_js_js_composer_purchase_code', $is_main_blog_activated );
}
update_site_option( 'vc_bc_options_called', true );
}

View File

@@ -0,0 +1,424 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Collection of static methods for work with settings presets
*
* @since 4.8
*/
class Vc_Settings_Preset {
/**
* Get default preset id for specific shortcode
*
* @since 4.7
*
* @param string $shortcode_name
*
* @return mixed int|null
*/
public static function getDefaultSettingsPresetId( $shortcode_name = null ) {
if ( ! $shortcode_name ) {
return null;
}
$args = array(
'post_type' => 'vc_settings_preset',
'post_mime_type' => self::constructShortcodeMimeType( $shortcode_name ),
'posts_per_page' => - 1,
'meta_key' => '_vc_default',
'meta_value' => true,
);
$posts = get_posts( $args );
if ( $posts ) {
$default_id = $posts[0]->ID;
} else {
// check for vendor presets
$default_id = vc_vendor_preset()->getDefaultId( $shortcode_name );
}
return $default_id;
}
/**
* Set existing preset as default
*
* If this is vendor preset, clone it and set new one as default
*
* @param int $id If falsy, no default will be set
* @param string $shortcode_name
*
* @return boolean
*
* @since 4.7
*/
public static function setAsDefaultSettingsPreset( $id, $shortcode_name ) {
$post_id = self::getDefaultSettingsPresetId( $shortcode_name );
if ( $post_id ) {
delete_post_meta( $post_id, '_vc_default' );
}
if ( $id ) {
if ( is_numeric( $id ) ) {
// user preset
update_post_meta( $id, '_vc_default', true );
} else {
// vendor preset
$preset = vc_vendor_preset()->get( $id );
if ( ! $preset || $shortcode_name !== $preset['shortcode'] ) {
return false;
}
self::saveSettingsPreset( $preset['shortcode'], $preset['title'], wp_json_encode( $preset['params'] ), true );
}
}
return true;
}
/**
* Get mime type for specific shortcode
*
* @since 4.7
*
* @param $shortcode_name
*
* @return string
*/
public static function constructShortcodeMimeType( $shortcode_name ) {
return 'vc-settings-preset/' . str_replace( '_', '-', $shortcode_name );
}
/**
* Get shortcode name from post's mime type
*
* @since 4.7
*
* @param string $post_mime_type
*
* @return string
*/
public static function extractShortcodeMimeType( $post_mime_type ) {
$chunks = explode( '/', $post_mime_type );
if ( 2 !== count( $chunks ) ) {
return '';
}
return str_replace( '-', '_', $chunks[1] );
}
/**
* Get all presets
*
* @since 5.2
*
* @return array E.g. array(preset_id => value, preset_id => value, ...)
*/
public static function listAllPresets() {
$list = array();
$args = array(
'post_type' => 'vc_settings_preset',
'posts_per_page' => - 1,
);
// user presets
$posts = get_posts( $args );
foreach ( $posts as $post ) {
$shortcode_name = self::extractShortcodeMimeType( $post->post_mime_type );
$list[ $post->ID ] = (array) json_decode( $post->post_content );
}
// vendor presets
$presets = self::listDefaultVendorSettingsPresets();
foreach ( $presets as $shortcode => $params ) {
if ( ! isset( $list[ $shortcode ] ) ) {
$list[ $shortcode ] = $params;
}
}
return $list;
}
/**
* Get all default presets
*
* @since 4.7
*
* @return array E.g. array(shortcode_name => value, shortcode_name => value, ...)
*/
public static function listDefaultSettingsPresets() {
$list = array();
$args = array(
'post_type' => 'vc_settings_preset',
'posts_per_page' => - 1,
'meta_key' => '_vc_default',
'meta_value' => true,
);
// user presets
$posts = get_posts( $args );
foreach ( $posts as $post ) {
$shortcode_name = self::extractShortcodeMimeType( $post->post_mime_type );
$list[ $shortcode_name ] = (array) json_decode( $post->post_content );
}
// vendor presets
$presets = self::listDefaultVendorSettingsPresets();
foreach ( $presets as $shortcode => $params ) {
if ( ! isset( $list[ $shortcode ] ) ) {
$list[ $shortcode ] = $params;
}
}
return $list;
}
/**
* Get all default vendor presets
*
* @since 4.8
*
* @return array E.g. array(shortcode_name => value, shortcode_name => value, ...)
*/
public static function listDefaultVendorSettingsPresets() {
$list = array();
$presets = vc_vendor_preset()->getDefaults();
foreach ( $presets as $id => $preset ) {
$list[ $preset['shortcode'] ] = $preset['params'];
}
return $list;
}
/**
* Save shortcode preset
*
* @since 4.7
*
* @param string $shortcode_name
* @param string $title
* @param string $content
* @param boolean $is_default
*
* @return mixed int|false Post ID
*/
public static function saveSettingsPreset( $shortcode_name, $title, $content, $is_default = false ) {
$post_id = wp_insert_post( array(
'post_title' => $title,
'post_content' => $content,
'post_status' => 'publish',
'post_type' => 'vc_settings_preset',
'post_mime_type' => self::constructShortcodeMimeType( $shortcode_name ),
), false );
if ( $post_id && $is_default ) {
self::setAsDefaultSettingsPreset( $post_id, $shortcode_name );
}
return $post_id;
}
/**
* Get list of all presets for specific shortcode
*
* @since 4.7
*
* @param string $shortcode_name
*
* @return array E.g. array(id1 => title1, id2 => title2, ...)
*/
public static function listSettingsPresets( $shortcode_name = null ) {
$list = array();
if ( ! $shortcode_name ) {
return $list;
}
$args = array(
'post_type' => 'vc_settings_preset',
'orderby' => array( 'post_date' => 'DESC' ),
'posts_per_page' => - 1,
'post_mime_type' => self::constructShortcodeMimeType( $shortcode_name ),
);
$posts = get_posts( $args );
foreach ( $posts as $post ) {
$list[ $post->ID ] = $post->post_title;
}
return $list;
}
/**
* Get list of all vendor presets for specific shortcode
*
* @since 4.8
*
* @param string $shortcode_name
*
* @return array E.g. array(id1 => title1, id2 => title2, ...)
*/
public static function listVendorSettingsPresets( $shortcode_name = null ) {
$list = array();
if ( ! $shortcode_name ) {
return $list;
}
$presets = vc_vendor_preset()->getAll( $shortcode_name );
foreach ( $presets as $id => $preset ) {
$list[ $id ] = $preset['title'];
}
return $list;
}
/**
* Get specific shortcode preset
*
* @since 4.7
*
* @param mixed $id Can be int (user preset) or string (vendor preset)
* @param bool $array If true, return array instead of string
*
* @return mixed string?array Post content
*/
public static function getSettingsPreset( $id, $array = false ) {
if ( is_numeric( $id ) ) {
// user preset
$post = get_post( $id );
if ( ! $post ) {
return false;
}
$params = $array ? (array) json_decode( $post->post_content ) : $post->post_content;
} else {
// vendor preset
$preset = vc_vendor_preset()->get( $id );
if ( ! $preset ) {
return false;
}
$params = $preset['params'];
}
return $params;
}
/**
* Delete shortcode preset
*
* @since 4.7
*
* @param int $post_id Post must be of type 'vc_settings_preset'
*
* @return bool
*/
public static function deleteSettingsPreset( $post_id ) {
$post = get_post( $post_id );
if ( ! $post || 'vc_settings_preset' !== $post->post_type ) {
return false;
}
return (bool) wp_delete_post( $post_id, true );
}
/**
* Return rendered popup menu
*
* @since 4.7
*
* @param string $shortcode_name
*
* @return string
*/
public static function getRenderedSettingsPresetPopup( $shortcode_name ) {
$list_vendor_presets = self::listVendorSettingsPresets( $shortcode_name );
$list_presets = self::listSettingsPresets( $shortcode_name );
$default_id = self::getDefaultSettingsPresetId( $shortcode_name );
if ( ! $default_id ) {
$default_id = vc_vendor_preset()->getDefaultId( $shortcode_name );
}
ob_start();
vc_include_template( apply_filters( 'vc_render_settings_preset_popup', 'editors/partials/settings_presets_popup.tpl.php' ), array(
'list_presets' => array(
$list_presets,
$list_vendor_presets,
),
'default_id' => $default_id,
'shortcode_name' => $shortcode_name,
) );
$html = ob_get_clean();
return $html;
}
/**
* @param $shortcodes
*
* @return array
* @throws \Exception
*/
public static function addVcPresetsToShortcodes( $shortcodes ) {
if ( vc_user_access()->part( 'presets' )->can()->get() ) {
$shortcodesAndPresets = array();
foreach ( $shortcodes as $shortcode ) {
$presets = self::listSettingsPresets( $shortcode['base'] );
$shortcodesAndPresets[ $shortcode['base'] ] = $shortcode;
if ( ! empty( $presets ) ) {
foreach ( $presets as $presetId => $preset ) {
$shortcodesAndPresets[ $presetId ] = array(
'name' => $preset,
'base' => $shortcode['base'],
'description' => $shortcode['description'],
'presetId' => $presetId,
'_category_ids' => array( '_my_elements_' ),
);
if ( isset( $shortcode['icon'] ) ) {
$shortcodesAndPresets[ $presetId ]['icon'] = $shortcode['icon'];
}
}
}
}
return $shortcodesAndPresets;
}
return $shortcodes;
}
/**
* @param $category
*
* @return array
*/
public static function addPresetCategory( $category ) {
$presetCategory = (array) '_my_elements_';
$category = array_merge( $presetCategory, $category );
return $category;
}
}

View File

@@ -0,0 +1,144 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Singleton to hold all vendor presets
*
* @since 4.8
*/
class Vc_Vendor_Preset {
private static $instance;
private static $presets = array();
/**
* @return \Vc_Vendor_Preset
*/
public static function getInstance() {
if ( ! self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
protected function __construct() {
}
/**
* Add vendor preset to collection
*
* @param string $title
* @param string $shortcode
* @param array $params
* @param bool $default
*
* @return bool
* @since 4.8
*
*/
public function add( $title, $shortcode, $params, $default = false ) {
if ( ! $title || ! is_string( $title ) || ! $shortcode || ! is_string( $shortcode ) || ! $params || ! is_array( $params ) ) {
return false;
}
$preset = array(
'shortcode' => $shortcode,
'default' => $default,
'params' => $params,
'title' => $title,
);
// @codingStandardsIgnoreLine
$id = md5( serialize( $preset ) );
self::$presets[ $id ] = $preset;
return true;
}
/**
* Get specific vendor preset
*
* @param string $id
*
* @return mixed array|false
* @since 4.8
*
*/
public function get( $id ) {
if ( isset( self::$presets[ $id ] ) ) {
return self::$presets[ $id ];
}
return false;
}
/**
* Get all vendor presets for specific shortcode
*
* @param string $shortcode
*
* @return array
* @since 4.8
*
*/
public function getAll( $shortcode ) {
$list = array();
foreach ( self::$presets as $id => $preset ) {
if ( $shortcode === $preset['shortcode'] ) {
$list[ $id ] = $preset;
}
}
return $list;
}
/**
* Get all default vendor presets
*
* Include only one default preset per shortcode
*
* @return array
* @since 4.8
*
*/
public function getDefaults() {
$list = array();
$added = array();
foreach ( self::$presets as $id => $preset ) {
if ( $preset['default'] && ! in_array( $preset['shortcode'], $added, true ) ) {
$added[] = $preset['shortcode'];
$list[ $id ] = $preset;
}
}
return $list;
}
/**
* Get ID of default preset for specific shortcode
*
* If multiple presets are default, return first
*
* @param string $shortcode
*
* @return string|null
* @since 4.8
*
*/
public function getDefaultId( $shortcode ) {
foreach ( self::$presets as $id => $preset ) {
if ( $shortcode === $preset['shortcode'] && $preset['default'] ) {
return $id;
}
}
return null;
}
}

View File

@@ -0,0 +1,43 @@
{
"params/hidden.php": "",
"params/vc_grid_item.php": "",
"vendors/acf.php": "",
"vendors/cf7.php": "",
"vendors/gravity_forms.php": "",
"vendors/jwplayer.php": "",
"vendors/layerslider.php": "",
"vendors/mqtranslate.php": "",
"vendors/ninja_forms.php": "",
"vendors/qtranslate.php": "",
"vendors/qtranslate-x.php": "",
"vendors/revslider.php": "",
"vendors/woocommerce.php": "",
"vendors/yoast_seo.php": "",
"vendors/wpml.php": "",
"vendors/gutenberg.php": "",
"hook-vc-grid.php": "Logic for shortcode vc_grid",
"hook-vc-iconpicker-param.php": "Logic for shortcode param iconpicker",
"hook-vc-message.php": "Logic for shortcode vc_message",
"hook-vc-progress-bar.php": "Logic for shortcode vc_progress_bar",
"hook-vc-wp-text.php": "Logic for shortcode vc_wp_text fix",
"hook-vc-pie.php": "Logic for shortcode vc_pie",
"vc-grid-item-editor.php": "Create new post type vc_grid_item or Grid item",
"ui-vc-pointers.php": "Integrating With WordPress UI: Admin Pointers",
"vc-pages/automapper.php": "",
"vc-pages/page-custom-css.php": "Vc Special pages.",
"vc-pages/page-design-options.php": "Vc Special pages.",
"vc-pages/page-role-manager.php": "Vc Special pages.",
"vc-pages/pages.php": "Vc Special pages.",
"vc-pages/settings-tabs.php": "Vc Special pages.",
"vc-pages/welcome-screen.php": "Vc Special pages.",
"vc-pointers-backend-editor.php": "Backend editor VC Pointers",
"vc-pointers-frontend-editor.php": "Frontend editor VC Pointers",
"vc-image-filters.php": "PHP class for photo effects like Instagram",
"vc-settings-presets.php": "Logic for settings presets",
"vc-single-image.php": "add bc for single image",
"params-to-init.php": "add required init params",
"bc-access-rules-4.8.php": "BC for roles via filters >= VC 4.8",
"post-type-default-template.php": "Load default templates",
"bc-multisite-options.php": "BC for multisite options",
"vc-undoredo.php": "Undo Redo logic"
}

View File

@@ -0,0 +1,182 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Class Vc_Hooks_Vc_Grid
* @since 4.4
*/
class Vc_Hooks_Vc_Grid {
protected $grid_id_unique_name = 'vc_gid'; // if you change this also change in vc-basic-grid.php
/**
* Initializing hooks for grid element,
* Add actions to save appended shortcodes to post meta (for rendering in preview with shortcode id)
* And add action to hook request for grid data, to output it.
* @since 4.4
*/
public function load() {
// Hook for set post settings meta with shortcodes data
/**
* @since 4.4.3
*/
add_filter( 'vc_hooks_vc_post_settings', array(
$this,
'gridSavePostSettingsId',
), 10, 3 );
/**
* Used to output shortcode data for ajax request. called on any page request.
*/
add_action( 'wp_ajax_vc_get_vc_grid_data', array(
$this,
'getGridDataForAjax',
) );
add_action( 'wp_ajax_nopriv_vc_get_vc_grid_data', array(
$this,
'getGridDataForAjax',
) );
}
/**
* @return string
* @since 4.4.3
*/
private function getShortcodeRegexForId() {
return '\\[' // Opening bracket
. '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]]
. '([\\w\-_]+)' // 2: Shortcode name
. '(?![\\w\-])' // Not followed by word character or hyphen
. '(' // 3: Unroll the loop: Inside the opening shortcode tag
. '[^\\]\\/]*' // Not a closing bracket or forward slash
. '(?:' . '\\/(?!\\])' // A forward slash not followed by a closing bracket
. '[^\\]\\/]*' // Not a closing bracket or forward slash
. ')*?'
. '(?:' . '(' . $this->grid_id_unique_name // 4: GridId must exist
. '[^\\]\\/]*' // Not a closing bracket or forward slash
. ')+' . ')'
. ')' . '(?:' . '(\\/)' // 5: Self closing tag ...
. '\\]' // ... and closing bracket
. '|' . '\\]' // Closing bracket
. '(?:' . '(' // 6: Unroll the loop: Optionally, anything between the opening and closing shortcode tags
. '[^\\[]*+' // Not an opening bracket
. '(?:' . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag
. '[^\\[]*+' // Not an opening bracket
. ')*+' . ')' . '\\[\\/\\2\\]' // Closing shortcode tag
. ')?' . ')' . '(\\]?)'; // 7: Optional second closing brocket for escaping shortcodes: [[tag]]
}
/**
* @param array $settings
* @param $post_id
* @param $post
*
* @return array
* @since 4.4.3
*
*/
public function gridSavePostSettingsId( array $settings, $post_id, $post ) {
$pattern = $this->getShortcodeRegexForId();
$content = stripslashes( $post->post_content );
preg_match_all( "/$pattern/", $content, $found ); // fetch only needed shortcodes
if ( is_array( $found ) && ! empty( $found[0] ) ) {
$to_save = array();
if ( isset( $found[1] ) && is_array( $found[1] ) ) {
foreach ( $found[1] as $key => $parse_able ) {
if ( empty( $parse_able ) || '[' !== $parse_able ) {
$id_pattern = '/' . $this->grid_id_unique_name . '\:([\w\-_]+)/';
$id_value = $found[4][ $key ];
preg_match( $id_pattern, $id_value, $id_matches );
if ( ! empty( $id_matches ) ) {
$id_to_save = $id_matches[1];
// why we need to check if shortcode is parse able?
// 1: if it is escaped it must not be displayed (parsed)
// 2: so if 1 is true it must not be saved in database meta
$shortcode_tag = $found[2][ $key ];
$shortcode_atts_string = $found[3][ $key ];
/** @var array $atts */
$atts = shortcode_parse_atts( $shortcode_atts_string );
$content = $found[6][ $key ];
$data = array(
'tag' => $shortcode_tag,
'atts' => $atts,
'content' => $content,
);
$to_save[ $id_to_save ] = $data;
}
}
}
}
if ( ! empty( $to_save ) ) {
$settings['vc_grid_id'] = array( 'shortcodes' => $to_save );
}
}
return $settings;
}
/**
* @throws \Exception
* @since 4.4
*
* @output/@return string - grid data for ajax request.
*/
public function getGridDataForAjax() {
$tag = str_replace( '.', '', vc_request_param( 'tag' ) );
$allowed = apply_filters( 'vc_grid_get_grid_data_access', vc_verify_public_nonce() && $tag, $tag );
if ( $allowed ) {
$shortcode_fishbone = visual_composer()->getShortCode( $tag );
if ( is_object( $shortcode_fishbone ) && vc_get_shortcode( $tag ) ) {
/** @var WPBakeryShortcode_Vc_Basic_Grid $vc_grid */
$vc_grid = $shortcode_fishbone->shortcodeClass();
if ( method_exists( $vc_grid, 'isObjectPageable' ) && $vc_grid->isObjectPageable() && method_exists( $vc_grid, 'renderAjax' ) ) {
// @codingStandardsIgnoreLine
wp_die( $vc_grid->renderAjax( vc_request_param( 'data' ) ) );
}
}
}
}
}
/**
* @since 4.4
* @var Vc_Hooks_Vc_Grid $hook
*/
$hook = new Vc_Hooks_Vc_Grid();
// when WPBakery Page Builder initialized let's trigger Vc_Grid hooks.
add_action( 'vc_after_init', array(
$hook,
'load',
) );
if ( 'vc_edit_form' === vc_post_param( 'action' ) ) {
VcShortcodeAutoloader::getInstance()->includeClass( 'WPBakeryShortCode_Vc_Basic_Grid' );
add_filter( 'vc_edit_form_fields_attributes_vc_basic_grid', array(
'WPBakeryShortCode_Vc_Basic_Grid',
'convertButton2ToButton3',
) );
add_filter( 'vc_edit_form_fields_attributes_vc_media_grid', array(
'WPBakeryShortCode_Vc_Basic_Grid',
'convertButton2ToButton3',
) );
add_filter( 'vc_edit_form_fields_attributes_vc_masonry_grid', array(
'WPBakeryShortCode_Vc_Basic_Grid',
'convertButton2ToButton3',
) );
add_filter( 'vc_edit_form_fields_attributes_vc_masonry_media_grid', array(
'WPBakeryShortCode_Vc_Basic_Grid',
'convertButton2ToButton3',
) );
}

View File

@@ -0,0 +1,88 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/***
* @since 4.4
* Hook Vc-Iconpicker-Param.php
*
* Adds actions and filters for iconpicker param.
* Used to:
* - register/enqueue icons fonts for admin pages
* - register/enqueue js for iconpicker param
* - register/enqueue css for iconpicker param
*/
// @see Vc_Base::frontCss, used to append actions when frontCss(frontend editor/and real view mode) method called
// This action registers all styles(fonts) to be enqueue later
add_action( 'vc_base_register_front_css', 'vc_iconpicker_base_register_css' );
// @see Vc_Base::registerAdminCss, used to append action when registerAdminCss(backend editor) method called
// This action registers all styles(fonts) to be enqueue later
add_action( 'vc_base_register_admin_css', 'vc_iconpicker_base_register_css' );
// @see Vc_Base::registerAdminJavascript, used to append action when registerAdminJavascript(backend/frontend editor) method called
// This action will register needed js file, and also you can use it for localizing js.
add_action( 'vc_base_register_admin_js', 'vc_iconpicker_base_register_js' );
// @see Vc_Backend_Editor::printScriptsMessages (wp-content/plugins/js_composer/include/classes/editors/class-vc-backend-editor.php),
// used to enqueue needed js/css files when backend editor is rendering
add_action( 'vc_backend_editor_enqueue_js_css', 'vc_iconpicker_editor_jscss' );
// @see Vc_Frontend_Editor::enqueueAdmin (wp-content/plugins/js_composer/include/classes/editors/class-vc-frontend-editor.php),
// used to enqueue needed js/css files when frontend editor is rendering
add_action( 'vc_frontend_editor_enqueue_js_css', 'vc_iconpicker_editor_jscss' );
/**
* This action registers all styles(fonts) to be enqueue later
* @see filter 'vc_base_register_front_css' - preview/frontend-editor
* filter 'vc_base_register_admin_css' - backend editor
*
* @since 4.4
*/
function vc_iconpicker_base_register_css() {
// Vc Icon picker fonts:
wp_register_style( 'vc_font_awesome_5_shims', vc_asset_url( 'lib/bower/font-awesome/css/v4-shims.min.css' ), array(), WPB_VC_VERSION );
wp_register_style( 'vc_font_awesome_5', vc_asset_url( 'lib/bower/font-awesome/css/all.min.css' ), array( 'vc_font_awesome_5_shims' ), WPB_VC_VERSION );
wp_register_style( 'vc_typicons', vc_asset_url( 'css/lib/typicons/src/font/typicons.min.css' ), false, WPB_VC_VERSION );
wp_register_style( 'vc_openiconic', vc_asset_url( 'css/lib/vc-open-iconic/vc_openiconic.min.css' ), false, WPB_VC_VERSION );
wp_register_style( 'vc_linecons', vc_asset_url( 'css/lib/vc-linecons/vc_linecons_icons.min.css' ), false, WPB_VC_VERSION );
wp_register_style( 'vc_entypo', vc_asset_url( 'css/lib/vc-entypo/vc_entypo.min.css' ), false, WPB_VC_VERSION );
wp_register_style( 'vc_monosocialiconsfont', vc_asset_url( 'css/lib/monosocialiconsfont/monosocialiconsfont.min.css' ), false, WPB_VC_VERSION );
wp_register_style( 'vc_material', vc_asset_url( 'css/lib/vc-material/vc_material.min.css' ), false, WPB_VC_VERSION );
// Theme
wp_register_style( 'vc-icon-picker-main-css', vc_asset_url( 'lib/bower/vcIconPicker/css/jquery.fonticonpicker.min.css' ), false, WPB_VC_VERSION );
wp_register_style( 'vc-icon-picker-main-css-theme', vc_asset_url( 'lib/bower/vcIconPicker/themes/grey-theme/jquery.fonticonpicker.vcgrey.min.css' ), false, WPB_VC_VERSION );
}
/**
* Register admin js for iconpicker functionality
*
* @since 4.4
*/
function vc_iconpicker_base_register_js() {
wp_register_script( 'vc-icon-picker', vc_asset_url( 'lib/bower/vcIconPicker/jquery.fonticonpicker.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
}
/**
* Enqueue ALL fonts/styles for Editor(admin) mode. (to allow easy change icons)
* - To append your icons fonts add action:
* vc_backend_editor_enqueue_jscss and vc_frontend_editor_enqueue_jscss
*
* @since 4.4
*/
function vc_iconpicker_editor_jscss() {
// Enqueue js and theme css files
wp_enqueue_script( 'vc-icon-picker' );
wp_enqueue_style( 'vc-icon-picker-main-css' );
wp_enqueue_style( 'vc-icon-picker-main-css-theme' );
// Fonts
wp_enqueue_style( 'vc_font_awesome_5' );
wp_enqueue_style( 'vc_openiconic' );
wp_enqueue_style( 'vc_typicons' );
wp_enqueue_style( 'vc_entypo' );
wp_enqueue_style( 'vc_linecons' );
wp_enqueue_style( 'vc_monosocialiconsfont' );
wp_enqueue_style( 'vc_material' );
}

View File

@@ -0,0 +1,13 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
if ( 'vc_edit_form' === vc_post_param( 'action' ) ) {
VcShortcodeAutoloader::getInstance()->includeClass( 'WPBakeryShortCode_Vc_Message' );
add_filter( 'vc_edit_form_fields_attributes_vc_message', array(
'WPBakeryShortCode_Vc_Message',
'convertAttributesToMessageBox2',
) );
}

View File

@@ -0,0 +1,12 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
if ( 'vc_edit_form' === vc_post_param( 'action' ) ) {
VcShortcodeAutoloader::getInstance()->includeClass( 'WPBakeryShortCode_Vc_Pie' );
add_filter( 'vc_edit_form_fields_attributes_vc_pie', array(
'WPBakeryShortCode_Vc_Pie',
'convertOldColorsToNew',
) );
}

View File

@@ -0,0 +1,13 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
if ( 'vc_edit_form' === vc_post_param( 'action' ) ) {
VcShortcodeAutoloader::getInstance()->includeClass( 'WPBakeryShortCode_Vc_Progress_Bar' );
add_filter( 'vc_edit_form_fields_attributes_vc_progress_bar', array(
'WPBakeryShortCode_Vc_Progress_Bar',
'convertAttributesToNewProgressBar',
) );
}

View File

@@ -0,0 +1,13 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
if ( 'vc_edit_form' === vc_post_param( 'action' ) ) {
VcShortcodeAutoloader::getInstance()->includeClass( 'WPBakeryShortCode_Vc_Wp_Text' );
add_filter( 'vc_edit_form_fields_attributes_vc_wp_text', array(
'WPBakeryShortCode_Vc_Wp_Text',
'convertTextAttributeToContent',
) );
}

View File

@@ -0,0 +1,79 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
add_filter( 'vc_edit_form_fields_optional_params', 'vc_edit_for_fields_add_optional_params' );
if ( 'vc_edit_form' === vc_post_param( 'action' ) ) {
add_action( 'vc_edit_form_fields_after_render', 'vc_output_required_params_to_init' );
add_filter( 'vc_edit_form_fields_optional_params', 'vc_edit_for_fields_add_optional_params' );
}
/**
* @param $params
* @return array
*/
function vc_edit_for_fields_add_optional_params( $params ) {
$arr = array(
'hidden',
'textfield',
'dropdown',
'checkbox',
'posttypes',
'taxonomies',
'taxomonies',
'exploded_textarea',
'textarea_raw_html',
'textarea_safe',
'textarea',
'attach_images',
'attach_image',
'widgetised_sidebars',
'colorpicker',
'loop',
'vc_link',
'sorted_list',
'tab_id',
'href',
'custom_markup',
'animation_style',
'iconpicker',
'el_id',
'vc_grid_item',
'google_fonts',
);
$params = array_values( array_unique( array_merge( $params, $arr ) ) );
return $params;
}
function vc_output_required_params_to_init() {
$params = WpbakeryShortcodeParams::getRequiredInitParams();
$js_array = array();
foreach ( $params as $param ) {
$js_array[] = '"' . $param . '"';
}
$data = '
if ( window.vc ) {
window.vc.required_params_to_init = [' . implode( ',', $js_array ) . '];
}';
$custom_tag = 'script';
$output = '<' . $custom_tag . '>' . $data . '</' . $custom_tag . '>';
echo $output;
}
add_action( 'wp_ajax_wpb_gallery_html', 'vc_gallery_html' );
function vc_gallery_html() {
vc_user_access()->checkAdminNonce()->validateDie()->wpAny( 'edit_posts', 'edit_pages' )->validateDie();
$images = vc_post_param( 'content' );
if ( ! empty( $images ) ) {
wp_send_json_success( vc_field_attached_images( explode( ',', $images ) ) );
}
die();
}

View File

@@ -0,0 +1,14 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* required hooks for hidden field.
* @since 4.5
*/
require_once vc_path_dir( 'PARAMS_DIR', 'hidden/hidden.php' );
vc_add_shortcode_param( 'hidden', 'vc_hidden_form_field' );
add_filter( 'vc_edit_form_fields_render_field_hidden_before', 'vc_edit_form_fields_render_field_hidden_before' );
add_filter( 'vc_edit_form_fields_render_field_hidden_after', 'vc_edit_form_fields_render_field_hidden_after' );

View File

@@ -0,0 +1,175 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @param $settings
* @param $value
* @return string
*/
function vc_vc_grid_item_form_field( $settings, $value ) {
require_once vc_path_dir( 'PARAMS_DIR', 'vc_grid_item/editor/class-vc-grid-item-editor.php' );
require_once vc_path_dir( 'PARAMS_DIR', 'vc_grid_item/class-vc-grid-item.php' );
$output = '<div data-vc-grid-element="container">' . '<select data-vc-grid-element="value" type="hidden" name="' . esc_attr( $settings['param_name'] ) . '" class="wpb_vc_param_value wpb-select ' . esc_attr( $settings['param_name'] ) . ' ' . esc_attr( $settings['type'] ) . '_field" ' . '>';
$vc_grid_item_templates = Vc_Grid_Item::predefinedTemplates();
if ( is_array( $vc_grid_item_templates ) ) {
foreach ( $vc_grid_item_templates as $key => $data ) {
$output .= '<option data-vc-link="' . esc_url( admin_url( 'post-new.php?post_type=vc_grid_item&vc_gitem_template=' . $key ) ) . '" value="' . esc_attr( $key ) . '"' . ( $key === $value ? ' selected="true"' : '' ) . '>' . esc_html( $data['name'] ) . '</option>';
}
}
$grid_item_posts = get_posts( array(
'posts_per_page' => '-1',
'orderby' => 'post_title',
'post_type' => Vc_Grid_Item_Editor::postType(),
) );
foreach ( $grid_item_posts as $post ) {
$output .= '<option data-vc-link="' . esc_url( get_edit_post_link( $post->ID ) ) . '"value="' . esc_attr( $post->ID ) . '"' . ( (string) $post->ID === $value ? ' selected="true"' : '' ) . '>' . esc_html( $post->post_title ) . '</option>';
}
$output .= '</select></div>';
return $output;
}
function vc_load_vc_grid_item_param() {
vc_add_shortcode_param( 'vc_grid_item', 'vc_vc_grid_item_form_field' );
}
add_action( 'vc_load_default_params', 'vc_load_vc_grid_item_param' );
/**
* @param $target
* @return string
*/
function vc_gitem_post_data_get_link_target_frontend_editor( $target ) {
return ' target="_blank"';
}
/**
* @param $rel
* @return string
*/
function vc_gitem_post_data_get_link_rel_frontend_editor( $rel ) {
return ' rel="' . esc_attr( $rel ) . '"';
}
/**
* @param $atts
* @param string $default_class
* @param string $title
* @return string
*/
function vc_gitem_create_link( $atts, $default_class = '', $title = '' ) {
$link = '';
$target = '';
$rel = '';
$title_attr = '';
$css_class = 'vc_gitem-link' . ( strlen( $default_class ) > 0 ? ' ' . $default_class : '' );
if ( isset( $atts['link'] ) ) {
if ( 'custom' === $atts['link'] && ! empty( $atts['url'] ) ) {
$link = vc_build_link( $atts['url'] );
if ( strlen( $link['target'] ) ) {
$target = ' target="' . esc_attr( $link['target'] ) . '"';
}
if ( strlen( $link['rel'] ) ) {
$rel = ' rel="' . esc_attr( $link['rel'] ) . '"';
}
if ( strlen( $link['title'] ) ) {
$title = $link['title'];
}
$link = 'a href="' . esc_url( $link['url'] ) . '" class="' . esc_attr( $css_class ) . '"';
} elseif ( 'post_link' === $atts['link'] ) {
$link = 'a href="{{ post_link_url }}" class="' . esc_attr( $css_class ) . '"';
if ( ! strlen( $title ) ) {
$title = '{{ post_title }}';
}
} elseif ( 'post_author' === $atts['link'] ) {
$link = 'a href="{{ post_author_href }}" class="' . esc_attr( $css_class ) . '"';
if ( ! strlen( $title ) ) {
$title = '{{ post_author }}';
}
} elseif ( 'image' === $atts['link'] ) {
$link = 'a{{ post_image_url_href }} class="' . esc_attr( $css_class ) . '"';
} elseif ( 'image_lightbox' === $atts['link'] ) {
$link = 'a{{ post_image_url_attr_prettyphoto:' . $css_class . ' }}';
}
}
if ( strlen( $title ) > 0 ) {
$title_attr = ' title="' . esc_attr( $title ) . '"';
}
return apply_filters( 'vc_gitem_post_data_get_link_link', $link, $atts, $css_class ) . apply_filters( 'vc_gitem_post_data_get_link_target', $target, $atts ) . apply_filters( 'vc_gitem_post_data_get_link_rel', $rel, $atts ) . apply_filters( 'vc_gitem_post_data_get_link_title', $title_attr, $atts );
}
/**
* @param $atts
* @param $post
* @param string $default_class
* @param string $title
* @return string
*/
function vc_gitem_create_link_real( $atts, $post, $default_class = '', $title = '' ) {
$link = '';
$target = '';
$rel = '';
$title_attr = '';
$link_css_class = 'vc_gitem-link';
if ( isset( $atts['link'] ) ) {
$link_css_class = 'vc_gitem-link' . ( strlen( $default_class ) > 0 ? ' ' . $default_class : '' );
if ( strlen( $atts['el_class'] ) > 0 ) {
$link_css_class .= ' ' . $atts['el_class'];
}
$link_css_class = trim( preg_replace( '/\s+/', ' ', $link_css_class ) );
if ( 'custom' === $atts['link'] && ! empty( $atts['url'] ) ) {
$link = vc_build_link( $atts['url'] );
if ( strlen( $link['target'] ) ) {
$target = ' target="' . esc_attr( $link['target'] ) . '"';
}
if ( strlen( $link['rel'] ) ) {
$rel = ' rel="' . esc_attr( $link['rel'] ) . '"';
}
if ( strlen( $link['title'] ) ) {
$title = $link['title'];
}
$link = 'a href="' . esc_url( $link['url'] ) . '" class="' . esc_attr( $link_css_class ) . '"';
} elseif ( 'post_link' === $atts['link'] ) {
$link = 'a href="' . esc_url( get_permalink( $post->ID ) ) . '" class="' . esc_attr( $link_css_class ) . '"';
if ( ! strlen( $title ) ) {
$title = the_title( '', '', false );
}
} elseif ( 'image' === $atts['link'] ) {
$href_link = vc_gitem_template_attribute_post_image_url( '', array(
'post' => $post,
'data' => '',
) );
$link = 'a href="' . esc_url( $href_link ) . '" class="' . esc_attr( $link_css_class ) . '"';
} elseif ( 'image_lightbox' === $atts['link'] ) {
$link = 'a' . vc_gitem_template_attribute_post_image_url_attr_prettyphoto( '', array(
'post' => $post,
'data' => esc_attr( $link_css_class ),
) );
}
}
if ( strlen( $title ) > 0 ) {
$title_attr = ' title="' . esc_attr( $title ) . '"';
}
return apply_filters( 'vc_gitem_post_data_get_link_real_link', $link, $atts, $post, $link_css_class ) . apply_filters( 'vc_gitem_post_data_get_link_real_target', $target, $atts, $post ) . apply_filters( 'vc_gitem_post_data_get_link_real_rel', $rel, $atts, $post ) . apply_filters( 'vc_gitem_post_data_get_link_real_title', $title_attr, $atts );
}
/**
* @param $link
* @return string
*/
function vc_gitem_post_data_get_link_link_frontend_editor( $link ) {
return empty( $link ) ? 'a' : $link;
}
if ( vc_is_page_editable() ) {
add_filter( 'vc_gitem_post_data_get_link_link', 'vc_gitem_post_data_get_link_link_frontend_editor' );
add_filter( 'vc_gitem_post_data_get_link_real_link', 'vc_gitem_post_data_get_link_link_frontend_editor' );
add_filter( 'vc_gitem_post_data_get_link_target', 'vc_gitem_post_data_get_link_target_frontend_editor' );
add_filter( 'vc_gitem_post_data_get_link_rel', 'vc_gitem_post_data_get_link_rel_frontend_editor' );
add_filter( 'vc_gitem_post_data_get_link_real_target', 'vc_gitem_post_data_get_link_target_frontend_editor' );
add_filter( 'vc_gitem_post_data_get_link_real_rel', 'vc_gitem_post_data_get_link_rel_frontend_editor' );
}

View File

@@ -0,0 +1,243 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Return true value for filter 'wpb_vc_js_status_filter'.
* It allows to start backend editor on load.
* @return string
* @since 4.12
*
*/
function vc_set_default_content_for_post_type_wpb_vc_js_status_filter() {
return 'true';
}
/**
* Set default content by post type in editor.
*
* Data for post type templates stored in settings.
*
* @param $post_content
* @param $post
* @return null
* @throws \Exception
* @since 4.12
*
*/
function vc_set_default_content_for_post_type( $post_content, $post ) {
if ( ! empty( $post_content ) || ! vc_backend_editor()->isValidPostType( $post->post_type ) ) {
return $post_content;
}
$template_settings = new Vc_Setting_Post_Type_Default_Template_Field( 'general', 'default_template_post_type' );
$new_post_content = $template_settings->getTemplateByPostType( $post->post_type );
if ( null !== $new_post_content ) {
add_filter( 'wpb_vc_js_status_filter', 'vc_set_default_content_for_post_type_wpb_vc_js_status_filter' );
return $new_post_content;
}
return $post_content;
}
/**
* Default template for post types manager
*
* Class Vc_Setting_Post_Type_Default_Template_Field
*
* @since 4.12
*/
class Vc_Setting_Post_Type_Default_Template_Field {
protected $tab;
protected $key;
protected $post_types = false;
/**
* Vc_Setting_Post_Type_Default_Template_Field constructor.
* @param $tab
* @param $key
*/
public function __construct( $tab, $key ) {
$this->tab = $tab;
$this->key = $key;
add_action( 'vc_settings_tab-general', array(
$this,
'addField',
) );
}
/**
* @return string
*/
protected function getFieldName() {
return esc_html__( 'Default template for post types', 'js_composer' );
}
/**
* @return string
*/
protected function getFieldKey() {
require_once vc_path_dir( 'SETTINGS_DIR', 'class-vc-settings.php' );
return Vc_Settings::getFieldPrefix() . $this->key;
}
/**
* @param $type
* @return bool
*/
protected function isValidPostType( $type ) {
return post_type_exists( $type );
}
/**
* @return array|bool
*/
protected function getPostTypes() {
if ( false === $this->post_types ) {
require_once vc_path_dir( 'SETTINGS_DIR', 'class-vc-roles.php' );
$vc_roles = new Vc_Roles();
$this->post_types = $vc_roles->getPostTypes();
}
return $this->post_types;
}
/**
* @return array
*/
protected function getTemplates() {
return $this->getTemplatesEditor()->getAllTemplates();
}
/**
* @return bool|\Vc_Templates_Panel_Editor
*/
protected function getTemplatesEditor() {
return visual_composer()->templatesPanelEditor();
}
/**
* Get settings data for default templates
*
* @return array|mixed
*/
protected function get() {
require_once vc_path_dir( 'SETTINGS_DIR', 'class-vc-settings.php' );
$value = Vc_Settings::get( $this->key );
return $value ? $value : array();
}
/**
* Get template's shortcodes string
*
* @param $template_data
* @return string|null
*/
protected function getTemplate( $template_data ) {
$template = null;
$template_settings = preg_split( '/\:\:/', $template_data );
$template_id = $template_settings[1];
$template_type = $template_settings[0];
if ( ! isset( $template_id, $template_type ) || '' === $template_id || '' === $template_type ) {
return $template;
}
WPBMap::addAllMappedShortcodes();
if ( 'my_templates' === $template_type ) {
$saved_templates = get_option( $this->getTemplatesEditor()->getOptionName() );
$content = trim( $saved_templates[ $template_id ]['template'] );
$content = str_replace( '\"', '"', $content );
$pattern = get_shortcode_regex();
$template = preg_replace_callback( "/{$pattern}/s", 'vc_convert_shortcode', $content );
} else {
if ( 'default_templates' === $template_type ) {
$template_data = $this->getTemplatesEditor()->getDefaultTemplate( (int) $template_id );
if ( isset( $template_data['content'] ) ) {
$template = $template_data['content'];
}
} else {
$template_preview = apply_filters( 'vc_templates_render_backend_template_preview', $template_id, $template_type );
if ( (string) $template_preview !== (string) $template_id ) {
$template = $template_preview;
}
}
}
return $template;
}
/**
* @param $type
* @return string|null
*/
public function getTemplateByPostType( $type ) {
$value = $this->get();
return isset( $value[ $type ] ) ? $this->getTemplate( $value[ $type ] ) : null;
}
/**
* @param $settings
* @return mixed
*/
public function sanitize( $settings ) {
foreach ( $settings as $type => $template ) {
if ( empty( $template ) ) {
unset( $settings[ $type ] );
} elseif ( ! $this->isValidPostType( $type ) || ! $this->getTemplate( $template ) ) {
add_settings_error( $this->getFieldKey(), 1, esc_html__( 'Invalid template or post type.', 'js_composer' ), 'error' );
return $settings;
}
}
return $settings;
}
public function render() {
vc_include_template( 'pages/vc-settings/default-template-post-type.tpl.php', array(
'post_types' => $this->getPostTypes(),
'templates' => $this->getTemplates(),
'title' => $this->getFieldName(),
'value' => $this->get(),
'field_key' => $this->getFieldKey(),
) );
}
/**
* Add field settings page
*
* Method called by vc hook vc_settings_tab-general.
*/
public function addField() {
vc_settings()->addField( $this->tab, $this->getFieldName(), $this->key, array(
$this,
'sanitize',
), array(
$this,
'render',
) );
}
}
/**
* Start only for admin part with hooks
*/
if ( is_admin() ) {
/**
* Initialize Vc_Setting_Post_Type_Default_Template_Field
* Called by admin_init hook
*/
function vc_settings_post_type_default_template_field_init() {
new Vc_Setting_Post_Type_Default_Template_Field( 'general', 'default_template_post_type' );
}
add_filter( 'default_content', 'vc_set_default_content_for_post_type', 100, 2 );
add_action( 'admin_init', 'vc_settings_post_type_default_template_field_init', 8 );
}

View File

@@ -0,0 +1,102 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
global $vc_default_pointers, $vc_pointers;
$vc_default_pointers = (array) apply_filters( 'vc_pointers_list', array(
'vc_grid_item',
'vc_pointers_backend_editor',
'vc_pointers_frontend_editor',
) );
if ( is_admin() ) {
add_action( 'admin_enqueue_scripts', 'vc_pointer_load', 1000 );
}
function vc_pointer_load() {
global $vc_pointers;
// Don't run on WP < 3.3
if ( get_bloginfo( 'version' ) < '3.3' ) {
return;
}
$screen = get_current_screen();
$screen_id = $screen->id;
// Get pointers for this screen
$pointers = apply_filters( 'vc-ui-pointers', array() );
$pointers = apply_filters( 'vc_ui-pointers-' . $screen_id, $pointers );
if ( ! $pointers || ! is_array( $pointers ) ) {
return;
}
// Get dismissed pointers
$dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
$vc_pointers = array( 'pointers' => array() );
// Check pointers and remove dismissed ones.
foreach ( $pointers as $pointer_id => $pointer ) {
// Sanity check
if ( in_array( $pointer_id, $dismissed, true ) || empty( $pointer ) || empty( $pointer_id ) || empty( $pointer['name'] ) ) {
continue;
}
$pointer['pointer_id'] = $pointer_id;
// Add the pointer to $valid_pointers array
$vc_pointers['pointers'][] = $pointer;
}
// No valid pointers? Stop here.
if ( empty( $vc_pointers['pointers'] ) ) {
return;
}
wp_enqueue_style( 'wp-pointer' );
wp_enqueue_script( 'wp-pointer' );
// messages
$vc_pointers['texts'] = array(
'finish' => esc_html__( 'Finish', 'js_composer' ),
'next' => esc_html__( 'Next', 'js_composer' ),
'prev' => esc_html__( 'Prev', 'js_composer' ),
);
// Add pointer options to script.
wp_localize_script( 'wp-pointer', 'vcPointer', $vc_pointers );
}
/**
* Remove Vc pointers keys to show Tour markers again.
* @sine 4.5
*/
function vc_pointer_reset() {
global $vc_default_pointers;
vc_user_access()->checkAdminNonce()->validateDie()->wpAny( 'manage_options' )->validateDie()->part( 'settings' )->can( 'vc-general-tab' )->validateDie();
$pointers = (array) apply_filters( 'vc_pointers_list', $vc_default_pointers );
$prev_meta_value = get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true );
$dismissed = explode( ',', (string) $prev_meta_value );
if ( count( $dismissed ) > 0 && count( $pointers ) ) {
$meta_value = implode( ',', array_diff( $dismissed, $pointers ) );
update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $meta_value, $prev_meta_value );
}
wp_send_json( array( 'success' => true ) );
}
/**
* Reset tour guid
* @return bool
*/
function vc_pointers_is_dismissed() {
global $vc_default_pointers;
$pointers = (array) apply_filters( 'vc_pointers_list', $vc_default_pointers );
$prev_meta_value = get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true );
$dismissed = explode( ',', (string) $prev_meta_value );
return count( array_diff( $dismissed, $pointers ) ) < count( $dismissed );
}
add_action( 'wp_ajax_vc_pointer_reset', 'vc_pointer_reset' );

View File

@@ -0,0 +1,298 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
global $vc_grid_item_editor;
/**
* Creates new post type for grid_editor.
*
* @since 4.4
*/
function vc_grid_item_editor_create_post_type() {
if ( is_admin() ) {
require_once vc_path_dir( 'PARAMS_DIR', 'vc_grid_item/editor/class-vc-grid-item-editor.php' );
Vc_Grid_Item_Editor::createPostType();
add_action( 'vc_menu_page_build', 'vc_gitem_add_submenu_page' );
// TODO: add check vendor is active
add_filter( 'vc_vendor_qtranslate_enqueue_js_backend', 'vc_vendor_qtranslate_enqueue_js_backend_grid_editor' );
}
}
/**
* @since 4.5
*/
function vc_vendor_qtranslate_enqueue_js_backend_grid_editor() {
return true;
}
/**
* Set required objects to render editor for grid item
*
* @since 4.4
*/
function vc_grid_item_editor_init() {
global $vc_grid_item_editor;
require_once vc_path_dir( 'PARAMS_DIR', 'vc_grid_item/editor/class-vc-grid-item-editor.php' );
require_once vc_path_dir( 'PARAMS_DIR', 'vc_grid_item/class-wpb-map-grid-item.php' );
$vc_grid_item_editor = new Vc_Grid_Item_Editor();
$vc_grid_item_editor->addMetaBox();
add_action( 'wp_ajax_vc_grid_item_editor_load_template_preview', array(
&$vc_grid_item_editor,
'renderTemplatePreview',
) );
$vc_grid_item_editor->addHooksSettings();
}
/**
* Render preview for grid item
* @since 4.4
*/
function vc_grid_item_render_preview() {
vc_user_access()->checkAdminNonce()->validateDie()->wpAny( array(
'edit_post',
(int) vc_request_param( 'post_id' ),
) )->validateDie()->part( 'grid_builder' )->can()->validateDie();
require_once vc_path_dir( 'PARAMS_DIR', 'vc_grid_item/class-vc-grid-item.php' );
$grid_item = new Vc_Grid_Item();
$grid_item->mapShortcodes();
require_once vc_path_dir( 'PARAMS_DIR', 'vc_grid_item/editor/class-vc-grid-item-preview.php' );
$vcGridPreview = new Vc_Grid_Item_Preview();
add_filter( 'vc_gitem_template_attribute_post_image_background_image_css_value', array(
$vcGridPreview,
'addCssBackgroundImage',
) );
add_filter( 'vc_gitem_template_attribute_post_image_url_value', array(
$vcGridPreview,
'addImageUrl',
) );
add_filter( 'vc_gitem_template_attribute_post_image_html', array(
$vcGridPreview,
'addImage',
) );
add_filter( 'vc_gitem_attribute_featured_image_img', array(
$vcGridPreview,
'addPlaceholderImage',
) );
add_filter( 'vc_gitem_post_data_get_link_real_link', array(
$vcGridPreview,
'disableRealContentLink',
), 10, 4 );
add_filter( 'vc_gitem_post_data_get_link_link', array(
$vcGridPreview,
'disableContentLink',
), 10, 3 );
add_filter( 'vc_gitem_zone_image_block_link', array(
$vcGridPreview,
'disableGitemZoneLink',
) );
$vcGridPreview->render();
die();
}
/**
* Map grid element shortcodes.
*
* @since 4.5
*/
function vc_grid_item_map_shortcodes() {
require_once vc_path_dir( 'PARAMS_DIR', 'vc_grid_item/class-vc-grid-item.php' );
$grid_item = new Vc_Grid_Item();
$grid_item->mapShortcodes();
vc_mapper()->setCheckForAccess( false );
}
/**
* Get current post type
*
* @return null|string
*/
function vc_grid_item_get_post_type() {
$post_type = null;
if ( vc_request_param( 'post_type' ) ) {
$post_type = vc_request_param( 'post_type' );
} elseif ( vc_request_param( 'post' ) ) {
$post = get_post( vc_request_param( 'post' ) );
$post_type = $post instanceof WP_Post && $post->post_type ? $post->post_type : null;
}
return $post_type;
}
/**
* Check and Map grid element shortcodes if required.
* @since 4.5
*/
function vc_grid_item_editor_shortcodes() {
require_once vc_path_dir( 'PARAMS_DIR', 'vc_grid_item/editor/class-vc-grid-item-editor.php' );
// TODO: remove this because mapping can be based on post_type
if ( ( 'true' === vc_request_param( 'vc_grid_item_editor' ) || ( is_admin() && vc_grid_item_get_post_type() === Vc_Grid_Item_Editor::postType() ) && vc_user_access()
->wpAny( 'edit_posts', 'edit_pages' )->part( 'grid_builder' )->can()->get() ) ) {
global $vc_grid_item_editor;
add_action( 'vc_user_access_check-shortcode_edit', array(
&$vc_grid_item_editor,
'accessCheckShortcodeEdit',
), 10, 2 );
add_action( 'vc_user_access_check-shortcode_all', array(
&$vc_grid_item_editor,
'accessCheckShortcodeAll',
), 10, 2 );
vc_grid_item_map_shortcodes();
}
}
/**
* add action in admin for vc grid item editor manager
*/
add_action( 'init', 'vc_grid_item_editor_create_post_type' );
add_action( 'admin_init', 'vc_grid_item_editor_init' );
add_action( 'vc_after_init', 'vc_grid_item_editor_shortcodes' );
/**
* Call preview as ajax request is called.
*/
add_action( 'wp_ajax_vc_gitem_preview', 'vc_grid_item_render_preview', 5 );
/**
* Add WP ui pointers in grid element editor.
*/
if ( is_admin() ) {
add_filter( 'vc_ui-pointers-vc_grid_item', 'vc_grid_item_register_pointer' );
}
/**
* @param $pointers
* @return mixed
*/
function vc_grid_item_register_pointer( $pointers ) {
$screen = get_current_screen();
if ( 'add' === $screen->action ) {
$pointers['vc_grid_item'] = array(
'name' => 'vcPointersController',
'messages' => array(
array(
'target' => '#vc_templates-editor-button',
'options' => array(
'content' => sprintf( '<h3> %s </h3> <p> %s </p>', esc_html__( 'Start Here!', 'js_composer' ), esc_html__( 'Start easy - use predefined template as a starting point and modify it.', 'js_composer' ) ),
'position' => array(
'edge' => 'left',
'align' => 'center',
),
),
),
array(
'target' => '[data-vc-navbar-control="animation"]',
'options' => array(
'content' => sprintf( '<h3> %s </h3> <p> %s </p>', esc_html__( 'Use Animations', 'js_composer' ), esc_html__( 'Select animation preset for grid element. "Hover" state will be added next to the "Normal" state tab.', 'js_composer' ) ),
'position' => array(
'edge' => 'right',
'align' => 'center',
),
),
),
array(
'target' => '.vc_gitem_animated_block-shortcode',
'options' => array(
'content' => sprintf( '<h3> %s </h3> <p> %s </p>', esc_html__( 'Style Design Options', 'js_composer' ), esc_html__( 'Edit "Normal" state to set "Featured image" as a background, control zone sizing proportions and other design options (Height mode: Select "Original" to scale image without cropping).', 'js_composer' ) ),
'position' => array(
'edge' => 'bottom',
'align' => 'center',
),
),
),
array(
'target' => '[data-vc-gitem="add-c"][data-vc-position="top"]',
'options' => array(
'content' => sprintf( '<h3> %s </h3> <p> %s </p>', esc_html__( 'Extend Element', 'js_composer' ), esc_html__( 'Additional content zone can be added to grid element edges (Note: This zone can not be animated).', 'js_composer' ) ) . '<p><img src="' . esc_url( vc_asset_url( 'vc/gb_additional_content.png' ) ) . '" alt="" /></p>',
'position' => array(
'edge' => 'right',
'align' => 'center',
),
),
),
array(
'target' => '#wpadminbar',
'options' => array(
'content' => sprintf( '<h3> %s </h3> %s', esc_html__( 'Watch Video Tutorial', 'js_composer' ), '<p>' . esc_html__( 'Have a look how easy it is to work with grid element builder.', 'js_composer' ) . '</p>' . '<iframe width="500" height="281" src="https://www.youtube.com/embed/sBvEiIL6Blo" frameborder="0" allowfullscreen></iframe>' ),
'position' => array(
'edge' => 'top',
'align' => 'center',
),
'pointerClass' => 'vc_gitem-animated-block-pointer-video',
'pointerWidth' => '530',
),
),
),
);
}
return $pointers;
}
/**
* @return array|mixed|void
*/
function vc_gitem_content_shortcodes() {
require_once vc_path_dir( 'PARAMS_DIR', 'vc_grid_item/class-vc-grid-item.php' );
$grid_item = new Vc_Grid_Item();
$invalid_shortcodes = apply_filters( 'vc_gitem_zone_grid_item_not_content_shortcodes', array(
'vc_gitem',
'vc_gitem_animated_block',
'vc_gitem_zone',
'vc_gitem_zone_a',
'vc_gitem_zone_b',
'vc_gitem_zone_c',
'vc_gitem_row',
'vc_gitem_col',
) );
return array_diff( array_keys( $grid_item->shortcodes() ), $invalid_shortcodes );
}
/**
* @param $content
* @return false|int
*/
function vc_gitem_has_content( $content ) {
$tags = vc_gitem_content_shortcodes();
$regexp = vc_get_shortcode_regex( implode( '|', $tags ) );
return preg_match( '/' . $regexp . '/', $content );
}
/**
* Add sub page to WPBakery Page Builder pages
*
* @since 4.5
*/
function vc_gitem_add_submenu_page() {
if ( vc_user_access()->part( 'grid_builder' )->can()->get() ) {
$labels = Vc_Grid_Item_Editor::getPostTypesLabels();
add_submenu_page( VC_PAGE_MAIN_SLUG, $labels['name'], $labels['name'], 'edit_posts', 'edit.php?post_type=' . rawurlencode( Vc_Grid_Item_Editor::postType() ), '' );
}
}
/**
* Highlight Vc submenu.
* @since 4.5
*/
function vc_gitem_menu_highlight() {
global $parent_file, $submenu_file, $post_type;
require_once vc_path_dir( 'PARAMS_DIR', 'vc_grid_item/editor/class-vc-grid-item-editor.php' );
if ( Vc_Grid_Item_Editor::postType() === $post_type && defined( 'VC_PAGE_MAIN_SLUG' ) ) {
$parent_file = VC_PAGE_MAIN_SLUG;
$submenu_file = 'edit.php?post_type=' . rawurlencode( Vc_Grid_Item_Editor::postType() );
}
}
add_action( 'admin_head', 'vc_gitem_menu_highlight' );
function vc_gitem_set_mapper_check_access() {
if ( vc_user_access()->checkAdminNonce()->wpAny( 'edit_posts', 'edit_pages' )->part( 'grid_builder' )->can()->get() && 'true' === vc_post_param( 'vc_grid_item_editor' ) ) {
vc_mapper()->setCheckForAccess( false );
}
}
add_action( 'wp_ajax_vc_edit_form', 'vc_gitem_set_mapper_check_access' );

View File

@@ -0,0 +1,358 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
add_filter( 'attachment_fields_to_edit', 'vc_attachment_filter_field', 10, 2 );
add_filter( 'media_meta', 'vc_attachment_filter_media_meta', 10, 2 );
add_action( 'wp_ajax_vc_media_editor_add_image', 'vc_media_editor_add_image' );
add_action( 'wp_ajax_vc_media_editor_preview_image', 'vc_media_editor_preview_image' );
/**
* @return array
*/
function vc_get_filters() {
return array(
'antique' => esc_html__( 'Antique', 'js_composer' ),
'blackwhite' => esc_html__( 'Black & White', 'js_composer' ),
'boost' => esc_html__( 'Boost', 'js_composer' ),
'concentrate' => esc_html__( 'Concentrate', 'js_composer' ),
'country' => esc_html__( 'Country', 'js_composer' ),
'darken' => esc_html__( 'Darken', 'js_composer' ),
'dream' => esc_html__( 'Dream', 'js_composer' ),
'everglow' => esc_html__( 'Everglow', 'js_composer' ),
'forest' => esc_html__( 'Forest', 'js_composer' ),
'freshblue' => esc_html__( 'Fresh Blue', 'js_composer' ),
'frozen' => esc_html__( 'Frozen', 'js_composer' ),
'hermajesty' => esc_html__( 'Her Majesty', 'js_composer' ),
'light' => esc_html__( 'Light', 'js_composer' ),
'orangepeel' => esc_html__( 'Orange Peel', 'js_composer' ),
'rain' => esc_html__( 'Rain', 'js_composer' ),
'retro' => esc_html__( 'Retro', 'js_composer' ),
'sepia' => esc_html__( 'Sepia', 'js_composer' ),
'summer' => esc_html__( 'Summer', 'js_composer' ),
'tender' => esc_html__( 'Tender', 'js_composer' ),
'vintage' => esc_html__( 'Vintage', 'js_composer' ),
'washed' => esc_html__( 'Washed', 'js_composer' ),
);
}
/**
* Add Image Filter field to media uploader
*
* @param array $form_fields , fields to include in attachment form
* @param object $post , attachment record in database
*
* @return array $form_fields, modified form fields
*/
function vc_attachment_filter_field( $form_fields, $post ) {
// don't add filter field, if image already has filter applied
if ( get_post_meta( $post->ID, 'vc-applied-image-filter', true ) ) {
return $form_fields;
}
$options = vc_get_filters();
$html_options = '<option value="">' . esc_html__( 'None', 'js_composer' ) . '</option>';
foreach ( $options as $value => $title ) {
$html_options .= '<option value="' . esc_attr( $value ) . '">' . esc_html( $title ) . '</option>';
}
$form_fields['vc-image-filter'] = array(
'label' => '',
'input' => 'html',
'html' => '
<div style="display:none">
<span class="vc-filter-label">' . esc_html__( 'Image filter', 'js_composer' ) . '</span>
<select name="attachments[' . esc_attr( $post->ID ) . '][vc-image-filter]" id="attachments-' . esc_attr( $post->ID ) . '-vc-image-filter" data-vc-preview-image-filter="' . esc_attr( $post->ID ) . '">
' . $html_options . '
</select>
</div>',
'value' => get_post_meta( $post->ID, 'vc_image_filter', true ),
'helps' => '',
);
return $form_fields;
}
/**
* Apply filters to specified images
*
* If image(s) has filter specified via filters _POST param:
* 1) copy it
* 2) apply specified filter
* 3) return new image id
*
* Required _POST params:
* - array ids: array of attachment ids
*
* Optional _POST params:
* - array filters: mapped array of ids and filters to apply
*
*/
function vc_media_editor_add_image() {
vc_user_access()->checkAdminNonce()->validateDie()->wpAny( 'upload_files' )->validateDie();
require_once vc_path_dir( 'HELPERS_DIR', 'class-vc-image-filter.php' );
$response = array(
'success' => true,
'data' => array(
'ids' => array(),
),
);
$filters = (array) vc_post_param( 'filters', array() );
$ids = (array) vc_post_param( 'ids', array() );
if ( ! $ids ) {
wp_send_json( $response );
}
// default action is wp_handle_upload, which forces wp to check upload with is_uploaded_file()
// override action to anything else to skip security checks
$action = 'vc_handle_upload_imitation';
$file_key = 0;
$post_id = 0;
$post_data = array();
$overrides = array( 'action' => $action );
$_POST = array( 'action' => $action );
foreach ( $ids as $key => $attachment_id ) {
if ( ! empty( $filters[ $attachment_id ] ) ) {
$filter_name = $filters[ $attachment_id ];
} else {
continue;
}
$source_path = get_attached_file( $attachment_id );
if ( empty( $source_path ) ) {
continue;
}
$temp_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . basename( $source_path );
if ( ! copy( $source_path, $temp_path ) ) {
continue;
}
$extension = strtolower( pathinfo( $temp_path, PATHINFO_EXTENSION ) );
$mime_type = '';
switch ( $extension ) {
case 'jpeg':
case 'jpg':
$image = imagecreatefromjpeg( $temp_path );
$mime_type = 'image/jpeg';
break;
case 'png':
$image = imagecreatefrompng( $temp_path );
$mime_type = 'image/png';
break;
case 'gif':
$image = imagecreatefromgif( $temp_path );
$mime_type = 'image/gif';
break;
default:
$image = false;
}
if ( ! $image ) {
continue;
}
$Filter = new vcImageFilter( $image );
$Filter->$filter_name();
if ( ! vc_save_gd_resource( $Filter->getImage(), $temp_path ) ) {
continue;
}
$new_filename = basename( $temp_path, '.' . $extension ) . '-' . $filter_name . '.' . $extension;
$_FILES = array(
array(
'name' => $new_filename,
'type' => $mime_type,
'tmp_name' => $temp_path,
'error' => UPLOAD_ERR_OK,
'size' => filesize( $temp_path ),
),
);
$new_attachment_id = media_handle_upload( $file_key, $post_id, $post_data, $overrides );
if ( ! $new_attachment_id || is_wp_error( $new_attachment_id ) ) {
continue;
}
update_post_meta( $new_attachment_id, 'vc-applied-image-filter', $filter_name );
$ids[ $key ] = $new_attachment_id;
}
$response['data']['ids'] = $ids;
wp_send_json( $response );
}
/**
* Generate filter preview
*
* Preview url is generated as data uri (base64)
*
* Required _POST params:
* - string filter: filter name
* - int attachment_id: attachment id
*
* @return void Results are sent out as json
* @throws \Exception
*/
function vc_media_editor_preview_image() {
vc_user_access()->checkAdminNonce()->validateDie()->wpAny( 'upload_files' )->validateDie();
require_once vc_path_dir( 'HELPERS_DIR', 'class-vc-image-filter.php' );
$response = array(
'success' => true,
'data' => array(
'src' => '',
),
);
$filter_name = vc_post_param( 'filter', '' );
$attachment_id = vc_post_param( 'attachment_id', false );
$preferred_size = vc_post_param( 'preferred_size', 'medium' );
if ( ! $filter_name || ! $attachment_id ) {
wp_send_json( $response );
}
$attachment_path = get_attached_file( $attachment_id );
$attachment_details = wp_prepare_attachment_for_js( $attachment_id );
if ( ! isset( $attachment_details['sizes'][ $preferred_size ] ) ) {
$preferred_size = 'thumbnail';
}
$attachment_url = wp_get_attachment_image_src( $attachment_id, $preferred_size );
if ( empty( $attachment_path ) || empty( $attachment_url[0] ) ) {
wp_send_json( $response );
}
$source_path = dirname( $attachment_path ) . '/' . basename( $attachment_url[0] );
$image = vc_get_gd_resource( $source_path );
if ( ! $image ) {
wp_send_json( $response );
}
$Filter = new vcImageFilter( $image );
$Filter->$filter_name();
$extension = strtolower( pathinfo( $source_path, PATHINFO_EXTENSION ) );
ob_start();
switch ( $extension ) {
case 'jpeg':
case 'jpg':
imagejpeg( $Filter->getImage() );
break;
case 'png':
imagepng( $Filter->getImage() );
break;
case 'gif':
imagegif( $Filter->getImage() );
break;
}
$data = ob_get_clean();
// @codingStandardsIgnoreLine
$response['data']['src'] = 'data:image/' . $extension . ';base64,' . base64_encode( $data );
wp_send_json( $response );
}
/**
* Read file from disk as GD resource
*
* @param string $file
*
* @return bool|resource
*/
function vc_get_gd_resource( $file ) {
$extension = strtolower( pathinfo( $file, PATHINFO_EXTENSION ) );
switch ( $extension ) {
case 'jpeg':
case 'jpg':
return imagecreatefromjpeg( $file );
case 'png':
return imagecreatefrompng( $file );
case 'gif':
return imagecreatefromgif( $file );
}
return false;
}
/**
* Save GD resource to file
*
* @param resource $resource
* @param string $file
*
* @return bool
*/
function vc_save_gd_resource( $resource, $file ) {
$extension = strtolower( pathinfo( $file, PATHINFO_EXTENSION ) );
switch ( $extension ) {
case 'jpeg':
case 'jpg':
return imagejpeg( $resource, $file );
case 'png':
return imagepng( $resource, $file );
case 'gif':
return imagegif( $resource, $file );
}
return false;
}
/**
* Add "Filter: ..." meta field to attachment details box
*
* @param array $media_meta , meta to include in attachment form
* @param object $post , attachment record in database
*
* @return array|string
*/
function vc_attachment_filter_media_meta( $media_meta, $post ) {
$filter_name = get_post_meta( $post->ID, 'vc-applied-image-filter', true );
if ( ! $filter_name ) {
return $media_meta;
}
$filters = vc_get_filters();
if ( ! isset( $filters[ $filter_name ] ) ) {
return $media_meta;
}
$media_meta .= esc_html__( 'Filter:', 'js_composer' ) . ' ' . $filters[ $filter_name ];
return $media_meta;
}

View File

@@ -0,0 +1,29 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Build and enqueue js/css for automapper settings tab.
* @since 4.5
*/
function vc_automapper_init() {
if ( vc_user_access()->wpAny( 'manage_options' )->part( 'settings' )->can( 'vc-automapper-tab' )->get() ) {
vc_automapper()->addAjaxActions();
}
}
/**
* Returns automapper template.
*
* @return string
* @since 4.5
*/
function vc_page_automapper_build() {
return 'pages/vc-settings/vc-automapper.php';
}
// TODO: move to separate file in autoload
add_filter( 'vc_settings-render-tab-vc-automapper', 'vc_page_automapper_build' );
is_admin() && ( strpos( vc_request_param( 'action' ), 'vc_automapper' ) !== false || 'vc-automapper' === vc_get_param( 'page' ) ) && add_action( 'admin_init', 'vc_automapper_init' );

View File

@@ -0,0 +1,10 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
function vc_page_settings_custom_css_load() {
wp_enqueue_script( 'ace-editor', vc_asset_url( 'lib/bower/ace-builds/src-min-noconflict/ace.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
}
add_action( 'vc-settings-render-tab-vc-custom_css', 'vc_page_settings_custom_css_load' );

View File

@@ -0,0 +1,140 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Used to check for current less version during page open
*
* @since 4.5
*/
add_action( 'vc_before_init', 'vc_check_for_custom_css_build' );
/**
* Function check is system has custom build of css
* and check it version in comparison with current VC version
*
* @since 4.5
*/
function vc_check_for_custom_css_build() {
$version = vc_settings()->getCustomCssVersion();
if ( vc_user_access()->wpAny( 'manage_options' )->part( 'settings' )->can( 'vc-color-tab' )
->get() && vc_settings()->useCustomCss() && ( ! $version || version_compare( WPB_VC_VERSION, $version, '<>' ) ) ) {
add_action( 'admin_notices', 'vc_custom_css_admin_notice' );
}
}
/**
* Display admin notice depending on current page
*
* @since 4.5
*/
function vc_custom_css_admin_notice() {
global $current_screen;
vc_settings()->set( 'compiled_js_composer_less', '' );
$class = 'notice notice-warning vc_settings-custom-design-notice';
$message_important = esc_html__( 'Important notice', 'js_composer' );
if ( is_object( $current_screen ) && isset( $current_screen->id ) && 'visual-composer_page_vc-color' === $current_screen->id ) {
$message = esc_html__( 'You have an outdated version of WPBakery Page Builder Design Options. It is required to review and save it.', 'js_composer' );
echo '<div class="' . esc_attr( $class ) . '"><p><strong>' . esc_html( $message_important ) . '</strong>: ' . esc_html( $message ) . '</p></div>';
} else {
$message = esc_html__( 'You have an outdated version of WPBakery Page Builder Design Options. It is required to review and save it.', 'js_composer' );
$btnClass = 'button button-primary button-large vc_button-settings-less';
echo '<div class="' . esc_attr( $class ) . '"><p><strong>' . esc_html( $message_important ) . '</strong>: ' . esc_html( $message ) . '</p>' . '<p>';
echo '<a ' . implode( ' ', array(
'href="' . esc_url( admin_url( 'admin.php?page=vc-color' ) ) . '"',
'class="' . esc_attr( $btnClass ) . '"',
'id="vc_less-save-button"',
'style="vertical-align: baseline;"',
// needed to fix ":active bug"
) ) . '>';
echo esc_html__( 'Open Design Options', 'js_composer' ) . '</a>';
echo '</p></div>';
}
}
/**
* @param $submitButtonAttributes
* @return mixed
*/
function vc_page_settings_tab_color_submit_attributes( $submitButtonAttributes ) {
$submitButtonAttributes['data-vc-less-path'] = vc_str_remove_protocol( vc_asset_url( 'less/js_composer.less' ) );
$submitButtonAttributes['data-vc-less-root'] = vc_str_remove_protocol( vc_asset_url( 'less' ) );
$submitButtonAttributes['data-vc-less-variables'] = wp_json_encode( apply_filters( 'vc_settings-less-variables', array(
// Main accent color:
'vc_grey' => array(
'key' => 'wpb_js_vc_color',
'default' => vc_settings()->getDefault( 'vc_color' ),
),
// Hover color
'vc_grey_hover' => array(
'key' => 'wpb_js_vc_color_hover',
'default' => vc_settings()->getDefault( 'vc_color_hover' ),
),
'vc_image_slider_link_active' => 'wpb_js_vc_color_hover',
// Call to action background color
'vc_call_to_action_bg' => 'wpb_js_vc_color_call_to_action_bg',
'vc_call_to_action_2_bg' => 'wpb_js_vc_color_call_to_action_bg',
'vc_call_to_action_border' => array(
'key' => 'wpb_js_vc_color_call_to_action_border',
// darken 5%
'default_key' => 'wpb_js_vc_color',
'modify_output' => array(
array(
'plain' => array(
'darken({{ value }}, 5%)',
),
),
),
),
// Google maps background color
'vc_google_maps_bg' => 'wpb_js_vc_color_google_maps_bg',
// Post slider caption background color
'vc_post_slider_caption_bg' => 'wpb_js_vc_color_post_slider_caption_bg',
// Progress bar background color
'vc_progress_bar_bg' => 'wpb_js_vc_color_progress_bar_bg',
// Separator border color
'vc_separator_border' => 'wpb_js_vc_color_separator_border',
// Tabs navigation background color
'vc_tab_bg' => 'wpb_js_vc_color_tab_bg',
// Active tab background color
'vc_tab_bg_active' => 'wpb_js_vc_color_tab_bg_active',
// Elements bottom margin
'vc_element_margin_bottom' => array(
'key' => 'wpb_js_margin',
'default' => vc_settings()->getDefault( 'margin' ),
),
// Grid gutter width
'grid-gutter-width' => array(
'key' => 'wpb_js_gutter',
'default' => vc_settings()->getDefault( 'gutter' ),
'modify_output' => array(
array(
'plain' => array(
'{{ value }}px',
),
),
),
),
'screen-sm-min' => array(
'key' => 'wpb_js_responsive_max',
'default' => vc_settings()->getDefault( 'responsive_max' ),
'modify_output' => array(
array(
'plain' => array(
'{{ value }}px',
),
),
),
),
) ) );
return $submitButtonAttributes;
}
function vc_page_settings_desing_options_load() {
add_filter( 'vc_settings-tab-submit-button-attributes-color', 'vc_page_settings_tab_color_submit_attributes' );
wp_enqueue_script( 'vc_less_js', vc_asset_url( 'lib/bower/lessjs/dist/less.min.js' ), array(), WPB_VC_VERSION, true );
}
add_action( 'vc-settings-render-tab-vc-color', 'vc_page_settings_desing_options_load' );

View File

@@ -0,0 +1,57 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @param $tabs
* @return array
*/
function vc_settings_tabs_vc_roles( $tabs ) {
// inster after vc-general tab
if ( array_key_exists( 'vc-general', $tabs ) ) {
$new = array();
foreach ( $tabs as $key => $value ) {
$new[ $key ] = $value;
if ( 'vc-general' === $key ) {
$new['vc-roles'] = esc_html__( 'Role Manager', 'js_composer' );
}
}
$tabs = $new;
} else {
$tabs['vc-roles'] = esc_html__( 'Roles Manager', 'js_composer' );
}
return $tabs;
}
if ( ! is_network_admin() ) {
add_filter( 'vc_settings_tabs', 'vc_settings_tabs_vc_roles' );
}
/**
* @return string
*/
function vc_settings_render_tab_vc_roles() {
return 'pages/vc-settings/tab-vc-roles.php';
}
add_filter( 'vc_settings-render-tab-vc-roles', 'vc_settings_render_tab_vc_roles' );
function vc_roles_settings_save() {
if ( check_admin_referer( 'vc_settings-roles-action', 'vc_nonce_field' ) && current_user_can( 'manage_options' ) ) {
require_once vc_path_dir( 'SETTINGS_DIR', 'class-vc-roles.php' );
$vc_roles = new Vc_Roles();
$data = $vc_roles->save( vc_request_param( 'vc_roles', array() ) );
echo wp_json_encode( $data );
die();
}
}
add_action( 'wp_ajax_vc_roles_settings_save', 'vc_roles_settings_save' );
if ( 'vc-roles' === vc_get_param( 'page' ) ) {
function vc_settings_render_tab_vc_roles_scripts() {
wp_register_script( 'vc_accordion_script', vc_asset_url( 'lib/vc_accordion/vc-accordion.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
}
add_action( 'admin_init', 'vc_settings_render_tab_vc_roles_scripts' );
}

View File

@@ -0,0 +1,68 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @since 4.5
*/
function vc_page_css_enqueue() {
wp_enqueue_style( 'vc_page-css', vc_asset_url( 'css/js_composer_settings.min.css' ), array(), WPB_VC_VERSION );
}
/**
* Build group page objects.
*
* @param $slug
* @param $title
* @param $tab
*
* @return Vc_Pages_Group
* @since 4.5
*
*/
function vc_pages_group_build( $slug, $title, $tab = '' ) {
$vc_page_welcome_tabs = vc_get_page_welcome_tabs();
require_once vc_path_dir( 'CORE_DIR', 'class-vc-page.php' );
require_once vc_path_dir( 'CORE_DIR', 'class-vc-pages-group.php' );
// Create page.
if ( ! strlen( $tab ) ) {
$tab = $slug;
}
$page = new Vc_Page();
$page->setSlug( $tab )->setTitle( $title )->setTemplatePath( 'pages/' . $slug . '/' . $tab . '.php' );
// Create page group to stick with other in template.
$pages_group = new Vc_Pages_Group();
$pages_group->setSlug( $slug )->setPages( $vc_page_welcome_tabs )->setActivePage( $page )->setTemplatePath( 'pages/vc-welcome/index.php' );
return $pages_group;
}
/**
* @since 4.5
*/
function vc_menu_page_build() {
if ( vc_user_access()->wpAny( 'manage_options' )->part( 'settings' )->can( 'vc-general-tab' )->get() ) {
define( 'VC_PAGE_MAIN_SLUG', 'vc-general' );
} else {
define( 'VC_PAGE_MAIN_SLUG', 'vc-welcome' );
}
add_menu_page( esc_html__( 'WPBakery Page Builder', 'js_composer' ), esc_html__( 'WPBakery Page Builder', 'js_composer' ), 'edit_posts', VC_PAGE_MAIN_SLUG, null, vc_asset_url( 'vc/logo/wpb-logo-white_32.svg' ), 76 );
do_action( 'vc_menu_page_build' );
}
function vc_network_menu_page_build() {
if ( ! vc_is_network_plugin() ) {
return;
}
if ( vc_user_access()->wpAny( 'manage_options' )->part( 'settings' )->can( 'vc-general-tab' )->get() && ! is_main_site() ) {
define( 'VC_PAGE_MAIN_SLUG', 'vc-general' );
} else {
define( 'VC_PAGE_MAIN_SLUG', 'vc-welcome' );
}
add_menu_page( esc_html__( 'WPBakery Page Builder', 'js_composer' ), esc_html__( 'WPBakery Page Builder', 'js_composer' ), 'exist', VC_PAGE_MAIN_SLUG, null, vc_asset_url( 'vc/logo/wpb-logo-white_32.svg' ), 76 );
do_action( 'vc_network_menu_page_build' );
}
add_action( 'admin_menu', 'vc_menu_page_build' );
add_action( 'network_admin_menu', 'vc_network_menu_page_build' );

View File

@@ -0,0 +1,43 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
function vc_page_settings_render() {
$page = vc_get_param( 'page' );
do_action( 'vc_page_settings_render-' . $page );
vc_settings()->renderTab( $page );
}
function vc_page_settings_build() {
if ( ! vc_user_access()->wpAny( 'manage_options' )->get() ) {
return;
}
$tabs = vc_settings()->getTabs();
foreach ( $tabs as $slug => $title ) {
$has_access = vc_user_access()->part( 'settings' )->can( $slug . '-tab' )->get();
if ( $has_access ) {
$page = add_submenu_page( VC_PAGE_MAIN_SLUG, $title, $title, 'manage_options', $slug, 'vc_page_settings_render' );
add_action( 'load-' . $page, array(
vc_settings(),
'adminLoad',
) );
}
}
do_action( 'vc_page_settings_build' );
}
function vc_page_settings_admin_init() {
vc_settings()->initAdmin();
}
add_action( 'vc_menu_page_build', 'vc_page_settings_build' );
add_action( 'vc_network_menu_page_build', 'vc_page_settings_build' );
add_action( 'admin_init', 'vc_page_settings_admin_init' );
add_action( 'vc-settings-render-tab-vc-roles', 'vc_settings_enqueue_js' );
function vc_settings_enqueue_js() {
// enqueue accordion in vc-roles page only
wp_enqueue_script( 'vc_accordion_script' );
}

View File

@@ -0,0 +1,103 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Get welcome pages main slug.
*
* @return mixed|string
* @since 4.5
*/
function vc_page_welcome_slug() {
$vc_page_welcome_tabs = vc_get_page_welcome_tabs();
return isset( $vc_page_welcome_tabs ) ? key( $vc_page_welcome_tabs ) : '';
}
/**
* Build vc-welcome page block which will be shown after Vc installation.
*
* vc_filter: vc_page_welcome_render_capabilities
*
* @since 4.5
*/
function vc_page_welcome_render() {
$vc_page_welcome_tabs = vc_get_page_welcome_tabs();
$slug = vc_page_welcome_slug();
$tab_slug = vc_get_param( 'tab', $slug );
// If tab slug in the list please render;
if ( ! empty( $tab_slug ) && isset( $vc_page_welcome_tabs[ $tab_slug ] ) ) {
$pages_group = vc_pages_group_build( $slug, $vc_page_welcome_tabs[ $tab_slug ], $tab_slug );
$pages_group->render();
}
}
function vc_page_welcome_add_sub_page() {
// Add submenu page
$page = add_submenu_page( VC_PAGE_MAIN_SLUG, esc_html__( 'About', 'js_composer' ), esc_html__( 'About', 'js_composer' ), 'edit_posts', vc_page_welcome_slug(), 'vc_page_welcome_render' );
// Css for perfect styling.
add_action( 'admin_print_styles-' . $page, 'vc_page_css_enqueue' );
}
function vc_welcome_menu_hooks() {
$settings_tab_enabled = vc_user_access()->wpAny( 'manage_options' )->part( 'settings' )->can( 'vc-general-tab' )->get();
add_action( 'vc_menu_page_build', 'vc_page_welcome_add_sub_page', $settings_tab_enabled ? 11 : 1 );
}
function vc_welcome_menu_hooks_network() {
if ( ! vc_is_network_plugin() ) {
return;
}
$settings_tab_enabled = vc_user_access()->wpAny( 'manage_options' )->part( 'settings' )->can( 'vc-general-tab' )->get();
add_action( 'vc_network_menu_page_build', 'vc_page_welcome_add_sub_page', $settings_tab_enabled && ! is_main_site() ? 11 : 1 );
}
add_action( 'admin_menu', 'vc_welcome_menu_hooks', 9 );
add_action( 'network_admin_menu', 'vc_welcome_menu_hooks_network', 9 );
/**
* ====================
* Redirect to welcome page on plugin activation.
* ====================
*/
/**
* Set redirect transition on update or activation
* @since 4.5
*/
function vc_page_welcome_set_redirect() {
if ( ! is_network_admin() && ! vc_get_param( 'activate-multi' ) ) {
set_transient( '_vc_page_welcome_redirect', 1, 30 );
}
}
/**
* Do redirect if required on welcome page
* @since 4.5
*/
function vc_page_welcome_redirect() {
$redirect = get_transient( '_vc_page_welcome_redirect' );
delete_transient( '_vc_page_welcome_redirect' );
if ( $redirect ) {
wp_safe_redirect( admin_url( 'admin.php?page=' . rawurlencode( vc_page_welcome_slug() ) ) );
}
}
// Enables redirect on activation.
add_action( 'vc_activation_hook', 'vc_page_welcome_set_redirect' );
add_action( 'admin_init', 'vc_page_welcome_redirect' );
/**
* @return mixed|void
*/
function vc_get_page_welcome_tabs() {
global $vc_page_welcome_tabs;
$vc_page_welcome_tabs = apply_filters( 'vc_page-welcome-slugs-list', array(
'vc-welcome' => esc_html__( 'What\'s New', 'js_composer' ),
'vc-faq' => esc_html__( 'FAQ', 'js_composer' ),
'vc-resources' => esc_html__( 'Resources', 'js_composer' ),
) );
return $vc_page_welcome_tabs;
}

View File

@@ -0,0 +1,91 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Add WP ui pointers to backend editor.
*/
function vc_add_admin_pointer() {
if ( is_admin() ) {
foreach ( vc_editor_post_types() as $post_type ) {
add_filter( 'vc_ui-pointers-' . $post_type, 'vc_backend_editor_register_pointer' );
}
}
}
add_action( 'admin_init', 'vc_add_admin_pointer' );
/**
* @param $pointers
* @return mixed
*/
function vc_backend_editor_register_pointer( $pointers ) {
$screen = get_current_screen();
$block = false;
if ( method_exists( $screen, 'is_block_editor' ) ) {
if ( $screen->is_block_editor() ) {
$block = true;
}
}
if ( ! $block || 'add' === $screen->action ) {
$pointers['vc_pointers_backend_editor'] = array(
'name' => 'vcPointerController',
'messages' => array(
array(
'target' => '.composer-switch',
'options' => array(
'content' => sprintf( '<h3> %s </h3> <p> %s </p>', esc_html__( 'Welcome to WPBakery Page Builder', 'js_composer' ), esc_html__( 'Choose Backend or Frontend editor.', 'js_composer' ) ),
'position' => array(
'edge' => 'left',
'align' => 'center',
),
'buttonsEvent' => 'vcPointersEditorsTourEvents',
),
),
array(
'target' => '#vc_templates-editor-button, #vc-templatera-editor-button',
'options' => array(
'content' => sprintf( '<h3> %s </h3> <p> %s </p>', esc_html__( 'Add Elements', 'js_composer' ), esc_html__( 'Add new element or start with a template.', 'js_composer' ) ),
'position' => array(
'edge' => 'left',
'align' => 'center',
),
'buttonsEvent' => 'vcPointersEditorsTourEvents',
),
'closeEvent' => 'shortcodes:vc_row:add',
'showEvent' => 'backendEditor.show',
),
array(
'target' => '[data-vc-control="add"]:first',
'options' => array(
'content' => sprintf( '<h3> %s </h3> <p> %s </p>', esc_html__( 'Rows and Columns', 'js_composer' ), esc_html__( 'This is a row container. Divide it into columns and style it. You can add elements into columns.', 'js_composer' ) ),
'position' => array(
'edge' => 'left',
'align' => 'center',
),
'buttonsEvent' => 'vcPointersEditorsTourEvents',
),
'closeEvent' => 'click #wpb_visual_composer',
'showEvent' => 'shortcodeView:ready',
),
array(
'target' => '.wpb_column_container:first .wpb_content_element:first .vc_controls-cc',
'options' => array(
'content' => sprintf( '<h3> %s </h3> <p> %s <br/><br/> %s</p>', esc_html__( 'Control Elements', 'js_composer' ), esc_html__( 'You can edit your element at any time and drag it around your layout.', 'js_composer' ), sprintf( esc_html__( 'P.S. Learn more at our %sKnowledge Base%s.', 'js_composer' ), '<a href="https://kb.wpbakery.com" target="_blank">', '</a>' ) ),
'position' => array(
'edge' => 'left',
'align' => 'center',
),
'buttonsEvent' => 'vcPointersEditorsTourEvents',
),
'showCallback' => 'vcPointersShowOnContentElementControls',
'closeEvent' => 'click #wpb_visual_composer',
),
),
);
}
return $pointers;
}

View File

@@ -0,0 +1,77 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Add WP ui pointers to backend editor.
*/
function vc_frontend_editor_pointer() {
vc_is_frontend_editor() && add_filter( 'vc-ui-pointers', 'vc_frontend_editor_register_pointer' );
}
add_action( 'admin_init', 'vc_frontend_editor_pointer' );
/**
* @param $pointers
* @return mixed
*/
function vc_frontend_editor_register_pointer( $pointers ) {
global $post;
if ( is_object( $post ) && ! strlen( $post->post_content ) ) {
$pointers['vc_pointers_frontend_editor'] = array(
'name' => 'vcPointerController',
'messages' => array(
array(
'target' => '#vc_add-new-element',
'options' => array(
'content' => sprintf( '<h3> %s </h3> <p> %s </p>', esc_html__( 'Add Elements', 'js_composer' ), esc_html__( 'Add new element or start with a template.', 'js_composer' ) ),
'position' => array(
'edge' => 'top',
'align' => 'left',
),
'buttonsEvent' => 'vcPointersEditorsTourEvents',
),
'closeEvent' => 'shortcodes:add',
),
array(
'target' => '.vc_controls-out-tl:first',
'options' => array(
'content' => sprintf( '<h3> %s </h3> <p> %s </p>', esc_html__( 'Rows and Columns', 'js_composer' ), esc_html__( 'This is a row container. Divide it into columns and style it. You can add elements into columns.', 'js_composer' ) ),
'position' => array(
'edge' => 'left',
'align' => 'center',
),
'buttonsEvent' => 'vcPointersEditorsTourEvents',
),
'closeCallback' => 'vcPointersCloseInIFrame',
'showCallback' => 'vcPointersSetInIFrame',
),
array(
'target' => '.vc_controls-cc:first',
'options' => array(
'content' => sprintf( '<h3> %s </h3> <p> %s <br/><br/> %s</p>', esc_html__( 'Control Elements', 'js_composer' ), esc_html__( 'You can edit your element at any time and drag it around your layout.', 'js_composer' ), sprintf( esc_html__( 'P.S. Learn more at our %sKnowledge Base%s.', 'js_composer' ), '<a href="https://kb.wpbakery.com" target="_blank">', '</a>' ) ),
'position' => array(
'edge' => 'left',
'align' => 'center',
),
'buttonsEvent' => 'vcPointersEditorsTourEvents',
),
'closeCallback' => 'vcPointersCloseInIFrame',
'showCallback' => 'vcPointersSetInIFrame',
),
),
);
}
return $pointers;
}
function vc_page_editable_enqueue_pointer_scripts() {
if ( vc_is_page_editable() ) {
wp_enqueue_style( 'wp-pointer' );
wp_enqueue_script( 'wp-pointer' );
}
}
add_action( 'wp_enqueue_scripts', 'vc_page_editable_enqueue_pointer_scripts' );

View File

@@ -0,0 +1,261 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
add_action( 'wp_ajax_vc_action_save_settings_preset', 'vc_action_save_settings_preset' );
add_action( 'wp_ajax_vc_action_set_as_default_settings_preset', 'vc_action_set_as_default_settings_preset' );
add_action( 'wp_ajax_vc_action_delete_settings_preset', 'vc_action_delete_settings_preset' );
add_action( 'wp_ajax_vc_action_restore_default_settings_preset', 'vc_action_restore_default_settings_preset' );
add_action( 'wp_ajax_vc_action_get_settings_preset', 'vc_action_get_settings_preset' );
add_action( 'wp_ajax_vc_action_render_settings_preset_popup', 'vc_action_render_settings_preset_popup' );
add_action( 'wp_ajax_vc_action_render_settings_preset_title_prompt', 'vc_action_render_settings_preset_title_prompt' );
add_action( 'wp_ajax_vc_action_render_settings_templates_prompt', 'vc_action_render_settings_templates_prompt' );
add_action( 'vc_restore_default_settings_preset', 'vc_action_set_as_default_settings_preset', 10, 2 );
add_action( 'vc_register_settings_preset', 'vc_register_settings_preset', 10, 4 );
add_filter( 'vc_add_new_elements_to_box', 'vc_add_new_elements_to_box' );
add_filter( 'vc_add_new_category_filter', 'vc_add_new_category_filter' );
function vc_include_settings_preset_class() {
require_once vc_path_dir( 'AUTOLOAD_DIR', 'class-vc-settings-presets.php' );
}
/**
* @return Vc_Vendor_Preset
*/
function vc_vendor_preset() {
require_once vc_path_dir( 'AUTOLOAD_DIR', 'class-vc-vendor-presets.php' );
return Vc_Vendor_Preset::getInstance();
}
/**
* Save settings preset for specific shortcode
*
* Include freshly rendered html in response
*
* Required _POST params:
* - shortcode_name string
* - title string
* - data string params in json
* - is_default
*
* @since 4.7
*/
function vc_action_save_settings_preset() {
vc_include_settings_preset_class();
vc_user_access()->part( 'presets' )->checkStateAny( true, null )->validateDie(); // user must have permission to save presets
$id = Vc_Settings_Preset::saveSettingsPreset( vc_post_param( 'shortcode_name' ), vc_post_param( 'title' ), vc_post_param( 'data' ), vc_post_param( 'is_default' ) );
$response = array(
'success' => (bool) $id,
'html' => Vc_Settings_Preset::getRenderedSettingsPresetPopup( vc_post_param( 'shortcode_name' ) ),
'id' => $id,
);
wp_send_json( $response );
}
/**
* Set existing preset as default
*
* Include freshly rendered html in response
*
* Required _POST params:
* - id int
* - shortcode_name string
*
* @since 4.7
*/
function vc_action_set_as_default_settings_preset() {
vc_include_settings_preset_class();
vc_user_access()->part( 'presets' )->checkStateAny( true, null )->validateDie(); // user must have permission to set as default presets
$id = vc_post_param( 'id' );
$shortcode_name = vc_post_param( 'shortcode_name' );
$status = Vc_Settings_Preset::setAsDefaultSettingsPreset( $id, $shortcode_name );
$response = array(
'success' => $status,
'html' => Vc_Settings_Preset::getRenderedSettingsPresetPopup( $shortcode_name ),
);
wp_send_json( $response );
}
/**
* Unmark current default preset as default
*
* Include freshly rendered html in response
*
* Required _POST params:
* - shortcode_name string
*
* @since 4.7
*/
function vc_action_restore_default_settings_preset() {
vc_include_settings_preset_class();
vc_user_access()->part( 'presets' )->checkStateAny( true, null )->validateDie(); // user must have permission to restore presets
$shortcode_name = vc_post_param( 'shortcode_name' );
$status = Vc_Settings_Preset::setAsDefaultSettingsPreset( null, $shortcode_name );
$response = array(
'success' => $status,
'html' => Vc_Settings_Preset::getRenderedSettingsPresetPopup( $shortcode_name ),
);
wp_send_json( $response );
}
/**
* Delete specific settings preset
*
* Include freshly rendered html in response
*
* Required _POST params:
* - shortcode_name string
* - id int
*
* @since 4.7
*/
function vc_action_delete_settings_preset() {
vc_include_settings_preset_class();
vc_user_access()->part( 'presets' )->checkStateAny( true, null )->validateDie(); // user must have permission to delete presets
$default = get_post_meta( vc_post_param( 'id' ), '_vc_default', true );
$status = Vc_Settings_Preset::deleteSettingsPreset( vc_post_param( 'id' ) );
$response = array(
'success' => $status,
'default' => $default,
'html' => Vc_Settings_Preset::getRenderedSettingsPresetPopup( vc_post_param( 'shortcode_name' ) ),
);
wp_send_json( $response );
}
/**
* Get data for specific settings preset
*
* Required _POST params:
* - id int
*
* @since 4.7
*/
function vc_action_get_settings_preset() {
vc_include_settings_preset_class();
$data = Vc_Settings_Preset::getSettingsPreset( vc_post_param( 'id' ), true );
if ( false !== $data ) {
$response = array(
'success' => true,
'data' => $data,
);
} else {
$response = array(
'success' => false,
);
}
wp_send_json( $response );
}
/**
* Respond with rendered popup menu
*
* Required _POST params:
* - shortcode_name string
*
* @since 4.7
*/
function vc_action_render_settings_preset_popup() {
vc_include_settings_preset_class();
$html = Vc_Settings_Preset::getRenderedSettingsPresetPopup( vc_post_param( 'shortcode_name' ) );
$response = array(
'success' => true,
'html' => $html,
);
wp_send_json( $response );
}
/**
* Return rendered title prompt
*
* @since 4.7
*
*/
function vc_action_render_settings_preset_title_prompt() {
vc_user_access()->checkAdminNonce()->validateDie()->wpAny( 'edit_posts', 'edit_pages' )->validateDie()->part( 'presets' )->can()->validateDie();
ob_start();
vc_include_template( apply_filters( 'vc_render_settings_preset_title_prompt', 'editors/partials/prompt-presets.tpl.php' ) );
$html = ob_get_clean();
$response = array(
'success' => true,
'html' => $html,
);
wp_send_json( $response );
}
/**
* Return rendered template prompt
*/
function vc_action_render_settings_templates_prompt() {
vc_user_access()->checkAdminNonce()->validateDie()->wpAny( 'edit_posts', 'edit_pages' )->validateDie()->part( 'templates' )->can()->validateDie();
ob_start();
vc_include_template( apply_filters( 'vc_render_settings_preset_title_prompt', 'editors/partials/prompt-templates.tpl.php' ) );
$html = ob_get_clean();
$response = array(
'success' => true,
'html' => $html,
);
wp_send_json( $response );
}
/**
* Register (add) new vendor preset
*
* @since 4.8
*
* @param string $title
* @param string $shortcode
* @param array $params
* @param bool $default
*/
function vc_register_settings_preset( $title, $shortcode, $params, $default = false ) {
vc_vendor_preset()->add( $title, $shortcode, $params, $default );
}
/**
* @param $shortcodes
* @return array
* @throws \Exception
*/
function vc_add_new_elements_to_box( $shortcodes ) {
require_once vc_path_dir( 'AUTOLOAD_DIR', 'class-vc-settings-presets.php' );
return Vc_Settings_Preset::addVcPresetsToShortcodes( $shortcodes );
}
/**
* @param $cat
* @return array
*/
function vc_add_new_category_filter( $cat ) {
require_once vc_path_dir( 'AUTOLOAD_DIR', 'class-vc-settings-presets.php' );
return Vc_Settings_Preset::addPresetCategory( $cat );
}

View File

@@ -0,0 +1,280 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Class VcShortcodeAutoloader
*/
class VcShortcodeAutoloader {
private static $instance = null;
private static $config = null;
private static $cached = null;
/**
* @param bool $load_config
* @return \VcShortcodeAutoloader|null
*/
public static function getInstance( $load_config = true ) {
if ( null === self::$instance ) {
self::$instance = new VcShortcodeAutoloader( $load_config );
}
return self::$instance;
}
/**
* VcShortcodeAutoloader constructor.
* @param bool $load_config
*/
private function __construct( $load_config = true ) {
if ( ! $load_config ) {
return;
}
$config = array(
'classmap_file' => vc_path_dir( 'APP_ROOT', 'vc_classmap.json.php' ),
'shortcodes_dir' => vc_path_dir( 'SHORTCODES_DIR' ),
'root_dir' => vc_path_dir( 'APP_ROOT' ),
);
if ( is_file( $config['classmap_file'] ) ) {
$config['classmap'] = require $config['classmap_file'];
self::$cached = true;
} else {
$config['classmap'] = self::generateClassMap( $config['shortcodes_dir'] );
self::$cached = false;
}
self::$config = $config;
}
/**
* Include class dependencies
*
* @param string $class Class name
*
* @return string[] Included (if any) files
*/
public static function includeClass( $class ) {
// call the constructor (php 7.4 compat)
self::getInstance();
$class = strtolower( $class );
$files = array();
if ( self::$config['classmap'] ) {
$files = isset( self::$config['classmap'][ $class ] ) ? self::$config['classmap'][ $class ] : array();
}
if ( $files ) {
foreach ( $files as $k => $file ) {
if ( self::$cached ) {
$files[ $k ] = $file = self::$config['root_dir'] . DIRECTORY_SEPARATOR . $file;
}
if ( is_file( $file ) ) {
require_once $file;
}
}
}
return $files;
}
/**
* Find all classes defined in file
*
* @param string $file Full path to file
*
* @return string[]
*/
public static function extractClassNames( $file ) {
$classes = array();
// @codingStandardsIgnoreLine
$contents = file_get_contents( $file );
if ( ! $contents ) {
return $classes;
}
$tokens = token_get_all( $contents );
$class_token = false;
foreach ( $tokens as $token ) {
if ( is_array( $token ) ) {
if ( T_CLASS === $token[0] ) {
$class_token = true;
} elseif ( $class_token && T_STRING === $token[0] ) {
$classes[] = $token[1];
$class_token = false;
}
}
}
return $classes;
}
/**
* Extract all classes from file with their extends
*
* @param $file
*
* @return array Associative array where key is class name and value is parent class name (if any))
*/
public static function extractClassesAndExtends( $file ) {
$classes = array();
// @codingStandardsIgnoreLine
$contents = file_get_contents( $file );
if ( ! $contents ) {
return $classes;
}
// class Foo extends Bar {
preg_match_all( '/class\s+(\w+)\s+extends\s(\w+)\s+\{/i', $contents, $matches, PREG_SET_ORDER );
foreach ( $matches as $v ) {
$classes[ $v[1] ] = $v[2];
}
// class Foo {
preg_match_all( '/class\s+(\w+)\s+\{/i', $contents, $matches, PREG_SET_ORDER );
foreach ( $matches as $v ) {
$classes[ $v[1] ] = null;
}
return $classes;
}
/**
* Find file by class name
*
* Search is case-insensitive
*
* @param string $class
* @param string[]|string $dirs One or more directories where to look (recursive)
*
* @return string|false Full path to class file
*/
public static function findClassFile( $class, $dirs ) {
foreach ( (array) $dirs as $dir ) {
$Directory = new RecursiveDirectoryIterator( $dir );
$Iterator = new RecursiveIteratorIterator( $Directory );
$Regex = new RegexIterator( $Iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH );
$class = strtolower( $class );
foreach ( $Regex as $file => $object ) {
$classes = self::extractClassNames( $file );
if ( $classes && in_array( $class, array_map( 'strtolower', $classes ), true ) ) {
return $file;
}
}
}
return false;
}
/**
* Construct full dependency list of classes for each class in right order (including class itself)
*
* @param string[]|string $dirs Directories where to look (recursive)
*
* @return array Associative array where key is lowercase class name and value is array of files to include for
* that class to work
*/
public static function generateClassMap( $dirs ) {
$flat_map = array();
foreach ( (array) $dirs as $dir ) {
$Directory = new RecursiveDirectoryIterator( $dir );
$Iterator = new RecursiveIteratorIterator( $Directory );
$Regex = new RegexIterator( $Iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH );
foreach ( $Regex as $file => $object ) {
$classes = self::extractClassesAndExtends( $file );
foreach ( $classes as $class => $extends ) {
$class = strtolower( $class );
$extends = strtolower( $extends );
if ( in_array( $extends, array(
'wpbakeryshortcodescontainer',
'wpbakeryvisualcomposer',
'wpbakeryshortcode',
'wpbmap',
), true ) ) {
$extends = null;
}
$flat_map[ $class ] = array(
'class' => $class,
'file' => $file,
'extends' => $extends,
);
}
}
}
$map = array();
foreach ( $flat_map as $params ) {
$dependencies = array(
array(
'class' => $params['class'],
'file' => $params['file'],
),
);
if ( $params['extends'] ) {
$queue = array( $params['extends'] );
while ( $queue ) {
$current_class = array_pop( $queue );
$current_class = $flat_map[ $current_class ];
$dependencies[] = array(
'class' => $current_class['class'],
'file' => $current_class['file'],
);
if ( ! empty( $current_class['extends'] ) ) {
$queue[] = $current_class['extends'];
}
}
$map[ $params['class'] ] = array_reverse( $dependencies );
} else {
$map[ $params['class'] ] = $dependencies;
}
}
// simplify array
$classmap = array();
foreach ( $map as $class => $dependencies ) {
$classmap[ $class ] = array();
foreach ( $dependencies as $v ) {
$classmap[ $class ][] = str_replace( '\\', '/', $v['file'] );
}
}
return $classmap;
}
/**
* Regenerate and save class map file
*
* @param string[]|string $dirs Directories where to look (recursive)
* @param string $target Output file
*
* @return bool
*/
public static function saveClassMap( $dirs, $target ) {
if ( ! $target ) {
return false;
}
$classmap = self::generateClassMap( $dirs );
// @codingStandardsIgnoreLine
$code = '<?php return (array) json_decode(\'' . json_encode( $classmap ) . '\') ?>';
// @codingStandardsIgnoreLine
return (bool) file_put_contents( $target, $code );
}
}

View File

@@ -0,0 +1,83 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
if ( 'vc_edit_form' === vc_post_param( 'action' ) ) {
add_filter( 'vc_edit_form_fields_attributes_vc_single_image', 'vc_single_image_convert_old_link_to_new' );
}
/**
* Backward compatibility
*
* @param $atts
* @return mixed
* @since 4.6
*/
function vc_single_image_convert_old_link_to_new( $atts ) {
if ( empty( $atts['onclick'] ) && isset( $atts['img_link_large'] ) && 'yes' === $atts['img_link_large'] ) {
$atts['onclick'] = 'img_link_large';
unset( $atts['img_link_large'] );
} elseif ( empty( $atts['onclick'] ) && ( ! isset( $atts['img_link_large'] ) || 'yes' !== $atts['img_link_large'] ) ) {
unset( $atts['img_link_large'] );
}
if ( empty( $atts['onclick'] ) && ! empty( $atts['link'] ) ) {
$atts['onclick'] = 'custom_link';
}
return $atts;
}
add_action( 'wp_ajax_wpb_single_image_src', 'vc_single_image_src' );
function vc_single_image_src() {
vc_user_access()->checkAdminNonce()->validateDie()->wpAny( 'edit_posts', 'edit_pages' )->validateDie();
$image_id = (int) vc_post_param( 'content' );
$params = vc_post_param( 'params' );
$post_id = (int) vc_post_param( 'post_id' );
$img_size = vc_post_param( 'size' );
$img = '';
if ( ! empty( $params['source'] ) ) {
$source = $params['source'];
} else {
$source = 'media_library';
}
switch ( $source ) {
case 'media_library':
case 'featured_image':
if ( 'featured_image' === $source ) {
if ( $post_id && has_post_thumbnail( $post_id ) ) {
$img_id = get_post_thumbnail_id( $post_id );
} else {
$img_id = 0;
}
} else {
$img_id = preg_replace( '/[^\d]/', '', $image_id );
}
if ( ! $img_size ) {
$img_size = 'thumbnail';
}
if ( $img_id ) {
$img = wp_get_attachment_image_src( $img_id, $img_size );
if ( $img ) {
$img = $img[0];
}
}
break;
case 'external_link':
if ( ! empty( $params['custom_src'] ) ) {
$img = $params['custom_src'];
}
break;
}
echo esc_url( $img );
die();
}

View File

@@ -0,0 +1,13 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
function vc_navbar_undoredo() {
if ( vc_is_frontend_editor() || is_admin() ) {
require_once vc_path_dir( 'EDITORS_DIR', 'navbar/class-vc-navbar-undoredo.php' );
new Vc_Navbar_Undoredo();
}
}
add_action( 'admin_init', 'vc_navbar_undoredo' );

View File

@@ -0,0 +1,28 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @since 4.4 vendors initialization moved to hooks in autoload/vendors.
*
* Used to initialize advanced custom fields vendor.
*/
add_action( 'acf/init', 'vc_init_vendor_acf' ); // pro version
add_action( 'acf/register_fields', 'vc_init_vendor_acf' ); // free version
add_action( 'plugins_loaded', 'vc_init_vendor_acf' );
add_action( 'after_setup_theme', 'vc_init_vendor_acf' ); // for themes
function vc_init_vendor_acf() {
if ( did_action( 'vc-vendor-acf-load' ) ) {
return;
}
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Require class-vc-wxr-parser-plugin.php to use is_plugin_active() below
if ( class_exists( 'acf' ) || is_plugin_active( 'advanced-custom-fields/acf.php' ) || is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) ) {
require_once vc_path_dir( 'VENDORS_DIR', 'plugins/class-vc-vendor-advanced-custom-fields.php' );
$vendor = new Vc_Vendor_AdvancedCustomFields();
add_action( 'vc_after_set_mode', array(
$vendor,
'load',
) );
}
}

View File

@@ -0,0 +1,22 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @since 4.4 vendors initialization moved to hooks in autoload/vendors.
*
* Used to initialize plugin contact form 7 vendor - fix load cf7 shortcode when in editor (frontend)
*/
add_action( 'plugins_loaded', 'vc_init_vendor_cf7' );
function vc_init_vendor_cf7() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Require class-vc-wxr-parser-plugin.php to use is_plugin_active() below
if ( is_plugin_active( 'contact-form-7/wp-contact-form-7.php' ) || defined( 'WPCF7_PLUGIN' ) ) {
require_once vc_path_dir( 'VENDORS_DIR', 'plugins/class-vc-vendor-contact-form7.php' );
$vendor = new Vc_Vendor_ContactForm7();
add_action( 'vc_after_set_mode', array(
$vendor,
'load',
) );
} // if contact form7 plugin active
}

View File

@@ -0,0 +1,106 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @since 4.4 vendors initialization moved to hooks in autoload/vendors.
*
* Used to add gravity forms shortcode into WPBakery Page Builder
*/
add_action( 'plugins_loaded', 'vc_init_vendor_gravity_forms' );
function vc_init_vendor_gravity_forms() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Require class-vc-wxr-parser-plugin.php to use is_plugin_active() below
if ( is_plugin_active( 'gravityforms/gravityforms.php' ) || class_exists( 'RGForms' ) || class_exists( 'RGFormsModel' ) ) {
// Call on map
add_action( 'vc_after_init', 'vc_vendor_gravityforms_load' );
} // if gravityforms active
}
function vc_vendor_gravityforms_load() {
$gravity_forms_array[ esc_html__( 'No Gravity forms found.', 'js_composer' ) ] = '';
if ( class_exists( 'RGFormsModel' ) ) {
/** @noinspection PhpUndefinedClassInspection */
$gravity_forms = RGFormsModel::get_forms( 1, 'title' );
if ( $gravity_forms ) {
$gravity_forms_array = array( esc_html__( 'Select a form to display.', 'js_composer' ) => '' );
foreach ( $gravity_forms as $gravity_form ) {
$gravity_forms_array[ $gravity_form->title ] = $gravity_form->id;
}
}
}
vc_map( array(
'name' => esc_html__( 'Gravity Form', 'js_composer' ),
'base' => 'gravityform',
'icon' => 'icon-wpb-vc_gravityform',
'category' => esc_html__( 'Content', 'js_composer' ),
'description' => esc_html__( 'Place Gravity form', 'js_composer' ),
'params' => array(
array(
'type' => 'dropdown',
'heading' => esc_html__( 'Form', 'js_composer' ),
'param_name' => 'id',
'value' => $gravity_forms_array,
'save_always' => true,
'description' => esc_html__( 'Select a form to add it to your post or page.', 'js_composer' ),
'admin_label' => true,
),
array(
'type' => 'dropdown',
'heading' => esc_html__( 'Display Form Title', 'js_composer' ),
'param_name' => 'title',
'value' => array(
esc_html__( 'No', 'js_composer' ) => 'false',
esc_html__( 'Yes', 'js_composer' ) => 'true',
),
'save_always' => true,
'description' => esc_html__( 'Would you like to display the forms title?', 'js_composer' ),
'dependency' => array(
'element' => 'id',
'not_empty' => true,
),
),
array(
'type' => 'dropdown',
'heading' => esc_html__( 'Display Form Description', 'js_composer' ),
'param_name' => 'description',
'value' => array(
esc_html__( 'No', 'js_composer' ) => 'false',
esc_html__( 'Yes', 'js_composer' ) => 'true',
),
'save_always' => true,
'description' => esc_html__( 'Would you like to display the forms description?', 'js_composer' ),
'dependency' => array(
'element' => 'id',
'not_empty' => true,
),
),
array(
'type' => 'dropdown',
'heading' => esc_html__( 'Enable AJAX?', 'js_composer' ),
'param_name' => 'ajax',
'value' => array(
esc_html__( 'No', 'js_composer' ) => 'false',
esc_html__( 'Yes', 'js_composer' ) => 'true',
),
'save_always' => true,
'description' => esc_html__( 'Enable AJAX submission?', 'js_composer' ),
'dependency' => array(
'element' => 'id',
'not_empty' => true,
),
),
array(
'type' => 'textfield',
'heading' => esc_html__( 'Tab Index', 'js_composer' ),
'param_name' => 'tabindex',
'description' => esc_html__( '(Optional) Specify the starting tab index for the fields of this form. Leave blank if you\'re not sure what this is.',
'js_composer' ),
'dependency' => array(
'element' => 'id',
'not_empty' => true,
),
),
),
) );
}

View File

@@ -0,0 +1,89 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @param $post
* @return bool
*/
function vcv_disable_gutenberg_for_classic_editor( $post ) {
return false;
}
/**
* @param \Vc_Settings $settings
*/
function vc_gutenberg_add_settings( $settings ) {
global $wp_version;
if ( function_exists( 'the_gutenberg_project' ) || version_compare( $wp_version, '4.9.8', '>' ) ) {
$settings->addField( 'general', esc_html__( 'Disable Gutenberg Editor', 'js_composer' ), 'gutenberg_disable', 'vc_gutenberg_sanitize_disable_callback', 'vc_gutenberg_disable_render_callback' );
}
}
/**
* @param $rules
*
* @return mixed
*/
function vc_gutenberg_sanitize_disable_callback( $rules ) {
return (bool) $rules;
}
/**
* Not responsive checkbox callback function
*/
function vc_gutenberg_disable_render_callback() {
$checked = ( $checked = get_option( 'wpb_js_gutenberg_disable' ) ) ? $checked : false;
?>
<label>
<input type="checkbox"<?php echo esc_attr( $checked ) ? ' checked' : ''; ?> value="1"
name="<?php echo 'wpb_js_gutenberg_disable' ?>">
<?php esc_html_e( 'Disable', 'js_composer' ) ?>
</label><br/>
<p
class="description indicator-hint"><?php esc_html_e( 'Disable Gutenberg Editor.', 'js_composer' ); ?></p>
<?php
}
/**
* @param $result
* @param $postType
* @return bool
*/
function vc_gutenberg_check_disabled( $result, $postType ) {
if ( 'wpb_gutenberg_param' === $postType ) {
return true;
}
if ( ! isset( $_GET['vcv-gutenberg-editor'] ) && ( get_option( 'wpb_js_gutenberg_disable' ) || vc_is_wpb_content() || isset( $_GET['classic-editor'] ) ) ) {
return false;
}
return $result;
}
/**
* @return bool
*/
function vc_is_wpb_content() {
$post = get_post();
if ( ! empty( $post ) && isset( $post->post_content ) && preg_match( '/\[vc_row/', $post->post_content ) ) {
return true;
}
return false;
}
function vc_gutenberg_map() {
global $wp_version;
if ( function_exists( 'the_gutenberg_project' ) || version_compare( $wp_version, '4.9.8', '>' ) ) {
vc_lean_map( 'vc_gutenberg', null, dirname( __FILE__ ) . '/shortcode-vc-gutenberg.php' );
}
}
add_filter( 'use_block_editor_for_post_type', 'vc_gutenberg_check_disabled', 10, 2 );
add_action( 'vc_settings_tab-general', 'vc_gutenberg_add_settings' );
add_action( 'init', 'vc_gutenberg_map' );
/** @see include/params/gutenberg/class-vc-gutenberg-param.php */
require_once vc_path_dir( 'PARAMS_DIR', 'gutenberg/class-vc-gutenberg-param.php' );
new Vc_Gutenberg_Param();

View File

@@ -0,0 +1,18 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @since 4.4 vendors initialization moved to hooks in autoload/vendors.
*
* Used to initialize plugin jwplayer vendor for frontend editor.
*/
add_action( 'plugins_loaded', 'vc_init_vendor_jwplayer' );
function vc_init_vendor_jwplayer() {
if ( is_plugin_active( 'jw-player-plugin-for-wordpress/jwplayermodule.php' ) || defined( 'JWP6' ) || class_exists( 'JWP6_Plugin' ) ) {
require_once vc_path_dir( 'VENDORS_DIR', 'plugins/class-vc-vendor-jwplayer.php' );
$vendor = new Vc_Vendor_Jwplayer();
$vendor->load();
}
}

View File

@@ -0,0 +1,19 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @since 4.4 vendors initialization moved to hooks in autoload/vendors.
*
* Used to initialize plugin layerslider vendor.
*/
add_action( 'plugins_loaded', 'vc_init_vendor_layerslider' );
function vc_init_vendor_layerslider() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Require class-vc-wxr-parser-plugin.php to use is_plugin_active() below
if ( is_plugin_active( 'LayerSlider/layerslider.php' ) || class_exists( 'LS_Sliders' ) || defined( 'LS_ROOT_PATH' ) ) {
require_once vc_path_dir( 'VENDORS_DIR', 'plugins/class-vc-vendor-layerslider.php' );
$vendor = new Vc_Vendor_Layerslider();
$vendor->load();
}
}

View File

@@ -0,0 +1,22 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @since 4.4 vendors initialization moved to hooks in autoload/vendors.
*
* Used to initialize plugin mqtranslate vendor
*/
add_action( 'plugins_loaded', 'vc_init_vendor_mqtranslate' );
function vc_init_vendor_mqtranslate() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Require class-vc-wxr-parser-plugin.php to use is_plugin_active() below
if ( is_plugin_active( 'mqtranslate/mqtranslate.php' ) || function_exists( 'mqtranslate_activation_check' ) ) {
require_once vc_path_dir( 'VENDORS_DIR', 'plugins/class-vc-vendor-mqtranslate.php' );
$vendor = new Vc_Vendor_Mqtranslate();
add_action( 'vc_after_set_mode', array(
$vendor,
'load',
) );
}
}

View File

@@ -0,0 +1,22 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @since 4.4 vendors initialization moved to hooks in autoload/vendors.
*
* Used to initialize plugin ninja forms vendor
*/
add_action( 'plugins_loaded', 'vc_init_vendor_ninja_forms' );
function vc_init_vendor_ninja_forms() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Require class-vc-wxr-parser-plugin.php to use is_plugin_active() below
if ( is_plugin_active( 'ninja-forms/ninja-forms.php' ) || defined( 'NINJA_FORMS_DIR' ) || function_exists( 'ninja_forms_get_all_forms' ) ) {
require_once vc_path_dir( 'VENDORS_DIR', 'plugins/class-vc-vendor-ninja-forms.php' );
$vendor = new Vc_Vendor_NinjaForms();
add_action( 'vc_after_set_mode', array(
$vendor,
'load',
) );
}
}

View File

@@ -0,0 +1,21 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @since 4.4 vendors initialization moved to hooks in autoload/vendors.
*
* Used to initialize plugin qtranslate vendor.
*/
add_action( 'plugins_loaded', 'vc_init_vendor_qtranslatex' );
function vc_init_vendor_qtranslatex() {
if ( defined( 'QTX_VERSION' ) ) {
require_once vc_path_dir( 'VENDORS_DIR', 'plugins/class-vc-vendor-qtranslate-x.php' );
$vendor = new Vc_Vendor_QtranslateX();
add_action( 'vc_after_set_mode', array(
$vendor,
'load',
) );
}
}

View File

@@ -0,0 +1,22 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @since 4.4 vendors initialization moved to hooks in autoload/vendors.
*
* Used to initialize plugin qtranslate vendor.
*/
add_action( 'plugins_loaded', 'vc_init_vendor_qtranslate' );
function vc_init_vendor_qtranslate() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Require class-vc-wxr-parser-plugin.php to use is_plugin_active() below
if ( is_plugin_active( 'qtranslate/qtranslate.php' ) || defined( 'QT_SUPPORTED_WP_VERSION' ) ) {
require_once vc_path_dir( 'VENDORS_DIR', 'plugins/class-vc-vendor-qtranslate.php' );
$vendor = new Vc_Vendor_Qtranslate();
add_action( 'vc_after_set_mode', array(
$vendor,
'load',
) );
}
}

View File

@@ -0,0 +1,19 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @since 4.4 vendors initialization moved to hooks in autoload/vendors.
*
* Used to initialize plugin revslider vendor.
*/
add_action( 'plugins_loaded', 'vc_init_vendor_revslider' );
function vc_init_vendor_revslider() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Require class-vc-wxr-parser-plugin.php to use is_plugin_active() below
if ( is_plugin_active( 'revslider/revslider.php' ) || class_exists( 'RevSlider' ) ) {
require_once vc_path_dir( 'VENDORS_DIR', 'plugins/class-vc-vendor-revslider.php' );
$vendor = new Vc_Vendor_Revslider();
$vendor->load();
}
}

View File

@@ -0,0 +1,41 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
return array(
'name' => esc_html__( 'Gutenberg Editor', 'js_composer' ),
'icon' => 'vc_icon-vc-gutenberg',
'wrapper_class' => 'clearfix',
'category' => esc_html__( 'Content', 'js_composer' ),
'description' => esc_html__( 'Insert Gutenberg editor in your layout', 'js_composer' ),
'weight' => - 10,
'params' => array(
array(
'type' => 'gutenberg',
'holder' => 'div',
'heading' => esc_html__( 'Text', 'js_composer' ),
'param_name' => 'content',
'value' => '<!-- wp:paragraph --><p>Hello! This is the Gutenberg block you can edit directly from the WPBakery Page Builder.</p><!-- /wp:paragraph -->',
),
vc_map_add_css_animation(),
array(
'type' => 'el_id',
'heading' => esc_html__( 'Element ID', 'js_composer' ),
'param_name' => 'el_id',
'description' => sprintf( esc_html__( 'Enter element ID (Note: make sure it is unique and valid according to %sw3c specification%s).', 'js_composer' ), '<a href="https://www.w3schools.com/tags/att_global_id.asp" target="_blank">', '</a>' ),
),
array(
'type' => 'textfield',
'heading' => esc_html__( 'Extra class name', 'js_composer' ),
'param_name' => 'el_class',
'description' => esc_html__( 'Style particular content element differently - add a class name and refer to it in custom CSS.', 'js_composer' ),
),
array(
'type' => 'css_editor',
'heading' => esc_html__( 'CSS box', 'js_composer' ),
'param_name' => 'css',
'group' => esc_html__( 'Design Options', 'js_composer' ),
),
),
);

View File

@@ -0,0 +1,41 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Add script for grid item add to card link
*
* @since 4.5
*/
function vc_woocommerce_add_to_cart_script() {
wp_enqueue_script( 'vc_woocommerce-add-to-cart-js', vc_asset_url( 'js/vendors/woocommerce-add-to-cart.js' ), array( 'wc-add-to-cart' ), WPB_VC_VERSION );
}
/**
* @since 4.4 vendors initialization moved to hooks in autoload/vendors.
*
* Used to initialize plugin WooCommerce vendor. (adds tons of WooCommerce shortcodes and some fixes)
*/
add_action( 'plugins_loaded', 'vc_init_vendor_woocommerce' );
function vc_init_vendor_woocommerce() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Require class-vc-wxr-parser-plugin.php to use is_plugin_active() below
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) || class_exists( 'WooCommerce' ) ) {
require_once vc_path_dir( 'VENDORS_DIR', 'plugins/class-vc-vendor-woocommerce.php' );
$vendor = new Vc_Vendor_Woocommerce();
add_action( 'vc_after_set_mode', array(
$vendor,
'load',
) );
require_once vc_path_dir( 'VENDORS_DIR', 'plugins/woocommerce/grid-item-filters.php' );
// Add 'add to card' link to the list of Add link.
add_filter( 'vc_gitem_add_link_param', 'vc_gitem_add_link_param_woocommerce' );
// Filter to add link attributes for grid element shortcode.
add_filter( 'vc_gitem_post_data_get_link_link', 'vc_gitem_post_data_get_link_link_woocommerce', 10, 3 );
add_filter( 'vc_gitem_post_data_get_link_target', 'vc_gitem_post_data_get_link_target_woocommerce', 12, 2 );
add_filter( 'vc_gitem_post_data_get_link_real_link', 'vc_gitem_post_data_get_link_real_link_woocommerce', 10, 4 );
add_filter( 'vc_gitem_post_data_get_link_real_target', 'vc_gitem_post_data_get_link_real_target_woocommerce', 12, 3 );
add_filter( 'vc_gitem_zone_image_block_link', 'vc_gitem_zone_image_block_link_woocommerce', 10, 3 );
add_action( 'wp_enqueue_scripts', 'vc_woocommerce_add_to_cart_script' );
}
}

View File

@@ -0,0 +1,16 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
add_action( 'plugins_loaded', 'vc_init_vendor_wpml' );
function vc_init_vendor_wpml() {
if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
require_once vc_path_dir( 'VENDORS_DIR', 'plugins/class-vc-vendor-wpml.php' );
$vendor = new Vc_Vendor_WPML();
add_action( 'vc_after_set_mode', array(
$vendor,
'load',
) );
}
}

View File

@@ -0,0 +1,27 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @since 4.4 vendors initialization moved to hooks in autoload/vendors.
*
* Used to initialize plugin yoast vendor.
*/
// 16 is required to be called after WPSEO_Admin_Init constructor. @since 4.9
add_action( 'plugins_loaded', 'vc_init_vendor_yoast', 16 );
function vc_init_vendor_yoast() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // Require class-vc-wxr-parser-plugin.php to use is_plugin_active() below
if ( is_plugin_active( 'wordpress-seo/wp-seo.php' ) || class_exists( 'WPSEO_Metabox' ) ) {
require_once vc_path_dir( 'VENDORS_DIR', 'plugins/class-vc-vendor-yoast_seo.php' );
$vendor = new Vc_Vendor_YoastSeo();
if ( defined( 'WPSEO_VERSION' ) && version_compare( WPSEO_VERSION, '3.0.0' ) === - 1 ) {
add_action( 'vc_after_set_mode', array(
$vendor,
'load',
) );
} elseif ( is_admin() && 'vc_inline' === vc_action() ) {
$vendor->frontendEditorBuild();
}
}
}