Giter VIP home page Giter VIP logo

Comments (5)

mav2287 avatar mav2287 commented on September 24, 2024

I had to go dig through the code to find the function you referenced in your note. You may want to change the example for Wordpress to...

require_once __DIR__ . '/path/to/wp-update-server/loader.php';

class Wpup_UpdateServer_Extension extends Wpup_UpdateServer {
    // Change the action and slug to match others
    protected function generateDownloadUrl(Wpup_Package $package) {
        $query = array(
            'update_action' => 'download',
            'update_slug' => $package->slug,
        );
        return self::addQueryArg($query, $this->serverUrl);
    }
}

class ExamplePlugin {
    protected $updateServer;

    public function __construct() {
        $this->updateServer = new Wpup_UpdateServer_Extension(home_url('/'));
        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(
                'action' => get_query_var('update_action'),
                'slug'   => get_query_var('update_slug'),
            ));
        }
    }
}

$examplePlugin = new ExamplePlugin();

from wp-update-server.

YahnisElsts avatar YahnisElsts commented on September 24, 2024

Do you mean the code example in the Running this server from another script section? Yes, it does use different query parameters (because action and slug are often already taken by WP core), but it also includes this note:

Note: If you intend to use something like the above in practice, you'll probably want to override Wpup_UpdateServer::generateDownloadUrl() to use your own URL structure or query variable names.

That code is intended to be a brief example, not something that you can use as-is. I guess I could make that more apparent or adjust the example as you suggested.

from wp-update-server.

mav2287 avatar mav2287 commented on September 24, 2024

Not a huge deal, but it's always nice to have working examples you get running quickly without extra code.

from wp-update-server.

hairkyahoo avatar hairkyahoo commented on September 24, 2024

I was able to get up and running quickly by using the documentation. When it come to coding, examples are just that, examples.

from wp-update-server.

YahnisElsts avatar YahnisElsts commented on September 24, 2024

I've updated the code example as suggested by @mav2287 (with a few slight modifications).

from wp-update-server.

Related Issues (20)

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.