I have a problem.
I want to disable 'dev_mode' if 'opt_name' not redux_demo, using the if statment, but it did not work ... where does the fault ??
I found the code on Here
and I turn it into like this
if ( ! function_exists( 'redux_disable_dev_mode_plugin' ) ) {
function redux_disable_dev_mode_plugin( $redux ) {
if ( $redux->args['opt_name'] != 'redux_demo' ) {
if ( $redux->args['dev_mode'] == true ) {
$redux->args['dev_mode'] = false;
}
} else {
if ( $redux->args['dev_mode'] == false ) {
$redux->args['dev_mode'] = true;
}
}
}
add_action( 'redux/construct', 'redux_disable_dev_mode_plugin' );
}
the above code, I input in config.php
Thanks B4 and sorry my english is not good. :D
You can also filter the args JUST for your opt_name using this:
apply_filters( "redux/args/{$this->args['opt_name']}", $this->args );
if ( ! function_exists( 'redux_disable_dev_mode_plugin' ) ) {
function redux_disable_dev_mode_plugin( $redux ) {
if ( $redux->args['opt_name'] != 'redux_demo' ) {
$redux->args['dev_mode'] = false;
}
}
add_action( 'redux/construct', 'redux_disable_dev_mode_plugin' );
}
In framework.php (for me it's from line 1281). It worked for me after making those two attr false.
// Force dev_mode on WP_DEBUG = true and if it's a local server
if ( Redux_Helpers::isLocalHost() || ( Redux_Helpers::isWpDebug() ) ) {
if ( $this->args['dev_mode'] != true ) {
$this->args['update_notice'] = false;
}
$this->dev_mode_forced = true; // make it false
$this->args['dev_mode'] = true; //make it false
}
Related
Good day,
I would like to know if there is any function for making the difference between this:
?param=
and this:
?param
Because I would like my script to detect if value is empty (first example), or if it's not given (second example).
I made a test with the following functions but I could not find what I want:
if( isset( $_GET['param'] ) ) {
echo '<div>isset</div>';
if( empty( $_GET['param'] ) ) {
echo '<div>empty</div>';
} else {
echo '<div>not empty</div>';
}
if( is_null( $_GET['param'] ) ) {
echo '<div>null</div>';
} else {
echo '<div>not null</div>';
}
if( defined( $_GET['param'] ) ) {
echo '<div>defined</div>';
} else {
echo '<div>undefined</div>';
}
} else {
echo '<div>not set</div>';
}
Any idea? Thank you in advance.
EDIT
Solution:
( strpos( '?'.$_SERVER['QUERY_STRING'], '?get=' ) !== false ) || ( strpos( '?'.$_SERVER['QUERY_STRING'], '&get=' ) !== false )
You can test with something like if( $_GET['param'] ) which will give true if Param is declared (even if it is an empty string) and false if not declared.
I made this function in php to check if a parent XML has already got a xml to insert it or not :
function has_xml_node( \DOMElement $needle, \DOMElement $node ) {
if( $node->hasChildNodes() ){
foreach ( $node->childNodes as $childNode ) {
if( $needle->isEqualNode( $childNode ) ){
return true;
}
}
}
return false;
}
I got this php error :
DOMNode::isEqualNode(): Not yet implemented in ...
How can I fix this ?
I found the solution here.
Use $needle->isSameNode( $childNode );
BUT it seems to check 'baseURI' as well so if you have two same tags but from different xml files, $needle->isSameNode( $childNode ); return false.
I made a function to work around this problem.
function is_same_node( \DOMNode $node_to_compare, \DOMNode $node_refered, $with_attributes = true ) {
if( $node_to_compare->tagName !== $node_refered->tagName )
return false;
if( $node_to_compare->nodeValue !== $node_refered->nodeValue )
return false;
if( $node_to_compare->prefix !== $node_refered->prefix )
return false;
if( $with_attributes ){
if( !$node_to_compare->hasAttributes() && $node_refered->hasAttributes() ){
return false;
}else{
if( !$node_refered->hasAttributes() && $node_to_compare->hasAttributes() ){
return false;
}else{
foreach ( $node_to_compare->attributes as $attribute ){
$find_attribute_with_same_value = false;
foreach ( $node_refered->attributes as $attribute_refered ){
if(
$attribute_refered->name === $attribute->name
&& ( $attribute_refered->value === $attribute->value )
){
$find_attribute_with_same_value = true;
}
}
if( !$find_attribute_with_same_value )
return false;
}
}
}
}
return true;
}
How can I create an array of multiple endpoint for the below custom conditional code?
function is_single_with_endpoint( $endpoint ) {
global $wp_query;
if ( ! isset( $endpoint ) && ! empty( $endpoint ) ) {
return false;
}
if ( array_key_exists( $endpoint, $wp_query->query_vars ) ) {
return true;
} else {
return false;
}
}
This will work is I use
if ( ! is_single_with_endpoint('overview') && ! is_single_with_endpoint('analytics') ) {
but not as
if ( ! is_single_with_endpoint(array('overview','analytics')) ){
We can just step through the array of inputs and check each one for a failure. If none of them produce failure, then it passes at the end.
function is_single_with_endpoint($endpoints) {
global $wp_query;
// Iterate through set (can be set of one)
foreach ((array)$endpoints AS $endpoint) {
if (empty($endpoint)) {
return false;
}
if (!array_key_exists($endpoint, $wp_query->query_vars)) {
return false;
}
}
// Didn't fail, so it passes
return true;
}
I would do this, instead:
function is_single_with_endpoint($endpoint = null){
global $wp_query;
if($endpoint === null){
return false;
}
if(is_array($endpoint)){
foreach($endpoint as $k => $v){
if(!array_key_exists($k, $wp_query->query_vars)){
return false;
}
}
}
else{
if(!array_key_exists($endpoint)){
return false;
}
}
return true;
}
I'm getting mysqli_get_server_info(): invalid object or resource mysqli error, when running wpdb outside of wordpress in a standalone 'plugin'.
Here's the code that returns the error:
private $use_mysqli = false;
if ( function_exists( 'mysqli_connect' ) ) {
if ( defined( 'WP_USE_EXT_MYSQL' ) ) {
$this->use_mysqli = ! WP_USE_EXT_MYSQL;
} elseif ( version_compare( phpversion(), '5.5', '>=' ) ||
! function_exists( 'mysql_connect' ) ) {
$this->use_mysqli = true;
} elseif ( false !== strpos( $GLOBALS['wp_version'], '-' ) ) {
$this->use_mysqli = true;
}
}
public function db_version() {
if ( $this->use_mysqli ) {
$server_info = mysqli_get_server_info( $this->dbh );
} else {
$server_info = mysql_get_server_info( $this->dbh );
}
return preg_replace( '/[^0-9.].*/', '', $server_info );
}
Why am I getting this error? How should I fix it?
I have created this function within a Class, And though it works, I think Its messy and can be simplified easily, What technique can i use to simplify this? Though i can use foreach, Every time it will make new directory in the Cache folder instead of creating directory within parent directory.
Example : $directory = 'page/subpage/homepage'
public static function add_directory( $directory, $cache_path ) {
$all_directories = explode( '/', $directory );
$total_directories = count( $all_directories );
if( $total_directories == 1 ) {
if( ! File::exists( $cache_path.'/'.$all_directories[0] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0] );
}
}
else if( $total_directories == 2 ) {
if( ! File::exists( $cache_path.'/'.$all_directories[0] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0] );
}
if( ! File::exists( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1] );
}
}
else if( $total_directories == 3 ) {
if( ! File::exists( $cache_path.'/'.$all_directories[0] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0] );
}
if( ! File::exists( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1] );
}
if( ! File::exists( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1].'/'.$all_directories[2] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1].'/'.$all_directories[2] );
}
}
else if( $total_directories == 4 ) {
if( ! File::exists( $cache_path.'/'.$all_directories[0] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0] );
}
if( ! File::exists( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1] );
}
if( ! File::exists( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1].'/'.$all_directories[2] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1].'/'.$all_directories[2] );
}
if( ! File::exists( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1].'/'.$all_directories[2].'/'.$all_directories[3] ) ) {
File::makeDirectory( $cache_path.'/'.$all_directories[0].'/'.$all_directories[1].'/'.$all_directories[2].'/'.$all_directories[3] );
}
}
else {}
}
Thanks.
You can specify whether you want to create directories recursively by setting true to your File::makeDirectory()'s third argument, so you can replace your entire code with something like this:
public static function add_directory( $directory, $cache_path ) {
if (!File::exists( $cache_path.'/'.$directory)) {
File::makeDirectory($cache_path . '/' . $directory, 0755, true);
}
}
Reference: Looks like it is not documented but it is in Laravel's source code for filesystem/Filesystem.php:
public function makeDirectory($path, $mode = 0755, $recursive = false, $force = false)
{
if ($force)
{
return #mkdir($path, $mode, $recursive);
}
else
{
return mkdir($path, $mode, $recursive);
}
}
From looking at your code - I dont see why this wouldnt work?
public static function add_directory( $directory, $cache_path ) {
if( ! File::exists( $cache_path.'/'.$directory ) ) {
File::makeDirectory( $cache_path.'/'.$directory );
}
}
There doesnt seem to need to be any need to 'explode' the array then rebuild it? This will build all the sub-directories along with it I believe...