%s', esc_url( $settings_url ), esc_html( $settings_label ) ); } return apply_filters( 'ipscmi_order_cart_corekit_plugin_action_links', $links, (bool) $is_premium, $plugin_slug ); } /** * Locate the templates and return the path of the file found * * @param string $plugin_basename The plugin base name. * @param string $path The path. * @param array $var Variable to make visible to the template. * * @return string * @since 1.0.0 */ function ipscmi_order_cart_corekit_plugin_locate_template( $plugin_basename, $path, $var = null ) { $template_path = '/theme/templates/' . $path; $located = locate_template( array( $template_path ) ); if ( ! $located ) { $located = $plugin_basename . '/templates/' . $path; } return $located; } /** * Retrieve a template file. * * @param string $plugin_basename The plugin basename. * @param string $path The path. * @param mixed $var Variable that will be extracted to make its items visible to the template. * @param bool $return return or print the template. * * @return string * @since 1.0.0 */ function ipscmi_order_cart_corekit_plugin_get_template( $plugin_basename, $path, $var = null, $return = false ) { $located = ipscmi_order_cart_corekit_plugin_locate_template( $plugin_basename, $path, $var ); if ( $var && is_array( $var ) ) { extract( $var ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract } if ( $return ) { ob_start(); } if ( file_exists( $located ) ) { include $located; } if ( $return ) { return ob_get_clean(); } } /** * Get the default SVG logo * * @return string default logo image url */ function ipscmi_order_cart_corekit_plugin_fw_get_default_logo() { return IPSCMI_ORDER_CART_COREKIT_PLUGIN_URL . '/assets/images/ips-icon.svg'; } /** * Retrieve a field. * * @param array $field The field. * @param false $echo Set to true to print the field directly; false otherwise. * @param bool $show_container Set to true to show the container; false otherwise. * * @return false|string */ function ipscmi_order_cart_corekit_plugin_fw_get_field( $field, $echo = false, $show_container = true ) { if ( empty( $field['type'] ) ) { return ''; } if ( ! isset( $field['value'] ) ) { $field['value'] = ''; } if ( ! isset( $field['name'] ) ) { $field['name'] = ''; } if ( ! isset( $field['custom_attributes'] ) ) { $field['custom_attributes'] = array(); } if ( is_array( $field['custom_attributes'] ) ) { /** * Convert custom_attributes to string to prevent issues in plugins using them as string in their templates. * todo: remove after checking plugins using custom_attributes as "string" in custom fields templates and as "array" in custom fields options. */ $field['custom_attributes'] = ipscmi_order_cart_corekit_plugin_fw_html_attributes_to_string( $field['custom_attributes'] ); } if ( ! isset( $field['default'] ) && isset( $field['std'] ) ) { $field['default'] = $field['std']; } $field_template = ipscmi_order_cart_corekit_plugin_fw_get_field_template_path( $field ); if ( ! isset( $field['id'] ) ) { static $field_number = 1; $field['id'] = "ipscmi-corekit-field__{$field_number}"; $field_number++; } if ( $field_template ) { if ( ! $echo ) { ob_start(); } if ( $show_container ) { echo '
'; } do_action( 'ipscmi_order_cart_corekit_get_field_before', $field ); do_action( 'ipscmi_order_cart_corekit_get_field_' . $field['type'] . '_before', $field ); include $field_template; do_action( 'ipscmi_order_cart_corekit_get_field_after', $field ); do_action( 'ipscmi_order_cart_corekit_get_field_' . $field['type'] . '_after', $field ); if ( $show_container ) { echo '
'; } if ( ! $echo ) { return ob_get_clean(); } } return ''; } /** * Transform attributes array to HTML attributes string. * If using a string, the attributes will be escaped. * Prefer using arrays. * * @param array|string $attributes The attributes. * @param bool $echo Set to true to print it directly; false otherwise. * * @return string * @since 3.7.0 * @since 3.8.0 Escaping attributes when using strings; allow value-less attributes by setting value to null. */ function ipscmi_order_cart_corekit_plugin_fw_html_attributes_to_string( $attributes = array(), $echo = false ) { if ( is_string( $attributes ) ) { $parsed_attrs = wp_kses_hair( $attributes, wp_allowed_protocols() ); $attributes = array(); foreach ( $parsed_attrs as $attr ) { if ( ! isset( $attr['name'] ) || ! is_string( $attr['name'] ) ) { continue; } $attributes[ $attr['name'] ] = 'n' === $attr['vless'] ? $attr['value'] : null; } } if ( ! is_array( $attributes ) ) { return ''; } $allowed_attributes = array( 'accept', 'accesskey', 'action', 'alt', 'autocomplete', 'autofocus', 'checked', 'class', 'cols', 'colspan', 'contenteditable', 'datetime', 'dir', 'disabled', 'download', 'draggable', 'enctype', 'for', 'form', 'formaction', 'formmethod', 'height', 'hidden', 'href', 'hreflang', 'id', 'inputmode', 'label', 'lang', 'list', 'max', 'maxlength', 'method', 'min', 'minlength', 'multiple', 'name', 'open', 'pattern', 'placeholder', 'poster', 'readonly', 'rel', 'required', 'role', 'rows', 'rowspan', 'selected', 'size', 'spellcheck', 'src', 'start', 'step', 'style', 'tabindex', 'target', 'title', 'translate', 'type', 'value', 'width', 'wrap', ); $boolean_attributes = array( 'autofocus', 'checked', 'disabled', 'hidden', 'multiple', 'open', 'readonly', 'required', 'selected', ); $url_attributes = array( 'action', 'formaction', 'href', 'poster', 'src', ); $html_attributes = array(); $printed = false; foreach ( $attributes as $key => $value ) { if ( ! is_scalar( $key ) ) { continue; } $key = strtolower( trim( (string) $key ) ); if ( 1 !== preg_match( '/^[a-z][a-z0-9_.:-]*$/', $key ) || 0 === strpos( $key, 'on' ) ) { continue; } $is_extended_attribute = 1 === preg_match( '/^(?:aria|data)-[a-z0-9][a-z0-9_.:-]*$/', $key ); if ( ! $is_extended_attribute && ! in_array( $key, $allowed_attributes, true ) ) { continue; } if ( is_bool( $value ) ) { if ( ! $value || ! in_array( $key, $boolean_attributes, true ) ) { continue; } $value = null; } if ( is_null( $value ) ) { if ( ! in_array( $key, $boolean_attributes, true ) ) { continue; } $html_attributes[] = esc_attr( $key ); if ( $echo ) { if ( $printed ) { echo ' '; } echo esc_attr( $key ); $printed = true; } continue; } if ( ! is_scalar( $value ) ) { continue; } $value = (string) $value; if ( in_array( $key, $url_attributes, true ) ) { $escaped_value = esc_url( $value ); if ( '' === $escaped_value && '' !== $value ) { continue; } } elseif ( 'style' === $key ) { if ( ! function_exists( 'safecss_filter_attr' ) ) { continue; } $value = (string) safecss_filter_attr( $value ); if ( '' === $value ) { continue; } $escaped_value = esc_attr( $value ); } else { $escaped_value = esc_attr( $value ); } $html_attributes[] = esc_attr( $key ) . '="' . $escaped_value . '"'; if ( $echo ) { if ( $printed ) { echo ' '; } echo esc_attr( $key ); echo '="'; if ( in_array( $key, $url_attributes, true ) ) { echo esc_url( $value ); } elseif ( 'style' === $key ) { echo esc_attr( $value ); } else { echo esc_attr( $value ); } echo '"'; $printed = true; } } return implode( ' ', $html_attributes ); } /** * Retrieve the field template path. * * @param array $field The field. * * @return false|string */ function ipscmi_order_cart_corekit_plugin_fw_get_field_template_path( $field ) { if ( empty( $field['type'] ) ) { return false; } $field_template = IPSCMI_ORDER_CART_COREKIT_PLUGIN_TEMPLATE_PATH . '/fields/' . sanitize_title( $field['type'] ) . '.php'; $field_template = apply_filters( 'ipscmi_order_cart_corekit_get_field_template_path', $field_template, $field ); return file_exists( $field_template ) ? $field_template : false; } /** * Transform data array to HTML data. * * @param array $data The array of data. * @param false $echo Set to true to print it directly; false otherwise. * * @return string */ function ipscmi_order_cart_corekit_plugin_fw_html_data_to_string( $data = array(), $echo = false ) { if ( ! is_array( $data ) ) { return ''; } $attributes = array(); foreach ( $data as $key => $value ) { if ( ! is_scalar( $key ) ) { continue; } if ( is_array( $value ) ) { $values = array(); foreach ( $value as $item ) { if ( is_scalar( $item ) ) { $values[] = (string) $item; } } $value = implode( ',', $values ); } if ( ! is_scalar( $value ) ) { continue; } $attributes[ 'data-' . (string) $key ] = (string) $value; } $html_data = ipscmi_order_cart_corekit_plugin_fw_html_attributes_to_string( $attributes ); if ( '' === $html_data ) { return ''; } if ( $echo ) { echo ' '; ipscmi_order_cart_corekit_plugin_fw_html_attributes_to_string( $attributes, true ); echo ' '; } return ' ' . $html_data . ' '; } /** * Enqueue the enhanced select style and script. */ function ipscmi_order_cart_corekit_plugin_fw_enqueue_enhanced_select() { if ( wp_script_is( 'ipscmi-corekit-enhanced-select', 'registered' ) ) { wp_enqueue_script( 'ipscmi-corekit-enhanced-select' ); } $select2_style_to_enqueue = 'woocommerce_admin_styles'; if ( ! function_exists( 'WC' ) ) { $select2_style_to_enqueue = 'ipscmi-corekit-select2-no-wc'; } if ( wp_style_is( $select2_style_to_enqueue, 'registered' ) ) { wp_enqueue_style( $select2_style_to_enqueue ); } } /** * Retrieve the Plugin Framework version. * * @return string */ function ipscmi_order_cart_corekit_plugin_fw_get_version() { $plugin_fw_data = get_file_data( trailingslashit( IPSCMI_ORDER_CART_COREKIT_PLUGIN_PATH ) . 'init.php', array( 'Version' => 'Version' ) ); return $plugin_fw_data['Version']; } /** * Is something true? * * @param string|bool|int $value The value to check for. * * @return bool */ function ipscmi_order_cart_corekit_plugin_fw_is_true( $value ) { return true === $value || 1 === $value || '1' === $value || 'yes' === $value || 'true' === $value; } /** * Is this a Plugin Framework panel? * * @return bool */ function ipscmi_order_cart_corekit_plugin_fw_is_panel() { $panel_screen_id = 'ipscmi-corekit-plugins_page'; $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; return $screen instanceof WP_Screen && strpos( $screen->id, $panel_screen_id ) !== false; } /** * Add new blocks to Gutenberg * * @param string|array $blocks Blocks to add. * * @return bool true if add a new blocks, false otherwise */ function ipscmi_order_cart_corekit_fw_gutenberg_add_blocks( $blocks ) { $added = false; if ( ipscmi_order_cart_corekit_fw_is_gutenberg_enabled() ) { // Add blocks. $added = IPS_Gutenberg()->add_blocks( $blocks ); } return $added; } /** * Is Gutenberg enabled? * * @return bool */ function ipscmi_order_cart_corekit_fw_is_gutenberg_enabled() { return function_exists( 'IPS_Gutenberg' ); } /** * Retrieve a component. * * @param array $component The component. * @param bool $echo Set to true to print the component directly; false otherwise. * * @return false|string * @since 3.7.0 */ function ipscmi_order_cart_corekit_plugin_fw_get_component( $component, $echo = true ) { if ( ! empty( $component['type'] ) ) { $type = sanitize_title( $component['type'] ); $defaults = array( 'id' => '', 'class' => '', 'attributes' => array(), 'data' => array(), ); $component = wp_parse_args( $component, $defaults ); $component_template = '/components/' . $type . '.php'; if ( ! $echo ) { ob_start(); } ipscmi_order_cart_corekit_plugin_fw_include_fw_template( $component_template, compact( 'component' ) ); if ( ! $echo ) { return ob_get_clean(); } } return ''; } /** * Include a FW template * * @param string $template The template. * @param array $args Arguments. * * @since 3.7.0 */ function ipscmi_order_cart_corekit_plugin_fw_include_fw_template( $template, $args = array() ) { $_template_path = trailingslashit( IPSCMI_ORDER_CART_COREKIT_PLUGIN_TEMPLATE_PATH ) . $template; if ( file_exists( $_template_path ) ) { extract( $args ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract include $_template_path; } } /** * Retrieve the field deps HTML data. * * @param array $field The field. * * @return string */ function ipscmi_order_cart_corekit_field_deps_data( $field ) { $deps_data = ''; if ( isset( $field['deps'] ) && ( isset( $field['deps']['ids'] ) || isset( $field['deps']['id'] ) ) && ( isset( $field['deps']['values'] ) || isset( $field['deps']['value'] ) ) ) { $deps = $field['deps']; $id = isset( $deps['target-id'] ) ? $deps['target-id'] : $field['id']; $dep_id = isset( $deps['id'] ) ? $deps['id'] : $deps['ids']; $dep_values = isset( $deps['value'] ) ? $deps['value'] : $deps['values']; $dep_type = isset( $deps['type'] ) ? $deps['type'] : 'fadeIn'; $deps_data = 'data-dep-target="' . esc_attr( $id ) . '" data-dep-id="' . esc_attr( $dep_id ) . '" data-dep-value="' . esc_attr( $dep_values ) . '" data-dep-type="' . esc_attr( $dep_type ) . '"'; } return $deps_data; } /** * Extract array variables * Usage example: * ``` * list ( $type, $class, $value ) = ipscmi_order_cart_corekit_plugin_fw_extract( $field, 'type', 'class', 'value' ); * ``` * * @param array $array The array. * @param string ...$keys The keys. * * @return array * @since 3.5 */ function ipscmi_order_cart_corekit_plugin_fw_extract( $array, ...$keys ) { return array_map( function ( $key ) use ( $array ) { return isset( $array[ $key ] ) ? $array[ $key ] : null; }, $keys ); } /** * Add select 2. * * @param array $args The arguments. */ function ipscmi_order_cart_corekit_add_select2_fields( $args = array() ) { $default = array( 'type' => 'hidden', 'class' => '', 'id' => '', 'name' => '', 'data-placeholder' => '', 'data-allow_clear' => false, 'data-selected' => '', 'data-multiple' => false, 'data-action' => '', 'value' => '', 'style' => '', 'custom-attributes' => array(), ); $args = wp_parse_args( $args, $default ); $custom_attributes = ipscmi_order_cart_corekit_plugin_fw_html_attributes_to_string( $args['custom-attributes'] ); if ( ! function_exists( 'WC' ) || version_compare( WC()->version, '2.7.0', '>=' ) ) { if ( true === $args['data-multiple'] && substr( $args['name'], - 2 ) !== '[]' ) { $args['name'] = $args['name'] . '[]'; } $select2_template_name = 'select2.php'; } else { if ( false === $args['data-multiple'] && is_array( $args['data-selected'] ) ) { $args['data-selected'] = current( $args['data-selected'] ); } $select2_template_name = 'select2-wc-2.6.php'; // ALters WooCommerce 2.6.x select2 template to work with IPS CoreKit. } $template = IPSCMI_ORDER_CART_COREKIT_PLUGIN_TEMPLATE_PATH . '/fields/resources/' . $select2_template_name; if ( file_exists( $template ) ) { include $template; } } /** * Retrieve action buttons. * * @param array $actions The actions. * @param bool $echo Set to true to print the field directly; false otherwise. * * @return string * @since 3.7.0 */ function ipscmi_order_cart_corekit_plugin_fw_get_action_buttons( $actions, $echo = true ) { $actions_html = ''; foreach ( $actions as $action ) { $action['type'] = 'action-button'; $actions_html .= ipscmi_order_cart_corekit_plugin_fw_get_component( $action, $echo ); } return $actions_html; } /** * Get id of post translation in current language * * @param int $element_id The element ID. * @param string $element_type The element type. * @param bool $return_original_if_missing Return original if missing or not. * @param null|string $language_code The language code. * * @return int the translation id * @since 1.0.0 */ function ipscmi_order_cart_corekit_plugin_object_id( $element_id, $element_type = 'post', $return_original_if_missing = false, $language_code = null ) { if ( function_exists( 'wpml_object_id_filter' ) ) { return wpml_object_id_filter( $element_id, $element_type, $return_original_if_missing, $language_code ); } elseif ( function_exists( 'icl_object_id' ) ) { return icl_object_id( $element_id, $element_type, $return_original_if_missing, $language_code ); } else { return $element_id; } } /** * Return the wrapper class for the UI style, by setting any additional class passed through the $class parameter. * * @param array|string $class List of additional classes to add to the UI style class. * * @return string */ function ipscmi_order_cart_corekit_set_wrapper_class( $class = '' ) { $new_class = ipscmi_order_cart_corekit_get_wrapper_class(); $class = ( ! empty( $class ) && is_array( $class ) ) ? implode( ' ', $class ) : $class; return $new_class . ' ' . $class; } /** * Return the wrapper class for the UI style. * * @return string * @since 1.0.0 */ function ipscmi_order_cart_corekit_get_wrapper_class() { return 'ipscmi-corekit-ui'; }