Skip to content

Papi ajax - Permalinks settings #218

Closed

Description

@nlemoine

Description

When using a repeater with a group a fields, the "add new" button is broken.

The ajax URL called when hitting the button is returning a 404. I found out the URL is only working when permalinks are enabled.

This should work in any case.

Checking the source code, I also noticed you didn't take advantage of the WordPress ajax "api", this would probably save some bugs (this one included) and provide a "native" way to achieve all the papi ajax stuffs.

There's also a tiny problem with adding your own endpoints with add_rewrite_rule, you need to flush rewrite rules so they can be added to all rewrite rules.

Steps to reproduce

  • Set permalinks to "simple" (?p=123)
  • Add a repeater property with some properties
  • Click on "add new"

What versions of softwares are you using?

  • Browser: Chrome 56
  • Papi: 3.1.18
  • WordPress: 4.7.2

Activity

  1. added this to the v3.1.19 milestone on Feb 13, 2017
  2. frozzare commented on Feb 13, 2017

    @frozzare
    Member

    You get a lot of overhead with WP's built in ajax api so that's why I'm not using it and that will not change.

    Simple permalinks should work but haven't been tested since I never use simple permalinks. Will look at a solution so simple permalinks should work.

  3. frozzare commented on Feb 13, 2017

    @frozzare
    Member

    The steps provided to reproduce this bug isn't working. Setting permalinks to simple doesn't work, I have also tried to reinstall my WordPress installation and reproduce the same steps as you provided without success.

  4. nlemoine commented on Feb 13, 2017

    @nlemoine
    ContributorAuthor

    Sorry, the english name for the permalinks setting is "Plain", not "Simple".

    I can easily reproduce it on a fresh install with this sample type:

    <?php
    
    class AjaxType extends Papi_Page_Type {
    
    	/**
    	 * Meta data
    	 *
    	 * @return array
    	 */
    	public function meta() {
    		return [
    			'name'        => 'Name',
    			'description' => 'Description',
    		];
    	}
    
    	/**
    	 * Define our properties.
    	 */
    	public function register() {
    
    		$this->box('Repeater', [
    			papi_property([
    				'title'    => 'Title',
    				'slug'     => 'repeater_property',
    				'type'     => 'repeater',
    				'settings' => [
    					'items' => [
    						papi_property([
    							'type'     => 'string',
    							'title'    => 'Description',
    							'slug'     => 'description',
    						]),
    					]
    				]
    			] ),
    		]);
    
    	}
    }
  5. frozzare commented on Feb 13, 2017

    @frozzare
    Member
    1. On a fresh installation I have selected "plain" permalinks
    2. Have a repeater property with a child properties
    3. papi-ajax endpoint works for me, maybe some type of cache in WordPress that isn't flushed or something like that.

    Running wp cli don't help.

    → wp rewrite flush
    Warning: Rewrite rules are empty, possibly because of a missing permalink_structure option. Use 'wp rewrite list' to verify, or 'wp rewrite structure' to update permalink_structure.

    → wp rewrite list
    Warning: No rewrite rules.

    So I'm unable to reproduce this right now but I have created a example that don't use papi-ajax endpoint when permalink structure is empty, would be great if you can try it 126f842

    With this solution we could remove papi-ajax endpoint and add a query string papi-ajax=true instead so plain permalink structure and the others use the same solution. papi-ajax endpoint it's nice but not necessary to use a real endpoint for that.

  6. nlemoine commented on Feb 13, 2017

    @nlemoine
    ContributorAuthor

    I think I know what's the issue here. Are you using Apache? Do the .htaccess file contains the WP rewrite rules? If so, you will not see the issue described here.

    Same goes is you're using nginx (rewrite rules are enabled by default).

    In order to reproduce the issue, you must either not have an .htaccess file or it must not contain rewrite rules.

    I'll try your fix but I looks like the one I used to fix this. I'll give you some feedback within the day.

  7. nlemoine commented on Feb 13, 2017

    @nlemoine
    ContributorAuthor

    👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions