Class Library for wordpress
I'm in the process of making something and i'm wondering if any of you will find it useful.
When creating WordPress themes there's a lot of code we have to type over and over again such as code to register menu locations and outputting menu to the page. The registration of sidebars and the display of them so i've began the process of making a class library to make these things cleaner and easier to use while making our themes.
For example with my class library this is how you register a menu location and then how you call the menu with a few options passed to it. https://gist.github.com/phpmypython/088ce5600b945d1889e1#file-gistfile1-php
<?php
// Code to register menu locations
AbleCore\Menu::CreateLocation("header_menu","Header Menu");
AbleCore\Menu::CreateLocation("footer_menu","Footer Menu");
// Code to call those menus
$header_menu = new AbleCore\Menu();
$header_menu->setContainer('nav');
->setContainerClass('dropdown');
->render();
?>
This is what the class file looks like for the menu system
this file is too long for me to paste in but you can click the link and see a gist of it. https://gist.github.com/phpmypython/43bc30314ddde8a8ce16#file-menu-php
I have the functionality for Sidebar registration and displaying built in as well as functionality for the creation of WordPress pages through code i've also began working on a post class that will make it easy to call the WordPress post loop without having to code it directly into the template. However those features aren't commented yet so i don't wanna share it until i have some decent documentation
The Library is currently installable as plugin and is easy to use all you have to do is add and activate the plugin and you can use the code in your theme. if you want an Alpha release of it let me know :)
I plan on adding in functionality to take full advantage of the theme customizer that will allow you create sections and fields to those sections easily and then allow you to call them.
Im curious if this interest anyone and also if anyone has suggestions on useful functionality that maybe i haven't thought about.
6 comments · 100% upvoted · other discussions
[deleted]
phpMyPython [OP] 1 points · Jul 2014
This is essentially being written for a couple of reasons. The first of which is that i work at firm that does a lot of Drupal development and we have a class library that we use for it and this makes it so that you can use AbleCore in WordPress much the same way that we use in Drupal which i understand that reason isn't useful to the community but in the interest of full disclosure there it is.
The second reason is that i find myself all the time having to go to the codex and look up the functions for doing various things like displaying a menu and registering a theme location as an example. Since my class is very semantic it makes it much easier to remember how to do without me having to refer to the codex and also i think it looks much cleaner which is an important thing to me. Also i'm not saying that WordPress isn't already semantic just that it makes it where i don't have to remember all the arguments to pass because i can just chain a method and tell it what i want. which although it's essentially the same way you do it anyway it makes it easier for me.
Keep in mind as well that this is just the class i have documented. i have others im working on which will make this much more useful such as my post class which will eliminate having to code the loop and conditionals directly into your template files. you will be able to call a new loop sets classes on them and wrappers and anything else you may want to do to the posts. much like the options passed to the wp_nav_menu function. Also functionality to make it easier to register theme customizer groups and fields.
[deleted] 2 points · Jul 2014
[removed]
phpMyPython [OP] 2 points · Jul 2014
I think you make a very good point. Thanks for taking the time to give me your opinion on it.
phpMyPython [OP] 1 points · Jul 2014
Also if you can think of another thing in WordPress that i might be able to streamline let me know. This is for me to gauge interest and get ideas.
PixelatorOfTime 1 points · Aug 2014
You clearly know what you're doing with PHP; you should check out the tickets in the Core Trac system to see what you can help out with.