Skip to content

Commit

Permalink
Fix permalink category (#3913)
Browse files Browse the repository at this point in the history
* Reset WP_Query after running the migration

Sometimes the request URL causes the query to be left as a category causing some URLs to be treated as category pages. Reseting the query back to before the migration seems to stop this

* Add build scripts

* Bump versions

* Fix JSON import showing success on a fail

* Only show CPTs with rewrite

* Bump versions
  • Loading branch information
johngodley authored Nov 24, 2024
1 parent 8a4b91f commit 103c907
Show file tree
Hide file tree
Showing 11 changed files with 2,653 additions and 2,409 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ redirection.js.LICENSE.txt
.DS_Store
release
dist
svn
Empty file modified dev/svn.sh
100644 → 100755
Empty file.
8 changes: 5 additions & 3 deletions fileio/json.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function load( $group, $filename, $data ) {
}

// Import groups
$groups = array();
$group_map = array();

if ( isset( $json['groups'] ) ) {
Expand Down Expand Up @@ -67,8 +66,11 @@ public function load( $group, $filename, $data ) {
}

$redirect['group_id'] = $group_map[ $redirect['group_id'] ];
Red_Item::create( $redirect );
$count++;
$created = Red_Item::create( $redirect );

if ( $created instanceof Red_Item ) {
$count++;
}

// Helps reduce memory usage
unset( $json['redirects'][ $pos ] );
Expand Down
7 changes: 6 additions & 1 deletion models/permalinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct( $permalinks ) {
* @return void
*/
public function migrate( WP_Query $query ) {
global $wp;
global $wp, $wp_query;

if ( count( $this->permalinks ) === 0 ) {
return;
Expand All @@ -46,6 +46,8 @@ public function migrate( WP_Query $query ) {

$this->intercept_permalinks();

$query_copy = clone $query;

foreach ( $this->permalinks as $old ) {
// Set the current permalink
$this->current_permalink = $old;
Expand All @@ -72,6 +74,9 @@ public function migrate( WP_Query $query ) {
}
}

// Reset the query back to the original
// phpcs:ignore
$wp_query = $query_copy;
break;
}
}
Expand Down
83 changes: 42 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redirection",
"version": "5.5.0",
"version": "5.5.1",
"description": "Redirection is a WordPress plugin to manage 301 redirections and keep track of 404 errors without requiring knowledge of Apache .htaccess files.",
"main": "redirection.php",
"browser": {
Expand All @@ -9,18 +9,19 @@
"sideEffects": true,
"scripts": {
"test": "jest --testPathIgnorePatterns='/node_modules/|/e2e/'",
"testsetup": "bin/install-wp-tests.sh wordpress_test wp wp localhost latest",
"testsetup": "dev/install-wp-tests.sh wordpress_test wp wp localhost latest",
"start": "NODE_ENV=development DEBUG=redirection* webpack serve --progress --color --port 3312",
"build": "yarn build:version && NODE_ENV=production webpack --progress --color --config ./webpack.config.js --mode production",
"build:version": "./dev/generate-version.sh $npm_package_version $npm_package_wordpress_supported",
"release": "yarn build && rm -rf release && mkdir -p release && cp -R *.php readme.txt redirection.js redirection.css license.txt modules models matches images fileio database api actions release",
"dist": "yarn release && rm -rf redirection dist && mkdir -p dist && mv release redirection && zip redirection.zip -r redirection && mv redirection.zip dist && rm -rf redirection",
"release": "yarn build && rm -rf release && mkdir -p release && cp -R *.php readme.txt redirection.js redirection.css license.txt modules models matches images fileio database api actions release && rm release/api/*.md",
"dist": "yarn release && rm -rf redirection dist && mkdir -p dist && mv release redirection && zip redirection.zip -r redirection && mv redirection.zip dist && mv redirection release",
"dist:github": "yarn dist && release-it",
"dist:svn": "yarn dist && ./dev/svn.sh $npm_package_version",
"e2e": "NODE_ENV=e2e jest --config=e2e-jest.js --testPathIgnorePatterns='/node_modules/|/client/' --testTimeout=30000 e2e",
"doc": "apidoc -v -i api/ -o ./api-doc/",
"phpunit": "WP_TESTS_DIR=/var/folders/9z/t36wpw1d6hzdy4x5sfq8nqt00000gn/T/wordpress-tests-lib ./vendor/bin/phpunit",
"test:php": "composer run-script test"
"test:php": "composer run-script test",
"update": "ncu -u"
},
"repository": {
"type": "git",
Expand All @@ -33,86 +34,85 @@
},
"homepage": "https://github.com/johngodley/redirection",
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/core": "^7.26.0",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/preset-env": "^7.25.3",
"@babel/preset-react": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@babel/preset-env": "^7.26.0",
"@babel/preset-react": "^7.25.9",
"@babel/preset-typescript": "^7.26.0",
"@redux-devtools/extension": "^3.3.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/react-highlight-words": "^0.20.0",
"@types/react-redux": "^7.1.33",
"@wordpress/base-styles": "^5.4.0",
"@wordpress/eslint-plugin": "^20.1.0",
"@wordpress/jest-preset-default": "^12.4.0",
"@wordpress/prettier-config": "^4.4.0",
"@wordpress/scripts": "^28.4.0",
"@types/react-redux": "^7.1.34",
"@wordpress/base-styles": "^5.12.0",
"@wordpress/eslint-plugin": "^21.5.0",
"@wordpress/jest-preset-default": "^12.12.0",
"@wordpress/prettier-config": "^4.12.0",
"@wordpress/scripts": "^30.5.1",
"apidoc": "^1.2.0",
"autoprefixer": "^10.4.20",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^29.7.0",
"babel-loader": "^9.1.3",
"chai": "^5.1.1",
"babel-loader": "^9.2.1",
"chai": "^5.1.2",
"css-loader": "^7.1.2",
"download": "^8.0.0",
"enzyme": "^3.11.0",
"enzyme-to-json": "^3.6.2",
"eslint-import-resolver-node": "0.3.9",
"eslint-plugin-eslint-comments": "3.2.0",
"eslint-plugin-import": "2.29.1",
"html-webpack-plugin": "^5.6.0",
"eslint-plugin-import": "2.31.0",
"html-webpack-plugin": "^5.6.3",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"json-loader": "^0.5.7",
"mocha": "^10.7.0",
"node-fetch": "2",
"node-sass": "^9.0.0",
"npm-check-updates": "^17.0.2",
"mocha": "^10.8.2",
"node-fetch": "3",
"npm-check-updates": "^17.1.11",
"path": "^0.12.7",
"postcss": "^8.4.40",
"postcss": "^8.4.49",
"postcss-focus": "^7.0.0",
"postcss-loader": "^8.1.1",
"postcss-preset-env": "^10.0.0",
"postcss-preset-env": "^10.1.1",
"postcss-reporter": "^7.1.0",
"prettier": "npm:[email protected]",
"redux-devtools-extension": "^2.13.9",
"release-it": "^17.6.0",
"release-it": "^17.10.0",
"request-promise": "^4.2.6",
"sass-loader": "^16.0.0",
"sass-loader": "^16.0.3",
"style-loader": "4.0.0",
"stylelint": "^16.8.1",
"stylelint": "^16.10.0",
"stylelint-config-wordpress": "^17.0.0",
"underscore": "^1.13.7",
"webpack": "^5.93.0",
"webpack": "^5.96.1",
"webpack-bundle-analyzer": "^4.10.2",
"webpack-bundle-size-analyzer": "^3.1.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@emotion/react": "^11.13.0",
"@wordpress/element": "^6.4.0",
"@wordpress/i18n": "^5.4.0",
"@emotion/react": "^11.13.5",
"@wordpress/element": "^6.12.0",
"@wordpress/i18n": "^5.12.0",
"classnames": "^2.5.1",
"deep-equal": "^2.2.3",
"lru": "^3.1.0",
"qs": "^6.13.0",
"qs": "^6.13.1",
"rc-progress": "^4.0.0",
"rc-util": "^5.43.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-dropzone": "^14.2.3",
"react-focus-lock": "^2.12.1",
"react-dropzone": "^14.3.5",
"react-focus-lock": "^2.13.2",
"react-highlight-words": "^0.20.0",
"react-redux": "^9.1.2",
"react-textarea-autosize": "^8.5.3",
"react-textarea-autosize": "^8.5.5",
"redux": "^5.0.1",
"redux-thunk": "^3.1.0",
"request": "^2.88.2",
"typescript": "^5.5.4",
"typescript": "^5.7.2",
"url": "^0.11.4",
"use-debounce": "^10.0.2"
"use-debounce": "^10.0.4"
},
"jest": {
"modulePaths": [
Expand Down Expand Up @@ -154,5 +154,6 @@
]
},
"npm": false
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
10 changes: 8 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: johnny5
Donate link: https://redirection.me/donation/
Tags: redirect, htaccess, 301, 404, apache
Tested up to: 6.6.1
Stable tag: 5.5.0
Tested up to: 6.7
Stable tag: 5.5.1
License: GPLv3

Manage 301 redirects, track 404 errors, and improve your site. No knowledge of Apache or Nginx required.
Expand Down Expand Up @@ -182,6 +182,12 @@ The plugin works in a similar manner to how WordPress handles permalinks and sho

A x.1 version increase introduces new or updated features and can be considered to contain 'breaking' changes. A x.x.1 increase is purely a bug fix and introduces no new features, and can be considered as containing no breaking changes.

= 5.5.1 =
* Fix problem with category pages and permalink migration
* Don't report invalid JSON import as successful
* Exclude CPTs without URLs for monitoring
* Update for WP 6.7

= 5.5.0 =
* Multiple 'URL and WP page type' redirects will now work
* Translations now use WP core
Expand Down
2 changes: 1 addition & 1 deletion redirection-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function red_get_plugin_data( $plugin ) {
}

function red_get_post_types( $full = true ) {
$types = get_post_types( array( 'public' => true ), 'objects' );
$types = get_post_types( [ 'public' => true, 'rewrite' => false ], 'objects' );
$types[] = (object) array(
'name' => 'trash',
'label' => __( 'Trash', 'default' ),
Expand Down
4 changes: 2 additions & 2 deletions redirection-version.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

define( 'REDIRECTION_VERSION', '5.5.0' );
define( 'REDIRECTION_VERSION', '5.5.1' );
define( 'REDIRECTION_MIN_WP', '6.4' );
define( 'REDIRECTION_BUILD', 'eff218e8a6050e14b616f8d6629e0ae4' );
define( 'REDIRECTION_BUILD', '08d49200baf486dd62bdff53420d0b5d' );
4 changes: 2 additions & 2 deletions redirection.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion redirection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Redirection
Plugin URI: https://redirection.me/
Description: Manage all your 301 redirects and monitor 404 errors
Version: 5.5.0
Version: 5.5.1
Author: John Godley
Text Domain: redirection
Requires PHP: 7.0
Expand Down
Loading

0 comments on commit 103c907

Please sign in to comment.