Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress:注册激活钩子不';正在开发我的插件_Php_Wordpress_Plugins - Fatal编程技术网

Php Wordpress:注册激活钩子不';正在开发我的插件

Php Wordpress:注册激活钩子不';正在开发我的插件,php,wordpress,plugins,Php,Wordpress,Plugins,我正在创建一个新的插件测试,当我在我的wordpress插件区激活时,什么都没有发生 有人有同样的问题吗? 我没有任何错误消息,只是没有发生任何 提前谢谢 <?php /* Plugin Name: My Admin Plugin URI: Description: Seu admin personalizado. Version: 0.1.4 Author: Vinícius Lourenço Author URI: Text Domain: my-admin Domain Path

我正在创建一个新的插件测试,当我在我的wordpress插件区激活时,什么都没有发生

有人有同样的问题吗? 我没有任何错误消息,只是没有发生任何

提前谢谢

<?php
/*
Plugin Name: My Admin
Plugin URI: 
Description: Seu admin personalizado.
Version: 0.1.4
Author: Vinícius Lourenço
Author URI: 
Text Domain: my-admin
Domain Path: /languages
*/

register_activation_hook(__FILE__, 'ativar' );

function ativar(){
    add_action('admin_menu','vilourenco_create_menu');
}


function vilourenco_create_menu(){
    add_menu_page('Menu de Opções','ViLourenco Settings','administrator', 'admin_fera' , 'vilourenco_menu_page','dashicons-format-status');
    add_action('admin_init','vilourenco_register_settings');
}


function vilourenco_register_settings(){
    register_setting('vilourenco-options', 'nome');
    register_setting('vilourenco-options', 'idade');
    register_setting('vilourenco-options', 'cidade');
}

function vilourenco_menu_page(){
    ?>
<div class="wrap">
<?php screen_icon(); ?>
<h2>Vinicius Plugin</h2>

<?php if( isset( $_GET['settings-updated'] ) ) : ?>
    <div class="updated">
      <p>Configurações salvas com sucesso!</p>
    </div>
    <?php endif; ?>

<form method="post" action="options.php">
    <?php settings_fields( 'vilourenco-options' ); ?>
    <?php do_settings_sections( 'vilourenco-options' ); ?>
    <table class="form-table">
    <tr valign="top">
    <th scope="row">Nome</th>
    <td><input type="text" name="nome" value="<?php echo esc_attr( get_option('nome') ); ?>" />    </td>
    </tr>

    <tr valign="top">
    <th scope="row">Idade</th>
    <td><input type="text" name="idade" value="<?php echo esc_attr( get_option('idade') ); ?>" />   </td>
    </tr>

    <tr valign="top">
    <th scope="row">Porte</th>
    <td><input type="text" name="cidade" value="<?php echo esc_attr( get_option('cidade') ); ?>" /></td>
    </tr>
</table>

<?php submit_button(); ?>

</form>
</div>

<?php } ?>

Vinicius插件
配置成功

诺姆
register\u activation\u hook
的回调只执行一次,即在激活时执行。它通常用于添加选项或创建数据库表

注册插件设置和菜单应该在单独的函数中完成,并连接到(admin)init


您的日志内容是什么?你怎么能确定问题来自于代码psoted?太好了!谢谢@diggy!现在,我使用add_action()来设置这个函数,并只向您所说的特定任务注册_activation_hook。