flush_rules(); akbar_settings_json_stuff(); } //add_action('after_switch_theme', 'akbar_setup_theme_options'); //add_action('admin_init', 'akbar_setup_theme_options'); function akbar_settings_json_stuff() { $access_type = get_filesystem_method(); // if ($access_type === 'direct') { /* you can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */ $creds = request_filesystem_credentials(home_url() . '/wp-admin/', '', false, false, array()); /* initialize the API */ if (!WP_Filesystem($creds)) { /* any problems and we exit */ return false; } global $wp_filesystem; if (false === ($creds = request_filesystem_credentials(esc_url_raw(home_url()), "", false, false, ['save']))) { return true; // Stop the normal page form from displaying, credential request form will be shown. } WP_Filesystem($creds); $string = akbar_theme_options_generation(); $wp_filesystem->put_contents(get_template_directory() . "/out/assets/settings.js", $string); return $wp_filesystem; // } else { // /* don't have direct write access. Prompt user with our notice */ // add_action('admin_notices', 'akbar_notice_function'); // } } function akbar_theme_options_generation_array() { global $AKBAR_API; $custom_logo_id = get_theme_mod('custom_logo'); $logo = wp_get_attachment_image_src($custom_logo_id, 'full'); // Get option settings from database if (!$logo[0]) { $logo[0] = ''; } $options = ['akbar_header_logo_image' => $logo[0]]; $home_url = home_url(); $footerm = $AKBAR_API->wp_api_v2_locations_get_menu_data(['id' => 'footerm']); if (!$footerm) { $footerm = new stdClass(); $footerm->items = []; } $headerm = $AKBAR_API->wp_api_v2_locations_get_menu_data(['id' => 'headerm']); if (!$headerm) { $headerm = new stdClass(); $headerm->items = []; } $mainmenu = $AKBAR_API->wp_api_v2_locations_get_menu_data(['id' => 'mainmenu']); if (!$mainmenu) { $mainmenu = new stdClass(); $mainmenu->items = []; } if ($mainmenu && $mainmenu->items) foreach ($mainmenu->items as $key => $m) { if ($m) $mainmenu->items[$key]->url = str_replace($home_url, "", $m->url); } $arr = [ 'home_url' => home_url(), 'rest_url' => get_rest_url(), 'blog_title' => get_bloginfo('name'), 'theme_uri' => get_template_directory_uri(), 'theme_options' => $options, 'menu' => [ 'headerm' => $headerm, 'footerm' => $footerm, 'mainmenu' => $mainmenu ] ]; return $arr; } function akbar_theme_options_generation() { $arr = akbar_theme_options_generation_array(); $string = "window.globalTS=" . json_encode($arr); return $string; } add_action('admin_notices', 'akbar_notice_function'); function akbar_notice_function() { $message = 'After changing menu, theme customization and changing front page please click on =>'; printf('