Pārlūkot izejas kodu

limiting revisions | working custom type plugin

tags/0.9.0
J 6 gadus atpakaļ
vecāks
revīzija
ae5e3b64fa

+ 3
- 0
configs/wp-config.php Parādīt failu

@@ -98,3 +98,6 @@ if(defined('IS_DEV') && IS_DEV ) {
98 98
 } else {
99 99
         $_SERVER['HTTPS'] = 'on';
100 100
 }
101
+
102
+/** Limit reivisions */
103
+define('WP_POST_REVISIONS', 2);

+ 68
- 0
plugins/cia-post-types.php Parādīt failu

@@ -0,0 +1,68 @@
1
+<?php
2
+/**
3
+ * Craft in America Custom Types Plugin
4
+ *
5
+ * @since             1.0.0
6
+ * @package           cia_post_types
7
+ *
8
+ * @wordpress-plugin
9
+ * Plugin Name:       Craft in America - Content Types
10
+ * Plugin URI:
11
+ * Description:       The test plugin that adds rest functionality
12
+ * Version:           1.0.0
13
+ * Author:            TOJ <john@yvvas.com>
14
+ */
15
+
16
+namespace Craft_Plugins;
17
+
18
+// If this file is called directly, abort.
19
+if ( ! defined( 'WPINC' ) ) { die; }
20
+
21
+require 'includes/custom-types.php';
22
+
23
+/**
24
+ * Class that holds all the necessary
25
+ * functionality to build custom post types
26
+ */
27
+class PostType {
28
+    /**
29
+     * The custom post type slug
30
+     * @var string
31
+     */
32
+    private $post_type;
33
+    /**
34
+     * The custom post type icon
35
+     * @var string
36
+     */
37
+    private $icon;
38
+
39
+    function __construct($post_type, $icon) {
40
+        $this->post_type = $post_type;
41
+        $this->icon = $icon;
42
+    }
43
+
44
+    /** Register custom post type call-back */
45
+    public function register_post_type() {
46
+        $args = array(
47
+            'label'              => esc_html( $this->post_type, 'test-plugin' ),
48
+            'public'             => true,
49
+            'menu_position'      => 47,
50
+            'menu_icon'          => $this->icon,
51
+            'supports'           => array( 'title', 'editor', 'revisions', 'thumbnail' ),
52
+            'has_archive'        => false,
53
+            'show_in_rest'       => true,
54
+            'publicly_queryable' => false,
55
+        );
56
+        register_post_type( $this->post_type, $args );
57
+    }
58
+}
59
+
60
+/**
61
+ * Plugin Logic
62
+ * Where the magic actually happens
63
+ */
64
+$custom_types = get_all_custom_types();
65
+foreach ($custom_types as $type):
66
+    $icon = get_icon($type);
67
+    add_action( 'init', [ new PostType($type, $icon), 'register_post_type' ] );
68
+endforeach;

+ 71
- 0
plugins/includes/custom-types.php Parādīt failu

@@ -0,0 +1,71 @@
1
+<?php
2
+    function get_all_custom_types() {
3
+        return array(
4
+            'custom type',
5
+            // 'artist',
6
+            // 'episode',
7
+            // 'short',
8
+            // 'talk',
9
+            // 'object',
10
+            // 'guide',
11
+            // 'event',
12
+            // 'exhibition',
13
+            // 'technique',
14
+            // 'profile',
15
+            // 'publication',
16
+            // 'release',
17
+            // 'article',
18
+            // 'product'
19
+        );
20
+    }
21
+
22
+    function get_icon($type) {
23
+        switch ($type):
24
+            case 'artist':
25
+                return 'dashicons-groups';
26
+                break;
27
+            case 'episode':
28
+                return 'dashicons-editor-video';
29
+                break;
30
+            case 'short':
31
+                return 'dashicons-video-alt3';
32
+                break;
33
+            case 'talk':
34
+                return 'dashicons-format-chat';
35
+                break;
36
+            case 'object';
37
+                return 'dashicons-visibility';
38
+                break;
39
+            case 'guide';
40
+                return 'dashicons-edit';
41
+                break;
42
+            case 'event';
43
+                return 'dashicons-calendar';
44
+                break;
45
+            case 'exhibition';
46
+                return 'dashicons-location';
47
+                break;
48
+            case 'technique';
49
+                return 'dashicons-art';
50
+                break;
51
+            case 'place';
52
+                return 'dashicons-admin-site';
53
+                break;
54
+            case 'release';
55
+                return 'dashicons-media-text';
56
+                break;
57
+            case 'profile';
58
+                return 'dashicons-businessman';
59
+                break;
60
+            case 'publication';
61
+                return 'dashicons-book';
62
+                break;
63
+            case 'article';
64
+                return 'dashicons-networking';
65
+                break;
66
+            default:
67
+                return 'dashicons-admin-post';
68
+        endswitch;
69
+    }
70
+
71
+?>

+ 35
- 1
vue-theme/functions.php Parādīt failu

@@ -5,6 +5,12 @@
5 5
  * 1. Scripts needed to run the vue theme
6 6
  */
7 7
 
8
+ // Load WP stuff as needed
9
+ // https://www.smashingmagazine.com/2018/10/headless-wordpress-decoupled/#improving-performance-decoupled-json-approach
10
+define( 'SHORTINIT', true );
11
+$parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
12
+// require_once filter_var( $parse_uri[0] . 'wp-load.php', FILTER_SANITIZE_STRING );
13
+
8 14
 $path = $_SERVER['DOCUMENT_ROOT'];
9 15
 
10 16
 require_once $path . '/wp-load.php';
@@ -105,4 +111,32 @@ add_filter( 'rest_endpoints', function ( $endpoints ) {
105 111
 /**
106 112
  * remove wordpress version number from files
107 113
  **/
108
-remove_action( 'wp_head', 'wp_generator' );
114
+remove_action( 'wp_head', 'wp_generator' );
115
+
116
+// Disable XML-RPC
117
+add_filter('xmlrpc_enabled', '__return_false');
118
+// Disable WLManifest
119
+remove_action( 'wp_head', 'wlwmanifest_link' ) ;
120
+// Disable self ping
121
+function disable_pingback( &$links ) {
122
+    foreach ( $links as $l => $link )
123
+        if ( 0 === strpos( $link, get_option( 'home' ) ) )
124
+            unset($links[$l]);
125
+}
126
+add_action( 'pre_ping', 'disable_pingback' );
127
+// Disable RSD (used with self ping and XML-RPC)
128
+remove_action( 'wp_head', 'rsd_link' ) ;
129
+// Disable post embed
130
+function disable_embed() { wp_dequeue_script( 'wp-embed' ); }
131
+add_action( 'wp_footer', 'disable_embed' );
132
+// Disable Shortlinking
133
+remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
134
+
135
+// Remove versions from static assets (prevents cache-ing)
136
+function remove_cssjs_ver( $src ) {
137
+    if( strpos( $src, '?ver=' ) )
138
+        $src = remove_query_arg( 'ver', $src );
139
+    return $src;
140
+}
141
+add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
142
+add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );

Notiek ielāde…
Atcelt
Saglabāt