Initial commit

This commit is contained in:
Zhongwei Li
2025-11-29 18:25:36 +08:00
commit cfadf66888
24 changed files with 4160 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
<?php
/**
* Register ability category: {{LABEL}}
*
* {{DESCRIPTION}}
*/
/**
* Hook: abilities_api_categories_init
* Categories must be registered BEFORE abilities that use them.
* This hook fires before 'abilities_api_init'.
*/
add_action( 'abilities_api_categories_init', '{{REGISTER_FUNCTION}}' );
function {{REGISTER_FUNCTION}}() {
wp_register_ability_category( '{{CATEGORY_NAME}}', array(
'label' => __( '{{LABEL}}', '{{NAMESPACE}}' ),
'description' => __( '{{DESCRIPTION}}', '{{NAMESPACE}}' ),
) );
}

View File

@@ -0,0 +1,73 @@
/**
* Client-Side Ability: {{LABEL}}
*
* {{DESCRIPTION}}
*/
import { registerAbility } from '@wordpress/abilities';
/**
* Register the {{ABILITY_NAME}} ability.
*/
registerAbility( {
name: '{{ABILITY_NAME}}',
label: '{{LABEL}}',
description: '{{DESCRIPTION}}',
category: '{{CATEGORY}}',
// Define expected input structure using JSON Schema
inputSchema: {
type: 'object',
properties: {
// TODO: Define input parameters
// param1: {
// type: 'string',
// description: 'Description of parameter',
// },
},
required: [], // TODO: List required parameters
additionalProperties: false,
},
// Define output structure using JSON Schema
outputSchema: {
type: 'object',
properties: {
result: {
type: 'string',
description: 'The result of the operation',
},
},
},
// The async callback function to execute
callback: async ( input ) => {
// TODO: Implement your ability logic here
// Example error handling:
// if ( ! someValidation( input ) ) {
// throw new Error( 'The provided input is invalid.' );
// }
return {
result: 'TODO: Implement logic',
};
},
// Permission check callback
permissionCallback: ( input ) => {
// TODO: Implement appropriate permission checks
// Examples:
// return window.wp?.data?.select('core')?.getCurrentUser() !== null;
return true; // Everyone can access (use with caution!)
},
// Metadata
meta: {
annotations: {
readonly: {{READONLY}},
destructive: {{DESTRUCTIVE}},
idempotent: {{IDEMPOTENT}},
},
},
} );

View File

@@ -0,0 +1,15 @@
/**
* Register ability category: {{LABEL}}
*
* {{DESCRIPTION}}
*
* Note: This must be called BEFORE registering abilities that use this category.
* Typically placed at the top of your abilities registration file.
*/
import { registerAbilityCategory } from '@wordpress/abilities';
await registerAbilityCategory('{{CATEGORY_NAME}}', {
label: '{{LABEL}}',
description: '{{DESCRIPTION}}',
});

View File

@@ -0,0 +1,88 @@
<?php
/**
* Ability: {{LABEL}}
*
* {{DESCRIPTION}}
*/
/**
* Execute callback for {{ABILITY_NAME}} ability.
*
* @param array|mixed $input Input data matching the input_schema.
* @return mixed Output data matching the output_schema, or WP_Error on failure.
*/
function {{CALLBACK_FUNCTION}}( $input ) {
// TODO: Implement your ability logic here
// Example error handling:
// if ( ! some_validation( $input ) ) {
// return new WP_Error(
// 'invalid_input',
// __( 'The provided input is invalid.', '{{NAMESPACE}}' )
// );
// }
return array(
'result' => 'TODO: Implement logic',
);
}
/**
* Register the {{ABILITY_NAME}} ability.
*/
add_action( 'abilities_api_init', '{{REGISTER_FUNCTION}}' );
function {{REGISTER_FUNCTION}}() {
wp_register_ability( '{{ABILITY_NAME}}', array(
'label' => __( '{{LABEL}}', '{{NAMESPACE}}' ),
'description' => __( '{{DESCRIPTION}}', '{{NAMESPACE}}' ),
'category' => '{{CATEGORY}}',
// Define expected input structure using JSON Schema
'input_schema' => array(
'type' => 'object',
'properties' => array(
// TODO: Define input parameters
// 'param1' => array(
// 'type' => 'string',
// 'description' => __( 'Description of parameter', '{{NAMESPACE}}' ),
// ),
),
'required' => array(), // TODO: List required parameters
'additionalProperties' => false,
),
// Define output structure using JSON Schema
'output_schema' => array(
'type' => 'object',
'properties' => array(
'result' => array(
'type' => 'string',
'description' => __( 'The result of the operation', '{{NAMESPACE}}' ),
),
),
),
// The callback function to execute
'execute_callback' => '{{CALLBACK_FUNCTION}}',
// Permission check callback
'permission_callback' => function( $input ) {
// TODO: Implement appropriate permission checks
// Examples:
// return current_user_can( 'manage_options' );
// return is_user_logged_in();
return __return_true(); // Everyone can access (use with caution!)
},
// Metadata
'meta' => array(
'show_in_rest' => true,
'annotations' => array(
'readonly' => {{READONLY}},
'destructive' => {{DESTRUCTIVE}},
'idempotent' => {{IDEMPOTENT}},
),
),
) );
}