Skip to content

Commit

Permalink
Merge pull request #14 from outlandishideas/publish-and-tidy
Browse files Browse the repository at this point in the history
Prepare to publish to Wordpress.org
  • Loading branch information
NoelLH authored May 13, 2020
2 parents 2b2d13d + 59d72b6 commit e8d03af
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 18 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish to WordPress.org
on:
push:
tags:
- "*"
jobs:
tag:
name: New tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Build
run: |
npm install
npm run build
- name: WordPress Plugin Deploy
uses: 10up/action-wordpress-plugin-deploy@1.4.1
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SLUG: Routemaster
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
.idea
## Composer ##
vendor/
wp-content/mu-plugins/
# Locked versions won't be reflected in installations, so not having any
# is probably less confusing.
# https://getcomposer.org/doc/02-libraries.md#lock-file
composer.lock

## IDEs ##
.idea/
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Routemaster WordPress plugin

Replaces the built-in WordPress routing logic with one defined by url patterns
Replaces the built-in WordPress routing logic with one defined by URL patterns.

## Installation

Expand All @@ -11,4 +11,14 @@ Replaces the built-in WordPress routing logic with one defined by url patterns
~~~~
$router = MyRouter::getInstance();
$router->setup();
~~~~
~~~~

### Use with [OOWP](https://github.com/outlandishideas/oowp)

To successfully extend `OowpRouter` and gain router awareness of post objects,
you should also install OOWP. This is optional if you avoid the
`Outlandish\Wordpress\Routemaster\Oowp` namespace.

To install it:

composer require outlandish/oowp
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
"Outlandish\\Wordpress\\Routemaster\\": "src/"
}
},
"require": {
"php": ">=5.6",
"ext-json": "*"
},
"suggest": {
"outlandish/oowp": "To optionally use a post-object-aware version of the router and corresponding views"
},
"authors": [
{
"name": "Rasmus Winter",
Expand Down
11 changes: 11 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
=== Routemaster ===
Contributors: outlandishcoop
Tags: routing, routes
Requires at least: 4.9.8
Tested up to: 5.4.1
Stable tag: 2.4.0
Requires PHP: 5.6
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Replaces the built-in WordPress routing logic with one defined by URL patterns.
4 changes: 2 additions & 2 deletions src/Oowp/OowpRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ protected function getDefaultRoutePatterns()
}


/** @var null Used in permalinkHook function, to prevent infinite recursion */
protected $permalinkHookPostId = null;
/** @var int|null Used in permalinkHook function, to prevent infinite recursion */
protected $permalinkHookPostId;

/**
* Overwrites the post_link with the post's permalink()
Expand Down
6 changes: 3 additions & 3 deletions src/Oowp/OowpRouterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public function createNotFoundResponse()
* @param WordpressPost $post
*/
protected function redirectCanonical($post) {
$scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
$scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$permalink = $post->permalink();
if ("$scheme://$_SERVER[HTTP_HOST]$path" != $permalink) {
if ("$scheme://$_SERVER[HTTP_HOST]$path" !== $permalink) {
wp_redirect($permalink);
die;
}
Expand All @@ -70,7 +70,7 @@ protected function query($args) {
public function querySingle($args, $redirectCanonical = false) {
global $post;

if (current_user_can('edit_posts') && (isset($_GET['preview']) && $_GET['preview'] == 'true')) {
if (current_user_can('edit_posts') && (isset($_GET['preview']) && $_GET['preview'] === 'true')) {
//currently published posts just need this to show the latest autosave instead
$args['preview'] = 'true';

Expand Down
4 changes: 4 additions & 0 deletions src/Response/JsonResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
class JsonResponse extends RoutemasterResponse {
public $status;

/**
* @param array|string $outputArgs
* @param int $status
*/
public function __construct($outputArgs = [], $status = 200)
{
if (is_string($outputArgs)) {
Expand Down
7 changes: 4 additions & 3 deletions src/Response/RoutemasterResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ abstract class RoutemasterResponse
{
public $headers = [];
public $outputArgs = [];
public $routeName = null;
/** @var string|null */
public $routeName;

public function __construct($outputArgs = [])
{
Expand All @@ -22,7 +23,7 @@ public function setRouteName($routeName)
$this->routeName = $routeName;
}

final function handleRequest()
final public function handleRequest()
{
$this->preRender();
$this->render();
Expand Down Expand Up @@ -50,4 +51,4 @@ protected function postRender()
{
/* do nothing by default */
}
}
}
10 changes: 5 additions & 5 deletions src/RouterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ public function getRequestMethod()
}

public function isPost() {
return $this->getRequestMethod() == 'POST';
return $this->getRequestMethod() === 'POST';
}

public function isGet() {
return $this->getRequestMethod() == 'GET';
return $this->getRequestMethod() === 'GET';
}

public function isPut() {
return $this->getRequestMethod() == 'PUT';
return $this->getRequestMethod() === 'PUT';
}

public function isDelete() {
return $this->getRequestMethod() == 'DELETE';
return $this->getRequestMethod() === 'DELETE';
}

public function getRequestBody() {
$body = file_get_contents('php://input');
return $body ? json_decode($body) : null;
}
}
}
4 changes: 2 additions & 2 deletions src/View/HtmlPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public function render($args = [])

</body>
</html>
<?
<?php
}
}
}

0 comments on commit e8d03af

Please sign in to comment.