fix rewrite

parent cf8c843f
......@@ -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()
{
wp_enqueue_style ('sexhackme_gallery', plugin_dir_url(__DIR__).'css/sexhackme_gallery.css');
......@@ -96,9 +104,18 @@ if(!class_exists('SexHackVideoGallery')) {
));
$projects_structure = '/v/%wooprod%/';
$rules = $wp_rewrite->wp_rewrite_rules();
// XXX This is HORRIBLE. Using a Try/Catch to test an array key is stupid. But apparently php is also
// 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);
//$projects_structure = '/v/%sexhackmodel%/%sexhackvideo%/'; // are we really using /v/ also for this? how we get 2 tags?
$wp_rewrite->flush_rules();
}
}
......
......@@ -4,6 +4,7 @@ namespace wp_SexHackMe;
function debug_rewrite_rules($matchonly=false)
{
$matchonly=true;
global $wp_rewrite, $wp, $template;
$i=1;
if (!empty($wp_rewrite->rules)) {
......
......@@ -207,8 +207,7 @@ if(!class_exists('SexHackMe')) {
// DEBUG REWRITE RULES
if( WP_DEBUG === true ){
// only matched?
$matched = true;
add_action("the_post", 'wp_SexHackMe\debug_rewrite_rules', $matched);
add_action("the_post", 'wp_SexHackMe\debug_rewrite_rules');
}
......
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