How do I “replace a function via plugins” in WordPress?

You’re on the right track with creating the plugin. All your assumptions are correct. To avoid errors on activation you’ll want to wrap the functions that you are redefining in function_exists blocks, as on activation those functions will already be defined: if ( ! function_exists( ‘wp_hash_password’ ) ) : function wp_hash_password( $password ) { return … Read more

How to control output of custom post type without modifying theme?

There’re two very often forgotten action ref arrays: loop_start/_end(). Just turn on output buffering and you’re ready to go. add_action( ‘loop_start’, ‘wpse75307_plugin_loop’ ); add_action( ‘loop_end’, ‘wpse75307_plugin_loop’ ); /** * Callback function triggered during: * + ‘loop_start’/`have_posts()` after the last post gets rendered * + ‘loop_end’/`the_post()` before the 1st post gets rendered * @param object \WP_Query … Read more

How do you create an archive for a custom post type from a plugin?

Include your template files in your plugin. I stick mine in /plugin/templates. You need to hook into template location for that template: add_filter(‘archive_template’, ‘yourplugin_get_custom_archive_template’); function yourplugin_get_custom_archive_template($template) { global $wp_query; if (is_post_type_archive(‘yourCPT’)) { $templates[] = ‘archive-yourCPT.php’; $template = yourplugin_locate_plugin_template($templates); } return $template; } Rinse and repeat with the appropriate checks for each template you want to … Read more

What is the difference between using global $current_screen and get_current_screen()?

In your example, there is currently no difference. You get the same object, if there is one. Try it: global $current_screen; $current_screen->foo = 1; $screen = get_current_screen(); $screen->foo = 2; echo ‘$current_screen->foo: ‘ . $current_screen->foo; // 2! The simple reason: objects are not passed as a copy in PHP. But: global variables are really bad, … Read more

Creating a user’s own folder on user registration

You can use the user_register action to hook into the register proces and then create the user directory with wp_mkdir_p. function create_user_dir($user_id) { $user_info = get_userdata( $user_id ); $upload_dir = wp_upload_dir(); $user_dir = $upload_dir[‘basedir’] . ‘/user_dirs/’ . $user_info->user_login; wp_mkdir_p($user_dir); } add_action( ‘user_register’, ‘create_user_dir’); This example makes a directory in uploads/user_dirs. http://codex.wordpress.org/Plugin_API/Action_Reference/user_register http://codex.wordpress.org/Function_Reference/wp_mkdir_p

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