diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml
index 5207628..9ae088a 100644
--- a/.github/workflows/build-release.yml
+++ b/.github/workflows/build-release.yml
@@ -89,6 +89,6 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
- name: dubinc-plugin
- path: dubinc.zip
+ name: dubinc
+ path: /tmp/dubinc
retention-days: 30
diff --git a/assets/js/admin/dubco-meta-box.js b/assets/js/admin/dubco-meta-box.js
index f7185a4..d33fa00 100644
--- a/assets/js/admin/dubco-meta-box.js
+++ b/assets/js/admin/dubco-meta-box.js
@@ -61,7 +61,7 @@ window.jQuery(document).ready(function ($) {
}
} catch (error) {
console.error(error);
- $('#dubco_error').addClass('error').text(error).show();
+ $('#dubco_error').addClass('error').text(error?.message || error).show();
} finally {
$(this).text(wp.i18n.__('Update', 'dubinc'));
}
diff --git a/assets/js/editor/components/dubco-side-panel.js b/assets/js/editor/components/dubco-side-panel.js
index 4043578..75a21f7 100644
--- a/assets/js/editor/components/dubco-side-panel.js
+++ b/assets/js/editor/components/dubco-side-panel.js
@@ -30,8 +30,7 @@ const MetaBox = ({ postStatus, metaFields, setMetaFields, postId }) => {
const [error, setError] = useState('');
const [isLoading, setIsLoading] = useState(false);
- const { _dubco_short_url, _dubco_short_url_id, _dubco_short_url_error } =
- metaFields;
+ const { _dubco_short_url, _dubco_short_url_id, _dubco_short_url_error } = metaFields;
useEffect(() => {
if (_dubco_short_url) {
@@ -120,9 +119,7 @@ const MetaBox = ({ postStatus, metaFields, setMetaFields, postId }) => {
)}
{error && {error}}
-
+
>
)}
{!_dubco_short_url && (
diff --git a/dist/js/editor.asset.php b/dist/js/editor.asset.php
index 4ce6b8a..50ca13c 100644
--- a/dist/js/editor.asset.php
+++ b/dist/js/editor.asset.php
@@ -1 +1 @@
- array('react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '5605b62c6a63015b5f7b');
+ array('react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '25e82788ac7ce4ccbfb3');
diff --git a/dist/js/editor.js b/dist/js/editor.js
index c369089..8fd7344 100644
--- a/dist/js/editor.js
+++ b/dist/js/editor.js
@@ -1 +1 @@
-!function(){"use strict";var e={n:function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,{a:n}),n},d:function(t,n){for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}},t=window.wp.plugins,n=window.wp.element,r=window.wp.i18n,i=window.wp.compose,a=window.wp.data,o=window.wp.editor,l=window.wp.components,c=window.wp.apiFetch,s=e.n(c);var u,d=({shortLink:e})=>{let t,i;try{const n=new URL(e);t=n.hostname,i=n.pathname.split("/")[1]}catch(e){return console.error("Invalid URL:",e),null}return(0,n.createElement)("div",{className:"dubco-analytics-link"},(0,n.createElement)("p",null,(0,n.createElement)("a",{href:`https://app.dub.co/analytics?domain=${t}&key=${i}&tab=clicks`,target:"_blank",rel:"noopener noreferrer"},(0,r.__)("Analytics for link","dubinc"))))},p=window.React;function _(){return _=Object.assign?Object.assign.bind():function(e){for(var t=1;t({metaFields:e("core/editor").getEditedPostAttribute("meta"),postStatus:e("core/editor").getEditedPostAttribute("status"),postId:e("core/editor").getCurrentPostId()}))),b=(0,a.withDispatch)((e=>({setMetaFields(t){e("core/editor").editPost({meta:t})}})));var w=(0,i.compose)([m,b])((({postStatus:e,metaFields:t,setMetaFields:i,postId:a})=>{const[c,u]=(0,n.useState)(!1),[p,_]=(0,n.useState)(""),[m,b]=(0,n.useState)(""),[w,f]=(0,n.useState)(!1),{_dubco_short_url:v,_dubco_short_url_id:E,_dubco_short_url_error:g}=t;return(0,n.useEffect)((()=>{if(v){const e=new URL(v);_(e.pathname.substring(1))}}),[v]),"publish"!==e?(0,n.createElement)(o.PluginDocumentSettingPanel,{title:(0,r.__)("Dub","dubinc"),initialOpen:!1,icon:(0,n.createElement)(h,null)},(0,n.createElement)(l.Notice,{status:"warning",isDismissible:!1},(0,r.__)("You can only create short links for published posts. A short link will be created automatically, if it doesn't exists when this post is published","dubinc"))):(0,n.createElement)(o.PluginDocumentSettingPanel,{title:(0,r.__)("Dubco","dubinc"),initialOpen:!1},(0,n.createElement)(l.PanelRow,null,(0,n.createElement)("div",null,v&&(0,n.createElement)(n.Fragment,null,(0,n.createElement)("div",{className:"dubco-short-link"},c?(0,n.createElement)(l.TextControl,{value:p,label:(0,r.__)("Edit the pathname","dubinc"),onChange:e=>_(e)}):(0,n.createElement)(l.TextControl,{value:v,label:(0,r.__)("Url","dubinc"),onChange:e=>i({_dubco_short_url:e}),readOnly:!0}),c?(0,n.createElement)(l.Button,{variant:"primary",onClick:async()=>{try{b(""),f(!0);const e=await(async(e,t,n)=>s()({path:`/dubco/v1/links/${t}`,method:"PATCH",data:{post_id:e,key:n}}))(a,E,p);e&&i({_dubco_short_url:e.shortLink})}catch(e){b(e)}finally{f(!1)}u(!c)}},w?(0,r.__)("Updating","dubinc"):(0,r.__)("Update","dubinc")):(0,n.createElement)(l.Button,{variant:"primary",onClick:()=>u(!c)},(0,r.__)("Edit","dubinc"))),m&&(0,n.createElement)(l.Notice,{status:"error"},m),(0,n.createElement)(d,{shortLink:v})),!v&&(0,n.createElement)("div",{className:"dubco-creat-link"},(0,n.createElement)(l.Button,{variant:"primary",disabled:w,description:(0,r.__)("Create a short link for this post","dubinc"),onClick:async()=>{try{b(""),f(!0);const e=await(async e=>s()({path:"/dubco/v1/links",method:"POST",data:{post_id:e}}))(a);e&&i({_dubco_short_url:e.shortLink})}catch(e){b(e)}finally{f(!1)}}},w?(0,r.__)("Creating Short Link...","dubinc"):(0,r.__)("Create Short Link","dubinc")),g&&(0,n.createElement)(l.Notice,{status:"error",onRemove:()=>{i({_dubco_short_url_error:""})}},g),m&&(0,n.createElement)(l.Notice,{status:"error"},m)))))}));(0,t.registerPlugin)("dubco-side-panel",{render:w})}();
\ No newline at end of file
+!function(){"use strict";var e={n:function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,{a:n}),n},d:function(t,n){for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}},t=window.wp.plugins,n=window.wp.element,r=window.wp.i18n,i=window.wp.compose,a=window.wp.data,o=window.wp.editor,l=window.wp.components,c=window.wp.apiFetch,s=e.n(c);var u,d=({shortLink:e})=>{let t,i;try{const n=new URL(e);t=n.hostname,i=n.pathname.split("/")[1]}catch(e){return console.error("Invalid URL:",e),null}return(0,n.createElement)("div",{className:"dubco-analytics-link"},(0,n.createElement)("p",null,(0,n.createElement)("a",{href:`https://app.dub.co/analytics?domain=${t}&key=${i}&tab=clicks`,target:"_blank",rel:"noopener noreferrer"},(0,r.__)("Analytics for link","dubinc"))))},p=window.React;function _(){return _=Object.assign?Object.assign.bind():function(e){for(var t=1;t({metaFields:e("core/editor").getEditedPostAttribute("meta"),postStatus:e("core/editor").getEditedPostAttribute("status"),postId:e("core/editor").getCurrentPostId()})),b=(0,a.withDispatch)(e=>({setMetaFields(t){e("core/editor").editPost({meta:t})}}));var w=(0,i.compose)([m,b])(({postStatus:e,metaFields:t,setMetaFields:i,postId:a})=>{const[c,u]=(0,n.useState)(!1),[p,_]=(0,n.useState)(""),[m,b]=(0,n.useState)(""),[w,f]=(0,n.useState)(!1),{_dubco_short_url:v,_dubco_short_url_id:E,_dubco_short_url_error:g}=t;return(0,n.useEffect)(()=>{if(v){const e=new URL(v);_(e.pathname.substring(1))}},[v]),"publish"!==e?(0,n.createElement)(o.PluginDocumentSettingPanel,{title:(0,r.__)("Dub","dubinc"),initialOpen:!1,icon:(0,n.createElement)(h,null)},(0,n.createElement)(l.Notice,{status:"warning",isDismissible:!1},(0,r.__)("You can only create short links for published posts. A short link will be created automatically, if it doesn't exists when this post is published","dubinc"))):(0,n.createElement)(o.PluginDocumentSettingPanel,{title:(0,r.__)("Dub","dubinc"),initialOpen:!1},(0,n.createElement)(l.PanelRow,null,(0,n.createElement)("div",null,v&&(0,n.createElement)(n.Fragment,null,(0,n.createElement)("div",{className:"dubco-short-link"},c?(0,n.createElement)(l.TextControl,{value:p,label:(0,r.__)("Edit the pathname","dubinc"),onChange:e=>_(e)}):(0,n.createElement)(l.TextControl,{value:v,label:(0,r.__)("Url","dubinc"),onChange:e=>i({_dubco_short_url:e}),readOnly:!0}),c?(0,n.createElement)(l.Button,{variant:"primary",onClick:async()=>{try{b(""),f(!0);const e=await(async(e,t,n)=>s()({path:`/dubco/v1/links/${t}`,method:"PATCH",data:{post_id:e,key:n}}))(a,E,p);e&&i({_dubco_short_url:e.shortLink})}catch(e){b(e)}finally{f(!1)}u(!c)}},w?(0,r.__)("Updating","dubinc"):(0,r.__)("Update","dubinc")):(0,n.createElement)(l.Button,{variant:"primary",onClick:()=>u(!c)},(0,r.__)("Edit","dubinc"))),m&&(0,n.createElement)(l.Notice,{status:"error"},m),(0,n.createElement)(d,{shortLink:v})),!v&&(0,n.createElement)("div",{className:"dubco-creat-link"},(0,n.createElement)(l.Button,{variant:"primary",disabled:w,description:(0,r.__)("Create a short link for this post","dubinc"),onClick:async()=>{try{b(""),f(!0);const e=await(async e=>s()({path:"/dubco/v1/links",method:"POST",data:{post_id:e}}))(a);e&&i({_dubco_short_url:e.shortLink})}catch(e){b(e)}finally{f(!1)}}},w?(0,r.__)("Creating Short Link...","dubinc"):(0,r.__)("Create Short Link","dubinc")),g&&(0,n.createElement)(l.Notice,{status:"error",onRemove:()=>{i({_dubco_short_url_error:""})}},g),m&&(0,n.createElement)(l.Notice,{status:"error"},m)))))});(0,t.registerPlugin)("dubco-side-panel",{render:w})}();
\ No newline at end of file
diff --git a/includes/classes/Rest/Links.php b/includes/classes/Rest/Links.php
index 759abf8..a457997 100644
--- a/includes/classes/Rest/Links.php
+++ b/includes/classes/Rest/Links.php
@@ -27,7 +27,7 @@ public function register_routes() {
register_rest_route(
'dubco/v1',
- '/links/(?P[a-zA-Z0-9]+)',
+ '/links/(?P[a-zA-Z0-9_]+)',
[
'methods' => WP_REST_Server::EDITABLE,
'callback' => [ $this, 'update_link' ],
@@ -61,7 +61,6 @@ public function create_link( $request ) {
}
public function update_link( $request ) {
- // Handle PATCH request to update an existing link
$id = $request->get_param( 'id' );
$params = $request->get_params();
@@ -86,7 +85,6 @@ public function update_link( $request ) {
}
public function permissions_check( $request ) {
- // Check if the user has permission to perform the action
return current_user_can( 'edit_posts' );
}
}
diff --git a/package.json b/package.json
index aae0168..339d36a 100644
--- a/package.json
+++ b/package.json
@@ -1,33 +1,33 @@
{
- "name": "dubinc",
- "version": "1.0.0",
- "scripts": {
- "start": "npm run watch",
- "watch": "10up-toolkit watch --port=5010 --hot",
- "build": "10up-toolkit build",
- "format-js": "10up-toolkit format-js",
- "lint-js": "10up-toolkit lint-js",
- "lint-style": "10up-toolkit lint-style",
- "lint-php": "./vendor/bin/phpcs ./includes --standard=ruleset.xml",
- "fix-php": "./vendor/bin/phpcbf ./includes --standard=ruleset.xml",
- "test": "10up-toolkit test-unit-jest",
- "clean-dist": "rm -rf ./dist"
- },
- "engines": {
- "node": ">=18.0.0"
- },
- "devDependencies": {
- "10up-toolkit": "^6.2.0"
- },
- "dependencies": {
- "prop-types": "^15.7.2"
- },
- "10up-toolkit": {
- "entry": {
- "admin": "./assets/js/admin/admin.js",
- "frontend": "./assets/js/frontend/frontend.js",
- "shared": "./assets/js/shared/shared.js",
- "editor": "./assets/js/editor/index.js"
+ "name": "dubinc",
+ "version": "1.0.0",
+ "scripts": {
+ "start": "npm run watch",
+ "watch": "10up-toolkit watch --port=5010",
+ "build": "10up-toolkit build",
+ "format-js": "10up-toolkit format-js",
+ "lint-js": "10up-toolkit lint-js",
+ "lint-style": "10up-toolkit lint-style",
+ "lint-php": "./vendor/bin/phpcs ./includes --standard=ruleset.xml",
+ "fix-php": "./vendor/bin/phpcbf ./includes --standard=ruleset.xml",
+ "test": "10up-toolkit test-unit-jest",
+ "clean-dist": "rm -rf ./dist"
+ },
+ "engines": {
+ "node": ">=18.0.0"
+ },
+ "devDependencies": {
+ "10up-toolkit": "^6.2.0"
+ },
+ "dependencies": {
+ "prop-types": "^15.7.2"
+ },
+ "10up-toolkit": {
+ "entry": {
+ "admin": "./assets/js/admin/admin.js",
+ "frontend": "./assets/js/frontend/frontend.js",
+ "shared": "./assets/js/shared/shared.js",
+ "editor": "./assets/js/editor/index.js"
+ }
}
- }
-}
+}
\ No newline at end of file