How can I call a function from one plugin within another plugin?

Maybe you should try calling the functions of your plugin using the plugins_loaded action. Plugin A class PluginA { public function func_a() { // do stuff } } Plugin B class PluginB { function functB() { if (class_exists(‘PluginA’)) { //do stuff that depends of PluginA } } } add_action(‘plugins_loaded’, ‘call_plugin_a_using_plugin_b’); function call_plugin_a_using_plugin_b() { PluginB::functB(); } … Read more

Define page template in wp_insert_post

From the wp_insert_post() documentation, the page_template argument reads as follow: page_template: If post_type is ‘page’, will attempt to set the page template. On failure, the function will return either a WP_Error or 0, and stop before the final actions are called. If the post_type is not ‘page’, the parameter is ignored. You can set the … Read more

Custom page with variables in url. Nice url with add_rewrite_rule

I think the add_rewrite_tag() is not needed, and can be replaced with adding the variables to the public query vars directly: // Either directly (in your init hook): $wp->add_query_var( ‘var1’ ); $wp->add_query_var( ‘var2’ ); // Or via a filter: add_filter( ‘query_vars’, ‘wpse12965_query_vars’ ); function wpse12965_query_vars( $query_vars ) { $query_vars[] = ‘var1’; $query_vars[] = ‘var2’; return … Read more

Memorizing syntax

Not everyone will follow convention, so you can be assured if you are copy-pasting then you are getting a mix-and-match approach from people who do it “right” and do it “wrong” and sometimes the difference between right and wrong is a matter of opinion, lets not forget. Also this applies to NOT only Syntax Style … Read more

Sort search results by post type

I found the key: SQL CASE Expression function order_search_by_posttype($orderby){ if (!is_admin() && is_search()) : global $wpdb; $orderby = ” CASE WHEN {$wpdb->prefix}posts.post_type=”artist” THEN ‘1’ WHEN {$wpdb->prefix}posts.post_type=”post” THEN ‘2’ WHEN {$wpdb->prefix}posts.post_type=”artwork” THEN ‘3’ WHEN {$wpdb->prefix}posts.post_type=”publication” THEN ‘4’ ELSE {$wpdb->prefix}posts.post_type END ASC, {$wpdb->prefix}posts.post_title ASC”; endif; return $orderby; } add_filter(‘posts_orderby’, ‘order_search_by_posttype’);

Include files in child theme functions file

Child themes reference parent themes by directory name, and in a normal install all your themes live in wp-content/themes/, so I’d say it’s fine to reference those themes by their relative path: include ‘../parent-theme/some-file.php’; If that makes you uncomfortable, I observe the following constants in WordPress 3.0.1 with a twentyten child theme called tt-child: TEMPLATEPATH … Read more

How to include a plugin’s php file to another plugin functions file [duplicate]

The first error message means that there is restrictions in place on where you can include files from, set by the server. You could try with require_once ABSPATH . ‘/wp-content/plugins/pluginname/pluginfunctions.php’; but I’m not sure if it would work. With the second include you’re trying to include an URL which is disabled by the server for … Read more

File not found.