fix update option error
This commit is contained in:
parent
8696f52eae
commit
ce0559649c
@ -273,10 +273,12 @@ class PluginWonderful {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handle_action_change_memberid() {
|
function handle_action_change_memberid() {
|
||||||
update_option('plugin-wonderful-memberid', "");
|
$original_member_id = get_option('plugin-wonderful-memberid');
|
||||||
if (trim($_POST['memberid'])) {
|
$trimmed_post_memberid = trim($_POST['memberid']);
|
||||||
if (trim($_POST['memberid']) === (string)(int)$_POST['memberid']) {
|
if ($trimmed_post_memberid) {
|
||||||
update_option('plugin-wonderful-memberid', (int)$_POST['memberid']);
|
if ($trimmed_post_memberid === (string)(int)$trimmed_post_memberid) {
|
||||||
|
if ($original_member_id !== $trimmed_post_memberid) {
|
||||||
|
update_option('plugin-wonderful-memberid', (int)$trimmed_post_memberid);
|
||||||
switch ($this->_download_project_wonderful_data((int)$_POST['memberid'])) {
|
switch ($this->_download_project_wonderful_data((int)$_POST['memberid'])) {
|
||||||
case $this->message_types['DOWNLOADED']:
|
case $this->message_types['DOWNLOADED']:
|
||||||
$this->messages[] = sprintf(__('Member number changed to %s and adbox information redownloaded.', 'plugin-wonderful'), (int)$_POST['memberid']);
|
$this->messages[] = sprintf(__('Member number changed to %s and adbox information redownloaded.', 'plugin-wonderful'), (int)$_POST['memberid']);
|
||||||
@ -288,18 +290,25 @@ class PluginWonderful {
|
|||||||
$this->messages[] = __("Unable to read publisher data from Project Wonderful.", 'plugin-wonderful');
|
$this->messages[] = __("Unable to read publisher data from Project Wonderful.", 'plugin-wonderful');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->messages[] = __("Member numbers need to be numeric.", 'plugin-wonderful');
|
$this->messages[] = __("Member numbers need to be numeric.", 'plugin-wonderful');
|
||||||
$this->publisher_info = false;
|
$this->publisher_info = false;
|
||||||
|
update_option('plugin-wonderful-memberid', "");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->messages[] = __("Existing adbox information removed.", 'plugin-wonderful');
|
$this->messages[] = __("Existing adbox information removed.", 'plugin-wonderful');
|
||||||
$this->publisher_info = false;
|
$this->publisher_info = false;
|
||||||
|
update_option('plugin-wonderful-memberid', "");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (array('use-standardcode', 'enable-body-copy-embedding') as $field) {
|
foreach (array('use-standardcode', 'enable-body-copy-embedding') as $field) {
|
||||||
update_option("plugin-wonderful-${field}", isset($_POST[$field]) ? "1" : "0");
|
update_option("plugin-wonderful-${field}", isset($_POST[$field]) ? "1" : "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (count($this->messages) == 0) {
|
||||||
|
$this->messages[] = __("Options updated.", 'plugin-wonderful');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _render_adbox($adboxid, $center = false) {
|
function _render_adbox($adboxid, $center = false) {
|
||||||
|
@ -393,18 +393,20 @@ class PluginWonderfulTest extends PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
function providerTestHandleActionChangeMemberID() {
|
function providerTestHandleActionChangeMemberID() {
|
||||||
return array(
|
return array(
|
||||||
array("", false),
|
array("", "", false, true),
|
||||||
array("1.5", false),
|
array("", "1.5", false, true),
|
||||||
array("a", false),
|
array("", "a", false, true),
|
||||||
array("1", true)
|
array("", "1", true, false),
|
||||||
|
array("1", "1", false, false)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerTestHandleActionChangeMemberID
|
* @dataProvider providerTestHandleActionChangeMemberID
|
||||||
*/
|
*/
|
||||||
function testHandleActionChangeMemberID($member_id, $is_downloaded) {
|
function testHandleActionChangeMemberID($original_member_id, $member_id, $is_downloaded, $member_id_blank) {
|
||||||
$_POST['memberid'] = $member_id;
|
$_POST['memberid'] = $member_id;
|
||||||
|
update_option('plugin-wonderful-memberid', $original_member_id);
|
||||||
|
|
||||||
$pw = $this->getMock('PluginWonderful', array("_download_project_wonderful_data"));
|
$pw = $this->getMock('PluginWonderful', array("_download_project_wonderful_data"));
|
||||||
if ($is_downloaded) {
|
if ($is_downloaded) {
|
||||||
@ -414,6 +416,9 @@ class PluginWonderfulTest extends PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$pw->handle_action_change_memberid();
|
$pw->handle_action_change_memberid();
|
||||||
|
|
||||||
|
$result = get_option('plugin-wonderful-memberid');
|
||||||
|
$this->assertEquals($member_id_blank, empty($result));
|
||||||
}
|
}
|
||||||
|
|
||||||
function providerTestRenderAdbox() {
|
function providerTestRenderAdbox() {
|
||||||
|
Loading…
Reference in New Issue
Block a user