douxia5179 2014-05-28 15:37
浏览 62
已采纳

用于解析TEXT文件(逗号分隔值)的WP插件,并将它们导入WP数据库

This is my first time writing a simple plugin for Wordpress so don't be evil with me. See this is what I'm trying to do with my plugin:

  1. Allow users from Admin CP to upload (temporary or not) a .txt file which contains several lines, each lines has some values as for example: GALUE,YOMAR,A,PP 36199230,,MVD,Y,9992200030748,1,3B,3,Y,C
  2. I need to parse this data and then attach to existent user by matching their names with the ones extracted from uploaded data

By attach to existent user I mean create extra meta data for that users and persist to the DB. Also if it's possible I would like to add support to edit some of this metadata only.

That's all but I don't know how to start writing a plugin, I read the docs at WP site but isn't clear at all to me. Can any give me some tips or maybe a piece of code as starting point?

  • 写回答

1条回答 默认 最新

  • douxiaochun4964 2014-05-28 17:08
    关注

    You're going to need to read the documentation, a lot. It starts with a simple header to a PHP file:

    Standard Plugin Information

    The top of your Plugin's main PHP file must contain a standard Plugin information header. This header lets WordPress recognize that your Plugin exists, add it to the Plugin management screen so it can be activated, load it, and run its functions; without the header, your Plugin will never be activated and will never run. Here is the header format:

       <?php
        /**
         * Plugin Name: Name Of The Plugin
         * Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
         * Description: A brief description of the Plugin.
         * Version: The Plugin's Version Number, e.g.: 1.0
         * Author: Name Of The Plugin Author
         * Author URI: http://URI_Of_The_Plugin_Author
         * License: A "Slug" license name e.g. GPL2
         */
    

    Then, you'll have to create the plugin's UI with add_(sub)menu_page() and auxiliary functions and hooks.

    To import the file, the basic is:

    $import_file = $_FILES['import_file']['tmp_name'];
    $csv = file_get_contents( $import_file );
    

    That's from the tutorial Building a settings import and export feature, although it deals with JSON.

    Also, you can learn from existing plugins, like CSV Importer, and researching the <plugin-development> tag at WPSE.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)