• Resolved yezzz

    (@yezzz)


    Hi,

    Great plugin! It can do things where other plugins fail.

    One thing though is that it, as i understand, doesn’t use wp rewrite rules. In wordpress when using a taxonomy term as a slug in a post url (ie. /%category%/%postname%/), the url would automatically change in wp this would automatically change if you change the term, but with this plugin you’d have to regenerate the url.

    Anyways, I’m using a feed to automatically create posts and that is where this plugin fails. It probably uses the publish button to do its work? Is there a way to also create rewritten urls for auto-published content? Maybe it can hook into publish post action or something like that?

Viewing 15 replies - 1 through 15 (of 19 total)
  • Thread Starter yezzz

    (@yezzz)

    A good second look showed that you do already support auto-published posts.

    I did find that various imported posts did actually get a rewritten url, but in many cases 1 out of 2 specified structure tags failed. Will have another look at the import settings and logs. Using wp-all-import.

    Plugin Author Maciej Bis

    (@mbis)

    Hi @yezz,

    last week I received similar issue ticket and it seems that in some particular cases “save_post” hook is not triggered along with “wp_insert_post()” function.

    This week, I am going to do some experiments to check if is save to attach the same function (that is used to save the custom URIs) also to “wp_insert_post” hook.

    If the experiments fail, I will prepare a snippet that would be based on WP Cron Jobs and would regenarate the URIs posts added in last 24 hours.

    Best Regards,
    Maciej

    Plugin Author Maciej Bis

    (@mbis)

    Hi again @yezz,

    it took me faster than I excepted, though I need to do some further tests before I publish the new public version of the plugin. If you would like to test it, please replace the contents of “includes/core/permalink-manager-uri-functions-post.php” file with this code:
    https://gist.github.com/maciejbis/4ba21d7c4e88c53fcae123910fb872d1

    I added a new hook for “wp_insert_post” action, as it seems that a hotfix for a large bug (the custom URIs were not saved) caused a minor bug (the custom URIs were not saved for posts generated with wp_insert_post() function).

    Best Regards,
    Maciej

    Thread Starter yezzz

    (@yezzz)

    Wow, that was fast. However replacing the code will cause fatal error on the manager page:

    Fatal error: Class ‘Permalink_Manager_URI_Functions_Tax’ not found in C:\xampp\htdocs\suupr.loc\wp-content\plugins\permalink-manager\includes\core\permalink-manager-uri-functions-post.php on line 177

    Plugin Author Maciej Bis

    (@mbis)

    Hi @yezzz,

    I updated the snippet on Gist, please try again.

    Thread Starter yezzz

    (@yezzz)

    That code fixed the fatal error, but didn’t fix the bug:

    I’m using an ‘Offers’ CPT with 2 taxonomies like this:
    %couponordeal%/%offer_cat%

    Both are associated with the Offers CPT. Both taxonomies are hierarchical. I’m using %couponordeal% with a ‘root’ term. For %offer_cat% I’m testing with a child category, but wp-all-import created a parent and used that instead (it’s a setting somewhere). Maybe this is not relevant, but I mention it for completeness sake.

    Anyway, after feed import the custom urls look like %offer_cat%/%offer_cat% was used, so something went wrong with the first taxonomy.

    After I manually save such post the url gets corrected. After I use the regenerate tool in Custom URIs Mode all matching posts’ urls get corrected.

    • This reply was modified 7 years, 3 months ago by yezzz.
    Plugin Author Maciej Bis

    (@mbis)

    Hi @yezzz,

    I will prepare the “dev” version of plugin and commit it in next 12 hours and of course will keep you posted.

    Thread Starter yezzz

    (@yezzz)

    I assume you noticed the term bug isn’t fixed, and dev version is for troubleshooting it. Let me know where to get it.

    Plugin Author Maciej Bis

    (@mbis)

    Hi @yezzz,

    I am still testing the plugin – it will be ready in next 4 hours. After it is published, I will post a link here.

    Plugin Author Maciej Bis

    (@mbis)

    Thread Starter yezzz

    (@yezzz)

    Sorry to say, but v1.11.6 completely ignores the first slug, ie it only uses %offer_cat% in the link. Same as previous version the url gets updated to %couponordeal%/%offer_cat% using manual update and/or regenerate tool.

    Plugin Author Maciej Bis

    (@mbis)

    Ok, I will do some additional tests and keep you posted.

    Plugin Author Maciej Bis

    (@mbis)

    Could you add this snippet to your theme’s functions.php file and test it?

    function pm_fix_permalinks($post_id) {
      if(class_exists('Permalink_Manager_URI_Functions_Post') == false) { return; }
    
      global $permalink_manager_uris;
    
      // Get default post URI
      $new_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($post_id);
      $permalink_manager_uris[$post_id] = $new_uri;
    
      update_option('permalink-manager-uris', $permalink_manager_uris);
    }
    add_action('pmxi_saved_post', 'pm_fix_permalinks', 10);

    It should automatically regenerate the URI for the post after the import process is completed.

    • This reply was modified 7 years, 3 months ago by Maciej Bis.
    Thread Starter yezzz

    (@yezzz)

    It made no difference. Same with v.1.1.2 with hotfix.

    Plugin Author Maciej Bis

    (@mbis)

    I did some research and the problem is probably caused by the fact that during import process, the SQL queries (SELECT …) used in get_terms() to obtain the terms assigned to the new post are executed faster than queries that assign the terms to those posts (UPDATE/INSERT). In consequence, get_terms() returns empty array in this particular case.

    It is not exactly a bug caused by my plugin as it is related to SQL architecture.

    I wrote a workaround to reset the URIs for new posts after the whole import process is completed (the snippet above was executed for each of the posts individually).

    function pm_fix_permalinks($import_id) {
      global $permalink_manager_uris, $wpdb;
    
    	$post_ids = $wpdb->get_col($wpdb->prepare("SELECT post_id FROM {$wpdb->prefix}pmxi_posts WHERE import_id = %s", $import_id));
    
    	// Just in case
    	sleep(3);
    
    	if(array($post_ids)) {
    		foreach($post_ids as $id) {
    			// Get default post URI
    		  $new_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($id);
    		  $permalink_manager_uris[$id] = $new_uri;
    		}
    	}
    
      update_option('permalink-manager-uris', $permalink_manager_uris);
    }
    add_action('pmxi_after_xml_import', 'pm_fix_permalinks', 10);
    • This reply was modified 7 years, 3 months ago by Maciej Bis.
    • This reply was modified 7 years, 3 months ago by Maciej Bis.
Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Create rewrite rule on autopost’ is closed to new replies.