This repository has been archived by the owner on Jan 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
/
repeater.php
119 lines (104 loc) · 3.74 KB
/
repeater.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
<?php
/**
* Plugin Name: Gravity Forms Repeater Add-On
* Plugin URI: https://wordpress.org/plugins/repeater-add-on-for-gravity-forms/
* Description: A Gravity Forms add-on that allows specified groups of fields to be repeated by the user.
* Version: 1.1.0-dev14
* Author: Kodie Grantham
* Author URI: http://kodieg.com
* GitHub Plugin URI: https://github.com/kodie/gravityforms-repeater
* GitHub Branch: development
* Text Domain: gravityforms-repeater
* Domain Path: languages
*/
define('GF_REPEATER_VERSION', '1.1.0-dev14');
define('GF_REPEATER_PATH', basename(__DIR__).'/'.basename(__FILE__));
if( !defined('GF_REPEATER_DEBUG') ){
define('GF_REPEATER_DEBUG', WP_DEBUG);
}
add_filter('plugin_row_meta', 'gfrepeater_row_meta', 10, 2);
function gfrepeater_row_meta($links, $file) {
if (strpos($file, basename(__FILE__)) !== false) {
$new_links = array(
'<a href="http://kodieg.com/projects/gravity-forms-repeater-add-on" target="_blank">Visit plugin site</a>',
'<a href="https://github.com/kodie/gravityforms-repeater" target="_blank">GitHub</a>'
);
$links = array_merge($links, $new_links);
}
return $links;
}
if (class_exists("GFForms")) {
GFForms::include_addon_framework();
class GFRepeater extends GFAddOn {
protected $_version = GF_REPEATER_VERSION;
protected $_min_gravityforms_version = "1.9";
protected $_slug = "gravityformsrepeater";
protected $_path = GF_REPEATER_PATH;
protected $_full_path = __FILE__;
protected $_title = "Gravity Forms Repeater Add-On";
protected $_short_title = "Repeater Add-On";
public function scripts() {
$scripts = array(
array(
"handle" => "gf_repeater_js_admin",
"src" => $this->get_base_url() . "/js/gf-repeater-admin.js",
"version" => $this->_version,
"deps" => array('jquery'),
"in_footer" => false,
"callback" => array($this, 'localize_scripts'),
"strings" => array('page' => rgget('page'), 'debug' => GF_REPEATER_DEBUG),
"enqueue" => array(
array(
"admin_page" => array('form_editor', 'entry_view', 'entry_detail')
)
)
)
);
return array_merge(parent::scripts(), $scripts);
}
public function init_admin() {
parent::init_admin();
GF_Field_Repeater::init_admin();
GF_Field_Repeater_End::init_admin();
}
public function init_frontend() {
parent::init_frontend();
GF_Field_Repeater::init_frontend();
}
public function upgrade($previous_version) {
if (version_compare($previous_version, '1.0.5') == -1) {
$forms = GFAPI::get_forms(true);
foreach ($forms as $form) {
$entries = GFAPI::get_entries($form['id']);
$fields = GFAPI::get_fields_by_type($form, 'repeater');
foreach ($entries as $entry) {
foreach ($fields as $field) {
if (array_key_exists($field['id'], $entry)) {
$dataArray = GFFormsModel::unserialize($entry[$field['id']]);
$dataUpdated = false;
if (!is_array($dataArray)) { continue; }
foreach ($dataArray as $repeaterChildId=>$repeaterChild) {
foreach ($repeaterChild as $repeatedFieldId=>$repeatedField) {
if (!is_array($repeatedField)) {
if ($repeatedField !== '[gfRepeater-section]') {
$dataUpdated = true;
$dataArray[$repeaterChildId][$repeatedFieldId] = Array($repeatedField);
}
} elseif (reset($repeatedField) == '[gfRepeater-section]') {
$dataUpdated = true;
$dataArray[$repeaterChildId][$repeatedFieldId] = reset($repeatedField);
}
}
}
if ($dataUpdated) { GFAPI::update_entry_field($entry['id'], $field['id'], maybe_serialize($dataArray)); }
}
}
}
}
}
}
}
new GFRepeater();
require_once('class-gf-field-repeater.php');
require_once('class-gf-field-repeater-end.php');
}