Problem updating the theme in the FrontEnd.php file

Hi, I wanted to report a problem I have encountered.
Every time I update the theme in the theme file a piece of code necessary for the restapi is deleted:

																 if ( ! $_p && $atts[‘_p’] ) {
																 $_p = $atts[‘_p’];
															 }

I am therefore forced at each update to go here:
pro/cornerstone/includes/classes/Services/FrontEnd.php
and add code that is deleted because render_content does not have the value $_p.

I would expect to find this code in the FrontEnd.php file at line 78:

public function render_content( $atts, $content ) {

    $_p = null;
    $wrap = null;

    extract( shortcode_atts( array(
      ‘_p’ => $this->get_post_id(),
      wrap' => true
    ), $atts, ‘cs_content’ ) );

    if ( ! $_p && $atts[‘_p’] ) {
      $_p = $atts[‘_p’];
    }

    $content = $this->render_the_content_cached($_p, $content);

    if ( $wrap && $wrap !== ‘false’) {
      return cs_tag( ‘div’, apply_filters( ‘cs_content_atts’, array(
        ‘id’ => ‘cs-content’,
        ‘class’ => ‘cs-content’,
      ), get_the_ID(), get_post_type() ), $content );
    }

    return $content;

  }

But I actually find this:

  public function render_content( $atts, $content ) {

    $_p = null;
    $wrap = null;

    extract( shortcode_atts( array(
      ‘_p’ => $this->get_post_id(),
      wrap' => true
    ), $atts, ‘cs_content’ ) );

    $content = $this->render_the_content_cached($_p, $content);

    // Wrap content
    if ( $wrap && $wrap !== ‘false’) {
      return $this->render_content_wrapped($content);
    }

    return $content;

  }

How can I make this not happen?
Can you fix the FrontEnd.php file so that I don’t have to edit it every time I update?

Thank you very much

Hello @LukeStephans,

Thank you for the inquiry.

The condition or if statement doesn’t really make sense because by the time the extract() function is called, $_p will always have the ID of the current post or page, which is the same as the value of $atts[’_p’] . Where and how can we test this issue?

Best regards.

Hi @Ismael in theory it should actually work as you say, but in reality without that modification I can’t get the API calls to work.
Here you can see the error in the staging site, if you go to this link you will not see the posts.
https://meeting.semplify.xyz/wp-json/wp/v2/posts

As you can see, it does not appear in content, but instead we only have

‘content": {
‘rendered‘: “\<div id=\”bsf_rt_marker\’>\</div>\<div id=\‘cs-content\’ class=\‘cs-content\’></div>\n’,
‘protected": false
},


Here instead in production where I put the fix, as you can see the posts load correctly.
https://www.meetingrimini.org/wp-json/wp/v2/posts

I leave you in the Secure Note the accesses to view the staging, you need the Basic Auth

Thank you for the update. If you can provide the WP and FTP details, we’ll try to check the issue further. Did you use the CS builder to edit the posts?

Hi @Ismael ,
yes I used the CS builder for the articles.
I put the staging access data in the secure note to test the problem. If you also need the production site access data please let me know.

Did you change the login URL in the staging site? We tried using the default login and admin URL, but they redirect to the 404 page. We may also need access to the file server. Please include the FTP login details in the secure note.

Yes, in the secure notes you will find all the details

Thank you for the info. We are not yet sure why the post ID is not returned when using the REST API, but we managed to work around it without editing the FrontEnd.php file by adding this filter in the child theme’s functions.php file:

add_filter('cs_element_post_id', function($id) {
	global $post;
	return $post->ID;
}, 10, 1);

This ensures that the post ID is returned. Let us know if this works on your end.

Best regards.

Fantastic!
I put the function in the function and removed the fix.
Now everything works without changes to the FrontEnd.php
Great as usual! You are the best

Glad to know that this has been resolved! Let us know if you have more questions. Have a nice day.