Skip to content

Commit

Permalink
Merge pull request #1954 from Codeinwp/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
HardeepAsrani authored Nov 14, 2023
2 parents 2c3e29d + 0a550c8 commit 0e35561
Show file tree
Hide file tree
Showing 94 changed files with 2,965 additions and 344 deletions.
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":{"TestBlockConditions::test_hide_css_desktop_condition":3},"times":{"TestBlockConditions::test_logged_in_user_on_login":0.034,"TestBlockConditions::test_logged_in_user_on_logout":0.023,"TestBlockConditions::test_logged_out_user_on_login":0.028,"TestBlockConditions::test_logged_out_user_on_logout":0.028,"TestBlockConditions::test_user_roles_has_role":0.028,"TestBlockConditions::test_user_roles_does_not_have_role":0.028,"TestBlockConditions::test_post_type":0.028,"TestBlockConditions::test_post_type_on_invalid":0.028,"TestBlockConditions::test_post_category":0.028,"TestBlockConditions::test_post_category_on_invalid":0.028,"TestBlockConditions::test_logged_in_user_meta":0.028,"TestBlockConditions::test_logged_in_user_meta_invalid":0.03,"TestBlockConditions::test_post_meta":0.029,"TestBlockConditions::test_post_meta_invalid":0.029,"TestBlockConditions::test_date_range":0.029,"TestBlockConditions::test_date_range_invalid":0.029,"TestBlockConditions::test_date_recurring":0.029,"TestBlockConditions::test_multiple_conditions":0.03,"TestBlockConditions::test_multiple_conditions__with_one_invalid":0.029,"TestBlockConditions::test_multiple_conditions_with_all_invalid":0.029,"TestBlockConditions::test_or_collection":0.029,"TestBlockConditions::test_or_collection_invalid":0.03,"TestBlockConditions::test_hide_css_desktop_condition":0.03,"TestCSS::test_css_simple":0,"TestCSS::test_css_defaults":0,"TestCSS::test_css_format":0,"TestCSS::test_css_condition":0.002,"TestCSS::test_css_pattern":0,"TestCSS::test_render_box":0,"TestDynamicContent::test_post_id":0.029,"TestDynamicContent::test_post_type":0.026,"TestDynamicContent::test_post_title":0.025,"TestDynamicContent::test_post_status":0.028,"TestDynamicContent::test_post_content":0.028,"TestDynamicContent::test_post_excerpt":0.028,"TestDynamicContent::test_post_date":0.032,"TestDynamicContent::test_post_time":0.032,"TestDynamicContent::test_post_terms":0.028,"TestDynamicContent::test_post_meta":0.029,"TestDynamicContent::test_acf":0.028,"TestDynamicContent::test_site_title":0.028,"TestDynamicContent::test_site_tagline":0.029,"TestDynamicContent::test_author_name":0.028,"TestDynamicContent::test_author_description":0.029,"TestDynamicContent::test_author_meta":0.028,"TestDynamicContent::test_logged_in_user_name":0.029,"TestDynamicContent::test_logged_in_user_description":0.028,"TestDynamicContent::test_logged_in_user_email":0.028,"TestDynamicContent::test_logged_in_user_meta":0.028,"TestDynamicContent::test_archive_title":0.028,"TestDynamicContent::test_archive_description":0.029,"TestDynamicContent::test_date":0.028,"TestDynamicContent::test_time":0.028,"TestDynamicContent::test_query_string":0.028,"TestDynamicContent::test_country":0.028,"TestDynamicContent::test_post_id_evaluation":0.028,"TestDynamicContent::test_post_type_evaluation":0.029,"TestDynamicContent::test_post_title_evaluation":0.03,"TestDynamicContent::test_post_status_evaluation":0.035,"TestDynamicContent::test_post_content_evaluation":0.033,"TestDynamicContent::test_post_excerpt_evaluation":0.029,"TestDynamicContent::test_logged_in_user_name_evaluation":0.028,"TestDynamicContent::test_logged_in_user_description_evaluation":0.027,"TestDynamicContent::test_logged_in_user_email_evaluation":0.029,"TestDynamicContent::test_date_evaluation":0.028,"TestDynamicContent::test_time_evaluation":0.027,"TestDynamicContent::test_author_name_evaluation":0.028,"TestDynamicContent::test_author_description_evaluation":0.029,"TestDynamicContent::test_multiple_dynamic_content_queries":0.03,"TestDynamicContent::test_multiple_dynamic_content_queries_on_long_content":0.05,"TestPatterns::test_fetch_patterns":0.475,"TestStripeAPI::test_retrieve_products":0.053,"TestStripeAPI::test_retrieve_prices":0.002,"TestStripeAPI::test_retrieve_product":0.001,"TestStripeAPI::test_retrieve_price":0.001,"TestStripeAPI::test_retrieve_session_email":0.001,"TestStripeAPI::test_user_purchase":0.001,"TestStripeAPI::test_status_for_price_id":0.001,"TestBlockConditions::test_hide_css_tablet_condition":0.028,"TestBlockConditions::test_hide_css_mobile_condition":0.029,"TestBlockConditions::test_hide_css_all_condition":0.028,"TestBlockConditions::test_get_css_hide_condition":0.03,"TestBlockConditions::test_get_css_hide_condition_no_hide":0.028}}
74 changes: 74 additions & 0 deletions inc/Tracker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Class for telemetry.
*
* @package ThemeIsle
*/

namespace ThemeIsle\GutenbergBlocks;

/**
* Class Tracker
*/
class Tracker {

/**
* Tracking URL.
*
* @var string
*/
public static $track_url = 'https://api.themeisle.com/tracking/events';

/**
* Send data to the server if the user has opted in.
*
* @param array<array> $events Data to track.
* @param array $options Options.
* @return void
*/
public static function track( $events, $options = array() ) {

if ( ! self::has_consent() && ( ! isset( $options['hasConsent'] ) || ! $options['hasConsent'] ) ) {
return;
}

try {
$payload = array();

$license = apply_filters( 'product_otter_license_key', 'free' );

if ( 'free' !== $license ) {
$license = wp_hash( $license );
}

foreach ( $events as $event ) {
$payload[] = array(
'slug' => 'otter',
'site' => get_site_url(),
'license' => $license,
'data' => $event,
);
}

$args = array(
'headers' => array(
'Content-Type' => 'application/json',
),
'body' => wp_json_encode( $payload ),
);

wp_remote_post( self::$track_url, $args );
} finally {
return;
}
}

/**
* Check if the user has consented to tracking.
*
* @return bool
*/
public static function has_consent() {
return (bool) get_option( 'otter_blocks_logger_flag', false );
}
}
5 changes: 3 additions & 2 deletions inc/class-blocks-animation.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function frontend_load( $block_content, $block ) {

wp_script_add_data( 'otter-animation-frontend', 'async', true );

add_action( 'wp_head', array( $this, 'add_fontend_anim_inline_style' ), 10 );
add_action( 'wp_footer', array( $this, 'add_frontend_anim_inline_style' ), 10 );

self::$scripts_loaded['animation'] = true;
}
Expand Down Expand Up @@ -208,10 +208,11 @@ public function frontend_load( $block_content, $block ) {
* @access public
* @since 2.0.14
*/
public static function add_fontend_anim_inline_style() {
public static function add_frontend_anim_inline_style() {
echo '<style id="o-anim-hide-inline-css"> .animated:not(.o-anim-ready) {
visibility: hidden;
animation-play-state: paused;
animation: none !important;
}</style>
<noscript><style>.animated { visibility: visible; animation-play-state: running; }</style></noscript>';
}
Expand Down
2 changes: 1 addition & 1 deletion inc/class-registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function enqueue_block_editor_assets() {
}

global $wp_roles;

wp_localize_script(
'otter-blocks',
'themeisleGutenberg',
Expand Down
77 changes: 77 additions & 0 deletions inc/css/blocks/class-posts-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,83 @@ public function render_css( $block ) {
'property' => '--content-gap',
'value' => 'contentGap',
),
array(
'property' => '--pag-gap',
'value' => 'pagGap',
),
array(
'property' => '--pag-color',
'value' => 'pagColor',
),
array(
'property' => '--pag-bg-color',
'value' => 'pagBgColor',
),
array(
'property' => '--pag-color-hover',
'value' => 'pagColorHover',
),
array(
'property' => '--pag-bg-color-hover',
'value' => 'pagBgColorHover',
),
array(
'property' => '--pag-color-active',
'value' => 'pagColorActive',
),
array(
'property' => '--pag-bg-color-active',
'value' => 'pagBgColorActive',
),
array(
'property' => '--pag-border-color',
'value' => 'pagBorderColor',
),
array(
'property' => '--pag-border-color-hover',
'value' => 'pagBorderColorHover',
),
array(
'property' => '--pag-border-color-active',
'value' => 'pagBorderColorActive',
),
array(
'property' => '--pag-size',
'value' => 'pagSize',
),
array(
'property' => '--pag-border-radius',
'value' => 'pagBorderRadius',
'format' => function( $value, $attrs ) {
return CSS_Utility::box_values( $value );
},
),
array(
'property' => '--pag-border-width',
'value' => 'pagBorderWidth',
'format' => function( $value, $attrs ) {
return CSS_Utility::box_values( $value );
},
),
array(
'property' => '--pag-padding',
'value' => 'pagPadding',
'format' => function( $value, $attrs ) {
return CSS_Utility::box_values( $value );
},
),
array(
'property' => '--pag-cont-margin',
'value' => 'pagContMargin',
'format' => function( $value, $attrs ) {
return CSS_Utility::box_values(
$value,
array(
'top' => '10px',
)
);
},
),
),
)
);
Expand Down
2 changes: 1 addition & 1 deletion inc/css/class-css-utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public static function merge_views( ...$views ) {
$views,
function( $view ) {
return isset( $view ) && is_array( $view );
}
}
);

foreach ( $valid as $arr ) {
Expand Down
67 changes: 64 additions & 3 deletions inc/plugins/class-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public function register_menu_page() {

add_action( "admin_print_scripts-$page_hook_suffix", array( $this, 'enqueue_options_assets' ) );

/**
* Add shortcut to the Blocks tab in Dashboard.
*/


add_submenu_page(
'otter',
__( 'Settings', 'otter-blocks' ),
Expand All @@ -72,6 +77,18 @@ public function register_menu_page() {
array( $this, 'form_submissions_callback' ),
10
);

add_submenu_page(
'otter',
__( 'Blocks', 'otter-blocks' ),
__( 'Blocks', 'otter-blocks' ),
'manage_options',
'otter-blocks-toggle',
function() {
echo '<p>Redirecting...</p>
<script>document.location.href = "/wp-admin/admin.php?page=otter#blocks";</script>';
}
);
}

/**
Expand Down Expand Up @@ -255,27 +272,71 @@ private function the_otter_banner() {
flex-wrap: wrap;
align-content: center;
width: 100%;
margin-left: 10px
margin-left: 10px;
align-items: center;
}

.otter-banner__version {
align-self: center;
font-size: 11px;
}

/* Hide the "Add New" button for Multisite WP. Second part is for Elementor */
a.page-title-action:first-of-type, #e-admin-top-bar-root:not(.e-admin-top-bar--active)~#wpbody .wrap a.page-title-action:first-of-type {
display: none;
}

#export-submissions {
font-size: 14px;
max-height: 35px;
}
</style>
<div class="otter-banner">
<div class="otter-banner__image">
<img src="<?php echo esc_url( OTTER_BLOCKS_URL . 'assets/images/logo-alt.png' ); ?>" alt="<?php esc_attr_e( 'Otter Blocks', 'otter-blocks' ); ?>" style="width: 90px">
</div>
<div class="otter-banner__content">
<h1 class="otter-banner__title" style="line-height: normal;"><?php esc_html_e( 'Form Submissions', 'otter-blocks' ); ?></h1>
<span class="otter-banner__version"><?php echo esc_html( 'v' . OTTER_BLOCKS_VERSION ); ?></span>
<h1 class="otter-banner__title" style="line-height: normal;"><?php esc_html_e( 'Form Submissions', 'otter-blocks' ); ?>
<sub class="otter-banner__version"><?php echo esc_html( 'v' . OTTER_BLOCKS_VERSION ); ?></sub>
</h1>
<button id="export-submissions" class="button">
<?php esc_html_e( 'Export', 'otter-blocks' ); ?>
</button>
</div>
</div>
<script>
window.document.addEventListener('DOMContentLoaded', () => {
document.querySelector('#export-submissions')?.addEventListener('click', () => {
fetch('<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
action: 'otter_form_submissions',
_nonce: '<?php echo esc_attr( wp_create_nonce( 'otter_form_export_submissions' ) ); ?>'
})
})
.then(response => response.text())
.then(response => {
const currentDate = new Date();
const year = currentDate.getFullYear();
const month = String(currentDate.getMonth() + 1).padStart(2, '0');
const day = String(currentDate.getDate()).padStart(2, '0');

const blob = new Blob([response], {type: 'text/xml'});
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `otter_form_submissions__${year}-${month}-${day}.xml`;
document.body.appendChild(a);
a.click();
})
.catch(error => console.error('Error:', error));
});

})
</script>
<?php
}

Expand Down
21 changes: 21 additions & 0 deletions inc/plugins/class-options-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,27 @@ function ( $item ) {
'default' => array(),
)
);

register_setting(
'themeisle_blocks_settings',
'themeisle_disabled_blocks',
array(
'type' => 'array',
'description' => __( 'The disabled blocks that will no longer be shown in Inserter.', 'otter-blocks' ),
'sanitize_callback' => function( $array ) {
return array_map( 'sanitize_text_field', $array );
},
'default' => array(),
'show_in_rest' => array(
'schema' => array(
'type' => 'array',
'items' => array(
'type' => 'string',
),
),
),
)
);
}

/**
Expand Down
Loading

0 comments on commit 0e35561

Please sign in to comment.