-
-
The upcoming WordPress 2.6 introduces new user defined constant for specific critical system directory settings. This new improvement may seem like a small “change” but on plugin developer context it can be an impending disaster.
The upcoming WordPress 2.6 introduces new user defined constant for specific critical system directory settings. This new improvement may seem like a small “change” but on plugin developer context it can be an impending disaster.wp-config & wp-load files
Most plugin depend on “absolute path” to wordpress system file (wp-config.php). So the problem is there.
Lester-chan (GaMerZ) has this to say regarding the new WordPress 2.6 constant change.
The constant only get loaded when you load WP. Plugins will have problem finding wp-config.php or wp-blog-header.php from the plugin file.
might be broken in WP 2.6
require_once('../../../wp-config.php');Long story, short
Below is my workaround for quick plugin activation setup. Its not the best solution as it involved the dirty “write-permission”, it need improvement. If you intent to uses it, there is few preliminary step to be set first:- ↓
- browse to your plugin dir
- create a blank php file: constant.php
- copy paste the below code save it as new file relative to the constant.php
- create or set your .htaccess and add Options All -Indexes.
Custom wp config file
function my_plugin_write_config() { $constant = get_defined_constants(true); $user_defined = $constant['user']; unset($constant); $constant = array(); // assuming that all latest wordpress CONSTANT start with WP_ $wp_constant_prefix = "/WP_/"; foreach($user_defined as $k=>$v){ if (preg_match($wp_constant_prefix,$k)){ $constant[$k] = $v; } } unset($user_defined); $constant['ABSPATH'] = (strtr(realpath(ABSPATH), array("\\", DIRECTORY_SEPERATOR))); $constant['WPINC'] = WPINC; $constant['WP_VERSION'] = get_bloginfo('version'); $constant = array_map('json_encode',$constant); $my_plugin_config_file = dirname(__FILE__).DIRECTORY_SEPARATOR.'constant.php'; if (is_writeable($my_plugin_config_file)) { $content = "<?php if(!defined('MY_PLUGIN_TOKEN')) die('42');\n"; foreach($constant as $k=>$v){ $content .= sprintf('define(\'CONST_%1s\', %2s);',strtoupper($k),$v)."\n"; } unset($constant,$k,$v); $content .= "?>"; $fp = false; if ( ($fp = fopen($my_plugin_config_file,'w+') ) != false) { stream_set_blocking($fp, TRUE); stream_set_timeout($fp,5); stream_set_write_buffer($fp, 0); fwrite($fp, $content); fclose($fp); } unset($content,$my_plugin_config_file,$fp); } else { add_action('admin_notices','my_plugin_notification'); } } function my_plugin_notification() { ?> <div id="message" class="error"> <h3><?php _e('ERR') ?> </h3> <p><a href="http://doc.myplugin.com"><? _e('RTFM!'); ?></a></p> </div> <?php } register_activation_hook(__FILE__, 'my_plugin_write_config' ); add_action('update_option_siteurl','my_plugin_write_config'); add_action('update_option_home','my_plugin_write_config');Basically this script will search all user defined constant that start with “WP_” prefix, plus additional wordpress constant. Then it will write all these constant to disk inside “constant.php” (once). It also runs after a WordPress option has been update (active when user update settings for home & siteurl, I add the extra action hook just for example).
Deprecated Functions
Out of all this issue I still think WordPress as one of the best “back-compat friendly” CMS. Most of the legacy functions & variables (since version 0.71 >= 2.5) is still available inside WordPress system (wp-includes/deprecated.php). Not sure how long it will stay there..
Might be interested
-
- July 2, 2008 at 4:55 pm
- July 5, 2008 at 11:18 am
- 0.3
- url
-
-
-
No Responses to “WP 2.6 user defined constant”
Trackback URL: Use the TrackBack url ↑ to ping this article. If your blog does not support Trackbacks you might want to leave a comment instead.
-
-
"write as if you were talking to a good friend (in front of your mother)."
.haveyoursay
Disclaimer: For any content that you post, you hereby grant to Kaizeku Ban the royalty-free, irrevocable, perpetual, exclusive and fully sublicensable license to use, reproduce, modify, adapt, publish, translate, create derivative works from, distribute, perform and display such content in whole or in part, world-wide and to incorporate it in other works, in any form, media or technology now known or later developed. Some rights reserved.
-
The following "Code" are designed to protect you and other users of this site.
In order to keep these experiences enjoyable and interesting for all of our users, we ask that you follow the above guidlines.
be the first to comment.