Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$30
Need help with theme update API script
index.php
<?php
// Sample Plugin & Theme API by Kaspars Dambis (kaspars@konstruktors.com)
$packages['ifeaturepro'] = array(
'versions' => array(
'1.1.5' => array(
'version' => '1.1.5',
'date' => '2011-05-25',
'package' => 'http://orangeola.com/ifeature/cache/ifeaturepro1.1.5.zip'
)
),
'info' => array(
'url' => 'http://cyberchimps.com/ifeaturepro/'
)
);
// Process API requests
$action = $_POST['action'];
$args = unserialize(stripslashes($_POST['request']));
if (is_array($args))
$args = array_to_object($args);
if (is_array($packages[$args->slug]))
$latest_package = array_shift($packages[$args->slug]['versions']);
// basic_check
if ($action == 'basic_check') {
$update_info = array_to_object($latest_package);
$update_info->slug = $args->slug;
if (version_compare($args->version, $latest_package['version'], '<'))
$update_info->new_version = $update_info->version;
print serialize($update_info);
}
// theme_update
if ($action == 'theme_update') {
$update_info = array_to_object($latest_package);
//$update_data = new stdClass;
$update_data = array();
$update_data['package'] = $update_info->package;
$update_data['new_version'] = $update_info->version;
$update_data['url'] = $packages[$args->slug]['info']['url'];
if (version_compare($args->version, $latest_package['version'], '<'))
print serialize($update_data);
}
function array_to_object($array = array()) {
if (empty($array) || !is_array($array))
return false;
$data = new stdClass;
foreach ($array as $akey => $aval)
$data->{$akey} = $aval;
return $data;
}
?>
update.php
<?php
/*
// TEMP: Enable update check on every request. Normally you don't need this! This is for testing only!
set_site_transient('update_themes', null);
*/
add_filter('pre_set_site_transient_update_themes', 'check_for_update');
function check_for_update($checked_data) {
global $wp_version;
if (empty($checked_data->checked))
return $checked_data;
$api_url = 'http://orangeola.com/api/';
$theme_base = basename(dirname(dirname(__FILE__)));
$request = array(
'slug' => $theme_base,
'version' => $checked_data->checked[$theme_base .'/'. $theme_base .'.php']
);
// Start checking for an update
$send_for_check = array(
'body' => array(
'action' => 'theme_update',
'request' => serialize($request),
'api-key' => md5(get_bloginfo('url'))
),
'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
);
$raw_response = wp_remote_post($api_url, $send_for_check);
if (!is_wp_error($raw_response) && ($raw_response['response']['code'] == 200))
$response = unserialize($raw_response['body']);
// Feed the update data into WP updater
if (!empty($response))
$checked_data->response[$theme_base] = $response;
return $checked_data;
}
if (is_admin())
$current = get_transient('update_themes');
?>The index.php is in the right location, the zip file is in the right directory, and I've used the proper theme slug in the $packages array, so I'm unsure as to what the problem is. This is definitely uncharted territory for me, and I'll be happy to provide any additional information.
Tyler Cunningham | 05/25/11 at 2:49pm
Edit
Tutorial: How to assign prize money
Previous versions of this question:
05/25/11 at 3:17pm
(4) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
05/25/11
3:43pmAdamGold says:What's the exact problem?
Are you sure you are using the latest version of the code?
I suggest that you try to use another code and combine the downloads with it.Previous versions of this answer: 05/25/11 at 3:35pm | 05/25/11 at 3:41pm | 05/25/11 at 3:43pm
- 05/25/11 3:58pm
Tyler Cunningham says:I have tried both his code (which is an offshoot of the original code), as well as this original code.
That second code would only notify the user that an update was available, I want it to notify AND allow the user to update which is what I'm assuming will be the result of the code I am trying to use.
- 05/25/11 3:58pm
-

Last edited:
05/26/11
7:10amSébastien | French WordpressDesigner says:maybe
'user-agent' => 'wordpress/' . $wp_version . '; ' . get_bloginfo('url')
instead of
'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
(dumb ?)
-
Last edited:
05/26/11
5:47pmDuncan O'Neill says:A simple suggestion which might help yield some answers as to why your script is 'failing';
Turn on debug. Note that this will display database errors and PHP warnings on your site;
http://codex.wordpress.org/Editing_wp-config.php
All you need to do is add the following line to /wp-config.php, or change the
value tofalse
if the define statement is already there;true
define('WP_DEBUG', true);
best, -

Last edited:
05/27/11
9:42pmChristianto says:Tyler,
Have you make it work?
What is the array of $checked_data that pass to the function? Could you show to us..
Thanks
This question has expired.
Current status of this question: Community pot
Please log in to add additional discourse to this page.
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
