晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
| DIR:/home/salvufkx/homedir/www/wp-content/themes/gridsby/inc/ |
| Current File : //home/salvufkx/homedir/www/wp-content/themes/gridsby/inc/use-child-theme.php |
<?php
/*
* Use Child Theme
* A drop-in to make it easy to use WordPress child themes
* @version 0.4
*/
defined( 'ABSPATH' ) or exit;
if ( ! class_exists( 'Use_Child_Theme' ) ) {
class Use_Child_Theme
{
public $theme;
public $child_slug;
function __construct() {
add_action( 'admin_init', array( $this, 'admin_init' ) );
}
function admin_init() {
// Exit if unauthorized
if ( ! current_user_can( 'switch_themes' ) ) {
return;
}
// Exit if dismissed
if ( false !== get_transient( 'uct_dismiss_notice' ) ) {
return;
}
$this->theme = wp_get_theme();
// Exit if child theme
if ( false !== $this->theme->parent() ) {
return;
}
// Exit if no direct access
if ( 'direct' != get_filesystem_method() ) {
return;
}
add_action( 'wp_ajax_uct_activate', array( $this, 'activate_child_theme' ) );
add_action( 'wp_ajax_uct_dismiss', array( $this, 'dismiss_notice' ) );
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
}
function admin_notices() {
// Show only on Appearance > Editor
$screen = get_current_screen();
if ( ! isset( $screen->id ) || 'theme-editor' != $screen->id ) {
return;
}
?>
<script>
(function($) {
$(function() {
$(document).on('click', '.uct-activate', function() {
$.post(ajaxurl, { action: 'uct_activate' }, function(response) {
$('.uct-notice p').html(response);
});
});
$(document).on('click', '.uct-notice .notice-dismiss', function() {
$.post(ajaxurl, { action: 'uct_dismiss' });
});
});
})(jQuery);
</script>
<div class="notice notice-error uct-notice is-dismissible">
<p>
<?php printf( esc_html__( 'Please use a %s child theme to make changes', 'gridsby' ), $this->theme->get( 'Name' ) ); ?>
<a class="uct-activate" href="javascript:;"><?php esc_html_e( 'Activate now', 'gridsby' ); ?></a>
</p>
</div>
<?php
}
function dismiss_notice() {
set_transient( 'uct_dismiss_notice', 'yes', apply_filters( 'uct_dismiss_timeout', 86400 ) );
exit;
}
function has_child_theme() {
$themes = wp_get_themes();
$folder_name = $this->theme->get_stylesheet();
$this->child_slug = $folder_name . '-child';
foreach ( $themes as $theme ) {
if ( $folder_name == $theme->get( 'Template' ) ) {
$this->child_slug = $theme->get_stylesheet();
return true;
}
}
return false;
}
function activate_child_theme() {
$parent_slug = $this->theme->get_stylesheet();
// Create child theme
if ( ! $this->has_child_theme() ) {
$this->create_child_theme();
}
switch_theme( $this->child_slug );
// Copy customizer settings, widgets, etc.
$settings = get_option( 'theme_mods_' . $this->child_slug );
if ( false === $settings ) {
$parent_settings = get_option( 'theme_mods_' . $parent_slug );
update_option( 'theme_mods_' . $this->child_slug, $parent_settings );
}
wp_die( esc_html__( 'All done!', 'gridsby' ) );
}
function create_child_theme() {
$parent_dir = $this->theme->get_stylesheet_directory();
$child_dir = $parent_dir . '-child';
if ( wp_mkdir_p( $child_dir ) ) {
$creds = request_filesystem_credentials( admin_url() );
WP_Filesystem( $creds ); // we already have direct access
global $wp_filesystem;
$wp_filesystem->put_contents( $child_dir . '/style.css', $this->style_css() );
$wp_filesystem->put_contents( $child_dir . '/functions.php', $this->functions_php() );
if ( false !== ( $img = $this->theme->get_screenshot( 'relative' ) ) ) {
$wp_filesystem->copy( "$parent_dir/$img", "$child_dir/$img" );
}
}
else {
wp_die( esc_html__( 'Error: theme folder not writable', 'gridsby' ) );
}
}
function style_css() {
$name = $this->theme->get( 'Name' ) . ' Child';
$uri = $this->theme->get( 'ThemeURI' );
$parent = $this->theme->get_stylesheet();
return "<?php
/*
Theme Name: {$name}
Theme URI: {$uri}
Template: {$parent}
Version: 0.1
*/
";
}
function functions_php() {
return "<?php
function child_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'child_enqueue_styles' );
";
}
}
new Use_Child_Theme();
}
|