How to make plugin required in a wp theme without using php conditional statements when calling an individual function from that plugin?

is_plugin_active() is rather fragile: it will break when either the plugin author renames the main file or when the user renames the plugin’s directory or main file. It’s better to check if a certain public function exists. To avoid having to make that check each time you need some of the plugin’s functionality, you could … Read more

Does the number of downloads displayed for a plug-in in the WordPress.org plug-in directory include automatic updates?

That’s the total number of downloads. It includes direct downloads in the Repository and installs/updates done in the dashboard. Quotes from Otto comments in this 2010 article about the stats charts in every plugin’s page. […] the download count includes direct downloads as well […] There is no “raw count” anywhere on that version number … Read more

What could a hacker do with my wp-config.php

localhost refers to the machine it’s running on. For example on my own site tomjn.com localhost is 127.0.0.1 as it always is. This doesn’t mean the hacker doesn’t know where to connect, it means the hacker replaces localhost with tomjn.com. Of course if I have a proxy sitting in front this won’t work, but keep … Read more

How to Add an Index to Plugin Database table

You can execute arbitrary SQL statements with wpdb::query(), including Data Definition Statements, e.g. function create_index () { global $wpdb ; $sql = “CREATE INDEX my_index ON {$wpdb->prefix}my_table (my_column)” ; $wpdb->query ($sql) ; return ; } Note: Because $wpdb->query() can execute arbitrary SQL, if the statement you pass to it contains ANY user input, then you … Read more

How do I call wp_get_current_user() in a plugin when plugins are loaded before pluggable.php?

To add to @EAMann’s answer, you need to wrap your wp_get_current_user() call (or any call that tries to access a function defined within pluggable.php) within the ‘plugins_loaded’ action. So, if you’re putting this inside your functions.php file, do it like this: add_action( ‘plugins_loaded’, ‘get_user_info’ ); function get_user_info(){ $current_user = wp_get_current_user(); if ( !($current_user instanceof WP_User) … Read more

How to Add a Third Level Sub Menu to the WordPress Admin Menu

No, it is not possible to create third level menu in admin panel. If you look at the definition of add_submenu_page, you need to mention the parent slug name. For eg: add_menu_page ( ‘Test Menu’, ‘Test Menu’, ‘read’, ‘testmainmenu’, ”, ” ); add_submenu_page ( ‘testmainmenu’, ‘Test Menu’, ‘Child1’, ‘read’, ‘child1’, ”); The first parameter of … Read more

Stop a plugin in the activation process when a certain WP version is not met then show error message in admin_notices action hook

I may be late to this party, but to stop plugin activation and have WordPress show an error message where the admin notices go, I simply output an error message and terminate execution. This has the added advantage of playing nice with wp-cli: Example: class testPlugin() { … static function activate() { //[do some stuff … Read more

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