Marketpress Removing My Existing Shopp Plugin Rewrite Rules

When I install MarketPress for the first time, it changes the rewrite rules for the site. Comparing a before and after, specifically, it is removing my Shopp plugin rewrite rules. What's the deal?

My Shopp plugin is at /shop. MarketPress uses /store by default. Why are they being removed completely?!

Also, still don't have an answer for https://premium.wpmudev.org/forums/topic/does-marketpress-submit-address-information-to-payment-gateway-payflow-pro

  • aristath

    Hello there @AB, I hope you're well today!

    When I install MarketPress for the first time, it changes the rewrite rules for the site. Comparing a before and after, specifically, it is removing my Shopp plugin rewrite rules. What's the deal?

    MarketPress (like many other plugins) requires that you have pretty permalinks enabled. It does not change any rewrite rules.

    Could you please post here the contents of your .htaccess file just to make sure there's nothing wrong with that? (that's where the rewrite rules reside).

    If you disable the MarketPress plugin, is the /shop url accessible again?

    Please advise,
    Ari.

  • AB

    MarketPress (like many other plugins) requires that you have pretty permalinks enabled. It does not change any rewrite rules.

    Could you please post here the contents of your .htaccess file just to make sure there's nothing wrong with that? (that's where the rewrite rules reside).

    If you disable the MarketPress plugin, is the /shop url accessible again?

    Please advise,
    Ari.

    If I disable MarketPress, no, /shop is not accessible again. The only way I can get it back is to restore my DB to a backup before MarketPress was installed.

    If MarketPress does not change the rewrite rules, then something else does when it is installed becuase, there are new rewrite rules for /store... which MarketPress uses.

    Which .htaccess file? This is the one in the root www dir:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteRule ^shop/images/(\d+)/?\??(.*)$ /wp-content/plugins/shopp/core/image.php?siid=$1&$2 [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

    I opened up a backup that I think was taken after installing MarketPress:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteRule ^shop/images/(\d+)/?\??(.*)$ /wp-content/plugins/shopp/core/image.php?siid=$1&$2 [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

    They are identical.

  • AB

    I just checked the MarketPress plugin and there's no reference to that url anywhere in the code.Perhaps it's a conflict with another plugin?

    Could you please try disabling all other plugins and check if any of them affects that url?

    Cheers,
    Ari.

    Sorry, not trying to be thick but, what URL? I cannot deactivate anything at this time (business hours).

    That .htaccess file was from the webroot (/var/www/html). Should I be looking at a different .htaccess file?

  • aristath

    Sorry, not trying to be thick but, what URL?

    Sorry, I should have made that more clear. I meant the /shop url.

    That .htaccess file was from the webroot (/var/www/html). Should I be looking at a different .htaccess file?

    If your website is installed on the webroot then yes, this is the .htaccess file.
    If your site is installed on a subfolder of that (for example on a folder called /var/www/html/site) then we'd need the .htaccess on that folder.

  • AB

    MarketPress (like many other plugins) requires that you have pretty permalinks enabled. It does not change any rewrite rules.

    function add_rewrite_rules($rules) {
        $new_rules = array();
    
        //product list
        $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->products') . '/?$'] = 'index.php?pagename=product_list';
      	$new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->products') . '/page/?([0-9]{1,})/?$'] = 'index.php?pagename=product_list&paged=$matches[1]';
    
        //checkout page
        $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->cart') . '/?$'] = 'index.php?pagename=cart';
        $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->cart') . '/([^/]+)/?$'] = 'index.php?pagename=cart&checkoutstep=$matches[1]';
    
        //order status page
        $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->orderstatus') . '/?$'] = 'index.php?pagename=orderstatus';
        $new_rules[$this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->orderstatus') . '/([^/]+)/?$'] = 'index.php?pagename=orderstatus&order_id=$matches[1]';
    
        //ipn handling for payment gateways
        $new_rules[$this->get_setting('slugs->store') . '/payment-return/(.+)'] = 'index.php?paymentgateway=$matches[1]';
    
      	return array_merge($new_rules, $rules);
      }
    
      //unfortunately some plugins flush rewrites before the init hook so they kill custom post type rewrites. This function verifies they are in the final array and flushes if not
      function check_rewrite_rules($value) {
    
        //prevent an infinite loop by only
        if ( ! post_type_exists( 'product' ) )
          return $value;
    
    		if ( is_array($value) && !in_array('index.php?product=$matches[1]&paged=$matches[2]', $value) ) {
    			flush_rewrite_rules();
        } else {
          return $value;
        }
      }
  • AB

    Sorry, I should have made that more clear. I meant the /shop url.

    Yes, I know. That's my point. We use /shop for the shopp plugin.

    So, this is my thinking now. Since Shopp is so screwed up (which is why we want to switch), when MarketPress calls for a rewrite flush to get plugins to re-register their rules, Shopp never add's it's re-write rules.

    That's what it seems like anyways. If I am reading http://codex.wordpress.org/Function_Reference/flush_rewrite_rules correctly?

  • AB

    @AB I think you might be on to something here...

    Can you locate the part of the shopp plugin that creates the /shop url? If you can, then you could simply copy-paste that part inside the MarketPress plugin for as long as it takes you to migrate your content...
    Unfortunately I don't have the shopp plugin as it's premium so I can't find that code.

    Cheers,
    Ari.

    I will try this as well, thanks for the suggestion. Now I am sweating a little. Maybe it was turned off for a reason LOL! We'll see! At least I know where to make the change!

    I will post here with an update later and maybe someone else will find it helpful.

  • AB

    For reference. Notice on the activate, it changes rewrite_rules to on but, in my db it was set to off...

    Shop constructor adds this:

    add_action('shopp_init', array($this,'rebuild'),99);

    This is the rebuild:

    function rebuild () {
    		if ( ! shopp_setting_enabled('rebuild_rewrites') ) return;
    
    		flush_rewrite_rules();
    		shopp_set_setting('rebuild_rewrites','off');
    	}

    This is the activate and deactivate

    function activate () {
    
    		// If no settings are available, no tables exist,
    		// so this is a new install
    		$db_version = intval(shopp_setting('db_version'));
    		if (!$db_version) $db_version = intval(ShoppSettings()->legacy('db_version'));
    		if (!$db_version) $this->install();
    
    		// Force the Shopp init action to register needed taxonomies & CPTs
    		do_action('shopp_init');
    
    		// Process any DB upgrades (if needed)
    		$this->upgrades();
    
    		do_action('shopp_setup');
    
    		if (ShoppSettings()->available() && shopp_setting('db_version'))
    			shopp_set_setting('maintenance','off');
    
    		if (shopp_setting_enabled('show_welcome'))
    			shopp_set_setting('display_welcome','on');
    
    		shopp_set_setting('updates', false);
    		shopp_set_setting('rebuild_rewrites','on');
    
    		return true;
    	}
    function deactivate () {
    		global $Shopp;
    
    		// Update rewrite rules (cleanup Shopp rewrites)
    		remove_action('shopp_init', array($Shopp,'pages'));
    		remove_filter('rewrite_rules_array',array($Shopp,'rewrites'));
    		flush_rewrite_rules();
    
    		shopp_set_setting('data_model','');
    
    		if (function_exists('get_site_transient')) $plugin_updates = get_site_transient('update_plugins');
    		else $plugin_updates = get_transient('update_plugins');
    		unset($plugin_updates->response[SHOPP_PLUGINFILE]);
    		if (function_exists('set_site_transient')) set_site_transient('update_plugins',$plugin_updates);
    		else set_transient('update_plugins',$plugin_updates);
    
    		return true;
    	}

    Here are the rules

    function rewrites ($wp_rewrite_rules) {
    		if ('' == get_option('permalink_structure')) return $wp_rewrite_rules;
    		$path = str_replace('%2F','/',urlencode(join('/',array(PLUGINDIR,SHOPP_DIR,'core'))));
    
    		$rules = array(
    			Storefront::slug().'/'.Storefront::slug('account').'/download/([a-f0-9]{40})/?$' // Download handling
    				=> 'index.php?src=download&shopp_download=$matches[1]',
    		);
    
    		add_rewrite_rule(Storefront::slug().'/images/(\d+)/?\??(.*)$', $path.'/image.php?siid=$1&$2');
    
    		return $rules + $wp_rewrite_rules;
    	}

    And this part is worrysome. I see some deleting going on but, not sure what Product refers to:

    function install () {
    		global $wpdb,$wp_rewrite,$wp_version,$table_prefix;
    
    		if (!file_exists(SHOPP_DBSCHEMA)) $this->error('nodbschema-install');
    
    		// Remove any old product post types and taxonomies to prevent duplication of irrelevant data
    		DB::query("DELETE FROM $wpdb->posts WHERE post_type='".Product::$posttype."'");
    		DB::query("DELETE FROM $wpdb->term_taxonomy WHERE taxonomy='".ProductCategory::$taxon."' OR taxonomy='".ProductTag::$taxon."'");
    
    		// Install tables
    		ob_start();
    		include(SHOPP_DBSCHEMA);
    		$schema = ob_get_contents();
    		ob_end_clean();
    
    		DB::loaddata($schema);
    		unset($schema);
    
    	}
  • aristath

    And this part is worrysome. I see some deleting going on but, not sure what Product refers to:

    Products are custom post types.
    The MarketPress post type for products is called "product".
    You can find that out simply by creating a new product. You'll see tat in marketpress the url is /wp-admin/post-new.php?post_type=product
    Is it the same url when you try to create a shopp product?
    That part of the code is there to ensure that no 2 plugins use the same content type as this can lead to errors.

    Can you export your products from shopp?? If you can export them then you could import them on mp later on...

  • AB

    Products are custom post types.
    The MarketPress post type for products is called "product".
    You can find that out simply by creating a new product. You'll see tat in marketpress the url is /wp-admin/post-new.php?post_type=product
    Is it the same url when you try to create a shopp product?
    That part of the code is there to ensure that no 2 plugins use the same content type as this can lead to errors.

    Can you export your products from shopp?? If you can export them then you could import them on mp later on...

    Shopp does not have any exporting functionality (for products) that I could find, unfortunately.

    This is all I see when I create a new product. I will have to do some more digging to find the post_type.

    wp-admin/admin.php?page=shopp-products&id=new

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.