post_modified) > strtotime(get_post($post_id)->post_modified) ? $autosave : false; } /** * Is CPT supports custom templates. * * Whether the Custom Post Type supports templates. * * @since 2.0.0 * @static * * @return bool True is templates are supported, False otherwise */ public static function isCptCustomTemplatesSupported(WPPost $post) { // return method_exists(wp_get_theme(), 'get_post_templates'); return UId::CONTENT !== $post->uid->id_type && $post->template_type !== 'product-quick-view' && $post->template_type !== 'product-miniature'; } /** * @since 2.1.2 * @static */ public static function arrayInject($array, $key, $insert) { $length = array_search($key, array_keys($array), true) + 1; return array_slice($array, 0, $length, true) + $insert + array_slice($array, $length, null, true); } /** * Render html attributes * * @static * * @param array $attributes * * @return string */ public static function renderHtmlAttributes(array $attributes) { $rendered_attributes = []; foreach ($attributes as $attribute_key => $attribute_values) { if ([] === $attribute_values) { $rendered_attributes[] = $attribute_key; continue; } if (is_array($attribute_values)) { $attribute_values = implode(' ', $attribute_values); } $rendered_attributes[] = sprintf('%1$s="%2$s"', $attribute_key, esc_attr($attribute_values)); } return implode(' ', $rendered_attributes); } public static function getMetaViewport($context = '') { $meta_tag = ''; /* * Viewport meta tag. * * Filters the Elementor preview URL. * * @since 2.5.0 * * @param string $meta_tag Viewport meta tag */ return apply_filters('elementor/template/viewport_tag', $meta_tag, $context); } // public static function printJsConfig($handle, $js_var, $config) - Use wp_localize_script instead // public static function handleDeprecation($item, $version, $replacement = null) /** * Checks a control value for being empty, including a string of '0' not covered by PHP's empty(). * * @param mixed $source * @param bool|string $key * * @return bool */ public static function isEmpty(&$source, $key = false) { if (is_array($source)) { if (!isset($source[$key])) { return true; } return !$source[$key] && '0' !== $source[$key]; } return !$source && '0' !== $source; } public static function hasPro() { return true; } /** * Convert HTMLEntities to UTF-8 characters * * @param $string * * @return string */ public static function urlencodeHtmlEntities($string) { $entities_dictionary = [ '‘' => "'", // Opening single quote '’' => "'", // Closing single quote '“' => '"', // Closing double quote '”' => '"', // Opening double quote '‘' => "'", // Closing single quote '’' => "'", // Opening single quote '‚' => "'", // Single low quote '“' => '"', // Closing double quote '”' => '"', // Opening double quote '„' => '"', // Double low quote ]; // Decode decimal entities $string = str_replace(array_keys($entities_dictionary), array_values($entities_dictionary), $string); return rawurlencode(html_entity_decode($string, ENT_QUOTES | ENT_HTML5, 'UTF-8')); } /** * Parse attributes that come as a string of comma-delimited key|value pairs. * Removes Javascript events and unescaped `href` attributes. * * @param string $attributes_string * @param string $delimiter Default comma `,` * * @return array */ public static function parseCustomAttributes($attributes_string, $delimiter = ',') { $attributes = explode($delimiter, $attributes_string); $result = []; foreach ($attributes as $attribute) { $attr_key_value = explode('|', $attribute); $attr_key = \Tools::strtolower($attr_key_value[0]); // Remove any not allowed characters. preg_match('/[-_a-z0-9]+/', $attr_key, $attr_key_matches); if (empty($attr_key_matches[0])) { continue; } $attr_key = $attr_key_matches[0]; // Avoid Javascript events and unescaped href. if ('href' === $attr_key || 'on' === substr($attr_key, 0, 2)) { continue; } if (isset($attr_key_value[1])) { $attr_value = trim($attr_key_value[1]); } else { $attr_value = ''; } $result[$attr_key] = $attr_value; } return $result; } }