Last active
July 19, 2016 19:03
-
-
Save ChrisFlannagan/0b40bb5779248b342d99625420a01be0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: User Website CPT | |
* Plugin URI: http://tri.be | |
* Description: Allow users to submit a website URL, Create a CPT that displays only the HTML pulled from that url, use shortcode [WSCPT] to display form | |
* Version: 1.0 | |
* Author: Chris Flannagan | |
* Text Domain: websites-cpt-text-domain | |
* Domain Path: /languages | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
die(); | |
} | |
if ( ! class_exists( 'UW_CPT' ) ) { | |
class UW_CPT { | |
public $Website_Submit; | |
/** | |
* Construct the plugin object | |
*/ | |
public function __construct() { | |
load_plugin_textdomain( 'websites-cpt-text-domain', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); | |
require_once( dirname( __FILE__ ) . '/classes/class-websites-cpt.php' ); | |
require_once( dirname( __FILE__ ) . '/classes/class-website-submit.php' ); | |
$WebSites_CPT = new WebSites_CPT(); | |
$this->Website_Submit = new Website_Submit(); | |
add_shortcode( 'WSCPT', array( $this->Website_Submit, 'display_form' ) ); | |
add_action( 'init', array( $this, 'your_website_rewrite' ) ); | |
add_action( 'template_redirect', array( $this, 'make_your_website_form' ) ); | |
} | |
public static function activate() { | |
if ( ! get_option( 'websites-cpt-flush-rewrites' ) ) { | |
add_option( 'websites-cpt-flush-rewrites', true ); | |
} | |
} | |
public function your_website_rewrite() { | |
add_rewrite_rule( '^your-website$', 'index.php?your-website=display-form', 'top' ); | |
add_rewrite_tag('%your-website%', '([^&]+)'); | |
if ( get_option( 'websites-cpt-flush-rewrites' ) ) { | |
flush_rewrite_rules(); | |
delete_option( 'websites-cpt-flush-rewrites' ); | |
} | |
} | |
public function make_your_website_form( $template ) { | |
if ( get_query_var( 'your-website' ) == 'display-form' ) { | |
get_header(); | |
echo do_shortcode( '[WSCPT]' ); | |
get_footer(); | |
exit(); | |
} else { | |
return $template; | |
} | |
} | |
} | |
} | |
if ( class_exists( 'UW_CPT' ) ) { | |
// instantiate the plugin class | |
register_activation_hook( __FILE__, array('UW_CPT', 'activate') ); | |
$UW_CPT = new UW_CPT(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment