-
Notifications
You must be signed in to change notification settings - Fork 4
/
campaigns.php
90 lines (75 loc) · 2.76 KB
/
campaigns.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
<?php
/**
* @package Campaigns
* @version 0.2
*/
/*
Plugin Name: Campaigns
Description: Pull and lists petitions from CSL and Speakout
Author: Hiemanshu Sharma & Frances McMullin
Version: 0.2
Text Domain: campaigns
*/
if ( ! defined('CAMPAIGNS_BASE_DIR') ) {
define('CAMPAIGNS_BASE_DIR', trailingslashit(plugin_dir_path(__FILE__)));
}
register_activation_hook(__FILE__, 'campaigns_activation_hook');
register_deactivation_hook(__FILE__, 'campaigns_deactivation_hook');
add_action('admin_menu', 'campaigns_admin_menu');
add_action('campaigns_sync_event', function() {
require_once(CAMPAIGNS_BASE_DIR . 'lib/sync.php');
sync_campaigns();
});
add_action('init', function() {
require_once(CAMPAIGNS_BASE_DIR . 'lib/campaign.php');
Campaign::create_post_type();
});
function campaigns_activation_hook() {
require_once(CAMPAIGNS_BASE_DIR . 'lib/sync.php');
setup_sync();
}
function campaigns_deactivation_hook() {
require_once(CAMPAIGNS_BASE_DIR . 'lib/sync.php');
remove_sync();
}
function campaigns_admin_menu() {
add_menu_page('Campaigns Plugin Settings', 'Campaigns Settings', 'administrator', __FILE__, 'campaigns_settings_page');
add_action('admin_init', 'campaigns_admin_init');
}
function campaigns_admin_init() {
register_setting('campaigns-settings', 'speakout_url');
register_setting('campaigns-settings', 'csl_url');
register_setting('campaigns-settings', 'acf_post_type');
}
function campaigns_settings_page() {
?>
<div class="wrap">
<h1>Campaigns Settings Page</h1>
<form method="post" action="options.php">
<?php settings_fields( 'campaigns-settings' ); ?>
<?php do_settings_sections( 'campaigns-settings' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Speakout URL</th>
<td><input type='text' name='speakout_url' value="<?php echo esc_attr(get_option('speakout_url')) ?>" style="width: 60%;"></td>
</tr>
</table>
<table class="form-table">
<tr valign="top">
<th scope="row">CSL URL</th>
<td><input type='text' name='csl_url' value="<?php echo esc_attr(get_option('csl_url')) ?>" style="width: 60%;"></td>
</tr>
</table>
<table class="form-table">
<tr valign="top">
<th scope="row">ACF Post Type: (Leave blank to not use ACF)</th>
<td><input type='text' name='acf_post_type' value="<?php echo esc_attr(get_option('acf_post_type')) ?>" style="width: 60%;"></td>
</tr>
</table>
<p>Note: if using ACF, ensure your chosen post type includes fields named external_id,url,source,image,actions and max_actions.</p>
<?php submit_button(); ?>
</form>
</div>
<?php
}
?>