diff --git a/README.md b/README.md index af8f211..b7a9b95 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ **Tags:** api, rest api, custom api, api builder, wp json **Requires at least:** 5.0 **Tested up to:** 6.6.1 -**Stable tag:** 1.0.2 +**Stable tag:** 1.0.3 **Requires PHP:** 7.0 **License:** GPLv2 or later **License URI:** https://www.gnu.org/licenses/gpl-2.0.html diff --git a/custom-api-creator.php b/custom-api-creator.php index 67b9da0..79eb78d 100644 --- a/custom-api-creator.php +++ b/custom-api-creator.php @@ -3,12 +3,12 @@ * Plugin Name: Custom API Creator * Plugin URI: https://github.com/mehdiraized/wp-custom-api-creator * Description: Create custom APIs with flexible output and user roles. - * Version: 1.0.2 + * Version: 1.0.3 * Author: Mehdi Rezaei * Author URI: https://mehd.ir * License: GPLv2 or later * License URI: https://www.gnu.org/licenses/gpl-2.0.html - * Text Domain: custom-api-creator + * Text Domain: cac-plugin-creator * Domain Path: /languages */ @@ -16,37 +16,37 @@ exit; // Exit if accessed directly } -class Custom_API_Creator { +class CAC_Plugin_Class { public function __construct() { add_action( 'init', array( $this, 'register_custom_post_type' ) ); add_action( 'init', array( $this, 'load_textdomain' ) ); add_action( 'admin_menu', array( $this, 'add_admin_menu' ) ); - add_action( 'rest_api_init', array( $this, 'register_custom_apis' ) ); - add_action( 'add_meta_boxes', array( $this, 'add_custom_api_meta_boxes' ) ); - add_action( 'save_post', array( $this, 'save_custom_api_meta' ) ); + add_action( 'rest_api_init', array( $this, 'register_cac_plugins' ) ); + add_action( 'add_meta_boxes', array( $this, 'add_cac_plugin_meta_boxes' ) ); + add_action( 'save_post', array( $this, 'save_cac_plugin_meta' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); // custom column - add_filter( 'manage_custom_api_posts_columns', array( $this, 'add_custom_columns' ) ); - add_action( 'manage_custom_api_posts_custom_column', array( $this, 'custom_column_content' ), 10, 2 ); + add_filter( 'manage_cac_plugin_posts_columns', array( $this, 'add_custom_columns' ) ); + add_action( 'manage_cac_plugin_posts_custom_column', array( $this, 'custom_column_content' ), 10, 2 ); } public function register_custom_post_type() { $labels = array( - 'name' => _x( 'Custom APIs', 'post type general name', 'custom-api-creator' ), - 'singular_name' => _x( 'Custom API', 'post type singular name', 'custom-api-creator' ), - 'menu_name' => _x( 'Custom APIs', 'admin menu', 'custom-api-creator' ), - 'name_admin_bar' => _x( 'Custom API', 'add new on admin bar', 'custom-api-creator' ), - 'add_new' => _x( 'Add New', 'custom api', 'custom-api-creator' ), - 'add_new_item' => __( 'Add New API', 'custom-api-creator' ), - 'new_item' => __( 'New API', 'custom-api-creator' ), - 'edit_item' => __( 'Edit API', 'custom-api-creator' ), - 'view_item' => __( 'View API', 'custom-api-creator' ), - 'all_items' => __( 'All APIs', 'custom-api-creator' ), - 'search_items' => __( 'Search API', 'custom-api-creator' ), - 'parent_item_colon' => __( 'Parent APIs:', 'custom-api-creator' ), - 'not_found' => __( 'No apis found.', 'custom-api-creator' ), - 'not_found_in_trash' => __( 'No apis found in Trash.', 'custom-api-creator' ) + 'name' => _x( 'Custom APIs', 'post type general name', 'cac-plugin-creator' ), + 'singular_name' => _x( 'Custom API', 'post type singular name', 'cac-plugin-creator' ), + 'menu_name' => _x( 'Custom APIs', 'admin menu', 'cac-plugin-creator' ), + 'name_admin_bar' => _x( 'Custom API', 'add new on admin bar', 'cac-plugin-creator' ), + 'add_new' => _x( 'Add New', 'custom api', 'cac-plugin-creator' ), + 'add_new_item' => __( 'Add New API', 'cac-plugin-creator' ), + 'new_item' => __( 'New API', 'cac-plugin-creator' ), + 'edit_item' => __( 'Edit API', 'cac-plugin-creator' ), + 'view_item' => __( 'View API', 'cac-plugin-creator' ), + 'all_items' => __( 'All APIs', 'cac-plugin-creator' ), + 'search_items' => __( 'Search API', 'cac-plugin-creator' ), + 'parent_item_colon' => __( 'Parent APIs:', 'cac-plugin-creator' ), + 'not_found' => __( 'No apis found.', 'cac-plugin-creator' ), + 'not_found_in_trash' => __( 'No apis found in Trash.', 'cac-plugin-creator' ) ); $args = array( @@ -56,7 +56,7 @@ public function register_custom_post_type() { 'show_ui' => true, 'show_in_menu' => false, 'query_var' => true, - 'rewrite' => array( 'slug' => 'custom-api' ), + 'rewrite' => array( 'slug' => 'cac-plugin' ), 'capability_type' => 'post', 'has_archive' => false, 'hierarchical' => false, @@ -64,19 +64,19 @@ public function register_custom_post_type() { 'supports' => array( 'title' ) ); - register_post_type( 'custom_api', $args ); + register_post_type( 'cac_plugin', $args ); } public function load_textdomain() { - load_plugin_textdomain( 'custom-api-creator', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); + load_plugin_textdomain( 'cac-plugin-creator', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); } public function add_admin_menu() { add_menu_page( - __( 'Custom API', 'custom-api-creator' ), - __( 'Custom API', 'custom-api-creator' ), + __( 'Custom API', 'cac-plugin-creator' ), + __( 'Custom API', 'cac-plugin-creator' ), 'manage_options', - 'edit.php?post_type=custom_api', + 'edit.php?post_type=cac_plugin', null, 'dashicons-rest-api', 30 @@ -89,31 +89,31 @@ public function enqueue_admin_scripts( $hook ) { } global $post; - if ( 'custom_api' !== $post->post_type ) { + if ( 'cac_plugin' !== $post->post_type ) { return; } - wp_enqueue_script( 'custom-api-admin', plugin_dir_url( __FILE__ ) . 'assets/js/script.js', array( 'jquery' ), '1.0', true ); + wp_enqueue_script( 'cac-plugin-admin', plugin_dir_url( __FILE__ ) . 'assets/js/script.js', array( 'jquery' ), '1.0', true ); } - public function add_custom_api_meta_boxes() { + public function add_cac_plugin_meta_boxes() { add_meta_box( - 'custom_api_details', - __( 'API Details', 'custom-api-creator' ), + 'cac_plugin_details', + __( 'API Details', 'cac-plugin-creator' ), array( $this, 'render_api_details_meta_box' ), - 'custom_api', + 'cac_plugin', 'normal', 'high' ); } public function render_api_details_meta_box( $post ) { - wp_nonce_field( 'custom_api_meta_box', 'custom_api_meta_box_nonce' ); + wp_nonce_field( 'cac_plugin_meta_box', 'cac_plugin_meta_box_nonce' ); - $endpoint = get_post_meta( $post->ID, '_custom_api_endpoint', true ); - $sections = get_post_meta( $post->ID, '_custom_api_sections', true ); - $access_type = get_post_meta( $post->ID, '_custom_api_access_type', true ) ?: 'public'; - $roles = get_post_meta( $post->ID, '_custom_api_roles', true ) ?: array(); + $endpoint = get_post_meta( $post->ID, '_cac_plugin_endpoint', true ); + $sections = get_post_meta( $post->ID, '_cac_plugin_sections', true ); + $access_type = get_post_meta( $post->ID, '_cac_plugin_access_type', true ) ?: 'public'; + $roles = get_post_meta( $post->ID, '_cac_plugin_roles', true ) ?: array(); $post_types = get_post_types( array( 'public' => true ), 'objects' ); $all_roles = wp_roles()->get_names(); @@ -122,15 +122,15 @@ public function render_api_details_meta_box( $post ) {
+ for="cac_plugin_endpoint"> | - - + | |
---|---|---|
+ |
|
|
+ |