Git Product home page Git Product logo

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 enri90 avatar grappler avatar kluverp avatar maxkoryukov avatar miya0001 avatar mjperales-tcu avatar omarabid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

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

How do I protect this?

Hi!

Great code and tutorial. I got this to work immediately! However, I would like to use this code to host updates for a plugin I made myself and use on some sites. You said that this does not come with protection or security. How should I go about to secure it?

I have no sensitive information whatsoever in my plugin. I am not making any SQL queries based on input, I am just using the plugin update functions just like you made it. The plugin is also just a WordPress skin more or less.
Any thoughts? Again, thanks for a great code!

Thanks in advance,

Kind regards
Teapot

Update class name

Hi,
I just wanted to note that the plugin.php file needs to be updated with the correct class name. The class name is WP_AutoUpdate and in the plugin.php file it is called wp_auto_update.

prevent other plugins to update

Hi,
Thank you for your great code, It is really helpful
But does it prevent other plugins to be check for new updates?

Regards

Folder rename problem

After updating a plugin the plugin changes name from "plugin" to "plugin-48HxJa" do you have any idea, why this is happening?

small bug in example 'update.php'

When the class checks for update, it calls the case 'version'.
This case needs the obj->tested, but that is only defined in the case 'info'.

I solved this by adding the obj->tested to the list of standards, just below obj->new_version.

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.