plugins_api example


    public function get_items( $request ) {
        require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
        require_once ABSPATH . 'wp-admin/includes/plugin.php';

        $response = plugins_api(
            'query_plugins',
            array(
                'block'    => $request['term'],
                'per_page' => $request['per_page'],
                'page'     => $request['page'],
            )
        );

        if ( is_wp_error( $response ) ) {
            $response->add_data( array( 'status' => 500 ) );

            

function install_popular_tags( $args = array() ) {
    $key  = md5( serialize( $args ) );
    $tags = get_site_transient( 'poptags_' . $key );
    if ( false !== $tags ) {
        return $tags;
    }

    $tags = plugins_api( 'hot_tags', $args );

    if ( is_wp_error( $tags ) ) {
        return $tags;
    }

    set_site_transient( 'poptags_' . $key$tags, 3 * HOUR_IN_SECONDS );

    return $tags;
}

/** * Displays the Featured tab of Add Plugins screen. * * @since 2.7.0 */
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
        require_once ABSPATH . 'wp-admin/includes/plugin-install.php';

        $slug = $request['slug'];

        // Verify filesystem is accessible first.         $filesystem_available = $this->is_filesystem_available();
        if ( is_wp_error( $filesystem_available ) ) {
            return $filesystem_available;
        }

        $api = plugins_api(
            'plugin_information',
            array(
                'slug'   => $slug,
                'fields' => array(
                    'sections'       => false,
                    'language_packs' => true,
                ),
            )
        );

        if ( is_wp_error( $api ) ) {
            
'slug'    => sanitize_key( wp_unslash( $_POST['slug'] ) ),
    );

    if ( ! current_user_can( 'install_plugins' ) ) {
        $status['errorMessage'] = __( 'Sorry, you are not allowed to install plugins on this site.' );
        wp_send_json_error( $status );
    }

    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    require_once ABSPATH . 'wp-admin/includes/plugin-install.php';

    $api = plugins_api(
        'plugin_information',
        array(
            'slug'   => sanitize_key( wp_unslash( $_POST['slug'] ) ),
            'fields' => array(
                'sections' => false,
            ),
        )
    );

    if ( is_wp_error( $api ) ) {
        $status['errorMessage'] = $api->get_error_message();
        

        iframe_footer();
    } elseif ( 'install-plugin' === $action ) {

        if ( ! current_user_can( 'install_plugins' ) ) {
            wp_die( __( 'Sorry, you are not allowed to install plugins on this site.' ) );
        }

        require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // For plugins_api().
        check_admin_referer( 'install-plugin_' . $plugin );
        $api = plugins_api(
            'plugin_information',
            array(
                'slug'   => $plugin,
                'fields' => array(
                    'sections' => false,
                ),
            )
        );

        if ( is_wp_error( $api ) ) {
            wp_die( $api );
        }

        $args = apply_filters( "install_plugins_table_api_args_{$tab}", $args );

        if ( ! $args ) {
            return;
        }

        $api = plugins_api( 'query_plugins', $args );

        if ( is_wp_error( $api ) ) {
            $this->error = $api;
            return;
        }

        $this->items = $api->plugins;

        if ( $this->orderby ) {
            uasort( $this->items, array( $this, 'order_callback' ) );
        }

        
Home | Imprint | This part of the site doesn't use cookies.