工作插件代码中断管理员

时间:2014-12-17 作者:Ciprian

如果您对下面的大量代码有任何批评,我将不胜感激。我要做的是查询一组自定义帖子,并根据自定义字段将它们返回到表中。它起作用了。。。正在生成表,返回正确的帖子,但在执行查询后,所有其他仪表板页面都为空。

//add menu option
add_action( \'admin_menu\', \'my_plugin_menu\' );

function my_plugin_menu() {
    add_options_page( \'Limitless Options\', \'Limitless\', \'manage_options\', \'limitless\', \'my_plugin_options\' );
}

function my_plugin_options() {
        if ( !current_user_can( \'manage_options\' ) )  {
            wp_die( __( \'You do not have sufficient permissions to access this page.\' ) );
        }
if( isset($_GET[\'set\']) ) {

//variables
$checkk = array();
$meta = NULL;
$date = NULL;

    //validate
    $start = ($_GET[\'start\'] != NULL ? $_GET[\'start\'] : false);
    $end = ($_GET[\'end\'] != NULL ? $_GET[\'end\'] : false);
    $question = ($_GET[\'question\'] != NULL ? $_GET[\'question\'] : false);
    $answer = ($_GET[\'answer\'] != NULL ? $_GET[\'answer\'] : false);
    $greutate_actuala = ($_GET[\'greutate_actuala\'] != NULL ? $_GET[\'greutate_actuala\'] : false);
    $greutate_dorita = ($_GET[\'greutate_dorita\'] != NULL ? $_GET[\'greutate_dorita\'] : false);
    $check = ($_GET[\'check\'] != NULL ? $_GET[\'check\'] : false);

    $startEx = explode("-", $start);
    $endEx = explode("-", $end);

    if($greutate_actuala) {
      $greutate_a = array(
                 \'key\' => \'greutate_actuala\',
                 \'value\' => $greutate_actuala,      
      );
    }else{
      $greutate_a = NULL;
    }

    if($greutate_dorita) {
      $greutate_d = array(
                 \'key\' => \'greutate_dorita\',
                 \'value\' => $greutate_dorita,
      );
    }else{
      $greutate_d = NULL;
    }

    if($check) {
      $checkk = array(
                  \'key\' => \'check\',
                  \'value\' => 1,
      );
    }

    if($question && $answer) {
      $meta = array(
                \'key\' => $question,
                \'value\' => $answer,
            );
    }
    if($question && !$answer) {
      $meta = array(
                \'key\' => $question,
            );
    }
    if(!$question && $answer){
        $meta = array(
                \'value\' => $answer,
            );
    }

    if($start && $end) {

    echo "start and end";

        $date = array(
                \'after\' => array(
                \'year\'  => $startEx[0],
                \'month\' => $startEx[1],
                \'day\'   => $startEx[2],
            ),

                \'before\' => array(
                \'year\'  => $endEx[0],
                \'month\' => $endEx[1],
                \'day\'   => $endEx[2],
            ),

            \'inclusive\' => true,
        );

    }
    if($start && !$end) {

    echo "start not end";

        $date = array(
            \'year\'  => $startEx[0],
            \'month\' => $startEx[1],
            \'day\'   => $startEx[2],
        );

    }

    $args = array(

        \'post_type\' => \'quiz\',
        \'meta_query\' => array(
            $meta,
            $greutate_a,
            $greutate_d,
            $checkk,
        ),
        \'date_query\' => array(
            $date
        ),

    );

    $loop = new WP_Query( $args );

    echo \'<table border="1" class="table">
            <tr>
              <td>Nume</td>
              <td>Email</td>
         \';

     for($i=1; $i<=10; $i++) {
        echo \'<td \'.(($_GET[\'question\'] === \'question_\'.$i.\'\') ? \'class="active"\' : "").\'>Question \'.$i.\'</td>\';
     }

    echo \'<td \'.(($greutate_actuala) ? \'class="active"\' : "").\'>GA</td>
          <td \'.(($greutate_dorita) ? \'class="active"\' : "").\'>GD</td>
          <td \'.(($check) ? \'class="active"\' : "").\'>Check</td>
          </tr>\';

    while ( $loop->have_posts() ) : $loop->the_post();
      echo \'<tr>\';
        echo "<td>".get_post_meta(get_the_ID(), \'name\', true)."</td>";
        echo "<td>".get_post_meta(get_the_ID(), \'email\', true)."</td>";

        for($i=1; $i <= 10; $i++) {
            echo "<td>".get_post_meta(get_the_ID(), \'question_\'.$i.\'\', true)."</td>";
        }

        echo "<td>".get_post_meta(get_the_ID(), \'greutate_actuala\', true)."</td>";
        echo "<td>".get_post_meta(get_the_ID(), \'greutate_dorita\', true)."</td>";
        echo "<td>".get_post_meta(get_the_ID(), \'check\', true)."</td>";
      echo \'</tr>\';

    $idArr[] = get_the_ID();

    endwhile;

    echo \'</table>\';

    if(isset($_POST[\'csv\'])) {
      csvDownload($idArr);
    }

    if(isset($_POST[\'dl-csv\'])) {
      email_csv();
    }

    echo \'<form method="post" action="">
              <input type="submit" name="csv" value="csv">
          </form>
         \';

    if(isset($_POST[\'csv\'])) {

        echo \'<form method="post" action="">
              <p>CSV to: \'.get_option( \'admin_email\' ).\' Add more: <input type="email" name="email"> ex: [email protected], [email protected]</p>
              <input type="submit" name="dl-csv" value="Send CSV">
              </form>
         \';
    }

}

1 个回复
最合适的回答,由SO网友:Welcher 整理而成

不确定这是否是对此的实际答案,但在pastebin链接的第252行更改:

 <form action="\'.site_url().\'/wp-admin/admin.php/options-general.php" method="get">

 <form action="\'.admin_url(\'options-general.php\').\'" method="get">
当我在设置中提交表单时,它给了我一个找不到的错误。

结束

相关推荐

无法在多站点上查看网络plugins.php或upgrade-core.php

我有一个有5或6个站点的网络。在网络管理面板中,我可以看到除/wp admin/network/plugins之外的所有页面。php页面和/wp admin/network/upgrade核心。php页面。查看文件夹结构时,这两个文件都存在,但由于某些原因,它们不会加载。非常感谢您的帮助。