2

I am working on a plugin in plugin. I make template folder and in template folder and there are files of plugin that shows my post type data.

First Scenario

When user activate my plugin the template folder move to active theme folder. Its working perfectly.

Second Scenario

Now If there is parent and child theme. When the parent theme activate the template folder move to parent theme but when user activate child theme the template folder also move to child theme.

Now i want that if user activate parent theme then template folder move to parent theme but when user activate child theme then it should not be moved.

Like:

if(parent theme active) {
    //files moved
} else {
    // Do nothing
}

I search from google and found wp_get_theme(); function but it is not fit for my work.

So is there any hook or function that i can write it and it solve my problem.

Here is my move folder function:

$foo_theme_dir = get_template_directory();
$foo_plugin_dir = plugin_dir_path( __FILE__ );

copy($foo_plugin_dir.'template/archive-foo_plugin.php', $foo_theme_dir.'template/archive-foo_plugin.php');
3
  • 1
    Did you try is_child_theme() ?
    – birgire
    May 22, 2015 at 10:25
  • i don't get it .... how can i use this May 22, 2015 at 10:28
  • Maybe under the switch_theme or after_switch_theme hooks, but I might be misunderstanding your question. ps: I'm not sure copy() is allowed in the wordpress.org plugin repo.
    – birgire
    May 22, 2015 at 10:39

2 Answers 2

4

I try this code and it solve my problem

if ( is_child_theme() === false ) {
    // files moved
} else {
    // do nothing
}

Thankx to @birgire

1

You could try the following:

add_action( 'switch_theme', function( $new_name, $new_theme )
{
    if( is_a( $new_theme->parent(), '\WP_Theme' ) )
    {
        // Child theme was activated
    }
    else
    {
       // Parent theme was activated
    }
}, 10, 2 );

to see if the theme you just activated is a child theme or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.