-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventRoundUp.php
More file actions
178 lines (129 loc) · 5.63 KB
/
EventRoundUp.php
File metadata and controls
178 lines (129 loc) · 5.63 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/*
Plugin Name: Event Calendar RoundUp
Plugin URI: http://v2swebdesign/projects/eventroundup
Description: Creates a post from your google calendar feed
Version: 0.1
Author: James Strocel
Author URI: http://www.v2swebdesign.com
*/
/* Copyright 2012 James Strocel (email : James@v2swebdesign.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
add_action('admin_menu', 'evcru_create_menu');
function evcru_create_menu() {
//create new top-level menu
add_options_page('Event Calendar Round Up', 'Event Calendar Round Up', 'manage_options', __FILE__, 'evcru_settings_page');
add_filter( "plugin_action_links", "evcru_settings_link", 10, 2 );
//call register settings function
add_action( 'admin_init', 'evcru_register_settings' );
}
#register_activation_hook(__FILE__, 'my_activation');
add_action('wp', 'my_activation');
add_action('my_hourly_event', 'do_this_hourly');
add_filter( 'cron_schedules', 'cron_add_seconds' );
function cron_add_seconds( $schedules ) {
// Adds once weekly to the existing schedules.
$schedules['seconds'] = array(
'interval' => 30,
'display' => __( 'seconds' )
);
return $schedules;
}
function my_activation() {
$activated = get_option('evcru_activated');
if ($activated == true){
if ( !wp_next_scheduled( 'my_hourly_event' ) ) {
wp_schedule_event( current_time( 'timestamp' ), 'seconds', 'my_hourly_event');
}
}
}
register_deactivation_hook(__FILE__, 'my_deactivation');
function my_deactivation() {
wp_clear_scheduled_hook('my_hourly_event');
}
function do_this_hourly() {
// do something every hour
// Create post object
$my_post = array(
'post_title' => 'My post',
'post_content' => 'This is my post.'.current_time( 'timestamp' ),
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(8,39)
);
// Insert the post into the database
wp_insert_post( $my_post );
}
//add settings link to plugins list
function evcru_settings_link($links, $file) {
static $this_plugin;
if (!$this_plugin) $this_plugin = plugin_basename(__FILE__);
if ($file == $this_plugin){
$settings_link = '<a href="options-general.php?page=EventRoundUp/EventRoundUp.php">'.__("Settings", "EventRoundUp").'</a>';
array_unshift($links, $settings_link);
}
return $links;
}
function evcru_register_settings() {
//register our settings
register_setting( 'EventRoundUp', 'evcru_calendar_url' );
register_setting( 'EventRoundUp', 'evcru_interval' );
register_setting( 'EventRoundUp', 'evcru_day' );
register_setting( 'EventRoundUp', 'evcru_activated' );
}
function evcru_admin_css() { ?>
<style type="text/css" >
.evcru_social_list {padding-top:15px;}
.evcru_social_list .setting {display:block;padding:1em;}
.evcru_social_list .setting p.label_title {font-size:12px;font-weight:bold;display:block;margin-bottom:5px;}
.evcru_social_list .setting label.no_bold {font-weight:normal;}
.evcru_social_list .setting label span.slim {width:200px;float:left;display:block;margin: 1px;padding: 3px;}
.evcru_social_list .setting p.desc {font-size:10px;font-style:italic;text-indent:10px; text-align:left;}
</style>
<?php }
add_action('admin_head', 'evcru_admin_css');
//html for settings form
function evcru_settings_page() { ?>
<?php
if ( isset($_POST['submit']) ) {
if ( isset( $_POST['evcru_activated'] ) )
update_option( 'evcru_activated', 'true' );
else
update_option( 'evcru_activated', 'false' );
}?>
<div class="wrap evcru_social_list">
<h2>Event Calendar Round Up</h2>
<form method="post" action="options.php">
<?php settings_fields( 'EventRoundUp' ); ?>
<div class="setting">
<p class="label_title">Where's the Calendar?'</p>
<p><label class="no_bold" for="evcru_calendar_url"><span class="slim">Calendar URL</span>
<input name="evcru_calendar_url" type="text" id="evcru_facebook" value="<?php form_option('evcru_calendar_url'); ?>" /></label></p>
<p class="label_title">How Often?</p>
<p><label class="no_bold" for="evcru_interval"><span class="slim">Interval</span>
<input name="evcru_interval" type="text" id="evcru_interval" value="<?php form_option('evcru_interval'); ?>" /></label></p>
<p class="label_title">What Day?</p>
<p><label class="no_bold" for="evcru_day"><span class="slim">Day of Post</span>
<input name="evcru_day" type="text" id="evcru_day" value="<?php form_option('evcru_day'); ?>" /></label></p>
<p class="label_title">Activate?</p>
<p><label class="no_bold" for="evcru_activated"><span class="slim">Activated?</span>
<input name="evcru_activated" type="checkbox" value="1" <?php checked( '1', get_option( 'evcru_activated' ) ); ?> />
<p class="setting">
<input type="submit" class="button-primary" value="Save Settings" />
</p>
</div>
</form>
</div>
<?php }
?>