* @author ThemePunch <info@themepunch.com>
* @link https://www.themepunch.com/
* @copyright 2024 ThemePunch
if(!defined('ABSPATH')) exit();
global $revslider_rev_start_size_loaded;
$revslider_rev_start_size_loaded = false;
class RevSliderFunctions extends RevSliderData {
public function __construct(){
* START: DEPRECATED FUNCTIONS THAT ARE IN HERE FOR OLD ADDONS TO WORK PROPERLY
* old version of get_val();
* added for compatibility with old AddOns
public static function getVal($arr, $key, $default = ''){
$f = RevSliderGlobals::instance()->get('RevSliderFunctions');
$f->add_deprecation_message('getVal', 'get_val');
return $f->get_val($arr, $key, $default);
* old version of class_to_array_single();
* added for compatibility with old AddOns
public static function cleanStdClassToArray($arr){
$f = RevSliderGlobals::instance()->get('RevSliderFunctions');
$f->add_deprecation_message('cleanStdClassToArray', 'class_to_array_single');
return $f->class_to_array_single($arr);
* END: DEPRECATED FUNCTIONS THAT ARE IN HERE FOR OLD ADDONS TO WORK PROPERLY
* attempt to load cache for _get_global_settings
public function get_global_settings(){
return $this->get_wp_cache('_get_global_settings');
* @before: RevSliderOperations::getGeneralSettingsValues()
protected function _get_global_settings(){
$gs = get_option('revslider-global-settings', '');
$gs = json_decode($gs, true);
return apply_filters('rs_get_global_settings', $gs);
* update general settings
* @before: RevSliderOperations::updateGeneralSettings()
public function set_global_settings($global, $merge = false){
$this->delete_wp_cache('_get_global_settings');
if($this->_truefalse($merge) === true){
$_global = $this->get_global_settings();
if(!is_array($_global)) $_global = array();
if(!is_array($global)) $global = array();
$global = array_replace_recursive($_global, $global);
$global = json_encode($global);
update_option('revslider-global-settings', $global);
* get all additions from the update checks
public function get_addition($key = ''){
$additions = (array)get_option('revslider-additions', array());
$additions = (!is_array($additions)) ? json_decode($additions, true) : $additions;
return (empty($key)) ? $additions : $this->get_val($additions, $key);
* @before: RevSliderFunctions::throwError()
public function throw_error($message, $code = null){
throw new Exception($message, $code);
throw new Exception($message);
* get value from array. if not - return alternative
* before: RevSliderFunctions::get_val();
* @param mixed $arr could be array | object | scalar
* @param mixed $key could be array | string
* @param mixed $default value to return if key not found
public function get_val($arr, $key, $default = ''){
//scalar = int, float, string и bool
if(is_scalar($arr)) return $default;
if(is_object($arr)) $arr = (array)$arr;
//if key is string, check immediately
if(!is_array($key)) return (isset($arr[$key])) ? $arr[$key] : $default;
if(is_object($arr)) $arr = (array)$arr;
public function set_val(&$base, $name, $value){
if(!isset($base[$key])) $base[$key] = array();
}elseif(is_object($base)){
if(!isset($base->$key)) $base->$key = new stdClass();
* before: RevSliderBase::getPostVar();
public function get_post_var($key, $default = '', $esc = true){
$val = $this->get_var($_POST, $key, $default);
return ($esc) ? esc_html($val) : $val;
* before: RevSliderBase::getGetVar();
public function get_get_var($key, $default = '', $esc = true){
$val = $this->get_var($_GET, $key, $default);
return ($esc) ? esc_html($val) : $val;
* get POST or GET variable in this order
* before: RevSliderBase::getPostGetVar();
public function get_request_var($key, $default = '', $esc = true){
$val = (array_key_exists($key, $_POST)) ? $this->get_var($_POST, $key, $default) : $this->get_var($_GET, $key, $default);
return ($esc) ? esc_html($val) : $val;
* get a variable from an array,
* before: RevSliderBase::getVar()
public function get_var($arr, $key, $default = ''){
return (isset($arr[$key])) ? $arr[$key] : $default;
* check for true and false in all possible ways
public function _truefalse($v){
if(in_array($v, array('false', false, 'off', NULL, 0, -1), true)){
}elseif(in_array($v, array('true', true, 'on'), true)){
* validate that some value is numeric
* before: RevSliderFunctions::validateNumeric
public function validate_numeric($val, $fn = 'Field'){
$this->validate_not_empty($val, $fn);
$this->throw_error($fn.__(' should be numeric', 'revslider'));
* validate that some variable not empty
* before: RevSliderFunctions::validateNotEmpty
public function validate_not_empty($val, $fn = 'Field'){
if(empty($val) && is_numeric($val) == false)
$this->throw_error($fn.__(' should not be empty', 'revslider'));
* encode array into json for client side
* @before: RevSliderFunctions::jsonEncodeForClientSide()
public function json_encode_client_side($arr){
$json = (defined('JSON_INVALID_UTF8_IGNORE')) ? json_encode($arr, JSON_INVALID_UTF8_IGNORE) : json_encode($arr);
$json = (!empty($json)) ? addslashes($json) : $json;
return (empty($json)) ? '{}' : "'".$json."'";
* turn a string into an array, check also for slashes!
public function json_decode_slashes($data){
if(gettype($data) !== 'string') return $data;
$data_decoded = json_decode(stripslashes($data), true);
if(empty($data_decoded)) $data_decoded = json_decode($data, true);
* Convert std class to array, with all sons
* before: RevSliderFunctions::convertStdClassToArray();
public function class_to_array($arr){
return json_decode(json_encode($arr), true);
* Convert std class to array, single
* before: RevSliderFunctions::cleanStdClassToArray();
public function class_to_array_single($arr){
* Check Array for Value Recursive
public function in_array_r($needle, $haystack, $strict = false){
if(is_array($haystack) && !empty($haystack)){
foreach($haystack as $item){
if(($strict ? $item === $needle : $item == $needle) || (is_array($item) && $this->in_array_r($needle, $item, $strict))){
* compress an array/object/string to a string
public function do_compress($data, $level = 9){
if(is_array($data) || is_object($data)) $data = json_encode($data);
if(!function_exists('gzcompress') || !function_exists('gzuncompress')) return $data; //gzencode / gzdecode
return base64_encode(gzcompress($data, $level));
* decompress an string to an array/object/string
public function do_uncompress($data){
if($data === false || empty($data) || is_array($data) || is_object($data)) return $data;
$_data = json_decode($data, true);
if(is_array($_data) || is_object($_data)) return $_data;
if(!function_exists('gzcompress') || !function_exists('gzuncompress')) return $data; //gzencode / gzdecode
$data = gzuncompress(base64_decode($data));
$_data = json_decode($data, true);
return (!empty($_data)) ? $_data : $data;
* get attachment image url
* before: RevSliderFunctionsWP::getUrlAttachmentImage();
public function get_url_attachment_image($id, $size = 'full'){
$image = wp_get_attachment_image_src($id, $size);
$url = (empty($image)) ? false : $this->get_val($image, 0);
if($url === false) $url = wp_get_attachment_url($id);
* gets a temporary path where files can be stored
public function get_temp_path($path = 'rstemp'){
if(function_exists('sys_get_temp_dir')){
$temp = sys_get_temp_dir();
if(@is_dir($temp) && wp_is_writable($temp)){
$dir = trailingslashit($temp).$path.'/';
if(!is_dir($dir)) @mkdir($dir, 0777, true);
if(is_dir($dir) && wp_is_writable($dir)) return $dir;
$temp = ini_get('upload_tmp_dir');
if(@is_dir($temp) && wp_is_writable($temp)){
$dir = trailingslashit($temp).$path.'/';
if(!is_dir($dir)) @mkdir($dir, 0777, true);
if(is_dir($dir) && wp_is_writable($dir)) return $dir;
$temp_dir = get_temp_dir();
if(wp_is_writable($temp_dir)){
$dir = trailingslashit($temp_dir).$path.'/';
if(!is_dir($dir)) @mkdir($dir, 0777, true);
if(is_dir($dir) && wp_is_writable($dir)) return $dir;
$upload_dir = wp_upload_dir();
$dir = $upload_dir['basedir'].'/'.$path.'/';
if(!is_dir($dir)) @mkdir($dir, 0777, true);
* retrieve the image id from the given image url
public function get_image_id_by_url($image_url){
if($image_url === '') return false;
$attachment_id = attachment_url_to_postid($image_url);
return (is_null($attachment_id) || $attachment_id === 0) ? false : $attachment_id; //fix for B-5855627275
* retrieve the image id from the given image filename/basename
public function get_image_id_by_basename($basename){
$var = $wpdb->get_var($wpdb->prepare("SELECT `post_id` FROM `".$wpdb->postmeta."` WHERE `meta_value` LIKE %s LIMIT 0,1", '%/'.$basename));
return ($var) ? $var : false;
* get image url from image path.
public function get_image_url_from_path($path){
if(empty($path) || substr($path, -1) === '/' || substr($path, -1) === '\\') return ''; //check if the path ends with /, if yes its not a correct image path
//protect from absolute url
$lower = strtolower($path);
$base_url = $this->get_base_url();
$return = (strpos($lower, 'http://') !== false || strpos($lower, 'https://') !== false || strpos($lower, 'www.') === 0) ? $path : $base_url.$path;
return ($return !== $base_url) ? $return : '';
* Check if Path is a Valid Image File
public function check_valid_image($url){
if(empty($url)) return false;
$ext = strtolower(pathinfo($url, PATHINFO_EXTENSION));
$img_exts = array('gif', 'jpg', 'jpeg', 'png');
return (in_array($ext, $img_exts)) ? $url : false;
* get the upload URL of images
public static function get_base_url(){
return (is_multisite() == false) ? content_url().'/' : wp_upload_dir()['baseurl'].'/';
* strip slashes recursive
* before: RevSliderBase::stripslashes_deep()
public static function stripslashes_deep($value){
if(empty($value)) return $value;
$value = is_array($value) ? array_map(array('RevSliderFunctions', 'stripslashes_deep'), $value) : stripslashes($value);
public static function esc_attr_deep($value){
$value = is_array($value) ? array_map(array('RevSliderFunctions', 'esc_attr_deep'), $value) : esc_attr($value);
* get post types with categories for client side.
public function get_post_types_with_categories_for_client(){
$post_types = $this->get_post_types_with_taxonomies();
foreach($post_types as $name => $tax){
foreach($tax as $tax_name => $tax_title){
$cats = $this->get_categories_assoc($tax_name);
if(empty($cats)) continue;
$cat['option_disabled_'.$c] = '---- '. $tax_title .' ----';
foreach($cats as $catID => $catTitle){
$cat[$tax_name.'_'.$catID] = $catTitle;
* get post types array with taxomonies
public function get_post_types_with_taxonomies(){
$post_types = $this->get_post_type_assoc();
foreach($post_types as $post_type => $title){
$post_types[$post_type] = $this->get_post_type_taxonomies($post_type);