PHP code example of yahnis-elsts / wp-update-server
1. Go to this page and download the library: Download yahnis-elsts/wp-update-server library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yahnis-elsts / wp-update-server example snippets
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
$MyUpdateChecker = PucFactory::buildUpdateChecker(
'http://example.com/wp-update-server/?action=get_metadata&slug=plugin-directory-name', //Metadata URL.
__FILE__, //Full path to the main plugin file.
'plugin-directory-name' //Plugin slug. Usually it's the same as the name of the directory.
);
$MyThemeUpdateChecker = new ThemeUpdateChecker(
'theme-directory-name', //Theme slug. Usually the same as the name of its directory.
'http://example.com/wp-update-server/?action=get_metadata&slug=theme-directory-name' //Metadata URL.
);
class MyCustomServer extends Wpup_UpdateServer {
protected function filterMetadata($meta, $request) {
$meta = parent::filterMetadata($meta, $request);
unset($meta['download_url']);
return $meta;
}
protected function actionDownload(Wpup_Request $request) {
$this->exitWithError('Downloads are disabled.', 403);
}
}
$server = new MyCustomServer();
$server->handleRequest();
/*
Plugin Name: Plugin Update Server
Description: An example plugin that runs the update API.
Version: 1.0
Author: Yahnis Elsts
Author URI: http://w-shadow.com/
*/
g" query parameters are often used by the WordPress core
//or other plugins, so lets use different parameter names to avoid conflict.
add_filter('query_vars', array($this, 'addQueryVariables'));
add_action('template_redirect', array($this, 'handleUpdateApiRequest'));
}
public function addQueryVariables($queryVariables) {
$queryVariables = array_merge($queryVariables, array(
'update_action',
'update_slug',
));
return $queryVariables;
}
public function handleUpdateApiRequest() {
if ( get_query_var('update_action') ) {
$this->updateServer->handleRequest(array_merge($_GET, array(
'action' => get_query_var('update_action'),
'slug' => get_query_var('update_slug'),
)));
}
}
}
class MyCustomServer extends Wpup_UpdateServer {
protected function generateDownloadUrl(Wpup_Package $package) {
$query = array(
'update_action' => 'download',
'update_slug' => $package->slug,
);
return self::addQueryArg($query, $this->serverUrl);
}
}
$examplePlugin = new ExamplePlugin();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.