• I am using WordPress 4.9.5 and WP-Members 3.1.9.3

    I am developing my own plugin, which has an AJAX request which calls a function, which in turn calls wp_insert_post. At this point it fails with “Trying to get property of non-object”. The trace shows that this from line 223 of …/wp-members/inc/utilities.php, which looks like:

    $content = apply_filters( 'wpmem_auto_excerpt', $content, $post->ID, $post->post_type );

    I have done some checking and at this point $post is empty. If I add the following code after global $post, $more, $wpmem; in function wpmem_do_excerpt, my plugin works:

    if ( empty ( $post ) ) {
      return null;
    }

    Obviously, I put that in only for debugging purposes and have reverted to the original and a state where my plugin won’t work.

    In case it helps, the full trace for the error is:

    [12-May-2018 07:08:17 UTC] PHP Notice:  Trying to get property of non-object in D:\wamp64\www\mysite\wp-content\plugins\wp-members\inc\utilities.php on line 223
    
    [12-May-2018 07:08:17 UTC] PHP Stack trace:
    
    [12-May-2018 07:08:17 UTC] PHP   1. {main}() D:\wamp64\www\mysite\wp-admin\admin-ajax.php:0
    
    [12-May-2018 07:08:17 UTC] PHP   2. do_action() D:\wamp64\www\mysite\wp-admin\admin-ajax.php:97
    
    [12-May-2018 07:08:17 UTC] PHP   3. WP_Hook->do_action() D:\wamp64\www\mysite\wp-includes\plugin.php:453
    
    [12-May-2018 07:08:17 UTC] PHP   4. WP_Hook->apply_filters() D:\wamp64\www\mysite\wp-includes\class-wp-hook.php:310
    
    [12-May-2018 07:08:17 UTC] PHP   5. call_user_func_array:{D:\wamp64\www\mysite\wp-includes\class-wp-hook.php:286}() D:\wamp64\www\mysite\wp-includes\class-wp-hook.php:286
    
    [12-May-2018 07:08:17 UTC] PHP   6. gnt_generate_posts() D:\wamp64\www\mysite\wp-includes\class-wp-hook.php:286
    
    [12-May-2018 07:08:17 UTC] PHP   7. wp_insert_post() D:\wamp64\www\mysite\wp-content\plugins\my-plugin\flickr-lightroom-plugin.php:219
    
    [12-May-2018 07:08:17 UTC] PHP   8. wp_transition_post_status() D:\wamp64\www\mysite\wp-includes\post.php:3496
    
    [12-May-2018 07:08:17 UTC] PHP   9. do_action() D:\wamp64\www\mysite\wp-includes\post.php:4069
    
    [12-May-2018 07:08:17 UTC] PHP  10. WP_Hook->do_action() D:\wamp64\www\mysite\wp-includes\plugin.php:453
    
    [12-May-2018 07:08:17 UTC] PHP  11. WP_Hook->apply_filters() D:\wamp64\www\mysite\wp-includes\class-wp-hook.php:310
    
    [12-May-2018 07:08:17 UTC] PHP  12. call_user_func_array:{D:\wamp64\www\mysite\wp-includes\class-wp-hook.php:288}() D:\wamp64\www\mysite\wp-includes\class-wp-hook.php:288
    
    [12-May-2018 07:08:17 UTC] PHP  13. Nelio_Content->update_post_in_cloud() D:\wamp64\www\mysite\wp-includes\class-wp-hook.php:288
    
    [12-May-2018 07:08:17 UTC] PHP  14. Nelio_Content_Post_Helper->post_to_aws_json() D:\wamp64\www\mysite\wp-content\plugins\nelio-content\includes\class-nelio-content.php:533
    
    [12-May-2018 07:08:17 UTC] PHP  15. Nelio_Content_Post_Helper->get_the_content() D:\wamp64\www\mysite\wp-content\plugins\nelio-content\admin\class-nelio-content-post-helper.php:391
    
    [12-May-2018 07:08:17 UTC] PHP  16. apply_filters() D:\wamp64\www\mysite\wp-content\plugins\nelio-content\admin\class-nelio-content-post-helper.php:688
    
    [12-May-2018 07:08:17 UTC] PHP  17. WP_Hook->apply_filters() D:\wamp64\www\mysite\wp-includes\plugin.php:203
    
    [12-May-2018 07:08:17 UTC] PHP  18. call_user_func_array:{D:\wamp64\www\mysite\wp-includes\class-wp-hook.php:286}() D:\wamp64\www\mysite\wp-includes\class-wp-hook.php:286
    
    [12-May-2018 07:08:17 UTC] PHP  19. WP_Members->do_securify() D:\wamp64\www\mysite\wp-includes\class-wp-hook.php:286
    
    [12-May-2018 07:08:17 UTC] PHP  20. wpmem_do_excerpt() D:\wamp64\www\mysite\wp-content\plugins\wp-members\inc\class-wp-members.php:706
    
  • The topic ‘“Trying to get property of non-object” error from WP-Members’ is closed to new replies.