Get GitHub File
Developed by azurecurve
Plugin Description
Gets the content of a file from a GitHub repository and outputs using the [github-file] shortcode.
Gets the content of a file from a GitHub repository and outputs using the [github-file] shortcode.
Settings allow default options, such as author, folder, filename to be specified. Additional options to allow the removal or conversion of WordPress headers in readme.txt files.
Available shortcode parameters:
-
account– account on GitHub -
branch– branch to get file from -
folder– folder containing the file -
file– file to get from GitHub repository -
repository– name of GitHub repository -
startfrom– text in file to start outputting from (e.g. # Description) -
htmlastext– 1 to output HTMl as text and 0 to output as HTML -
shortcodesastext– 1 to output shortcodes as text and 0 to output as shortcode -
wordpresstitles– remove/ignore/convert
All parameters except repository can be defined as defaults in settings.
Example shortcode usage:
[github-file branch="master" repository="azrcrv-get-github-file"]
Output is in markdown, but use of a plugin such as Markdown by azurecurve can convert this markdown to HTML markup. The shortcode’s line breaks are preserved on the front end even without a markdown plugin installed, but markdown syntax (headings, etc.) will only be converted to actual HTML by a markdown renderer such as that plugin.
Fetched files are cached (default one hour, filterable via azrcrv_gghf_cache_ttl) so a page using this shortcode does not fetch from GitHub on every page view; use the “Clear Cached Files” button on the Settings tab after updating the source file on GitHub.
This plugin is multisite compatible; settings need to be configured for each site.
- Download the latest release of the plugin from GitHub.
- Upload the entire zip file using the Plugins upload function in your ClassicPress admin panel.
- Activate the plugin.
- Configure relevant settings via the configuration page in the admin control panel (azurecurve menu).
Yes, the .pot file is in the plugin’s languages folder; if you do translate this plugin, please send the .po and .mo files to [email protected] for inclusion in the next version (full credit will be given).
This plugin is developed for ClassicPress, but will likely work on WordPress.
Many GitHub repositories now default to a branch called “main” rather than “master” – check the Default Branch setting, or the branch shortcode attribute, matches the repository’s actual default branch.
- Rebuilt to match the current azurecurve plugin architecture (namespaced code, settings/menu/shortcode split across includes files, tabbed admin UI matching Shortcodes in Comments).
- Fixed a bug where the “Output shortcodes as text?” setting/attribute had no effect, because the shortcode handler read the wrong array key (a copy-paste from the adjacent “Output HTML as text?” line) instead of
shortcodesastext. - Fixed a bug where
uninstall.phpdeleted the optionazrcrv-gff(a copy-paste leftover from the Gallery From Folder plugin’s uninstaller) instead of this plugin’s ownazrcrv-gghfoption, so the plugin’s settings were never actually removed on uninstall. - Replaced
file_get_contents()against a hand-built, unencoded URL withwp_remote_get()(the ClassicPress/WordPress HTTP API), adding a configurable timeout (default 10 seconds, filterable viaazrcrv_gghf_fetch_timeout) and distinct, translated error messages instead of a single generic “Could not get the file.” string. - Added transient caching of successfully fetched files (default one hour, filterable via
azrcrv_gghf_cache_ttl), so a page using the shortcode no longer makes a fresh outbound HTTP request to GitHub on every single page view. Added a “Clear Cached Files” button on the Settings tab. - Added a front-end stylesheet so the shortcode’s output preserves the fetched file’s line breaks (
white-space: pre-wrap) by default. Previously (both before and immediately after this rewrite) the plugin shipped no front-end CSS at all, so the fetched markdown’snline breaks were collapsed by the browser and everything ran together into a single unbroken block unless paired with a markdown-rendering plugin. - Added
markdown="1"to the shortcode’s<div class="azrcrv-gghf">wrapper element, so that pairing this plugin with a Markdown Extra-based renderer (such as Markdown by azurecurve) actually converts the fetched file’s markdown to HTML. Without this attribute, Markdown Extra correctly treats a<div>as a self-contained block of raw HTML and does not parse markdown inside it – this is standard Markdown Extra behaviour, not a bug in the renderer. - Fixed shortcode attribute values (account/repository/branch/folder/file) not being URL-encoded before being used to build the GitHub request URL, which could silently produce a broken request for values containing spaces or other URL-unsafe characters.
- Fixed an inefficient
plugin_action_linkshook so it no longer runs for every plugin on the Plugins list page (now registered against this plugin’s ownplugin_action_links_{$basename}hook). - Fixed the shared azurecurve plugin-menu list being rebuilt and written to the database on every single wp-admin page load; it’s now only rebuilt on plugin activation or update.
- Fixed submitted settings not being unslashed (
wp_unslash()) before sanitizing, which could leave stray backslashes in saved values containing a quote or backslash. - Fixed
wp_redirect()being used instead ofwp_safe_redirect()after saving settings. - Fixed a misuse of
esc_html_e()against a variable (get_admin_page_title()) instead of a literal string, which doesn’t actually translate anything and trips i18n linting; nowecho esc_html( get_admin_page_title() ). - Fixed missing
esc_url()/esc_url_raw()around dynamically-built admin and plugin-index links. - Removed a dead, non-functional
page_optionshidden form field left over from an unused WordPress Settings API convention. - Added an Instructions tab and a proper tabbed admin UI (Settings / Instructions / Other Plugins), matching Shortcodes in Comments.
- Added a proper
uninstall.phpfix as above, consistent with the rest of the azurecurve plugin family. - BREAKING: minimum PHP requirement raised to 8.2.
- BREAKING: text domain renamed from
get-github-filetoazrcrv-gghf; existing translation (.po/.mo) files must be re-supplied under the new domain. - Update readme.md and remove readme.txt (not required for ClassicPress).
- Update azurecurve menu.
- Update plugin header for compatibility with ClasssicPress v2.
- Update plugin header and readme for compatibility with ClassicPress Directory v2.
- Update Update Manager to version 2.5.0.
- Update readme file for compatibility with ClassicPress Directory.
- Update readme files.
- Update language template.
- Fix bug with azurecurve menu.
- Update azurecurve menu.
- Update readme files.
- Add uninstall.
- Update azurecurve menu and logo.
- Fix plugin action link to use admin_url() function.
- Rewrite option handling so defaults not stored in database on plugin initialisation.
- Add plugin icon and banner.
- Update azurecurve plugin menu.
- Fix bug with setting of default options.
- Fix bug with plugin menu.
- Update plugin menu css.
- Fix bug with wordpress_title default.
- Replace call to deprecated each PHP function.
- Rewrite default option creation function to resolve several bugs.
- Upgrade azurecurve plugin to store available plugins in options.
- Update Update Manager class to v2.0.0.
- Update azurecurve menu icon with compressed image.
- Initial release.
azurecurve was one of the first plugin developers to start developing for ClassicPress; all plugins are available from azurecurve Development and are integrated with the Update Manager plugin for fully integrated, no hassle, updates.
The plugins available from azurecurve are:
- Add Open Graph Tags – details / download
- Add Twitter Cards – details / download
- Avatars – details / download
- BBCode – details / download
- Breadcrumbs – details / download
- Broken Links – details / download
- Call-out Boxes – details / download
- Chroma – details / download
- Code – details / download
- Comment Validator – details / download
- Conditional Links – details / download
- Contact Forms – details / download
- Disable FLoC – details / download
- Display After Post Content – details / download
- Estimated Read Time – details / download
- Events – details / download
- Feed to Post – details / download
- Filtered Categories – details / download
- Flags – details / download
- Floating Featured Image – details / download
- Get GitHub File – details / download
- Icons – details / download
- Image Optimiser – details / download
- Images – details / download
- Insult Generator – details / download
- Load Admin CSS – details / download
- Loop Injection – details / download
- Lorem Ipsum Generator – details / download
- Maintenance Mode – details / download
- Markdown – details / download
- Nearby – details / download
- Page Index – details / download
- Post Archive – details / download
- Quiz Engine – details / download
- Read GitHub File – details / download
- Redirect – details / download
- Remove Revisions – details / download
- RSS Feed – details / download
- RSS Suffix – details / download
- Series Index – details / download
- Shortcodes in Comments – details / download
- Shortcodes in Widgets – details / download
- SMTP – details / download
- Snippets – details / download
- String Inspector – details / download
- Strong Password Generator – details / download
- Tag Cloud – details / download
- Taxonomy Index – details / download
- Taxonomy Order – details / download
- Theme Switcher – details / download
- Timelines – details / download
- Toggle Show/Hide – details / download
- Update Admin Menu – details / download
- URL Shortener – details / download
- Username Protection – details / download
- View Counter – details / download
- Widget Announcements – details / download