markdown Gist嵌入示例:PHP类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Gist嵌入示例:PHP类相关的知识,希望对你有一定的参考价值。
<?php
/**
* This is a PHP comment block
*
* Let's put a description here so that we can see how
* it looks with multiple lines.
*
* @link http://example.com
* @since 1.0.0
* @package Plugin_Name
*/
namespace CCDzine_Gist_Sample\PHP;
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Gist Embed Sample: PHP
*
* @since 1.0.0
*/
class CCDzine_Gist_Sample_PHP {
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
*/
public function __construct() {
// Access a function.
$this->dependencies();
// Add an action, old array syntax.
add_action( 'wp_head', array( $this, 'head_action' ) );
// Add an action, new array syntax + priority.
add_action( 'wp_footer', [ $this, 'footer_action' ], 20 );
// Filter some text.
add_filter( 'some_filter', [ $this, 'filter_text' ] );
// Arrays.
$this->arrays();
}
/**
* Load dependencies for this plugin.
*
* @since 1.0.0
* @access private
*/
private function dependencies() {
// Require a file once.
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/required-file.php';
// Include a file.
include plugin_dir_path( dirname( __FILE__ ) ) . 'includes/included_file.php';
}
/**
* Run via wp_head.
*
* @since 1.0.0
* @access public
*/
public function head_action() {
if ( class_exists( 'Another_Plugin' ) ) {
// Let's echo a style block.
$style =
'<style>
body {
background: #fff;
}
.class_selector {
color: #000;
}
#id_selector {
border: solid 1px #ccc;
}
</style>';
} else {
$style = '';
}
echo apply_filters( 'style_filter', $style );
}
/**
* Run via wp_footer.
*
* @since 1.0.0
* @access public
*/
public function footer_action() { ?>
<script>
// Here is some script added directly.
jQuery(document).ready( function($) {
$( 'a.cool-link' ).addClass( 'even-cooler' );
} );
</script>
<?php }
/**
* Text to be filtered.
*
* @since 1.0.0
* @access public
*/
public function filter_text() {
$text = sprintf( '<h1>%1s</h1>', esc_html__( 'Gist Embed Sample: PHP', 'ccdzine' ) );
return $text;
}
/**
* Let's test some arrays.
*
* @since 1.0.0
* @access public
*/
public static function arrays() {
$one = array( 'controlled', 'chaos', 'design' );
$two = [
'make' => __( 'Datsun' ),
'model' => __( '510' ),
'year' => __( '1969' )
];
$output = $one;
$output .= $two;
return $output;
}
}
$gist_sample_php = new CCDzine_Gist_Sample_PHP();
## Gist Embed Sample: PHP Class
Code is for display purposes only.
以上是关于markdown Gist嵌入示例:PHP类的主要内容,如果未能解决你的问题,请参考以下文章
markdown 如何使用Jekyll在GitHub页面上嵌入Gist的示例。
markdown 如何使用Jekyll在GitHub页面上嵌入Gist的示例。
markdown Gist Embed示例:PHP HTML模板
markdown Gist嵌入样本:CSS
markdown Gist嵌入 - 隐藏自述文件
markdown Gist Embed示例:jQuery