singleton.
*
* @since 2.0.9.1
*/
private function __construct() {
$this->debug = false;
$this->current_user_id = get_current_user_id();
if ( 0 == $this->current_user_id ) {
$this->debug = apply_filters( 'custom_sidebars_explain', $this->debug );
} else {
$this->debug = (boolean) get_user_meta( $this->current_user_id, 'custom_sidebars_explain', true );
$this->set_explain();
}
add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 999 );
if ( false === $this->debug ) {
return;
}
if ( is_admin() ) {
return;
}
add_action( 'cs_explain', array( $this, 'add_info' ), 10, 2 );
add_action( 'wp_footer', array( $this, 'show_infos' ) );
add_action( 'dynamic_sidebar_before', array( $this, 'before_sidebar' ), 0, 2 );
add_action( 'dynamic_sidebar_after', array( $this, 'after_sidebar' ), 0, 2 );
add_action( 'wp_print_styles', array( $this, 'print_styles' ) );
}
/**
* Returns true if the "explain mode" is enabled.
* Explain mode will display additional information in the front-end of the
* website on why which sidebar/widget is displayed.
* This is a per-user option (stored in current session)
*
* @since 2.0.9.1
* @return boolean
*/
public function do_explain() {
return $this->debug;
}
/**
* Sets the explain state
*
* @since 2.0.9.1
* @param string $state [on|off]
*/
public function set_explain() {
if ( ! isset( $_GET['cs-explain'] ) ) {
return;
}
if ( current_user_can( 'manage_options' ) && 'on' == $_GET['cs-explain'] ) {
$this->debug = true;
$result = add_user_meta( $this->current_user_id, 'custom_sidebars_explain', $this->debug, true );
if ( ! $result ) {
update_user_meta( $this->current_user_id, 'custom_sidebars_explain', $this->debug );
}
return;
}
$this->debug = false;
delete_user_meta( $this->current_user_id, 'custom_sidebars_explain' );
}
/**
* Adds an info to the explanation output.
*
* @since 2.0.9.1
*/
public function add_info( $info, $new_item = false ) {
if ( $new_item || 0 === count( $this->infos ) ) {
$this->infos[] = $info;
} else {
$this->infos[ count( $this->infos ) - 1 ] .= '
' . $info;
}
}
/**
* Outputs the collected information to the webpage.
*
* @since 2.0.9.1
*/
public function show_infos() {
?>