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; } ?>

theme->get( 'Name' ) ); ?>

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!', 'bldr' ) ); } 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', 'bldr' ) ); } } function style_css() { $name = $this->theme->get( 'Name' ) . ' Child'; $uri = $this->theme->get( 'ThemeURI' ); $parent = $this->theme->get_stylesheet(); return "