inc2734/wp-github-theme-updater

一个用于WordPress的库,可自动使用GitHub API更新主题。

3.1.9 2024-09-24 01:38 UTC

README

CI Latest Stable Version License

安装

$ composer require inc2734/wp-github-theme-updater

如何使用

<?php
$updater = new Inc2734\WP_GitHub_Theme_Updater\Bootstrap(
  get_template(),
  'user-name',
  'repository'
);

过滤钩子

inc2734_github_theme_updater_zip_url_<$user_name>/<$repository>

自定义下载包的URL。

add_filter(
  'inc2734_github_theme_updater_zip_url_inc2734/snow-monkey',
  function( $url, $user_name, $repository, $tag_name ) {
    return $url;
  },
  10,
  4
);

inc2734_github_theme_updater_request_url_<$user_name>/<$repository>

自定义请求的API URL。

add_filter(
  'inc2734_github_theme_updater_request_url_inc2734/snow-monkey',
  function( $url, $user_name, $repository ) {
    return $url;
  },
  10,
  3
);

inc2734_github_theme_updater_transient_response_<$user_name>/<$repository>

自定义短暂响应

add_filter(
  'inc2734_github_theme_updater_transient_response_inc2734/snow-monkey',
  function( $transient_response ) {
    return $transient_response;
  }
);

inc2734_github_theme_updater_repository_content_url_<$user_name>/<$repository>

自定义内容API URL。

add_filter(
  'inc2734_github_theme_updater_repository_content_url_inc2734/snow-monkey',
  function( $url, $user_name, $repository, $theme_name ) {
    return $url;
  },
  10,
  4
);

inc2734_github_theme_updater_repository_content_headers_<$user_name>/<$repository>

自定义fields_contents_api字段。

add_filter(
  'inc2734_github_theme_updater_repository_content_headers_inc2734/snow-monkey',
  function( $headers ) {
    return $headers;
  }
);

inc2734_github_theme_updater_zip_url

自v2.0.0版本已弃用

自定义下载API URL。

add_filter(
  'inc2734_github_theme_updater_zip_url',
  function( $url, $user_name, $repository, $tag_name ) {
    if ( 'inc2734' === $user_name && 'snow-monkey-blocks' === $repository ) {
      return 'https://example.com/my-custom-updater-zip-url';
    }
    return $url;
  },
  10,
  4
);

inc2734_github_theme_updater_request_url

自v2.0.0版本已弃用

自定义请求的API URL。

add_filter(
  'inc2734_github_theme_updater_request_url',
  function( $url, $user_name, $repository ) {
    if ( 'inc2734' === $user_name && 'snow-monkey' === $repository ) {
      return 'https://example.com/my-custom-updater-request-url';
    }
    return $url;
  },
  10,
  3
);