如何将wordpress包含和登录管理添加到自定义模块中


How to add wordpress includes and login management to custom module?

我正在构建一个以Constructor为主题的Wordpress网站。我不得不添加自定义编码来解决我的目标。有一个模块,让用户将子元素添加到他的配置文件中,该模块将保存到数据库中。(创建、更新、删除(此功能由中的以下文件完成

wp-content'themes'constructor'crud'
 destroy_user.php,
 get_users.php,
 save_user.php,
 show_form.php,
 update_user.php 

这些文件目前没有include,它们只是从自定义编码的页面模板中调用的。到目前为止,它们是有效的。

现在我想开发这个模块来处理多个用户。为此,我需要知道谁在使用该模块。我在自定义页面模板中知道这一点,但在例如get_users.php中的代码中不知道

$user_id = get_current_user_id();

在get_users.php中控制sql并在用户未登录时重定向用户。要使用get_current_user_id((,我必须包括哪些文件以及如何包括(简单地包括"../../../wp-includs/user.php"并不能解决这个问题。(

谢谢你的帮助,Sziro

编辑:这是wp-content''themes''constructor''crud''get_users.php

<?php
    $page = isset($_POST['page']) ? intval($_POST['page']) : 1;
    $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
    $offset = ($page-1)*$rows;
    $result = array();
    include 'conn.php';
    require('../../../../wp-blog-header.php');
    $user_id = get_current_user_id(); //This does not work. If it would be set to = 1, it would work.

    $rs = mysql_query("select count(*) from user_partner where user_id=$user_id");
    $row = mysql_fetch_row($rs);
    $result["total"] = $row[0];
    $rs = mysql_query("select * from user_partner where user_id=$user_id limit $offset,$rows");
    $items = array();
    while($row = mysql_fetch_object($rs)){
        array_push($items, $row);
    }
    $result["rows"] = $items;
    echo json_encode($result);

?>

所以目前Wordpress主题包含并使用这些文件。你想创建另一个/使用相同的php文件来包含Wordpress的函数吗?

您可以通过以下方式包含Wordpress功能:

<?php
    require('/root_of_wp_installation/wp-blog-header.php');
    //or     require('../../../../wp-blog-header.php');
    get_categories();
?>

最后用iframe解决了这个问题。不太安全,但至少还不错。