Created
March 27, 2021 03:53
-
-
Save csaborio001/e1e4847490ea5ad8ee780577fbc78111 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Oxygen helper class to define when to display search results. | |
* | |
* @package scorpiotek-wordpress-utilities | |
*/ | |
namespace ScorpioTek\WPUtil\Oxygen; | |
class SearchAssist { | |
/** | |
* Initialises the condtition to show up in Oxygen's interface and assigns | |
* the callback function. | |
*/ | |
public function __construct() { | |
if( function_exists( 'oxygen_vsb_register_condition' ) ) { | |
global $oxy_condition_operators; | |
oxygen_vsb_register_condition( | |
'Has Results', | |
array( | |
'options' => array( | |
'true', | |
'false', | |
), | |
'custom' => false, | |
), | |
array( | |
'==', | |
), | |
array( | |
$this, | |
'search_has_results_callback', | |
), | |
'Search' | |
); | |
} | |
} | |
/** | |
* Callback function to figure out if the search yielded any results. | |
* | |
* @param mixed $value - the value of the search, only false if nothing was found. | |
* @param mixed $operator - the operator to use for comparison. | |
* @return void | |
*/ | |
function search_has_results_callback( $value, $operator ) { | |
global $wp_query; | |
$posts_found = $wp_query->found_posts; | |
if ( 'true' === $value && $posts_found > 0 ) { | |
return true; | |
} elseif( 'false' === $value && 0 === $posts_found ) { | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment