Site logo

Archived topic

DISALLOW_FILE_EDIT prevents hooks from working

13 replies · Started by Susanne on March 9, 2022

Viewing posts 1–14 of 14

Hello, I have a website using several hooks built with elements. My client has now installed a security plugin which uses DISALLOW_FILE_EDIT. Now several items like custom menu, and portfolio tags are not working. Is there a way to allow these hooks to be used? can I just put them in the function.php?
thanksa for your help

can I just put them in the function.php?
thanksa for your help

Yes, you can turn your hooks to something like this:

add_action('hook_name', 'hook_1');

function hook_1() {
	your code
}

Ok thank you Ying, would you mind telling me exactly how a code like this would look?

For example I use the hook "generate_after_entry_title" named "add-portfolio-tag-style"
I have placed this code in the field in Elements
<div class="ptag"><?php echo get_the_term_list( $post->ID, 'portfolio_tag', 'Tags: ', ', ', '' ); ?></div>

The display rules are Portfolio Item Archive,Portfolio Item Category Archive and Portfolio Item Tag archive

The result is that it spits out a list of the portfolio tags
Thanks for your help!

Hi Susanne,

You can do it like this:

add_action('hook_name', 'custom_display_portfolio_tags');

function custom_display_portfolio_tags() {
	echo '<div class="ptag">';
	echo get_the_term_list( $post->ID, 'portfolio_tag', 'Tags: ', ', ', '' ); 
	echo '</div>';
}

Change the hook_name to where you want it to display. :)

Hi Elvin,
Thanks so much that worked!
I have one more which I need to add: I made a custom nav to show on certain pages
The hook is 'generate_before_main_content' and my code there is <?php generate_secondary_navigation_position(); ?>
So I just want to show the nav there. But in Elements I can specify on what pages. In my case it is Portfolio Item Category, Portfolio Item Archive and Portfolio Tag archive. How would I specify that just using functions? Thank you so much for your help!

Hi David, Thanks for you fast response.
Yes indeed that would work, I tried it., but my client had a severe hack attack and they specifically put in this security plugin that prevents rewrite. If a hacker gets into the admin somehow they can use the GP hooks to add their own code. Am I right? It even says that "However, it is recommended that if DISALLOW_FILE_EDIT is defined, then you should disable PHP execution in Hooks Element. Likewise, if you disable PHP execution in Hooks Element, you should define DISALLOW_FILE_EDIT as well."

I would love to have a simple solution, but if they get hacked again it will be my fault!

The reality is - if the Hacker can access the Dashboard as an Administrator then they are pretty much free to do whatever they want. They could install their own plugin to run PHP or install Code Snippets and do the same.

But we can replace the function with a snippet if you wish.

What are the display rules you have for the secondary navigation hook ?

I want the nav to show on these locations:

Portfolio Item Category, Portfolio Item Archive and Portfolio Tag archive
Exclusions: all singular, blog, page

I promise I will study up on my hooks!

Follow up question: in your opinion then, is it good practice to use this snippet when " disallow_file_edit" is defined?

Try this snippet:

add_action('generate_before_main_content', function(){
    if ( 'portfolio' === get_post_type() ) {
	    generate_secondary_navigation_position();
    }
});

This assumes that portfolio is the name of the CPT.

Follow up question: in your opinion then, is it good practice to use this snippet when ” disallow_file_edit” is defined?

If it were my own site then I would use the snippet to allow file_edit in the GP Hooks and then use a Security plugin that has 2 factor authentication :)

But for a client who may not have control over there server and has had an issue with hackers I may be inclined to NOT use GP hooks.

Thank you David! The snippet works like magic and I learned a lot. GP customer support is the best!

So very glad to hear that!

This archived topic is closed to new replies.