Last active
December 1, 2016 08:34
-
-
Save hideokamoto/1bf2d53d336eae2002b2 to your computer and use it in GitHub Desktop.
Get Plugin-Data fromWordPress.org API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<div class="wp_org_api"></div> | |
<script> | |
//setUp Post Data | |
var actionType = 'hot_tags'; | |
var number = 10; | |
var timeout = 15; | |
//Parse Post Data | |
var postData = { | |
action: actionType, | |
timeout: timeout, | |
request: { | |
number: number | |
} | |
}; | |
$.ajax({ | |
url: 'https://api.wordpress.org/plugins/info/1.1/', | |
type:'POST', | |
data: postData, | |
dataType: 'json', | |
timeout:10000, | |
}).done(function(data) { | |
var html = '<ul>'; | |
for(key in data){ | |
html += '<li><dl>'; | |
html += '<dt>TagName</dt><dd>' + data[key].name + '</dt>'; | |
html += '<dt>Plugin Count</dt><dd>' + data[key].count + '</dt>'; | |
html += '</dl></li>'; | |
}; | |
html += '</ul>'; | |
$('.wp_org_api').append(html); | |
}).fail(function(data) { | |
var html = 'failed'; | |
$('.wp_org_api').append(html); | |
}); | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<div class="wp_org_api"></div> | |
<script> | |
//setUp Post Data | |
var actionType = 'plugin_information'; | |
var slug = 'jetpack'; | |
var fields = { | |
added:true, | |
compatibility:true, | |
downloadlink:true, | |
donate_link:true, | |
homepage:true, | |
last_updated:true, | |
rating:true, | |
require:true, | |
sections:true, | |
tags:true, | |
tested:true | |
}; | |
var timeout = 15; | |
//Parse Post Data | |
var postData = { | |
action: actionType, | |
timeout: timeout, | |
request: { | |
slug: slug, | |
fields: fields | |
} | |
}; | |
$.ajax({ | |
url: 'https://api.wordpress.org/plugins/info/1.1/', | |
type:'POST', | |
data: postData, | |
dataType: 'json', | |
timeout:10000, | |
}).done(function(data) { | |
console.log(data); | |
var html = '<dl>'; | |
html += '<dt>PluginName</dt><dd>' + data.name + '</dd>'; | |
html += '<dt>Version</dt><dd>' + data.version + '</dd>'; | |
html += '<dt>Author</dt><dd>' + data.author + '</dd>'; | |
html += '<dt>Downloaded</dt><dd>' + data.downloaded + 'DL</dd>'; | |
html += '<dt>About</dt><dd>' + data.sections.description + '</dd>'; | |
html += '</dl>'; | |
$('.wp_org_api').append(html); | |
}).fail(function(data) { | |
var html = 'failed'; | |
$('.wp_org_api').append(html); | |
}); | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<div class="wp_org_api"></div> | |
<script> | |
//setUp Post Data | |
var actionType = 'query_plugins'; | |
var searchArg = {browse:'popular'}; | |
var option ={ | |
page: 1, | |
per_page: 5 | |
}; | |
var fields = { | |
downloaded: true | |
}; | |
var timeout = 15; | |
//Parse Post Data | |
var postData = { | |
action: actionType, | |
timeout: timeout | |
}; | |
var requestData = option; | |
$.extend(requestData,searchArg); | |
requestData['fields']= fields; | |
postData['request'] = requestData; | |
$.ajax({ | |
url: 'https://api.wordpress.org/plugins/info/1.1/', | |
type:'POST', | |
data: postData, | |
dataType: 'json', | |
timeout:10000, | |
}).done(function(data) { | |
var result = data.plugins; | |
for (var i = result.length - 1; i >= 0; i--) { | |
var html = '<dl>'; | |
html += '<dt>' +result[i].name+'</dt>'; | |
html += '<dd>' +result[i].short_description+'<br/>'; | |
html += '<b>' +result[i].downloaded+'</b>Downloaded</dd>'; | |
html += '</dl>'; | |
$('.wp_org_api').append(html); | |
} | |
}).fail(function(data) { | |
var html = 'failed'; | |
$('.wp_org_api').append(html); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment