-
Notifications
You must be signed in to change notification settings - Fork 9
/
awesome-surveys.php
143 lines (131 loc) · 4.66 KB
/
awesome-surveys.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
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
<?php
/*
Plugin Name: Awesome Surveys
Plugin URI: http://www.willthewebmechanic.com/awesome-surveys
Description: Easily create surveys for your WordPress website and publish them with a simple shortcode
Version: 2.1
Author: Will Brubaker
Author URI: http://www.willthewebmechanic.com
License: GPLv3.0
Text Domain: awesome-surveys
Domain Path: /languages/
*/
/**
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* Other software packaged with this plugin is subject to other licenses:
*
* pure css (forms.css) is licensed under the Yahoo! BSD License. See css/purecss-license.txt
* The jQuery validate plugin is licensed under the MIT license. See js/jquery-validate-license.txt
* normalize.css is licensed under the MIT license see css/normalize-license.txt
* the PHP Form Builder class is licensed under the GPL v3. See LICENSE
*
*/
/*
todo:
*/
/**
* @package Awesome_Surveys
*
*/
load_plugin_textdomain( 'awesome-surveys', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
$admin_includes = array(
'awesome-surveys-admin'
);
$frontend_includes = array(
'awesome-surveys-frontend',
);
$includes = array(
'awesome-surveys',
'awesome-surveys-ajax-actions',
);
global $awesome_surveys;
foreach ( $includes as $include_file ) {
include_once( plugin_dir_path( __FILE__ ) . 'includes/class-' . $include_file . '.php' );
}
if ( ! isset( $awesome_surveys ) ) {
$awesome_surveys = new Awesome_Surveys;
}
if ( ! isset( $awesome_surveys_ajax ) ) {
$awesome_surveys_ajax = new Awesome_Surveys_Ajax;
}
if ( is_admin() ) {
foreach ( $admin_includes as $include_file ) {
include_once( plugin_dir_path( __FILE__ ) . 'includes/class-' . $include_file . '.php' );
}
new Awesome_Surveys_Admin;
} else {
foreach ( $frontend_includes as $include_file ) {
include_once( plugin_dir_path( __FILE__ ) . 'includes/class-' . $include_file . '.php' );
}
new Awesome_Surveys_Frontend;
}
if ( ! defined( 'WWM_AWESOME_SURVEYS_URL' ) ) {
define( 'WWM_AWESOME_SURVEYS_URL', plugins_url( '', __FILE__ ) );
}
if ( ! defined( 'WWM_AWESOME_SURVEYS_PATH' ) ) {
define( 'WWM_AWESOME_SURVEYS_PATH', plugin_dir_path( __FILE__ ) );
}
$awesome_surveys_nopriv_ajax_actions = array(
'answer-survey' => 'process_response',
);
$awesome_surveys_ajax_actions = array(
'add-form-element' => 'add_form_element',
'options-fields' => 'echo_options_fields',
'generate-preview' => 'generate_preview',
'wwm-as-get-json' => 'get_json',
'parse-elements' => 'parse_elements',
'update-post-content' => 'update_post_content',
'wwm_delete_responses' => 'delete_responses',
);
foreach ( $awesome_surveys_nopriv_ajax_actions as $action => $function ) {
add_action( 'wp_ajax_nopriv_' . $action, array( $awesome_surveys_ajax, $function ) );
add_action( 'wp_ajax_' . $action, array( $awesome_surveys_ajax, $function ) );
}
foreach ( $awesome_surveys_ajax_actions as $action => $function ) {
add_action( 'wp_ajax_' . $action, array( $awesome_surveys_ajax, $function ) );
}
register_activation_hook( __FILE__, 'wwm_as_plugin_activation' );
function wwm_as_plugin_activation() {
global $awesome_surveys;
$awesome_surveys->register_post_type();
flush_rewrite_rules();
$capability_type = 'survey';
$caps = array(
"edit_{$capability_type}",
"read_{$capability_type}",
"delete_{$capability_type}",
"edit_{$capability_type}s",
"edit_others_{$capability_type}s",
"publish_{$capability_type}s",
"read_private_{$capability_type}s",
"delete_{$capability_type}s",
"delete_private_{$capability_type}s",
"delete_published_{$capability_type}s",
"delete_others_{$capability_type}s",
"edit_private_{$capability_type}s",
"edit_published_{$capability_type}s",
"edit_published_{$capability_type}",
);
$role = get_role( 'administrator' );
foreach ( $caps as $cap_type ) {
$role->add_cap( $cap_type );
}
}
$filters = array(
'awesome_surveys_form_preview' => array( 10, 1 ),
);
foreach ( $filters as $filter => $args ) {
add_filter( $filter, array( $awesome_surveys, $filter ), $args[0], $args[1] );
}