Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
returnPageField
#1
I want to read the parent of a slug in a plugin, if possible without reading the slug xml file.

- In the frontend I cannot use returnPageField($slug,'parent') before index-pretemplate (it's still not defined)

- In the backend (the plugin page) the function is available but doesn't work - I get these errors:
Code:
Notice: Undefined index: my-slug in [...]\admin\inc\caching_functions.php on line 114

Warning: array_key_exists() expects parameter 2 to be array, null given in [...]\admin\inc\caching_functions.php on line 114
(I suppose it's because $pagesArray has not been populated.)

Any other recommended way to do this?
Reply
#2
What version ?

Well its a plugin so I guess all versions preferably.

3.2 or 3.2.1+ ( dont recall ) load page cache on index-header now, and eventually we will have lazy loading.

for now you can probably just check $pagesArray and call
getPagesXmlValues(false) if not set first.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#3
Thank you, but as I only need to find out one parent, I prefer not calling getPagesXmlValues as it would be an extra file read (what I want to avoid).

I was testing with GS 3.2.1 but I've just tried with 3.2.0 and 3.1.2 too.
It seems that, when in index-pretemplate, returnPageField only works since 3.2.1 (so I assume the index-header cache loading was introduced in this version)

This is what I might do to get the parent slug:

Code:
// if version>3.2.0 and is frontend
if (function_exists('get_gs_version') && get_gs_version() >= '3.2.1' && (basename($_SERVER['PHP_SELF']) == 'index.php') ) {
  ... use returnPageField ...
} else {
  .... read page xml  ....
}
Reply
#4
why not just check if pagesarray is empty, and pull the the file manually if you need it. Instead of checking versions.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#5
I'm assuming that get_gs_version and returnPageField will work the same way in future GS versions.

I could check and directly get values from $pagesArray, but I think I cannot be so "sure" it will work the same (name, structure, contents) in the future (when GS uses lazy loading or whatever).
Reply
#6
It will always work the same. $pagesArray IS the global pagecache.

we might add wrappers to abstract it like getPageCache() and add lazy loading to it. ( in fact i already have most of this plumbed in for 3.3)

But you can use $pagesArray just fine.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#7
Is this like what you suggest?

Code:
global $pagesArray;
if ($pagesArray) {
   ... use returnPageField ....
} else {
   ... read xml file ...
}
Reply
#8
yup, you might have to use count() == 0

I am pretty sure caching_functions does a
$pagesArray = array();

So its an empty array when its initialized.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#9
No need to use count. An empty array evaluates to false (I had tested and worked for me, but just in case I searched and found it's how PHP works)

I'll use if($pagesArray) then. Thank you for your comments!
Reply




Users browsing this thread: 1 Guest(s)