Explorar el Código

feat: setting up p2p relationships

tags/0.9.0
J hace 6 años
padre
commit
284b5651b5

+ 1
- 1
plugins/cia-endpoints/cia-end-points.php Ver fichero

@@ -8,7 +8,7 @@
8 8
  * @wordpress-plugin
9 9
  * Plugin Name:       Craft in America - API Endpoints
10 10
  * Plugin URI:
11
- * Description:       The test plugin that adds rest functionality
11
+ * Description:       Plugin that adds custom rest interface
12 12
  * Version:           1.0.0
13 13
  * Author:            TOJ <john@yvvas.com>
14 14
  */

plugins/cia-post-types.php → plugins/cia-post-types/cia-post-types.php Ver fichero

@@ -8,17 +8,16 @@
8 8
  * @wordpress-plugin
9 9
  * Plugin Name:       Craft in America - Content Types
10 10
  * Plugin URI:
11
- * Description:       The test plugin that adds rest functionality
11
+ * Description:       Adds custom custom types, and p2p relationships
12 12
  * Version:           1.0.0
13 13
  * Author:            TOJ <john@yvvas.com>
14 14
  */
15 15
 
16
-namespace Craft_Plugins;
17
-
18 16
 // If this file is called directly, abort.
19 17
 if ( ! defined( 'WPINC' ) ) { die; }
20 18
 
21
-require 'includes/custom-types.php';
19
+include('includes/custom-types.php');
20
+include('includes/p2p-mappings.php');
22 21
 
23 22
 /**
24 23
  * Class that holds all the necessary
@@ -66,3 +65,4 @@ foreach ($custom_types as $type):
66 65
     $icon = get_icon($type);
67 66
     add_action( 'init', [ new PostType($type, $icon), 'register_post_type' ] );
68 67
 endforeach;
68
+

plugins/includes/custom-types.php → plugins/cia-post-types/includes/custom-types.php Ver fichero

@@ -7,7 +7,7 @@
7 7
             // 'short',
8 8
             // 'talk',
9 9
             // 'object',
10
-            // 'guide',
10
+            'guide',
11 11
             // 'event',
12 12
             // 'exhibition',
13 13
             // 'technique',

+ 28
- 0
plugins/cia-post-types/includes/p2p-mappings.php Ver fichero

@@ -0,0 +1,28 @@
1
+<?php
2
+include('/custom-types.php');
3
+
4
+function register_to_from($to, $from) {
5
+    p2p_register_connection_type( array(
6
+        'name' => $from . 's_to_' . $to . 's',
7
+        'from' => $from,
8
+        'to' => $to,
9
+        'reciprocal' => true
10
+    ) );
11
+}
12
+
13
+function register_all_from_type($type_list, $from_type) {
14
+    foreach ($type_list as $type):
15
+        register_to_from($type, $from_type);
16
+    endforeach;
17
+}
18
+
19
+add_action( 'p2p_init', function () {
20
+    $all_types = get_all_custom_types();
21
+    
22
+    register_all_from_type($all_types, 'artist');
23
+    array_splice($all_types, array_search('artist', $all_types), 1);
24
+    
25
+    register_all_from_type($all_types, 'episode');
26
+    array_splice($all_types, array_search('episode', $all_types), 1);
27
+} );
28
+?>

+ 31
- 18
vue-theme/functions.php Ver fichero

@@ -88,35 +88,35 @@ add_action( 'wp_enqueue_scripts', 'vue_theme_scripts' );
88 88
  * disable endpoints in rest api
89 89
  **/
90 90
 add_filter( 'rest_endpoints', function ( $endpoints ) {
91
-	if ( isset( $endpoints['/wp/v2/users'] ) ) {
92
-		unset( $endpoints['/wp/v2/users'] );
93
-	}
94
-	if ( isset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] ) ) {
95
-		unset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] );
96
-	}
91
+    if ( isset( $endpoints['/wp/v2/users'] ) ) {
92
+        unset( $endpoints['/wp/v2/users'] );
93
+    }
94
+    if ( isset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] ) ) {
95
+        unset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] );
96
+    }
97 97
 
98 98
     if ( isset( $endpoints['/wp/v2/comments'] ) ) {
99
-		unset( $endpoints['/wp/v2/comments'] );
100
-	}
101
-	if ( isset( $endpoints['/wp/v2/comments/(?P<id>[\d]+)'] ) ) {
102
-		unset( $endpoints['/wp/v2/comments/(?P<id>[\d]+)'] );
99
+        unset( $endpoints['/wp/v2/comments'] );
103 100
     }
104
-    
101
+    if ( isset( $endpoints['/wp/v2/comments/(?P<id>[\d]+)'] ) ) {
102
+        unset( $endpoints['/wp/v2/comments/(?P<id>[\d]+)'] );
103
+    }
104
+
105 105
     if ( isset( $endpoints['/wp/v2/settings'] ) ) {
106
-		unset( $endpoints['/wp/v2/settings'] );
107
-	}
108
-	return $endpoints;
109
-} );
106
+        unset( $endpoints['/wp/v2/settings'] );
107
+    }
108
+    return $endpoints;
109
+    } );
110 110
 
111
-/**
112
- * remove wordpress version number from files
113
- **/
111
+// Remove wordpress version number from files
114 112
 remove_action( 'wp_head', 'wp_generator' );
115 113
 
116 114
 // Disable XML-RPC
117 115
 add_filter('xmlrpc_enabled', '__return_false');
116
+
118 117
 // Disable WLManifest
119 118
 remove_action( 'wp_head', 'wlwmanifest_link' ) ;
119
+
120 120
 // Disable self ping
121 121
 function disable_pingback( &$links ) {
122 122
     foreach ( $links as $l => $link )
@@ -124,11 +124,14 @@ function disable_pingback( &$links ) {
124 124
             unset($links[$l]);
125 125
 }
126 126
 add_action( 'pre_ping', 'disable_pingback' );
127
+
127 128
 // Disable RSD (used with self ping and XML-RPC)
128 129
 remove_action( 'wp_head', 'rsd_link' ) ;
130
+
129 131
 // Disable post embed
130 132
 function disable_embed() { wp_dequeue_script( 'wp-embed' ); }
131 133
 add_action( 'wp_footer', 'disable_embed' );
134
+
132 135
 // Disable Shortlinking
133 136
 remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
134 137
 
@@ -138,6 +141,7 @@ function remove_cssjs_ver( $src ) {
138 141
         $src = remove_query_arg( 'ver', $src );
139 142
     return $src;
140 143
 }
144
+// !:Possible Bug HERE
141 145
 add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
142 146
 add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );
143 147
 
@@ -162,3 +166,12 @@ add_action( 'wp_enqueue_scripts', 'webapptiv_remove_block_library_css' );
162 166
 
163 167
 // header( 'Access-Control-Allow-Origin: http://localhost:8080' );
164 168
 header( 'Content-Type: application/json' );
169
+
170
+// function artists_types() {
171
+//     p2p_register_connection_type( array(
172
+//         'name' => 'artists_to_episodes',
173
+//         'from' => 'artist',
174
+//         'to' => 'episode'
175
+//     ) );
176
+// }
177
+// add_action( 'p2p_init', 'artists_types' );

Loading…
Cancelar
Guardar