template/wordpress/code/main.php in edge_framework-1.0.0 vs template/wordpress/code/main.php in edge_framework-1.1.0
- old
+ new
@@ -3,44 +3,21 @@
EDGE Press v1.0
- Cleaner code for Wordpress Theme
- Requirement: Wordpress 3.8 and PHP 5.3
------------------------------------------- */
include "inflector.php";
+include "cpt.php";
+include "query.php";
function home() { echo home_url()."/"; }
function root() { return get_template_directory_uri()."/"; }
function img() { echo root()."assets/img/"; }
function css() { echo root()."assets/css/"; }
function js() { echo root()."assets/js/"; }
function files() { echo root()."assets/files/"; }
-/*
- ELLIPSIZE
- - Adding "..." at the end of the string.
- - Default is 160 characters
-*/
-function ellipsize($text, $char_number = "160", $etc = "...") {
- $text = html_entity_decode($text, ENT_QUOTES);
- if (strlen($text) > $char_number) {
- $text = substr($text, 0, $char_number);
- $text = substr($text,0,strrpos($text," "));
-
- $punctuation = ".!?:;,-"; // punctuation you want removed
-
- $text = (strspn(strrev($text), $punctuation) != 0)
- ?
- substr($text, 0, -strspn(strrev($text), $punctuation))
- :
- $text;
-
- $text = $text.$etc;
- }
- $text = htmlentities($text, ENT_QUOTES);
- return $text;
-}
-
/*
CUSTOM NAV MENU
*/
function edge_nav_menu() {
@@ -49,116 +26,9 @@
"container_class" => " ",
"container_id" => "",
"menu_class" => " ",
"menu_id" => " ",
));
-}
-
-/*
- DATABASE CALL
-*/
-
-class Post {
- public static function find($args = null) {
- wp_reset_postdata();
-
- if(empty($args) ) {
- $args = array(
- "post_type" => get_called_class()
- );
- }
-
- return new WP_Query($args);
- }
-
- public static function find_by($key, $value) {
- wp_reset_postdata();
-
- $args = array(
- $key => $value,
- "post_type" => get_called_class()
- );
- return new WP_Query($args);
- }
-}
-
-class Page extends Post {}
-
-/*
- CUSTOM POST TYPE
-*/
-
-function add_post_type($name, $icon = "admin-post", $tax_name = null) {
- $plural = Inflector::pluralize($name);
- $singular = $name;
-
- $labels = array(
- "name" => $plural,
- "singular_name" => $singular,
- "add_new_item" => "Add New " . $singular,
- "edit_item" => "Edit " . $singular,
- "new_item" => "New " . $singular,
- "view_item" => "View " . $singular,
- "search_items" => "Search " . $plural,
- "not_found" => "No " . strtolower($plural) . " found",
- "not_found_in_trash" => "No " . strtolower($plural) . " found in Trash",
- "parent_item_colon" => "Parent " . $singular . ":",
- );
-
- $post_args = array(
- "public" => true,
- "menu_icon" => "dashicons-".$icon,
- "labels" => $labels,
- "capability_type" => "post",
- "supports" => array(
- "title",
- "editor",
- "custom-fields",
- "revisions",
- "thumbnail",
- ),
- );
-
- // If taxonomy is given
- if($tax_name) {
- add_taxonomy($tax_name, $name);
- }
-
- register_post_type(strtolower($name), $post_args);
-}
-
-/*
- CUSTOM TAXONOMY
-*/
-
-function add_taxonomy($name, $post_type) {
- $plural = Inflector::pluralize($name);
- $singular = $name;
-
- $labels = array(
- "name" => $plural,
- "singular_name" => $singular,
- "all_items" => "All " . $plural,
- "edit_item" => "Edit " . $singular,
- "view_item" => "View " . $singular,
- "update_item" => "Update " . $singular,
- "add_new_item" => "Add New " . $singular,
- "parent_item" => "Parent " . $singular,
- "search_items" => "Search " . $plural,
- "popular_items" => "Popular " . $plural,
- "add_or_remove_items" => "Add or remove " . strtolower($plural),
- "choose_from_most_used" => "Choose from the most used " . strtolower($plural),
- "not_found" => "No " . strtolower($plural) . " found"
- );
-
- $tax_args = array(
- "labels" => $labels,
- "show_ui" => true,
- "query_var" => true,
- "show_admin_column" => false,
- "hierarchical" => true,
- );
- register_taxonomy(strtolower($name), strtolower($post_type), $tax_args);
}
/* REMOVE MENU ITEMS */
add_action("admin_menu", "remove_menu_items");
\ No newline at end of file