Pārlūkot izejas kodu

feat: setting up p2p relationships

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

+ 1
- 1
plugins/cia-endpoints/cia-end-points.php Parādīt failu

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

plugins/cia-post-types.php → plugins/cia-post-types/cia-post-types.php Parādīt failu

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

plugins/includes/custom-types.php → plugins/cia-post-types/includes/custom-types.php Parādīt failu

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

+ 28
- 0
plugins/cia-post-types/includes/p2p-mappings.php Parādīt failu

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 Parādīt failu

88
  * disable endpoints in rest api
88
  * disable endpoints in rest api
89
  **/
89
  **/
90
 add_filter( 'rest_endpoints', function ( $endpoints ) {
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
     if ( isset( $endpoints['/wp/v2/comments'] ) ) {
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
     if ( isset( $endpoints['/wp/v2/settings'] ) ) {
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
 remove_action( 'wp_head', 'wp_generator' );
112
 remove_action( 'wp_head', 'wp_generator' );
115
 
113
 
116
 // Disable XML-RPC
114
 // Disable XML-RPC
117
 add_filter('xmlrpc_enabled', '__return_false');
115
 add_filter('xmlrpc_enabled', '__return_false');
116
+
118
 // Disable WLManifest
117
 // Disable WLManifest
119
 remove_action( 'wp_head', 'wlwmanifest_link' ) ;
118
 remove_action( 'wp_head', 'wlwmanifest_link' ) ;
119
+
120
 // Disable self ping
120
 // Disable self ping
121
 function disable_pingback( &$links ) {
121
 function disable_pingback( &$links ) {
122
     foreach ( $links as $l => $link )
122
     foreach ( $links as $l => $link )
124
             unset($links[$l]);
124
             unset($links[$l]);
125
 }
125
 }
126
 add_action( 'pre_ping', 'disable_pingback' );
126
 add_action( 'pre_ping', 'disable_pingback' );
127
+
127
 // Disable RSD (used with self ping and XML-RPC)
128
 // Disable RSD (used with self ping and XML-RPC)
128
 remove_action( 'wp_head', 'rsd_link' ) ;
129
 remove_action( 'wp_head', 'rsd_link' ) ;
130
+
129
 // Disable post embed
131
 // Disable post embed
130
 function disable_embed() { wp_dequeue_script( 'wp-embed' ); }
132
 function disable_embed() { wp_dequeue_script( 'wp-embed' ); }
131
 add_action( 'wp_footer', 'disable_embed' );
133
 add_action( 'wp_footer', 'disable_embed' );
134
+
132
 // Disable Shortlinking
135
 // Disable Shortlinking
133
 remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
136
 remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
134
 
137
 
138
         $src = remove_query_arg( 'ver', $src );
141
         $src = remove_query_arg( 'ver', $src );
139
     return $src;
142
     return $src;
140
 }
143
 }
144
+// !:Possible Bug HERE
141
 add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
145
 add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
142
 add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );
146
 add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );
143
 
147
 
162
 
166
 
163
 // header( 'Access-Control-Allow-Origin: http://localhost:8080' );
167
 // header( 'Access-Control-Allow-Origin: http://localhost:8080' );
164
 header( 'Content-Type: application/json' );
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' );

Notiek ielāde…
Atcelt
Saglabāt