Giter Site home page Giter Site logo

sherkspear / self-hosted-wordpress-plugin-repository Goto Github PK

View Code? Open in Web Editor NEW

This project forked from omarabid/self-hosted-wordpress-plugin-repository

0.0 2.0 0.0 21 KB

Create your own self-hosted WordPress Plugin repository for pushing automatic updates.

PHP 100.00%

self-hosted-wordpress-plugin-repository's Introduction

Self-Hosted-WordPress-Plugin-repository

Create your own self-hosted WordPress Plugin repository for pushing automatic updates.

For integration with Composer, please use wp-autoupdate

Quick Start

  1. Place the wp_autoupdate.php file somewhere in your plugin directory and require it.
require_once( 'wp_autoupdate.php' );
  1. Hook the init function to initiatilize the update function when your plugin loads. Best put in your main plugin.php file:
	function snb_activate_au()
	{
		// set auto-update params
		$plugin_current_version = '<your current version> e.g. "0.6"';
		$plugin_remote_path     = '<remote path to your update server> e.g. http://update.example.com';
		$plugin_slug            = plugin_basename(__FILE__);
		$license_user           = '<optional license username>';
		$license_key            = '<optional license key>';

		// only perform Auto-Update call if a license_user and license_key is given
		if ( $license_user && $license_key && $plugin_remote_path )
		{
			new wp_autoupdate ($plugin_current_version, $plugin_remote_path, $plugin_slug, $license_user, $license_key);
		}
	}

	add_action('init', 'snb_activate_au');

The license_user and license_key fields are optional. You can use these to implement an auto-update functionility for specified customers only. It's left to the developer to implement this if needed.

Note that it's possible to store certain settings as a Wordpress option like the plugin_remote_path version. If you do so, you can use get_option() to get fields like plugin_remote_path, license_user, license_key directly from your plugin. This increases maintainability.

  1. Create your server back-end to handle the update requests. You are fee to implement this any way you want, with any framework you want. The idea is that when Wordpress loads your plugin, it will check the given remote path to see if an update is availabe through the returned transient. For a basic implementation see the example below.

Note however this example does not provide any protection or security, it serves as a demonstration purpose only.

if (isset($_POST['action'])) {
  switch ($_POST['action']) {
    case 'version':
      echo '1.1';
      break;
    case 'info':
      $obj                = new stdClass();
      $obj->slug          = 'plugin.php';
      $obj->plugin_name   = 'plugin.php';
      $obj->new_version   = '1.1';
      $obj->requires      = '3.0';
      $obj->tested        = '3.3.1';
      $obj->downloaded    = 12540;
      $obj->last_updated  = '2012-01-12';
      $obj->sections      = array(
          'description'     => 'The new version of the Auto-Update plugin',
          'another_section' => 'This is another section',
          'changelog'       => 'Some new features'
      );
      $obj->download_link = 'http://localhost/repository/update.zip';
      echo serialize($obj);
    case 'license':
      echo 'false';
      break;
  }
} else {
    header('Cache-Control: public');
    header('Content-Description: File Transfer');
    header('Content-Type: application/zip');
    readfile('update.zip');
}
  1. Make sure the download_link points to a *.zip file that holds the new version of your plugin. This *.zip file must have the same name as your WordPress plugin does. Also the *.zip file must NOT contain the plugin files directly, but must have a subfolder with the same name as your plugin to make WordPress play nicely with it. e.g.:
my-plugin.zip
     │
     └ my-plugin
           │
           ├ my-plugin.php
           ├ README.txt
           ├ uninstall.php
           ├ index.php
           ├ ..
           └ etc.

More information

You could find detailed explanation and example of usage here

self-hosted-wordpress-plugin-repository's People

Contributors

btwatts avatar grappler avatar kluverp avatar maxkoryukov avatar miya0001 avatar mjperales-tcu avatar omarabid avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.