Display error message when shortcode user entry id not added - wordpress

I have this shortcode ( put together from different sources ) and it works.. when a user inputs the shortcode to a page [insert_xpage idnum="123"] it will show the contents of the page id123.
However if in the shortcode itself when a user inputs the shortcode and does not add the id number [insert_xpage idnum=""] the site dies. NOT the backend, just the frontend. You can navigate to the shortcode on the post and enter a number and the site comes back.
I have added a var called $err containing an error message with some html markup also shown below.
How can the $output = ''; be amended to show the error, instead of killing the page? and... still allow the site to work!
But have a little error message where the $output should be?
Maybe another filter? or some kind of elseif? don't know....
I had tried to do different output, return, echo or just different ways to show an error
tried:
.$GLOBALS["err"].
' ".$GLOBALS["err"]." '
echo "".$GLOBALS["err"]."";
echo ""$err"";
If a user does not add the required id in the correct place, the site itself breaks.
EG: [insert_xpage idnum=""]
instead of [insert_xpage idnum="123"]

Related

Adding a Advanced Custom Field to Woocommerce users My Account Page

I am using admin columns together with ACF (advanced custom fields)
in the backend I created a field in ACF for just some text, now with admin columns I made this field viewable in the backend for me to add some text that I want .
Now I want to display this text in the my-account page on the frontend.
now I got this far that i added the snippet code to the account page and that works .
But it's only displaying the DEFAULT value I have filled in in ACF and not the value I have entered in the admin custom column backend.
so to clarify even more in my users backend page i give the user a string of text.
That text needs to be displayed in the frontend on the users account
So all users should have a different string of text. The text I can add using admin columns
thats no problem but its only displaying (echo,printing) this text that I have filled in there to the woocommerce account page is not working.
Again I only get the default result text from ACF there not the text I had put in.
For getting default message the code that I use now is:
<?php echo the_field('ethwallet'); ?>
This is giving me the default message right now. not the result that I entered in the backend.
I realize this is an older question, but I wanted to provide an answer as it has been viewed several hundred times.
To retrieve custom meta data (specifically ACF field data) from a User object you need to pass in the current user ID as a second parameter to the get_field or the_field function.
Like so:
<?php echo get_field( 'ethwallet', 'user_' . get_current_user_id() ); ?>
The way it works is that ACF needs the second parameter formatted as user_X, where X is the actual ID of the user (1, 347, whatever). So we concatenate the string part ('user_') with the actual ID of the logged in user and that forms the full parameter to pass to the_field() or get_field().
P.S. It's a minor detail, but in this case echo the_field(); is redundant because the_field() echoes its values by default. You could likely omit the echo or do echo get_field();

CFDB plugin : Preventing Duplicate Submissions from CF7

I have a form where user add his email address, I’m trying to prevent users to enter there email many times. I use "contact form to database plugin" to save email address and export them to excel. while searching on internet I found this solution (link below) but I can’t get it work can you help me please :
https://cfdbplugin.com/?page_id=904
Thanks
I found the solution,
in the line where you put the name of the form you should put the title of the form (line bellow ) :
$formName = 'email_form'; // Change to name of the form containing this field
so, for exemple if we have created with the contact form 7 a form here is the shortcode that we will have :
<?php echo do_shortcode( '[contact-form-7 id="69" title="Email_form" html_name="my_form"]' ); ?>
what I did is I put the value of html_name in the script of CFDB but when I changed to the value of title it works

Hide a post but make it accessible via a link Wordpress

I'm trying to hide certain posts from displaying on the site using custom code. I CANNOT USE A PLUGIN!
I would like to do something like IF the page is named the-hidden-page do not display it anywhere on the site BUT someone can access it using a URL... For example, http://thedomain/the-hidden-page.
I haven't been successful finding sample code except for this -
<?php if (is_front_page() && !is_paged()
) $posts = query_posts($query_string . '&cat=-33,-66'); ?>
This code is using category names rather than page names. Also if I used the code above I'm not sure where to add it to. I tried function.php but that didn't work.
Can someone provide an example of how the code could be written to hide post with a certain name?
Also tell me in what file I should add your code to?

Wordpress Form Submit button GETS (or POSTS) form data to external page

We have a wordpress website that does marketing display, but now we want to allow a customer to submit an email and selection to a separate website with a landing page that will handle the backend DB work and finish them in the other website.
Something like,
www.ourmarket.com/getdata (on Submit button click GETS to...)
www.ouradminsite/landingpage.aspx (which processes the data that the use will not see then...)
www.ouradminsite/login.aspx (where the user can now login)
I am not familiar with WP at all, but I was able to create a page with a form that has the textbox/combobox I need.
I thought it would be something simple, but somehow it seems not. I read about AJAX and doing something in functions.php and creating a custom .js file, but when working on the marketing site I find no way to add this type of function in.
My fall back is to have the WP page just have a link to a generic landing page where they enter data, but it would be visually jarring to the customer unless I duplicate the WP site for one page.
Is there an easy way to just tell WP to redirect to an external page with a GET?
UPDATE--------------
I like to think I'm making progress. I found a link that may have given me a good start. I added a function to the functions.php file located in my WP theme. It starts like this:
add_action("gform_post_submission_4", "set_post_content", 10, 2);
function set_post_content($entry, $form){
//Gravity Forms has validated the data
//Our Custom Form Submitted via PHP will go here
// Lets get the IDs of the relevant fields and prepare an email message
$message = print_r($entry, true);
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);
// Send
mail('myuser#mycompany.com', 'Getting the Gravity Form Field IDs', $message);
**wp_redirect("http://my.hearbuilder.com/hellomoto.aspx",301);**
}
From there I tried to edit the function to do that wp_redirect, just a simple one to start. This is added under the mail statement:
wp_redirect("http://my.hearbuilder.com/hellomoto.aspx",301);
From this link, when I fill out the form I can get the email, but the new page did not display. I added the exit; line and still got the same result, the page seems like it hangs.
The end result is that I need to have the new website landing page display (after it processes the data from the Wordpress form.
What am I still missing?
yes use wp_redirect()
if($_POST):
$textbox=$_POST['textboxname'];
$url= 'url'.'?custom=hello&textbox='.$textbox.'&anothervalue='.$anothervalue;
wp_redirect($url);
exit;
endif;
you can easily add the variables to the string as needed. The easiest way to control the url properly is to post the information to the same page , catch the post and redirect (place before get_header call or any output has started)
The other way is php Curl which is more difficult esp when dealing with .asp pages, but if you have access to the other server it makes figuring it out easier!

Custom action on user_register hook in WordPress

I try to implement a custom function/action after a new user profile has been created in WordPress. To test the code I try to write a text in a file as proof of function execution.
Here is the code that I have inserted at the end of the active theme's functions.php file
if ( ! function_exists( 'register_for_cmsa' ) ) :
function register_for_cmsa($user_id) {
// write in an external file
// writeLogWP($msg) is a function from a file I have included in index.php
writeLogWP("A new user is: " . $user_id);
}
add_action('user_register', 'register_for_cmsa');
endif;
Therefore, I added a new user through the admin panel. As soon as I validate the standard WP add user form (wp-admin/user-new.php) I get a blank page, meaning that the above code is in trouble. But the user is added in the database (it is visible in the users' list if I comment my function). The trouble here is when executing the writeLogWP("A new user is: " . $user_id) statement inside the register_for_cmsa() function.
I tried to see if the statement works outside of the function, while always inside the functions.php file. And I noticed that it writes the message to the external file when I navigate in the WP site, BUT it publishes blank page as soon as I get into the admin dashboard section.
My code is accepted in 'site' side but it is in error in the 'admin' one.
The code is however not executed in the 'site' side because the hook is not triggered. It is triggered only if I go to the 'wp-admin/user-new.php' but ... I can' test it, as per the above reason.
I am really confused, glad to have your comments and, why not, solution.
Thanks
The index.php is not loaded when accessing the WordPress admin, hence the writeLogWP function is not being called in that case. Moving it to functions.php should solve the issue.

Resources