If it helps, when I hack wpmvc.php to accept $_GET[‘argv’] and visit http://localhost/wp-content/plugins/wp-mvc/core/wpmvc.php?argv%5B%5D=caller&argv%5B%5D=generate&argv%5B%5D=plugin&argv=test in my browser, here’s the output:
[35;1m[4mWelcome to WP MVC Console![0m[0m Sorry, a shell named “e_shell” couldn’t be found in any of the MVC plugins. Please make sure a shell class exists in “app/shells/e_shell.php”, or execute “./wpmvc” to see a list of available shells.
Additionally, visiting http://localhost/wp-content/plugins/wp-mvc/core/wpmvc.php outputs
[35;1m[4mWelcome to WP MVC Console![0m[0m Available Shells: Core [1mDestroy[0m [1mGenerate[0m [1mHelp[0m To get information about a shell try: wpmvc help shell
and register_argc_argv is on.
No output at the terminal at all…
Fixed!
Added the following right before the include statement –
$_SERVER = array(
“HTTP_HOST” => “localhost”,
“SERVER_NAME” => “localhost”,
“REQUEST_URI” => “/”,
“REQUEST_METHOD” => “GET”
);
thanks to info found here – http://vocecommunications.com/blog/2011/03/running-wordpress-from-command-line/
I’d suspect this works on any setup, but I haven’t tested anywhere other than my local (should be localhost no matter what though, even if over ssh.)
In the case that’s correct, the author might like to add this code to the plugin, and better yet, add me as contributor… 🙂
I don’t doubt that the command line is working perfectly under Unix but for me it’s a pain under Windows.
If you’re like me and want to use the command line from your webserver replace the content of wp-mvc/core/wpmvc.php by:
<?php
//Allow command via html form only for localhost.
//If you dev on a distant server you might want to add it here
$allow_html_cmd_for = array('localhost', '127.0.0.1');
$command = null;
if (isset($argv))
{ //Run from command line
$command = $argv;
}
elseif (in_array($_SERVER['SERVER_ADDR'], $allow_html_cmd_for))
{ //No command line argument, use html form
if (isset($_POST['cmd']))
{ //Process form command
$command = array(__FILE__);
$command = array_merge($command, explode(' ', $_POST['cmd']));
}
//Display html form
?>
<h2>WP-MVC Command line</h2>
<form action="" method="POST" name="command">
wpmvc
<input type="text" name="cmd" size="100" value="<?php echo isset($_POST['cmd']) ? $_POST['cmd'] : '' ?>"/>
<button type="submit">Run command</button>
</form>
<script type="text/javascript">
//Make the input field behave like a prompt
input = document.forms['command'].elements['cmd'];
input.focus();
input.value = input.value;
</script>
<?php
}
if ($command !== null)
{ //Run command
$wordpress_path = getenv('WPMVC_WORDPRESS_PATH');
$wordpress_path = $wordpress_path ? rtrim($wordpress_path, '/').'/' : dirname(__FILE__).'/../../../../';
ob_start();
require_once $wordpress_path.'wp-load.php';
$shell = new MvcShellDispatcher($command);
$lines = ob_get_contents();
ob_end_clean();
if (isset($argv))
echo $lines."\n";
else
echo nl2br(preg_replace('/\[[0-9,;]*m/U', '', $lines));
}
?>
You can then access the form from your browser at something like: http://127.0.0.1/wp-content/plugins/wp-mvc/core/wpmvc.php
Error won’t display pretty because of the die() in the subfunctions but at least it’ll let you generate your plugin without having to dig in your php installation in case the command line isn’t working!