Jump to content

Hook, exposed varibale only when logged in


rooofl
 Share

Recommended Posts

I have a hook in a ready.php file, that is supposed to fill a page’s field when a public form is submitted.

wire()->addHookBefore("Pages::saveReady", function(HookEvent $event) {
// do all that for font pages only
  $page = $event->arguments(0);
    // avoid the error “page can’t be saved”
    if($page->id){
      if($page->template->name !== "font") return;
      if(!$page->webfont_archive->count()) return; 
      // fills styles
      foreach($page->webfont_archive->find("ext=woff2") as $font) {
        $styleTitle = basename($font, ".woff2");
        $styleName = wire('sanitizer')->pageName($styleTitle,true);
        $styleToFind = wire('pages')->find("name=$styleName, template=repeater_font_styles");
        wire('log')->save('vtf_custom', "TOFIND: ".$styleToFind);
        
     }
    $event->arguments(0, $page);

I noticed that $styleToFind is logged only when I use the form when being logged. Can someone explain me why? And how can I make sure it can be found also for guests (not logged in visitors)?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...