PHP making difference between get with and without value - php

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.

Related

Sanitizing the code as per wpcs for yoda condition checks

i am trying to cleanup the file with phpcs --standard=Wordpress ../filename.php . But it seems phpcbf is unable to perform the action. So, can anyone share some help as how can i manually fix these doc comment and yoda errors. Attached is related chunk of code and the snip of the actual php file and the errors encountered. Any help would be highly appreciated.
<?php
function is_blog() {
return ( is_archive() || is_author() || is_category() || is_home() || is_single() || is_tag() ) && 'post' == get_post_type();
}
?>
<?php do_action( 'generate_before_footer' ); ?>
<div <?php generate_footer_class(); ?>>
<?php
do_action( 'generate_before_footer_content' );
// Get how many widgets to show.
$widgets = generate_get_footer_widgets();
if ( ! empty( $widgets ) && 0 !== $widgets ) :
// Set up the widget width.
$widget_width = '';
if ( $widgets == 1 ) {
$widget_width = '100';
}
if ( $widgets == 2 ) {
$widget_width = '50';
}
if ( $widgets == 3 ) {
$widget_width = '33';
}
if ( $widgets == 4 ) {
$widget_width = '25';
}
if ( $widgets == 5 ) {
$widget_width = '20';
}
?>
Above the is_blog() function, you'll need to add a docblock:
/**
* Function comment here.
*
*/
function is_blog() {
}
Yoda conditions are when you write the value to compare against before the variable you are comparing. So instead of:
if ( $widgets == 1 ) {
$widget_width = '100';
}
It wants you to write:
if ( 1 == $widgets ) {
$widget_width = '100';
}
Changing those things should get the file passing the checks.

Redux Framework Custom Rest Api / Export

I want to learn how I can change this export link to custom?
wp-admin/admin-ajax.php?action=redux_download_options-custom&secret=c232a146b76ca2976c6a7a345f3c7432
Like :
wp-admin/admin-ajax.php?action=redux_download_options-custom&secret=custom_export
I need to see what they change something for mobile apps.
Thanks for helping me ;)
extentions_import_export.php line 136
change md5 checks to "custom_export_uri"
function link_options() {
if ( ! isset( $_GET['secret'] ) || $_GET['secret'] != 'custom_export_uri' ) {
wp_die( 'Invalid Secret for options use' );
exit;
}
$var = $this->parent->options;
$var['redux-backup'] = '1';
if ( isset( $var['REDUX_imported'] ) ) {
unset( $var['REDUX_imported'] );
}
echo json_encode( $var );
die();
}
public function download_options() {
if ( ! isset( $_GET['secret'] ) || $_GET['secret'] != 'custom_export_uri' ) {
wp_die( 'Invalid Secret for options use' );
exit;
}
Then "field_import_export.php" line 74
public function render() {
$secret = 'custom_export_uri';
admin-ajax.php?action=redux_download_options-port&secret=custom_export_uri

Getting this error "Trying to get property of non-object" for a function

This is a function to removed some banners, I know the error is happening around the if ( ! in_array( $current_screen->post_type, $post_types ) ) but I don't know to properly fix it.
function lsx_tec_disable_lsx_banner( $disabled ) {
global $current_screen;
$post_types = apply_filters( 'tribe_is_post_type_screen_post_types', Tribe__Main::get_post_types() );
if ( ! in_array( $current_screen->post_type, $post_types ) ) {
$disabled = true;
}
if ( is_null( $id ) && false !== strpos( $current_screen->id, 'tribe' ) )
{
$disabled = true;
}
if ( is_single() && tribe_is_event() ) {
$disabled = true;
}
return $disabled;
}
please check below link and change your code.
https://codex.wordpress.org/Function_Reference/get_current_screen
<?php
$current_screen = get_current_screen(); // use this instead of global $current_screen;
?>

woocommerce override of product

I have a problem with the following code when I make the price variable the function doesn't work but when I hardcode a price it works. (note I am in a testing face and haven't worried about security)
this, down't work:
function add_custom_price( $cart_obj ) {
global $product, $woocommerce ,$wpdb;
if ( isset( $_POST['fra'] ) ){
$GLOBALS['$_fra'] = urldecode( $_POST["fra"] );
} else {
$GLOBALS['$_fra'] = "";
}
if ( isset( $_POST['til'] ) ){
$GLOBALS['$_til'] = urldecode($_POST["til"]);
} else {
$GLOBALS['$_til'] = "";
}
if ( $GLOBALS['$_til'] !="" && $GLOBALS['$_fra'] !="" ){
$t1 = urldecode( $GLOBALS['$_til'] );
$t2 = urldecode( $GLOBALS['$_fra']);
$objArray = $wpdb->get_results("SELECT $t1 FROM test_priser WHERE city = '$t2'");
if ( isset($objArray[0]->$t1) ){
$priser = explode("/",$objArray[0]->$t1);
if ( !isset($priser[1]) ){
$priser[1] = intval($priser[0]);
}
}
echo "priser[1] = ".$priser[1]; //this outputs the expected value
}
if ( is_admin() && ! defined( 'DOING_AJAX' ) ){
return;
}
foreach ( $cart_obj->get_cart() as $key => $value ) {
$value['data']->set_price( $priser[1] );
}
}
When I add this line, and override the variable, it works:
$priser[1] = 1000;
I am quite confused as to what the problem might be.
for anyone else who might stumble upon this. Seems I need to pass the variable price in the session then it works.
you can find the answer here: custom price on woocommerce product

Redux WP Framework. Cannot disable 'dev_mode' with if statment

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
}

Categories