fix rewrite

parent cf8c843f
...@@ -15,7 +15,7 @@ if(!class_exists('SexHackVideoGallery')) { ...@@ -15,7 +15,7 @@ if(!class_exists('SexHackVideoGallery')) {
add_filter("query_vars", array($this, "query_vars")); add_filter("query_vars", array($this, "query_vars"));
add_action('wp_enqueue_scripts', array( $this, 'add_css' ), 200); add_action('wp_enqueue_scripts', array( $this, 'add_css' ), 200);
add_shortcode("sexgallery", array($this, "sexgallery_shortcode")); add_shortcode("sexgallery", array($this, "sexgallery_shortcode"));
add_action('init', array($this, "register_sexhack_video_post_type")); add_action('init', array($this, "register_sexhack_video_post_type"));
//add_filter('page_template', array($this, 'sexhack_video_template')); //add_filter('page_template', array($this, 'sexhack_video_template'));
add_filter('archive_template', array($this, 'sexhack_video_template')); add_filter('archive_template', array($this, 'sexhack_video_template'));
add_action('pre_get_posts', array($this, 'fix_video_query'), 1, 1); add_action('pre_get_posts', array($this, 'fix_video_query'), 1, 1);
...@@ -23,6 +23,14 @@ if(!class_exists('SexHackVideoGallery')) { ...@@ -23,6 +23,14 @@ if(!class_exists('SexHackVideoGallery')) {
} }
public function check_rewrite($rules)
{
// TODO Check if our rules are present and call flush if not
sexhack_log($rules);
return $rules;
}
public function add_css() public function add_css()
{ {
wp_enqueue_style ('sexhackme_gallery', plugin_dir_url(__DIR__).'css/sexhackme_gallery.css'); wp_enqueue_style ('sexhackme_gallery', plugin_dir_url(__DIR__).'css/sexhackme_gallery.css');
...@@ -96,9 +104,18 @@ if(!class_exists('SexHackVideoGallery')) { ...@@ -96,9 +104,18 @@ if(!class_exists('SexHackVideoGallery')) {
)); ));
$projects_structure = '/v/%wooprod%/'; $projects_structure = '/v/%wooprod%/';
$wp_rewrite->add_rewrite_tag("%wooprod%", '([^/]+)', "post_type=sexhack_video&wooprod="); $rules = $wp_rewrite->wp_rewrite_rules();
$wp_rewrite->add_permastruct('v', $projects_structure, false); // XXX This is HORRIBLE. Using a Try/Catch to test an array key is stupid. But apparently php is also
//$projects_structure = '/v/%sexhackmodel%/%sexhackvideo%/'; // are we really using /v/ also for this? how we get 2 tags? // stupid and array_key_exists() doesn't work.
try {
sexhack_log("REWRITE: rules OK: ".'v/([^/]+)/?$ => '.$rules['v/([^/]+)/?$']);
} catch(Exception $e) {
sexhack_log("REWRITE: Need to add and flush our rules!");
$wp_rewrite->add_rewrite_tag("%wooprod%", '([^/]+)', "post_type=sexhack_video&wooprod=");
$wp_rewrite->add_permastruct('v', $projects_structure, false);
$wp_rewrite->flush_rules();
}
} }
......
...@@ -4,6 +4,7 @@ namespace wp_SexHackMe; ...@@ -4,6 +4,7 @@ namespace wp_SexHackMe;
function debug_rewrite_rules($matchonly=false) function debug_rewrite_rules($matchonly=false)
{ {
$matchonly=true;
global $wp_rewrite, $wp, $template; global $wp_rewrite, $wp, $template;
$i=1; $i=1;
if (!empty($wp_rewrite->rules)) { if (!empty($wp_rewrite->rules)) {
......
...@@ -207,8 +207,7 @@ if(!class_exists('SexHackMe')) { ...@@ -207,8 +207,7 @@ if(!class_exists('SexHackMe')) {
// DEBUG REWRITE RULES // DEBUG REWRITE RULES
if( WP_DEBUG === true ){ if( WP_DEBUG === true ){
// only matched? // only matched?
$matched = true; add_action("the_post", 'wp_SexHackMe\debug_rewrite_rules');
add_action("the_post", 'wp_SexHackMe\debug_rewrite_rules', $matched);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment