dpcj40970
2013-04-26 09:22
浏览 155
已采纳

如何在WordPress Post文件中编辑php代码?

I have a wordpress page. In that WordPress page, user will have access to the following Window to Publish their Post in to the webpage.

enter image description here

If the user enters an URL in any of the three filed I have marked in red above, my php code will look in to those URLs and determine if they are spam or not. Therefore, I want to put my php code inside the Publish button, so I can either disallow or allow the post after my php code run and determine if those URLs are spam or not. Can you please tell me the name of the wordpress file I should edit in order to put my php code in. I am new to wordpress and don’t know too much about their file structure.

图片转代码服务由CSDN问答提供 功能建议

我有一个wordpress页面。 在该WordPress页面中,用户可以访问以下窗口以发布他们的帖子到网页。

< p>如果用户在我上面用红色标记的三个字段中的任何一个中输入了URL,我的php代码将查看这些URL并确定它们是否是垃圾邮件。 因此,我想将我的PHP代码放在 Publish 按钮中,所以我可以在我的php代码运行后禁止或允许发布,并确定这些URL是否是垃圾邮件。 你可以告诉我我应该编辑的wordpress文件的名称,以便将我的PHP代码放入。我是wordpress的新手,并且不太了解他们的文件结构。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doutian3010 2013-04-26 09:31
    已采纳

    NEVER edit core files. it is the worst practice that you can choose when working with a ready made cms / publishing system

    you need to filter or hook into some action, there are several ones that are triggered when a post is published ,

    for example the wp_insert_post_data fires when the info is INSERTED to the DB .

    add_filter ( 'wp_insert_post_data' , 'my_filter_function' , 99 );
    

    publish_post is when a post is published, or if it is edited and its status is "published". pre_post_update Runs just before a post or page is updated.

    And so on. see the codex page in the link above to read more about actions, filters and hooks.

    And just so You will not forget : NEVER edit core files.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题