It would be really easy if function names would automagically be linked to the codex, the function reference or the Trac browser. If someone could create a solution that does this via Javascript, we could probably convince the powers that be to add it here (if Math Overflow can have MathJax to format formulas, surely we can have something too!).
-
Cool feature, indeed.– IgnacioAug 12, 2010 at 14:43
-
I don't know if it should be automatic though, as could pick up false positives, but maybe some sort of tag to do it?– Adam DempseyAug 12, 2010 at 14:52
-
3Well, we use backticks ` to mark code snippets ... maybe automatically highlight/link functions that are contained within backticks ... and use a tilda ~ or something similar to mark functions when they're used as a standalone references.– EAMannAug 17, 2010 at 15:18
-
Great idea. Where are we on this?– editorFeb 14, 2011 at 20:26
-
@editor: Not very far! It would require someone to take up the work and write a Javascript implementation that does this. After some of us start using it (first as a Greasemonkey script), we can try to confirm the site owners to include it by default.– Jan FabryFeb 17, 2011 at 13:46
5 Answers
Now that my QueryPosts (meta) WordPress code reference site had launched - in case connecting to Codex is complicated or not preferable... I will be very, verrrry open to provide such API to be used by WPSE. :)
-
Would it not be a problem that your site is not open source nor community driven like the actual codex ?– WyckMay 14, 2012 at 5:50
-
1While nice in theory (and a very generous offer), I think, long-term, it would be preferable to connect directly to the Codex. Perhaps we could use queryposts.com as a temporary fix, and as a way to work out the script/API issues from WPSE's end? May 14, 2012 at 14:43
-
I am just throwing this as one of the options. It's true that QueryPosts is my site, but that also means that it will be more open and flexible towards working with WPSE than Codex. Anyway there had been little traction on this issue, so I am not sure if this ever happening anyway.– RarstMay 14, 2012 at 15:13
I think it would be great if posters would include more links to the things they reference in-line with their questions. Makes the site much more useful. I feel like the WYSIWYG tool is pretty explicit, and I would prefer it NOT to add links if I don't want it to. Also, links are not allowed within a block of source code.
Maybe another thought would be to have named functions listed after the answer or question, like:
Functions referenced in this answer: is_admin(), wp_enqueue_script()
... with each one linked?
-
1That's a nice format. I looked at the list of the function reference, and there are 3698 functions defined in WordPress, totaling 56308 characters. This should be doable in a single JS file. Who wants to give it a try? Aug 12, 2010 at 18:18
-
-
One small thing which I've just noticed is with
is_page
andis_paged
- what should I do here? I'm regex'ing out the function names and sois_page
is matching the functionis_paged()
– nobodyAug 12, 2010 at 19:10 -
-
1@EAMann, I have a solution in my head, I just haven't found enough time to go through and change the current code yet.– nobodyAug 17, 2010 at 16:40
-
2@Thomas: Is your code public anywhere, so others can base their work on it? Sep 25, 2010 at 7:54
I have inquired about this in mod room and it was suggested as first step that easy to use endpoint would be strong requirement to consider this.
Function pages in Codex follow specific title
Function Reference/the content
and URL structure:
http://codex.wordpress.org/Function_Reference/the_content
Since Codex is is powered by MediaWiki it exposes its API and it is possible to query for a page by title:
Gives:
<?xml version="1.0"?>
<api>
<query>
<normalized>
<n from="Function_Reference/the_content" to="Function Reference/the content" />
</normalized>
<pages>
<page pageid="765" ns="0" title="Function Reference/the content" touched="2012-01-03T22:52:29Z" lastrevid="110295" counter="18814" length="4259" fullurl="http://codex.wordpress.org/Function_Reference/the_content" editurl="http://codex.wordpress.org/index.php?title=Function_Reference/the_content&action=edit" />
</pages>
</query>
</api>
If page is missing:
http://codex.wordpress.org/api.php?action=query&prop=info&inprop=url&titles=not_a_function
Gives:
<?xml version="1.0"?>
<api>
<query>
<normalized>
<n from="not_a_function" to="not a function" />
</normalized>
<pages>
<page ns="0" title="not a function" missing="" fullurl="http://codex.wordpress.org/not_a_function" editurl="http://codex.wordpress.org/index.php?title=not_a_function&action=edit" />
</pages>
</query>
</api>
Response format can be customized, as well as other properties. I am not very proficient with it, just put this together from API docs.
-
Just dropping a note that this is still being investigated. Sorry for the delays. ♪ Feb 24, 2012 at 15:09
We could start creating tags for functions and include the Codex Url in the tag wiki.
It would also give you a list of all questions about the function by clicking hovering over the tag.
Update:
I made a tag wiki edit for query-posts Using the same format as Rarst's queryposts.com format.
The Stack Exchange javascript already includes a regex parser for turning [tag:some-tag]
into some-tag so it shouldn't be impossible to add something similar using http://codex.wordpress.org/Function_Reference/tagged_function
as the url to output. We would also have to convert -
to _
since our tags use a hyphen instead of an underscore.
Stack Exchange tag parsing regex function:
function(b, c, d, a, g, i) {
for (var j = $(b).val(), p = sanitizeAndSplitTags(j, !0), s = !1, q = 0; q < p.length; q++)
0 != $.trim(p[q]).length && ($©.children().each(function() {
$(this).text() == p[q] && ($(this).fadeTo(500, 0.1).fadeTo(500, 1), s = !0)
}), s || (j = $.URLEncode(p[q]), $©.append('<a id="' + p[q] + '" href="/questions/tagged/' + j + '" class="' + a + '" title="show questions tagged \'' +
p[q] + "'\">" + p[q] + "</a> "), e(d)), s = !1);
$(b).val("");
g && $(b).focus();
i || f(d, $©.text());
h()
}
-
I would be against tags and manual maintenance of those for such purpose. Codex can't get close to complete function reference, we wouldn't be able to reach a fraction of Codex coverage in this fashion. The point of auto-linking is computers doing all grunt work. Getting human in the chain is compromise that shots the process (as it does for Codex in my opinion).– RarstMay 18, 2012 at 11:08
-
Have you ever looked at the Geshi syntax highligher? I was playing with over the weekend and created a WordPress language file that links every function to codex in the code block. It uses a keyword parser that is slow with all WP functions in it but could be trimmed down.– Chris_OMay 29, 2012 at 21:43
I'm tagging this as a favorite so I can quickly get back to this URL via meta:
- http://core.trac.wordpress.org/browser/tags/3.0.1/wp-includes/post-template.php#L775
Or more generally:
- http://core.trac.wordpress.org/browser/tags/<version>/<file path>#<line no.>