add_feed and flush_rewrite_rules

You have to check the existing rewrite rules before you run a flush. If your feed name is test, they are stored under the keys ‘feed/(feed|rdf|rss|rss2|atom|test)/?$’ and ‘(feed|rdf|rss|rss2|atom|test)/?$’. So this should do the trick: add_action( ‘init’, function() { $name=”test”; $registered = FALSE; add_feed( $name, ‘test_feed’ ); $rules = get_option( ‘rewrite_rules’ ); $feeds = array_keys( $rules, … Read more

Intercept request to /wp-content/uploads/random.file

I just ran a test where I uploaded an image to media library, then renamed my root index.php file to break WordPress, but the image I uploaded was still available by accessing it directly with its wp-content/uploads/… URL. There are no .htaccess files in wp-content or uploads either, which means that, barring any plugins that … Read more

Change page title from plugin

There’s a filter for that: function wpse_alter_title( $title, $id ) { // $id = $post->ID; // alter the title here return $title; } If you want to alter the “Protected” and “Private” titles, then you need other filters: // Preserve the “%s” – else the title will be removed. function wpse_alter_protected_title_format( $title ) { return … Read more

Use wp init hook to call other hooks?

In general: Yes, wait for a dedicated hook to start your own code. Never just throw an object instance into the global namespace. But init is rarely necessary. You hook in as late as possible. If your first code runs on wp_head do not use an earlier hook. You can even cascade hooks: add_action( ‘wp_head’, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)