-
Notifications
You must be signed in to change notification settings - Fork 27
/
wp-libre-form.php
132 lines (107 loc) · 3.84 KB
/
wp-libre-form.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
<?php
/**
* Plugin name: WP Libre Form
* Plugin URI: https://github.com/hencca/wp-libre-form
* Description: A minimal HTML form builder for WordPress; made for developers
* Version: 1.5.0.3
* Author: @anttiviljami
* Author URI: https://github.com/anttiviljami/
* License: GPLv3
* License URI: https://www.gnu.org/licenses/gpl.html
* Text Domain: wp-libre-form
*
* This plugin is a simple html form maker for WordPress.
*/
/** Copyright 2017 Viljami Kuosmanen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 3, as
published by the Free Software Foundation.
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
*/
if ( ! class_exists( 'WP_Libre_Form' ) ) :
define( 'WPLF_VERSION', '1.5.0.1' );
class WP_Libre_Form {
public static $instance;
public $plugins;
public static function init() {
if ( is_null( self::$instance ) ) {
self::$instance = new WP_Libre_Form();
}
return self::$instance;
}
private function __construct() {
require_once 'classes/class-cpt-wplf-form.php';
require_once 'classes/class-cpt-wplf-submission.php';
require_once 'classes/class-wplf-dynamic-values.php';
require_once 'classes/class-wplf-plugins.php';
require_once 'inc/wplf-ajax.php';
// default functionality
require_once 'inc/wplf-form-actions.php';
require_once 'inc/wplf-form-validation.php';
// init our plugin classes
CPT_WPLF_Form::init();
CPT_WPLF_Submission::init();
WPLF_Dynamic_Values::init();
$this->plugins = WPLF_Plugins::init();
add_action( 'after_setup_theme', array( $this, 'init_polylang_support' ) );
add_action( 'plugins_loaded', array( $this, 'load_our_textdomain' ) );
add_action( 'rest_api_init', array( $this, 'register_rest_routes' ) );
// flush rewrites on activation since we have slugs for our cpts
register_activation_hook( __FILE__, array( 'WP_Libre_Form', 'flush_rewrites' ) );
register_deactivation_hook( __FILE__, 'flush_rewrite_rules' );
}
/**
* Plugin activation hook
*/
public static function flush_rewrites() {
CPT_WPLF_Form::register_cpt();
CPT_WPLF_Submission::register_cpt();
flush_rewrite_rules();
}
/**
* Load our plugin textdomain
*/
public static function load_our_textdomain() {
$loaded = load_plugin_textdomain( 'wp-libre-form', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
if ( ! $loaded ) {
$loaded = load_muplugin_textdomain( 'wp-libre-form', dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
}
}
public function register_rest_routes() {
register_rest_route( 'wplf/v1', 'submit', [
'methods' => 'POST',
'callback' => 'wplf_ajax_submit_handler', // admin-ajax handler, works but...
// The REST API handbook discourages from using $_POST, and instead use $request->get_params()
]);
}
/**
* Enable Polylang support
*/
public function init_polylang_support() {
if ( apply_filters( 'wplf_load_polylang', true ) && class_exists( 'Polylang' ) ) {
require_once 'classes/class-wplf-polylang.php';
WPLF_Polylang::init();
}
}
/**
* Public version of wplf_form
*/
public function wplf_form( $id, $content = '', $xclass = '' ) {
return CPT_WPLF_Form::wplf_form( $id, $content, $xclass );
}
}
endif;
/**
* Expose a global function for less awkward usage
*/
function wplf() {
// init the plugin
return WP_Libre_Form::init();
}
wplf();