Category: WordPress

CMS WordPress

Programmatically Sign-on a WordPress User, the true way!

function rsf_programmatic_login( $username ) { if ( is_user_logged_in() ) { wp_logout(); } add_filter( ‘authenticate’, ‘allow_programmatic_login’, 10, 3 ); // hook in earlier than other callbacks to short-circuit them $user = wp_signon( array( ‘user_login’ => $username ) ); remove_filter( ‘authenticate’, ‘allow_programmatic_login’, 10, 3 ); if ( is_a( $user, ‘WP_User’ ) ) { wp_set_current_user( $user->ID, $user->user_login ); […]

CMS PHP WordPress

Buffering WordPress rendered page

if( current_user_can(‘manage_options’) ) { add_action(‘template_redirect’, ‘YOURPLUGIN_buffer_start’, 0); } function YOURPLUGIN_buffer_start() { add_action(‘shutdown’, ‘YOURPLUGIN_buffer_stop’, PHP_INT_MAX); ob_start(‘YOURPLUGIN_modify_content’); } function YOURPLUGIN_buffer_stop() { ob_end_flush(); } function YOURPLUGIN_modify_content($content) { $dom = new DomDocument(); $dom->loadHTML($content); $styles=array(); foreach ($dom->getElementsByTagName(‘link’) as $node) { if($node->hasAttribute(‘rel’) && $node->getAttribute(‘rel’)==’stylesheet’ ) { $styles[]=$node->getAttribute(“href”); } } //modify $content return serialize($styles).$content; }