gpt4 book ai didi

php - 在 wordpress 中运行 php 应用程序

转载 作者:行者123 更新时间:2023-11-28 23:38:14 25 4
gpt4 key购买 nike

所以我拥有一家电脑维修店。我们有一个我们非常喜欢的销售点软件。有一个“检查修复状态”文件夹,你可以在另一个网站上安装这个应用程序,我喜欢它的工作方式,但想合并它(deps.php、index.php、headerstatus.php、footerstatus.php、common.php ) 全部放入一个文件中,这样我就可以在 WordPress 页面的帖子部分执行该 php 删除 <? php {php _code here} ?>标签并将其替换为 [insert_php] {php code here} [/insert_php]使用 wordpress 插件“insert php”,只有这两个标签之间的代码会在它发布的 WordPress 页面 (inphp) 内执行。

问题是它无法从那里访问另一个文件,它必须全部包含在内。由于 wordpress 页面不是物理位置,而是来自数据库的信息。从页面运行 php 会很好,这样我就可以轻松地为框和 div 创建几个小的自定义类大小,然后删除 php 中所有以前的自定义类和样式,并允许我们主题中的默认类/样式采用它们由我为那些未由我们主题的默认 css 定义的样式/类(可能是内联的)放置和自定义样式/类。

那么有没有命令我们可以用来告诉索引在同一个文件中引用这些函数、参数或命令的位置,而不是引用单独的文件?

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 或其他命令指向本地化的函数、行或路径来代替它。要么(注意我说的是可能,这段代码不需要完美,它需要从单个脚本运行并工作。我知道人们讨厌推荐非标准的编程答案。)

重写 common、deps 和 php 文件中所需的每个单独元素以反射(reflect)其寻找的数据类型需要多少工作量?或者重写索引中的代码以更好地使用本地化函数会更有意义吗?

问题是我需要这个来工作,但在网上找不到示例,这通常不是一个好兆头。我愿意接受任何和所有的建议!在这里只是抛出一些想法,如果你有什么建议也请举个例子。

最佳答案

执行此操作的最佳方法是保留要插入的应用程序的文件夹结构。这样路径应该仍然有效,它们是相对于文件的,所以应该仍然有效。

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

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

  2. 将以下代码放在您的主题 functions.php 中(或创建一个子主题

    //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(目前看起来很有趣)..

现在修改 index.php 文件...我们需要做的就是注释掉 headerstatus 和 footerstatus 要求,它们会破坏 html 输出...

我们可以使用 get_header() 加载 wp 站点的标题,它将加载 css、导航等,并使用 get_footer() 加载页脚元素。

    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 代码没有样式。您可以使用

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

(注意这是 html,关闭 php 标签以使用它)但我建议您打开此文件并复制到主题中的 style.css 中,然后您可以更改 css 以适应。

请注意,这可能会按原样工作,但可能会出现错误,因此请彻底检查操作。我将建议您使用 google wpdb 并更新以使用 WP 数据库功能(如果需要,您可以创建单独的表),否则您将有 2 个数据库连接。这对网站的性能不利,它可以加载 1 个用户,但 3/4 的并发用户将开始减慢一切...

关于php - 在 wordpress 中运行 php 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35189328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com