I am creating custom Divi plugin, that fetches data from MongoDB and displays it accordingly inside WordPress. Everything worked fine, until recently I found out that on some client devices and in different browsers than Chrome, it doesn’t fetch the latest data, but just displays data from the initial release of the plugin. Here is the php file, where that divi module for fetching the exams is located:
<?php
require __DIR__ . '../../../../vendor/autoload.php';
use MongoDBClient;
class TEYO_Exams extends ET_Builder_Module
{
public $slug = 'teyo_exams';
public $vb_support = 'on';
protected $module_credits = array(
'module_uri' => '',
'author' => 'Solved',
'author_uri' => '',
);
public function init()
{
$this->name = esc_html__('Exams', 'teyo-test-yourself');
add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
}
public function get_fields()
{
return array(
'content' => array(
'label' => esc_html__('Content', 'teyo-test-yourself'),
'type' => 'tiny_mce',
'option_category' => 'basic_option',
'description' => esc_html__('Content entered here will appear inside the module.', 'teyo-test-yourself'),
'toggle_slug' => 'main_content',
),
'quantity_exams' => array(
'label' => esc_html__('How Much Exams?', 'teyo-test-yourself'),
'type' => 'range',
'option_category' => 'basic_option',
'description' => esc_html__('Choose how much exams you want to display.', 'teyo-test-yourself'),
'toggle_slug' => 'main_content',
'range_settings' => array(
'min' => '0',
'max' => '10',
'step' => '1',
),
),
);
}
public function render($attrs, $content = null, $render_slug)
{
$mongodb_data = $this->get_mongodb_data();
$content = $this->display_exams($mongodb_data);
return $content;
}
public function enqueue_styles()
{
wp_enqueue_style('teyo-style-css', plugins_url('teyo-style.css', __FILE__));
}
private function get_mongodb_data()
{
$uri = "...";
$client = new Client($uri);
$db = $client->selectDatabase("testyourself");
$collection = $db->selectCollection("examtypes");
$result = $collection->find();
$data = [];
foreach ($result as $document) {
$data[] = $document;
}
return $data;
}
public function display_exams($mongodb_data)
{
$content = '<div class="exams-container">';
foreach ($mongodb_data as $exam) {
$exam_name = isset($exam->exam_name) ? $exam->exam_name : '';
$exam_information = isset($exam->information) ? $exam->information : '';
$exam_image = isset($exam->image) ? $exam->image : '';
$exam_page_url = esc_url('https://testyourself.net/exams/' . str_replace(" ", "-", $exam_name));
$content .= sprintf(
'<div class="exam">
<a href="%4$s">
<img class="exam-image" src="%1$s" alt="%2$s Image">
</a>
<h1 class="exam-title">
<a href="%4$s">%2$s</a>
</h1>
<p class="exam-information">%3$s</p>
<a class="exam-read-more" href="%4$s">%5$s</a>
</div>',
$exam_image,
$exam_name,
$exam_information,
esc_url($exam_page_url),
esc_html__('read more', 'teyo-test-yourself')
);
}
$content .= '</div>';
return $content;
}
}
new TEYO_Exams;
I tried clearing cache and that stuff, but didn’t seem to work. I noticed that adding some headers is also an option, but due to not understanding PHP very well, I decided to ask for help and possible guidance too.
Thank you all!