Grow your CSS skills. Land your dream job.

PHP/WP – Apply function result to an object’s property

  • # August 3, 2010 at 11:29 pm

    That tile probably makes no sense. Sorry.

    What I’m doing: I’m using Chris’ Wufoo plugin to create a WP plugin. I have an options page setup in WP where I can store a username/subdomain, API Key, and Form Hash (just to start). I can get those options very easily with the get_option(); function.

    What I cannot figure out how to do is apply the sql results from the getUsername and getApiKey functions to their respective variables and then pass them to the WufooGetter class and corresponding object.

    Here’s the code for each class.

    Code:
    class jQueryConfig {

    public $username;
    public $api_key;

    public function getUsername() {
    global $wpdb;

    $sql = $wpdb->get_row(“SELECT * FROM $wpdb->options WHERE option_name = ‘w4wp_username’”);
    $this->username = $sql->option_value;

    return $this->$username;
    }

    public function getApiKey() {
    global $wpdb;

    $query = $wpdb->get_row(“SELECT * FROM $wpdb->options WHERE option_name = ‘w4wp_api_key’”);
    return $this->api_key = $query->option_value;
    }
    }

    Code:
    class WufooGetter {

    private $url;
    private $config;

    public function __construct($url, $config) {
    $this->url = $url;
    $this->config = $config;
    }

    public function makeCall() {

    $curl = curl_init(‘https://’.$this->config->subdomain.’.wufoo.com/’.$this->url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_USERPWD, $this->config->apiKey.’:footastic’);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_USERAGENT, ‘Wufoo Sample Code’);

    $response = curl_exec($curl);
    $resultStatus = curl_getinfo($curl);

    if ($resultStatus['http_code'] == 200) {
    echo $response;
    } else {
    echo ‘Call Failed ‘.print_r($resultStatus);
    }
    }
    }

    $wufooGetter = new WufooGetter($_GET['url'], new jQueryConfig());
    $wufooGetter->makeCall();

    And here’s the link to the jQuery Plugin on Git Hub http://github.com/wufoo/Wufoo-API-Wrappers/

    Any advice is greatly appreciated!

    Thanks.

    # August 12, 2010 at 11:02 pm

    AS far as I know this is the formal documentation of WP_Query. You shouldn’t alter the properties directly, but instead use the methods to interact with them. And Gets filled with the requested posts from the database.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".