예제 #1
0
 /**
  * Install sample data or dismiss the notice depending on user's option
  */
 static function install_sample_data()
 {
     $yes = !empty($_REQUEST['yes']) ? $_REQUEST['yes'] : '';
     $response = array();
     if ('false' == $yes) {
         set_transient('learn_press_install_sample_data', 'off', 12 * HOUR_IN_SECONDS);
         $response['hide_notice'] = true;
     } else {
         $result = learn_press_install_and_active_add_on('learnpress-import-export');
         if ('activate' == $result['status']) {
             if (!class_exists('LPR_Import')) {
                 $import_file_lib = WP_PLUGIN_DIR . "/learnpress-import-export/incs/lpr-import.php";
                 if (file_exists($import_file_lib)) {
                     include_once WP_PLUGIN_DIR . "/learnpress-import-export/incs/lpr-import.php";
                 }
             }
             if (!class_exists('LPR_Import')) {
                 $response['error'] = __('Import/Export addon not found', 'learn_press');
             } else {
                 $importer = new LPR_Import();
                 $import_source = LPR_PLUGIN_PATH . '/dummy-data/learnpress-how-to-use-learnpress.xml';
                 $upload_dir = wp_upload_dir();
                 $copy = $upload_dir['path'] . '/learnpress-how-to-use-learnpress-copy.xml';
                 @copy($import_source, $copy);
                 if (file_exists($copy)) {
                     $result = $importer->import($copy);
                     if ($result == 1) {
                         $response['success'] = __('Import sample data successfully. The page will reload now!', 'learn_press');
                         $response['redirect'] = admin_url('edit.php?post_type=lpr_course');
                     } else {
                         $response['error'] = __('Unknown error when importing sample data. Please try again!', 'learn_press');
                     }
                 } else {
                     $response['error'] = __('Dummy sample data not found. Please try again!', 'learn_press');
                 }
             }
         } else {
             $response['error'] = __('Unknown error when installing/activating Import/Export addon. Please try again!', 'learn_press');
         }
     }
     learn_press_send_json($response);
     die;
 }
예제 #2
0
 function do_bulk_actions()
 {
     ///
     $wp_list_table = _get_list_table('WP_Posts_List_Table');
     $action = $wp_list_table->current_action();
     if ($action != 'export') {
         if (!empty($_REQUEST['export']) && ($action = $_REQUEST['export'])) {
         }
     }
     if ($action == 'export') {
         switch ($action) {
             case 'export':
                 $post_ids = isset($_REQUEST['post']) ? (array) $_REQUEST['post'] : array();
                 require_once $this->_plugin_path . '/incs/lpr-export-functions.php';
                 require_once $this->_plugin_path . '/incs/lpr-export.php';
                 die;
                 //wp_redirect( admin_url('edit.php?post_type=lpr_course') );
         }
     } elseif (isset($_REQUEST['reset'])) {
     } else {
         $import_file = isset($_FILES['lpr_import']) ? $_FILES['lpr_import'] : false;
         if (!$import_file) {
             return;
         }
         $message = 0;
         require_once $this->_plugin_path . '/incs/lpr-import-functions.php';
         require_once $this->_plugin_path . '/incs/lpr-import.php';
         $lpr_import = new LPR_Import();
         $message = $lpr_import->dispatch();
         if ($message >= 1) {
             $duplication_ids = $lpr_import->get_duplication_course();
             $message .= '&post=' . join(',', $duplication_ids);
             wp_redirect(admin_url('edit.php?post_type=lpr_course&course-imported=1&message=' . $message));
         } else {
             wp_redirect(admin_url('edit.php?post_type=lpr_course&course-imported=error&message=' . $message));
         }
         die;
     }
     //echo admin_url('edit.php?post_type=lpr_course');
 }