-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathxml-rpc-validator.php
executable file
·102 lines (94 loc) · 2.93 KB
/
xml-rpc-validator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/*
Plugin Name: XML-RPC Validator
Version: 0.1
Description:
Author: Danilo E
Author URI:
Plugin URI:
*/
global $wp_version;
$exit_msg='XML-RPC validator requires WordPress 3.0 or newer. <a href="http://codex.wordpress.org/Upgrading_WordPress">Please update!</a>';
if (version_compare($wp_version,"3.0","<"))
{
exit ($exit_msg);
}
/**
* global constant for the plugin directory
*/
define( 'XMLRPC_VALIDATOR_PLUGIN_DIR', dirname( __FILE__ ) );
define( 'XMLRPC_VALIDATOR__PLUGIN_URL', plugins_url() . '/' . wp_basename( dirname( __FILE__ ) ) );
define( 'XMLRPC_VALIDATOR__SITE_URL', get_site_url() );
require_once 'commons.php';
function get_custom_page_template($single_template) {
$options = get_option('xml_rpc_validator');
// get our pageId
$pageId = $options['pageId'];
if (get_the_ID() === $pageId) {
if( isset($_REQUEST['action']) && $_REQUEST['action'] == 'ajax_calls' ) {
$single_template = dirname( __FILE__ ) . '/xml-rpc-validator-ajax.php';
} else {
$single_template = dirname( __FILE__ ) . '/page.php';
}
}
return $single_template;
}
add_filter( 'page_template', "get_custom_page_template" ) ;
register_activation_hook(__FILE__, 'xml_rpc_validator_activation');
register_deactivation_hook(__FILE__, 'xml_rpc_validator_deactivation');
function xml_rpc_validator_deactivation()
{
$options = get_option('xml_rpc_validator');
// get our pageId
$pageId=$options['pageId'];
// check if the actual post exists
$actual_post = get_post($pageId);
// check if the page is already created
if (!$pageId || !$actual_post || ($pageId!=$actual_post->ID))
{
//the page doesn't exists anymore
} else {
wp_update_post(array('ID' => $pageId, 'post_status' => 'draft'));
}
}
function xml_rpc_validator_activation()
{
$options = get_option('xml_rpc_validator');
// get our pageId
$pageId=$options['pageId'];
// check if the actual post exists
$actual_post=get_post($pageId);
// check if the page is already created
if (!$pageId || !$actual_post || ($pageId!=$actual_post->ID))
{
// create the page and save it's ID
$options['pageId'] = xml_rpc_validator_create_main_page();
update_option('xml_rpc_validator', $options);
} else {
//update the page status to publish. just a check.
wp_update_post(array('ID' => $pageId, 'post_status' => 'publish'));
}
}
function xml_rpc_validator_create_main_page()
{
// create post object
class mypost
{
var $post_title;
var $post_content;
var $post_status;
var $post_type; // can be 'page' or 'post'
var $comment_status; // open or closed for commenting
}
// initialize the post object
$mypost = new mypost();
// fill it with data
$mypost->post_title = 'XML-RPC Validator';
$mypost->post_content = '';
$mypost->post_status = 'publish';
$mypost->post_type = 'page';
$mypost->comment_status = 'closed';
// insert the post and return it's ID
return wp_insert_post($mypost);
}
?>