• Hello,

    i created a plugin and tried to activate it.
    Unfortunatelly i get some Fatal Errors.
    After research via google i found out, that i use some wp functions which are working in functions.php of theme but not in the plugin.

    I found out that it seems to be the problem, that this function are not initialised yet. But if i want to use some wp functions in my plugin what i have to do?

    My code:

    <?php
    defined( 'ABSPATH' ) or die( 'Error' );
    /*
    
    Plugin Name: MyPlugin
     
    Description: This is my own Plugin
     
    */
     
    function get_user_roles() {
    	if( is_user_logged_in() ) {
    	$user = wp_get_current_user();
    	$roles = ( array ) $user->roles;
    	return $roles; // This returns an array
    	// Use this to return a single value
    	// return $roles[0];
    	} else {
    	return array();
    	}
    }
    
    function print_a($value) {
    	echo '<pre>';
    	print_r($value);
    	echo '</pre>';
    }
    
    $myuserid = get_current_user_id();
    $myuserrole = get_user_roles($myuserid)[0];
    $usermeta = get_user_meta($myuserid, 'ztgm_abo_cats');
     
Viewing 5 replies - 1 through 5 (of 5 total)
  • You should read, starting at https://developer.www.ads-software.com/

    Thread Starter firehold

    (@firehold)

    Thank you for your fast answer. i start reading there and i read the basics but wasnt able to find the source of my error or how to use qp functions which are optional or postloaded. Or do i have to register all wp functions via hook?
    Maybe i cant see the wood for the trees, would you give me a hint? ??

    Thread Starter firehold

    (@firehold)

    Unfortunatelly i wasn’t able to find the way to go to prevent this error.
    May someone give me a hint what i have to looking for?

    • This reply was modified 5 years, 11 months ago by firehold.

    Download other plugins and read the code. That might be a better way to learn.

    Thread Starter firehold

    (@firehold)

    Thank you for your answer. Im really happy that you help me.
    I tried to figure out what i’ve missed.
    I tried to look in some simple plugins but nearly all actual are working with classes, of course, its the contemporary programming style.
    I’m within learning it but im not firm already ??

    Unfortunatelly we dont have a big budget for our Project to start so we’ve to do it on our own. Most estimates of cost was at 2000-3000 $ and thats far to much for us.

    So im hard working to learn fast and im everytime thankful for every hints ??

    • This reply was modified 5 years, 11 months ago by firehold.
    • This reply was modified 5 years, 11 months ago by firehold.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Fatal Error after Plugin creation’ is closed to new replies.