airesvsg / acf-to-rest-api

Exposes Advanced Custom Fields Endpoints in the WordPress REST API
https://wordpress.org/plugins/acf-to-rest-api/
1.33k stars 111 forks source link

maximum execution time when get acf pages #304

Open simonjoom opened 5 years ago

simonjoom commented 5 years ago

I found an infinite loop issue (maximum time)

When the developer create a custom register_rest_field in function.php on page content.

 register_rest_field(
        'page',
        'content',
        array(
                'get_callback'    => 'mycallback',
                'update_callback' => null,
                'schema'          => null,
        )
    ); 

(I personaly use it a callback to encode the shortcodes and format the output).

In my test i concluded that is not good to use the same class class-wp-rest-controller and class-wp-rest-posts-controller from wordpress.

To avoid this problem, i decided to duplicate this 2 classes and add them in acf-to-rest-api folder
give at acf-to-rest-api the access to these new classes and remove completely the code who fetch the contents field that acf have no need; see below part commented.

I think there is some test to do on it. I wanted just to share my experience on this infinite loop

php
/* part comment remove the infinite loop
        if ( in_array( 'content', $fields, true ) ) {
            $data['content'] = array(
                'raw'           => $post->post_content,
                'rendered'      => post_password_required( $post ) ? '' : apply_filters( 'the_content', $post->post_content ),
                'protected'     => (bool) $post->post_password,
                'block_version' => block_version( $post->post_content ),
            );
        }

        if ( in_array( 'excerpt', $fields, true ) ) {
            $excerpt         = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) );
            $data['excerpt'] = array(
                'raw'       => $post->post_excerpt,
                'rendered'  => post_password_required( $post ) ? '' : $excerpt,
                'protected' => (bool) $post->post_password,
            );
        }
         */