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