first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
<?php
/**
* Class for the base update.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Base updater class.
*
* @since 1.0.0
*/
class Jet_Woo_Product_Gallery_Base_Update {
/**
* Api parameters.
*
* @since 1.0.0
* @access protected
* @var array
*/
protected $api = array(
'version' => '',
'slug' => '',
'api_url' => 'http://jetproductgallery.zemez.io/updates/%s.json',
);
/**
* Init class parameters.
*
* @since 1.0.0
* @param array $attr Input attributes array.
* @return void
*/
protected function base_init( $attr = array() ) {
$this->api = array_merge( $this->api, $attr );
}
/**
* Check if update are available.
*
* @since 1.0.0
* @return array
*/
protected function check_update() {
$response = $this->remote_query();
if ( ! $response ) {
return array( 'version' => false );
}
if ( version_compare( $this->api['version'], $response->version, '<' ) ) {
return array(
'version' => $response->version,
'package' => $response->package,
);
}
return array( 'version' => false );
}
/**
* Remote request to updater API.
*
* @since 1.0.0
* @return array|bool
*/
protected function remote_query() {
$response = wp_remote_get( sprintf( $this->api['api_url'], $this->api['slug'] ) );
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != '200' ) {
return false;
}
$response = json_decode( $response['body'] );
return $response;
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* Class for the update plugins.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
require jet_woo_product_gallery()->plugin_path( 'includes/updater/class-jet-woo-product-gallery-base-update.php' );
/**
* Define plugin updater class.
*
* @since 1.0.0
*/
class Jet_Woo_Product_Gallery_Plugin_Update extends Jet_Woo_Product_Gallery_Base_Update {
/**
* Init class parameters.
*
* @since 1.0.0
* @param array $attr Input attributes array.
* @return void
*/
public function init( $attr = array() ) {
$this->base_init( $attr );
/**
* Need for test update - set_site_transient( 'update_plugins', null );
*/
add_action( 'pre_set_site_transient_update_plugins', array( $this, 'update' ) );
}
/**
* Process update.
*
* @since 1.0.0
* @param object $data Update data.
* @return object
*/
public function update( $data ) {
$new_update = $this->check_update();
if ( $new_update['version'] ) {
$this->api['plugin'] = $this->api['slug'] . '/' . $this->api['slug'] . '.php';
$update = new stdClass();
$update->slug = $this->api['slug'];
$update->plugin = $this->api['plugin'];
$update->new_version = $new_update['version'];
$update->url = isset( $this->api['details_url'] ) ? $this->api['details_url'] : false;
$update->package = $new_update['package'];
$data->response[ $this->api['plugin'] ] = $update;
}
return $data;
}
}
if ( ! function_exists( 'jet_woo_product_gallery_updater' ) ) {
function jet_woo_product_gallery_updater() {
return new Jet_Woo_Product_Gallery_Plugin_Update();
}
}