2013-02-24 43 views
0

我正在用構造函數主題構建一個Wordpress網站。我不得不添加自定義編碼來解決我的目標。有一個模塊,讓我們的用戶添加孩子元素到他的個人資料,這將被保存到數據庫。 (創建,更新,刪除)該功能在以下文件來完成:如何添加WordPress的包括和登錄管理自定義模塊?

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

這些文件目前都沒有包括,他們只是從一個自定義編碼的頁面模板調用。到目前爲止他們工作。

現在我想開發這個模塊來處理多個用戶。爲此,我需要知道誰在使用模塊。這我知道在自定義頁面模板,但不是在前面的代碼。 get_users.php。比如我想使用

$user_id = get_current_user_id(); 

在get_users.php控制SQL和重定向用戶,如果他沒有登錄。哪些文件,我怎麼必須包括,爲了能夠使用get_current_user_id() ? (只要加入 '../../../../wp-includes/user.php' 不解決這個問題。)

感謝您的幫助, Sziro

編輯:此是的wp-content \主題\構造\ 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); 


?> 

回答

0

在它與一個iframe解決結尾:

您可以通過包括WordPress的功能。不是很安全,但至少是可以表達的。

1

所以目前一個WordPress主題包括並使用此文件。你想創建另一個/使用相同的PHP文件,以包括WordPress的功能?

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

基本上是。 你的建議沒有解決問題。我在我的文章中包含了代碼。 – Sziro 2013-02-24 15:01:05

+0

在您的文章中?它不會在那裏工作,這是包含在你的PHP文件。 – Skatox 2013-02-24 15:15:01

+0

不知何故,required()函數崩潰。 Ex $ user_id = 1運行正常,require('../../../../ wp-blog-header.php'); $ user_id = 1;崩潰。 – Sziro 2013-02-24 17:35:21

相關問題