php - Wordpress plugin, trying to pass variable from admin page to function

470

I'm trying to add an admin panel to a WordPress plugin. It's my first attempt with working on a plugin and I don't use PHP frequently. My problem is getting values entered in the admin panel to where they need to be used in the functionbp_tweet_button_activity_filter(). The values are saved and displayed fine on the admin page. I've been hacking it for a bit and may have added a little bit of superfluous code. I think the problem is in the beginning lines of that function, or maybe towards the beginning of thetweet_urls_menu_options function.

The plugin takes the link of an activity stream post and shortens it with a custom YOURLS URL shortener, so the values needed are the username, password, and URL of the API for the shortener.

Thank you for any help or advice, I'll be continuing to read up on PHP and plugin development in the meantime.

Note: plugin originally modified from BuddyPress Tweet Button by modem looper.

278

Answer

Solution:

I just figured it out, thanks to any who looked at this.

My problem was in this part of the code, going from this:

function bp_tweet_button_activity_filter() {

    //admin username
    $username = get_option('opt_val');
    //admin password
    $password = get_option('opt_val_pass');
    //url to your custom YOURLS site API
    $api_url = get_option('opt_val_api'); //

    //get activity stream post link
    $url = bp_get_activity_thread_permalink();
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $api_url);
    curl_setopt($ch, CURLOPT_HEADER, 0);            // No header in the result
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return, do not echo result
    curl_setopt($ch, CURLOPT_POST, 1);              // This is a POST request
    curl_setopt($ch, CURLOPT_POSTFIELDS, array(     // Data to POST
        'url'      => $url,
        'keyword'  => $keyword,
        'format'   => $format,
        'action'   => 'shorturl',
        'username' => $username,
        'password' => $password

to this:

function bp_tweet_button_activity_filter() {


    //get activity stream post link
$url = bp_get_activity_thread_permalink();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, get_option('api_url'));
curl_setopt($ch, CURLOPT_HEADER, 0);            // No header in the result
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return, do not echo result
curl_setopt($ch, CURLOPT_POST, 1);              // This is a POST request
curl_setopt($ch, CURLOPT_POSTFIELDS, array(     // Data to POST
    'url'      => $url,
    'keyword'  => $keyword,
    'format'   => $format,
    'action'   => 'shorturl',
    'username' => get_option('username'),
    'password' => get_option('password')
));

People are also looking for solutions to the problem: php - MySQL connection error in configuration file

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.