• This could be an issue with my PHP level.

    I understand that if you make a function in a plugin:

    function myFunction () {
     //function code here
    }

    Then you can call that function in a template.

    However, I am trying to make a plugin following a safety standard to put the plugin functions in a class.

    if (!class_exists("EnterClassName")) {
    	class EnterClassName {
    		function EnterClassName() { //constructor
    		}
    
    		function addFunction() {
    			?>
    				<!-- Place Function Code Here -->
    			<?php
    		}
    
    		function addFunction2() {
    			?>
    				<!-- Place Function2 Code Here -->
     				echo "hello all";
    			<?php
    		}
    	} //End Class DevloungePluginSeries
    
    if (class_exists("EnterClassName")) {
    	$nameInstance = new EnterClassName();
    }
    
    //Actions and Filters
    if (isset($nameInstance)) {
    	//Actions
    	// add_action('hook_name', 'your_function_name', [priority], [accepted_args]);
    	//Filters
    	// add_filter('hook_name', 'your_filter', [priority], [accepted_args]);
    }

    So say I wanted to have function2 in a template I was thinking at the end of my code I could put:

    function myTemplateFunction2() {
         print $nameInstance->function2;
    }

    And then I could put myTemplateFunction2() in my template file and this would cause “hello all” to show up in the browser. However, I am not getting any result. Nor an error.

    Am I missing something?

Viewing 1 replies (of 1 total)
  • Thread Starter bdiddymc

    (@bdiddymc)

    nb: that last bit of code should be

    //Template Functions
    function myTemplateFunction2() {
      print $nameInstance->addFunction2;
    }
Viewing 1 replies (of 1 total)

The topic ‘Template Tag from function in Plugin class’ is closed to new replies.