Skip to content

Commit 8eb709b

Browse files
author
Chris Gårdenberg
committed
Adding option to block customers to edit their info (Person name and email)
Enabling auto-update for all users of the plugin.
1 parent 42ae4a9 commit 8eb709b

9 files changed

Lines changed: 184 additions & 12 deletions

File tree

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
.official.plugin.php
2-
includes/auto_update.php
31
.idea
42
.vscode

.official.plugin.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
if(!function_exists('edu_isOfficialPlugin'))
3+
{
4+
function edu_isOfficialPlugin()
5+
{
6+
if(isset($_REQUEST['checkOfficialPlugin']))
7+
{
8+
echo "<script>(function() { alert(new Date() + \"\\nI'm official!\"); })();</script>";
9+
}
10+
}
11+
}
12+
13+
if(!function_exists('edu_check_for_updates'))
14+
{
15+
function edu_check_for_updates()
16+
{
17+
require_once("includes/auto_update.php");
18+
$current_version = eduadmin_get_plugin_version();
19+
$slug = "eduadmin/eduadmin.php";
20+
new wp_auto_update($current_version, $slug);
21+
}
22+
}
23+
add_action('admin_init', 'edu_check_for_updates');
24+
add_action('wp_footer', 'edu_isOfficialPlugin');

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Change log
22

3-
## [Unreleased]
3+
## [0.10.2]
44
### Added
5+
- Added option to block editing user fields of they are logged in
56

67
## [0.10.1]
78
### Added
@@ -240,8 +241,9 @@
240241
### Added
241242
- Added inquiry support in course
242243

243-
[Unreleased]: https://github.com/MultinetInteractive/EduAdmin-WordPress/compare/v0.10.1...HEAD
244-
[0.10.1]: https://github.com/MultinetInteractive/EduAdmin-WordPress/compare/v0.10.1...v0.10.1
244+
[Unreleased]: https://github.com/MultinetInteractive/EduAdmin-WordPress/compare/v0.10.2...HEAD
245+
[0.10.2]: https://github.com/MultinetInteractive/EduAdmin-WordPress/compare/v0.10.1...v0.10.2
246+
[0.10.1]: https://github.com/MultinetInteractive/EduAdmin-WordPress/compare/v0.10.0...v0.10.1
245247
[0.10.0]: https://github.com/MultinetInteractive/EduAdmin-WordPress/compare/v0.9.18...v0.10.0
246248
[0.9.19]: https://github.com/MultinetInteractive/EduAdmin-WordPress/compare/v0.9.18...v0.9.19
247249
[0.9.18]: https://github.com/MultinetInteractive/EduAdmin-WordPress/compare/v0.9.17.16...v0.9.18

content/template/bookingTemplate/contactView.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1+
<?php
2+
$blockEditIfLoggedIn = get_option('eduadmin-blockEditIfLoggedIn', true);
3+
$__block = ($blockEditIfLoggedIn && $contact->CustomerContactID != 0);
4+
?>
15
<div class="contactView">
26
<h2><?php edu_e("Contact information"); ?></h2>
37
<label>
48
<div class="inputLabel">
59
<?php edu_e("Contact name"); ?>
610
</div>
711
<div class="inputHolder">
8-
<input type="text" style="width: 48%; display: inline;" required onchange="eduBookingView.ContactAsParticipant();" id="edu-contactFirstName" name="contactFirstName" placeholder="<?php edu_e("Contact first name"); ?>" value="<?php echo @esc_attr(explode(' ', $contact->ContactName)[0]); ?>" />
9-
<input type="text" style="width: 48%; display: inline;" required onchange="eduBookingView.ContactAsParticipant();" id="edu-contactLastName" name="contactLastName" placeholder="<?php edu_e("Contact surname"); ?>" value="<?php echo @esc_attr(str_replace(explode(' ', $contact->ContactName)[0], '', $contact->ContactName)); ?>" />
12+
<input type="text" style="width: 48%; display: inline;"<?php echo ($__block ? " readonly" : ""); ?> required onchange="eduBookingView.ContactAsParticipant();" id="edu-contactFirstName" name="contactFirstName" placeholder="<?php edu_e("Contact first name"); ?>" value="<?php echo @esc_attr(explode(' ', $contact->ContactName)[0]); ?>" />
13+
<input type="text" style="width: 48%; display: inline;"<?php echo ($__block ? " readonly" : ""); ?> required onchange="eduBookingView.ContactAsParticipant();" id="edu-contactLastName" name="contactLastName" placeholder="<?php edu_e("Contact surname"); ?>" value="<?php echo @esc_attr(str_replace(explode(' ', $contact->ContactName)[0], '', $contact->ContactName)); ?>" />
1014
</div>
1115
</label>
1216
<label>
1317
<div class="inputLabel">
1418
<?php edu_e("E-mail address"); ?>
1519
</div>
1620
<div class="inputHolder">
17-
<input type="email" id="edu-contactEmail" required name="contactEmail" onchange="eduBookingView.ContactAsParticipant();" placeholder="<?php edu_e("E-mail address"); ?>" value="<?php echo @esc_attr($contact->Email); ?>" />
21+
<input type="email" id="edu-contactEmail" required name="contactEmail"<?php echo ($__block ? " readonly" : ""); ?> onchange="eduBookingView.ContactAsParticipant();" placeholder="<?php edu_e("E-mail address"); ?>" value="<?php echo @esc_attr($contact->Email); ?>" />
1822
</div>
1923
</label>
2024
<label>

content/template/bookingTemplate/singlePersonBooking.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1+
<?php
2+
$blockEditIfLoggedIn = get_option('eduadmin-blockEditIfLoggedIn', true);
3+
$__block = ($blockEditIfLoggedIn && $contact->CustomerContactID != 0);
4+
?>
15
<div class="contactView">
26
<h2><?php edu_e("Contact information"); ?></h2>
37
<label>
48
<div class="inputLabel">
59
<?php edu_e("Contact name"); ?>
610
</div>
711
<div class="inputHolder">
8-
<input type="text" style="width: 48%; display: inline;" required onchange="eduBookingView.ContactAsParticipant();" id="edu-contactFirstName" name="contactFirstName" placeholder="<?php edu_e("Contact first name"); ?>" value="<?php echo @esc_attr(explode(' ', $contact->ContactName)[0]); ?>" />
9-
<input type="text" style="width: 48%; display: inline;" required onchange="eduBookingView.ContactAsParticipant();" id="edu-contactLastName" name="contactLastName" placeholder="<?php edu_e("Contact surname"); ?>" value="<?php echo @esc_attr(str_replace(explode(' ', $contact->ContactName)[0], '', $contact->ContactName)); ?>" />
12+
<input type="text" style="width: 48%; display: inline;"<?php echo ($__block ? " readonly" : ""); ?> required onchange="eduBookingView.ContactAsParticipant();" id="edu-contactFirstName" name="contactFirstName" placeholder="<?php edu_e("Contact first name"); ?>" value="<?php echo @esc_attr(explode(' ', $contact->ContactName)[0]); ?>" />
13+
<input type="text" style="width: 48%; display: inline;"<?php echo ($__block ? " readonly" : ""); ?> required onchange="eduBookingView.ContactAsParticipant();" id="edu-contactLastName" name="contactLastName" placeholder="<?php edu_e("Contact surname"); ?>" value="<?php echo @esc_attr(str_replace(explode(' ', $contact->ContactName)[0], '', $contact->ContactName)); ?>" />
1014
</div>
1115
</label>
1216
<label>
1317
<div class="inputLabel">
1418
<?php edu_e("E-mail address"); ?>
1519
</div>
1620
<div class="inputHolder">
17-
<input type="email" id="edu-contactEmail" required name="contactEmail" onchange="eduBookingView.ContactAsParticipant();" placeholder="<?php edu_e("E-mail address"); ?>" value="<?php echo @esc_attr($contact->Email); ?>" />
21+
<input type="email" id="edu-contactEmail" required name="contactEmail"<?php echo ($__block ? " readonly" : ""); ?> onchange="eduBookingView.ContactAsParticipant();" placeholder="<?php edu_e("E-mail address"); ?>" value="<?php echo @esc_attr($contact->Email); ?>" />
1822
</div>
1923
</label>
2024
<label>

eduadmin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Plugin URI: http://www.eduadmin.se
77
* Description: EduAdmin plugin to allow visitors to book courses at your website
88
* Tags: booking, participants, courses, events, eduadmin, lega online
9-
* Version: 0.10.1
9+
* Version: 0.10.2
1010
* Requires at least: 3.0
1111
* Tested up to: 4.7.3
1212
* Author: Chris Gårdenberg, MultiNet Interactive AB

includes/_options.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ function eduadmin_settings_init()
140140
register_setting('eduadmin-booking', 'eduadmin-noInvoiceFreeEvents');
141141
register_setting('eduadmin-booking', 'eduadmin-validateCivicRegNo');
142142
register_setting('eduadmin-booking', 'eduadmin-useLimitedDiscount');
143+
register_setting('eduadmin-booking', 'eduadmin-blockEditIfLoggedIn');
143144

144145
/* Phrase settings */
145146
register_setting('eduadmin-phrases', 'eduadmin-phrases');

includes/auto_update.php

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
class wp_auto_update
3+
{
4+
/**
5+
* The plugin current version
6+
* @var string
7+
*/
8+
public $current_version;
9+
10+
/**
11+
* The plugin remote update path
12+
* @var string
13+
*/
14+
public $update_path;
15+
16+
/**
17+
* Plugin Slug (plugin_directory/plugin_file.php)
18+
* @var string
19+
*/
20+
public $plugin_slug;
21+
22+
/**
23+
* Plugin name (plugin_file)
24+
* @var string
25+
*/
26+
public $slug;
27+
28+
/**
29+
* Initialize a new instance of the WordPress Auto-Update class
30+
* @param string $current_version
31+
* @param string $plugin_slug
32+
*/
33+
function __construct($current_version, $plugin_slug)
34+
{
35+
// Set the class public variables
36+
$this->current_version = $current_version;
37+
$this->update_path = 'http://ws10.multinet.se/edu-plugin/update.php?oldv=' . $this->current_version;
38+
$this->plugin_slug = $plugin_slug;
39+
list ($t1, $t2) = explode('/', $plugin_slug);
40+
$this->slug = str_replace('.php', '', $t2);
41+
42+
// define the alternative API for updating checking
43+
add_filter('pre_set_site_transient_update_plugins', array(&$this, 'check_update'));
44+
45+
// Define the alternative response for information checking
46+
add_filter('plugins_api', array(&$this, 'check_info'), 10, 3);
47+
}
48+
49+
/**
50+
* Add our self-hosted autoupdate plugin to the filter transient
51+
*
52+
* @param $transient
53+
* @return object $ transient
54+
*/
55+
public function check_update($transient)
56+
{
57+
if (empty($transient->checked)) {
58+
return $transient;
59+
}
60+
61+
// Get the remote version
62+
$remote_version = $this->getRemote_version();
63+
64+
// If a newer version is available, add the update
65+
if (version_compare($this->current_version, $remote_version, '<')) {
66+
$obj = new stdClass();
67+
$obj->slug = $this->slug;
68+
$obj->new_version = $remote_version;
69+
$obj->url = $this->update_path;
70+
$obj->package = $this->update_path;
71+
$transient->response[$this->plugin_slug] = $obj;
72+
}
73+
return $transient;
74+
}
75+
76+
/**
77+
* Add our self-hosted description to the filter
78+
*
79+
* @param boolean $false
80+
* @param array $action
81+
* @param object $arg
82+
* @return bool|object
83+
*/
84+
public function check_info($false, $action, $arg)
85+
{
86+
if ($arg->slug === $this->slug) {
87+
$information = $this->getRemote_information();
88+
return $information;
89+
}
90+
return false;
91+
}
92+
93+
/**
94+
* Return the remote version
95+
* @return string $remote_version
96+
*/
97+
public function getRemote_version()
98+
{
99+
$request = wp_remote_post($this->update_path, array('body' => array('action' => 'version')));
100+
if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200) {
101+
return $request['body'];
102+
}
103+
return false;
104+
}
105+
106+
/**
107+
* Get information about the remote version
108+
* @return bool|object
109+
*/
110+
public function getRemote_information()
111+
{
112+
$request = wp_remote_post($this->update_path, array('body' => array('action' => 'info')));
113+
if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200) {
114+
return unserialize($request['body']);
115+
}
116+
return false;
117+
}
118+
119+
/**
120+
* Return the status of the plugin licensing
121+
* @return boolean $remote_license
122+
*/
123+
public function getRemote_license()
124+
{
125+
$request = wp_remote_post($this->update_path, array('body' => array('action' => 'license')));
126+
if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200) {
127+
return $request['body'];
128+
}
129+
return false;
130+
}
131+
}

includes/bookingSettings.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ function edu_writeOptions($g, $array, $depth, $selectedOption)
101101
</label>
102102
<br />
103103
<?php
104+
$blockEditIfLoggedIn = get_option('eduadmin-blockEditIfLoggedIn', true);
105+
?>
106+
<label>
107+
<input type="checkbox" name="eduadmin-blockEditIfLoggedIn"<?php echo ($blockEditIfLoggedIn ? " checked=\"checked\"" : ""); ?> value="true" />
108+
<?php _e("Block ability to edit login information if logged in", "eduadmin"); ?>
109+
</label>
110+
<br />
111+
<?php
104112
$allowDiscountCode = get_option('eduadmin-allowDiscountCode', false);
105113
?>
106114
<label>

0 commit comments

Comments
 (0)