PluginProbe
My WP Customize Admin/Frontend / 1.14
My WP Customize Admin/Frontend v1.14
1.27.4 1.27.3 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.10 1.10.1 1.10.2 1.11 1.12 1.12.1 1.12.2 1.13 1.13.1 1.13.2 1.14 1.15.0 1.16 1.17.0 All 76 releases
my-wp / shortcode / modules / mywp.shortcode.module.post.php

mywp.shortcode.module.post.php in My WP Customize Admin/Frontend 1.14, at shortcode/modules/mywp.shortcode.module.post.php

104 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 if( ! class_exists( 'MywpShortcodeAbstractModule' ) ) {
8 return false;
9 }
10
11 if ( ! class_exists( 'MywpShortcodeModulePost' ) ) :
12
13 final class MywpShortcodeModulePost extends MywpShortcodeAbstractModule {
14
15 protected static $id = 'mywp_post';
16
17 public static function do_shortcode( $atts , $content = false , $tag ) {
18
19 global $post;
20
21 if( empty( $atts['field'] ) ) {
22
23 MywpHelper::error_not_found_message( '$atts["field"]' , sprintf( '[%s] shortcode' , self::$id ) );
24
25 return $content;
26
27 }
28
29 $field = strip_tags( $atts['field'] );
30
31 $post_id = false;
32
33 if( ! empty( $atts['current'] ) ) {
34
35 if( ! empty( $post->ID ) ) {
36
37 $post_id = intval( $post->ID );
38
39 }
40
41 } else {
42
43 if( ! empty( $atts['post_id'] ) ) {
44
45 $post_id = intval( $atts['post_id'] );
46
47 }
48
49 }
50
51 if( empty( $post_id ) ) {
52
53 return $content;
54
55 }
56
57 $get_post = get_post( $post_id );
58
59 if( empty( $get_post ) ) {
60
61 return $content;
62
63 }
64
65 if( $field === 'id' or $field === 'ID' ) {
66
67 $content = $post_id;
68
69 } elseif( $field === 'title' ) {
70
71 $content = get_the_title( $post_id );
72
73 } elseif( $field === 'post_type' ) {
74
75 $content = $get_post->post_type;
76
77 } elseif( $field === 'post_status' ) {
78
79 $content = $get_post->post_status;
80
81 } elseif( $field === 'edit_link' ) {
82
83 $content = get_edit_post_link( $post_id );
84
85 } else {
86
87 MywpHelper::error_not_found_message( '$atts["field"]' , sprintf( '[%s] shortcode' , self::$id ) );
88
89 return $content;
90
91 }
92
93 $content = apply_filters( 'mywp_shortcode_post' , $content , $atts );
94
95 return $content;
96
97 }
98
99 }
100
101 MywpShortcodeModulePost::init();
102
103 endif;
104