# Why does my hand-written plugin installer fail to find request_filesystem_credentials?

I'm trying to write a plugin installer, akin to TGMPA, but just for its core functionality of actually installing the plugin and nothing more.

I've identified that Plugin_Upgrader is what I need and decided to emulate this.

$plugin = THEME_DIR . '/Inc/Plugins/my-shortcodes.zip';$options = array(
'package' => $plugin, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => false, 'clear_working' => true, 'is_multi' => true, 'hook_extra' => array( 'plugin' =>$plugin,
),
);

{
public function run( $options ) {$result = parent::run( $options ); return$result;
}
}

$upgrader = new My_Upgrader;$upgrader->run($options);$upgrader->install( $plugin ); Unfortunately, this throws the following error: Uncaught Error: Call to undefined function request_filesystem_credentials() in C:\xampp\htdocs\wordpress\wp-admin\includes\class-wp-upgrader-skin.php:93 Stack trace: #0 C:\xampp\htdocs\wordpress\wp-admin\includes\class-wp- upgrader.php(187): WP_Upgrader_Skin->request_filesystem_credentials(false, 'C:\\xampp\\htdocs...', false) #1 C:\xampp\htdocs\wordpress\wp- admin\includes\class-wp-upgrader.php(693): WP_Upgrader->fs_connect(Array) #2 C:\xampp\htdocs\wordpress\wp-content\themes\amaranth\header.php(53): WP_Upgrader->run(Array) #3 C:\xampp\htdocs\wordpress\wp- content\themes\amaranth\header.php(59): My_Upgrader->run(Array) #4 C:\xampp\htdocs\wordpress\wp-includes\template.php(688): require_once('C:\\xampp\\htdocs...') #5 C:\xampp\htdocs\wordpress\wp- includes\template.php(647): load_template('C:\\xampp\\htdocs...', true) #6 C:\xampp\htdocs\wordpress\wp-includes\general-template.php(41): locate_template(Array, true) #7 C:\xampp\htdocs\wordpress\wp- content\themes\amaranth\index.php(15): get_header() #8 C:\xampp\htdoc in C:\xampp\htdocs\wordpress\wp-admin\includes\class-wp-upgrader-skin.php on line 93 It has something to do with its...skin? Am I missing something? A few notes: • I understand that the Filesystem module would default to FTP if it can't write to wp-content, as such, this error might pop up, but it's not the case. WP can write to wp-content. Disclaimer: This is a very dumb installer, but I gotta start somewhere. Any suggestions are welcome. ## 2 Answers I forgot to include the files necessary for these functions to work. And so, here's your dirty-quick way to install plugins:$plugin = THEME_DIR . '/Inc/Plugins/my-shortcodes.zip';
$options = array( 'package' =>$plugin,
'destination' => WP_PLUGIN_DIR,
'clear_destination' => false,
'clear_working' => true,
'is_multi' => true,
'hook_extra' => array(
'plugin' => $plugin, ), ); require_once ABSPATH . 'wp-admin/includes/misc.php'; if(!function_exists('request_filesystem_credentials')){ require_once ABSPATH . 'wp-admin/includes/file.php'; } if( !class_exists('\Plugin_Upgrader')) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; } class My_Upgrader extends Plugin_Upgrader { public function run($options )
{
$result = parent::run($options );
return $result; } }$upgrader = new My_Upgrader;
$upgrader->run($options);
$upgrader->install($plugin );

The error message says that request_filesystem_credentials() is undefined. So make sure that function is defined by including the file before class-wp-upgrader.php.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.22041168808937073, "perplexity": 21636.411951481423}, "config": {"markdown_headings": true, "markdown_code": false, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2021-49/segments/1637964359065.88/warc/CC-MAIN-20211130171559-20211130201559-00615.warc.gz"}