php / WordPress / Ajax Button调用php脚本 - php

我刚刚开始学习PHP,并且正在开发WordPress插件。但是我有一个问题。当我按下一个按钮时,我希望它调用一个PHP脚本,在该脚本中我可以执行其他SQL请求,而无需更改页面即可执行其他操作。我知道我需要使用Ajax,但我不知道如何使用它以及在哪里编写它。请问你能帮帮我吗?

index.php是我具有在其中打印带有复选框的列表和执行脚本createInsert.php的按钮的函数的地方

PS:对不起,我的英语不好。

index.php

 <?php
   public function pref_liste_checkbox(){
        global $wpdb; 

        print '<h3>Composition de la liste synthetique</h3>';
        print '<form method="POST" action=" "><table border="1"><tr><th>Attributs</th><th>Choix</th></tr>';

        $resultat= $wpdb->get_results("SELECT * from wp_frm_fields ",ARRAY_N); 

        foreach ($resultat as $post) {      
           print'<tr>';
           echo '<td>'.$post[2].'</td>';
           echo"<td><center><input type='checkbox' name='choixP[]'value='".$post[0]."'></center></td>";
        }

        print '</tr><input type="submit" name ="execute"value="execute"></table></form>';
    }
?>

createInsert.php

<?php
     //if the table exist =1 
    if(FrmStatisticsController::table_ok('testWP','wp_users')==1){

    ?>
            <script type="text/javascript">

                    var r = confirm("Voulez-vous vraiment mettre à jour les attributs de la liste synthétique?");
                    if (r == true) {

                        <?php
                                ///////////CLEAN LA TABLE//////////
                                ////////////INSERT INTO/////////

                        ?>
                        var f = alert("MàJ réussie !");

                    }else {
                                ///////////Aucune Action\No Action////////
                    }

            </script>
    <?php

    } else (FrmStatisticsController::table_ok('testWP','wp_users')==0){

    ?>
            <script type="text/javascript">

                    var r = confirm("Voulez-vous sauvegarder les attributs de la liste synthétique?");
                    if (r == true) {

                        <?php
                                ///////////CREATE TABLE//////////

                                global $wpdb;
                                $nom_table = $wpdb->prefix .'choix_attributs_liste';
                                $sql = "CREATE TABLE $nom_table ( mytable_id bigint(20) unsigned NOT NULL auto_increment, att_name varchar(255), att_id bigint(20),PRIMARY KEY(mytable_id));";
                                dbDelta($sql);

                                ////////////INSERT INTO/////////
                        ?>

                        var f = alert("Création et insertion des n-uplets réussie!");

                    }else {
                                ///////////Aucune Action\No Action////////
                    }

            </script>
    <?php
    }

参考方案

我知道您的问题是关于按钮的,但是您应该在这之前查看这些问题。

要创建具有标准的插件...请参阅此工具将帮助您获取文件...并设置基本的插件已准备好http://wppb.me/
查看一些教程

http://www.smashingmagazine.com/2011/09/how-to-create-a-wordpress-plugin/
https://codex.wordpress.org/Writing_a_Plugin

在创建插件之前先搜索其他插件(这样就不必重新发明轮子了)
https://wordpress.org/plugins/

WordPress:在网站上仅加载一个jquery脚本 - php

刚要启动一个WordPress网站,但注意到它当前正在加载两个jquery文件,一个包含在wp-includes中,另一个来自我的header.php,是否有一种方法可以使wordpress在前端加载wp-includes?做了大量的搜索,并且对此的唯一提及似乎包括以下代码,但是我找不到关于它的任何文档,任何想法?<?php wp_enqueue_sc…

Ajax在“最新帖子”小部件wordpress中加载更多按钮 - php

我创建了最近发布的Wordpress小部件,并尝试为其创建“加载更多”按钮以通过ajax(例如twitter)获取更多“最近发布的链接”,是否有任何制作方法的教程? 参考方案 看一下infinite scroll插件的来源,它确实可以满足您的需求,并且开发类似的东西,this可以为您提供帮助。

AJAX实时电子邮件验证(PHP) - php

当用户在我的网站上创建帐户时,我希望对照我的数据库(MySQL)中的所有当前用户名检查输入的用户名,并确认是否可用。有谁知道我可以使用的任何好的库,或者是jQuery的插件? 参考方案 所需的确切信息以示例形式here给出。它使用jQuery作为JavaScript库

为什么函数执行后无法获取数组键值? - php

我称这个WordPress功能为:get_user_meta($user->ID, "user_address"); 它返回数组,我不想将其放入变量,而只是将其回显。但这不起作用:get_user_meta($user->ID, "user_address")[0]; 为什么?有什么办法做到这一点吗? 参考…

PHP-复选框组 - php

我有一个需要发布的表单复选框组。<input type="checkbox" value="true" checked name="chk0[]"> <input type="checkbox" value="false" name=…