The plugin that i built essentially has a login page, which once validated, takes you to a screen with a couple of options. If you choose one of the options (button press), it redirects the user to another WP page which only contains a shortcode which runs the PHP that i’d written years ago.
This is the code of that button:
<button id="statsBtn" name="submit" class="submit-btn" type="submit" onclick="location.href=document.location.href='/mypage-setup'" value="submit">Enter App</button>
The WP page is entitled “mypage-setup” and it only contains a shortcode which contains PHP and external JS code. Last night (again, no code changes), the button press only displays a blank page. I’ve debugged and the button press does not execute the shortcode at all (when i put debug messages in the PHP file containing the shortcode, those messages DO display in the error log). I’ve removed the shortcode from the page entirely and replaced it with a simple paragraph, still no dice. Perhaps something to do with the onclick redirect? However, when i’m in the WP page editor for the page containing the shortcode and i choose ‘View Page’, the intended plugin code displays properly.
When i scrape the above ‘View Page’ URL and put it in another browser tab or different browser entirely, it displays as I would expect. However, if i attempt to access the page itself thru the plugin, it displays a blank page (no plugin output and debugging shows it never executes any plugin code), however the URL is the exact same URL as when i choose ‘View Page’.
I’m unsure what to check or try at this point. The intended shortcode doesn’t execute (hence no errors) and i’m not getting any Javascript console errors either. All of this code was used this past Sunday with no issues and it works 100% as it did on my local server. Frankly, i’m a bit baffled. Can anyone point out some possible candidates of things to try?
]]><a href="#" onclick="if(window.__lxG__consent__!==undefined&&window.__lxG__consent__.getState()!==null){window.__lxG__consent__.showConsent()} else {alert('This function only for users from European Economic Area (EEA)')}; return false">Change privacy settings</a>
but it doesn’t work, i looked at source code and the HTML is rendered without onclick so only the link to #.
Is this a bug?
Another question: if i would use the button to show, how can i implement the link above?
Thanks in advice.
]]>This is my code in save.js that should be in preview part – not in editor:
export default function save({attributes}) {
const blockProps = useBlockProps.save();
const onBlockClick = () => {
document.getElementsByClassName(blockClass)[0].classList.add("blue");
console.log("clicked");
};
return (
<div { ...blockProps } className={"exe-more-info-button "+attributes.className} onClick={onBlockClick}>
<span className="wp-block-button__link wp-element-button">
<RichText.Content
tagName="p"
value={ attributes.content }
/>
</span>
</div>
);
}
It should put another class to class list of specified element, and log something to console (for this specific debug reason), but it doesn’t.
What I was able to find online is that the function that onClick refers to in jsx must be in const <name> = () => {}
format, but it does not work with it too.
The thing is that it behaves like there wasn’t any onClick handler – no console output, no error, nothing… Even in Dev Tools in browser there is no onclick in html in that particular div.
What am I doing wrong, and how can I define onClick handler correctly?
WP 6.2.2
PHP 8.2.4
Thanks in advance.
]]>I was thinking if it’s somehow possible to add scroll to id / custom onclick event on collapse button of TP expand block. My goal is to scroll above the top of the block I want to collapse.
Thank you!
]]>The event triggers on touch, not on tap. For example: When scrolling the page, if you accidentally touch on the popup button during a thumb scroll action, the popup will be triggered. The user in this case isn’t actually clicking the button and this isn’t how the standard touch event works for mobile.
I have the OnClick event selected as the trigger in the back end.
Is it supposed to behave this way?
]]>–
<script>
jQuery(document).on(‘change’, ‘[id*=”fieldname391_”]’, function(){
alert(this.value);
});
</script>`
—
thanks very much!
]]>We are trying to change Wordfence’s 2FA overlay form “Log In” button text on click to “Processing…”
Details: https://ibb.co/t3ZpMnJ
We have tried both the PHP and JS code snippets provided below, but none work.
We have also submitted a ticket to Wordfence Support for assistance, but it’s under review and a solution may not be available within 2-3 months.
So, hoping an experienced coder out there can help us. We prefer a PHP Code Snippet
Thank you!
———————————
Button HTML Code:
https://ibb.co/Htkgptj
PHP Code Snippet (Option 1):
add_action( 'login_enqueue_scripts', 'login_enqueue_wordfence_js' );
function login_enqueue_wordfence_js() {
wp_register_script( 'button-handle-wf', '', array("jquery"), '', true );
wp_enqueue_script( 'button-handle-wf' );
wp_add_inline_script( 'button-handle-wf', '(function($){$("#loginform input#wfls-token-submit").on("click", function() {$(this).val("Processing...");});})(jQuery);');
}
JS Code Snippet (Option 2):
<input onclick="changeText()" type="submit" value="Log In" id="wfls-token-submit">
function changeText(){
let element = document.getElementById("wfls-token-submit");
if (element.value=="Log In")
element.value = "Processing...";
else
element.value = "Log In";
}
]]>What approach have others used? Thank you.
]]>Can I know how can I do that?
Thank you!
]]>