コード例 #1
0
 public function addPanel()
 {
     $this->version = OT_VERSION;
     $sections = $this->getSections();
     $this->data = get_option('option_tree');
     if (!empty($sections) && class_exists('ReduxFramework')) {
         $args = array('opt_name' => $this->framework . '2Redux_Panel', 'save_defaults' => false, 'menu_title' => $this->framework . ' 2 Redux', 'output' => false, 'show_import_export' => false, 'page_slug' => $this->framework . 'Redux_Converter', 'enqueue' => false, 'intro_text' => '<p>This is your panel converted. Saving will be saved to a transient value which gets reset every hour. <a href="./admin.php?page=' . $this->framework . '_2_redux">Proceed here</a> to get the export code you would need to migrate from ' . $this->framework . ' to Redux.</p>');
         $theme = wp_get_theme();
         $args['display_name'] = $theme->get('Name');
         $args['display_version'] = $theme->get('Version');
         $args['google_api_key'] = 'AIzaSyAX_2L_UzCDPEnAHTG7zhESRVpMPS4ssII';
         $sections[] = array('type' => 'divide');
         $sections[] = array('title' => 'Convert to Redux!', 'icon' => 'el-icon-asl', 'fields' => array(array('id' => 'redux_conversion_welcome', 'type' => 'info', 'title' => __("Rest assured, you're making the right choice.", 'redux-framework-demo'), 'desc' => "Converting to a new framework is not always easy, in fact it's downright <strong>painful</strong>. We don't think it has to be that way. That's why we created this converter plugin.<br /><br />Fill out the items below and download a fully function Redux Framework class. <a href='https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3WQGEY4NSYE38' target='_blank'>Be sure to donate</a>. Every bit helps."), array('id' => 'redux_convert_refresh_data', 'type' => 'checkbox', 'title' => __('Reset Panel to Old Data', 'redux-framework-demo'), 'subtitle' => __('Reset this panel to match what is inside ' . $this->framework . '.', 'redux-framework-demo'), 'options' => array(1 => 'Reset this panel to match what is stored in ' . $this->framework . '.')), array('id' => 'redux_opt_name', 'type' => 'text', 'title' => __('Database name, aka Redux opt_name', 'redux-framework-demo'), 'subtitle' => __('Choose the place where your data will be stored in the database.', 'redux-framework-demo'), 'desc' => 'Once this is specified, Redux will take care of the rest. It is suggested to use a different key than you previously had. Data migration code will be provided.', 'default' => 'redux_converter'), array('id' => 'redux_convert_data', 'type' => 'switch', 'title' => __('Add Data Migration', 'redux-framework-demo'), 'subtitle' => __('Don\'t just implement a new panel, but migrate your old data as well.', 'redux-framework-demo'), 'default' => 1, 'desc' => 'A function will be provided which will, on theme activation/upgrade, migrate your data to your new Redux opt_name location denoted above. This makes it super easy to convert even if you have many users! <span style="color: maroon;">Please verify data migrates properly. Redux takes no responsibility if a field does not convert as it should.</span> If you find a bug, <a href="https://github.com/ReduxFramework/redux-converter/issues" target="_blank">please submit it to us</a>!'), array('id' => 'redux_global_variable', 'type' => 'text', 'title' => __('Redux Global Variable', 'redux-framework-demo'), 'subtitle' => __('Redux provides a global variable for your access your panel data anywhere within wordpress.', 'redux-converter'), 'desc' => 'By default the global variable is the same as the opt_name. If you want it to be something else (or your old variable), choose a name here. All standard variable rules apply (no spaces, dashes, or other odd symbols). ' . $this->framework . '\'s typical variables (if you wanted to keep your code as is) are $data or $smof_data.'), array('id' => 'redux_delete_old_data', 'type' => 'checkbox', 'title' => __('Delete Old Panel Data?', 'redux-framework-demo'), 'subtitle' => __('We strongly suggest you don\'t do this, but it is your choice.', 'redux-framework-demo'), 'desc' => '<span style="color: red;">There is no undoing this. If something in the conversion goes bad, your previously set data will be lost. It is suggested to leave this be just in case.</span>', 'options' => array(1 => 'Remove old data on migration')), array('id' => 'redux_download_file', 'type' => 'raw', 'content' => '<center><input type="hidden" class="convertToReduxNonce" value="' . wp_create_nonce('convertToRedux' . $this->framework) . '"><a href="#" target="_blank" class="button button-primary redux-converter-action">View Redux Config File</a> <a href="#" data-action="download" class="button button-primary redux-converter-action">Download Redux Config File</a></center>')));
         $ReduxFramework = new ReduxFramework($sections, $args);
         //print_r(get_option( 'option_tree' ));
         //print_r(ot_get_option('my_category_checkbox'));
         //echo ot_get_option('my_category_checkbox');
         $convertData = false;
         if (empty($ReduxFramework->options) || isset($ReduxFramework->options['redux_convert_refresh_data']) && $ReduxFramework->options['redux_convert_refresh_data'] == 1) {
             $convertData = true;
             $ReduxFramework->options = get_option('option_tree');
         }
         foreach ($sections as $section) {
             if (isset($section['fields'])) {
                 foreach ($section['fields'] as $field) {
                     if ($convertData && isset($ReduxFramework->options[$field['id']]) && !empty($ReduxFramework->options[$field['id']])) {
                         $ReduxFramework->options[$field['id']] = $this->convertValue($ReduxFramework->options[$field['id']], $field);
                         // Not sure why this happens. Huh.
                     }
                     if (isset($field['required'])) {
                         $ReduxFramework->get_fold($field);
                     }
                 }
             }
         }
     }
 }