Skip to content

Commit

Permalink
Merge branch 'hotfix-1.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
mjavadhpour committed Jun 15, 2020
2 parents b5b15bd + 6dcebf3 commit 80e32cf
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 20 deletions.
27 changes: 16 additions & 11 deletions includes/class-pzz-api-client-activator.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
<?php

/**
* Fired during plugin activation
*
* @link https://www.linkedin.com/in/mjavadhpour/
* @since 1.0.0
*
* @package Pzz_Api_Client
* @subpackage Pzz_Api_Client/includes
*/

/**
* Fired during plugin activation.
*
Expand All @@ -35,7 +25,22 @@ public static function activate() {
* Detect plugin. For use in Admin area only.
*/
if ( is_plugin_active( 'reactor-core/reactor-core.php' ) ) {
die("This plugin has a conflict with Reactor Core plugin. please remove or disable this plugin and try again!");
wp_die(
'<h1>Oops! 🤦‍♂️</h1>' .
'<p>' . sprintf(
__( 'Our plugin has a conflict with <a href="%s">Reactor: Core</a>. <b>please remove or deactivate it and try again.</b>' ),
'https://wordpress.org/plugins/reactor-core/'
) . '</p>'
. '<p>' .
__( 'This is because some of our functions and APIs have an internal conflict with this plugin, we sorry about that and this will be fixed later.' )
. '</p>'
. '<p>' .
sprintf(
__('<a href="%s">Back</a>'),
self_admin_url( "plugins.php" )
)
. '</p>'
);
}

}
Expand Down
8 changes: 8 additions & 0 deletions includes/lib/class-pzz-json-meta-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
* @since 1.1.1
*/
class PZZ_JSON_Meta_Posts extends PZZ_JSON_Meta {
/**
* Associated object type.
*
* @since 1.1.2
* @var string Type slug ("post" or "user")
*/
protected $type = 'post';

/**
* Check that the object can be accessed.
*
Expand Down
68 changes: 67 additions & 1 deletion includes/lib/class-pzz-json-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
* @since 1.1.1
*/
abstract class PZZ_JSON_Meta {
/**
* Construct the API handler object.
*
* @since 1.1.2
*/
public function __construct() {
if ( empty( $this->type ) ) {
_doing_it_wrong( 'PZZ_JSON_Meta::__construct', __( 'The object type must be overridden' ), 'WPAPI-1.2' );
return;
}
}

/**
* Check that the object is valid and can be accessed.
*
Expand All @@ -15,6 +27,16 @@ abstract class PZZ_JSON_Meta {
*/
abstract protected function check_object( $id );

/**
* Get the object (parent) ID column for the relevant table.
*
* @since 1.1.2
* @return string
*/
protected function get_parent_column() {
return ( 'user' === $this->type ) ? 'user_id' : 'post_id';
}

/**
* Retrieve custom fields for object.
*
Expand Down Expand Up @@ -46,7 +68,51 @@ public function get_all_meta( $id ) {
$meta[] = $value;
}

return apply_filters( 'json_prepare_meta', $meta, $id );
/**
* @since 1.1.2 'pzz_prepare_meta'
*/
return apply_filters( 'pzz_prepare_meta', $meta, $id );
}

/**
* Prepares meta data for return as an object.
*
* @since 1.1.2
* @param int $parent_id Object ID
* @param stdClass $data Metadata row from database
* @param boolean $is_raw Is the value field still serialized? (False indicates the value has been unserialized)
* @return array|WP_Error Meta object data on success, WP_Error otherwise
*/
protected function prepare_meta( $parent_id, $data, $is_raw = false ) {
$ID = $data->meta_id;
$key = $data->meta_key;
$value = $data->meta_value;

// Don't expose protected fields.
if ( is_protected_meta( $key ) ) {
return new WP_Error( 'pzz_meta_protected', sprintf( __( '%s is marked as a protected field.' ), $key ), array( 'status' => 403 ) );
}

// Normalize serialized strings
if ( $is_raw && is_serialized_string( $value ) ) {
$value = unserialize( $value );
}

// Don't expose serialized data
if ( is_serialized( $value ) || ! is_string( $value ) ) {
return new WP_Error( 'pzz_meta_protected', sprintf( __( '%s contains serialized data.' ), $key ), array( 'status' => 403 ) );
}

$meta = array(
'ID' => (int) $ID,
'key' => $key,
'value' => $value,
);

/**
* @since 1.1.2 'pzz_prepare_meta_value'
*/
return apply_filters( 'pzz_prepare_meta_value', $meta, $parent_id );
}

}
4 changes: 2 additions & 2 deletions includes/lib/class-pzz-json-users.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ protected function prepare_user( $user, $context = 'view' ) {

$user_fields['meta'] = array(
'links' => array(
'self' => PZZ_URL_Helper::convert_url_to_json_endpoint( '/users/' . $user->ID ),
'archives' => PZZ_URL_Helper::convert_url_to_json_endpoint( '/users/' . $user->ID . '/posts' ),
'self' => PZZ_URL_Helper::convert_url_to_json_endpoint( '/users/' . $user->ID, 'json', '/wp/v2/' ),
'archives' => '',
),
);

Expand Down
12 changes: 8 additions & 4 deletions includes/utils/class-pzz-url.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,35 @@ public static function get_avatar_url( $email ) {
/**
* Get URL to a JSON endpoint.
*
* @since 1.1.2 Add new optional argument $namespace
* @since 1.1.1
* @param string $path Optional. JSON route. Default empty.
* @param string $scheme Optional. Sanitization scheme. Default 'json'.
* @param string $namespace Optional. Default '/pzz/v1/'.
* @return string Full URL to the endpoint.
*/
public static function convert_url_to_json_endpoint( $path = '', $scheme = 'json' ) {
return self::get_json_url( null, $path, $scheme );
public static function convert_url_to_json_endpoint( $path = '', $scheme = 'json', $namespace = '/pzz/v1/' ) {
return self::get_json_url( null, $path, $scheme, $namespace );
}

/**
* Get URL to a JSON endpoint on a site.
*
* @since 1.1.2 Add new optional argument $namespace
* @since 1.1.1
* @todo Check if this is even necessary
* @param int $blog_id Blog ID.
* @param string $path Optional. JSON route. Default empty.
* @param string $scheme Optional. Sanitization scheme. Default 'json'.
* @param string $namespace Optional. Default '/pzz/v1/'.
* @return string Full URL to the endpoint.
*/
private static function get_json_url( $blog_id = null, $path = '', $scheme = 'json' ) {
private static function get_json_url( $blog_id = null, $path = '', $scheme = 'json', $namespace = '/pzz/v1/' ) {
if ( get_option( 'permalink_structure' ) ) {
$url = get_home_url( $blog_id, self::json_get_url_prefix(), $scheme );

if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
$url .= '/pzz/v1/' . ltrim( $path, '/' );
$url .= $namespace . ltrim( $path, '/' );
} else {
$url = trailingslashit( get_home_url( $blog_id, '', $scheme ) );

Expand Down
4 changes: 2 additions & 2 deletions pzz-api-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Plugin Name: PZZ WordPress Simple API
* Plugin URI: https://github.com/mjavadhpour/pzz-api-client
* Description: این افزونه ارائه دهنده <strong>رابط برنامه‌نویسی وب</strong> به صورت ساده شده برای استفاده در اپلیکیشن‌سازهای آنلاین است
* Version: 1.1.1
* Version: 1.1.2
* Author: MJavad Hpour
* Author URI: https://www.linkedin.com/in/mjavadhpour/
* License: GPL-2.0+
Expand All @@ -38,7 +38,7 @@
*
* @since 1.0.0
*/
define( 'PZZ_API_CLIENT_VERSION', '1.1.1' );
define( 'PZZ_API_CLIENT_VERSION', '1.1.2' );

/**
* The code that runs during plugin activation.
Expand Down

0 comments on commit 80e32cf

Please sign in to comment.