Plugin Directory

Changeset 3393564


Ignore:
Timestamp:
11/11/2025 10:52:06 AM (5 months ago)
Author:
imminentsoftware
Message:

Initial commit of EasySecure Import Export Courses Learndash

Location:
easysecure-import-export-courses-learndash/trunk
Files:
220 added
5 edited

Legend:

Unmodified
Added
Removed
  • easysecure-import-export-courses-learndash/trunk/composer.json

    r3393421 r3393564  
    11{
    22    "name": "yourname/easysecure-import-export",
    3     "require": {
    4         "openspout/openspout": "4.32.0"
    5     },
    63    "config": {
    74        "platform": {
    8             "php": "8.3.0"
     5            "php": "8.2.0"
    96        }
     7    },
     8    "require": {
     9        "openspout/openspout": "3.4"
    1010    }
    1111}
  • easysecure-import-export-courses-learndash/trunk/composer.lock

    r3393421 r3393564  
    55        "This file is @generated automatically"
    66    ],
    7     "content-hash": "16b6497ee3154a430a89a5d2b5e2e752",
     7    "content-hash": "3d63527334299fe9d7661b101df95c90",
    88    "packages": [
    99        {
    1010            "name": "openspout/openspout",
    11             "version": "v4.32.0",
     11            "version": "v3.4.0",
    1212            "source": {
    1313                "type": "git",
    1414                "url": "https://github.com/openspout/openspout.git",
    15                 "reference": "41f045c1f632e1474e15d4c7bc3abcb4a153563d"
     15                "reference": "06b28c080bf811562d0552c87726ae0fcdac53f8"
    1616            },
    1717            "dist": {
    1818                "type": "zip",
    19                 "url": "https://api.github.com/repos/openspout/openspout/zipball/41f045c1f632e1474e15d4c7bc3abcb4a153563d",
    20                 "reference": "41f045c1f632e1474e15d4c7bc3abcb4a153563d",
     19                "url": "https://api.github.com/repos/openspout/openspout/zipball/06b28c080bf811562d0552c87726ae0fcdac53f8",
     20                "reference": "06b28c080bf811562d0552c87726ae0fcdac53f8",
    2121                "shasum": ""
    2222            },
    2323            "require": {
    2424                "ext-dom": "*",
    25                 "ext-fileinfo": "*",
    26                 "ext-filter": "*",
    27                 "ext-libxml": "*",
    2825                "ext-xmlreader": "*",
    2926                "ext-zip": "*",
    30                 "php": "~8.3.0 || ~8.4.0 || ~8.5.0"
     27                "php": "~7.3.0 || ~7.4.0 || ~8.0.0 || ~8.1.0"
    3128            },
    3229            "require-dev": {
    33                 "ext-zlib": "*",
    34                 "friendsofphp/php-cs-fixer": "^3.86.0",
    35                 "infection/infection": "^0.31.2",
    36                 "phpbench/phpbench": "^1.4.1",
    37                 "phpstan/phpstan": "^2.1.22",
    38                 "phpstan/phpstan-phpunit": "^2.0.7",
    39                 "phpstan/phpstan-strict-rules": "^2.0.6",
    40                 "phpunit/phpunit": "^12.3.7"
     30                "friendsofphp/php-cs-fixer": "^3",
     31                "phpstan/phpstan": "^1",
     32                "phpunit/phpunit": "^9"
    4133            },
    4234            "suggest": {
    43                 "ext-iconv": "To handle non UTF-8 CSV files (if \"php-mbstring\" is not already installed or is too limited)",
    44                 "ext-mbstring": "To handle non UTF-8 CSV files (if \"iconv\" is not already installed)"
     35                "ext-iconv": "To handle non UTF-8 CSV files (if \"php-intl\" is not already installed or is too limited)",
     36                "ext-intl": "To handle non UTF-8 CSV files (if \"iconv\" is not already installed)"
    4537            },
    4638            "type": "library",
     
    5244            "autoload": {
    5345                "psr-4": {
    54                     "OpenSpout\\": "src/"
     46                    "OpenSpout\\": "src/Spout"
    5547                }
    5648            },
     
    8678            "support": {
    8779                "issues": "https://github.com/openspout/openspout/issues",
    88                 "source": "https://github.com/openspout/openspout/tree/v4.32.0"
     80                "source": "https://github.com/openspout/openspout/tree/v3.4.0"
    8981            },
    9082            "funding": [
    9183                {
    92                     "url": "https://paypal.me/filippotessarotto",
    93                     "type": "custom"
    94                 },
    95                 {
    96                     "url": "https://github.com/Slamdunk",
     84                    "url": "https://github.com/adrilo",
    9785                    "type": "github"
    9886                }
    9987            ],
    100             "time": "2025-09-03T16:03:54+00:00"
     88            "time": "2022-03-02T07:23:00+00:00"
    10189        }
    10290    ],
     
    11098    "platform-dev": {},
    11199    "platform-overrides": {
    112         "php": "8.3.0"
     100        "php": "8.2.0"
    113101    },
    114102    "plugin-api-version": "2.6.0"
  • easysecure-import-export-courses-learndash/trunk/export/export.php

    r3393421 r3393564  
    77require_once plugin_dir_path(__FILE__) . '../vendor/autoload.php';
    88
    9 use OpenSpout\Writer\XLSX\Writer;
     9use OpenSpout\Writer\Common\Creator\WriterEntityFactory;
     10use OpenSpout\Writer\XLSX\Writer as XLSXWriter;
    1011use OpenSpout\Writer\CSV\Writer as CSVWriter;
    11 use OpenSpout\Common\Entity\Row;
    1212
    1313global $wpdb;
     
    4646
    4747    // --- Create writer ---
    48     if ($format === 'csv') {
    49         $writer = new CSVWriter();
     48   
     49
     50// XLSX
     51if ($format === 'csv') {
     52        $writer = WriterEntityFactory::createCSVWriter();
    5053        $filename = 'selected-courses-' . time() . '.csv';
    5154        header("Content-Type: text/csv");
    5255    } else {
    53         $writer = new Writer();
     56        $writer = WriterEntityFactory::createXLSXWriter();
    5457        $filename = 'selected-courses-' . time() . '.xlsx';
    5558        header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
     
    6063    ob_end_clean();
    6164
     65    header("Content-Disposition: attachment; filename=\"{$filename}\"");
     66    header("Cache-Control: max-age=0");
     67    ob_end_clean();
     68
    6269    // Open writer to browser
    6370    $writer->openToBrowser($filename);
     
    7279    if (!empty($coursedata)) {
    7380        foreach ($coursedata as $rowData) {
    74             $writer->addRow(Row::fromValues($rowData));
     81            $row = WriterEntityFactory::createRowFromArray($rowData);
     82            $writer->addRow($row);
    7583        }
    7684    }
     
    8290        if (!empty($lessondata)) {
    8391            foreach ($lessondata as $rowData) {
    84                 $writer->addRow(Row::fromValues($rowData));
     92                $row = WriterEntityFactory::createRowFromArray($rowData);
     93                $writer->addRow($row);
    8594            }
    8695        }
     
    93102        if (!empty($topicdata)) {
    94103            foreach ($topicdata as $rowData) {
    95                 $writer->addRow(Row::fromValues($rowData));
     104                $row = WriterEntityFactory::createRowFromArray($rowData);
     105                $writer->addRow($row);
    96106            }
    97107        }
     
    105115function handle_multiple_courses_export_action($redirect_to, $action, $post_ids)
    106116{
    107     if ($action !== 'export_selected_courses') {
    108         return $redirect_to;
    109     }
    110 
    111     if (!current_user_can('manage_options')) {
    112         wp_die(esc_html__('Unauthorized access', 'easysecure-import-export-courses-learndash'));
    113     }
    114 
    115     if (empty($post_ids)) {
    116         wp_die(esc_html__('No courses selected for export.', 'easysecure-import-export-courses-learndash'));
    117     }
    118 
     117    if ($action !== 'export_selected_courses') return $redirect_to;
     118
     119    if (!current_user_can('manage_options')) wp_die('Unauthorized access');
     120    if (empty($post_ids)) wp_die('No courses selected for export.');
    119121    if (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_wpnonce'])), 'bulk-posts')) {
    120         wp_die(esc_html__('Security check failed.', 'easysecure-import-export-courses-learndash'));
    121     }
    122 
    123     // Determine export format
     122        wp_die('Security check failed.');
     123    }
     124
    124125    $format = 'xlsx';
    125     if (isset($_GET['format'])) {
    126         $format_sanitized = sanitize_text_field(wp_unslash($_GET['format']));
    127         if (in_array($format_sanitized, ['csv', 'xlsx'], true)) {
    128             $format = $format_sanitized;
    129         }
    130     }
    131 
    132     // Collect all course data
     126    if (isset($_GET['format']) && in_array(sanitize_text_field(wp_unslash($_GET['format'])), ['csv','xlsx'], true)) {
     127        $format = sanitize_text_field(wp_unslash($_GET['format']));
     128    }
     129
    133130    $coursedata = [];
    134131    $lessondata = [];
    135     $topicdata  = [];
     132    $topicdata = [];
    136133
    137134    foreach ($post_ids as $course_id) {
     
    143140    // --- Prepare Writer ---
    144141    if ($format === 'csv') {
    145         $writer = new \OpenSpout\Writer\CSV\Writer();
     142        $writer = WriterEntityFactory::createCSVWriter();
    146143        $filename = 'selected-courses-' . time() . '.csv';
    147144        header("Content-Type: text/csv");
    148145    } else {
    149         $writer = new \OpenSpout\Writer\XLSX\Writer();
     146        $writer = WriterEntityFactory::createXLSXWriter(); // ✅ Correct v3.4.0 way
    150147        $filename = 'selected-courses-' . time() . '.xlsx';
    151148        header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
     
    159156
    160157    // --- Courses Sheet ---
    161     if ($format === 'xlsx') {
    162         $writer->getCurrentSheet()->setName('Courses');
    163     }
    164 
    165     foreach ($coursedata as $rowData) {
    166         $writer->addRow(\OpenSpout\Common\Entity\Row::fromValues($rowData));
    167     }
     158    if ($format === 'xlsx') $writer->getCurrentSheet()->setName('Courses');
     159    foreach ($coursedata as $rowData) $writer->addRow(WriterEntityFactory::createRowFromArray($rowData));
    168160
    169161    // --- Lessons Sheet ---
     
    171163        $writer->addNewSheetAndMakeItCurrent();
    172164        $writer->getCurrentSheet()->setName('Lessons');
    173         foreach ($lessondata as $rowData) {
    174             $writer->addRow(\OpenSpout\Common\Entity\Row::fromValues($rowData));
    175         }
     165        foreach ($lessondata as $rowData) $writer->addRow(WriterEntityFactory::createRowFromArray($rowData));
    176166    }
    177167
     
    180170        $writer->addNewSheetAndMakeItCurrent();
    181171        $writer->getCurrentSheet()->setName('Topics');
    182         foreach ($topicdata as $rowData) {
    183             $writer->addRow(\OpenSpout\Common\Entity\Row::fromValues($rowData));
    184         }
     172        foreach ($topicdata as $rowData) $writer->addRow(WriterEntityFactory::createRowFromArray($rowData));
    185173    }
    186174
  • easysecure-import-export-courses-learndash/trunk/import/import.php

    r3393421 r3393564  
    1111{
    1212    global $wpdb, $wp_filesystem;
    13 
    14     if (empty($wp_filesystem)) {
    15         require_once ABSPATH . 'wp-admin/includes/file.php';
    16         WP_Filesystem();
    17     }
    1813
    1914    // Verify nonce before processing
     
    3732    }
    3833
    39     // Move file to uploads dir using WordPress API
    40     if (!function_exists('WP_Filesystem')) {
    41         require_once ABSPATH . 'wp-admin/includes/file.php';
    42     }
    4334    $uploaded_file = wp_handle_upload(
    4435        $_FILES['csv_file'],
     
    233224                            global $wp_filesystem;
    234225                            if (empty($wp_filesystem)) {
    235                                 require_once ABSPATH . 'wp-admin/includes/file.php';
    236226                                WP_Filesystem();
    237227                            }
     
    264254                                $attachment_id = wp_insert_attachment($attachment, $material_full_path);
    265255                                if (!is_wp_error($attachment_id)) {
    266                                     // Only load these if the functions are not already available
    267                                     if (!function_exists('wp_generate_attachment_metadata')) {
    268                                         require_once ABSPATH . 'wp-admin/includes/image.php';
    269                                     }
    270                                     if (!function_exists('media_handle_upload')) {
    271                                         require_once ABSPATH . 'wp-admin/includes/media.php';
    272                                     }
    273                                     if (!function_exists('WP_Filesystem')) {
    274                                         require_once ABSPATH . 'wp-admin/includes/file.php';
    275                                     }
    276256
    277257                                    $attachment_metadata = wp_generate_attachment_metadata($attachment_id, $material_full_path);
     
    395375        wp_reset_postdata();
    396376
    397 
    398377        $associated_course_ids = [];
    399378        foreach ($associated_courses as $course_title) {
     
    438417                        global $wp_filesystem;
    439418                        if (empty($wp_filesystem)) {
    440                             require_once ABSPATH . 'wp-admin/includes/file.php';
    441419                            WP_Filesystem();
    442420                        }
     
    467445                            $attachment_id = wp_insert_attachment($attachment, $material_full_path);
    468446                            if (!is_wp_error($attachment_id)) {
    469                                 // Only load these if the functions are not already available
    470                                 if (!function_exists('wp_generate_attachment_metadata')) {
    471                                     require_once ABSPATH . 'wp-admin/includes/image.php';
    472                                 }
    473                                 if (!function_exists('media_handle_upload')) {
    474                                     require_once ABSPATH . 'wp-admin/includes/media.php';
    475                                 }
    476                                 if (!function_exists('WP_Filesystem')) {
    477                                     require_once ABSPATH . 'wp-admin/includes/file.php';
    478                                 }
    479 
    480447
    481448                                $attachment_metadata = wp_generate_attachment_metadata($attachment_id, $material_full_path);
     
    795762                            global $wp_filesystem;
    796763                            if (empty($wp_filesystem)) {
    797                                 require_once ABSPATH . 'wp-admin/includes/file.php';
    798764                                WP_Filesystem();
    799765                            }
     
    822788                                    $attachment_id = wp_insert_attachment($attachment, $material_full_path);
    823789                                    if (!is_wp_error($attachment_id)) {
    824                                         if (!function_exists('wp_generate_attachment_metadata')) {
    825                                             require_once ABSPATH . 'wp-admin/includes/image.php';
    826                                         }
    827                                         if (!function_exists('media_handle_upload')) {
    828                                             require_once ABSPATH . 'wp-admin/includes/media.php';
    829                                         }
    830                                         if (!function_exists('WP_Filesystem')) {
    831                                             require_once ABSPATH . 'wp-admin/includes/file.php';
    832                                         }
    833 
    834790
    835791                                        $attach_meta = wp_generate_attachment_metadata($attachment_id, $material_full_path);
     
    932888function import_featured_image($post_id, $image_url)
    933889{
    934     if (!function_exists('wp_generate_attachment_metadata')) {
    935         require_once ABSPATH . 'wp-admin/includes/image.php';
    936     }
    937     if (!function_exists('media_handle_upload')) {
    938         require_once ABSPATH . 'wp-admin/includes/media.php';
    939     }
    940     if (!function_exists('WP_Filesystem')) {
    941         require_once ABSPATH . 'wp-admin/includes/file.php';
    942     }
    943 
    944890
    945891    $upload_dir = wp_upload_dir();
     
    992938{
    993939    global $wp_filesystem;
    994     if (empty($wp_filesystem)) {
    995         require_once ABSPATH . 'wp-admin/includes/file.php';
    996         WP_Filesystem();
    997     }
    998940
    999941    if (preg_match_all('/<img.*?src=["\'](.*?)(?=["\'])|mp4=["\'](.*?\.(?:mp4|mov|avi|wmv|webm))(?=["\'])|<a.*?href=["\'](.*?\.(?:mp4|pdf|gif|mov|avi|wmv|webm))(?=["\'])/i', $content, $matches)) {
  • easysecure-import-export-courses-learndash/trunk/readme.txt

    r3393421 r3393564  
    1010Text Domain: easysecure-import-export-courses-learndash
    1111
    12 A simple plugin to import and export LearnDash courses, lessons, topics, quizzes, and questions.
     12A simple plugin to import and export LearnDash courses, lessons, topics.
    1313
    1414== Description ==
    15 
    16 **LearnDash Course Import & Export – Bulk Upload via CSV is the easiest way to manage LearnDash content in bulk. This plugin lets you import and export LearnDash courses, lessons, and topics using simple and pre-formatted CSV files. Whether you're migrating from another LMS or just want to manage content faster, this tool saves hours of manual work.
     15LearnDash Course Import & Export – Bulk Upload via CSV is the easiest way to manage LearnDash content in bulk. This plugin lets you import and export LearnDash courses, lessons, and topics using simple and pre-formatted CSV files. Whether you're migrating from another LMS or just want to manage content faster, this tool saves hours of manual work.
    1716
    1817You can bulk upload structured content or export single courses for backup or reuse — all with clean CSV files. A downloadable sample CSV is included to make formatting easy.
    1918
    2019== Installation ==
    21 
    22201. Firstly install and activate Learndash plugin.
    23212. Upload the `easysecure-import-export-courses-learndash` folder to the `/wp-content/plugins/` directory.
     
    3735
    3836== Changelog ==
    39 
    4037= 1.0 =
    4138* Initial release.
    42 * Added support for importing and exporting LearnDash courses, lessons, topics, quizzes, and questions.
     39* Added support for importing and exporting LearnDash courses, lessons, topics.
    4340* Bulk export feature added.
    4441
    4542== Upgrade Notice ==
    46 
    4743= 1.0 =
    4844Initial release of the plugin.
Note: See TracChangeset for help on using the changeset viewer.