Handy "edit this page" link when your logged in!

DGEC

So that's how it's done.

Thanks for that info - good job, Dustin!

vivitron

Greetings,

I was using this and made a small modification that makes the link always for the default page when the id changes.


<?php  
if (FRONTEND_LOGIN == 'enabled' AND is_numeric($wb->get_session('USER_ID')))
 if (
$wb->get_session('GROUP_ID')==1)
 {
  
?>

  <a href="<?php echo ADMIN_URL?>/index.php"><?php 
      
echo $TEXT['ADMINISTRATION']; ?>
</a><br />
  <a href="<?php echo ADMIN_URL?>/pages/modify.php?page_id=<?php 
      
if ($page_id
         echo 
$page_id
      else 
         echo  
$wb->default_page_id; ;
      
?>
" target="_blank"><?php echo $HEADING['MODIFY_PAGE']; ?></a>
  <?php
     
}    
    
?>
     


Notice the use of  $wb->default_page_id. 

Hope this helps!

Sincerely,
Dustin Lambert

gavjof

Thank for this 'handy' piece of code.
I'd used something similar in the past for jumping to the ADMIN_URL but the "edit this page" feature is really nice :)

DGEC

You mean... like I did?  :lol:

That's a good point. You might have to just tell them not to do that, I couldn't figure out another way to do it without mucking into the core further and I didn't have time to do that.

It would be best to integrate this function into the system, and have it as an option on Settings, like Log In and Search.

Actually another thing I've been wanting to try doing is a "view page as guest/member/non-admin" function. I remember seeing that on another CMS and thinking how useful that would be. They implemented it as a fixed administrator menu option.  That method sounds like a lot of work for WB.

One quick mod might be to change the Edit Page link to a drop-down listbox with Edit as the first option, and "View as Guest,..." and then display the rest of the types in the Group database.  The view link could pass a parameter and a refresh would then automatically bring back the edit/view menu, hopefully.  Similar to the template preview function - it can work for one page view, but harder to make it sticky.  If it was an available value like the test if you're signed in or not, then you could turn it on and off.

icouto

Wow! This hint is SOOO useful!

Is there a way to automatically find out what the id of the home page is without having to hard-code it? I ask because I can imagine some of my clients deleting the home page, making another one, and causing the link to fail.

DGEC

I was trying to figure out why my implementation of this didn't work until I realized that I was on Home as well. I guess we'll just have to hardcode IF id="" then ID=1 or whatever your home page code is (mine is 3, must have deleted it twice I guess)

Vincent - good idea, but your code got cut off at the end. 

So here's my combined solution!


<?php  
if (FRONTEND_LOGIN == 'enabled' AND is_numeric($wb->get_session('USER_ID')))
 if (
$wb->get_session('GROUP_ID')==1)
 {
  
?>

  <a href="<?php echo ADMIN_URL?>/index.php"><?php 
      
echo $TEXT['ADMINISTRATION']; ?>
</a><br />
  <a href="<?php echo ADMIN_URL?>/pages/modify.php?page_id=<?php 
      
if ($page_id
         echo 
$page_id
      else 
         echo 
"3";
      
?>
" target="_blank"><?php echo $HEADING['MODIFY_PAGE']; ?></a>
  <?php
     
}    
    
?>
     

dellington

I love this! This will be really great for some of the folks I build websites for. Thanks!!

marathoner

This works great for me and saves time when tweaking pages.

However, I'm having a problem. This snippet works fine for every page except my 'home' page which happens to be $page_id=1. Has anyone else had a problem using this snippet with $page_id=1? If so, is there a solution?

Vincent

#5
Very handy indeed!

I slightly refined it (open new window). Thanks.
Vincent

<?php
if(FRONTEND_LOGIN == 'enabled' AND is_numeric($wb->get_session('USER_ID')))
if (
$wb->get_session('GROUP_ID')==1)
{
  
?>

  <a href="<?php echo ADMIN_URL?>/index.php"target="_blank"><?php echo $TEXT['ADMINISTRATION']; ?></a><br />
  <a href="<?php echo ADMIN_URL?>/pages/modify.php?page_id=<?php echo $page_id?>"target="_blank"><?php echo $HEADING['MODIFY_PAGE']; ?></a>

felix_se_cat

check to see if logged in user is an admin could be done with:
if ($wb->get_session('GROUP_ID')==1)

(i did so and it works fine for me)

baZzz

Very handy indeed, good job!
A little improvement, in case you have a multilingual website, you might want to do this:

<?php
if(FRONTEND_LOGIN == 'enabled' AND is_numeric($wb->get_session('USER_ID')))
{
  ?>

  <a href="<?php echo ADMIN_URL?>/index.php"><?php echo $TEXT['ADMINISTRATION']; ?></a><br />
  <a href="<?php echo ADMIN_URL?>/pages/modify.php?page_id=<?php echo $page_id?>"><?php echo $HEADING['MODIFY_PAGE']; ?></a>
  <?php
}
?>


pcwacht

Very good idea, 1 improvement though, the second url, doens't make use of the ADMIN_URL yet, change to:


<?php
       
if(FRONTEND_LOGIN == 'enabled' AND is_numeric($wb->get_session('USER_ID'))) {
      
?>
<a href="<?php echo ADMIN_URL?>/index.php"><?php echo $TEXT['ADMINISTRATION']; ?></a><br />
<a href="<?php echo ADMIN_URL?>/pages/modify.php?page_id=<?php echo $page_id?>">Edit Page</a>
      <?php
      
}
      
?>


I suggestion, maybe a  check to see if the logged in user is admin or has the rights to edit the page??

John



englishdingbat

#1
I wanted a way to quickly edit the page when I was on it, so i just added this simple bit of code in to my template. Place where ever it is convenient for you, but it only shows when you are logged in. You must have login enabled in prefs, but someone might be able to hack the code further???


<?php
 if(FRONTEND_LOGIN == 'enabled' AND is_numeric($wb->get_session('USER_ID'))) {
?>
<a href="<?php echo ADMIN_URL?>/index.php"><?php echo $TEXT['ADMINISTRATION']; ?></a><br />
<a href="http://[you-website.domain]/admin/pages/modify.php?page_id=<?php echo $page_id?>">Edit Page</a>
<?php
}
?>


simple i know, but useful.
Pete