MOON
Server: Apache
System: Linux vps.erhabenn.com.br 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User: machen (1008)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /disk001/machen/www/support/wp-content/plugins/echo-widgets/includes/class-widg-core-utilities.php
<?php

/**
 * Utility functions specific to this plugin
 */
class WIDG_Core_Utilities {


	/**
	 * if the Editor is active then use its configuration changes to update the current configuration
	 * @param $config
	 * @return mixed
	 */
	public static function update_from_editor_config( $config ) {

		// do not make any changes to the configuration unless Editor is active
		if ( empty( $_REQUEST['epkb-editor-page-loaded'] ) || empty( $_REQUEST['epkb-editor-settings'] ) ) {
			return $config;
		}

		$new_config = json_decode(stripcslashes($_REQUEST['epkb-editor-settings'] ), true);
		if ( empty( $new_config ) || ! is_array($new_config) ) {
			return $config;
		}

		// use Editor configuration to update current configuration
		foreach ( $new_config as $zone_name => $zone ) {
			foreach ( $zone['settings'] as $field_name => $field ) {
				if ( ! isset( $config[$field_name] ) ) {
					continue;
				}

				$config[$field_name] = $field['value'];
			}
		}

		return $config;
	}

	/**
	 * Retrieve a KB article with security checks
	 *
	 * @param $post_id
	 * @return null|WP_Post - return null if this is NOT KB post
	 */
	public static function get_kb_post_secure( $post_id ) {

		if ( empty($post_id) ) {
			return null;
		}

		// ensure post_id is valid
		$post_id = WIDG_Utilities::sanitize_int( $post_id );
		if ( empty($post_id) ) {
			return null;
		}

		// retrieve the post and ensure it is one
		$post = get_post( $post_id );
		if ( empty( $post ) || ! $post instanceof WP_Post ) {
			return null;
		}

		// verify it is a KB article
		if ( ! WIDG_KB_Handler::is_kb_post_type( $post->post_type ) ) {
			return null;
		}

		return $post;
	}

	/**
	 * Is WPML enabled? Only for KB CORE. ADD-ONs to call this function in core
	 *
	 * @param $kb_id
	 *
	 * @return bool
	 */
	public static function is_wpml_enabled_addon( $kb_id ) {

		if ( WIDG_Utilities::is_positive_int( $kb_id ) ) {
			$kb_config = WIDG_KB_Core::get_kb_config( $kb_id );
			if ( is_wp_error( $kb_config ) ) {
				return false;
			}
		} else {
			return false;
		}

		return WIDG_Utilities::is_wpml_enabled( $kb_config );
	}
}