tarhe
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: XML with api to wordpressYou can add the above from the main plugin file i would also advice leaving the MINUTE_IN_SECONDS to around 20 mins so you don’t get rate limited by the API for making too many request within a short time.
You can download the updated plugin here.
Forum: Developing with WordPress
In reply to: XML with api to wordpressHow can we reset the update time to 2 min.
To reset the cache update time to 2 minutes, you need to adjust the cache expiration value in the code. Change the
cache_expiration
variable to useMINUTE_IN_SECONDS * 2
, which will set it to 2 minutes.And one more question where do i have to put the css script in to elementor
You don’t need to put any CSS into Elementor. All CSS needs to go inside the php code or added separately inside the plugin files which is usually the best practice then you can enqueue the css file from the php code.
To make it easier for you I’ve update the plugin again which you can download here to show this structure as it should be and also update the time to 2 min. please work to modify the plugin to meet any specification you’d like. The styling should look nice at least for now until you update it further to meet your needs.
- This reply was modified 2 weeks, 2 days ago by tarhe.
Forum: Developing with WordPress
In reply to: XML with api to wordpressYou can add styling and like CSS and HTML to make it look the way you want as i’ve done below. When you have the time you can also hire a developer to style the plugin to meet your site specification. You can download the modification which i added the space here.
<?php
/*
Plugin Name: ANWB Traffic Info
Description: Displays live traffic information from ANWB API using an API key.
Version: 1.2
Author: Goos
*/
function fetch_and_display_anwb_traffic_info() {
// Define the cache key and expiration time
$cache_key = 'anwb_traffic_info_cache';
$cache_expiration = HOUR_IN_SECONDS; // Cache duration (1 hour)
// Try to get the cached data
$cached_data = get_transient($cache_key);
if ($cached_data !== false) {
// Return the cached data if it exists
return $cached_data;
}
$api_url = 'https://cris-admin.anwb.nl/export-api/v1/pqfeed/latest';
$api_key = 'ADD-YOUR-API-KEY-HERE';
// Set up the request with the API Key in the headers
$response = wp_remote_get($api_url, [
'headers' => [
'x-api-key' => $api_key
]
]);
if (is_wp_error($response)) {
return 'Error retrieving traffic data: ' . $response->get_error_message();
}
$xml_data = wp_remote_retrieve_body($response);
// Check if we have data
if (empty($xml_data)) {
return 'No data received from the API.';
}
// Parse the XML response
$xml = simplexml_load_string($xml_data);
if (!$xml) {
return 'Error parsing traffic data.';
}
// Start output buffer to capture HTML content
ob_start();
echo '<div class="anwb-traffic-info">';
foreach ($xml->Sections->Section->Messages->Message as $message) {
// Check if FullText field exists and is not empty
if (!empty($message->FullText)) {
echo '<div class="traffic-message">';
// Display the road sign (road name) in a separate box
if (!empty($message->Road)) {
echo '<div class="road-sign">' . esc_html($message->Road) . '</div>';
}
// Display the main location and direction in a separate row
if (!empty($message->MainLocation)) {
echo '<div class="location-direction">' . esc_html($message->MainLocation);
if (!empty($message->From)) {
echo ' richting ' . esc_html($message->From);
}
echo '</div>';
}
// Display hectometer detail if available
if (!empty($message->Hectometer)) {
echo '<div class="hectometer">Hectometerpaal: ' . esc_html($message->Hectometer) . '</div>';
}
// Display the full traffic message text
echo '<div class="message-content">' . esc_html($message->FullText) . '</div>';
echo '</div><hr>';
}
}
echo '</div>'; // Close main container
// Get buffer contents and clean buffer
$output = ob_get_clean();
// Cache the output for future requests
set_transient($cache_key, $output, $cache_expiration);
return $output;
}
// Register a shortcode to display the data on any page/post
add_shortcode('anwb_traffic_info', 'fetch_and_display_anwb_traffic_info');Forum: Developing with WordPress
In reply to: XML with api to wordpressYes, since the XML data from the API contains a
<FullText>
field that includes the primary information you want to display, then accessing$message->FullText
is the way to go.Forum: Developing with WordPress
In reply to: XML with api to wordpressGood to know you were able to get the plugin to work to modify the plugin to display only the
FullText
field from each traffic message, you can update theforeach
loop to check specifically for that field.
You can download the new modified plugin here that will display theFullText
field only. You just need to update the previous plugin with this new version to see only theFullText
field on the response.Forum: Developing with WordPress
In reply to: XML with api to wordpressLook like the link got expired. Please download here as soon as you can before it expires again.
Forum: Developing with WordPress
In reply to: XML with api to wordpressPlease follow the steps below to use the plugin.
- Download the plugin from here – https://file.io/RfKuedub1CqT
- Install and activate the plugin from WordPress admin > plugins
- Add this shortcode
[anwb_traffic_info]
on elementor with the steps here to any of your page/post and save your page
Once you follow the above process you see the traffic data displaying on the page/post you added it to.
Forum: Developing with WordPress
In reply to: XML with api to wordpressYou can follow the steps here on the link to add a shortcode on your page/post from Elementor.
I hope that helps ??
Forum: Developing with WordPress
In reply to: XML with api to wordpressHi @meganmante
We’re unable to help further than this but for now the plugin above should work 90% to output the response from the above API when you install the plugin add the shortcode
[anwb_traffic_info]
to any page or post where you want the traffic data to appear.You’re welcome to reach out to a developer to help expand the functionality further, just wanted to demonstrate how you can make it work.
Forum: Developing with WordPress
In reply to: XML with api to wordpressHello @meganmante
To be able to get the content from the above API you’ll need to develop a custom plugin that can query the XML API – https://cris-admin.anwb.nl/export-api/v1/pqfeed/latest and the display the response via shortcode.
This can be typically done by consulting a WordPress developer. To help you get started if it’s something you’d like to do yourself you can work with the sample plugin below as a start point. The plugin is currently working when i tested it, your API key is already added to the plugin code
Save the above code as a PHP file e.g.,
anwb-traffic-info.php
inside your plugins directory. then enable theanwb-traffic-info
plugin.Once it’s enabled, add the shortcode
[anwb_traffic_info]
to any page or post where you want the traffic data to appear. Please ensure you work further on the plugin to improve the functionality before using it on a production site.<?php
/*
Plugin Name: ANWB Traffic Info
Description: Displays live traffic information from ANWB API using an API key.
Version: 1.0
Author: Your Name
*/
function fetch_and_display_anwb_traffic_info() {
// Define the cache key and expiration time
$cache_key = 'anwb_traffic_info_cache';
$cache_expiration = HOUR_IN_SECONDS; // Cache duration (1 hour)
// Try to get the cached data
$cached_data = get_transient($cache_key);
if ($cached_data !== false) {
// Return the cached data if it exists
return $cached_data;
}
$api_url = 'https://cris-admin.anwb.nl/export-api/v1/pqfeed/latest';
$api_key = 'xxxxxxxxxxxxxxxxx';
// Set up the request with the API Key in the headers
$response = wp_remote_get($api_url, [
'headers' => [
'x-api-key' => $api_key
]
]);
if (is_wp_error($response)) {
return 'Error retrieving traffic data: ' . $response->get_error_message();
}
$xml_data = wp_remote_retrieve_body($response);
// Check if we have data
if (empty($xml_data)) {
return 'No data received from the API.';
}
// Parse the XML response
$xml = simplexml_load_string($xml_data);
if (!$xml) {
return 'Error parsing traffic data.';
}
// Start output buffer to capture HTML content
ob_start();
echo '<div class="anwb-traffic-info">';
foreach ($xml->Sections->Section->Messages->Message as $message) {
echo '<div class="traffic-message">';
// Dynamically get and display each field
foreach ($message as $key => $value) {
// Skip empty fields
if (!empty($value)) {
echo '<strong>' . esc_html($key) . ':</strong> ' . esc_html($value) . '<br>';
}
}
echo '</div><hr>';
}
echo '</div>';
// Get buffer contents and clean buffer
$output = ob_get_clean();
// Cache the output for future requests
set_transient($cache_key, $output, $cache_expiration);
return $output;
}
// Register a shortcode to display the data on any page/post
add_shortcode('anwb_traffic_info', 'fetch_and_display_anwb_traffic_info');- This reply was modified 2 weeks, 2 days ago by tarhe.
- This reply was modified 2 weeks, 2 days ago by tarhe.
- This reply was modified 2 weeks, 2 days ago by tarhe.
- This reply was modified 2 weeks, 2 days ago by tarhe.
- This reply was modified 2 weeks, 2 days ago by Steven Stern (sterndata).
Forum: Fixing WordPress
In reply to: After add www in the url I cant loginHello @wakewakeup ,
This is likely due to URL mismatch between the site URL settings and the one on the database.
You might consider running a search-replace on the site to make sure “www” is consistently added to the site then clear your site cache.
Best,
Forum: Everything else WordPress
In reply to: Is it possible to expose the revision history to readers?If you choose to do it grammatically you can use the
wp_get_post_revisions() Function
on your code to get the revision history and process it the way you’d like to display it or you can display it via simple widget.Forum: Everything else WordPress
In reply to: Is it possible to expose the revision history to readers?Hello @thomasjowens
While it’s possible to display list published revision history for post or page on your website for users that are not logged in, it may require you to do it programmatically with the use of a custom code which you’ll need to develop yourself as most of the plugin you might find on the WP.org library like – Simple History might not work exactly as you want it.
Best,
Forum: Everything else WordPress
In reply to: error in search consoleHello @mohsen2677
Sorry that you’re running into this issue!
The error may indicates that there was a temporary issue with Google’s indexing function when you attempted to submit your request, I can see that the error message did not provide enough information relating to the potential issue.
You might consider taking a look at this thread – Google Search Console help forum thread – Oops! Something went wrong We had a problem and also if your website is behind Cloudflare firewall you might need to remove the proxy temporarily then try again or I would suggest you contact Google support for help.
Best,
- This reply was modified 1 month, 3 weeks ago by tarhe.
Forum: Developing with WordPress
In reply to: Selling my own plugin, but what about GDPR and T&C?There are some few options you can consider if you don’t want to spend money or much money writing up the GDPR. You can use Legal Text Generators tool online like https://termly.io/ – They can handle minimal compliance for zero cost but you might need to pay a small fee for something comprehensive, many plugin developers use generated templates which are GDPR compliant.
One platform that can sale your plugin and handle sales, licensing, compliance etc which you can try is Freemius.
I hope this helps.
Best,