Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@smeric
Last active April 20, 2020 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smeric/0b511224d7a36362b30c7ed9251690a3 to your computer and use it in GitHub Desktop.
Save smeric/0b511224d7a36362b30c7ed9251690a3 to your computer and use it in GitHub Desktop.
WordPress plugin to make the displayed WordPress functions names in your posts content clickable and linked to their reference page in the codex using a shortcode.
=== Functions 2 Links ===
Contributors: sebmeric
Tags: codex, developer, development, reference, documentation, manual
Requires at least: 5.0
Tested up to: 5.4
Stable tag: 0.1b
License: GPLv2 or later
Make the displayed WordPress functions names in your posts content clickable and linked to their reference page in the codex using a shortcode.
== Description ==
Make your displayed WordPress functions names in your posts content clickable and linked to their reference page in the codex using a shortcode.
Use [F2L type="wpf" name="the_content"] to get <code><a href="https://developer.wordpress.org/reference/functions/the_content/" title="Check on WordPress Code Reference...">the_content</a></code>.
Default types are "wpf" for WordPress functions, "wph" for WordPress hooks, "wpc" for WordPress classes and "wpm" for WordPress methods.
WordPress dev : add your own types by hooking in the F2L_types filter ! For example you can create a "phpf" type to forge links to the php.net manual :
<?php
function F2L_types( $type, $name, $content ) {
if ( 'phpf' === $type ) {
$content = '<code><a href="https://www.php.net/manual/fr/function.' . str_replace( '_', '-', $name ) . '.php" title="' . esc_attr__( 'Check on php.net...', 'txt-domain' ) . '" rel="external noopener noreferrer">' . $name . '</a></code>';
}
return $content;
}
add_filter( 'F2L_types', 'F2L_types', 10, 3 );
?>
== Installation ==
Upload the F2L plugin to your blog, activate it, and start using the shortcode in your post content.
== Changelog ==
= 0.1b =
*Release Date - 26 March 2020*
* First release as beta version
<?php
// as an example, this is the way to add a type to forge links to php.net manual
function F2L_types( $type, $name, $content ) {
if ( 'phpf' === $type ) {
$content = '<code><a href="https://www.php.net/manual/fr/function.' . str_replace( '_', '-', $name ) . '.php" title="' . esc_attr__( 'Check on php.net...', 'txt-domain' ) . '" rel="external noopener noreferrer">' . $name . '</a></code>';
}
return $content;
}
add_filter( 'F2L_types', 'F2L_types', 10, 3 );
<?php
/**
* Plugin Name: Functions 2 Links
* Plugin URI: https://gist.github.com/smeric/0b511224d7a36362b30c7ed9251690a3
* Description: Use [F2L type="wpf" name="the_content"] to get <code><a href="https://developer.wordpress.org/reference/functions/the_content/" title="Check on WordPress Code Reference...">the_content</a></code>. Default types are "wpf" for WordPress functions, "wph" for WordPress hooks, "wpc" for WordPress classes and "wpm" for WordPress methods. WordPress dev : add your own types by hooking in the F2L_types filter !
* Version: 0.1b
* Author: Sébastien Méric
* Author URI: https://sebastien-meric.com/
*/
add_shortcode( 'F2L', function( $atts, $content = '' ) {
extract( shortcode_atts( array(
'name' => '',
'type' => '',
), $atts, 'F2L' ) );
if ( 'wpf' === $type ) {
$content = '<code><a href="https://developer.wordpress.org/reference/functions/' . $name . '/" title="' . esc_attr__( 'Check on WordPress Code Reference...', 'functionality-plugin' ) . '" rel="external noopener noreferrer">' . $name . '</a></code>';
}
elseif ( 'wph' === $type ) {
$content = '<code><a href="https://developer.wordpress.org/reference/hooks/' . $name . '/" title="' . esc_attr__( 'Check on WordPress Code Reference...', 'functionality-plugin' ) . '" rel="external noopener noreferrer">' . $name . '</a></code>';
}
elseif ( 'wpc' === $type ) {
$content = '<code><a href="https://developer.wordpress.org/reference/classes/' . $name . '/" title="' . esc_attr__( 'Check on WordPress Code Reference...', 'functionality-plugin' ) . '" rel="external noopener noreferrer">' . $name . '</a></code>';
}
elseif ( 'wpm' === $type ) {
$content = '<code><a href="https://developer.wordpress.org/reference/methods/' . $name . '/" title="' . esc_attr__( 'Check on WordPress Code Reference...', 'functionality-plugin' ) . '" rel="external noopener noreferrer">' . $name . '</a></code>';
}
$content = apply_filters( 'F2L_types', $type, $name, $content );
return $content;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment