1
votes

i am trying to call a callable function that will write a file when plugin is activated

this is my code

register_activation_hook( __FILE__, 'ordero_create');

function ordero_create(){

$file = plugin_dir_path( __FILE__ ) . '/errors.txt'; 
$open = fopen( $file, "a" );

with above code, plugin is successfully activated but ordero_create() function is not being called.

when i change register_activation_hook to become like this

register_activation_hook( __FILE__, ordero_create());

the plugin is successfully activated and ordero_create() function is being called. but there is a warning like this

The plugin generated 230 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.

i'm sure there is no space or new line after ?> or before <?php

1
can you provide whole function body? - Banzay

1 Answers

0
votes

finally, its solved.

previously i have 2 files, index.php that contain standard wordpress plugin initialization that call another php file that contain the main code

    <?php
/*
Plugin Name: tes
Plugin URI: xxx
Description: xxx
Version: 1.0.1
Author: xxx
Author URI: xxx
License: 
    Copyright 2020 xxx


Logs:
v1.0
- Release first version.
*/
include_once('tes.php');
?>

and then on tes.php

<?php
register_activation_hook( __FILE__, 'ordero_tb_create');



function ordero_tb_create(){

$file = plugin_dir_path( __FILE__ ) . '/errors.txt'; 
$open = fopen( $file, "a" ); 
}
?>

after i merge these two file into one its work like it should be