Themes, 2: link to Appearance > Editor */ esc_html__( 'Head over to %1$s to activate it. Add your custom styles in %2$s.', 'child-theme-wizard' ), '' . esc_html__( 'Appearance › Themes', 'child-theme-wizard' ) . '', '' . esc_html__( 'Appearance › Editor', 'child-theme-wizard' ) . '' ); ?>
' . esc_html__( 'Child Theme', 'child-theme-wizard' ) . '' ); ?>
Plugin by Jay Versluis | Fork me or Contribute on GitHub | Support me on Patreon
0, 'message' => '', ); global $wp_filesystem; if ( empty( $wp_filesystem ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; WP_Filesystem(); } $directory = get_theme_root() . '/' . sanitize_file_name( $childtheme['title'] ); if ( ! $wp_filesystem->mkdir( $directory ) ) { $status['message'] = '' . esc_html__( 'Could not create directory. Does it exist already?', 'child-theme-wizard' ) . '
'; $status['alert'] = -1; return $status; } $status['message'] .= '' . esc_html__( 'Directory created successfully.', 'child-theme-wizard' ) . '
'; // Strip */ so user-supplied values cannot break out of the CSS comment block. $safe = array_map( fn( $v ) => str_replace( '*/', '', (string) $v ), $childtheme ); $style = "/* \n Theme Name: " . $safe['title']; $style .= "\n Theme URI: " . $safe['url']; $style .= "\n Description: " . $safe['description']; $style .= "\n Author: " . $safe['author']; $style .= "\n Author URI: " . $safe['author-url']; $style .= "\n Template: " . $safe['parent']; $style .= "\n Version: " . $safe['version']; if ( $safe['include-gpl'] === 'on' ) { $style .= "\n License: GNU General Public License v2 or later"; $style .= "\n License URI: http://www.gnu.org/licenses/gpl-2.0.html"; } $style .= "\n\n /* == Add your own styles below this line =="; $style .= "\n--------------------------------------------*/\n\n"; if ( ! $wp_filesystem->put_contents( $directory . '/style.css', $style, FS_CHMOD_FILE ) ) { $status['message'] .= '' . esc_html__( 'There was a problem writing data to style.css.', 'child-theme-wizard' ) . '
'; $status['alert'] = -1; return $status; } $status['message'] .= '' . esc_html__( 'Writing data to style.css…', 'child-theme-wizard' ) . '
'; $functions = "get( 'Version' )\n"; $functions .= " );\n"; $functions .= "}\n"; $functions .= "add_action( 'wp_enqueue_scripts', 'your_theme_enqueue_styles' );\n\n"; $functions .= "/* Add your own functions below this line.\n"; $functions .= " ======================================== */\n\n"; if ( ! $wp_filesystem->put_contents( $directory . '/functions.php', $functions, FS_CHMOD_FILE ) ) { $status['message'] .= '' . esc_html__( 'There was a problem writing data to functions.php.', 'child-theme-wizard' ) . '
'; $status['alert'] = -1; return $status; } $status['message'] .= '' . esc_html__( 'Writing data to functions.php…', 'child-theme-wizard' ) . '
'; $status['message'] .= ctw_make_thumbnail( $directory ); return $status; } function ctw_giveme_parents(): array { $parent_themes = array(); foreach ( wp_get_themes() as $theme ) { if ( $theme->parent() === false ) { $parent_themes[] = $theme; } } return $parent_themes; } function ctw_make_thumbnail( string $childpath ): string { global $wp_filesystem; if ( empty( $wp_filesystem ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; WP_Filesystem(); } $source = plugin_dir_path( __FILE__ ) . 'images/screenshot.png'; $destination = $childpath . '/screenshot.png'; if ( ! $wp_filesystem->copy( $source, $destination ) ) { return '' . esc_html__( 'Could not copy thumbnail image.', 'child-theme-wizard' ) . '
'; } return '' . esc_html__( 'Copied thumbnail file — looking good!', 'child-theme-wizard' ) . '
'; }