Git Product home page Git Product logo

rewrite-command's Introduction

wp-cli/rewrite-command

Lists or flushes the site's rewrite rules, updates the permalink structure.

Testing

Quick links: Using | Installing | Contributing | Support

Using

This package implements the following commands:

wp rewrite

Lists or flushes the site's rewrite rules, updates the permalink structure.

wp rewrite

See the WordPress Rewrite API and WP Rewrite class reference.

EXAMPLES

# Flush rewrite rules
$ wp rewrite flush
Success: Rewrite rules flushed.

# Update permalink structure
$ wp rewrite structure '/%year%/%monthnum%/%postname%'
Success: Rewrite structure set.

# List rewrite rules
$ wp rewrite list --format=csv
match,query,source
^wp-json/?$,index.php?rest_route=/,other
^wp-json/(.*)?,index.php?rest_route=/$matches[1],other
category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$,index.php?category_name=$matches[1]&feed=$matches[2],category
category/(.+?)/(feed|rdf|rss|rss2|atom)/?$,index.php?category_name=$matches[1]&feed=$matches[2],category
category/(.+?)/embed/?$,index.php?category_name=$matches[1]&embed=true,category

wp rewrite flush

Flushes rewrite rules.

wp rewrite flush [--hard]

Resets WordPress' rewrite rules based on registered post types, etc.

To regenerate a .htaccess file with WP-CLI, you'll need to add the mod_rewrite module to your wp-cli.yml or config.yml. For example:

apache_modules:
  - mod_rewrite

OPTIONS

[--hard]
	Perform a hard flush - update `.htaccess` rules as well as rewrite rules in database. Works only on single site installs.

EXAMPLES

$ wp rewrite flush
Success: Rewrite rules flushed.

wp rewrite list

Gets a list of the current rewrite rules.

wp rewrite list [--match=<url>] [--source=<source>] [--fields=<fields>] [--format=<format>]

OPTIONS

[--match=<url>]
	Show rewrite rules matching a particular URL.

[--source=<source>]
	Show rewrite rules from a particular source.

[--fields=<fields>]
	Limit the output to specific fields. Defaults to match,query,source.

[--format=<format>]
	Render output in a particular format.
	---
	default: table
	options:
	  - table
	  - csv
	  - json
	  - count
	  - yaml
	---

EXAMPLES

$ wp rewrite list --format=csv
match,query,source
^wp-json/?$,index.php?rest_route=/,other
^wp-json/(.*)?,index.php?rest_route=/$matches[1],other
category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$,index.php?category_name=$matches[1]&feed=$matches[2],category
category/(.+?)/(feed|rdf|rss|rss2|atom)/?$,index.php?category_name=$matches[1]&feed=$matches[2],category
category/(.+?)/embed/?$,index.php?category_name=$matches[1]&embed=true,category

wp rewrite structure

Updates the permalink structure.

wp rewrite structure <permastruct> [--category-base=<base>] [--tag-base=<base>] [--hard]

Sets the post permalink structure to the specified pattern.

To regenerate a .htaccess file with WP-CLI, you'll need to add the mod_rewrite module to your WP-CLI config. For example:

apache_modules:
  - mod_rewrite

OPTIONS

<permastruct>
	The new permalink structure to apply.

[--category-base=<base>]
	Set the base for category permalinks, i.e. '/category/'.

[--tag-base=<base>]
	Set the base for tag permalinks, i.e. '/tag/'.

[--hard]
	Perform a hard flush - update `.htaccess` rules as well as rewrite rules in database.

EXAMPLES

$ wp rewrite structure '/%year%/%monthnum%/%postname%/'
Success: Rewrite structure set.

Installing

This package is included with WP-CLI itself, no additional installation necessary.

To install the latest version of this package over what's included in WP-CLI, run:

wp package install [email protected]:wp-cli/rewrite-command.git

Contributing

We appreciate you taking the initiative to contribute to this project.

Contributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

For a more thorough introduction, check out WP-CLI's guide to contributing. This package follows those policy and guidelines.

Reporting a bug

Think you’ve found a bug? We’d love for you to help us get it fixed.

Before you create a new issue, you should search existing issues to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.

Once you’ve done a bit of searching and discovered there isn’t an open or fixed issue for your bug, please create a new issue. Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, review our bug report documentation.

Creating a pull request

Want to contribute a new feature? Please first open a new issue to discuss whether the feature is a good fit for the project.

Once you've decided to commit the time to seeing your pull request through, please follow our guidelines for creating a pull request to make sure it's a pleasant experience. See "Setting up" for details specific to working on this package locally.

Support

GitHub issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support

This README.md is generated dynamically from the project's codebase using wp scaffold package-readme (doc). To suggest changes, please submit a pull request against the corresponding part of the codebase.

rewrite-command's People

Contributors

aaemnnosttv avatar clemens-tolboom avatar conatus avatar danielbachhuber avatar ernilambar avatar eugeneware avatar francescolaffi avatar gilbitron avatar gitlost avatar janw-me avatar japh avatar jmslbam avatar johnbillion avatar leewillis77 avatar lkwdwrd avatar miya0001 avatar mpeshev avatar mwilliamson avatar natewr avatar nyordanov avatar pattonwebz avatar rodrigoprimo avatar schlessera avatar scribu avatar szepeviktor avatar thanj avatar thrijith avatar wesm87 avatar wojsmol avatar yivi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rewrite-command's Issues

Confirmation messages from wp rewrite structure appear in reverse order

Given the following command:

wp rewrite structure /%year%/%monthnum%/%postname%/

the output is:

Success: Rewrite rules flushed.
Success: Rewrite structure set.

One would expect that the new rewrite structure gets set before the rewrite rules are flushed (which does happen), but the confirmation message suggests the opposite.

Is there a way that this confirmation message can be improved?

Move command over to new v2 structure

The following changes need to be made to move the command over to the v2 structure:

  • Make sure the correct framework is required:
    composer require wp-cli/wp-cli:^2
    
  • Require the testing framework as a dev dependency:
    composer require --dev wp-cli/wp-cli-tests:^0
    
  • Use the .travis.yml file from wp-cli/wp-cli:
    wget https://raw.githubusercontent.com/wp-cli/wp-cli/master/.travis.yml
    
  • Add the default script configuration to Composer file:
      "scripts": {
          "lint": "run-linter-tests",
          "phpcs": "run-phpcs-tests",
          "phpunit": "run-php-unit-tests",
          "behat": "run-behat-tests",
          "prepare-tests": "install-package-tests",
          "test": [
              "@lint",
              "@phpcs",
              "@phpunit",
              "@behat"
          ]
      },
    
  • Remove scaffolded binary files:
    git rm bin/install-package-tests.sh
    git rm bin/test.sh
    
  • Remove scaffolded Behat setup:
    git rm features/bootstrap/*
    git rm features/extra/*
    git rm features/steps/*
    
  • Remove scaffolded Behat tags util script:
    git rm utils/behat-tags.php
    
  • Add command packages that are needed for Behat tests as --dev dependencies.
    The following commands are already available, anything else needs to be explicitly required:
    • cli *
    • config *
    • core *
    • eval
    • eval-file
    • help
  • Update all dependencies:
    composer update
    
  • Optional - Add PHPCS rule set to enable CS & compatibility sniffing:
    wget https://raw.githubusercontent.com/wp-cli/wp-cli/master/phpcs.xml.dist
    
  • Run and adapt tests to make sure they all pass:
    composer test
    

wp rewrite flush throws PHP Parse error

Bug Report

Describe the current, buggy behavior
Running wp rewrite flush from the wordpress:cli docker image in CircleCI gives me the following error:

PHP Parse error:  syntax error, unexpected ',' in phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1198) : eval()'d code on line 88
Exited with code 255

Other wp cli commands work fine.

Describe how other contributors can replicate this bug

Not suure. Run wordpress base docker image and wp:cli image in a circle ci job.

Describe what you would expect as the correct outcome

Expected command returns Success: Rewrite rules flushed.

Let us know what environment you are running this on
CircleCi running the following docker image with wp cli:

FROM wordpress:cli

USER root

ENV PHP_INI_MEMORY_LIMIT 1024M
RUN echo 'memory_limit = ${PHP_INI_MEMORY_LIMIT}' > "$PHP_INI_DIR/php.ini"

RUN apk update && apk upgrade && \
    apk add --no-cache bash git openssh

USER www-data

(Paste the output of "wp cli info" into this box)

^@^@OS:	Linux 4.10.0-35-generic #39~16.04.1-Ubuntu SMP Wed Sep 13 09:02:42 UTC 2017 x86_64
Shell:	
PHP binary:	/usr/local/bin/php
PHP version:	7.3.9
php.ini used:	/usr/local/etc/php/php.ini
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/var/www/html
WP-CLI packages dir:	
WP-CLI global config:	
WP-CLI project config:	
WP-CLI version:	2.3.0

Why is the apache_modules config necessary?

Hi 👋 ,

I was wondering why the additional config wp-cli.yml or config.yml is necessary? Can't this be passed as an argument? It feels cumbersome to add this config file to all our repos.

apache_modules:
  - mod_rewrite

Would you welcome a PR? Thanks in advance 🙏 .

Remove unused variable `$new_assoc_args` in `wp rewrite structure` subcommand

Feature Request

Describe your use case and the problem you are facing

I have been reviewing the code of the wp rewrite structure command and have run into unused $new_assoc_args variable , which looks like a residuum after past code updates:

$new_assoc_args = [];

The variable was introduced in 3be1d98 where \WP_CLI::launch_wpcli was used for launching the flush command.

But it was later changed to WP_CLI::runcommand ( in bf6c7c0 ) which does not accept the assoc args param, and the --hard flag is being appended to the $cmd.

Keeping the $new_assoc_args variable in place makes the code less readable.

Describe the solution you'd like

Removing the $new_assoc_args variable definition and the only other usage in the code, as the variable is never really used:

$new_assoc_args = [];

$new_assoc_args['hard'] = true;

I'm happy to open a pull request, if we agree that this issue is valid.

Automatically rerun failed scenarios

The following changes need to be made:

  1. In the .travis.yml file, the - composer behat line in the script: section needs to be changed into the following:
- composer behat || composer behat-rerun
  1. In the composer-json file, the requirement on wp-cli/wp-cli-tests needs to be adapted to require at least v2.0.7:
"wp-cli/wp-cli-tests": "^2.0.7"
  1. In the composer-json file, the "scripts" section needs to be extended. Immediately after the line "behat": "run-behat-tests",, the following line needs to be inserted:
"behat-rerun": "rerun-behat-tests",

Here's an example of how this should look like:

Adopt and enforce new `WP_CLI_CS` standard

We have a new PHPCS standard for WP-CLI called WPCliCS (props @jrfnl). It is part of the wp-cli/wp-cli-tests package starting with version v2.1.0.

To adopt & enforce this new standard, the following actions need to be taken for this repository:

  • Create a PR that adds a custom ruleset phpcs.xml.dist to the repository

    • Add phpcs.xml.dist file
    • Adapt .distignore to ignore phpcs.xml.dist & phpunit.xml.dist
    • Adapt .gitignore to ignore phpunit.xml, phpcs.xml & .phpcs.xml
    • Require version ^2.1 of the wp-cli/wp-cli-tests as a dev dependency
  • Make any required changes to the code that fail the checks from the above ruleset in separate PRs

  • Merge thre ruleset once all required changes have been processed and merged

A sample PR for a simple repository can be seen here: https://github.com/wp-cli/maintenance-mode-command/pull/3/files

Related wp-cli/wp-cli#5179

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.