spot_img
HomeWordPress教程wordpress建站公司 WordPress.org API - 获取插件作者最喜欢的插件

wordpress建站公司 WordPress.org API – 获取插件作者最喜欢的插件

spot_img

JasperAI 10000字免费额度试用

WordPress.org 插件存储库最近增加了一些内容。 最值得注意的是对插件页面和作者个人资料页面的更改,现在显示作者最喜欢的插件。

我想创建一个显示插件作者收藏夹的侧边栏小部件插件。 我知道如何使用 API 获取插件统计信息,并且还阅读了 DD32 的 API 文档,但我不相信配置文件中存在文档,或者配置文件 API 是否存在。

我试图使用 wp_remote_get 而且我能够从个人资料页面获取正文 html,但还没有尝试尝试解析它,因为这似乎是一种混乱的处理方式。 如果我能获得 XML 或 json 格式的配置文件,那就太好了。

是否有我遗漏的任何方法或是否存在配置文件 API?

WordPress divi主题

编辑:

好的,我在 github 上有一个使用 SimpleHTML Dom 解析器的 beta 版本。 我认为我无法获得星级评分,但我对第一次没有 API 的结果感到非常满意。

WordPress.org 不允许内容抓取并将禁止您(通过@otto)。 因此,在发布公共 API 之前,这是不行的。

还没有。

奥托周三表示“很快”。 但他这个周末去烧烤了,所以“很快”可能是“这个月”。 ;)

编辑:

Otto42:@Ipstenu @EricMann 我有执行此操作的代码,但尚未部署。 关于最佳方式的一些争论。 它最终会在那里。

高质量外链购买

最喜欢的插件已添加到 WordPress.org API。 3.5 中有一项新功能,允许您从插件安装程序访问您的收藏夹。

WordPress建站服务

有关如何在核心中使用它的信息,请参阅 http://core.trac.wordpress.org/ticket/22002。

API 允许您检索包含每个插件的对象

  • 姓名
  • 描述
  • 作者
  • 评分
  • 最后更新日期
  • 更改日志
  • 稳定版
  • 适用于 wp 版本

检索对象

使用 wp_remote_post 调用 http://api.wordpress.org/plugins/info/1.0/ 传递参数数组,包括将是“query_plugins”的操作和 wp dot org 用户名以从中检索收藏夹。

$request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))) );

在你有一个漂亮干净的对象之前,你需要做一些错误处理和其他解析。 这是一个示例函数,它将返回一个漂亮干净的对象,其中包含所有插件详细信息。

function api( $action, $args ) {
        if ( is_array( $args ) )
            $args = (object) $args;

        $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))) );
        if ( is_wp_error($request) ) {
            $res = new WP_Error('plugins_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.' ), $request->get_error_message() );
        } else {
            $res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
            if ( ! is_object( $res ) && ! is_array( $res ) )
                $res = new WP_Error('plugins_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.' ), wp_remote_retrieve_body( $request ) );
        }

        return apply_filters( 'c3m_favorite_results', $res, $action, $args );
    }

用法

此示例用法将为您提供最喜欢的插件的无序列表以及指向 dot org 上的插件的链接、指向作者 uri 和星级的链接。

$api_data = api( 'query_plugins', array( 'user' => 'my_dot_org_username' ) );
$api_plugins = $api_data->plugins;

echo '<ul class="c3m-favorites">';
        foreach( $api_plugins as $plugin ) {

            $name = $plugin->name; ?>
            <li><strong><a target="_blank" href="http://wordpress.org/extend/plugins/<?php echo $plugin->slug ?>/"><?php echo esc_html( $name ); ?></a></strong><br>

                <div class="star-holder" title="<?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $plugin->num_ratings ), number_format_i18n( $plugin->num_ratings ) ); ?>">
                <div class="star star-rating" style="width: <?php echo esc_attr( str_replace( ',', '.', $plugin->rating ) ); ?>px"></div></div>

                <em><?php _e('By: ') ?></em> <?php echo links_add_target( $plugin->author, '_blank' ). '<br>'; ?>
            </li><?php
        }
        echo '</ul>';

结果

在此处输入图像描述

wordpress建站公司

我最喜欢的插件小部件插件的小部件屏幕截图:http://wordpress.org/extend/plugins/favorite-plugins-widget/

5分钟生成10篇英文软文article forge软件试用
siteground guangda
WordPress花园官方账号
WordPress花园隶致力于为广大跨境电商和独立站爱好者提供优质的WordPress教程、Woocommerce教程、Facebook、Twitter、tiktok、Instagram教程和谷歌SEO教程等资料和对应的建站推广服务。关注‘哟派出海’公众号了解最新资讯。粉丝福利:Shopline免费独立站建设14天优惠 商务合作: [email protected]
RELATED ARTICLES