--- a/jupiterx-core/includes/admin/attachment-media/class.php
+++ b/jupiterx-core/includes/admin/attachment-media/class.php
@@ -1,353 +1,353 @@
-<?php
-/**
- * Class for attachment media.
- *
- * @package JupiterX_CoreAdmin
- *
- * @since 2.5.0
- */
-
-if ( ! class_exists( 'JupiterX_Core_Attachment_Media' ) ) {
- /**
- * Attachment Media class.
- *
- * @since 2.5.0
- */
- class JupiterX_Core_Attachment_Media {
- /**
- * Video type key.
- *
- * @access private
- * @var array Video type meta.
- */
- const VIDEO_TYPE = 'jupiterx_video_type';
-
- /**
- * Media URL key.
- *
- * @access private
- * @static
- *
- * @var array Media url meta.
- */
- const MEDIA_URL = 'jupiterx_media_url';
-
- /**
- * Embed URL.
- *
- * @access private
- * @var array Media url meta.
- */
- const EMBED_URL = 'jupiterx_embed_url';
-
- /**
- * Aspect ratio.
- *
- * @access private
- * @var array Aspect ratio meta.
- */
- const ASPECT_RATIO = 'jupiterx_aspect_ratio';
-
- /**
- * Construct class.
- *
- * @since 2.5.0
- */
- public function __construct() {
- if ( empty( jupiterx_core_get_option( 'enable_media_controls' ) || ! function_exists( 'WC' ) ) ) {
- return;
- }
-
- add_filter( 'attachment_fields_to_edit', [ $this, 'add_new_video_attachment_fields' ], 10, 2 );
- add_filter( 'attachment_fields_to_save', [ $this, 'save_new_video_attachment_fields' ], 10, 2 );
- }
-
- /**
- * Add fields to the form fields.
- *
- * @param array $form_fields
- * @param object $post
- * @since 2.5.0
- * @return array
- */
- public function add_new_video_attachment_fields( $form_fields, $post ) {
- if ( strpos( $post->post_mime_type, 'image/' ) !== 0 || empty( $this->validate_is_edit_product() ) ) {
- return $form_fields;
- }
-
- $video_types = [
- 'custom' => esc_html__( 'Custom Video (MP4)', 'jupiterx-core' ),
- 'embed' => esc_html__( 'Embed URL', 'jupiterx-core' ),
- ];
-
- $aspect_ratios = [
- '1:1',
- '2:1',
- '3:2',
- '4:3',
- '5:4',
- '5:3',
- '8:5',
- '9:5',
- '9:16',
- '10:7',
- '16:9',
- '20:9',
- '21:9',
- '25:16',
- ];
-
- $video_type_select = $this->render_select( $video_types, $post->ID, self::VIDEO_TYPE, 'custom' );
- $video_aspect_ratio = $this->render_select( $aspect_ratios, $post->ID, self::ASPECT_RATIO, '16:9' );
-
- $form_fields['jupiterx_media_details'] = [
- 'tr' => sprintf( '<h2 class="jupiterx-media-details-title">%s</h2>', esc_html__( 'Jupiterx Media Details', 'jupiterx-core' ) ),
- ];
-
- $form_fields[ self::VIDEO_TYPE ] = [
- 'label' => esc_html__( 'Video Type', 'jupiterx-core' ),
- 'input' => 'html',
- 'html' => $video_type_select,
- ];
-
- $selected_video_type = $this->get_value_on_change( $post->ID, self::VIDEO_TYPE );
-
- $form_fields[ self::MEDIA_URL ] = [
- 'label' => esc_html__( 'Media URL', 'jupiterx-core' ),
- 'input' => 'text',
- 'value' => $this->get_attachment_data( $post->ID, self::MEDIA_URL ),
- ];
-
- $form_fields['jupiterx_attached_video'] = [
- 'tr' => sprintf(
- '<th scope="row" class="label"> </th><td class="field jupiterx-attach-video">
- <span class="setting has-description"><a href="#" class="button-secondary" data-media-id="%1$s">%2$s</a></span>
- <p class="description" style="%3$s">%4$s</p>
- </td>',
- esc_attr( $post->ID ),
- esc_html__( 'Attach MP4', 'jupiterx-core' ),
- esc_attr( 'width: 100%; padding-top: 4px;' ),
- esc_html__( 'Enter an external MP4 URL or click "Attach MP4" to upload your MP4 video into the media library.', 'jupiterx-core' )
- ),
- ];
-
- $form_fields[ self::EMBED_URL ] = [
- 'label' => esc_html__( 'Embed URL', 'jupiterx-core' ),
- 'input' => 'text',
- 'value' => $this->get_attachment_data( $post->ID, self::EMBED_URL ),
- ];
-
- $form_fields['jupiterx_embed_url_text'] = [
- 'label' => '',
- 'input' => 'html',
- 'html' => sprintf(
- '<th scope="row" class="label"> </th><td class="field jupiterx-embed-video">
- <p class="description" style="%1$s">
- %2$s
- <a href="%3$s" target="_blank">%4$s</a>
- </p>
- </td>',
- esc_attr( 'width: 100%; padding-top: 4px;' ),
- esc_html__( 'Enter a valid', 'jupiterx-core' ),
- 'https://wordpress.org/support/article/embeds/#okay-so-what-sites-can-i-embed-from',
- esc_html__( 'media URL', 'jupiterx-core' )
- ),
- ];
-
- $form_fields[ self::ASPECT_RATIO ] = [
- 'label' => esc_html__( 'Aspect ratio', 'jupiterx-core' ),
- 'input' => 'html',
- 'html' => $video_aspect_ratio,
- ];
-
- $form_fields['jupiterx_attached_video'] = [
- 'label' => '',
- 'input' => 'html',
- 'html' => sprintf(
- '<th scope="row" class="label"> </th><td class="field jupiterx-attach-video">
- <span class="setting has-description"><a href="#" class="jupiterx-attach-mp4 button-secondary" data-media-id="%1$s">%2$s</a></span>
- <p class="description" style="%3$s">%4$s</p>
- </td>',
- esc_attr( $post->ID ),
- esc_html__( 'Attach MP4', 'jupiterx-core' ),
- esc_attr( 'width: 100%; padding-top: 4px;' ),
- esc_html__( 'Enter an external MP4 URL or click "Attach MP4" to upload your MP4 video into the media library.', 'jupiterx-core' )
- ),
- ];
-
- $form_fields['jupiterx_media_note'] = [
- 'tr' => sprintf(
- '<td colspan="2" style="display: block; padding-top: 8px;">
- <p class="description">
- <strong>%1$s: </strong>
- %2$s
- <a href="%3$s" target="_blank">%4$s</a></p>
- </td>',
- esc_html__( 'Note', 'jupiterx-core' ),
- esc_html__( 'To access Product Gallery video settings', 'jupiterx-core' ),
- esc_url( admin_url( 'admin.php?page=jupiterx#/settings#woocommerce' ) ),
- esc_html__( 'click here', 'jupiterx-core' )
- ),
- ];
-
- if ( 'embed' === $selected_video_type ) {
- unset( $form_fields[ self::MEDIA_URL ] );
- unset( $form_fields['jupiterx_attached_video'] );
- }
-
- if ( 'custom' === $selected_video_type ) {
- unset( $form_fields[ self::EMBED_URL ] );
- unset( $form_fields['jupiterx_embed_url_text'] );
- }
-
- return $form_fields;
- }
-
- /**
- * This method will render select option html code.
- *
- * @param array $options
- * @param int $id
- * @param string $type
- * @param string $default
- * @since 2.5.0
- * @return string
- */
- private function render_select( $options, $id, $type, $default ) {
- if ( empty( $options ) || empty( $id ) || empty( $type ) ) {
- return;
- }
-
- $options_html = '';
- $default = ! empty( $this->get_attachment_data( $id, $type ) ) ? $this->get_attachment_data( $id, $type ) : $default;
-
- foreach ( $options as $key => $option ) {
- $value = $key;
-
- if ( self::ASPECT_RATIO === $type ) {
- $value = $option;
- }
-
- $options_html .= sprintf(
- '<option value="%1$s" %2$s>%3$s</option>',
- $value,
- selected( $default, $value, false ),
- $option
- );
- }
-
- $video_type_select = sprintf(
- '<select class="jupiterx-attachment-form-select %1$s" name="attachments[%2$s][%3$s]">%4$s</select>',
- str_replace( '_', '-', $type ) . '-select',
- $id,
- $type,
- $options_html
- );
-
- return $video_type_select;
- }
-
- /**
- * Save form fields.
- *
- * @param array $post
- * @param array $attachment
- * @since 2.5.0
- * @return array
- */
- public function save_new_video_attachment_fields( $post, $attachment ) {
- $meta = [];
-
- foreach ( $attachment as $key => $value ) {
- if ( ! str_starts_with( $key, 'jupiterx_' ) ) {
- continue;
- }
-
- $meta[ $key ] = sanitize_text_field( $value );
- }
-
- update_post_meta( $post['ID'], '_jupiterx_attachment_meta', $meta );
-
- return $post;
- }
-
- /**
- * Get meta data.
- *
- * @param integer $id
- * @param string $key
- * @since 2.5.0
- * @return mixed Value set for the option.
- */
- private function get_attachment_data( $id, $key, $default = false ) {
- $options = get_post_meta( $id, '_jupiterx_attachment_meta', true );
-
- if ( ! isset( $options[ $key ] ) ) {
- return $default;
- }
-
- if ( 'jupiterx_embed_url' === $key && empty( wp_oembed_get( $options[ $key ] ) ) ) {
- $options[ $key ] = null;
- }
-
- return $options[ $key ];
- }
-
- /**
- * Get changed meta field.
- *
- * @param integer $id
- * @param string $meta
- * @since 2.5.0
- * @return string
- */
- private function get_value_on_change( $id, $meta ) {
- $default = $this->get_attachment_data( $id, $meta );
-
- if ( empty( $default ) ) {
- $default = 'custom';
- }
-
- if ( empty( $_POST['attachments'][ $id ][ $meta ] ) ) { // phpcs:ignore
- return $default;
- }
-
- return htmlspecialchars( $_POST['attachments'][ $id ][ $meta ] ); // phpcs:ignore
- }
-
- /**
- * Check is product edit page.
- *
- * @since 2.5.0
- * @return boolean|null
- */
- private function validate_is_edit_product() {
- $post_id = ! empty( $_POST['post_id'] ) ? htmlspecialchars( $_POST['post_id'] ) : null; // phpcs:ignore.
-
- if ( empty( $post_id ) ) {
- $params = [];
-
- $url = ! empty( $_SERVER['HTTP_REFERER'] ) ? htmlspecialchars( $_SERVER['HTTP_REFERER'] ) : null; // phpcs:ignore.
- $url_params = wp_parse_url( $url );
-
- if ( empty( $url_params['query'] ) ) {
- return;
- }
-
- wp_parse_str( $url_params['query'], $params );
-
- $post_id = ! empty( $params['post'] ) ? htmlspecialchars( $params['post'] ) : null; // phpcs:ignore.
- }
-
- $post_type = get_post_type( $post_id );
-
- if ( ! in_array( $post_type, [ 'product', 'product_variation' ], true ) || empty( $post_id ) ) {
- return;
- }
-
- return true;
- }
- }
-}
-
-new JupiterX_Core_Attachment_Media();
+<?php
+/**
+ * Class for attachment media.
+ *
+ * @package JupiterX_CoreAdmin
+ *
+ * @since 2.5.0
+ */
+
+if ( ! class_exists( 'JupiterX_Core_Attachment_Media' ) ) {
+ /**
+ * Attachment Media class.
+ *
+ * @since 2.5.0
+ */
+ class JupiterX_Core_Attachment_Media {
+ /**
+ * Video type key.
+ *
+ * @access private
+ * @var array Video type meta.
+ */
+ const VIDEO_TYPE = 'jupiterx_video_type';
+
+ /**
+ * Media URL key.
+ *
+ * @access private
+ * @static
+ *
+ * @var array Media url meta.
+ */
+ const MEDIA_URL = 'jupiterx_media_url';
+
+ /**
+ * Embed URL.
+ *
+ * @access private
+ * @var array Media url meta.
+ */
+ const EMBED_URL = 'jupiterx_embed_url';
+
+ /**
+ * Aspect ratio.
+ *
+ * @access private
+ * @var array Aspect ratio meta.
+ */
+ const ASPECT_RATIO = 'jupiterx_aspect_ratio';
+
+ /**
+ * Construct class.
+ *
+ * @since 2.5.0
+ */
+ public function __construct() {
+ if ( empty( jupiterx_core_get_option( 'enable_media_controls' ) || ! function_exists( 'WC' ) ) ) {
+ return;
+ }
+
+ add_filter( 'attachment_fields_to_edit', [ $this, 'add_new_video_attachment_fields' ], 10, 2 );
+ add_filter( 'attachment_fields_to_save', [ $this, 'save_new_video_attachment_fields' ], 10, 2 );
+ }
+
+ /**
+ * Add fields to the form fields.
+ *
+ * @param array $form_fields
+ * @param object $post
+ * @since 2.5.0
+ * @return array
+ */
+ public function add_new_video_attachment_fields( $form_fields, $post ) {
+ if ( strpos( $post->post_mime_type, 'image/' ) !== 0 || empty( $this->validate_is_edit_product() ) ) {
+ return $form_fields;
+ }
+
+ $video_types = [
+ 'custom' => esc_html__( 'Custom Video (MP4)', 'jupiterx-core' ),
+ 'embed' => esc_html__( 'Embed URL', 'jupiterx-core' ),
+ ];
+
+ $aspect_ratios = [
+ '1:1',
+ '2:1',
+ '3:2',
+ '4:3',
+ '5:4',
+ '5:3',
+ '8:5',
+ '9:5',
+ '9:16',
+ '10:7',
+ '16:9',
+ '20:9',
+ '21:9',
+ '25:16',
+ ];
+
+ $video_type_select = $this->render_select( $video_types, $post->ID, self::VIDEO_TYPE, 'custom' );
+ $video_aspect_ratio = $this->render_select( $aspect_ratios, $post->ID, self::ASPECT_RATIO, '16:9' );
+
+ $form_fields['jupiterx_media_details'] = [
+ 'tr' => sprintf( '<h2 class="jupiterx-media-details-title">%s</h2>', esc_html__( 'Jupiterx Media Details', 'jupiterx-core' ) ),
+ ];
+
+ $form_fields[ self::VIDEO_TYPE ] = [
+ 'label' => esc_html__( 'Video Type', 'jupiterx-core' ),
+ 'input' => 'html',
+ 'html' => $video_type_select,
+ ];
+
+ $selected_video_type = $this->get_value_on_change( $post->ID, self::VIDEO_TYPE );
+
+ $form_fields[ self::MEDIA_URL ] = [
+ 'label' => esc_html__( 'Media URL', 'jupiterx-core' ),
+ 'input' => 'text',
+ 'value' => $this->get_attachment_data( $post->ID, self::MEDIA_URL ),
+ ];
+
+ $form_fields['jupiterx_attached_video'] = [
+ 'tr' => sprintf(
+ '<th scope="row" class="label"> </th><td class="field jupiterx-attach-video">
+ <span class="setting has-description"><a href="#" class="button-secondary" data-media-id="%1$s">%2$s</a></span>
+ <p class="description" style="%3$s">%4$s</p>
+ </td>',
+ esc_attr( $post->ID ),
+ esc_html__( 'Attach MP4', 'jupiterx-core' ),
+ esc_attr( 'width: 100%; padding-top: 4px;' ),
+ esc_html__( 'Enter an external MP4 URL or click "Attach MP4" to upload your MP4 video into the media library.', 'jupiterx-core' )
+ ),
+ ];
+
+ $form_fields[ self::EMBED_URL ] = [
+ 'label' => esc_html__( 'Embed URL', 'jupiterx-core' ),
+ 'input' => 'text',
+ 'value' => $this->get_attachment_data( $post->ID, self::EMBED_URL ),
+ ];
+
+ $form_fields['jupiterx_embed_url_text'] = [
+ 'label' => '',
+ 'input' => 'html',
+ 'html' => sprintf(
+ '<th scope="row" class="label"> </th><td class="field jupiterx-embed-video">
+ <p class="description" style="%1$s">
+ %2$s
+ <a href="%3$s" target="_blank">%4$s</a>
+ </p>
+ </td>',
+ esc_attr( 'width: 100%; padding-top: 4px;' ),
+ esc_html__( 'Enter a valid', 'jupiterx-core' ),
+ 'https://wordpress.org/support/article/embeds/#okay-so-what-sites-can-i-embed-from',
+ esc_html__( 'media URL', 'jupiterx-core' )
+ ),
+ ];
+
+ $form_fields[ self::ASPECT_RATIO ] = [
+ 'label' => esc_html__( 'Aspect ratio', 'jupiterx-core' ),
+ 'input' => 'html',
+ 'html' => $video_aspect_ratio,
+ ];
+
+ $form_fields['jupiterx_attached_video'] = [
+ 'label' => '',
+ 'input' => 'html',
+ 'html' => sprintf(
+ '<th scope="row" class="label"> </th><td class="field jupiterx-attach-video">
+ <span class="setting has-description"><a href="#" class="jupiterx-attach-mp4 button-secondary" data-media-id="%1$s">%2$s</a></span>
+ <p class="description" style="%3$s">%4$s</p>
+ </td>',
+ esc_attr( $post->ID ),
+ esc_html__( 'Attach MP4', 'jupiterx-core' ),
+ esc_attr( 'width: 100%; padding-top: 4px;' ),
+ esc_html__( 'Enter an external MP4 URL or click "Attach MP4" to upload your MP4 video into the media library.', 'jupiterx-core' )
+ ),
+ ];
+
+ $form_fields['jupiterx_media_note'] = [
+ 'tr' => sprintf(
+ '<td colspan="2" style="display: block; padding-top: 8px;">
+ <p class="description">
+ <strong>%1$s: </strong>
+ %2$s
+ <a href="%3$s" target="_blank">%4$s</a></p>
+ </td>',
+ esc_html__( 'Note', 'jupiterx-core' ),
+ esc_html__( 'To access Product Gallery video settings', 'jupiterx-core' ),
+ esc_url( admin_url( 'admin.php?page=jupiterx#/settings#woocommerce' ) ),
+ esc_html__( 'click here', 'jupiterx-core' )
+ ),
+ ];
+
+ if ( 'embed' === $selected_video_type ) {
+ unset( $form_fields[ self::MEDIA_URL ] );
+ unset( $form_fields['jupiterx_attached_video'] );
+ }
+
+ if ( 'custom' === $selected_video_type ) {
+ unset( $form_fields[ self::EMBED_URL ] );
+ unset( $form_fields['jupiterx_embed_url_text'] );
+ }
+
+ return $form_fields;
+ }
+
+ /**
+ * This method will render select option html code.
+ *
+ * @param array $options
+ * @param int $id
+ * @param string $type
+ * @param string $default
+ * @since 2.5.0
+ * @return string
+ */
+ private function render_select( $options, $id, $type, $default ) {
+ if ( empty( $options ) || empty( $id ) || empty( $type ) ) {
+ return;
+ }
+
+ $options_html = '';
+ $default = ! empty( $this->get_attachment_data( $id, $type ) ) ? $this->get_attachment_data( $id, $type ) : $default;
+
+ foreach ( $options as $key => $option ) {
+ $value = $key;
+
+ if ( self::ASPECT_RATIO === $type ) {
+ $value = $option;
+ }
+
+ $options_html .= sprintf(
+ '<option value="%1$s" %2$s>%3$s</option>',
+ $value,
+ selected( $default, $value, false ),
+ $option
+ );
+ }
+
+ $video_type_select = sprintf(
+ '<select class="jupiterx-attachment-form-select %1$s" name="attachments[%2$s][%3$s]">%4$s</select>',
+ str_replace( '_', '-', $type ) . '-select',
+ $id,
+ $type,
+ $options_html
+ );
+
+ return $video_type_select;
+ }
+
+ /**
+ * Save form fields.
+ *
+ * @param array $post
+ * @param array $attachment
+ * @since 2.5.0
+ * @return array
+ */
+ public function save_new_video_attachment_fields( $post, $attachment ) {
+ $meta = [];
+
+ foreach ( $attachment as $key => $value ) {
+ if ( ! str_starts_with( $key, 'jupiterx_' ) ) {
+ continue;
+ }
+
+ $meta[ $key ] = sanitize_text_field( $value );
+ }
+
+ update_post_meta( $post['ID'], '_jupiterx_attachment_meta', $meta );
+
+ return $post;
+ }
+
+ /**
+ * Get meta data.
+ *
+ * @param integer $id
+ * @param string $key
+ * @since 2.5.0
+ * @return mixed Value set for the option.
+ */
+ private function get_attachment_data( $id, $key, $default = false ) {
+ $options = get_post_meta( $id, '_jupiterx_attachment_meta', true );
+
+ if ( ! isset( $options[ $key ] ) ) {
+ return $default;
+ }
+
+ if ( 'jupiterx_embed_url' === $key && empty( wp_oembed_get( $options[ $key ] ) ) ) {
+ $options[ $key ] = null;
+ }
+
+ return $options[ $key ];
+ }
+
+ /**
+ * Get changed meta field.
+ *
+ * @param integer $id
+ * @param string $meta
+ * @since 2.5.0
+ * @return string
+ */
+ private function get_value_on_change( $id, $meta ) {
+ $default = $this->get_attachment_data( $id, $meta );
+
+ if ( empty( $default ) ) {
+ $default = 'custom';
+ }
+
+ if ( empty( $_POST['attachments'][ $id ][ $meta ] ) ) { // phpcs:ignore
+ return $default;
+ }
+
+ return htmlspecialchars( $_POST['attachments'][ $id ][ $meta ] ); // phpcs:ignore
+ }
+
+ /**
+ * Check is product edit page.
+ *
+ * @since 2.5.0
+ * @return boolean|null
+ */
+ private function validate_is_edit_product() {
+ $post_id = ! empty( $_POST['post_id'] ) ? htmlspecialchars( $_POST['post_id'] ) : null; // phpcs:ignore.
+
+ if ( empty( $post_id ) ) {
+ $params = [];
+
+ $url = ! empty( $_SERVER['HTTP_REFERER'] ) ? htmlspecialchars( $_SERVER['HTTP_REFERER'] ) : null; // phpcs:ignore.
+ $url_params = wp_parse_url( $url );
+
+ if ( empty( $url_params['query'] ) ) {
+ return;
+ }
+
+ wp_parse_str( $url_params['query'], $params );
+
+ $post_id = ! empty( $params['post'] ) ? htmlspecialchars( $params['post'] ) : null; // phpcs:ignore.
+ }
+
+ $post_type = get_post_type( $post_id );
+
+ if ( ! in_array( $post_type, [ 'product', 'product_variation' ], true ) || empty( $post_id ) ) {
+ return;
+ }
+
+ return true;
+ }
+ }
+}
+
+new JupiterX_Core_Attachment_Media();
--- a/jupiterx-core/includes/admin/class-auto-updates.php
+++ b/jupiterx-core/includes/admin/class-auto-updates.php
@@ -1,168 +1,168 @@
-<?php
-/**
- * This class is responsible to managing all plugins & theme auto updates.
- *
- * @package JupiterX_CoreAdmin
- */
-
-class JupiterX_Core_Auto_Updates {
- /**
- * Transient to remember when update was checked last time.
- *
- * @since 1.18.0
- */
- const LAST_CHECKED_TRANSIENT_KEY = 'jupiterx_core_cp_updates_last_checked';
- /**
- * Transient to remember updates.
- *
- * @since 1.18.0
- */
- const UPDATES_TRANSIENT_KEY = 'jupiterx_core_cp_updates';
-
- /**
- * Updates Manager Constructor
- *
- * @since 1.18.0
- */
- public function __construct() {
- add_action( 'wp_ajax_jupiterx_core_cp_toggle_auto_updater', [ self::class, 'toggle_auto_updater' ] );
- add_action( 'pre_auto_update', [ $this, 'clear_transients' ] );
-
- $this->init_auto_updater();
- }
-
- /**
- * Watch for updates. Allow updates for jupiterx theme & managed plugins only
- * with the exception of manually enabled auto updates for themes & plugins.
- *
- * @since 1.18.0
- *
- * @return void
- */
- public function init_auto_updater() {
- $status = jupiterx_core_get_option( 'auto_updater', false );
-
- if ( false === $status ) {
- return;
- }
-
- if ( ! jupiterx_core_is_registered() || ! function_exists( 'jupiterx_core_get_managed_plugins' ) ) {
- return;
- }
-
- add_filter( 'auto_update_theme', [ self::class, 'auto_update_theme' ], 10, 2 );
- add_filter( 'auto_update_plugin', [ self::class, 'auto_update_plugin' ], 10, 2 );
- }
-
- /**
- * Auto update plugin.
- *
- * @since 1.18.0
- *
- * @param bool $update Trigger update if true.
- * @param object $item Plugin.
- *
- * @return void
- */
- public static function auto_update_plugin( $update, $item ) {
- $enabled_plugins = (array) get_site_option( 'auto_update_plugins', [] );
-
- if ( in_array( $item->plugin, $enabled_plugins, true ) ) {
- return $update;
- }
-
- $plugins = jupiterx_core_get_managed_plugins();
-
- if ( ! is_array( $plugins ) || empty( $plugins ) ) {
- return false;
- }
-
- $slugs = [];
-
- foreach ( $plugins as $plugin ) {
- $slugs[] = $plugin->slug;
- }
-
- return in_array( $item->slug, $slugs, true );
- }
-
- /**
- * Auto update theme.
- *
- * @since 1.18.0
- *
- * @param bool $update Trigger update if true.
- * @param object $item Theme.
- *
- * @return void
- */
- public static function auto_update_theme( $update, $item ) {
- $enabled_themes = (array) get_site_option( 'auto_update_themes', [] );
-
- if ( in_array( $item->theme, $enabled_themes, true ) ) {
- return $update;
- }
-
- return 'jupiterx' === $item->theme;
- }
-
- /**
- * Toggle auto updater state.
- *
- * @since 1.18.0
- *
- * @return void
- */
- public static function toggle_auto_updater() {
- if ( ! current_user_can( 'edit_others_posts' ) || ! current_user_can( 'edit_others_pages' ) ) {
- wp_send_json_error( 'You do not have access to this section', 'jupiterx-core' );
- }
-
- check_ajax_referer( 'jupiterx_control_panel' );
-
- require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
-
- delete_site_transient( 'update_plugins' );
- delete_site_transient( 'update_themes' );
- WP_Upgrader::release_lock( 'auto_updater' );
-
- $enable = false;
-
- if ( ! empty( $_POST['enable'] ) ) {
- $enable = sanitize_text_field( wp_unslash( $_POST['enable'] ) ) === 'true';
- }
-
- jupiterx_core_update_option( 'auto_updater', $enable );
-
- wp_send_json_success( [ 'state' => $enable ? 'enabled' : 'disabled' ] );
- }
-
- /**
- * Get auto updater state.
- *
- * @since 1.18.0
- *
- * @return void
- */
- public static function get_auto_updater_state() {
- $status = jupiterx_core_get_option( 'auto_updater', false );
-
- if ( false === $status ) {
- return 'disabled';
- }
-
- return 'enabled';
- }
-
- /**
- * Clear transients.
- *
- * @since 1.18.0
- */
- public function clear_transients() {
- delete_transient( self::LAST_CHECKED_TRANSIENT_KEY );
- delete_transient( self::UPDATES_TRANSIENT_KEY );
- }
-}
-
-new JupiterX_Core_Auto_Updates();
+<?php
+/**
+ * This class is responsible to managing all plugins & theme auto updates.
+ *
+ * @package JupiterX_CoreAdmin
+ */
+
+class JupiterX_Core_Auto_Updates {
+ /**
+ * Transient to remember when update was checked last time.
+ *
+ * @since 1.18.0
+ */
+ const LAST_CHECKED_TRANSIENT_KEY = 'jupiterx_core_cp_updates_last_checked';
+ /**
+ * Transient to remember updates.
+ *
+ * @since 1.18.0
+ */
+ const UPDATES_TRANSIENT_KEY = 'jupiterx_core_cp_updates';
+
+ /**
+ * Updates Manager Constructor
+ *
+ * @since 1.18.0
+ */
+ public function __construct() {
+ add_action( 'wp_ajax_jupiterx_core_cp_toggle_auto_updater', [ self::class, 'toggle_auto_updater' ] );
+ add_action( 'pre_auto_update', [ $this, 'clear_transients' ] );
+
+ $this->init_auto_updater();
+ }
+
+ /**
+ * Watch for updates. Allow updates for jupiterx theme & managed plugins only
+ * with the exception of manually enabled auto updates for themes & plugins.
+ *
+ * @since 1.18.0
+ *
+ * @return void
+ */
+ public function init_auto_updater() {
+ $status = jupiterx_core_get_option( 'auto_updater', false );
+
+ if ( false === $status ) {
+ return;
+ }
+
+ if ( ! jupiterx_core_is_registered() || ! function_exists( 'jupiterx_core_get_managed_plugins' ) ) {
+ return;
+ }
+
+ add_filter( 'auto_update_theme', [ self::class, 'auto_update_theme' ], 10, 2 );
+ add_filter( 'auto_update_plugin', [ self::class, 'auto_update_plugin' ], 10, 2 );
+ }
+
+ /**
+ * Auto update plugin.
+ *
+ * @since 1.18.0
+ *
+ * @param bool $update Trigger update if true.
+ * @param object $item Plugin.
+ *
+ * @return void
+ */
+ public static function auto_update_plugin( $update, $item ) {
+ $enabled_plugins = (array) get_site_option( 'auto_update_plugins', [] );
+
+ if ( in_array( $item->plugin, $enabled_plugins, true ) ) {
+ return $update;
+ }
+
+ $plugins = jupiterx_core_get_managed_plugins();
+
+ if ( ! is_array( $plugins ) || empty( $plugins ) ) {
+ return false;
+ }
+
+ $slugs = [];
+
+ foreach ( $plugins as $plugin ) {
+ $slugs[] = $plugin->slug;
+ }
+
+ return in_array( $item->slug, $slugs, true );
+ }
+
+ /**
+ * Auto update theme.
+ *
+ * @since 1.18.0
+ *
+ * @param bool $update Trigger update if true.
+ * @param object $item Theme.
+ *
+ * @return void
+ */
+ public static function auto_update_theme( $update, $item ) {
+ $enabled_themes = (array) get_site_option( 'auto_update_themes', [] );
+
+ if ( in_array( $item->theme, $enabled_themes, true ) ) {
+ return $update;
+ }
+
+ return 'jupiterx' === $item->theme;
+ }
+
+ /**
+ * Toggle auto updater state.
+ *
+ * @since 1.18.0
+ *
+ * @return void
+ */
+ public static function toggle_auto_updater() {
+ if ( ! current_user_can( 'edit_others_posts' ) || ! current_user_can( 'edit_others_pages' ) ) {
+ wp_send_json_error( 'You do not have access to this section', 'jupiterx-core' );
+ }
+
+ check_ajax_referer( 'jupiterx_control_panel' );
+
+ require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
+
+ delete_site_transient( 'update_plugins' );
+ delete_site_transient( 'update_themes' );
+ WP_Upgrader::release_lock( 'auto_updater' );
+
+ $enable = false;
+
+ if ( ! empty( $_POST['enable'] ) ) {
+ $enable = sanitize_text_field( wp_unslash( $_POST['enable'] ) ) === 'true';
+ }
+
+ jupiterx_core_update_option( 'auto_updater', $enable );
+
+ wp_send_json_success( [ 'state' => $enable ? 'enabled' : 'disabled' ] );
+ }
+
+ /**
+ * Get auto updater state.
+ *
+ * @since 1.18.0
+ *
+ * @return void
+ */
+ public static function get_auto_updater_state() {
+ $status = jupiterx_core_get_option( 'auto_updater', false );
+
+ if ( false === $status ) {
+ return 'disabled';
+ }
+
+ return 'enabled';
+ }
+
+ /**
+ * Clear transients.
+ *
+ * @since 1.18.0
+ */
+ public function clear_transients() {
+ delete_transient( self::LAST_CHECKED_TRANSIENT_KEY );
+ delete_transient( self::UPDATES_TRANSIENT_KEY );
+ }
+}
+
+new JupiterX_Core_Auto_Updates();
--- a/jupiterx-core/includes/admin/class-notices.php
+++ b/jupiterx-core/includes/admin/class-notices.php
@@ -1,55 +1,55 @@
-<?php
-/**
- * This class handles admin notices.
- *
- * @package JupiterX_CoreAdmin
- *
- * @since 1.18.0
- */
-
-/**
- * Handle admin notices.
- *
- * @package JupiterX_CoreAdmin
- *
- * @since 1.18.0
- */
-class JupiterX_Core_Admin_Notices {
-
- /**
- * Constructor.
- *
- * @since 1.18.0
- */
- public function __construct() {
- add_filter( 'jet-dashboard/js-page-config', [ $this, 'remove_croco_license_notice' ], 10, 1 );
- }
-
- /**
- * Remove Croco notice.
- *
- * @param $notices
- * @return void|array
- * @since 1.20.0
- */
- public function remove_croco_license_notice( $notices ) {
- if ( empty( $notices['noticeList'] ) ) {
- return $notices;
- }
-
- foreach ( $notices['noticeList'] as $key => $notice ) {
- if ( empty( $notice['id'] ) || '30days-to-license-expire' !== $notice['id'] ) {
- continue;
- }
-
- unset( $notices['noticeList'][ $key ] );
- }
-
- // Reindex array after unset
- $notices['noticeList'] = array_values( $notices['noticeList'] );
-
- return $notices;
- }
-}
-
-new JupiterX_Core_Admin_Notices();
+<?php
+/**
+ * This class handles admin notices.
+ *
+ * @package JupiterX_CoreAdmin
+ *
+ * @since 1.18.0
+ */
+
+/**
+ * Handle admin notices.
+ *
+ * @package JupiterX_CoreAdmin
+ *
+ * @since 1.18.0
+ */
+class JupiterX_Core_Admin_Notices {
+
+ /**
+ * Constructor.
+ *
+ * @since 1.18.0
+ */
+ public function __construct() {
+ add_filter( 'jet-dashboard/js-page-config', [ $this, 'remove_croco_license_notice' ], 10, 1 );
+ }
+
+ /**
+ * Remove Croco notice.
+ *
+ * @param $notices
+ * @return void|array
+ * @since 1.20.0
+ */
+ public function remove_croco_license_notice( $notices ) {
+ if ( empty( $notices['noticeList'] ) ) {
+ return $notices;
+ }
+
+ foreach ( $notices['noticeList'] as $key => $notice ) {
+ if ( empty( $notice['id'] ) || '30days-to-license-expire' !== $notice['id'] ) {
+ continue;
+ }
+
+ unset( $notices['noticeList'][ $key ] );
+ }
+
+ // Reindex array after unset
+ $notices['noticeList'] = array_values( $notices['noticeList'] );
+
+ return $notices;
+ }
+}
+
+new JupiterX_Core_Admin_Notices();
--- a/jupiterx-core/includes/admin/license/class-api-license.php
+++ b/jupiterx-core/includes/admin/license/class-api-license.php
@@ -1,116 +1,116 @@
-<?php
-/**
- * API License.
- *
- * @package JupiterX_CoreAdminLicense
- *
- * @since 4.10.1
- */
-class JupiterX_Core_API_License {
-
- private static $instance = null;
- const ENVATO_ITEM_ID = '5177775';
- const PURCHASE_CODE_OPTION_NAME = 'envato_purchase_code_' . self::ENVATO_ITEM_ID;
- const ACCESS_TOKEN_OPTION_NAME = 'api_access_token';
- const API_KEY_OPTION_NAME = 'api_key';
- const EMAIL_OPTION_NAME = 'api_email';
- const EXPIRY_OPTION_NAME = 'api_expiry';
-
- /**
- * Get instance.
- *
- * @since 4.10.1
- *
- * @return JupiterX_Core_API_License
- */
- public static function get_instance() {
- if ( null === self::$instance ) {
- self::$instance = new self();
- }
-
- return self::$instance;
- }
-
- /**
- * Constructor.
- *
- * @since 4.10.1
- */
- public function __construct() {
- add_action( 'rest_api_init', [ $this, 'register_routes' ] );
- }
-
- /**
- * Register routes.
- *
- * @since 4.10.1
- */
- public function register_routes() {
- register_rest_route( 'jupiterx-license', 'deactivate', [
- 'methods' => 'POST',
- 'callback' => [ $this, 'remote_deactivate' ],
- 'permission_callback' => '__return_true',
- ] );
- }
-
- /**
- * Remote deactivate.
- *
- * @since 4.10.1
- *
- * @param object $request Request.
- *
- * @return WP_REST_Response
- */
- public function remote_deactivate( $request ) {
- $site_key = $request->get_param( 'site_key' );
- $access_token = $request->get_param( 'access_token' );
-
- if ( empty( $site_key ) || empty( $access_token ) ) {
- return new WP_REST_Response( [ 'message' => __( 'Invalid request.', 'jupiterx-core' ) ], 400 );
- }
-
- if ( $this->get_option( self::API_KEY_OPTION_NAME ) === $site_key && $this->get_option( self::ACCESS_TOKEN_OPTION_NAME ) === $access_token ) {
- $this->remove_option( self::PURCHASE_CODE_OPTION_NAME );
- $this->remove_option( self::ACCESS_TOKEN_OPTION_NAME );
- $this->remove_option( self::API_KEY_OPTION_NAME );
- $this->remove_option( self::EMAIL_OPTION_NAME );
- $this->remove_option( self::EXPIRY_OPTION_NAME );
-
- return new WP_REST_Response( [ 'message' => __( 'License deactivated', 'jupiterx-core' ) ], 200 );
- }
-
- return new WP_REST_Response( [ 'message' => __( 'Invalid request.', 'jupiterx-core' ) ], 400 );
- }
-
- /**
- * Get option value.
- *
- * @since 4.10.1
- *
- * @param string $name Option name.
- *
- * @return string Option value.
- */
- private function get_option( $name ) {
- return jupiterx_get_option( $name, false );
- }
-
- /**
- * Remove option value.
- *
- * @since 4.10.1
- *
- * @param string $name Option name.
- *
- * @return boolean Remove status.
- */
- private function remove_option( $name ) {
- if ( $this->get_option( $name ) ) {
- return jupiterx_delete_option( $name );
- }
- return true;
- }
-}
-
-JupiterX_Core_API_License::get_instance();
+<?php
+/**
+ * API License.
+ *
+ * @package JupiterX_CoreAdminLicense
+ *
+ * @since 4.10.1
+ */
+class JupiterX_Core_API_License {
+
+ private static $instance = null;
+ const ENVATO_ITEM_ID = '5177775';
+ const PURCHASE_CODE_OPTION_NAME = 'envato_purchase_code_' . self::ENVATO_ITEM_ID;
+ const ACCESS_TOKEN_OPTION_NAME = 'api_access_token';
+ const API_KEY_OPTION_NAME = 'api_key';
+ const EMAIL_OPTION_NAME = 'api_email';
+ const EXPIRY_OPTION_NAME = 'api_expiry';
+
+ /**
+ * Get instance.
+ *
+ * @since 4.10.1
+ *
+ * @return JupiterX_Core_API_License
+ */
+ public static function get_instance() {
+ if ( null === self::$instance ) {
+ self::$instance = new self();
+ }
+
+ return self::$instance;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @since 4.10.1
+ */
+ public function __construct() {
+ add_action( 'rest_api_init', [ $this, 'register_routes' ] );
+ }
+
+ /**
+ * Register routes.
+ *
+ * @since 4.10.1
+ */
+ public function register_routes() {
+ register_rest_route( 'jupiterx-license', 'deactivate', [
+ 'methods' => 'POST',
+ 'callback' => [ $this, 'remote_deactivate' ],
+ 'permission_callback' => '__return_true',
+ ] );
+ }
+
+ /**
+ * Remote deactivate.
+ *
+ * @since 4.10.1
+ *
+ * @param object $request Request.
+ *
+ * @return WP_REST_Response
+ */
+ public function remote_deactivate( $request ) {
+ $site_key = $request->get_param( 'site_key' );
+ $access_token = $request->get_param( 'access_token' );
+
+ if ( empty( $site_key ) || empty( $access_token ) ) {
+ return new WP_REST_Response( [ 'message' => __( 'Invalid request.', 'jupiterx-core' ) ], 400 );
+ }
+
+ if ( $this->get_option( self::API_KEY_OPTION_NAME ) === $site_key && $this->get_option( self::ACCESS_TOKEN_OPTION_NAME ) === $access_token ) {
+ $this->remove_option( self::PURCHASE_CODE_OPTION_NAME );
+ $this->remove_option( self::ACCESS_TOKEN_OPTION_NAME );
+ $this->remove_option( self::API_KEY_OPTION_NAME );
+ $this->remove_option( self::EMAIL_OPTION_NAME );
+ $this->remove_option( self::EXPIRY_OPTION_NAME );
+
+ return new WP_REST_Response( [ 'message' => __( 'License deactivated', 'jupiterx-core' ) ], 200 );
+ }
+
+ return new WP_REST_Response( [ 'message' => __( 'Invalid request.', 'jupiterx-core' ) ], 400 );
+ }
+
+ /**
+ * Get option value.
+ *
+ * @since 4.10.1
+ *
+ * @param string $name Option name.
+ *
+ * @return string Option value.
+ */
+ private function get_option( $name ) {
+ return jupiterx_get_option( $name, false );
+ }
+
+ /**
+ * Remove option value.
+ *
+ * @since 4.10.1
+ *
+ * @param string $name Option name.
+ *
+ * @return boolean Remove status.
+ */
+ private function remove_option( $name ) {
+ if ( $this->get_option( $name ) ) {
+ return jupiterx_delete_option( $name );
+ }
+ return true;
+ }
+}
+
+JupiterX_Core_API_License::get_instance();
--- a/jupiterx-core/includes/admin/license/class-event-license.php
+++ b/jupiterx-core/includes/admin/license/class-event-license.php
@@ -1,208 +1,208 @@
-<?php
-/**
- * The file class that handles events of license.
- *
- * @package JupiterX_CoreAdminLicense
- *
- * @since 4.10.1
- */
-
-class JupiterX_Core_Event_License {
-
- const ARTBEES_THEMES_API = 'https://my.artbees.net/wp-json/artbees_license';
- const ENVATO_ITEM_ID = '5177775';
- const PURCHASE_CODE_OPTION_NAME = 'envato_purchase_code_' . self::ENVATO_ITEM_ID;
- const ACCESS_TOKEN_OPTION_NAME = 'api_access_token';
- const API_KEY_OPTION_NAME = 'api_key';
- const EMAIL_OPTION_NAME = 'api_email';
- const EXPIRY_OPTION_NAME = 'api_expiry';
- const IS_REGISTERED_ON_ANOTHER_DOMAIN_OPTION_NAME = 'is_registered_on_another_domain';
-
- /**
- * Class instance.
- *
- * @since 4.10.1
- *
- * @var JupiterX_Core_Event_License Class instance.
- */
- private static $instance = null;
-
- /**
- * Get a class instance.
- *
- * @since 4.10.1
- *
- * @return JupiterX_Core_Event_License Class instance.
- */
- public static function get_instance() {
- if ( null === self::$instance ) {
- self::$instance = new self();
- }
-
- return self::$instance;
- }
-
- /**
- * Class constructor.
- *
- * @since 4.10.1
- */
- public function __construct() {
- add_action( 'jupiterx_license_checks', [ $this, 'validate_license' ] );
- }
-
- /**
- * Validate license.
- *
- * @since 4.10.1
- */
- public function validate_license() {
- if ( ! $this->has_api_key() || ! $this->has_access_token() ) {
- return;
- }
-
- $result = wp_remote_post( static::ARTBEES_THEMES_API . '/validate_license', [
- 'body' => [
- 'api_key' => $this->get_option( self::API_KEY_OPTION_NAME ),
- 'domain' => $this->get_domain(),
- ],
- ]);
-
- if ( is_wp_error( $result ) ) {
- return;
- }
-
- $body = json_decode( wp_remote_retrieve_body( $result ) );
-
- if ( false === $body->status ) {
- $this->update_option( self::IS_REGISTERED_ON_ANOTHER_DOMAIN_OPTION_NAME, true );
-
- //TODO: Remove License in next release
- } else {
- $this->update_option( self::IS_REGISTERED_ON_ANOTHER_DOMAIN_OPTION_NAME, false );
- }
- }
-
- /**
- * Check API key from the database.
- *
- * @since 4.10.1
- *
- * @return boolean API key status.
- */
- private function has_api_key() {
- return ! empty( $this->get_option( self::API_KEY_OPTION_NAME ) );
- }
-
- /**
- * Check access token from the database.
- *
- * @since 4.10.1
- *
- * @return boolean Access token status.
- */
- private function has_access_token() {
- return ! empty( $this->get_option( self::ACCESS_TOKEN_OPTION_NAME ) );
- }
-
- /**
- * Get email.
- *
- * @since 4.10.1
- *
- * @return string License email.
- */
- private function get_email() {
- return $this->get_option( self::EMAIL_OPTION_NAME );
- }
-
- /**
- * Get expiry.
- *
- * @since 4.10.1
- *
- * @return string License expiry.
- */
- private function get_expiry() {
- return $this->get_option( self::EXPIRY_OPTION_NAME );
- }
-
- /**
- * Check license status.
- *
- * @since 4.10.1
- *
- * @return boolean License status.
- */
- private function is_registered() {
- $access_token = $this->has_access_token() ? $this->has_access_token() : true;
- $email = ! empty( $this->get_email() ) ? $this->get_email() : true;
- $expiry = ! empty( $this->get_expiry() ) ? $this->get_expiry() : true;
-
- return (
- $this->has_api_key() &&
- $access_token &&
- $email &&
- $expiry
- );
- }
-
- /**
- * Get license details.
- *
- * @since 4.10.1
- */
- public function get_details() {
- return [
- 'is_registered' => $this->is_registered(),
- 'has_access_token' => $this->has_access_token(),
- 'has_api_key' => $this->has_api_key(),
- 'email' => $this->get_email(),
- 'expiry' => $this->get_expiry(),
- ];
- }
-
- /**
- * Update option.
- *
- * @since 4.10.1
- *
- * @param string $name Option name.
- * @param mixed $value Update value.
- *
- * @return string Updated value.
- */
- private function update_option( $name, $value ) {
- return jupiterx_update_option( $name, $value );
- }
-
- /**
- * Get option value.
- *
- * @since 4.10.1
- *
- * @return string|null Option value.
- */
- private function get_option( $name ) {
- if ( function_exists( 'jupiterx_get_option' ) ) {
- return jupiterx_get_option( $name, false );
- }
-
- return null;
- }
-
- /**
- * Extract the domain (sub-domain) from URL.
- *
- * We keep this function here as we may change our approach for sending data of domain.
- *
- * @since 4.10.1
- *
- * @return string Domain name.
- */
- private function get_domain() {
- return get_site_url();
- }
-}
-
-JupiterX_Core_Event_License::get_instance();
+<?php
+/**
+ * The file class that handles events of license.
+ *
+ * @package JupiterX_CoreAdminLicense
+ *
+ * @since 4.10.1
+ */
+
+class JupiterX_Core_Event_License {
+
+ const ARTBEES_THEMES_API = 'https://my.artbees.net/wp-json/artbees_license';
+ const ENVATO_ITEM_ID = '5177775';
+ const PURCHASE_CODE_OPTION_NAME = 'envato_purchase_code_' . self::ENVATO_ITEM_ID;
+ const ACCESS_TOKEN_OPTION_NAME = 'api_access_token';
+ const API_KEY_OPTION_NAME = 'api_key';
+ const EMAIL_OPTION_NAME = 'api_email';
+ const EXPIRY_OPTION_NAME = 'api_expiry';
+ const IS_REGISTERED_ON_ANOTHER_DOMAIN_OPTION_NAME = 'is_registered_on_another_domain';
+
+ /**
+ * Class instance.
+ *
+ * @since 4.10.1
+ *
+ * @var JupiterX_Core_Event_License Class instance.
+ */
+ private static $instance = null;
+
+ /**
+ * Get a class instance.
+ *
+ * @since 4.10.1
+ *
+ * @return JupiterX_Core_Event_License Class instance.
+ */
+ public static function get_instance() {
+ if ( null === self::$instance ) {
+ self::$instance = new self();
+ }
+
+ return self::$instance;
+ }
+
+ /**
+ * Class constructor.
+ *
+ * @since 4.10.1
+ */
+ public function __construct() {
+ add_action( 'jupiterx_license_checks', [ $this, 'validate_license' ] );
+ }
+
+ /**
+ * Validate license.
+ *
+ * @since 4.10.1
+ */
+ public function validate_license() {
+ if ( ! $this->has_api_key() || ! $this->has_access_token() ) {
+ return;
+ }
+
+ $result = wp_remote_post( static::ARTBEES_THEMES_API . '/validate_license', [
+ 'body' => [
+ 'api_key' => $this->get_option( self::API_KEY_OPTION_NAME ),
+ 'domain' => $this->get_domain(),
+ ],
+ ]);
+
+ if ( is_wp_error( $result ) ) {
+ return;
+ }
+
+ $body = json_decode( wp_remote_retrieve_body( $result ) );
+
+ if ( false === $body->status ) {
+ $this->update_option( self::IS_REGISTERED_ON_ANOTHER_DOMAIN_OPTION_NAME, true );
+
+ //TODO: Remove License in next release
+ } else {
+ $this->update_option( self::IS_REGISTERED_ON_ANOTHER_DOMAIN_OPTION_NAME, false );
+ }
+ }
+
+ /**
+ * Check API key from the database.
+ *
+ * @since 4.10.1
+ *
+ * @return boolean API key status.
+ */
+ private function has_api_key() {
+ return ! empty( $this->get_option( self::API_KEY_OPTION_NAME ) );
+ }
+
+ /**
+ * Check access token from the database.
+ *
+ * @since 4.10.1
+ *
+ * @return boolean Access token status.
+ */
+ private function has_access_token() {
+ return ! empty( $this->get_option( self::ACCESS_TOKEN_OPTION_NAME ) );
+ }
+
+ /**
+ * Get email.
+ *
+ * @since 4.10.1
+ *
+ * @return string License email.
+ */
+ private function get_email() {
+ return $this->get_option( self::EMAIL_OPTION_NAME );
+ }
+
+ /**
+ * Get expiry.
+ *
+ * @since 4.10.1
+ *
+ * @return string License expiry.
+ */
+ private function get_expiry() {
+ return $this->get_option( self::EXPIRY_OPTION_NAME );
+ }
+
+ /**
+ * Check license status.
+ *
+ * @since 4.10.1
+ *
+ * @return boolean License status.
+ */
+ private function is_registered() {
+ $access_token = $this->has_access_token() ? $this->has_access_token() : true;
+ $email = ! empty( $this->get_email() ) ? $this->get_email() : true;
+ $expiry = ! empty( $this->get_expiry() ) ? $this->get_expiry() : true;
+
+ return (
+ $this->has_api_key() &&
+ $access_token &&
+ $email &&
+ $expiry
+ );
+ }
+
+ /**
+ * Get license details.
+ *
+ * @since 4.10.1
+ */
+ public function get_details() {
+ return [
+ 'is_registered' => $this->is_registered(),
+ 'has_access_token' => $this->has_access_token(),
+ 'has_api_key' => $this->has_api_key(),
+ 'email' => $this->get_email(),
+ 'expiry' => $this->get_expiry(),
+ ];
+ }
+
+ /**
+ * Update option.
+ *
+ * @since 4.10.1
+ *
+ * @param string $name Option name.
+ * @param mixed $value Update value.
+ *
+ * @return string Updated value.
+ */
+ private function update_option( $name, $value ) {
+ return jupiterx_update_option( $name, $value );
+ }
+
+ /**
+ * Get option value.
+ *
+ * @since 4.10.1
+ *
+ * @return string|null Option value.
+ */
+ private function get_option( $name ) {
+ if ( function_exists( 'jupiterx_get_option' ) ) {
+ return jupiterx_get_option( $name, false );
+ }
+
+ return null;
+ }
+
+ /**
+ * Extract the domain (sub-domain) from URL.
+ *
+ * We keep this function here as we may change our approach for sending data of domain.
+ *
+ * @since 4.10.1
+ *
+ * @return string Domain name.
+ */
+ private function get_domain() {
+ return get_site_url();
+ }
+}
+
+JupiterX_Core_Event_License::get_instance();
--- a/jupiterx-core/includes/admin/options.php
+++ b/jupiterx-core/includes/admin/options.php
@@ -1,65 +1,65 @@
-<?php
-/**
- * Add Jupiter X admin options.
- *
- * @package JupiterX_CoreAdmin
- *
- * @since 1.9.0
- */
-
-add_filter( 'upload_mimes', 'jupiterx_add_extra_mime_types' );
-
-if ( ! function_exists( 'jupiterx_add_extra_mime_types' ) ) {
- /**
- * Add more mime type.
- *
- * @since 1.9.0
- *
- * @param array $mimes Current array of mime types..
- *
- * @return array Updated array of mime types.
- */
- function jupiterx_add_extra_mime_types( $mimes ) {
- if ( jupiterx_core()->check_default_settings() ) {
- return $mimes;
- }
-
- if ( ! empty( jupiterx_get_option( 'svg_support' ) ) ) {
- $mimes['svg'] = 'image/svg+xml';
- }
-
- $mimes['zip'] = 'application/zip';
-
- return $mimes;
- }
-}
-
-add_filter( 'wp_check_filetype_and_ext', 'jupiterx_fix_filetype_check', 10, 4 );
-/**
- * Fix the mime type filtering issue.
- *
- * @since 1.9.0
- *
- * @param array $data file data.
- * @param string $file Full path to the file.
- * @param string $filename The name of the file (may differ from $file due to $file being in a tmp.
- * @param array $mimes Key is the file extension with value as the mime type.
- * @return array Filetype data.
- *
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- */
-function jupiterx_fix_filetype_check( $data, $file, $filename, $mimes ) {
- if ( ! empty( $data['ext'] ) && ! empty( $data['type'] ) ) {
- return $data;
- }
-
- $wp_filetype = wp_check_filetype( $filename, $mimes );
-
- if ( 'svg' === $wp_filetype['ext'] || 'svgz' === $wp_filetype['ext'] ) {
- $data['ext'] = $wp_filetype['ext'];
- $data['type'] = 'image/svg+xml';
- }
-
- return $data;
-}
-
+<?php
+/**
+ * Add Jupiter X admin options.
+ *
+ * @package JupiterX_CoreAdmin
+ *
+ * @since 1.9.0
+ */
+
+add_filter( 'upload_mimes', 'jupiterx_add_extra_mime_types' );
+
+if ( ! function_exists( 'jupiterx_add_extra_mime_types' ) ) {
+ /**
+ * Add more mime type.
+ *
+ * @since 1.9.0
+ *
+ * @param array $mimes Current array of mime types..
+ *
+ * @return array Updated array of mime types.
+ */
+ function jupiterx_add_extra_mime_types( $mimes ) {
+ if ( jupiterx_core()->check_default_settings() ) {
+ return $mimes;
+ }
+
+ if ( ! empty( jupiterx_get_option( 'svg_support' ) ) ) {
+ $mimes['svg'] = 'image/svg+xml';
+ }
+
+ $mimes['zip'] = 'application/zip';
+
+ return $mimes;
+ }
+}
+
+add_filter( 'wp_check_filetype_and_ext', 'jupiterx_fix_filetype_check', 10, 4 );
+/**
+ * Fix the mime type filtering issue.
+ *
+ * @since 1.9.0
+ *
+ * @param array $data file data.
+ * @param string $file Full path to the file.
+ * @param string $filename The name of the file (may differ from $file due to $file being in a tmp.
+ * @param array $mimes Key is the file extension with value as the mime type.
+ * @return array Filetype data.
+ *
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ */
+function jupiterx_fix_filetype_check( $data, $file, $filename, $mimes ) {
+ if ( ! empty( $data['ext'] ) && ! empty( $data['type'] ) ) {
+ return $data;
+ }
+
+ $wp_filetype = wp_check_filetype( $filename, $mimes );
+
+ if ( 'svg' === $wp_filetype['ext'] || 'svgz' === $wp_filetype['ext'] ) {
+ $data['ext'] = $wp_filetype['ext'];
+ $data['type'] = 'image/svg+xml';
+ }
+
+ return $data;
+}
+
--- a/jupiterx-core/includes/admin/site-health/site-health.php
+++ b/jupiterx-core/includes/admin/site-health/site-health.php
@@ -1,725 +1,725 @@
-<?php
-/**
- * Class for providing data the WordPress' Site Health debug information.
- *
- * @package JupiterX_CoreAdmin
- *
- * @since 1.18.0
- */
-
-/**
- * Site Health class.
- *
- * @since 1.18.0
- *
- * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
- */
-class JupiterX_Core_Site_Health {
-
- /**
- * Site health class instance.
- *
- * @since 1.18.0
- *
- * @var JupiterX_Core_Site_Health|null
- */
- private static $instance = null;
-
- /**
- * Return an instance of the JupiterX_Core_Site_Health class, or create one if none exist yet.
- *
- * @since 1.18.0
- *
- * @return JupiterX_Core_Site_Health|null
- */
- public static function get_instance() {
- if ( null === self::$instance ) {
- self::$instance = new JupiterX_Core_Site_Health();
- }
-
- return self::$instance;
- }
-
- /**
- * Construct class.
- *
- * @since 1.18.0
- */
- public function __construct() {
- add_action( 'wp_ajax_jupiterx_system_status', [ $this, 'system_status' ] );
- add_filter( 'debug_information', [ $this, 'debug_information' ] );
- add_filter( 'site_status_tests', [ $this, 'site_status_tests' ] );
- }
-
- /**
- * Get site status using WP_Site_Health class.
- *
- * @since 1.18.0
- *
- * @return void
- *
- * @SuppressWarnings(PHPMD.NPathComplexity)
- */
- public function system_status() {
- if ( ! current_user_can( 'manage_options' ) ) {
- wp_send_json_error( 'You do not have access to this section.', 'jupiterx-core' );
- }
-
- $health_check_js_variables = [
- 'site_status' => [
- 'direct' => [],
- 'async' => [],
- 'issues' => [
- 'good' => 0,
- 'recommended' => 0,
- 'critical' => 0,
- ],
- ],
- ];
-
- $issue_counts = get_transient( 'health-check-site-status-result' );
-
- jupiterx_log(
- '[Control Panel > Dashboard > Site Health] To get site health issues, the following data is expected to be an object.',
- $issue_counts
- );
-
- if ( false !== $issue_counts ) {
- $issue_counts = json_decode( $issue_counts );
-
- $health_check_js_variables['site_status']['issues'] = $issue_counts;
- }
-
- $core_current_version = get_bloginfo( 'version' );
-
- if ( version_compare( $core_current_version, '5.2', '<' ) ) {
- jupiterx_log(
- '[Control Panel > Dashboard > Site Health] To show site health issues, WordPress needs to be updated.',
- $core_current_version
- );
-
- $health_check_js_variables['site_status']['direct'][] = [
- 'label' => sprintf(
- // translators: %s Site's current WordPress version
- __( 'WordPress version (%s) is outdated', 'jupiterx-core' ),
- $core_current_version
- ),
- 'status' => 'critical',
- 'badge' => [
- 'label' => 'Performance',
- 'color' => 'blue',
- ],
- 'actions' => sprintf(
- '<a href="%s">%s</a>',
- esc_url( admin_url( 'update-core.php' ) ),
- __( 'Update core', 'jupiterx-core' )
- ),
- 'description' => '',
- 'test' => 'wordpress_version',
- ];
-
- wp_send_json_success( $health_check_js_variables );
- }
-
- if ( ! class_exists( 'WP_Site_Health' ) ) {
- require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
- }
-
- $site_health = new WP_Site_Health();
-
- // Start running tests.
- $tests = $site_health::get_tests();
-
- jupiterx_log(
- '[Control Panel > Dashboard > Site Health] To show site health issues, the following data is expected to be an array.',
- $tests
- );
-
- // Don't run https test on localhost.
- if ( 'localhost' === preg_replace( '|https?://|', '', get_site_url() ) ) {
- unset( $tests['direct']['https_status'] );
- }
-
- foreach ( $tests['direct'] as $test ) {
- if ( is_string( $test['test'] ) ) {
- $test_function = sprintf(
- 'get_test_%s',
- $test['test']
- );
-
- if ( method_exists( $site_health, $test_function ) && is_callable( [ $site_health, $test_function ] ) ) {
- $health_check_js_variables['site_status']['direct'][] = $this->perform_test( [ $site_health, $test_function ] );
- continue;
- }
- }
-
- if ( is_callable( $test['test'] ) ) {
- $health_check_js_variables['site_status']['direct'][] = $this->perform_test( $test['test'] );
- }
- }
-
- foreach ( $tests['async'] as $test ) {
- if ( is_string( $test['test'] ) ) {
- $health_check_js_variables['site_status']['async'][] = [
- 'test' => $test['test'],
- 'completed' => false,
- ];
- }
- }
-
- wp_send_json_success( $health_check_js_variables );
- }
-
- /**
- * Run a Site Health test directly.
- *
- * @since 1.18.0
- *
- * @param array $callback Callback method for test.
- *
- * @return mixed|void
- */
- private function perform_test( $callback ) {
- // Borrowed filter from WP_Site_Health::perform_test().
- return apply_filters( 'site_status_test_result', call_user_func( $callback ) );
- }
-
- /**
- * Add debug data to WP_Debug_Data class.
- *
- * @since 1.18.0
- *
- * @param array $info WP debug data for the site.
- *
- * @return array Filters debug data.
- *
- * @SuppressWarnings(PHPMD)
- */
- public function debug_information( $info ) {
- // Compose common internationalized values.
- $value = [
- 'yes' => __( 'Yes', 'jupiterx-core' ),
- 'no' => __( 'No', 'jupiterx-core' ),
- 'enabled' => __( 'Enabled', 'jupiterx-core' ),
- 'disabled' => __( 'Disabled', 'jupiterx-core' ),
- ];
-
- // WordPress section.
- $info['wp-core']['fields']['content_url'] = [
- 'label' => __( 'Content URL', 'jupiterx-core' ),
- 'value' => WP_CONTENT_URL,
- ];
-
- $upload_dir = wp_get_upload_dir();
-
- $info['wp-core']['fields']['upload_url'] = [
- 'label' => __( 'Upload URL', 'jupiterx-core' ),
- 'value' => $upload_dir['baseurl'],
- ];
- $info['wp-core']['fields']['front_page'] = [
- 'label' => __( 'Front page display', 'jupiterx-core' ),
- 'value' => get_option( 'show_on_front' ),
- ];
-
- // Server section.
- // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
- $is_localhost = ( '127.0.0.1' === $_SERVER['REMOTE_ADDR'] || 'localhost' === $_SERVER['REMOTE_ADDR'] || '::1' === $_SERVER['REMOTE_ADDR'] );
-
- $info['wp-server']['fields']['localhost'] = [
- 'label' => __( 'Is local environment?', 'jupiterx-core' ),
- 'value' => $is_localhost ? $value['yes'] : $value['no'],
- ];
-
- $info['wp-server']['fields']['php_errors'] = [
- 'label' => __( 'PHP display errors', 'jupiterx-core' ),
- 'value' => ini_get( 'display_errors' ) ? $value['yes'] : $value['no'],
- ];
-
- $info['wp-server']['fields']['fsockopen'] = [
- 'label' => __( 'Is fsockopen available?', 'jupiterx-core' ),
- 'value' => function_exists( 'fsockopen' ) ? $value['yes'] : $value['no'],
- ];
-
- $info['wp-server']['fields']['php_gzopen'] = [
- 'label' => __( 'Is gzipopen available?', 'jupiterx-core' ),
- 'value' => is_callable( 'gzopen' ) ? $value['yes'] : $value['no'],
- ];
-
- $info['wp-server']['fields']['php_xml'] = [
- 'label' => __( 'PHP XML ', 'jupiterx-core' ),
- 'value' => function_exists( 'xml_parse' ) ? $value['enabled'] : $value['disabled'],
- ];
-
- $simplexml_loaded = class_exists( 'SimpleXMLElement' ) && function_exists( 'simplexml_load_string' );
-
- $info['wp-server']['fields']['php_simplexml'] = [
- 'label' => __( 'SimpleXML', 'jupiterx-core' ),
- 'value' => $simplexml_loaded ? $value['enabled'] : $value['disabled'],
- ];
-
- $mbstring_loaded = extension_loaded( 'mbstring' ) && function_exists( 'mb_eregi' ) && function_exists( 'mb_ereg_match' );
-
- $info['wp-server']['fields']['php_mbstring'] = [
- 'label' => __( 'MBString', 'jupiterx-core' ),
- 'value' => $mbstring_loaded ? $value['enabled'] : $value['disabled'],
- ];
-
- $info['wp-server']['fields']['php_soapclient'] = [
- 'label' => __( 'SoapClient', 'jupiterx-core' ),
- 'value' => class_exists( 'SoapClient' ) ? $value['enabled'] : $value['disabled'],
- ];
-
- $info['wp-server']['fields']['php_domdocument'] = [
- 'label' => __( 'DOMDocument', 'jupiterx-core' ),
- 'value' => class_exists( 'DOMDocument' ) ? $value['enabled'] : $value['disabled'],
- ];
-
- $info['wp-server']['fields']['php_ziparchive'] = [
- 'label' => __( 'ZipArchive', 'jupiterx-core' ),
- 'value' => class_exists( 'ZipArchive' ) ? $value['enabled'] : $value['disabled'],
- ];
-
- $info['wp-server']['fields']['php_iconv'] = [
- 'label' => __( 'Iconv', 'jupiterx-core' ),
- 'value' => class_exists( 'Iconv' ) ? $value['enabled'] : $value['disabled'],
- ];
-
- if ( defined( 'WP_HTTP_BLOCK_EXTERNAL' ) ) {
- $block_external = __( 'HTTP requests have been blocked by the WP_HTTP_BLOCK_EXTERNAL constant, with no allowed hosts.', 'jupiterx-core' );
-
- if ( defined( 'WP_ACCESSIBLE_HOSTS' ) ) {
- $allowed_hosts = explode( ',', WP_ACCESSIBLE_HOSTS );
- }
-
- if ( isset( $allowed_hosts ) && count( $allowed_hosts ) > 0 ) {
- $block_external = sprintf(
- /* translators: 1: Allowed hosts */
- esc_html__( 'HTTP requests have been blocked by the WP_HTTP_BLOCK_EXTERNAL constant, with some hosts whitelisted: %s.', 'jupiterx-core' ),
- implode( ',', $allowed_hosts )
- );
- }
- }
-
- $info['wp-server']['fields']['http_requests'] = [
- 'label' => __( 'HTTP Requests', 'jupiterx-core' ),
- 'value' => isset( $block_external ) ? $block_external : __( 'Accessible', 'jupiterx-core' ),
- ];
-
- $artbees_dotnet = wp_remote_get( 'https://artbees.net', [ 'timeout' => 10 ] );
-
- if ( ! is_wp_error( $artbees_dotnet ) ) {
- $info['wp-server']['fields']['artbees_communication'] = [
- 'label' => __( 'Communication with Artbees' ),
- 'value' => __( 'artbees.net is reachable' ),
- 'debug' => 'true',
- ];
- } else {
- $info['wp-server']['fields']['artbees_communication'] = [
- 'label' => __( 'Communication with artbees.net' ),
- 'value' => sprintf(
- /* translators: 1: The IP address artbees.net resolves to. 2: The error returned by the lookup. */
- __( 'Unable to reach Artbees at %1$s: %2$s' ),
- gethostbyname( 'artbees.net' ),
- $artbees_dotnet->get_error_message()
- ),
- 'debug' => $artbees_dotnet->get_error_message(),
- ];
- }
-
- // Database section.
- $tables = $this->get_tables_sizes();
-
- foreach ( $tables as $table ) {
- $info['wp-database']['fields'][ $table['name'] ] = [
- 'label' => esc_html( $table['name'] ),
- 'value' => $table['size'] . ' MB',
- ];
- }
-
- // Browser section.
- if ( ! class_exists( 'Browser' ) ) {
- jupiterx_core()->load_files( [
- 'control-panel-2/includes/class-browser',
- ] );
- }
-
- $browser = new Browser();
-
- $info['browser'] = [
- 'label' => __( 'Browser', 'jupiterx-core' ),
- 'fields' => [
- 'browse