WordPress.org

Ready to get started?Download WordPress

Forums

Custom rewriter rules return 404 (2 posts)

  1. yakatz
    Member
    Posted 3 years ago #

    I have this (straight-forward) code in a plugin:

    add_filter('query_vars', 'emailpost_query_vars');
    function emailpost_query_vars($public_query_vars) {
    	$public_query_vars[] = "yep_newemailpost";
    	return $public_query_vars;
    }
    add_filter('generate_rewrite_rules', 'emailpost_rewrite');
    function emailpost_rewrite($wp_rewrite) {
    	$wp_rewrite->rules = array_merge(array('newemailpost?$' => 'index.php?yep_newemailpost=y'), $wp_rewrite->rules);
    }

    (The reason the rewriter does not seem to do much is that the purpose of this rule is to allow a separate script to posting a file to this script by HTTP and have it processed by the plugin.)

    Everything works, EXCEPT that the HTTP return status code is always 404.
    The plugin is returning content and I can't see any reason for the 404 to be there.
    A coworker said he had that problem but it disappeared by itself (which I find very unlikely).
    Anyone know what to do about this or even where I should be looking?

  2. yakatz
    Member
    Posted 3 years ago #

    Sorry, it looks like a bit got cut off

    add_action('template_redirect', 'process_post', 5);
    function process_post() {
    	global $wpdb, $user_ID;
    
    	$message = file_get_contents($_FILES['file_contents']['tmp_name']);
    	unlink($_FILES['file_contents']['tmp_name']);
    	$hash = $_POST['messagehash'];
    	process_message($message, $hash);
    	exit();
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags