Skip to main content
added 37 characters in body
Source Link
LS_
  • 140
  • 6

I'm facing a weird issue with a Wordpress installation and I'm not sure how to proceed further. I've developed a simple AJAX endpoint only available for logged in userusers, which returns the detaildetails of a custom post type associated with the user. Example:

The problem is that as soon as I switch to another page it returnsthe whole front-end starts returning an error:

define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );

I'm facing a weird issue with a Wordpress installation and I'm not sure how to proceed further. I've developed a simple AJAX endpoint only available for logged in user, which returns the detail of a custom post type associated with the user. Example:

The problem is that as soon as I switch to another page it returns:

define('WP_DISABLE_FATAL_ERROR_HANDLER', true );
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );

I'm facing a weird issue with a Wordpress installation and I'm not sure how to proceed further. I've developed a simple AJAX endpoint only available for logged in users, which returns the details of a custom post type associated with the user. Example:

The problem is that as soon as I switch to another page the whole front-end starts returning an error:

define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
added 342 characters in body
Source Link
LS_
  • 140
  • 6
function get_return_request_detail() {
 
    $returnRequestId = ( isset( $_POST['return_request_id'] ) ) ? $_POST['return_request_id'] : '';
    if( empty( $returnRequestId ) ) {
        echo json_encode("missing parameter");
    exit;    wp_die();
    }

    $results = get_post_meta($returnRequestId);
    $meta = unserialize($results["_meta"][0]);

    if($results["_field_user_id"][0] == get_current_user_id()) {

        ... logic ...

        echo json_encode($data);
 
    } else {
        echo json_encode("unauthorized");
    }
    exit;wp_die();
}
add_action('wp_ajax_get_return_request_detail', 'get_return_request_detail');
function get_return_request_detail() {
 
  $returnRequestId = ( isset( $_POST['return_request_id'] ) ) ? $_POST['return_request_id'] : '';
  if( empty( $returnRequestId ) ) {
    echo json_encode("missing parameter");
    exit;
  }

    $results = get_post_meta($returnRequestId);
    $meta = unserialize($results["_meta"][0]);

    if($results["_field_user_id"][0] == get_current_user_id()) {

        ... logic ...

        echo json_encode($data);
 
    } else {
        echo json_encode("unauthorized");
    }
    exit;
}
add_action('wp_ajax_get_return_request_detail', 'get_return_request_detail');
function get_return_request_detail() {
    $returnRequestId = (isset($_POST['return_request_id'])) ? $_POST['return_request_id'] : '';
    if(empty($returnRequestId)) {
        echo json_encode("missing parameter");
        wp_die();
    }

    $results = get_post_meta($returnRequestId);
    $meta = unserialize($results["_meta"][0]);

    if($results["_field_user_id"][0] == get_current_user_id()) {

        ... logic ...

        echo json_encode($data);
    } else {
        echo json_encode("unauthorized");
    }
    wp_die();
}
add_action('wp_ajax_get_return_request_detail', 'get_return_request_detail');
added 342 characters in body
Source Link
LS_
  • 140
  • 6

I'm facing a weird issue with a Wordpress installation and I'm not sure how to proceed further. I've developed a simple apiAJAX endpoint only available for logged in user, it just printswhich returns the detail of a custom post type associated with the user. Example:

The apiendpoint works fine and I retrieve the data correctly. An example on how I call it:

jQuery.ajax({
            type: "post",
            dataType: "json",
            url: "/wp-admin/admin-ajax.php",
            data: {
                action:'get_return_request_detail',
                return_request_id: id,
            },
            success: function(response) {
                console.log(response);
        },
    });

The problem is that as soon as I switch to another page I start receiving a 500 errorit returns:

The weird behaviour is that, in order to make the pagefront-end work again, I just need to visit an Admin page and the error disappears. My questions are:

I'm facing a weird issue with a Wordpress installation and I'm not sure how to proceed further. I've developed a simple api only available for logged in user, it just prints a custom post type associated with the user. Example:

The api works fine and I retrieve the data correctly. The problem is that as soon as I switch to another page I start receiving a 500 error:

The weird behaviour is that, in order to make the page work again, I just need to visit an Admin page and the error disappears. My questions are:

I'm facing a weird issue with a Wordpress installation and I'm not sure how to proceed further. I've developed a simple AJAX endpoint only available for logged in user, which returns the detail of a custom post type associated with the user. Example:

The endpoint works fine and I retrieve the data correctly. An example on how I call it:

jQuery.ajax({
            type: "post",
            dataType: "json",
            url: "/wp-admin/admin-ajax.php",
            data: {
                action:'get_return_request_detail',
                return_request_id: id,
            },
            success: function(response) {
                console.log(response);
        },
    });

The problem is that as soon as I switch to another page it returns:

The weird behaviour is that, in order to make the front-end work again, I just need to visit an Admin page and the error disappears. My questions are:

added 445 characters in body
Source Link
LS_
  • 140
  • 6
Loading
deleted 1 character in body; edited tags
Source Link
LS_
  • 140
  • 6
Loading
Source Link
LS_
  • 140
  • 6
Loading