WordPress / theme-review-action

Other
31 stars 10 forks source link

Redirect on theme activation is not allowed #61

Open carolinan opened 3 years ago

carolinan commented 3 years ago

Redirecting the user away from the theme screen when a theme is activated is not allowed.

There are two ways to redirect on activation that are more common:

global $pagenow;

if (is_admin() && 'themes.php' == $pagenow && isset($_GET['activated'])) {
    $theme_info = wp_get_theme();
    $theme_name = $theme_info->get( 'Name' );
    if($theme_name =='THEME NAME'){
        wp_redirect(admin_url("themes.php?page=prefix_activation")); // Your admin page URL
    }
}
function prefix_after_switch_theme(){
    wp_redirect('admin.php?page=prefix-panel');
}

add_action( 'after_switch_theme', 'prefix_after_switch_theme' );

Note that neither wp_redirect or after_switch_theme on their own cause any problems. This makes it difficult to test this requirement with a static code check.

A test could be set up to check if there is a redirect after theme activation.

StevenDufresne commented 2 years ago

Can I get more information on how this is being abused? Maybe an example theme or some documentation?