Skip to content

Commit

Permalink
Issue #54 - implement 'wp trace off <type>'
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Apr 23, 2018
1 parent 4813cd7 commit dcb3bf3
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions includes/class-trace-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
* # Display trace status
* $wp trace status
*
* # Enable tracing
* $wp trace on
* # Enable tracing for browser requests
* $wp trace on browser
*
* # Disable tracing for cli
* $wp trace off cli
Expand Down Expand Up @@ -69,7 +69,6 @@ class trace_command extends WP_CLI_Command {
* - ajax
* - rest
* - cli
* - all
*
* [--file=<trace_file_name>]
* : Base name of the trace file, relative to ABSPATH
Expand All @@ -86,9 +85,9 @@ class trace_command extends WP_CLI_Command {
* ## EXAMPLES
*
* wp trace on browser
*/
*/
public function on( $args, $assoc_args) {

WP_CLI::log( "Turning trace on" );
$type = bw_array_get( $args, 0, null );
if ( $type ) {
Expand Down Expand Up @@ -192,6 +191,22 @@ private function trace_on( $type, $args, $assoc_args ) {
$this->update_options();
}

/**
* Turns tracing off for the given type
*/
private function trace_off( $type, $args, $assoc_args ) {
$this->get_options();
$this->set_type( $type );
$this->set_type_suffix( $type );

// No need to get_option for trace
$this->set_option( "trace", true, "0" );

$this->update_options();
}



/**
* Gets the option value from assoc_args
*
Expand All @@ -216,7 +231,7 @@ private function get_option( $key, $use_suffix=false ) {
* @param string $default - default value
* @param bool $use_suffix - true when the suffix is required
*/
public function set_option( $key, $use_suffix=false, $value ) {
private function set_option( $key, $use_suffix=false, $value ) {
$index = $key;
if ( $use_suffix ) {
$index .= $this->suffix;
Expand All @@ -226,8 +241,23 @@ public function set_option( $key, $use_suffix=false, $value ) {
}
}

public function off() {
WP_CLI::line( "Turning trace off" );
public function off( $args, $assoc_args ) {
WP_CLI::log( "Turning trace off" );




WP_CLI::log( "Turning trace on" );
$type = bw_array_get( $args, 0, null );
if ( $type ) {
$type = $this->validate_type( $type );
WP_CLI::log( "Disabling trace type: $type" );
} else {
$type = 'browser';
WP_CLI::log( "Disabling default trace type: browser" );
}
$this->trace_off( $type, $args, $assoc_args );

}


Expand Down

0 comments on commit dcb3bf3

Please sign in to comment.