$t->get_stylesheet(), $parent_themes ); $submitted_parent = sanitize_text_field( wp_unslash( $_POST['parent'] ?? '' ) ); if ( ! in_array( $submitted_parent, $valid_parents, true ) ) { wp_die( esc_html__( 'Invalid parent theme selected.', 'child-theme-wizard' ) ); } $newchildtheme = array( 'parent' => $submitted_parent, 'title' => sanitize_text_field( wp_unslash( $_POST['title'] ?? '' ) ), 'description' => sanitize_text_field( wp_unslash( $_POST['description'] ?? '' ) ), 'url' => esc_url_raw( wp_unslash( $_POST['url'] ?? '' ) ), 'author' => sanitize_text_field( wp_unslash( $_POST['author'] ?? '' ) ), 'author-url' => esc_url_raw( wp_unslash( $_POST['author-url'] ?? '' ) ), 'version' => sanitize_text_field( wp_unslash( $_POST['version'] ?? '' ) ), 'include-gpl' => ( isset( $_POST['include-gpl'] ) && $_POST['include-gpl'] === 'on' ) ? 'on' : 'off', ); $status = ctw_create_theme( $newchildtheme ); if ( $status['alert'] === -1 ) { ?>

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' ) . '' ); ?>





WP Guru

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' ) . '

'; }