Skip to content

Commit

Permalink
release: fixes
Browse files Browse the repository at this point in the history
- Fixed PHP fatal error that was occurring when editing imported group of fields
- Fixed PHP warnings on the changelog page
- Fixed console error that was blocking the editing/updating of the image in the popup
- Fixed conditional loading
- Fixed repeater field issue with multiple groups
- Implemented a user satisfaction survey
  • Loading branch information
vytisbulkevicius authored Aug 13, 2024
2 parents 6138c8f + 6c69240 commit 8de828e
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 86 deletions.
4 changes: 2 additions & 2 deletions backend/changelog_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ private function parse_changelog( $changelog_path ) {
preg_match( '/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $changelog_line, $found_v );
preg_match( '/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}/', $changelog_line, $found_d );
$releases[ $release_count ] = array(
'version' => $found_v[0],
'date' => $found_d[0],
'version' => ! empty( $found_v ) ? $found_v[0] : '',
'date' => ! empty( $found_d ) ? $found_d[0] : '',
);
continue;
}
Expand Down
13 changes: 12 additions & 1 deletion classes/admin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function add_menu_pages() {
if ( ! current_user_can( 'administrator' ) ) {
$cap = 'ppom_options_page';
// Menu page for roles set by PPOM Permission Settings
add_menu_page(
$menu = add_menu_page(
__( $page ['page_title'], 'woocommerce-product-addon' ),
__( 'PPOM Fields', 'woocommerce-product-addon' ),
$cap,
Expand All @@ -145,6 +145,8 @@ function add_menu_pages() {
)
);
}

add_action( "load-$menu", array( $this, 'load_admin_menu' ) );
}
}

Expand Down Expand Up @@ -396,5 +398,14 @@ class="select_none button" href="#"><?php esc_html_e( 'Select none', 'woocommerc

}

/**
* Load admin menu page.
*/
public function load_admin_menu() {
// Call survey class.
include_once PPOM_PATH . '/classes/survey.class.php';
PPOM_Survey::get_instance()->init();
}


}
10 changes: 5 additions & 5 deletions classes/fields.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ function render_all_input_types( $name, $data, $fields_type, $field_index, $valu
* @since 7.1
*/
case 'bulk-quantity':
$bulk_data = json_decode( $values, true );
$bulk_data = is_string( $values ) ? json_decode( $values, true ) : (array) $values;
// ppom_pa($bulk_data[0]);
$html_input .= '<div class="ppom-bulk-quantity-wrapper">';
$html_input .= '<div class="table-content">';
Expand All @@ -1059,7 +1059,7 @@ function render_all_input_types( $name, $data, $fields_type, $field_index, $valu
$html_input .= '<thead>';
$html_input .= '<tr>';

if ( $values ) {
if ( ! empty( $bulk_data ) ) {
foreach ( $bulk_data[0] as $title => $value ) {
$deleteIcon = ( $title != 'Quantity Range' && $title != 'Base Price' ) ? '<span class="remove ppom-rm-bulk-variation"><i class="fa fa-times" aria-hidden="true"></i></span>' : '';
$html_input .= '<th>' . $title . ' ' . $deleteIcon . '</th>';
Expand All @@ -1073,7 +1073,7 @@ function render_all_input_types( $name, $data, $fields_type, $field_index, $valu
$html_input .= '</thead>';
$html_input .= '<tbody>';

if ( $values ) {
if ( ! empty( $bulk_data ) ) {
foreach ( $bulk_data as $row => $data ) {
$html_input .= '<tr>';
foreach ( $data as $key => $value ) {
Expand Down Expand Up @@ -1109,8 +1109,8 @@ function render_all_input_types( $name, $data, $fields_type, $field_index, $valu
$html_input .= '<button class="btn btn-info ppom-save-bulk-json">'.esc_html__( 'Save Changing', 'woocommerce-product-addon' ).'</button> ';
$html_input .= '<button class="btn btn-success ppom-edit-bulk-json">'.esc_html__( 'Edit Changing', 'woocommerce-product-addon' ).'</button>';

if ( $values ) {
$html_input .= "<input type='hidden' name='ppom[" . esc_attr( $field_index ) . "][options]' class='ppom-saved-bulk-data ppom-meta-field' value='" . json_encode( $bulk_data ) . "' data-metatype='options'>";
if ( ! empty( $bulk_data ) ) {
$html_input .= "<input type='hidden' name='ppom[" . esc_attr( $field_index ) . "][options]' class='ppom-saved-bulk-data ppom-meta-field' value='" . wp_json_encode( $bulk_data ) . "' data-metatype='options'>";
} else {
$html_input .= "<input type='hidden' class='ppom-saved-bulk-data ppom-meta-field' data-metatype='options'>";
}
Expand Down
5 changes: 5 additions & 0 deletions classes/ppom.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ function __construct( $product_id = null ) {
}
}

// Retrieve fields with the repeater enabled.
$is_cloned = is_array( $this->fields ) ? array_filter( array_column( $this->fields, 'is_cloned' ) ) : array();
if ( isset( $this->ppom_settings->productmeta_validation ) && ! empty( $is_cloned ) ) {
$this->ppom_settings->productmeta_validation = 'on';
}
}

public static function get_instance( $product_id ) {
Expand Down
134 changes: 134 additions & 0 deletions classes/survey.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php
/**
* Class PPOM_Survey file.
*
* @package PPOM_Survey
*/

defined( 'ABSPATH' ) || exit;

if ( ! class_exists( 'PPOM_Survey' ) ) {

/**
* PPOM Survey class.
*/
class PPOM_Survey {

/**
* Reference to singleton insance.
*
* @var [PPOM_Survey]
*/
public static $instance = null;

/**
* Init hooks.
*/
public function init() {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
}

/**
* Get instance
*/
public static function get_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}

/**
* Get the data used for the survey.
*
* @return array
* @see survey.js
*/
public function get_survey_metadata() {
$license_data = get_option( 'ppom_pro_license_data', array() );
$attributes = array();
$user_id = 'ppom_' . ( ! empty( $license_data->key ) ? $license_data->key : preg_replace( '/[^\w\d]*/', '', get_site_url() ) ); // Use a normalized version of the site URL as a user ID for free users.

$days_since_install = round( ( time() - get_option( 'woocommerce_product_addon_install', 0 ) ) / DAY_IN_SECONDS );
$install_category = 0; // Normalized value.
if ( 0 === $days_since_install || 1 === $days_since_install ) {
$install_category = 0;
} elseif ( 1 < $days_since_install && 8 > $days_since_install ) {
$install_category = 7;
} elseif ( 8 <= $days_since_install && 31 > $days_since_install ) {
$install_category = 30;
} elseif ( 30 < $days_since_install && 90 > $days_since_install ) {
$install_category = 90;
} elseif ( 90 <= $days_since_install ) {
$install_category = 91;
}

$attributes['days_since_install'] = strval( $install_category );
$attributes['license_status'] = ! empty( $license_data->license ) ? $license_data->license : 'invalid';
$attributes['free_version'] = PPOM_VERSION;

if ( ! empty( $license_data->plan ) ) {
$attributes['plan'] = $this->plan_category( $license_data );
}

if ( defined( 'PPOM_PRO_VERSION' ) ) {
$attributes['pro_version'] = PPOM_PRO_VERSION;
}

return array(
'userId' => $user_id,
'attributes' => $attributes,
);
}

/**
* Enqueue scripts.
*/
public function enqueue_scripts() {

if ( defined( 'CYPRESS_TESTING' ) ) {
return;
}

$survey_handler = apply_filters( 'themeisle_sdk_dependency_script_handler', 'survey' );
if ( empty( $survey_handler ) ) {
return;
}

do_action( 'themeisle_sdk_dependency_enqueue_script', 'survey' );
wp_enqueue_script( 'ppom_survey', PPOM_URL . '/js/survey.js', array( $survey_handler ), PPOM_VERSION, true );
wp_localize_script( 'ppom_survey', 'PPOMSurveyData', $this->get_survey_metadata() );
}

/**
* Get the plan category for the product plan ID.
*
* @param object $license_data The license data.
* @return int
*/
private static function plan_category( $license_data ) {

if ( ! isset( $license_data->plan ) || ! is_numeric( $license_data->plan ) ) {
return 0; // Free.
}

$plan = (int) $license_data->plan;
$current_category = -1;

$categories = array(
'1' => array( 1, 4, 9 ), // Personal.
'2' => array( 2, 5, 8 ), // Business/Developer.
'3' => array( 3, 6, 7, 10 ), // Agency.
);

foreach ( $categories as $category => $plans ) {
if ( in_array( $plan, $plans, true ) ) {
$current_category = (int) $category;
break;
}
}

return $current_category;
}
}
}
Loading

0 comments on commit 8de828e

Please sign in to comment.