ठीक है, मुझे यह कोड मिला है जिसका उपयोग मैं अपने आवेदन के लिए समाचार थूकने के लिए कर रहा हूं। यह आज तक काम कर रहा था। मैंने इसे सिंपलर बनाने के लिए निम्न कोड में सभी तर्कों को काट दिया है। लेकिन इसे "काम करना चाहिए" क्या कोई इस कोड को ठीक करने में मदद कर सकता है जहां यह काम करता है, और सही हो गया है? मुझे पता है कि यह एक साथ हैक किया गया है, लेकिन ऐसा लगता है कि आज तक कोई समस्या नहीं है। मैंने कुछ भी अपडेट नहीं किया है, यह नहीं पता कि सौदा क्या है।वर्डप्रेस प्लगइन में wp_rewrite
Plugin Name: MyPlugin Example
Version: 1.0.1
If (! class_exists("MyPlugin"))
{
class MyPlugin
{
var $db_version = "1.0"; //not used yet
function init()
{
//Nothing as of now.
}
function activate()
{
global $wp_rewrite;
$this->flush_rewrite_rules();
}
function pushoutput($id)
{
$output->out =' The output worked!';
$this->output($output);
}
function output($output)
{
ob_start();
ob_end_clean();
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
echo json_encode($output);
//Must encode this...
}
function flush_rewrite_rules()
{
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
function createRewriteRules($rewrite)
{
global $wp_rewrite;
$new_rules = array('MyPlugin/(.+)' => 'index.php?MyPlugin=' . $wp_rewrite->preg_index(1));
if (! is_array($wp_rewrite->rules))
{
$wp_rewrite->rules = array();
}
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
return $wp_rewrite;
}
function add_query_vars($qvars)
{
$qvars[] = 'MyPlugin';
return $qvars;
}
function template_redirect_intercept()
{
global $wp_query;
if ($wp_query->get('MyPlugin'))
{
$id = $wp_query->query_vars['MyPlugin'];
$this->pushoutput($id);
exit;
}
}
}
}
If (class_exists("MyPlugin"))
{
$MyPluginCode = new MyPlugin();
}
If (isset($MyPluginCode))
{
register_activation_hook(__file__, array($MyPluginCode, 'activate'));
add_action('admin-init', array(&$MyPluginCode, 'flush_rewrite_rules'));
//add_action('init', array(&$MyPluginCode, 'init'));
add_action('generate_rewrite_rules', array(&$MyPluginCode, 'createRewriteRules'));
add_action('template_redirect', array(&$MyPluginCode, 'template_redirect_intercept'));
// add_filter('query_vars', array(&$MyPluginCode, 'add_query_vars'));
}
मुझे मूल रूप से केवल एक यूआरएल से इनपुट लेने और कुछ JSON डेटा आउटपुट करने में सक्षम होना चाहिए। – Brad