You could plop it into the database into a temporary storage area and then when wordpress “shutsdown” delete all the data from this temporary table. (or create a temporary table with MySQL).
Or, use cookies 😮
-Zack
Thread Starter
Carl
(@carlthome)
Exhaustive but doable workarounds. Good ideas!
I’m hoping for something more native and less labor-intensive though.
You can also wrap your plugin in a class too. That’s what I’m doing right now with the plugin I’m writing for work.
-Zack
I am having trouble passing variables into a function I am attaching to the admin_head hook. Is there something I’m missing here? I keep getting “Invalid argument supplied for foreach()”
$array = array('posts', 'links', 'comments');
add_action('admin_head','hides_menus');
<?php
function hides_menus() { ?>
<style type="text/css">
<?php
foreach ($array as $value) {
echo '#menu-' . $value . ', ';
} ?> { display:none; } </style>
<?php } ?>
Or do I have to do something with classes to fix this?
add_action('admin_head','hides_menus');
<?php
function hides_menus() {
$array = array('posts', 'links', 'comments');?>
<style type="text/css">
<?php
foreach ($array as $value) {
echo '#menu-' . $value . ', ';
} ?> { display:none; } </style>
<?php } ?>
perhaps?
Thanks esmi, that’s perfect (except for the “<?php” on the second line, but that was my fault). The only thing is it outputs the last comma, which breaks the CSS:
#menu-posts, #menu-links, #menu-comments, { display:none;}
In terms of best practices, what’s the best/most efficient way to remove the trailing comma? It could be done with a conditional, or with substr, like this:
substr($thelistofvalues, 0, -2);
Everything that I can think of makes the code a lot longer and harder to understand. Any suggestions?
How about:
add_action('admin_head','hides_menus');
function hides_menus() {
$array = array('posts', 'links', 'comments');?>
$output = '<style type="text/css">';
foreach ($array as $value) {
$output .= '#menu-' . $value;
if( $value != 'comments' ) $output .= ', ';
}
$output .= '{ display:none; } </style>';
echo $output;
}