Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gutenberg support v2 #28

Merged
merged 5 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions composer.lock

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

19 changes: 19 additions & 0 deletions deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public function run( array $args ) {

$this->validateVersion( $this->version );

// Update deps
echo "Updating dependencies...\n";
$this->updateComposer();
echo "Updating dependencides done OK.\n\n";


// Building package
echo sprintf( 'Building package for version %s... ', $this->version );
$package = $this->buildPackage();
Expand Down Expand Up @@ -170,6 +176,19 @@ private function cleanDir( $dir ) {
}
}

private function updateComposer($baseDir = __DIR__) {
$prevDir = getcwd();
$cmd = 'composer install';

chdir( $baseDir );
passthru( $cmd, $return_var );
chdir( $prevDir );

if ( $return_var !== 0 ) {
throw new \RuntimeException( sprintf( 'Compoase command failed, command was: "%s"', $cmd ) );
}
}

/**
* @return string
*/
Expand Down
1 change: 1 addition & 0 deletions js/gutenberg/blocks.build.js

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

19 changes: 19 additions & 0 deletions js/gutenberg/blocks.editor.build.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* #.# Common SCSS
*
* Can include things like variables and mixins
* that are used across the project.
*/
/**
* #.# Editor Styles
*
* CSS for just Backend enqueued after style.scss
* which makes it higher in priority.
*/
.wp-block-cgb-block-my-block {
background: #bada55;
border: 0.2rem solid #292929;
color: #292929;
margin: 0 auto;
max-width: 740px;
padding: 2rem; }
18 changes: 18 additions & 0 deletions js/gutenberg/blocks.style.build.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* #.# Common SCSS
*
* Can include things like variables and mixins
* that are used across the project.
*/
/**
* #.# Styles
*
* CSS for both Frontend+Backend.
*/
.wp-block-cgb-block-my-block {
background: orangered;
border: 0.2rem solid #292929;
color: #292929;
margin: 0 auto;
max-width: 740px;
padding: 2rem; }
Empty file added js/gutenberg/ss-gutenberg.js
Empty file.
85 changes: 85 additions & 0 deletions src/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,91 @@ public function get_no_access_redirect_url( $post_id = '' ) {
return get_post_meta( $post_id, '_ssc_no_access_redirect', true );
}

/**
* Check if the user is allowed to view specific content (shortcode or Gutenberg block)
*
* @param $args
*
* @return bool
*/
public function user_can_view_content( $args = [] ) {
$defaults = [
'group_id' => '',
'is_member' => '',
'is_logged_in' => '',
'specific_date_from' => '',
'specific_date_to' => '',
'days_to_view' => '',
];

$args = wp_parse_args( $args, $defaults );
$group_id = $args['group_id'];
$is_member = $args['is_member'];
$is_logged_in = $args['is_logged_in'];
$specific_date_from = $args['specific_date_from'];
$specific_date_to = $args['specific_date_to'];
$days_to_view = $args['days_to_view'];


if ( ! empty( $specific_date_from ) ) {
// Check against the from date, this has nothing to do with groups or other settings
if ( date( 'Y-m-d' ) < $specific_date_from ) {
return false;
}
}

if ( ! empty( $specific_date_to ) ) {
// Check against the to date, this has nothing to do with groups or other settings
if ( date( 'Y-m-d' ) > $specific_date_to ) {
return false;
}
}

// Stop if there's no group_id or is_member, and no specific date is set
// if ( empty( $group_id ) || ( empty( $is_member ) && empty( $specific_date_from ) && empty( $specific_date_to ) ) ) {
// return false;
// }


$group = new Group( $group_id );

if ( $is_member == 'yes' ) {
// Check, if the user is logged in and is member of the group, if not, bail
if ( ! is_user_logged_in() || ! $group->user_is_member_of_group( get_current_user_id() ) ) {
return false;
}
} elseif ( $is_member == 'no' ) {
// Check, if the user is NOT a member of specific group. This includes non-logged-in users
if ( is_user_logged_in() && $group->user_is_member_of_group( get_current_user_id() ) ) {
return false;
}
} else {
// If the is_member isn't 'yes' or 'no', the parameter is wrong, so stop here
//return false;
}


// Check if we should display content for logged-in or non-logged-in user
if ( $is_logged_in == 'yes' && ! is_user_logged_in() ) {
return false;
} elseif ( $is_logged_in == 'no' && is_user_logged_in() ) {
return false;
}

// Group check done, check if there are some days set and if is_member is yes
// it doesn't make sense to check days condition for users who should NOT be members of a group
if ( ! empty( $days_to_view ) && $is_member == 'yes' ) {
$membership = new Membership( get_current_user_id() );
$subscription_date = $membership->groups[ $group_id ]['subscription_date'];
// Compare against today's date
if ( date( 'Y-m-d' ) < date( 'Y-m-d', strtotime( "$subscription_date + $days_to_view days" ) ) ) {
return false;
}
}

return true;
}

/**
* Setup the cart in menu
*
Expand Down
25 changes: 16 additions & 9 deletions src/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public function __construct(Plugin $loader) {
* Get products from simple shop via API
*/
public function wp_ajax_load_simple_shop_products() {
$products = $this->get_simpleshop_products();
update_option( 'simpleshop_products', $products );
echo wp_json_encode( $products );
exit();
}

public function get_simpleshop_products() {
$values = [];
if ( $this->loader->has_credentials() ) {
$vyfakturuj_api = new VyfakturujAPI( $this->loader->get_api_email(), $this->loader->get_api_key() );
Expand All @@ -57,8 +64,8 @@ public function wp_ajax_load_simple_shop_products() {
}
}
}
echo json_encode( $values );
exit();

return $values;
}

/**
Expand Down Expand Up @@ -147,7 +154,7 @@ public function tiny_mce_add_buttons( $plugins ) {
public function tiny_mce_register_buttons( $buttons ) {
$newBtns = [
'sscaddformbutton',
'ssccontentbutton'
'ssccontentbutton',
];
$buttons = array_merge( $buttons, $newBtns );

Expand All @@ -172,7 +179,7 @@ public function register_groups_cpt() {
'search_items' => __( 'Find groups', 'simpleshop-cz' ),
'parent_item_colon' => __( 'Parent group:', 'simpleshop-cz' ),
'not_found' => __( 'No Groups found.', 'simpleshop-cz' ),
'not_found_in_trash' => __( 'No Groups is a Trash', 'simpleshop-cz' )
'not_found_in_trash' => __( 'No Groups is a Trash', 'simpleshop-cz' ),
];

$args = [
Expand All @@ -186,7 +193,7 @@ public function register_groups_cpt() {
'has_archive' => false,
'hierarchical' => true,
'menu_position' => null,
'supports' => [ 'title' ]
'supports' => [ 'title' ],
];

register_post_type( 'ssc_group', $args );
Expand All @@ -198,12 +205,12 @@ public function register_groups_cpt() {
public function add_settings_page() {
add_menu_page(
__( 'SimpleShop', 'simpleshop-cz' ),
__( 'SimpleShop', 'simpleshop-cz' ),
'manage_options',
'simple_shop_settings',
__( 'SimpleShop', 'simpleshop-cz' ),
'manage_options',
'simple_shop_settings',
[ $this, 'render_settings_page' ],
$this->pluginDirUrl . '/img/white_logo.png',
99
99
);
}

Expand Down
Loading