I was able to get the issue (POST request) from my previous forum question working with much appreciated help from Gerry @metamezzo in order to get data from wordpress page posted into a database table. Thank you so much Gerry for your help!! Now, I’m trying to get the GET request working in order to get data from database table into my wordpress page.
If someone can take a look and see where I’m going wrong, it would be very appreciated! As I mentioned in previous post, I’ve spent so much time trying to figure this out myself but almost everything that I find is just posting using a form. There seems to be very little on how to use WordPress hooks beyond the documentation, which I’ve tried in vain to figure out.
Below is the relevant code for what I’m trying to do: get the value ‘1000’ from ‘adapt’ column of database table (MLT_Exam_db) and retrieve it and display it on wordpress page <div> where id = #retrieveAdapt.
Thanks!
Will S.
// ——— HTML Widget ———
//left out top part of html document
<body>
<button id="getFromDbButton" onclick="getFromDbButtonFxn()" >Get from Database</button>
<div>Value retrieved from db: <span id="retrieveAdapt"></span></div>
</body>
// ——— functions.php ———
//left out the code for child hello theme
function register_flashcard_scripts2() {
wp_register_script('flashcard_settings2', get_stylesheet_directory_uri() . '/scripts/getFromDB.js', array('jquery'));
wp_localize_script('flashcard_settings2', 'FlashcardApp2', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'user_id' => get_current_user_id()
));
wp_enqueue_script('flashcard_settings2');
}
add_action('wp_enqueue_scripts', 'register_flashcard_scripts2');
function save_flashcard_settings2() {
global $wpdb;
$adaptValueFromDb = intval($_GET['adapt']); // TRYING TO GET 'adapt' VALUE FROM DB
$query = "SELECT adapt FROM MLT_Exam_db WHERE adapt=' .$adaptValueFromDb. '";
$result = $wpdb->query($query);
}
add_action('wp_ajax_save_flashcard_settings2', 'save_flashcard_settings2');
add_action('wp_ajax_nopriv_save_flashcard_settings2', 'save_flashcard_settings2');
// ——— getFromDB.js ———
jQuery(document).ready(function ($) {
var $flashcard_exit_btn2 = $('#getFromDbButtonFxn');
if ($flashcard_exit_btn2.length !== 0) {
$flashcard_exit_btn2.on('click', function (e) {
if(confirm('Warning:')) {
$.ajax({
type: 'GET',
dataType: 'json',
url: FlashcardApp2.ajaxurl,
aync: false,
data: {
action: 'save_flashcard_settings2', // RUN PHP SCRIPT:
adaptValueFromDb: document.querySelector('#retrieveAdapt').innerHTML,
adaptValueFromDb: $adaptValueFromDb
},
error: function(xhr, textStatus, error) {
window.location.reload();
},
success: function(data) {
window.location.reload();
}
});
e.preventDefault();
} else {
window.location.reload();
}
});
}
});
]]>I saw this on the plugin page
“Public profile
[user-meta type=public form=”Form_Name”]
(To show public profile if user_id parameter provided as GET request.)”
How do I form such a “GET request”? I am wondering if I can code my own PHP template (to pick from any page edit screen) and include some Advanced Custom Fields references (to user ID) and User Meta tags to pull through the relevant profile information on a page of my chosing.
E.g. page www/mysite/authors/a/aubrey-bent
Used my custom PHP template which pulls through an author ID, plus, Cover Photo, Profile Picture, Bio and Website URL.
Thanks.
]]>My website sends an unexplained get request for a non existing .jpg file path which results in a 404 error. This error creates a delay in the website response time which I’d like to resolve. As far as I understand the request origin is made by Elementor.
I’d appreciate your advice how to remove this problematic request.
Thanks!
]]>I have an email newsletter, in which I would like to encourage people to fill out a survey. The best option is to include the first question in the mail (“Do you like this newsletter?”), along with buttons (“Yes”, “No”) for answers. Each button has an URL behind, leading to the questionnaire, with the chosen option pre-selected.
Something like: https://groupworker.at/poll/?ps_questions[1][]=2, and question 1 is pre-set with value 2 (I tried this one, it won’t work).
Many thanks, Claus
]]>You know newsletters (sent per mail) which have the first question of a poll in the newsletter (like “yes” or “no”), each with a button, showing up in the newsletter. Behind the button, there is an URL which leads the user to the poll, where the first question has already the value clicked.
Can this be done?
… with a GET request like www.yoururl.com/pollpage/?answer[1]=yes (I tried this one, won’t work)
… with a POST request (i.e. the newsletter contains a form)?
And if yes, how do I handle the security thing that posting crap won’t mess up anything?
Many thanks, Claus
]]>Is this possible, pro version or otherwise? I am not sure how to get that URL info to the plugin.
]]>I’m using the rest API to fill an extrnal table with all the existing categories
But when I’m trying to request with parameter for example per_page=100 I’m getting only 10 rows as the defult per_page value is 10.
//$module goes for $endpoint
try {
$result = $this->wooCommerce()->get($module, $_GET);
} catch (\Exception $e) {
return new SwalController('error',$e->getMessage(),'error') and die();
}
WC verision: 3.3.3
WP verision: 4.9.5
Ex.
<!–img src=”www.somewebsite.com/web-content/uploads/date/filename” />
throws error -> GET https://www.somewebsite.com/currentpage/filename 404 (not found)
Why does it change the url from the one that is in the tag? and how can I get around this. Also why the hell does the server do that? Should that not have been tested before a server update and realized that it would break many sites?
The blog I need help with is www.lives-of-gethra.com.
]]>After installing BPS I got a stream of helpdesk tickets about users not being able to get past the serial key validation screen. I immediately knew BPS had to be the problem and switching RBM off fixed the issue.
Looking at my log I saw this:
[403 GET Request: 11/04/2017 – 4:57 PM]
BPS: 1.1
WP: 4.7.3
Event Code: BFHS – Blocked/Forbidden Hacker or Spammer
Solution: N/A – Hacker/Spammer Blocked/Forbidden
REMOTE_ADDR: 83.86.XXX.XXX
Host Name: 5356EEBE.cm-6-7d.dynamic.ziggo.nl
SERVER_PROTOCOL: HTTP/1.0
HTTP_CLIENT_IP:
HTTP_FORWARDED:
HTTP_X_FORWARDED_FOR: 83.86.XXX.XXX
HTTP_X_CLUSTER_CLIENT_IP:
REQUEST_METHOD: GET
HTTP_REFERER:
REQUEST_URI: /?wc-api=validate_serial_key&serial=XXXXX&sku=XXXX&uuid=https://www.XXXXX.nl/
QUERY_STRING:
HTTP_USER_AGENT: NSIS_Inetc (Mozilla)
So BPS is indeed blocking something. I tried to whitelist this URL in the # CUSTOM CODE BOTTOM HOTLINKING/FORBID COMMENT SPAMMERS/BLOCK BOTS/BLOCK IP/REDIRECT CODE without success. That is mainly because I am close to a NOOB in this level of coding.
I did see that most whitelisting examples have a .php address which I haven’t..
For example: RewriteCond %{REQUEST_URI} !^.*/wp-comments-post.php [NC]
I (don’t laugh) tried : RewriteCond %{REQUEST_URI} !^.*/?wc-api=validate_serial_key [NC] which did not help.
The question is how I can whitelist the above JSON POST/GET request?
Any help would be very much appreciated.
Paul