HEX
Server: Apache
System: Linux pdx1-shared-a4-02 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: niched (5283231)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/niched/writesideup.net/wp-content/plugins/codevz-plus/updates.php
<?php if ( ! defined( 'ABSPATH' ) ) { wp_die(); }
/**
 *
 * Automatic update plugins
 * 
 * @author Codevz
 * @link http://codevz.com/
 *
 */
class Codevz_Plugin_Update {

	/**
	 *
	 * Instance
	 *
	 * @access private
	 * @var class
	 *
	 */
	private static $instance = null;

	/**
	 *
	 * List of plugins
	 *
	 * @access private
	 * @var array of plugins
	 *
	 */
	private static $plugins = [];

	/**
	 *
	 * List of plugins
	 *
	 * @access private
	 * @var plugins server URL
	 *
	 */
	private static $server = 'https://xtratheme.com/';

	public function __construct() {

		self::$server  = apply_filters( 'codevz_server', self::$server );
		self::$plugins = apply_filters( 'codevz_plugins', [
			'codevz-plus' 	=> 'Codevz Plus', 
			'js_composer' 	=> 'WPBakery Page Builder', 
			'revslider' 	=> 'Revolution Slider'
		] );

		// Inform WordPress version of plugins
		add_filter( 'pre_set_site_transient_update_plugins', [ __CLASS__, 'transient' ], 99999 );

		// Get plugin changelog and inform WordPress
		add_filter( 'plugins_api', [ __CLASS__, 'changelog' ], 99999, 3 );

		// Allow WordPress download zip file of plugins
		add_filter( 'upgrader_pre_download', [ __CLASS__, 'download' ], 99999, 3 );
	}

	/**
	 *
	 * Instance
	 *
	 * @return object
	 *
	 */
	public static function instance() {
		if ( self::$instance === null ) {
			self::$instance = new self();
		}

		return self::$instance;
	}

	/**
	 *
	 * Inform WordPress from new vesion of plugins
	 * 
	 * @return object
	 * 
	 */
	public static function transient( $transient ) {

		// Get new versions
		$versions = get_transient( 'codevz_versions' );
		if ( empty( $versions ) ) {
			$request = wp_remote_get( self::$server . 'plugins/versions.json' );
			if ( ! is_wp_error( $request ) ) {
				$body = wp_remote_retrieve_body( $request );
				$versions = json_decode( $body, true );
				set_transient( 'codevz_versions', $versions, 21600 ); // cache for 6 hours
			}
		}

		// There is no new versions
		if ( ! isset( $versions['plugins'] ) ) {
			return $transient;
		}

		// Fix when there is no any plugins
		if ( empty( $transient->response ) ) {
			$transient->response = [];
		}

		// Get current plugins versions
		$plugins = function_exists( 'get_plugins' ) ? get_plugins() : [];

		// Inform WordPress about new plugins versions
		foreach( self::$plugins as $slug => $title ) {
			if ( class_exists( 'stdClass' ) && isset( $versions['plugins'][ $slug ]['version'] ) ) {
				
				// Get current plugin version
				$current_ver = isset( $plugins[ $slug . '/' . $slug . '.php' ]['Version'] ) ? $plugins[ $slug . '/' . $slug . '.php' ]['Version'] : '999';
				
				// Compare current and new plugin version
				if ( version_compare( $current_ver, $versions['plugins'][ $slug ]['version'], '<' ) ) {

					$obj 				= new stdClass();
					$obj->slug 			= $slug;
					$obj->name 			= $title;
					$obj->new_version 	= $versions['plugins'][ $slug ]['version'];
					$obj->url 			= '';
					$obj->package 		= self::$server . 'plugins/' . $slug . '.zip';

					$transient->response[ $slug . '/' . $slug . '.php' ] = $obj;

				}
			}
		}

		return $transient;
	}

	/**
	 *
	 * Set changelog for plugin update
	 * 
	 * @return string
	 * 
	 */
	public static function changelog( $false, $action, $arg ) {

		// Create new information for codevz plus
		if ( isset( $arg->slug ) && $arg->slug === 'codevz-plus' ) {

			$obj 				= new stdClass();
			$obj->author 		= 'Codevz';
			$obj->name 			= 'Codevz Plus';
			$obj->slug 			= 'codevz-plus';
			$obj->plugin_name 	= 'codevz-plus';
			$obj->description 	= '';
			$obj->sections 		= [ 'changelog' => 'Please check item page on themeforest for changelog ...' ];

			return $obj;
		}

		return $false;
	}

	/**
	 *
	 * Allow WordPress to download zip file of plugins
	 * 
	 * @return string $reply
	 *
	 */
	public static function download( $reply, $package, $updater ) {

		foreach ( self::$plugins as $slug => $title ) {
			if ( Codevz_Plus::contains( $package, $slug ) ) {
				return false;
			}
		}

		return $reply;
	}

}

// Run
Codevz_Plugin_Update::instance();