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(site_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(TEMPLATEPATH . "/out/assets/settings.js", $string); } else { /* don't have direct write access. Prompt user with our notice */ add_action('admin_notices', 'akbar_notice_function'); } } function akbar_theme_options_generation() { global $AKBAR_API; $option_name = ''; // Gets option name as defined in the theme // if (function_exists('optionsframework_option_name')) { // $option_name = optionsframework_option_name(); // } // // // Fallback option name // if ('' == $option_name) { // $option_name = get_option('stylesheet'); // $option_name = preg_replace("/\W/", "_", strtolower($option_name)); // } $custom_logo_id = get_theme_mod( 'custom_logo' ); $logo = wp_get_attachment_image_src( $custom_logo_id , 'full' ); // Get option settings from database $options = ['akbar_header_logo_image'=>$logo[0]]; $home_url = home_url(); $tblm = $AKBAR_API->wp_api_v2_locations_get_menu_data(['id' => 'tblm']); $tbrm = $AKBAR_API->wp_api_v2_locations_get_menu_data(['id' => 'tbrm']); $mainmenu = $AKBAR_API->wp_api_v2_locations_get_menu_data(['id' => 'mainmenu']); if ($mainmenu && $mainmenu->items) foreach ($mainmenu->items as $key => $m) { $mainmenu->items[$key]->url = str_replace($home_url, "", $m->url); } $arr = [ // 'site_url' => site_url(), 'home_url' => home_url(), 'theme_uri' => get_template_directory_uri(), 'theme_options' => $options, 'menu' => [ 'tblm' => $tblm, 'tbrm' => $tbrm, 'mainmenu' => $mainmenu ] ]; $string = "window.globalTS=" . json_encode($arr); return $string; } function akbar_notice_function() { $message = 'lkjhgf'; printf('
%s
', $message); } function akbar_customizer_live_preview() { wp_enqueue_script( 'akbar-themecustomizer', //Give the script an ID AKBAR_INCLUDES_URL.'/dist/js/theme-customizer.js',//Point to file array( 'jquery','customize-preview' ), //Define dependencies '', //Define a version (optional) true //Put script in footer? ); } add_action( 'customize_preview_init', 'akbar_customizer_live_preview' );