I have a form made with Contact Form 7 and I need to save the attachment in a folder but move_uploaded_file() or copy doesn't work. Do you know how to solve this problem? Thanks!!
add_action('wpcf7_before_send_mail', 'save_form' );
function save_form( $wpcf7 ) {
if (move_uploaded_file($_FILES["photo1"]["tmp_name"],$_FILES["photo1"]["name"]))
{ /* CORRECT */ }
else { /* ERROR */ } }
Hope you can help me, I don't know how continue. In a php file this function works but in Wordpress it's impossible. Thanks very much!!!!
Related
I'm having this strange issue to save functions.php in the Wordpress backend editor.
/* This saves okay */
add_action( 'template_redirect', 'redirect_non_admin_coming_soon_page' );
function redirect_non_admin_coming_soon_page()
{
if(is_admin()){
wp_safe_redirect('https://www.mysite.nl/coming-soon');
exit;
}
}
/* This also saves okay */
add_action( 'template_redirect', 'redirect_non_admin_coming_soon_page' );
function redirect_non_admin_coming_soon_page()
{
if(!is_admin()){
//wp_safe_redirect('https://www.mysite.nl/coming-soon');
exit;
}
}
/* But this fails to save*/
add_action( 'template_redirect', 'redirect_non_admin_coming_soon_page' );
function redirect_non_admin_coming_soon_page()
{
if(!is_admin()){
wp_safe_redirect('https://www.mysite.nl/coming-soon');
exit;
}
}
That last one gives the error message: "Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP."
Google has not helped me so far, so any help is much appreciated.
I'm am creating a new function on my WordPress theme: I want to open a new page if the options that I insert inside my form correct.
This is what i wrote inside my functions.php:
function form_action_filter() {
if($_POST['name'] == "Emanuele" && $_POST['nascita'] == "Loreto"){
header('Location: https://www.youtube.com/watch?v=HBBIXeosabg');
} else {
echo "Compila il form";
}
}
add_action('myAction', 'form_action_filter');
do_action('myAction');
At the moment, if I write my function directly inside the layout, the function works, but, if I write my function inside functions.php when i push "Invia", the code doesn't work.
Thank's to everyone that will help me to understand how to fix this error.
I created a new page in my admin panel.
On this page, for example function is_admin() works fine.
if ( ! is_admin() ) {
echo "You are viewing the theme";
} else {
echo "You are viewing the WordPress Administration Panels";
}
From this page i send post data to xxx.php file.
And! In this xxx.php file functions such as is_admin doens't work.
How can i let wordpress to understand, that this xxx.php file is the part of him? So i can use functions on this page?
I am using
"include wp-load.php"
but it doesn't help me.
You can add him in the theme folder & include in functions.php:
// functions.php of your current theme
include __DIR__.'/custom.php';
I just checked the source code on Github.
function is_admin() appears in this file https://github.com/WordPress/WordPress/blob/6fda2e67b0fe3872cbf5f82b58b98f2a4c96d8f8/wp-includes/load.php#L710-L717
So, require_once 'wp-includes/load.php; should sort you out.
The fact that you're sending POST data (request, i assume) to another php file makes me think that it's a completely different HTTP request, therefore you won't be able to use wp functions in the target php file, unless you include wp-load.ph in that file.
See this: https://wordpress.stackexchange.com/questions/69184/how-to-load-wordpress-on-non-wp-page
add_action('admin_menu', function(){
add_menu_page( 'Subscribe', 'Subscribe', 'manage_options', 'subsc-options', 'sub_setting', '', 4 );
} );
add_action( 'current_screen', function( $current_screen ){ // hook is admin panel only
if ( stripos($current_screen->base, 'subsc-options')==true ) {
include __DIR__.'/custom.php';
}
});
<form method="post">
<input type="hidden" name="my_save_settings" >
..............
</form>
/********* CUSTOM.PHP **************/
if ( isset($_POST['my_save_settings']) ) {
// save form fields
}
I need to add 'global $woocommerce;' in the wordpress my-ac-plugin.php to pull in the users country code for my caching but I'm getting a 500 error.
Does anyone know how I can do this, or any ideas what's wrong?
Here's my code...
if (!defined('WPINC')) {
exit('Do NOT access this file directly.');
}
function my_ac_plugin()
{
$ac = $GLOBALS['comet_cache_advanced_cache'];
$ac->addFilter('comet_cache_version_salt',
'my_ac_version_salt_shaker');
}
function my_ac_version_salt_shaker($version_salt)
{
global $woocommerce;
$customer_country = $woocommerce->customer->get_country();
$version_salt .= $customer_country;
geoip_close($gi);
return $version_salt;
}
my_ac_plugin();
Follow these steps to help in troubleshooting:
Go FTP into your website
Open the file named wp-config.php
Find the line where you see define('WP_DEBUG', false);
Change false to true and save the file
The next time you refresh the page you were getting an error on you should now see more descriptive error messages which will help in troubleshooting.
I am facing an issue with Contact Form 7 for Wordpress. I want to disable the email notification which i did using
demo_mode: on
At the same time i want to redirect on submit which i used to do using
on_sent_ok: "location = 'http://domain.com/about-us/';"
Both would work when used individually.But i want to use both at the same time.
I tried doing
on_sent_ok: "location = 'http://domain.com/about-us/';"
demo_mode: on
Doesnt seem to work. Kindly advice.
The plugin author has changed as of at least 4.0 the way you should do this again. The skip_mail property is now private :
class WPCF7_Submission {
private $skip_mail = false;
...
}
You should use this filter : wpcf7_skip_mail
For example :
function my_skip_mail($f){
$submission = WPCF7_Submission::get_instance();
if(/* YOUR TEST HERE */){
return true; // DO NOT SEND E-MAIL
}
}
add_filter('wpcf7_skip_mail','my_skip_mail');
The author of the plugin Contact Form 7 has refactored some of the code for its version 3.9 and since then the callback function for the hook wpcf7_before_send_mail must be written differently.
To prevent Contact Form 7 from sending the email and force it to redirect after the form has been submitted, please have a look at the following piece of code (for version >= 3.9):
add_action( 'wpcf7_before_send_mail', wpcf7_disablEmailAndRedirect );
function wpcf7_disablEmailAndRedirect( $cf7 ) {
// get the contact form object
$wpcf7 = WPCF7_ContactForm::get_current();
// do not send the email
$wpcf7->skip_mail = true;
// redirect after the form has been submitted
$wpcf7->set_properties( array(
'additional_settings' => "on_sent_ok: \"location.replace('http://example.com//');\"",
) );
}
Hook into wpcf7_before_send_mail instead of using the flag .
add_action("wpcf7_before_send_mail", "wpcf7_disablemail");
function wpcf7_disablemail(&$wpcf7_data) {
// this is just to show you $wpcf7_data and see all the stored data ..!
var_dump($wpcf7_data); // disable this line
// If you want to skip mailing the data..
$wpcf7_data->skip_mail = true;
}
Just an update. The following works in 4.1.1.
on_sent_ok: "location = 'http://domain.com/about-us/';"
demo_mode: on
Set skip_mail: on does the trick.
There might have been a change to contact-form-7, because I wasn't able to access the $skip_mail variable in the WPCF7_Submission object. I looked at the submission.php object in the \wp-content\plugins\contact-form-7\includes\submission.php file and found this:
private $skip_mail = false;
Since the variable is private, and there are no getters or setters in the file, you're not going to be able to change it externally. Just change it to this:
public $skip_mail = false;
and then you can change the variable like this in your functions.php file:
add_filter('wpcf7_before_send_mail', 'wpcf7_custom_form_action_url');
function wpcf7_custom_form_action_url( $form)
{
$submission = WPCF7_Submission::get_instance();
$submission->skip_mail = true;
}
A reminder, if you update the contact-form-7 plugin, it will probably nullify your change, so keep that in mind.
Simple code
Copy and paste the following code in your activated theme functions.php file.
add_filter('wpcf7_skip_mail','__return_true');
UPDATE WPCF7 ver. 7.5: There is now a filter specifically to handle this.
function my_skip_mail($f){
$submission = WPCF7_Submission::get_instance();
$data = $submission->get_posted_data();
if (/* do your testing here*/){
return true; // DO NOT SEND E-MAIL
}
}
add_filter('wpcf7_skip_mail','my_skip_mail');