dhempy
Forum Replies Created
-
I abandoned the get_header approach, above, and created a shortcode instead. Details here: https://www.ads-software.com/support/topic/plugin-user-switching-template-tag-show-switch-back-link?replies=4
Forum: Plugins
In reply to: [User Switching] [Plugin: User Switching] Template tag show switch back linkOK… I implemented a shortcode to insert a switchback link.
You can call it from PHP like this, with or without a custom message:
<?php echo do_shortcode( "[switch_back_link]" ) ?> <?php echo do_shortcode( "[switch_back_link]WARNING: Don't use the logout button![/switch_back_link]" ) ?>
To do this, I added this line in __construct():
add_shortcode('switch_back_link', array($this,'switch_back_link_shortcode'));
I initially wrote switch_back_link_shortcode() as a call to admin_notice() wrapped in ob_start() … ob_end_clean(), but I couldn’t get it to work. The script quietly aborted in or around admin_notice(). Probably something a more experienced PHP programmer would figure out, but it stumped me. So I just copied the guts of admin_notice() into my function. Not elegant, but gets me what I need.
function switch_back_link_shortcode ($atts, $content = null) { global $user_identity, $user_login; ob_start(); if ( $old_user = $this->get_old_user() ) { ?> <div id="user_switching" class="updated"> <p><?php if ( isset( $_GET['user_switched'] ) ) printf( __( 'Switched to %1$s (%2$s).', 'user_switching' ), $user_identity, $user_login ); printf( ' <a href="%s">%s</a>.%s', $this->switch_back_url(), sprintf( __( 'Switch back to %1$s (%2$s)', 'user_switching' ), $old_user->display_name, $old_user->user_login ), (!is_null($content) ? " <span>$content</span>" : "" ) ); ?></p> </div> <?php } else if ( isset( $_GET['user_switched'] ) ) { ?> <div id="user_switching" class="updated"> <p><?php if ( isset( $_GET['switched_back'] ) ) printf( __( 'Switched back to %1$s (%2$s).', 'user_switching' ), $user_identity, $user_login ); else printf( __( 'Switched to %1$s (%2$s).', 'user_switching' ), $user_identity, $user_login ); ?></p> </div> <?php } $sb_link = ob_get_contents(); ob_end_clean(); return $sb_link; }
I’ve not tested this extensively, but it does work in header.php while switched and not.
John – Feel free to use or adapt this in any way you would like in your module. I’d rather abandon my branch if you do.
-dave
Forum: Plugins
In reply to: [User Switching] [Plugin: User Switching] Template tag show switch back link+1 for a shortcode to insert a switch back link.
Thanks, John. I’ll use that approach when I get some time.
FWIW, I ended up copying your plugin and hacking it with this addition:
add_action( 'get_header', array( $this, 'admin_notice' ), 1 ); // Added by dhempy 9/14/2012 11:16:15 since we don't have an admin bar or footer. // using get_header for this is a hack...it appears above <html>... probably will break some nuance of our styles. I'll repent later. // would be better to find a good action hook at the top of the page, but I failed at that. *sigh* -dave
I wanted to call add_action() from our own code so it wouldn’t break our update path with user-switching, but could not figure out how to add an action to a class function from outside the class.
Thanks for the reply, and the great module.
-dave
Would this be possible:
While impersonating another user, if you click “Logout” you either a) revert back to yourself; or b) log your primary (admin) session out, so that you could then log in anew?
Either of those would be a boon to me, and perhaps helpful to others. This could be in addition to the “Switch Back” button you already have.
-dave
Oh yeah…we also restrict multiple logins from the same account. This coupled with the inability to Switch Back resulted in me being locked out of my admin account until it timed out on its own. That was the core of my problem.
Again, this is probably a pretty unique scenario, I acknowledge.
-dave
Forum: Plugins
In reply to: [PHP Execution] PHP tags get 'commented' outAny more info on this? I am seeing the same problem with php-execution plugin. I can write this in the HTML editor…
<?php
$voucher = intval($_GET[“voucher”]);
if ($voucher) {
echo “You are redeeming this voucher: [$voucher]\n”;
}
?>(Note – not sure if the formatting above will carry through in this forum, but assume it’s nice, tidy, functional PHP)
…and after switching to Visual and back to HTML, it becomes:
<!–?php $voucher = intval($_GET[“voucher”]); if ($voucher) { echo “You are redeeming this voucher: [$voucher]\n”; } ?–>
(In case the formatting is changed in this forum, the significant difference is that the entire php block has been converted into an HTML comment. Of further annoyance, it’s been wrapped into a single line of text.)
I am running a fairly clean install of WordPress v3.2.1 and v1.0.0 of PHP-Execution.
I see this plugin is now two years old, with no updates. Should I simply use another PHP plugin? Any suggestions?
Thanks,
-daveForum: Fixing WordPress
In reply to: Media Attach – Search returning no results.I had this problem, as described here: https://www.ads-software.com/support/topic/unable-to-attach-media-to-new-post?replies=3#post-2264559
For me, it works in IE8, but not FireFox 5.0.
Go figger.
Forum: Fixing WordPress
In reply to: Unable to attach media to new postMore info – The problem above is in FireFox 5.0.
For some reason, the login box is not showing in Chrome.
I dusted off IE v8 (first time in months!) and it works there.
FWIW,
-daveForum: Fixing WordPress
In reply to: Unable to attach media to new postSame here. I get the pop-up asking to search posts, pages, etc. If I search for something I know is in a post, I get a blank stare. If I search for something that doesn’t exist (“asfaslkfj;aslf jas;fd”), I get “No posts found.”
So clearly the search is able to detect if the search succeeds, but is foobar’d before it can display the results.
As such, I can’t attach media to posts.
Any suggestions?