PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 4.6
Shortcoder — Create Shortcodes for Anything v4.6
trunk 3.0 3.0.1 3.1 3.2 3.3 3.4 3.4.1 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.3 4.4 4.5 4.6 5.0 5.0.1 5.0.2 5.0.3 5.0.4 5.1 5.2 5.2.1 5.3 5.3.1 5.3.2 5.3.3 5.3.4 5.4 5.5 5.6 5.7 5.8 6.0 6.1 6.2 6.3 6.3.1 6.3.2 6.4 6.5 6.5.1 6.5.2 6.5.3
shortcoder / includes / metadata.php
shortcoder / includes Last commit date
import.php 6 years ago metadata.php 6 years ago
metadata.php
218 lines
1 <?php
2 /**
3 * Gives the page details for the services
4 *
5 */
6
7 class Shortcoder_Metadata{
8
9 public static function init(){
10
11 }
12
13 public static function metadata(){
14
15 global $post;
16
17 $d = array();
18 $defaults = array(
19 'title' => '',
20 'url' => '',
21 'short_url' => '',
22
23 'post_id' => '',
24 'post_excerpt' => '',
25 'post_comments_count' => '',
26 'post_image' => '',
27 'post_author' => '',
28 'post_date' => '',
29 'post_modified_date' => '',
30
31 'site_name' => get_bloginfo( 'name' ),
32 'site_description' => get_bloginfo( 'description' ),
33 'site_url' => get_bloginfo( 'url' ),
34 'site_wpurl' => get_bloginfo( 'wpurl' ),
35 'site_charset' => get_bloginfo( 'charset' ),
36 'wp_version' => get_bloginfo( 'version' ),
37 'stylesheet_url' => get_bloginfo( 'stylesheet_url' ),
38 'stylesheet_directory' => get_bloginfo( 'stylesheet_directory' ),
39 'template_url' => get_bloginfo( 'template_url' ),
40 'atom_url' => get_bloginfo( 'atom_url' ),
41 'rss_url' => get_bloginfo( 'rss2_url' ),
42
43 'day' => date_i18n( 'j' ),
44 'day_lz' => date_i18n( 'd' ),
45 'day_ws' => date_i18n( 'D' ),
46 'day_wf' => date_i18n( 'l' ),
47 'month' => date_i18n( 'n' ),
48 'month_lz' => date_i18n( 'm' ),
49 'month_ws' => date_i18n( 'M' ),
50 'month_wf' => date_i18n( 'F' ),
51 'year' => date_i18n( 'Y' ),
52 'year_2d' => date_i18n( 'y' ),
53
54 );
55
56 if( in_the_loop()) {
57
58 $d = self::meta_by_id( get_the_ID() );
59
60 }else{
61
62 if( is_home() && get_option( 'show_on_front' ) == 'page' ){
63
64 $d = self::meta_by_id( get_option( 'page_for_posts' ) );
65
66 }elseif( is_front_page() || ( is_home() && ( get_option( 'show_on_front' ) == 'posts' || !get_option( 'page_for_posts' ) ) ) ){
67
68 $d = array(
69 'title' => get_bloginfo( 'name' ),
70 'url' => get_bloginfo( 'url' ),
71 'post_excerpt' => get_bloginfo( 'description' ),
72 'short_url' => get_bloginfo( 'url' ),
73 );
74
75 }elseif( is_singular() ){
76
77 if( is_object( $post ) ){
78 $d = self::meta_by_id( $post->ID );
79 }
80
81 }elseif( is_tax() || is_tag() || is_category() ){
82
83 $term = get_queried_object();
84 $d = array(
85 'title' => wp_title( '', false ),
86 'url' => get_term_link( $term, $term->taxonomy ),
87 'post_excerpt' => $term->description
88 );
89
90 }elseif( function_exists( 'get_post_type_archive_link' ) && is_post_type_archive() ){
91
92 $post_type = get_query_var( 'post_type' );
93 $post_type_obj = get_post_type_object( $post_type );
94
95 $d = array(
96 'title' => wp_title( '', false ),
97 'url' => get_post_type_archive_link( $post_type ),
98 'post_excerpt' => $post_type_obj->description
99 );
100
101 }elseif( is_date() ){
102
103 if( is_day() ){
104
105 $d = array(
106 'title' => wp_title( '', false ),
107 'url' => get_day_link( get_query_var( 'year' ), get_query_var( 'monthnum' ), get_query_var( 'day' ) )
108 );
109
110 }elseif( is_month() ){
111
112 $d = array(
113 'title' => wp_title( '', false ),
114 'url' => get_month_link( get_query_var( 'year' ), get_query_var( 'monthnum' ) )
115 );
116
117 }elseif( is_year() ){
118
119 $d = array(
120 'title' => wp_title( '', false ),
121 'url' => get_year_link( get_query_var( 'year' ) )
122 );
123
124 }
125
126 }elseif( is_author() ){
127
128 $d = array(
129 'title' => wp_title( '', false ),
130 'url' => get_author_posts_url( get_query_var( 'author' ), get_query_var( 'author_name' ) )
131 );
132
133 }elseif( is_search() ){
134
135 $d = array(
136 'title' => wp_title( '', false ),
137 'url' => get_search_link()
138 );
139
140 }elseif( is_404() ){
141
142 $d = array(
143 'title' => wp_title( '', false ),
144 'url' => home_url( esc_url( $_SERVER['REQUEST_URI'] ) )
145 );
146
147 }
148 }
149
150 $meta = wp_parse_args( $d, $defaults );
151 $meta = array_map( 'trim', $meta );
152 $meta = apply_filters( 'sc_mod_metadata', $meta );
153
154 return $meta;
155
156 }
157
158 public static function meta_by_id( $id ){
159
160 $d = array();
161
162 if( $id ){
163 $d = array(
164 'title' => get_the_title( $id ),
165 'url' => get_permalink( $id ),
166 'short_url' => wp_get_shortlink( $id ),
167
168 'post_id' => $id,
169 'post_excerpt' => self::excerpt( 100 ),
170 'post_comments_count' => get_comments_number( $id ),
171 'post_image' => self::post_image( $id ),
172 'post_author' => get_the_author(),
173 'post_date' => get_the_date(),
174 'post_modified_date' => get_the_modified_date()
175 );
176
177 if( empty( $d[ 'short_url' ] ) ){
178 $d[ 'short_url' ] = $d[ 'url' ];
179 }
180
181 }
182
183 return $d;
184
185 }
186
187 public static function excerpt( $length = 250 ){
188
189 global $post;
190
191 if( !is_object( $post ) ){
192 return '';
193 }
194
195 $excerpt = $post->post_excerpt; // using $post->post_excerpt instead of get_the_excerpt as the_content filter loses shortcode formatting
196
197 $excerpt_text = ( empty( $excerpt ) ) ? strip_tags( strip_shortcodes( $post->post_content ) ) : $excerpt;
198 return substr( $excerpt_text, 0, $length );
199
200 }
201
202 public static function post_image( $post_id ){
203
204 $thumbnail = get_the_post_thumbnail_url( $post_id );
205
206 if( $thumbnail === false ){
207 return '';
208 }else{
209 return $thumbnail;
210 }
211
212 }
213
214 }
215
216 Shortcoder_Metadata::init();
217
218 ?>