Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WP CLI as an alternative to cURL? #133

Open
ThatStevensGuy opened this issue Dec 5, 2021 · 0 comments
Open

WP CLI as an alternative to cURL? #133

ThatStevensGuy opened this issue Dec 5, 2021 · 0 comments

Comments

@ThatStevensGuy
Copy link

ThatStevensGuy commented Dec 5, 2021

Just a suggestion. Some people may want to use WP CLI instead of cURL to update FeedWordPress.

My site uses Composer, so the implementation might be a bit different to others.

It would be nicer if FeedWordPress had the WP CLI command built in. 'wp feedwordpress update' for example.

$feedwordpress variable doesn't seem to be fully accessible from WP CLI, so I had to redeclare it. I basically redo what the plugin does when it initialises, then it seems to work fine.

// crontab
*/10 * *   *   *     /usr/local/bin/wp mysite feedwordpress update --path="/var/www/mysite.com/html" > /dev/null 2>&1

// functions.php

/**
 * Include theme namespace.
 */
require_once __DIR__ . '/vendor/autoload.php';

if (class_exists('WP_CLI')) {
    WP_CLI::add_command('mysite feedwordpress', 'MySite\Theme\CLI\FeedWordPress');
}

// Class - /Theme/CLI/FeedWordPress.php

<?php

namespace MySite\Theme\CLI;

use WP_CLI;
use FeedWordPress as FWP;

class FeedWordPress
{
    /**
     * Update FeedWordPress
     *
     * ## EXAMPLES
     *
     *     wp mysite feedwordpress update
     *
     * @when after_wp_load
     *
     * @param array|null $args The arguments.
     * @param array|null $assoc_args The associative arguments.
     *
     * @return void
     */
    public function update($args = null, $assoc_args = null): void
    {
        global $feedwordpress;

        $feedwordpress = new FWP(); // Redeclare FeedWordPress.

        // Unsure if this is necessary, but do it just incase.
        if (!$feedwordpress->needs_upgrade()) {
            $feedwordpress->add_filters();
        }

        $feedwordpress->update();

        WP_CLI::success('Done!');
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant