Skip Navigation

[Resolved] Problem With Astra Theme & Taxonomies

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a Form that creates posts. There is a custom taxonomy term checkboxes group in the Form. If a the Form is placed in a WordPress Archive and at least one custom taxonomy term is selected, PHP Warnings and Notices will be generated when the Form is submitted. In some cases the same issue happens when the Form is placed on a custom Page.

Solution: Our developers have identified the issue and produced a workaround you can use until the permanent fix is implemented:

class tssnippet_Support_Submit_Forms_On_Archives {
     
    private $data = null;
    private $needs_restore = false;
     
    function __construct() {
        $this->maybe_save_postdata();
        add_action( 'wp', array( $this, 'maybe_restore_postdata' ) );
    }
     
    public function maybe_save_postdata() {
        if ( ! get_option( 'permalink_structure' ) ) {
            // Note that this will not work on sites with ugly permalinks :-/
            return;
        }
        if (
            isset( $_POST['_cred_cred_prefix_form_id'] )
            && isset( $_POST['_cred_cred_prefix_form_count'] )
        ) {
            $this->needs_restore = true;
            $this->data = $_POST;
            $_POST = array();
        }
    }
     
    public function maybe_restore_postdata() {
        if ( ! $this->needs_restore ) {
            return;
        }
         
        $_POST = $this->data;
    }
}
add_action( 'wp_loaded', 'tssnippet_load_support_submit_forms_on_archives' );
function tssnippet_load_support_submit_forms_on_archives() {
    new tssnippet_Support_Submit_Forms_On_Archives();
}

Note that this workaround only applies to sites that use something other than the default permalink structure.

This support ticket is created 5 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 14 replies, has 2 voices.

Last updated by Christian Cox 3 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#1223401

Whilst seeking the reason why a code snippet of mine isn't working, I've set up a fresh test site (multisite) using just Types, CRED, Views & Access plugins. I set up a single post type, a radio field, two single line fields, taxonomy 'County' with values 'England' and 'Bedfordshire' (with England as parent), taxonomy 'Services' with value 'Major'. I created a form for submission by a Guest (create version) containing the fields and taxonomies. With theme 2017 enabled, the form submits without issue. With Astra installed, activated for the Network, enabled for the site and activated at site level, the following entries appear in my debug.log file when the form is submitted:-

[30-Mar-2019 12:58:03 UTC] PHP Warning:  urlencode() expects parameter 1 to be string, array given in /home/xxxxxxx/public_html/wp-includes/formatting.php on line 5205
[30-Mar-2019 12:58:03 UTC] PHP Notice:  Trying to get property of non-object in /home/xxxxxxx/public_html/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/user-editors/medium/screen/content-template/frontend.php on line 60
[30-Mar-2019 12:58:03 UTC] PHP Notice:  Trying to get property of non-object in /home/xxxxxxx/public_html/wp-includes/general-template.php on line 2795
[30-Mar-2019 12:58:03 UTC] PHP Notice:  Trying to get property of non-object in /home/xxxxxxx/public_html/wp-includes/general-template.php on line 2796
[30-Mar-2019 12:58:03 UTC] PHP Notice:  Trying to get property of non-object in /home/xxxxxxx/public_html/wp-includes/general-template.php on line 2796
[30-Mar-2019 12:58:03 UTC] PHP Notice:  Trying to get property of non-object in /home/xxxxxxx/public_html/wp-includes/general-template.php on line 2796
[30-Mar-2019 12:58:03 UTC] PHP Notice:  Trying to get property of non-object in /home/xxxxxxx/public_html/wp-includes/general-template.php on line 2797
[30-Mar-2019 12:58:03 UTC] PHP Notice:  Trying to get property of non-object in /home/xxxxxxx/public_html/wp-includes/general-template.php on line 2797
[30-Mar-2019 12:58:03 UTC] PHP Notice:  Trying to get property of non-object in /home/xxxxxxx/public_html/wp-includes/general-template.php on line 1539
[30-Mar-2019 12:58:03 UTC] PHP Notice:  Trying to get property of non-object in /home/xxxxxxx/public_html/wp-includes/general-template.php on line 1541
[30-Mar-2019 12:58:03 UTC] PHP Notice:  Trying to get property of non-object in /home/xxxxxxx/public_html/wp-includes/general-template.php on line 1541
[30-Mar-2019 12:58:03 UTC] PHP Notice:  Trying to get property of non-object in /home/xxxxxxx/public_html/wp-content/plugins/wp-views/embedded/inc/views-templates/wpv-template.class.php on line 968

I've looked at the files referenced in the entries and the issue seems to be linked to taxonomies. If I remove the taxonomy fields from the form and keep Astra activated, it submits without issue.

Any suggestions please?

#1223403

A little update; I've just tried a few other themes to see if the issue is just Astra related but it appears this is not the case.

Of these themes, only 'einfach' works without generating the log entries:-

coherent
blankslate
einfach
OceanWP
plaintext
Simpleasy

#1223491

I've discovered this morning that actually the errors ARE also being logged when using theme 'einfach' The form submits when using this theme but the errors aren't displayed on the frontend, they're just written to the file. With Astra the form doesn't submit and the errors are displayed on the frontend.

#1223520

Hi, thanks for the report. After a bit of troubleshooting I was able to replicate this locally and pin down a few more things:
- It seems to require that I select at least one custom taxonomy term in the Form.
- Multisite is not required.
- Access is not required.
- The notices and warnings are logged regardless of the theme, with only Types, Views and Forms active.
- This Form must be placed in a WordPress Archive or added to a WP Archive page some other way for the notices to be generated. The same Form placed in a custom Page will not trigger the same logs.

I'm able to escalate this now to my second tier team for additional investigation, and I'll let you know what I find out.

#1223861

Hi Christian

Thanks for checking this out & escalating

I only placed the Form on a Page. You're not getting the errors with a Form on a Page???

#1223915

No, I wasn't able to see the logs produced on a custom Page. Can you take screenshots of the Form settings in wp-admin so I can see your configurations? I may need to update the ticket for my internal team.

#1224294
form settings.JPG

Let me know if you need anything else?

#1224586

Okay the settings look similar to mine, so there must be something else going on. If you can reproduce this on a single site installation, I can work from a Duplicator clone or an export of all your Types, Views and Forms info.

#1224849

Hi Christian
I've re-created on a single site install, tested that the issue is still present and have export files for Types, Views & Forms ready. Can you enable a private field for a download link please?

#1225129

Yes here is a private reply field for you to share a download link. Thank you.

#1225414

Same behavior for me with these exports - the logs are only produced when the test-post_create Form is placed in a WordPress Archive. No logs when the same Form is placed on a custom Page. There could be something else I'm missing. Maybe it has something to do with your URL structure, permalinks and the slug of the page somehow? Maybe certain content on the page or the in the post content template is a factor? I can try working from a Duplicator package next if you'd like, or we can wait and see if the fix for the message in archives resolves the issue for you in pages as well.

#1225857

Our developers have provided a workaround that should fix this issue in sites that do not use the default permalink structure. The permanent fix for this issue for all permalink structures will not be available soon as it requires a significant amount of work and is not on the current schedule. The workaround solves the issue temporarily until we can address the problem in a more permanent way. Please add the following snippet to a child theme's functions.php file, or create a new snippet in Toolset > Settings > Custom code:

class tssnippet_Support_Submit_Forms_On_Archives {
	
	private $data = null;
	private $needs_restore = false;
	
	function __construct() {
		$this->maybe_save_postdata();
		add_action( 'wp', array( $this, 'maybe_restore_postdata' ) );
	}
	
	public function maybe_save_postdata() {
		if ( ! get_option( 'permalink_structure' ) ) {
			// Note that this will not work on sites with ugly permalinks :-/
			return;
		}
		if (
			isset( $_POST['_cred_cred_prefix_form_id'] )
			&& isset( $_POST['_cred_cred_prefix_form_count'] )
		) {
			$this->needs_restore = true;
			$this->data = $_POST;
			$_POST = array();
		}
	}
	
	public function maybe_restore_postdata() {
		if ( ! $this->needs_restore ) {
			return;
		}
		
		$_POST = $this->data;
	}
}
add_action( 'wp_loaded', 'tssnippet_load_support_submit_forms_on_archives' );
function tssnippet_load_support_submit_forms_on_archives() {
	new tssnippet_Support_Submit_Forms_On_Archives();
}

Then test your Form to confirm the logs have stopped. If not, I'll need to work with a clone of your site to see exactly what is happening.

#1226212

Hi Christian

Have tested this on both single and multi site installs & I can confirm my forms are now submitting and the errors are no longer being generated.

Many thanks for getting this sorted.

#2079301

FYI the permanent solution for this problem will be included in the upcoming Forms 2.6.10 release. Once you update, the workaround is no longer required.

#2125219

Forms 2.6.10 is now available.

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.