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

时间:2013-02-24 14:32:05

标签: php wordpress constructor include

我正在使用构造函数主题构建一个Wordpress站点。我不得不添加自定义编码来解决我的目标。有一个模块,让用户将子元素添加到他的配置文件中,这些元素将保存到数据库中。 (创建,更新,删除)此功能通过以下文件完成:

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

目前这些文件没有包含,只能从自定义编码页面模板中调用它们。到目前为止他们工作。

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

$user_id = get_current_user_id();

在get_users.php中控制sql并在用户未登录时重定向用户。我可以包含哪些文件以及如何使用get_current_user_id()? (只需包含'../../../../wp-includes/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);


?>

2 个答案:

答案 0 :(得分:1)

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

您可以通过以下方式添加Wordpress功能:

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

答案 1 :(得分:0)

最后用iframe解决了。不是很安全,但至少可以表现出来。

相关问题