1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
<?php
function papi_get_meta_id( $type = null, $id = null ) {
$type = papi_get_meta_type( $type );
if ( function_exists( sprintf( 'papi_get_%s_id', $type ) ) ) {
return call_user_func_array( sprintf( 'papi_get_%s_id', $type ), [$id] );
}
return intval( $id );
}
function papi_get_meta_id_column( $type = 'post' ) {
if ( $type = papi_get_meta_type( $type ) ) {
return sprintf( '%s_id', $type );
}
}
function papi_get_meta_store( $post_id = 0, $type = 'post' ) {
return Papi_Core_Meta_Store::factory( $post_id, $type );
}
function papi_get_meta_type( $type = null ) {
if ( $meta_type = papi_get_qs( 'meta_type' ) ) {
return $meta_type;
}
switch ( $type ) {
case 'option':
return 'option';
case 'post':
case 'page':
return 'post';
case 'taxonomy':
case 'term':
return 'term';
default:
break;
}
$request_uri = $_SERVER['REQUEST_URI'];
$parsed_url = parse_url( $request_uri );
if ( ! empty( $parsed_url['query'] ) ) {
if ( is_admin() && preg_match( '/taxonomy=/', $parsed_url['query'] ) ) {
return 'term';
}
if ( is_admin() && preg_match( '/page\=papi(\%2F|\/)option/', $parsed_url['query'] ) ) {
return 'option';
}
}
if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) {
if ( isset( $_POST['taxonomy'] ) ) {
return 'term';
}
if ( isset( $_POST['post_type'] ) ) {
return 'post';
}
}
if ( ! is_admin() && ( is_category() || is_tag() ) ) {
return 'term';
}
if ( $obj = get_queried_object() ) {
if ( $obj instanceof WP_Term || isset( $obj->term_id ) ) {
return 'term';
}
if ( $obj instanceof WP_Post || isset( $obj->post_id ) ) {
return 'post';
}
}
if ( is_null( $type ) ) {
$type = 'post';
}
if ( function_exists( "get_{$type}_meta" ) ) {
return $type;
}
}