在wordpress中运行php应用程序 [英] run php application within wordpress

查看:107
本文介绍了在wordpress中运行php应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我拥有一家电脑维修店。我们有一个销售点软件,我们真的很喜欢。有一个检查修复状态文件夹,你可以在另一个网站上安装这个应用程序,我喜欢这种工作方式,但想要合并它(deps.php,index.php,headerstatus.php,footerstatus.php,common.php )所有到一个文件,所以我可以在WordPress页面的post部分执行该php删除
<?标签,并用 [insert_php] {php code here} [/ insert_php] 替换为一个wordpress插件插入php只有这两个标签之间的代码将执行的WordPress页面(inphp)它已被张贴。

So I own a computer repair store. We have a point of sale software that we really like. There is a "check repair status" folder you can install this app on another website, I love the way this works, but want to incorporate it (deps.php, index.php, headerstatus.php, footerstatus.php, common.php) all into one file so I can execute that php in the post section of a WordPress page remove the <? php {php _code here} ?> tags and replace them with [insert_php] {php code here} [/insert_php] with the use of a wordpress plugin "insert php" only the code between those two tags will be executed inside that WordPress page (inphp) it has been posted on.

问题是它无法连接到另一个文件,它必须包含所有。因为wordpress页面不是物理位置,而是来自DB的信息。这将是很好从页面上运行php,所以我可以很容易地创建一个几个小的自定义类大小的框和div然后删除所有以前的自定义类和样式在PHP,并允许默认类/样式从我们的主题采取他们

The problem is it cannot reach out to another file from there it all has to be contained. Since wordpress pages aren't physical locations rather information from a DB. It would be nice to run that php from the page so I could easily just create a couple small custom class sizes for boxes and divs then delete all previous custom classes and styles in the php and allow the default class/styles from our theme take their place and custom styles/classes (likely inline)by me for those that aren't defined by the default css of our theme.

因此,我们可以使用的命令是:告诉索引在同一文件中引用这些函数,参数或命令的位置,而不是引用单独的文件?

So is there command we could use to tell the index where to reference those functions, parameters, or commands from within the same file, as opposed to referencing separate files?

require("deps.php"); require("headerstatus.php"); require("common.php");
require_once("footerstatus.php");
function showstatus() { require("deps.php"); require("headerstatus.php"); require("common.php");

因此,如果无法删除require,或使用require或another命令指向本地化函数,线或路径。 (注意我说的可能,这段代码不需要是完美的,它需要从单个脚本和工作运行我了解人们讨厌推荐非标准的编程答案。)

So if it's not possible to remove require, or use the require or another command to point at a localized function, line, or path in its place. either a (note I said possible, this code doesn't need to be perfect it needs to run from a single script and work. I understand people hate to recommend non standard answers to programming.)

要从common,deps和php文件中重写每个单独的项目需要多少工作来反映它寻找的数据类型?
或者更有意义的是,在索引中重写代码以更好地使用本地化函数?

How much work would it be to rewrite each individual item needed from the common, deps and php files to reflect the type of data its looking for? Or would it make more sense to rewrite the code in the index to work better with localized functions?

问题是,我需要这个工作,可以找到没有在线的例子,这通常不是一个好兆头。我打开任何和所有的建议!

The problem is that I need this to work, and can find no examples online which is not usually a good sign. I'm open to any and all suggestions! Just throwing out ideas here, also if you make a suggestion please give an example.

推荐答案

这是最好的方法。这样做是为了保留要插入的应用程序的文件夹结构。路径应该仍然工作,它们是相对于文件所以仍然应该工作。

The best way to do this is to preserve the folder structure of the application you want to insert. This way paths should still work, they are relative to the file so should still work.

所以
1.在您的主题中创建一个新文件夹名为repairstatus

so 1. create a new folder in your theme called "repairstatus"


  1. 将所有文件上传到 - index.php等

  1. upload all the files into that -- index.php etc

将以下代码放在主题中函数functions.php(或创建子主题

Place the following code in your themes functions.php (or create a child theme

//1. add a wp query variable to redirect to
add_action('query_vars','plugin_set_query_var');
function plugin_set_query_var($vars) {
    array_push($vars, 'is_repair_page'); // ref url redirected to in add rewrite rule

    return $vars;
}


//2. Create a redirect
add_action('init', 'plugin_add_rewrite_rule');
function plugin_add_rewrite_rule(){
    add_rewrite_rule('^repairstatus$','index.php?is_repair_page=1','top');

    //flush the rewrite rules, should be in a plugin activation hook, i.e only run once...

    //flush_rewrite_rules();  
}

//3.return the file we want...
add_filter('template_include', 'plugin_include_template');
function plugin_include_template($template){


    // see above 2 functions..
    if(get_query_var('is_repair_page')){
        //path to your template file
        $new_template = get_stylesheet_directory().'/repairstatus/index.php';
        if(file_exists($new_template)){
            $template = $new_template;
        } 
        // else needed? up to you maybe 404?
    }    

    return $template;    

}


现在,导航到管理仪表板上的设置,然后点击固定链接。只需点击保存按钮。在此阶段测试, http://accuratepctech.com/repairstatus/ 应该打开index.php(它会看起来有趣的一刻)。

Now navigate to settings on the admin dashboard and click on permalinks. Just hit the save button. test at this stage, http://accuratepctech.com/repairstatus/ should open index.php (it will look funny for the moment)..

现在mod index.php文件...所有我们需要做的是注释headerstatus和footerstatus要求,他们将打破html output ...

now mod the index.php file...all we need to do is comment out the headerstatus and footerstatus requires, they will break the html output...

我们可以使用 get_header()加载wp网站的标题, css,导航等和 get_footer()用于页脚元素。

We can use get_header() to load the header of the wp site which will load css, navigation etc. and get_footer() for the footer element.

    if (array_key_exists('func',$_REQUEST)) {

    $func = $_REQUEST['func'];

    } else {

    $func = "";

    }





    //loads header and related 
    get_header();


    function repairlookup() {

    require("deps.php");

    //require("headerstatus.php"); -->not needed, its only html

    require("common.php");

    //etc////////////


    //find require("footerstatus.php") and remove

    }

    get_footer();

现在你应该有一个wp寻找页面只是index.php代码将被取消。您可以使用

now you should have a wp looking page just the index.php code will be unstyled. You can add the css in by using

<link rel="stylesheet" type="text/css" href="style.css">

(注意这是html,关闭php标签才能使用它),但是id建议你打开这个文件,复制到你的style.css中你的主题,然后可以改变CSS以适应。

(note this is html, close php tags to use it) but id recommend you open this file and copy into your style.css in your theme, you can then change the css to suit.

请注意,这可能会按原样工作,但可能有错误,因此请检查操作。我要推荐你谷歌wpdb和更新使用WP数据库函数(你可以创建单独的表,如果你想要的)否则你有2 db连接在旅途中。这将不利于网站的性能,它将加载确定与1个用户,但3/4并发用户将开始减慢一切下来...

Note this will probably work as is, but there may be errors so check the operation throughly. I'm going to recommend you google wpdb and update to use WP database functions (you can create seperate tables if you want) otherwise you have 2 db connections on the go. This will not be good for the performance of the website, it will load ok with 1 user but 3/4 concurrent users will start to slow everything down...

这篇关于在wordpress中运行php应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆