Brad
Brad

Reputation: 2237

WordPress Rewrite Plugin

Example Code:

function flush_rewrite_rules()
{
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}
function activate()
{
    global $wp_rewrite;
    createRewriteRules( $wp_rewrite );
    flush_rewrite_rules();
}
function createRewriteRules( $rewrite )
{
    global $wp_rewrite;
    $new_rules = array( 'option/(.+)' => 'index.php?option=' . $wp_rewrite->preg_index(1) );
    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; // ERROR HERE............
    return $wp_rewrite;
}
add_action( 'generate_rewrite_rules', createRewriteRules );
register_activation_hook( file, activate );

Sometimes gives Fatal error: Unsupported operand types, but activates the plugin and doesn't stop it from working... What am I doing wrong here?

Upvotes: 0

Views: 555

Answers (1)

Jimmy Shelter
Jimmy Shelter

Reputation: 1540

Probably either $new_rules or $wp_rewrite->rules is not an array at the moment you want to combine them.

You could add a test to see if they are arrays, and if not, initialize them as an empty array.

(Addition: Why pass $rewrite as an argument, when you use a global to get the original variable?)

Upvotes: 3

Related Questions