Skip to content

Commit

Permalink
Merge pull request #290 from codemonkey-jack/gb-blocks-experiment
Browse files Browse the repository at this point in the history
1.5.92
  • Loading branch information
codemonkey-jack committed Jan 13, 2024
2 parents 1742ddf + 3cf4ee5 commit e925e8c
Show file tree
Hide file tree
Showing 22 changed files with 3,767 additions and 2,411 deletions.
4 changes: 4 additions & 0 deletions assets/css/kbs-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,10 @@ span.price_restricted:before {
padding: 4px 4px 4px 0;
}

body.wp-admin.wp-core-ui.post-type-kbs_ticket .alignleft.actions.bulkactions {
padding: 5px 0 5px 0;
}

/* Metabox Styles
-------------------------------------------------------------- */
#postbox-container-1 .kbs_fields_name_label {
Expand Down
2 changes: 1 addition & 1 deletion assets/css/kbs-admin.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/admin-conditions-scripts.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions assets/js/kbs-login-block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
( function( wp ) {
var registerBlockType = wp.blocks.registerBlockType;
var ServerSideRender = wp.serverSideRender;
var __ = wp.i18n.__;
var TextControl = wp.components.TextControl;
var InspectorControls = wp.blockEditor.InspectorControls;
var PanelBody = wp.components.PanelBody;

registerBlockType( 'kbs/login-block', {
title: __( 'KBS Login', 'kb-support' ),
icon: 'admin-users',
category: 'common',
attributes: {
redirect: {
type: 'string',
default: ''
}
},

edit: function( props ) {
var attributes = props.attributes;
var setAttributes = props.setAttributes;

return [
wp.element.createElement(
InspectorControls,
null,
wp.element.createElement(
PanelBody,
{ title: __( 'Settings', 'kb-support' ) },
wp.element.createElement(
TextControl,
{
label: __( 'Redirect URL', 'kb-support' ),
value: attributes.redirect,
onChange: function( value ) {
setAttributes( { redirect: value } );
}
}
)
)
),
wp.element.createElement(
ServerSideRender,
{
block: "kbs/login-block",
attributes: attributes
}
)
];
},

save: function() {
return null;
},
} );
} )( window.wp );
25 changes: 25 additions & 0 deletions assets/js/kbs-profile-editor-block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
( function( wp ) {
var registerBlockType = wp.blocks.registerBlockType;
var ServerSideRender = wp.serverSideRender;
var __ = wp.i18n.__;

registerBlockType( 'kbs/profile-editor-block', {
title: __( 'KBS Profile Editor', 'kb-support' ),
icon: 'admin-users', // Use a WordPress dashicon or custom SVG
category: 'common',

edit: function() {
return wp.element.createElement(
ServerSideRender,
{
block: "kbs/profile-editor-block"
}
);
},

save: function() {
// Rendering in PHP, so return null
return null;
},
} );
} )( window.wp );
57 changes: 57 additions & 0 deletions assets/js/kbs-register-block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
( function( wp ) {
var registerBlockType = wp.blocks.registerBlockType;
var ServerSideRender = wp.serverSideRender;
var __ = wp.i18n.__;
var TextControl = wp.components.TextControl;
var InspectorControls = wp.blockEditor.InspectorControls;
var PanelBody = wp.components.PanelBody;

registerBlockType( 'kbs/register-block', {
title: __( 'KBS Register', 'kb-support' ),
icon: 'admin-users',
category: 'common',
attributes: {
redirect: {
type: 'string',
default: ''
}
},

edit: function( props ) {
var attributes = props.attributes;
var setAttributes = props.setAttributes;

return [
wp.element.createElement(
InspectorControls,
null,
wp.element.createElement(
PanelBody,
{ title: __( 'Settings', 'kb-support' ) },
wp.element.createElement(
TextControl,
{
label: __( 'Redirect URL', 'kb-support' ),
value: attributes.redirect,
onChange: function( value ) {
setAttributes( { redirect: value } );
}
}
)
)
),
wp.element.createElement(
ServerSideRender,
{
block: "kbs/register-block",
attributes: attributes
}
)
];
},

save: function() {
return null;
},
} );
} )( window.wp );
25 changes: 25 additions & 0 deletions assets/js/kbs-search-block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
( function( wp ) {
var registerBlockType = wp.blocks.registerBlockType;
var ServerSideRender = wp.serverSideRender;
var __ = wp.i18n.__;

registerBlockType( 'kbs/search-block', {
title: __( 'KBS Search', 'kb-support' ),
icon: 'search', // Use a WordPress dashicon or custom SVG
category: 'common',

edit: function() {
return wp.element.createElement(
ServerSideRender,
{
block: "kbs/search-block"
}
);
},

save: function() {
// Rendering in PHP, so return null
return null;
},
} );
} )( window.wp );
57 changes: 57 additions & 0 deletions assets/js/kbs-submit-block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
( function( wp ) {
var registerBlockType = wp.blocks.registerBlockType;
var ServerSideRender = wp.serverSideRender;
var __ = wp.i18n.__;
var TextControl = wp.components.TextControl;
var InspectorControls = wp.blockEditor.InspectorControls;
var PanelBody = wp.components.PanelBody;

registerBlockType( 'kbs/submit-block', {
title: __( 'KBS Submit', 'kb-support' ),
icon: 'forms', // Use a WordPress dashicon or custom SVG
category: 'common',
attributes: {
formId: {
type: 'string',
default: ''
}
},

edit: function( props ) {
var attributes = props.attributes;
var setAttributes = props.setAttributes;

return [
wp.element.createElement(
InspectorControls,
null,
wp.element.createElement(
PanelBody,
{ title: __( 'Settings', 'kb-support' ) },
wp.element.createElement(
TextControl,
{
label: __( 'Form ID', 'kb-support' ),
value: attributes.formId,
onChange: function( value ) {
setAttributes( { formId: value } );
}
}
)
)
),
wp.element.createElement(
ServerSideRender,
{
block: "kbs/submit-block",
attributes: attributes
}
)
];
},

save: function() {
return null;
},
} );
} )( window.wp );
25 changes: 25 additions & 0 deletions assets/js/kbs-tickets-block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
( function( wp ) {
var registerBlockType = wp.blocks.registerBlockType;
var ServerSideRender = wp.serverSideRender;
var __ = wp.i18n.__;

registerBlockType( 'kbs/tickets-block', {
title: __( 'KBS Tickets', 'kb-support' ),
icon: 'tickets-alt', // Use a WordPress dashicon or custom SVG
category: 'common',

edit: function() {
return wp.element.createElement(
ServerSideRender,
{
block: "kbs/tickets-block"
}
);
},

save: function() {
// Rendering in PHP, so return null
return null;
},
} );
} )( window.wp );
17 changes: 15 additions & 2 deletions includes/ajax-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,16 @@ function kbs_ajax_insert_ticket_reply() {
function kbs_ajax_display_ticket_replies() {
$output = '';

if ( ! is_user_logged_in() ) {
return;
}

if ( ! empty( $_POST['kbs_reply_id'] ) && ! empty( $_POST['kbs_ticket_id'] ) ) {
// check if the user is able to access the ticket
$ticket = new KBS_Ticket( absint( $_POST['kbs_ticket_id'] ) );
if ( current_user_can( 'manage_options' ) || $ticket->user_id === get_current_user_id() ) {
$output .= kbs_get_reply_html( absint( $_POST['kbs_reply_id'] ), absint( $_POST['kbs_ticket_id'] ) );
}
} else {
$user_id = get_current_user_id();
$number = get_user_meta( $user_id, '_kbs_load_replies', true );
Expand Down Expand Up @@ -542,9 +550,14 @@ function kbs_ajax_ticket_insert_note() {
*/
function kbs_ajax_display_ticket_notes() {
$output = '';

if ( ! is_user_logged_in() ) {
return '';
}
if ( ! empty( $_POST['kbs_note_id'] ) && ! empty( $_POST['kbs_ticket_id'] ) ) {
$output .= kbs_get_note_html( absint( $_POST['kbs_note_id'] ), absint( $_POST['kbs_ticket_id'] ) );
$ticket = new KBS_Ticket( absint( $_POST['kbs_ticket_id'] ) );
if ( current_user_can( 'manage_options' ) || $ticket->user_id === get_current_user_id() ) {
$output .= kbs_get_note_html( absint( $_POST['kbs_note_id'] ), absint( $_POST['kbs_ticket_id'] ) );
}
} else {

$notes = kbs_get_notes( absint( $_POST['kbs_ticket_id'] ) );
Expand Down
35 changes: 35 additions & 0 deletions includes/blocks/kbs-login-block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
// Ensure ABSPATH is defined for security
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

// Function to render the block
function kbs_login_block_render( $attributes ) {
$redirect = isset( $attributes['redirect'] ) ? $attributes['redirect'] : '';

// Check if the shortcode function exists
if ( function_exists( 'kbs_login_form_shortcode' ) ) {
return kbs_login_form_shortcode( array( 'redirect' => $redirect ) );
}

return '';
}

// Register the block
function kbs_register_login_block() {
// Check if function exists
if ( function_exists( 'register_block_type' ) ) {
register_block_type( 'kbs/login-block', array(
'render_callback' => 'kbs_login_block_render',
'attributes' => array(
'redirect' => array(
'type' => 'string',
'default' => '',
),
),
) );
}
}
add_action( 'init', 'kbs_register_login_block' );

27 changes: 27 additions & 0 deletions includes/blocks/kbs-profile-editor-block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
// Ensure ABSPATH is defined for security
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

// Function to render the block
function kbs_profile_editor_block_render() {
// Check if the shortcode function exists
if ( function_exists( 'kbs_profile_editor_shortcode' ) ) {
// Pass an empty array as the argument
return kbs_profile_editor_shortcode( array() );
}

return '';
}

// Register the block
function kbs_register_profile_editor_block() {
// Check if function exists
if ( function_exists( 'register_block_type' ) ) {
register_block_type( 'kbs/profile-editor-block', array(
'render_callback' => 'kbs_profile_editor_block_render',
) );
}
}
add_action( 'init', 'kbs_register_profile_editor_block' );

0 comments on commit e925e8c

Please sign in to comment.