0

I've written some very simple code based off of this tutorial by Harish Chouhan on the Plugins API:

    /** Add Plugins API if not already existing */
if ( ! function_exists( 'plugins_api' ) )
    require_once( '../../wp-admin/includes/plugin-install.php' );


/** Add Internationalization if not already existing */
if ( ! function_exists( 'get_locale' ) )
    require_once( '../../wp-includes/l10n.php' );

/** Prepare our query */
$call_api = plugins_api( 'plugin_information', array( 'slug' => 'custom-favicon' ) );

/** Check for Errors & Display the results */
if ( is_wp_error( $call_api ) ) {

    echo '<pre>' . print_r( $call_api->get_error_message(), true ) . '</pre>';

} else {

    echo '<pre>' . print_r( $call_api, true ) . '</pre>';

    if ( ! empty( $call_api->downloaded ) ) {

        echo '<p>Downloaded: ' . print_r( $call_api->downloaded, true ) . ' times.</p>';

    }

}

The problem I am encountering is that it doesn't seem to be aware of the built-in WordPress functions. Why? I looked at Hello Dolly and I don't see any includes there?

[Additional Details; I'm running this in Cloud 9 (c9.io) and the file is in the plugins directory, same as hello.php]

  • 2
    Which functions namely? Which precise errors are you getting? – Rarst Oct 28 '15 at 16:55
  • @Rarst - Initially it was looking for plugins_api(), so I added the reference to plugin-install.php. Then it was looking for get_locale() so I added l10n.php. Now it is looking for is_multisite(). Errors look like: "Fatal error: Call to undefined function plugins_api() in /home/ubuntu/workspace/wp-content/plugins/plugin_api_plus.php on line 25 Call Stack: 0.0004 247152 1. {main}() /home/ubuntu/workspace/wp-content/plugins/plugin_api_plus.php:0" – davemackey Oct 28 '15 at 17:02
  • 1
    code should be hooked to run on an action. WordPress isn't fully loaded when your plugin file is loaded. – Milo Oct 28 '15 at 17:46
  • @Milo - What if I just want to have a page that doesn't necessarily "hook" into anything in WP? e.g., is there a general hook I can call? – davemackey Oct 28 '15 at 19:31
  • 1
    Use the AJAX-API, even if not technically AJAX: wordpress.stackexchange.com/a/108145/21376 – s_ha_dum Oct 28 '15 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.