• Resolved manowp

    (@manowp)


    Hello,

    Great plugin and very useful. I have a question about Priority option given.

    In the php code I am adding – add_filter – has priority as a parameter. Code snippets has this option.

    Which one will be effective ? Am I supposed to keep both Priority same value ?

    Thanks,
    Mano

Viewing 7 replies - 1 through 7 (of 7 total)
  • If you refer in another snippet your own function, which is in another snippet do this:

    1. Se the priority of the snippet, which you refer lower priority, for example 9 if you refer to it in a snippet, which has priority 10
    2. Use always if(function_exists(‘your-function’){
      // use here you own function, for example echo ‘your-function($argument);

      } in the snippet, where you use you own function, which has been defined in another snippet.

    In principle the function_exists should not be needed, but Code Snippet can’t ever check the existence of function reliable. You can’t in this respect rely on Code Snippet at all. So you must use function_exist in order to ensure, that you can save the snippet.

    WARNING!Be careful defining your own functions. Don’t ever define the same function twice. Code Snippet can’t reliable check if your own function already exists or not. It might accept that you have duplicate function definition. If you save a snippet, which cause duplicate function definition, your site will crash.

    Code Snippet has serious bugs relating with handling priorities and checking if function exists or not.

    Plugin Author Shea Bunge

    (@bungeshea)

    The priority feature of Code Snippets simply determines which snippets will run before others. When using add_filter code, it usually doesn’t matter what this is set to.

    When you are adding action and filter hooks, the priority there is important as it will specify whether your hook runs before or after others, which could have an effect on the final result.

    Thread Starter manowp

    (@manowp)

    Thanks.

    Plugin provider has given the list of functions and I am adding them using Code Snippets.

    eg.
    add_filter(‘frm_setup_edit_fields_vars’, ‘frm_set_uri’, 21, 3);
    function frm_set_uri($values, $field, $entry_id){

    21 is the priority mentioned in the add_filter. So, I should make the Code Snippets Priority as 22 ? Please clarify.

    Some examples:
    This is in a snippet with priority

    function pageLists($list){...}

    this is the function call in a snippet, which has priority 18:

    if(function_exists('pageLists')){
    $address = pageLists($list);
    $y=0;
    foreach ($address as $value) {
    	if($y==0){$blogi=$value;}
    ...
    	$y++;
    	}	
    }

    Well the function pageList exist and in the final run WordPress finds it, but if I try to save the snippet without using the if-statement, Code Snippet wrongly complains that the function doesn’t exist. I just can’t save the snippet without using as such unneeded function_exists function. If I define the function in the same snippet, Code Snippet would accept the usage of the function and it would accept to save the snippet. But after saving the site will be crashed!

    Finding of existing own function succeeds sometimes and sometimes not. I don’t have figured any reason, why finding existing function fails. You can try to save your snippet without using if(function_exists(‘your-function’). If Code Snippet doesn’t allow to save the snippet, use then the function_exist(‘your-function’). But remember newer defining your function twice.

    Thread Starter manowp

    (@manowp)

    @bungeshea : I see your reply now and clarified – “When using add_filter code, it usually doesn’t matter what this is set to.”. Thank you.

    Using add_filter the priority setting is not important.

    But it is very important if you use you own function together with your another own function.

    It is important also if you use the same add_action hook in several snippets. because in the final run wrong order means that added code will be put to the template into wrong order. add_action is for adding your own code to templates.

    If you use some other add_action hook the priority setting is not important to change.

    Plugin Author Shea Bunge

    (@bungeshea)

    Yes, it is correct that if you are using the same action or filter hook in different snippets which have the same add_action or add_filter priority, then this is the case where the snippet priority will matter.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Priority Option’ is closed to new replies.