Skip to content

Instantly share code, notes, and snippets.

@ozh
Created April 16, 2020 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozh/715b9ecf34517717318a3a687252d286 to your computer and use it in GitHub Desktop.
Save ozh/715b9ecf34517717318a3a687252d286 to your computer and use it in GitHub Desktop.
YOURLS: Old Pages (backward compatibility plugin for pages directory in root)

Plugin for YOURLS 1.7.7+: Old Pages

What for

Display pages that are located in <root>/pages/ instead of <root>/user/pages/

How to

  • In /user/plugins, create a new folder named old-pages
  • Drop these files in that directory
  • Go to the Plugins administration page and activate the plugin
  • Have fun
<?php
/*
Plugin Name: Old Pages
Plugin URI: http://yourls.org/
Description: Backward compatibility for pages directory located at YOURLS root
Version: 1.0
Author: Ozh
Author URI: http://ozh.org/
*/
// No direct call
if( !defined( 'YOURLS_ABSPATH' ) ) die();
// Detect pages existing in the old pages dir
yourls_add_filter( 'keyword_is_reserved', 'ozh_oldpages_reserved' );
function ozh_oldpages_reserved($reserved, $keyword) {
if (file_exists(YOURLS_ABSPATH . "/pages/$keyword")) {
$reserved = true;
}
return $reserved;
}
// Redirect to existing pages in the old directory
yourls_add_filter( 'redirect_keyword_not_found', 'ozh_oldpages_redirect' );
function ozh_oldpages_redirect($keyword) {
$keyword = $keyword[0];
if (file_exists(YOURLS_ABSPATH . "/pages/$keyword.php")) {
yourls_do_action( 'pre_page', $keyword );
include_once( YOURLS_ABSPATH . "/pages/$keyword.php" );
yourls_do_action( 'post_page', $keyword );
die();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment