• I write a lot of plugins that aren’t included in the WP extension directory, and have an api setup that can return the latest version of said plugins. I’m trying to write a function that checks the latest version against the installed version and notifies admins if the installed version is out of date. I’ve gotten it to do the actual check, but I’m at a loss as to how to notify the admin. Suggestions?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    It’s a little dated but this may help you out.

    https://clark-technet.com/2010/12/wordpress-self-hosted-plugin-update-api

    Thread Starter Dan Griffiths

    (@ghost1227)

    Found my own solution ??

    In case anyone else wants it, here’s the server-side code:

    checkver.php

    <?php
    
    	if(empty($_GET)) {
    		echo "You forgot to tell me what you're looking for!";
    	} else {
    		if(isset($_GET['app']) && isset($_GET['option'])) {
    			$app = $_GET['app'];
    			$option = $_GET['option'];
    
    			$ini_array =  parse_ini_file("checkver.ini", true);
    
    			if($ini_array[$app]) {
    				if($ini_array[$app][$option]) {
    					echo $ini_array[$app][$option];
    				} else {
    					echo 'Invalid option!';
    				}
    			} else {
    				echo "$app not found!";
    			}
    		} elseif(isset($_GET['app']) && !isset($_GET['option'])) {
    			echo "Option not specified for " . $_GET['app'] . "!";
    		} elseif(!isset($_GET['app']) && isset($_GET['option'])) {
    			echo "Get option " . $_GET['option'] . " for what?";
    		} else {
    			echo "Uh-oh... you're really lost aren't you?";
    		}
    	}
    ?>

    Here’s the ini file:

    checkver.ini

    [Plugin Name]
    ver=1.0

    Here’s the client side code:

    // Define some variables
    $app='Plugin Name';
    $ver='1.0';
    
    // Check for updates
    function update_check() {
        $latest = file_get_contents('https://path.to/checkver.php?app=' . rawurlencode($GLOBALS[app]) . '&option=ver');
        if($latest) {
            if(version_compare($GLOBALS[ver], $latest, '<')) { ?>
                <div class="updated"><p>An update for <?php echo $GLOBALS[app]; ?> is available! You are running version <?php echo $GLOBALS[ver]; ?>, the latest is version <?php echo $latest; ?>!</p></div>
            <?php }
        }
    }
    add_action('admin_notices', 'update_check');
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Third party update notifications’ is closed to new replies.