Skip to content

Instantly share code, notes, and snippets.

@shrimp2t
Created May 10, 2018 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shrimp2t/fb084ffa6009c45fc3f47fc406ed1288 to your computer and use it in GitHub Desktop.
Save shrimp2t/fb084ffa6009c45fc3f47fc406ed1288 to your computer and use it in GitHub Desktop.
Install and active by url or ajax
<?php
// get_current_screen()
//$class= 'updated notice notice-success notice-alt is-dismissible';
// install theme url esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) )
$theme_slug = 'twentyseventeen';
$install_url = add_query_arg( array(
'action' => 'install-theme',
'theme' => $theme_slug,
), self_admin_url( 'update.php' ) );
/** ajax_install_theme
slug: appsetter
action: install-theme
_ajax_nonce: 14550356f5
_fs_nonce:
username:
password:
connection_type:
public_key:
Respond: {"success":true,"data":{"install":"theme","slug":"appsetter","debug":["Downloading installation package from https:\/\/downloads.wordpress.org\/theme\/appsetter.1.0.7.zip&#8230;","Unpacking the package&#8230;","Installing the theme&#8230;","Theme installed successfully."],"themeName":"AppSetter","activateUrl":"https:\/\/onepress.dev\/wp-admin\/themes.php?action=activate&_wpnonce=63ec2e200a&stylesheet=appsetter","customizeUrl":"https:\/\/onepress.dev\/wp-admin\/customize.php?theme=appsetter&return=%2Fwp-admin%2Ftheme-install.php"}}
*button button-primary theme-install updating-message
*/
$ajax_data = array(
'action' => 'install-theme',
'theme' => $theme_slug,
'_ajax_nonce' => wp_create_nonce( 'install-theme_' . $theme_slug )
);
$url = wp_nonce_url( $install_url, 'install-theme_' . $theme_slug );
$active_url = wp_nonce_url( admin_url( 'themes.php?action=activate&amp;stylesheet=' . $theme_slug ), 'switch-theme_' . $theme_slug );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment