Skip to content

Commit

Permalink
Small tweeks
Browse files Browse the repository at this point in the history
  • Loading branch information
scottyzen committed Jan 25, 2023
1 parent 9c53e5c commit 10eb972
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 48 deletions.
63 changes: 59 additions & 4 deletions assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
max-width: 960px;
margin: 40px auto;
}

.settings_page_woonuxt .wrap > form > div:not(.woonuxt-section){
display: none;
}
.required-plugins-list {
display: flex;
flex-direction: row;
Expand All @@ -21,6 +25,13 @@
flex-direction: column;
}

button.remove_global_attribute.button.button-danger {
background: #e13b3d;
border-color: #980b0b;
color: white;
min-width: 102px;
}

.plugin-state {
display: flex;
flex-direction: row;
Expand Down Expand Up @@ -51,21 +62,26 @@
margin-bottom: 0;
}

.global_attribute{
.global_attributes{
display: grid;
gap: 1rem;
}

/* .global_attribute{
padding: 1rem;
box-shadow: 0 3px 12px -3px #dee1e6;
border-radius: 5px;
background: #fff;
margin-bottom: 1rem;
display: grid;
gap: 1rem;
}
} */

.global_attribute .row{
display: flex;
flex-direction: row;
/* flex-direction: row; */
gap: 1rem;
align-items: center;
/* align-items: center; */
}

.remove_global_attribute{
Expand All @@ -76,6 +92,42 @@
margin-left: auto;
}

#wpcontent .acf-admin-toolbar {
box-sizing: border-box;
margin-left: -20px;
padding-top: 16px;
padding-right: 32px;
padding-bottom: 16px;
padding-left: 32px;
}

.acf-admin-toolbar {
display: flex;
justify-content: flex-start;
align-content: center;
align-items: center;
position: unset;
top: 32px;
height: 72px;
z-index: 800;
background: #344054;
color: #98A2B3;
}

.acf-admin-toolbar h2 {
color: #F9FAFB;
}

.acf-admin-toolbar .acf-logo {
margin-right: 32px;
}

.acf-admin-toolbar .acf-logo img {
display: block;
max-width: 55px;
line-height: 0%;
}

.flex{
display: flex;
align-items: center;
Expand Down Expand Up @@ -110,4 +162,7 @@
}
.mt-24{
margin-top: 3rem;
}
.w-full{
width: 100%;
}
134 changes: 90 additions & 44 deletions woonuxt.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Author: Scott Kennedy
Author URI: http://scottyzen.com
Plugin URI: http://woonuxt.com
Version: 1.0.2
Version: 1.0.4
*/

// Exit if accessed directly
Expand Down Expand Up @@ -51,13 +51,6 @@ function woonuxt_options_page_html() {
<?php endif; ?>
<button id="deploy-button" class="acf-button button button-primary button-large" style="display: block;">Deploy</button>
</div>
<div class="acf-headerbar">
<div class="acf-headerbar-left">
<div class="acf-headerbar-title">
<h2>WooNuxt Options</h2>
</div>
</div>
</div>
<div class="wrap">
<form action="options.php" method="post">
<?php
Expand Down Expand Up @@ -94,7 +87,7 @@ function woonuxt_register_settings() {
function required_plugins_callback() {
$tick_svg_icon = '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24"><path d="M9 16.17l-3.59-3.59L4 14l5 5 9-9-1.41-1.41L9 16.17z"/></svg>';
?>
<div>
<div class="woonuxt-section">
<ul class="required-plugins-list">
<li class="required-plugin <?php echo is_plugin_active( 'wp-graphql/wp-graphql.php' ) ? 'active' : 'inactive'; ?>">
<img src="https://www.wpgraphql.com/logo-wpgraphql.svg" alt="WPGraphQL" width="64" height="64">
Expand Down Expand Up @@ -144,22 +137,36 @@ function required_plugins_callback() {

// https://downloads.wordpress.org/plugin/wp-graphql.1.13.7.zip
if ( $_GET['install_plugin'] == 'wp-graphql' && ! is_plugin_active( 'wp-graphql/wp-graphql.php' ) ) {
$url = 'https://downloads.wordpress.org/plugin/wp-graphql.1.13.7.zip';
$upgrader = new Plugin_Upgrader();
$result = $upgrader->install( $url );
if ( ! is_wp_error( $result ) ) {
$fileURL = WP_PLUGIN_DIR . '/wp-graphql/wp-graphql.php';
if ( file_exists( $fileURL ) ) {
activate_plugin( 'wp-graphql/wp-graphql.php' );
wp_redirect( '/wp-admin/options-general.php?page=woonuxt' );
} else {
$url = 'https://downloads.wordpress.org/plugin/wp-graphql.1.13.7.zip';
$upgrader = new Plugin_Upgrader();
$result = $upgrader->install( $url );
if ( ! is_wp_error( $result ) ) {
activate_plugin( 'wp-graphql/wp-graphql.php' );
wp_redirect( '/wp-admin/options-general.php?page=woonuxt' );
}
}
}


// https://github.com/wp-graphql/wp-graphql-woocommerce/releases/download/v0.12.0/wp-graphql-woocommerce.zip
if ( $_GET['install_plugin'] == 'woographql' && ! is_plugin_active( 'wp-graphql-woocommerce/wp-graphql-woocommerce.php' ) ) {
$url = 'https://github.com/wp-graphql/wp-graphql-woocommerce/releases/download/v0.12.0/wp-graphql-woocommerce.zip';
$upgrader = new Plugin_Upgrader();
$result = $upgrader->install( $url );
if ( ! is_wp_error( $result ) ) {
$fileURL = WP_PLUGIN_DIR . '/wp-graphql-woocommerce/wp-graphql-woocommerce.php';
if ( file_exists( $fileURL ) ) {
activate_plugin( 'wp-graphql-woocommerce/wp-graphql-woocommerce.php' );
wp_redirect( '/wp-admin/options-general.php?page=woonuxt' );
} else {
$url = 'https://github.com/wp-graphql/wp-graphql-woocommerce/releases/download/v0.12.0/wp-graphql-woocommerce.zip';
$upgrader = new Plugin_Upgrader();
$result = $upgrader->install( $url );
if ( ! is_wp_error( $result ) ) {
activate_plugin( 'wp-graphql-woocommerce/wp-graphql-woocommerce.php' );
wp_redirect( '/wp-admin/options-general.php?page=woonuxt' );
}
}
}

Expand All @@ -168,16 +175,20 @@ function required_plugins_callback() {
$fileURL = WP_PLUGIN_DIR . '/wp-graphql-cors-2.1/wp-graphql-cors.php';
if ( file_exists( $fileURL ) ) {
activate_plugin( 'wp-graphql-cors-2.1/wp-graphql-cors.php' );
return;
}
$url = 'https://github.com/funkhaus/wp-graphql-cors/archive/refs/tags/2.1.zip';
$upgrader = new Plugin_Upgrader();
$result = $upgrader->install( $url );
if ( ! is_wp_error( $result ) ) {
activate_plugin( 'wp-graphql-cors-2.1/wp-graphql-cors.php' );
wp_redirect( '/wp-admin/options-general.php?page=woonuxt' );
} else {
$url = 'https://github.com/funkhaus/wp-graphql-cors/archive/refs/tags/2.1.zip';
$upgrader = new Plugin_Upgrader();
$result = $upgrader->install( $url );
if ( ! is_wp_error( $result ) ) {
activate_plugin( 'wp-graphql-cors-2.1/wp-graphql-cors.php' );
wp_redirect( '/wp-admin/options-general.php?page=woonuxt' );
}
}
}

wp_redirect( admin_url( 'options-general.php?page=woonuxt' ) );

}
}

Expand Down Expand Up @@ -213,13 +224,36 @@ function required_plugins_callback() {
'logo' => [
'type' => 'String'
],
'maxPrice' => [
'type' => 'Int',
'description' => __( 'Most expensive product price', 'woonuxt' ),
],
],
]);
register_graphql_field( 'RootQuery', 'woonuxtSettings', [
'type' => 'woonuxtOptions',
'description' => __( 'Woonuxt Settings', 'woonuxt' ),
'resolve' => function() {
return get_option( 'woonuxt_options' );
$max_price = 0;

$args = [
'post_type' => 'product',
'posts_per_page' => 1,
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_key' => '_price',
];

$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
$max_price = $product->get_price();
endwhile;
wp_reset_query();

$options = get_option( 'woonuxt_options' );
$options['maxPrice'] = $max_price;
return $options;
},
]);
});
Expand All @@ -231,7 +265,7 @@ function global_setting_callback() {
$options = get_option( 'woonuxt_options' );

?>
<div class="global_setting">
<div class="global_setting woonuxt-section">

<!-- BUILD HOOK -->
<label for="woonuxt_options[build_hook]">Build Hook</label>
Expand Down Expand Up @@ -269,32 +303,29 @@ class="mb-16"
name="woonuxt_options[primary_color]"
value="<?php echo $options['primary_color'] ? $options['primary_color'] : '#7F54B2'; ?>"
/>

<br>

<!-- GLOBAL ATTRIBLUES FOR FILTERS -->
<label for="woonuxt_options[global_attributes]">Global Attributes</label>
<div class="global_attributes">
<div class="global_attributes woonuxt-section">
<?php
if ( $options['global_attributes'] ) {
$product_attributes = wc_get_attribute_taxonomies();

foreach ( $options['global_attributes'] as $key => $value ) {
?>
<div class="global_attribute">
<div class="grid gap-1 grid-cols-2">
<div class="grid">
<label for="woonuxt_options[global_attributes][<?php echo $key; ?>][label]">Label</label>
<div class="flex gap-1">
<!-- <label for="woonuxt_options[global_attributes][<?php echo $key; ?>][label]">Label</label> -->
<input type="text"
class="flex-1 widefat"
class="flex-1"
name="woonuxt_options[global_attributes][<?php echo $key; ?>][label]"
value="<?php echo $value['label']; ?>"
placeholder="e.g. Color"
/>
</div>
<div class="grid">
<label for="woonuxt_options[global_attributes][<?php echo $key; ?>][slug]">Slug</label>
<select name="woonuxt_options[global_attributes][<?php echo $key; ?>][slug]" class="widefat">

<!-- <label for="woonuxt_options[global_attributes][<?php echo $key; ?>][slug]">Slug</label> -->
<select name="woonuxt_options[global_attributes][<?php echo $key; ?>][slug]" class="flex-1">
<?php
foreach ( $product_attributes as $attribute ) {
$slected_attribute = $value['slug'] == 'pa_' . $attribute->attribute_name ? 'selected' : '' ;
Expand All @@ -306,9 +337,7 @@ class="flex-1 widefat"
}
?>
</select>
</div>
</div>
<div class="row">

<label for="woonuxt_options[global_attributes][<?php echo $key; ?>][showCount]">Show Count</label>
<input type="checkbox"
class="widefat"
Expand All @@ -331,14 +360,15 @@ class="widefat"
<?php echo $value['openByDefault']
? 'checked' : ''; ?>
/>
<button class="remove_global_attribute">Remove</button>
<button class="remove_global_attribute button button-danger">Remove</button>
</div>

</div>
<?php
}
}
?>
<hr class="w-full" />
<div class="flex gap-1 add_global_attribute_row">
<input class="flex-1 new-attr-label" type="text" placeholder="Label" />
<select class="flex-1 new-attr-slug" id="global_attribute_dropdown">
Expand All @@ -353,6 +383,15 @@ class="widefat"
}
?>
</select>
<lable>Show Count
</lable>
<input type="checkbox" class="new-attr-showCount" value="1" />
<lable>Hide Empty
</lable>
<input type="checkbox" class="new-attr-hideEmpty" value="1" />
<lable>Open By Default
</lable>
<input type="checkbox" class="new-attr-openByDefault" value="1" />
<button class="add_global_attribute button button-primary">Add Attribute</button>
</div>

Expand All @@ -368,7 +407,11 @@ class="widefat"
e.preventDefault();
var label = $('.new-attr-label').val();
var slug = $('.new-attr-slug').val();
var html = '<div class="global_attribute">';
var showCount = $('.new-attr-showCount').is(':checked') ? 1 : 0;
var hideEmpty = $('.new-attr-hideEmpty').is(':checked') ? 1 : 0;
var openByDefault = $('.new-attr-openByDefault').is(':checked') ? 1 : 0;

var html = '<div class="global_attribute woonuxt-section">';
html += '<div class="grid gap-1 grid-cols-2">';
html += '<div class="grid">';
html += '<label for="woonuxt_options[global_attributes][' + slug + '][label]">Label</label>';
Expand All @@ -386,19 +429,22 @@ class="widefat"
html += '</div>';
html += '<div class="row">';
html += '<label for="woonuxt_options[global_attributes][' + slug + '][showCount]">Show Count</label>';
html += '<input type="checkbox" class="widefat" name="woonuxt_options[global_attributes][' + slug + '][showCount]" value="1" />';
html += '<input type="checkbox" class="widefat" name="woonuxt_options[global_attributes][' + slug + '][showCount]" value="1" ' + (showCount ? 'checked' : '') + ' />';
html += '<label for="woonuxt_options[global_attributes][' + slug + '][hideEmpty]">Hide Empty</label>';
html += '<input type="checkbox" class="widefat" name="woonuxt_options[global_attributes][' + slug + '][hideEmpty]" value="1" />';
html += '<input type="checkbox" class="widefat" name="woonuxt_options[global_attributes][' + slug + '][hideEmpty]" value="1" ' + (hideEmpty ? 'checked' : '') + ' />';
html += '<label for="woonuxt_options[global_attributes][' + slug + '][openByDefault]">Open By Default</label>';
html += '<input type="checkbox" class="widefat" name="woonuxt_options[global_attributes][' + slug + '][openByDefault]" value="1" />';
html += '<input type="checkbox" class="widefat" name="woonuxt_options[global_attributes][' + slug + '][openByDefault]" value="1" ' + (openByDefault ? 'checked' : '') + ' />';
html += '<button class="remove_global_attribute">Remove</button>';
html += '</div>';
html += '</div>';




$('.add_global_attribute_row').before(html);
$('.new-attr-label').val('');
$('.new-attr-slug').val('');

});

// remove global attribute
Expand Down

0 comments on commit 10eb972

Please sign in to comment.