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