Skip to content

Commit

Permalink
2.0.0 beta
Browse files Browse the repository at this point in the history
  • Loading branch information
hrsetyono authored Mar 19, 2019
2 parents 076610c + a263a2e commit 47c9109
Show file tree
Hide file tree
Showing 23 changed files with 714 additions and 752 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2019 Henner Setyono

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
132 changes: 107 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,126 @@
# Edje WordPress
# Edje WordPress Library

![Edje Wordpress](http://cdn.setyono.net/edge/wp-edge.jpg)
![Edje Wordpress](https://cdn.setyono.net/edge/wp-edge.jpg)

Simplify WordPress complicated functions.
WordPress is a fantastic web platform, but it's complicated for developer. This plugin helps simplifying many functions.

## Requirement
**REQUIREMENT**

- PHP 5.6+
- WordPress 4.9+
- PHP 7.0+
- WordPress 5.0+

## Sample Features
**TABLE OF CONTENTS**

Create new Custom Post Type
1. [Custom Post Type](#custom-post-type)
1. [Custom Taxonomy](#custom-taxonomy)
1. [Theme Customizer](#theme-customizer)
1. [Post Table Columns](#post-table-columns)
1. [Other Features](#other-features)

## 1. Custom Post Type

[Read full documentation »](https://github.com/hrsetyono/edje-wp-library/wiki/Custom-Post-Type)

![Edje WordPress - Product Custom Post Type](https://cdn.setyono.net/edjewp/cpt-product.jpg)

```php
H::register_post_type( 'product' );
H::register_post_type( 'product', [
'icon' => 'dashicons-cart',
'supports' => [ 'comments' ]
] );
```

Add new Admin Sidebar menu:
## 2. Custom Taxonomy

[Read full documentation »](https://github.com/hrsetyono/edje-wp-library/wiki/Custom-Taxonomy)

![Edje WordPress - Product Custom Post Type](https://cdn.setyono.net/edjewp/cpt-product.jpg)

```php
H::add_menu( 'Home' array(
'slug' => 'post.php?post=10&action=edit',
'icon' => 'dashicons-admin-home',
'position' => 'above Pages'
));
H::register_taxonomy( 'brand' , [
'post_type' => 'product',
] );
```

Sending push notification after publishing new post:

## 3. Theme Customizer

[Read full documentation »](https://github.com/hrsetyono/edje-wp-library/wiki/Customizer)

You can access this from **Appearance > Customizer**. By default, only Administrator role can see this page.

![Edje Customize Example](https://cdn.setyono.net/edjewp/cust-sample-header.jpg)

```php
add_action( 'publish_post', 'after_publish_notify_users', 10, 2 );

function after_publish_notify_users( $id, $post ) {
$payload = array(
'title' => $post->post_title,
'body' => $post->post_excerpt,
);
H::send_push( $payload );
add_action( 'customize_register', 'my_customize_register' );

function my_customize_register( $wp_customize ) {
$c = H::customizer( $wp_customize ); // init the class

$c->add_section( 'header' );

$c->add_theme_mod( 'head_code', 'code_editor htmlmixed' );
$c->add_theme_mod( 'background_color', 'color' );
$c->add_theme_mod( 'phone_no', 'text' );
}
```

## Visit our [WIKI](https://github.com/hrsetyono/edje-wp/wiki) for full documentation.
## 4. Post Table Columns

[Read full documentation »](https://github.com/hrsetyono/edje-wp-library/wiki/Table-Columns)

![Edje WordPress - Complex Column](https://cdn.setyono.net/edjewp/cpt-column.jpg)

```php
H::override_columns( 'product', [
'title',
'price',
'Discount' => 'show_discounted_price',
] );

function show_discounted_price( $post, $fields ) {
$discount = isset( $fields['discount'] ) ? $fields['discount'][0] : null;
$price = isset( $fields['price'] ) ? $fields['price'][0] : null;

$total = $price - ($price * $discount / 100);
$saving = $price - $total;

return $discount . '% Discount - You save ' . $saving;
}
```

## 5. Other Features

All these features are enabled by default:

**JavaScript**

- Removed emoji converter.
- Removed ability to embed WordPress post.
- Removed Jetpack's Device-px script because it's useless.
- Removed Jetpack's Sharing script. It's only for sharing via email which is rarely used.
- [COMING SOON] Removed jQuery and jQuery migrate. If you need jQuery, enqueue it in your Theme.

**SEO**

- Disabled automatic URL guessing if a visitor enters 404 page.
- Disabled Jetpack's Open Graph module when Yoast or The SEO Framework is installed

**CUSTOMIZER**

- Added Head and Footer code field.
- Added Theme Color field in Site Identity for changing the actionbar color in Chrome mobile.

**EDIT POST**

- Removed Medium-Large size when uploading new image.
- Changed the Category checklist to always be in same the position.
- Added a better styling to WYSIWYG classic editor.
- Added styling to Gutenberg editor for ACF block.

**OTHER**

- Removed "Created by Wordpress" message in the bottom-left of WP Admin
- Changed the login error message to "Sorry, your username or password is wrong" instead of giving hint of which one is wrong.
- Changed the Wordpress logo in login page to the one you have set in Customizer > Site Identity.
- Added the ability to edit TWIG file in Appearance > Editor. But it's still recommended to disable Editor by adding this line in WP Config: `define('DISALLOW_FILE_EDIT', true);`
113 changes: 67 additions & 46 deletions admin/h-on-activate.php → activation-hook.php
Original file line number Diff line number Diff line change
@@ -1,85 +1,107 @@
<?php
/*
Functions to run after plugin is activated
*/
class H_OnActivate {
function __construct() {
register_activation_hook( H_BASE, array($this, 'activation_hook') );
}
You need to define EDJE variable to true in WP Config
define( 'EDJE', true );
*/
class H_Hook {
/*
Run when the plugin is activated
*/
function activation_hook() {
$options = get_option('h_options');

// create empty option if doesn't exist
if(!$options) { add_option('h_options', array() ); }
if( !$options ) {
add_option('h_options', [] );
}

// if page not initialized
if(!isset($options['init']) ) {
$this->_create_default_page();
$this->_create_default_post();
$this->_set_default_setting();
// If first time activation
if( !isset($options['init'] ) ) {
$this->_create_frontpage();
$this->_create_blogpage();

$this->_set_default_setting();
$this->_create_default_nav();

$options['init'] = true;
}

// if post not initialized
if(!isset($options['post_init']) ) {
// If sample post never created before
if( !isset($options['post_init']) ) {
$this->_create_default_post();

$options['post_init'] = true;
}

update_option('h_options', $options);
update_option( 'h_options', $options );
}


/*
Create default page for HOME and BLOG
Run when the plugin is deactivated
*/
function _create_default_page() {
$frontpage_id = get_option('page_on_front');
$blogpage_id = get_option('page_for_posts');
function deactivation_hook() {

}

/////

/*
Create default Frontpage
*/
private function _create_frontpage() {
$frontpage_id = get_option( 'page_on_front' );

// if already exists, just change the title
if($frontpage_id) {
$args = array(
if( $frontpage_id ) {
$args = [
'ID' => $frontpage_id,
'post_title' => get_bloginfo()
);
];

wp_update_post($args);
wp_update_post( $args );
}
// if not exists, create it
// if does not exists, create it
else {
$home = array(
$home = [
'post_title' => get_bloginfo(),
'post_type' => 'page',
'post_status' => 'publish',
);
];

$home_id = wp_insert_post($home);
update_option('show_on_front', 'page');
update_option('page_on_front', $home_id);
$home_id = wp_insert_post( $home );
update_option( 'show_on_front', 'page' );
update_option( 'page_on_front', $home_id );
}
}

// create posts page if not set
if(!$blogpage_id) {
$blog = array(
/*
Create default Blog page
*/
private function _create_blogpage() {
$blogpage_id = get_option( 'page_for_posts' );

// If does not exists, create one
if( !$blogpage_id ) {
$blog = [
'post_title' => 'Blog',
'post_type' => 'page',
'post_status' => 'publish',
);
];

$blog_id = wp_insert_post($blog);
update_option('page_for_posts', $blog_id);
$blog_id = wp_insert_post( $blog );
update_option( 'page_for_posts', $blog_id );
}
}


/*
Create default navigation menu
*/
function _create_default_nav() {
private function _create_default_nav() {
$navs = array(
// MAIN
array(
Expand Down Expand Up @@ -121,8 +143,6 @@ function _create_default_nav() {
$locations = get_theme_mod('nav_menu_locations');

foreach($navs as $nav):
// var_dump($nav);
// exit();
// if doesn't exist AND the location isn't occupied
if(! wp_get_nav_menu_object($nav['name'] && !has_nav_menu($nav['location'])) ) {
// create empty menu
Expand All @@ -142,32 +162,33 @@ function _create_default_nav() {
}

/*
Create sample post that also acts as guide to WordPress
Create sample post content
*/
function _create_default_post() {
$args = array(
private function _create_default_post() {
$args = [
'post_title' => 'Welcome to WordPress',
'post_name' => 'welcome-to-wordpress',
'post_type' => 'post',
'post_content' => $this->sample_content,
'post_status' => 'publish'
);
];

// if post ID 1 exist
if(is_string(get_post_status(1)) ) {
// if post ID 1 exist, edit it
if( is_string(get_post_status(1)) ) {
$args['ID'] = 1;
wp_update_post($args);
wp_update_post( $args );
}
// if does not exist, create new post with ID 1
else {
$args['import_id'] = 1;
wp_insert_post($args);
wp_insert_post( $args );
}
}

/*
Default setting for Standard website
*/
function _set_default_setting() {
private function _set_default_setting() {
// general
update_option('use_smiles', 0);

Expand Down
20 changes: 20 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "pixelstudio/edje-wp-library",
"version": "2.0.0",
"description": "Plugin to simplify WordPress complicated functions.",
"keywords": ["wordpress", "plugin", "library"],
"type": "wordpress-plugin",
"homepage": "https://github.com/hrsetyono/edje-wp-library/",
"authors": [
{
"name": "Pixel Studio",
"email": "[email protected]",
"homepage": "https://pixelstudio.id"
}
],
"license": "MIT",
"require": {
"php": ">=7.0.0",
"composer/installers": ">=1.6.0"
}
}
Loading

0 comments on commit 47c9109

Please sign in to comment.