Skip to content

Commit

Permalink
Merge pull request #40 from XeCreators/update_1.2.4
Browse files Browse the repository at this point in the history
Update 1.2.4
  • Loading branch information
zohaib87 authored Apr 11, 2023
2 parents df2352d + 9e28e2a commit dd449b7
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 108 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

[![Issues](https://img.shields.io/github/issues/XeCreators/xe-plugin)](https://github.com/XeCreators/xe-plugin/issues)
[![Release Latest](https://img.shields.io/github/v/release/XeCreators/xe-plugin?color=yellowgreen)](https://github.com/XeCreators/xe-plugin/releases/latest)
[![Downloads](https://img.shields.io/github/downloads/XeCreators/xe-plugin/total)](https://github.com/XeCreators/xe-plugin/releases/latest)
[![Downloads](https://img.shields.io/github/downloads/XeCreators/xe-plugin/total)](https://github.com/XeCreators/xe-plugin/releaseslatest/download/xe-plugin.zip)
![Repo Size](https://img.shields.io/github/repo-size/XeCreators/xe-plugin.svg)
[![License](https://img.shields.io/github/license/XeCreators/xe-plugin)](https://github.com/XeCreators/xe-plugin/blob/master/LICENSE.md)

Xe Plugin is a starter WordPress plugin which have built-in functionalities that are used in almost every plugin. So just focus on the main functionality that you want to built for WordPress.

[![Download Latest Release](https://img.shields.io/badge/Download_Latest_Release-blue?style=for-the-badge)](https://github.com/XeCreators/xe-plugin/releases/latest)
[![Download Latest Release](https://img.shields.io/badge/Download_Latest_Release-blue?style=for-the-badge)](https://github.com/XeCreators/xe-plugin/releaseslatest/download/xe-plugin.zip)
[![Explore Documentation »](https://img.shields.io/badge/Explore_Documentation-282a2e?style=for-the-badge)](https://xecreators.github.io/xe-plugin)

## Requirements
Expand Down
64 changes: 32 additions & 32 deletions assets/css/admin.css
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
/*--------------------------------------------------------------
# Meta Boxes
--------------------------------------------------------------*/
.xe-plugin-field:not(:last-of-type) {
.xep-field:not(:last-of-type) {
margin: 0 0 12px;
}
.xe-plugin-label,
.xe-plugin-input {
.xep-label,
.xep-input {
display: inline-block;
}
.xe-plugin-label {
.xep-label {
width: 30%;
margin-bottom: 5px;
}
.xe-plugin-label, .xe-plugin-input {
.xep-label, .xep-input {
vertical-align: top;
float: left;
box-sizing: border-box;
}
.xe-plugin-field:after {
.xep-field:after {
content: " ";
display: table;
clear: both;
}
.xe-plugin-field-sm {
.xep-field-sm {
width: 65px;
}
.xe-plugin-field-md {
.xep-field-md {
width: 120px;
}
.xe-plugin-field-full {
.xep-field-full {
width: 100%;
}
.xe-plugin-field .select2-container--default .select2-selection--single,
.xe-plugin-field .select2-container--default .select2-selection--multiple,
.xe-plugin-field input[type=color],
.xe-plugin-field input[type=date],
.xe-plugin-field input[type=datetime-local],
.xe-plugin-field input[type=datetime],
.xe-plugin-field input[type=email],
.xe-plugin-field input[type=month],
.xe-plugin-field input[type=number],
.xe-plugin-field input[type=password],
.xe-plugin-field input[type=search],
.xe-plugin-field input[type=tel],
.xe-plugin-field input[type=text],
.xe-plugin-field input[type=time],
.xe-plugin-field input[type=url],
.xe-plugin-field input[type=week],
.xe-plugin-field input[type=checkbox],
.wp-core-ui .xe-plugin-field select,
.xe-plugin-field textarea {
.xep-field .select2-container--default .select2-selection--single,
.xep-field .select2-container--default .select2-selection--multiple,
.xep-field input[type=color],
.xep-field input[type=date],
.xep-field input[type=datetime-local],
.xep-field input[type=datetime],
.xep-field input[type=email],
.xep-field input[type=month],
.xep-field input[type=number],
.xep-field input[type=password],
.xep-field input[type=search],
.xep-field input[type=tel],
.xep-field input[type=text],
.xep-field input[type=time],
.xep-field input[type=url],
.xep-field input[type=week],
.xep-field input[type=checkbox],
.wp-core-ui .xep-field select,
.xep-field textarea {
border-radius: 0px;
border: 1px solid #ccc;
margin: 0;
}
.xe-plugin-field .select2-container--default .select2-selection--multiple .select2-selection__choice {
.xep-field .select2-container--default .select2-selection--multiple .select2-selection__choice {
margin-bottom: 0;
}
.toplevel_page_xe-plugin-options .select2-container--default .select2-selection--single,
.xe-plugin-field .select2-container--default .select2-selection--single,
.wp-core-ui .xe-plugin-field select {
.toplevel_page_xep-options .select2-container--default .select2-selection--single,
.xep-field .select2-container--default .select2-selection--single,
.wp-core-ui .xep-field select {
min-height: 30px;
}
/*--------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*--------------------------------------------------------------
# Admin Js Start
--------------------------------------------------------------*/
(function($) {
( function ($) {

// ....

})( jQuery );
} )( jQuery );
4 changes: 2 additions & 2 deletions assets/js/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*--------------------------------------------------------------
# Main Js Start
--------------------------------------------------------------*/
(function($) {
( function ($) {

// ....

})( jQuery );
} )( jQuery );
47 changes: 47 additions & 0 deletions helpers/class-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,51 @@ public static function update_field($post_id, $name, $is_array, $validation, $me

}

/**
* # Verify or check for nonce, auto save and post type.
*
* @param string $action Nonce action ID
* @param string $nonce Nonce ID
* @param string $post_type Post type for which saving is going to proceed
* @param string $post_id Current post ID
*
* @return bool true or false
*/
public static function verify_save( $action, $nonce, $post_type, $post_id ) {

// Check if our nonce is set.
if ( ! isset( $_POST[$nonce] ) ) {
return false;
}

// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $_POST[$nonce], $action ) ) {
return false;
}

// If this is an autosave, our form has not been submitted,
// so we don't want to do anything.
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
return false;
}

// Check the user's permissions.
if ( $post_type == $_POST['post_type'] ) {

if ( ! current_user_can( 'edit_page', $post_id ) ) {
return false;
}

} else {

if ( ! current_user_can( 'edit_post', $post_id ) ) {
return false;
}

}

return true;

}

}
24 changes: 12 additions & 12 deletions includes/class-scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Scripts {

function __construct() {

add_action('wp_enqueue_scripts', [$this, 'frontend']);
add_action('admin_enqueue_scripts', [$this, 'admin'], 9999);
add_action( 'wp_enqueue_scripts', [ $this, 'frontend'] );
add_action( 'admin_enqueue_scripts', [ $this, 'admin' ], 9999 );

}

Expand All @@ -28,19 +28,19 @@ public function frontend() {
/**
* Styles
*/
Helper::enqueue('style', 'xe-plugin-main', '/assets/css/main.css');
Helper::enqueue( 'style', 'xe-plugin-main', '/assets/css/main.css' );

/**
* Scripts
*/
Helper::enqueue('script', 'xe-plugin-main', '/assets/js/main.js', ['jquery']);
Helper::enqueue( 'script', 'xe-plugin-main', '/assets/js/main.js', ['jquery'] );

wp_localize_script('xe-plugin-main', 'xepObj', [
wp_localize_script( 'xe-plugin-main', 'xepObj', [
'ajaxUrl' => admin_url('admin-ajax.php'),
'pluginUrl' => _xe_plugin_directory_uri(),
'nonce' => wp_create_nonce('_xe_plugin_ajax_nonce'),
'nonce' => wp_create_nonce('_xep_ajax_nonce'),
'localhost' => $xep_opt->localhost
]);
] );

}

Expand All @@ -54,20 +54,20 @@ public function admin() {
/**
* Styles
*/
Helper::enqueue('style', 'xe-plugin-admin', '/assets/css/admin.css');
Helper::enqueue( 'style', 'xe-plugin-admin', '/assets/css/admin.css' );

/**
* Scripts
*/
Helper::enqueue('script', 'xe-plugin-admin', '/assets/js/admin.js', ['jquery']);
Helper::enqueue( 'script', 'xe-plugin-admin', '/assets/js/admin.js', ['jquery'] );

wp_localize_script('xe-plugin-admin', 'xepObj', [
wp_localize_script( 'xe-plugin-admin', 'xepObj', [
'pluginUrl' => _xe_plugin_directory_uri(),
'nonce' => wp_create_nonce('_xe_plugin_ajax_nonce'),
'nonce' => wp_create_nonce('_xep_ajax_nonce'),
'postType' => $current_screen->post_type,
'base' => $current_screen->base,
'localhost' => $xep_opt->localhost
]);
] );

}

Expand Down
46 changes: 14 additions & 32 deletions includes/metaboxes/class-sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Sample {

function __construct() {

add_action('add_meta_boxes', [$this, 'add']);
add_action('save_post_'.$this->post_type(), [$this, 'save']);
add_action( 'add_meta_boxes', [ $this, 'add' ] );
add_action( 'save_post_'.$this->post_type(), [ $this, 'save'] );

}

Expand All @@ -33,23 +33,23 @@ protected function post_type() {
* # Set up and add the meta box.
*/
public function add() {
add_meta_box('sample_meta_box', esc_html__('Sample Title', 'xem-pos'), [$this, 'html'], $this->post_type());
add_meta_box( 'sample_meta_box', esc_html__( 'Sample Title', 'xem-pos' ), [ $this, 'html' ], $this->post_type() );
}

/**
* Display the meta box HTML to the user.
*/
public function html($post) {
public function html( $post ) {

// Add an nonce field so we can check for it later.
wp_nonce_field('xe_plugin_cpt_meta_box', 'xe_plugin_cpt_meta_box_nonce');
wp_nonce_field( 'xep_cpt_meta_box', 'xep_cpt_meta_box_nonce' );

$sample = get_post_meta($post->ID, '_sample', true);

?>
<div class="xe-plugin-field">
<div class="xe-plugin-label">
<label for="sample">Serial No:</label>
<label for="sample"><?php echo esc_html__( 'Serial No:', 'xe-plugin' ); ?></label>
</div>
<div class="xe-plugin-input">
<input type="text" name="sample" id="sample" value="<?php echo esc_attr($sample); ?>" required>
Expand All @@ -62,37 +62,19 @@ public function html($post) {
/**
* Save the meta box selections.
*/
public function save(int $post_id) {
public function save( int $post_id ) {

// Check if our nonce is set.
if ( !isset($_POST['xe_plugin_cpt_meta_box_nonce']) ) {
return $post_id;
}

$nonce = $_POST['xe_plugin_cpt_meta_box_nonce'];

// Verify that the nonce is valid.
if ( !wp_verify_nonce($nonce, 'xe_plugin_cpt_meta_box') ) {
return $post_id;
}
$verify_save = Helper::verify_save(
'xep_cpt_meta_box',
'xep_cpt_meta_box_nonce',
$this->post_type(),
$post_id
);

// If this is an autosave, our form has not been submitted,
// so we don't want to do anything.
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
if ( $verify_save == false ) {
return $post_id;
}

// Check the user's permissions.
if ( 'xe-plugin-cpt' == $_POST['post_type'] ) {
if ( !current_user_can('edit_page', $post_id) ) {
return $post_id;
}
} else {
if ( !current_user_can('edit_post', $post_id) ) {
return $post_id;
}
}

// Saving or Updating the data
Helper::update_field($post_id, 'sample', false, 'text', '_sample'); // $post_id, $name, $is_array, $validation, $meta_key, $delete = false

Expand Down
6 changes: 4 additions & 2 deletions node_scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var globalVars = "$"+global+"_opt";
var namespaces = name.replace(/ /g, '_')+"\\";
var folderNames = "/"+nameHyphen;
var globalObj = "'"+global+"Obj'";
var cssPrefixes = global+'-';
var nonces = global+'_';

var currentPlugin = path.resolve(__dirname, '..');

Expand All @@ -29,8 +31,8 @@ var options = {
currentPlugin+'/**/*.php',
currentPlugin+'/readme.txt',
],
from: [/'xe-plugin'/g, /_xe_plugin_/g, /Text Domain: xe-plugin/g, / Xe Plugin/g, /xe-plugin-/g, /\$xep_opt/g, /Xe_Plugin\\/g, /\/xe-plugin/g, /'xepObj'/g],
to: [txtDomain, funcNames, styleCss, dockBlocks, preHandles, globalVars, namespaces, folderNames, globalObj],
from: [ /'xe-plugin'/g, /_xe_plugin_/g, /Text Domain: xe-plugin/g, / Xe Plugin/g, /xe-plugin-/g, /\$xep_opt/g, /Xe_Plugin\\/g, /\/xe-plugin/g, /'xepObj'/g, /xep-/g, /_xep_/g ],
to: [ txtDomain, funcNames, styleCss, dockBlocks, preHandles, globalVars, namespaces, folderNames, globalObj, cssPrefixes, nonces ],
};

fs.rename(currentPlugin+'/xe-plugin.php', currentPlugin+'/'+nameHyphen+'.php', function(err) {
Expand Down
Loading

0 comments on commit dd449b7

Please sign in to comment.