• Resolved psubraty

    (@psubraty)


    Hi,

    I am trying to add your code:

    add_action( ‘cf7_2_post_status_post’, ‘publish_new_post’,10,3);
    /**
    * Function to change the post status of saved/submitted posts.
    * @param string $status the post status, default is ‘draft’.
    * @param string $ckf7_key unique key to identify your form.
    * @param array $submitted_data complete set of data submitted in the form as an array of field-name=>value pairs.
    * @return string a valid post status (‘publish’|’draft’|’pending’|’trash’)
    */
    function publish_new_post($status, $ckf7_key, $submitted_data){
    /*The default behaviour is to save post to ‘draft’ status. If you wish to change this, you can use this filter and return a valid post status: ‘publish’|’draft’|’pending’|’trash’*/
    return ‘publish’;
    }

    I am getting an error:
    Can’t use function return value in write context
    line 193, file: wp-content/plugins/post-my-contact-form-7/public/class-cf7-2-post-public.php

    I noticed people had similar problems with PHP5*, I am using 7.2. Am I doing sth wrong?

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 17 total)
  • Thread Starter psubraty

    (@psubraty)

    PHP is 7.2.3. Tried downgrading to 7.1 – the same. It turns out I don’t even have to add any code. When I open editor and just click save – I get an error.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    Hi @psubraty

    sorry for the delayed response, I went through a bout of sickness and lots of work to catch up.

    That’s odd, this error only happens for PHP version < 5.5

    PHP is 7.2.3. Tried downgrading to 7.1 – the same.

    Are you sure your server is using php 7? it is possible that you have v7 installed, but if you do not configure your apache server to use it, it is quite possible that it is using v5.4.

    Follow these instructions to double check your php version.

    Thread Starter psubraty

    (@psubraty)

    Yes, I triple checked. Also right now using this method You pointed. PHP Version 7.1.15

    Plugin Author Aurovrata Venet

    (@aurovrata)

    mmmh, that’s odd. I am using php 7 on my local machine. I will give it a try to see if I can reproduce the error.

    Thread Starter psubraty

    (@psubraty)

    Hi. Were You able to find the problem?
    Psubraty

    Plugin Author Aurovrata Venet

    (@aurovrata)

    No. Did you check you php with php_info() or using the command line php -version?

    Thread Starter psubraty

    (@psubraty)

    As I sad, I triple checked. Including all the methodes mentioned in the link You provided. I really know the version of PHP on my server. I can give You an access to the wordpress to test it.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    It’s very strange, this is an error that occurs with php versions prior to v7.

    So the only issue can I see is that your php is somewhat referring to an older library… maybe your installation of pho had an issue and some libraries were not upgraded to v7?

    My suggestion would be to upgrade your server to v7.3 (the lastest version) or at least try to re-install your current version.

    If this is not possible then the only solution is to hack the plugin code to make it compatible with your specific setup, in which case I can tell you which lines to change to make it work.

    let me know what you want to do.

    Thread Starter psubraty

    (@psubraty)

    This is a shared server, I’ll ask my hosting provider about the possible problems You mentioned. Meanwhile it would be great if You could provide the code to be replaced ??

    Plugin Author Aurovrata Venet

    (@aurovrata)

    HI there, I realised I never got back to your with the code…

    Replace the lines 188-193 which have this code,

    
        $pattern = get_shortcode_regex();
    
        // if shortcode 'book' exists
        if ( preg_match_all( '/'. $pattern .'/s', $content, $matches )
          && array_key_exists( 2, $matches )
          && !empty(array_intersect( $shortcodes, $matches[2] )) )  {
    

    with the following lines of code,

    
        $pattern = get_shortcode_regex();
        $search_shortcodes = array_intersect( $shortcodes, $matches[2] );
        // if shortcode 'book' exists
        if ( preg_match_all( '/'. $pattern .'/s', $content, $matches )
          && array_key_exists( 2, $matches )
          && !empty($search_shortcodes) )  {
    
    Thread Starter psubraty

    (@psubraty)

    Hi,

    I am able to save this change, but I am getting an error while loading any page:

    Warning: array_intersect(): Argument #2 is not an array in /home/users/woof/public_html/ogrod.ptakipolskie.pl/wp-content/plugins/post-my-contact-form-7/public/class-cf7-2-post-public.php on line 189

    Now I can’t go back to old code neither. This time I get an error while trying to save code:

    Line 193: && !empty(array_intersect( $shortcodes, $matches[2] )) ) {
    Can’t use function return value in write context

    • This reply was modified 5 years, 6 months ago by psubraty.
    Plugin Author Aurovrata Venet

    (@aurovrata)

    ah, yes, I see my mistake, apologies for this, please replace with the following lines instaed,

    
    $pattern = get_shortcode_regex();
    $isMatch = preg_match_all( '/'. $pattern .'/s', $content, $matches );
    if($isMatch) $search_shortcodes = array_intersect( $shortcodes, $matches[2] );
    // if shortcode 'book' exists
    if ( $isMatch && array_key_exists( 2, $matches ) && !empty($search_shortcodes) )  {
    
    Thread Starter psubraty

    (@psubraty)

    works like charm, thank You!

    Thread Starter psubraty

    (@psubraty)

    oh, one more thing. Will this change in code be implemented in “standard”? If not, it will get updated after next patch and I will have to switch code manually?

    Plugin Author Aurovrata Venet

    (@aurovrata)

    No i don’t plan to put it as std. The only people who have faced a similar issue (in this plugin or other plugins i maintain) where all running php 5.6 or lower. The issue systematically went away when users upgraded to php 7.

    So i am still not sure why you’re facing this issue with php 7.2. It is possible the php installation was incomplete and some libraries are from5.6.

    Could you test your installation on a different server running php 7?

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Can’t use function return value in write context (PHP 7.2)’ is closed to new replies.