1

there's a problem, I can not understand what I'm doing wrong ..

I want to get the value of the function of the other features in WordPress ..

This code replaces some parts of the code ..

I want to get the value of the argument variable words (it needs to go $attr['words']) and then use the other functions (new_quote).

    <?php
    /*
    * Plugin Name: Random Quotes
    */

    function random_quote($atts) {
        extract( shortcode_atts( array(
        'path' => plugin_dir_path(__FILE__).'quotes.txt',// default, if not set
        'label_new' => 'New Quote',
        'words' => 'no'   // yes or no 
        ), $atts ) );

        $temp = $attr['words']; // no
        ...

    }

    add_shortcode('randomquotes','random_quote');


    function new_quote(){
    global $temp;  // NULL
    /*
    global $attr;
    $temp = $attr['words']; // again NULL
    */
        ...

        if($temp == "no") {
        ...
        }
    }

   ...

?>

What am I doing wrong? Maybe just can not get the value of this variable?

1
  • Where are you running this new_quote() function? And why do you need it? Commented Oct 10, 2013 at 18:04

1 Answer 1

3

It looks like you need to declare global $temp within your random_quote() function. Right now, random_quote() is using a local version of $temp, which is lost when the function is completed.

EDIT: Here's an example snippet

<?php
function test() {
  global $temp;
  $temp = 'no';
}
function my_test() {
  global $temp;

  var_dump($temp);
}

test();
my_test();
?>
Sign up to request clarification or add additional context in comments.

10 Comments

What is returning NULL?
When a function is returned, then random_quote argument value (all right), but after the function is called new_quote, it returns NULL. This is an undefined value. But it should not be. I did all the functions of a global variable.
Can you edit your post to show the updates you did to the code to try and get it to work?
Ok, in your random_quote function, add "global $temp;" "above extract( shortcode_atts( array("
Solved the problem this way: simply pass this argument as a parameter query using AJAX. Thanks for the response anyway!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.