本文整理汇总了PHP中WooThemes_Sensei_Utils::get_user_data方法的典型用法代码示例。如果您正苦于以下问题:PHP WooThemes_Sensei_Utils::get_user_data方法的具体用法?PHP WooThemes_Sensei_Utils::get_user_data怎么用?PHP WooThemes_Sensei_Utils::get_user_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WooThemes_Sensei_Utils
的用法示例。
在下文中一共展示了WooThemes_Sensei_Utils::get_user_data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_user_answers_feedback
/**
* Get the user's answers feedback.
*
* This function returns the feedback submitted by the teacher/admin
* during grading. Grading occurs manually or automatically.
*
* @since 1.7.5
* @access public
*
* @param int $lesson_id
* @param int $user_id
*
* @return false | array $answers_feedback{
* $type int $question_id
* $type string $question_feedback
* }
*/
public function get_user_answers_feedback($lesson_id, $user_id = 0)
{
$answers_feedback = array();
// get the user_id if none was passed in use the current logged in user
if (!intval($user_id) > 0) {
$user_id = get_current_user_id();
}
if (!intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id) || !intval($user_id) > 0 || !get_userdata($user_id)) {
return false;
}
// first check the transient to save a few split seconds
$transient_key = 'sensei_answers_feedback_' . $user_id . '_' . $lesson_id;
$encoded_feedback = get_transient($transient_key);
// get the data if nothing was stored in the transient
if (empty($encoded_feedback) || !$encoded_feedback) {
$encoded_feedback = WooThemes_Sensei_Utils::get_user_data('quiz_answers_feedback', $lesson_id, $user_id);
//set the transient with the new valid data for faster retrieval in future
set_transient($transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS);
}
// end if transient check
// if there is no data for this user
if (!is_array($encoded_feedback)) {
return false;
}
foreach ($encoded_feedback as $question_id => $feedback) {
$answers_feedback[$question_id] = base64_decode($feedback);
}
return $answers_feedback;
}
示例2: testDeleteUserData
/**
* This tests Woothemes_Sensei_Utils::delete_user_data
*/
public function testDeleteUserData()
{
// does this function add_user_data exist?
$this->assertTrue(method_exists('WooThemes_Sensei_Utils', 'delete_user_data'), 'The utils class function `delete_user_data` does not exist ');
// does it return false for invalid the parameters?
$invalid_data_message = 'This function does not check false data correctly';
$this->assertFalse(WooThemes_Sensei_Utils::delete_user_data('', '', ''), $invalid_data_message . ": '','','' ");
$this->assertFalse(WooThemes_Sensei_Utils::delete_user_data(' ', ' ', ' '), $invalid_data_message . ": ' ', ' ', ' ' ");
$this->assertFalse(WooThemes_Sensei_Utils::delete_user_data(-1, -2, -3), $invalid_data_message . ": -1,-2, -3 ");
$this->assertFalse(WooThemes_Sensei_Utils::delete_user_data('key', 500, 5000), $invalid_data_message . ": 500, 'key', 5000");
// setup the data for the next assertions
$test_user_id = wp_create_user('testDeleteUserData', 'testDeleteUserData', 'testDeleteUserData@test.com');
$test_array = array(1, 2, 3, 4);
$test_lesson_id = $this->factory->post->create(array('post_type' => "lesson"));
$test_data_key = 'test_key';
//does this function return false when there is no lesson status?
$this->assertFalse(WooThemes_Sensei_Utils::get_user_data($test_data_key, $test_lesson_id, $test_user_id), 'This function should return false when the status has not be set for the given post type');
//setup assertion data
WooThemes_Sensei_Utils::update_user_data($test_data_key, $test_lesson_id, $test_array, $test_user_id);
$deleted = WooThemes_Sensei_Utils::delete_user_data($test_data_key, $test_lesson_id, $test_user_id);
$retrieved_value = WooThemes_Sensei_Utils::get_user_data($test_data_key, $test_lesson_id, $test_user_id);
// doest the function successfully delete existing Sensei user data ?
$this->assertTrue($deleted, 'The user data should have been deleted, but was not');
$this->assertEmpty($retrieved_value, 'After deleting the user data should return false');
}