Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] - Only show page on menu if logged in
#1
How can I make a page only show on the menu if the user is logged in?
Thanks,
jwzumwalt
(\__/)
(='.'=)
(")_(")
Reply
#2
(2016-01-12, 14:55:48)jwzumwalt Wrote: How can I make a page only show on the menu if the user is logged in?

Look here http://get-simple.info/wiki/how_to:page_editing

Search  Create a New Page and look at  Page Options
Reply
#3
Private pages are not filtered automatically in menus, you have to write your own menu functions.
It only controls its visibility /access
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#4
get_navigation_customget_navigation


(2016-01-12, 14:55:48)jwzumwalt Wrote: How can I make a page only show on the menu if the user is logged in?
Quote:[NOT POSSIBLE] - Only show page on menu if logged in
Why not possible? A lot of things possible with GetSimple. Smile
1. Create private page and add it to menu;
2. Paste this function into your website template functions.php file;
3. Use get_navigation_custom instead standart get_navigation function.

PHP Code:
function get_navigation_custom($currentpage,$classPrefix "") {

 
 $menu '';

 
 global $pagesArray;
 
 
  $pagesSorted 
subval_sort($pagesArray,'menuOrder');
 
 if (count($pagesSorted) != 0) { 
 
   foreach ($pagesSorted as $page) {
 
     $sel ''$classes '';
 
     $url_nav $page['url'];
 
     
      if 
($page['menuStatus'] == 'Y') {
 
       if ($page['private'] != 'Y' || is_logged_in()) {
 
         $parentClass = !empty($page['parent']) ? $classPrefix.$page['parent'] . " " "";
 
         $classes trim$parentClass.$classPrefix.$url_nav);
 
         if ("$currentpage== "$url_nav"$classes .= " current active";
 
         if ($page['menu'] == '') { $page['menu'] = $page['title']; }
 
         if ($page['title'] == '') { $page['title'] = $page['menu']; }
 
         $menu .= '<li class="'$classes .'"><a href="'find_url($page['url'],$page['parent']) . '" title="'encode_quotes(cl($page['title'])) .'">'.strip_decode($page['menu']).'</a></li>'."\n";
 
       }
 
     }
 
   }
 
   
  
}
 
 
  echo exec_filter
('menuitems',$menu);

Reply
#5
(2016-01-18, 07:04:36)DimaYakovlev Wrote: get_navigation_customget_navigation

Wow!   Thanks,  you are really talented...

Now if you feel like helping on something else, I would like to have a button show up on a "404 page not found" that allows the missing page to be created (if the user has backend privileges).

Somehow, the missing page link needs to be sent to the "404 page not found" for a button to be created.

Thanks ahead of time, if you try to solve this Smile
Thanks,
jwzumwalt
(\__/)
(='.'=)
(")_(")
Reply
#6
(2016-01-18, 15:51:17)jwzumwalt Wrote:
(2016-01-18, 07:04:36)DimaYakovlev Wrote: get_navigation_customget_navigation

Wow!   Thanks,  you are really talented...

Now if you feel like helping on something else, I would like to have a button show up on a "404 page not found" that allows the missing page to be created (if the user has backend privileges).

Somehow, the missing page link needs to be sent to the "404 page not found" for a button to be created.

Thanks ahead of time, if you try to solve this Smile

Well... This is quick and dirty solution for your need. Smile
PHP Code:
<?php
/*
Plugin Name: New Page From 404
Description: Helps user to create a new page from 404 
Version: 0.1
Author: Dmitry Yakovlev
Author URI: http://dimayakovlev.ru
*/

$thisfile basename(__FILE__'.php');

# register plugin
register_plugin(
 
 $thisfile,
 
 'New Page From 404',
 
 '0.1',
 
 'Dmitry Yakovlev',
 
 'http://dimayakovlev.ru',
 
 'Helps user to create a new page from 404',
 
 '',
 
 ''
);

add_action('admin-pre-header', function() {
 
 global $url;
 
 if (basename($_SERVER['PHP_SELF']) == 'edit.php') {
 
   if (!$url && isset($_GET['newpagefrom404'])) {
 
     $url $_GET['newpagefrom404'];
 
   }
 
 }
});

function 
get_new_page_from_404_link($link_title) {
 
 global $id;
  global $GSADMIN;
  if (is_logged_in() && $id != '404') {
 
   $url get_site_url(false) . $GSADMIN '/edit.php?newpagefrom404=' urlencode($id);
 
   echo '<a href="' $url '">' $link_title '</a>';
 
  


1. Create plugin with this code and activate it.
2. Create 404 page and template for it.
3. Place in 404 page template this code (in place where you want to get the link to new page creation page):
PHP Code:
<?php if (function_exists('get_new_page_from_404_link')) get_new_page_from_404_link('Create a new page'); ?>
Reply
#7
Ok, so I tried this and it locks up my computer.
I am sure I am not doing something right.

1) I copied the program and put it in the plugin root directory in a file called "newpagefrom404.php" .

2) I created a blank page in my theme root directory called "newpagefrom404.php" and placed the line
<?php if (function_exists('get_new_page_from_404_link')) get_new_page_from_404_link('Create a new page'); ?>
in it.

When I activate the plugin, it locks up.
Thanks,
jwzumwalt
(\__/)
(='.'=)
(")_(")
Reply
#8
(2016-01-19, 07:46:51)jwzumwalt Wrote: Ok, so I tried this and it locks up my computer.
I am sure I am not doing something right.

1) I copied the program and put it in the plugin root directory in a file called "newpagefrom404.php" .

2) I created a blank page in my theme root directory called "newpagefrom404.php" and placed the line
<?php if (function_exists('get_new_page_from_404_link')) get_new_page_from_404_link('Create a new page'); ?>
in it.

When I activate the plugin, it locks up.

You can send me zip of your site and I will help you to configure it properly. Smile
Reply
#9
(2016-01-19, 16:55:36)DimaYakovlev Wrote: You can send me zip of your site and I will help you to configure it properly. Smile

If you are familiar with ftp, I can create a ftp user account for you. Will that be ok with you?
Thanks,
jwzumwalt
(\__/)
(='.'=)
(")_(")
Reply
#10
(2016-01-19, 17:32:20)jwzumwalt Wrote:
(2016-01-19, 16:55:36)DimaYakovlev Wrote: You can send me zip of your site and I will help you to configure it properly. Smile

If you are familiar with ftp, I can create a ftp user account for you. Will that be ok with you?

Ok! But also I need access to admin area.
Reply
#11
I would just use my component hook plugin and a small component. less complicarted
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#12
(2016-01-19, 22:27:38)shawn_a Wrote: I would just use my component hook plugin and a small component. less complicarted

Hey, Shawn, I don't now about your plugin before. Smile A lot of things can be done with it without developing standalone small plugins.
Reply
#13
jwzumwalt, you can try another way, with using Shawns plugin sa hook components.

For simplicity, I combined all code into one component. But you can split it into to two components - one for frontend, another for backend.
PHP Code:
<?php
global $GSADMIN;
global 
$id;
global 
$url;
if (
is_frontend()) {
 
 if ($url == '404' && $id != $url && is_logged_in()) {
 
   $url get_site_url(false) . $GSADMIN '/edit.php?newpagefrom404=' urlencode($id);
 
   echo '<a href="' $url '">Create page</a>';
 
 }
} else {
 
 if (basename($_SERVER['PHP_SELF']) == 'edit.php') {
 
   if (!$url && isset($_GET['newpagefrom404'])) {
 
     $url $_GET['newpagefrom404'];
 
   }
 
 }
}
?>
How to use:
1. Install sa hook components plugin;
2. Create new component with name hook_admin-pre-header and paste into it given PHP code;
3. Call created component from your template or from another component. For example place this code in the default sidebar component:
PHP Code:
<?php get_component('hook_admin-pre-header'); ?>
Reply
#14
You can probably just stick a link on the page if logged in and 404.

It can literally be one line of code.

if(blargh)
echo get_site_url(false) . $GSADMIN . '/edit.php?title=' . _id($id);

But does $id work since we redirect to 404 ?

Also you don't call get_component with my plugin....
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#15
Install my component hook plugin

create component called

hook_content-bottom

add this to it

PHP Code:
<?php
// component hook_content-bottom
GLOBAL $id,$url,$GSADMIN;
if(
$url == '404' && $id != $url && is_logged_in()){
  echo 
'<a href="'.get_site_url(false) . $GSADMIN '/edit.php?title=' _id($id) . '">Create Page</a>';
}
?>

Done
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#16
(2016-01-20, 00:43:46)shawn_a Wrote: You can probably just stick a link on the page if logged in and 404.

It can literally be one line of code.

if(blargh)
echo get_site_url(false) . $GSADMIN . '/edit.php?title=' . _id($id);

But does $id work since we redirect to 404 ?

Also you don't call get_component with my plugin....

There is no redirect if default or user 404 page existed. So $id is setted from $_GET array and $url is setted from $data_index object.

In my code I want to set value for page slug not for title, because page was requested by slug. For this I need to call hook in admin header.
Reply
#17
The slug will automatically be set from the title, so it makes no difference, and makes the code simpler, since you cannot preset slug through querysting


hmm, I see the problem now, it still doesn't populate, so you can change the title.

hmm
I wonder if there is another way around that, definitely something i want to fix in the future.
I guess set $url global via another hook...

It looks like we removed this functionality at some point as there is a $uri querystring param that is not used.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#18
(2016-01-20, 01:20:19)shawn_a Wrote: The slug will automatically be set from the title, so it makes no difference, and makes the code simpler, since you cannot preset slug through querysting

Yes, slug will be automatically setted from title on page save.  But in this situation slug must be setted firstly and it not depend from title. Just because we need create page with slug what have been requested.
Reply




Users browsing this thread: 2 Guest(s)