Plugin Directory

Changeset 3106064


Ignore:
Timestamp:
06/22/2024 04:44:13 PM (22 months ago)
Author:
xmic
Message:

Update to version 1.3.0 from GitHub

Location:
timestamps
Files:
4 added
16 edited
1 copied

Legend:

Unmodified
Added
Removed
  • timestamps/tags/1.3.0/includes/classes/AdminNotices.php

    r3048002 r3106064  
    1313use SDCOM_Timestamps\Utils;
    1414use SDCOM_Timestamps\Screen;
     15
     16use function SDCOM_Timestamps\Utils\get_plugin_option;
    1517
    1618if ( ! defined( 'ABSPATH' ) ) {
     
    7072    protected function process_need_setup_notice() {
    7173
    72         $timestamps_options = get_option( SDCOM_TIMESTAMPS_OPTIONS );
    73         $timestamps_api_key = isset( $timestamps_options['api_key'] ) ? $timestamps_options['api_key'] : '';
     74        $timestamps_api_key = get_plugin_option( 'api_key', '' );
    7475
    7576        if ( ! empty( $timestamps_api_key ) ) {
     
    7778        }
    7879
    79         $dismiss = Utils\get_option( 'sdcom_timestamps_hide_need_setup_notice', false );
     80        $dismiss = get_option( 'sdcom_timestamps_hide_need_setup_notice', false );
    8081
    8182        if ( $dismiss ) {
     
    128129        $value = true;
    129130
    130         Utils\update_option( 'timestamps_hide_' . $notice . '_notice', $value );
     131        update_option( 'timestamps_hide_' . $notice . '_notice', $value );
    131132    }
    132133
  • timestamps/tags/1.3.0/includes/classes/Feature/Timestamp/Timestamp.php

    r3076784 r3106064  
    1212use SDCOM_Timestamps\Utils;
    1313
     14use function SDCOM_Timestamps\Utils\get_plugin_option;
     15
    1416/**
    1517 * Timestamp feature class
     
    4850
    4951    /**
    50      * We need to delay setup up since it will fire after protected content and protected
    51      * content filters into the setup.
     52     * We need to delay setup up until init to ensure all plugins are loaded.
    5253     *
    5354     * @since 1.0.0
     
    160161        wp_set_script_translations( 'timestamp-post-editor', 'timestamps' );
    161162
    162         $timestamps_options = get_option( SDCOM_TIMESTAMPS_OPTIONS );
    163         $timestamps_api_key = isset( $timestamps_options['api_key'] ) ? $timestamps_options['api_key'] : '';
     163        $timestamps_api_key = get_plugin_option( 'api_key', '' );
    164164
    165165        wp_localize_script(
     
    259259                update_post_meta( $post_id, 'sdcom_timestamp_post', true );
    260260
    261                 $create_certificate = $this->create_certificate( $post );
     261                $create_certificate = $this->create_certificate_post( $post );
    262262
    263263                // Handle the case where the method returned false.
     
    273273                }
    274274
    275                 $update_certificate = $this->update_certificate( $post, $certificate_id );
     275                $update_certificate = $this->update_certificate_post( $post, $certificate_id );
    276276
    277277                // Handle the case where the method returned false.
     
    352352            }
    353353
    354             $create_certificate = $this->create_certificate( $post );
     354            $create_certificate = $this->create_certificate_post( $post );
    355355
    356356            // Handle the case where the method returned false.
     
    366366            }
    367367
    368             $update_certificate = $this->update_certificate( $post, $certificate_id );
     368            $update_certificate = $this->update_certificate_post( $post, $certificate_id );
    369369
    370370            // Handle the case where the method returned false.
     
    436436     * @throws \Exception If the options, post content, or API key is empty.
    437437     */
    438     private function create_certificate( $post ) {
     438    private function create_certificate_post( $post ) {
    439439        try {
    440440            $post_id                       = $post->ID;
     
    518518            }
    519519
     520            // Return the data.
    520521            return $data;
    521522
     
    534535     * @throws \Throwable If an exception occurs during the process.
    535536     */
    536     private function update_certificate( $post, $certificate_id ) {
     537    private function update_certificate_post( $post, $certificate_id ) {
    537538        try {
    538539            $post_content     = $post->post_content;
     
    575576            );
    576577
    577             $body = json_encode(
     578            $body = wp_json_encode(
    578579                array(
    579580                    'certificateId' => $certificate_id,
     
    619620            }
    620621
     622            // Return the data.
    621623            return $data;
    622624
  • timestamps/tags/1.3.0/includes/classes/Screen/Settings.php

    r3048002 r3106064  
    1313use SDCOM_Timestamps\Utils;
    1414
     15use function SDCOM_Timestamps\Utils\get_plugin_option;
    1516use function SDCOM_Timestamps\Utils\is_authenticated;
     17use function SDCOM_Timestamps\Utils\is_woocommerce_active;
    1618
    1719if ( ! defined( 'ABSPATH' ) ) {
     
    8385     */
    8486    public function register_settings() {
     87
     88        $option = get_option( SDCOM_TIMESTAMPS_OPTIONS );
     89
    8590        register_setting(
    8691            SDCOM_TIMESTAMPS_OPTIONS,
     
    146151                'sdcom_timestamps_general_settings_section'
    147152            );
     153
     154            // WooCommerce Settings.
     155            if ( is_woocommerce_active() ) {
     156                add_settings_section(
     157                    'sdcom_timestamps_woocommerce_settings_section',
     158                    null,
     159                    [ $this, 'woocommerce_settings_section' ],
     160                    $this->settings_page
     161                );
     162
     163                add_settings_field(
     164                    'sdcom_timestamps_enable_timestamps_woocommerce_orders',
     165                    __( 'Enable Timestamps on WooCommerce Orders', 'timestamps' ),
     166                    [ $this, 'enable_timestamps_woocommerce_orders_settings_field_callback' ],
     167                    $this->settings_page,
     168                    'sdcom_timestamps_woocommerce_settings_section'
     169                );
     170
     171                // Check if the option "enable_timestamps_woocommerce_orders" is present and is true.
     172                if ( ! empty( $option['enable_timestamps_woocommerce_orders'] ) && $option['enable_timestamps_woocommerce_orders'] === 'true' ) {
     173                    add_settings_field(
     174                        'sdcom_timestamps_delete_certificates_old_woocommerce_orders_age',
     175                        __( 'Delete Old Certificates by WooCommerce Order Age', 'timestamps' ),
     176                        [ $this, 'delete_certificates_old_woocommerce_orders_age_settings_field_callback' ],
     177                        $this->settings_page,
     178                        'sdcom_timestamps_woocommerce_settings_section'
     179                    );
     180
     181                    add_settings_field(
     182                        'sdcom_timestamps_woocommerce_order_statuses_marked_old_certificates',
     183                        __( 'WooCommerce Order Statuses Marked for Old Certificates', 'timestamps' ),
     184                        [ $this, 'woocommerce_order_statuses_marked_old_certificates_settings_field_callback' ],
     185                        $this->settings_page,
     186                        'sdcom_timestamps_woocommerce_settings_section'
     187                    );
     188                }
     189            }
    148190        }
    149191    }
     
    185227
    186228    /**
     229     * Outputs the WooCommerce settings section.
     230     *
     231     * @since 1.3.0
     232     * @return void
     233     */
     234    public function woocommerce_settings_section() {
     235        echo wp_kses_post(
     236            sprintf(
     237                '<h2>%s</h2>',
     238                __( 'WooCommerce Settings', 'timestamps' )
     239            )
     240        );
     241    }
     242
     243    /**
    187244     * Outputs the "Display Created By" settings input checkbox field.
    188245     *
     
    195252        $option = get_option( SDCOM_TIMESTAMPS_OPTIONS );
    196253
    197         $display_created_by = ! empty( $option['display_created_by'] ) ? $option['display_created_by'] : false;
     254        $display_created_by = get_plugin_option( 'display_created_by', false );
    198255        $username           = ! empty( $option['username'] ) && $display_created_by ? $option['username'] : 'anonymous';
    199256        $date_and_time      = current_time( 'l, F j, Y \a\t g:i:s A' );
     
    224281                    wp_kses_post(
    225282                        sprintf(
     283                            /* translators: %s: username */
    226284                            __( 'by %s', 'timestamps' ),
    227285                            $username
     
    253311
    254312    /**
     313     * Outputs the "Enable Timestamps on WooCommerce Orders" settings input checkbox field.
     314     *
     315     * If the option value is present, the checkbox will be checked.
     316     * If the option value is not present, the checkbox will be unchecked.
     317     *
     318     * @since 1.3.0
     319     * @return void
     320     */
     321    public function enable_timestamps_woocommerce_orders_settings_field_callback() {
     322        $option = get_option( SDCOM_TIMESTAMPS_OPTIONS );
     323
     324        printf(
     325            '<label><input type="checkbox" name="' . esc_attr( SDCOM_TIMESTAMPS_OPTIONS ) . '[enable_timestamps_woocommerce_orders]" id="enable_timestamps_woocommerce_orders" value="true" %s> %s</label><p class="description">%s</p>',
     326            checked( isset( $option['enable_timestamps_woocommerce_orders'] ), true, false ),
     327            wp_kses_post( __( 'Active', 'timestamps' ) ),
     328            wp_kses_post( __( 'Adds Timestamps to WooCommerce Orders.', 'timestamps' ) ),
     329        );
     330    }
     331
     332    /**
     333     * Outputs the "Delete Old Certificates by WooCommerce Order Age" settings input number field.
     334     *
     335     * The default value is 365 days.
     336     *
     337     * @since 1.3.0
     338     * @return void
     339     */
     340    public function delete_certificates_old_woocommerce_orders_age_settings_field_callback() {
     341        $option = get_option( SDCOM_TIMESTAMPS_OPTIONS );
     342
     343        // Get the value from the option, or use the default value of 365 days.
     344        $value = isset( $option['delete_certificates_old_woocommerce_orders_age'] ) && ! empty( $option['delete_certificates_old_woocommerce_orders_age'] ) ? $option['delete_certificates_old_woocommerce_orders_age'] : 365;
     345
     346        printf(
     347            '<label><input type="number" min="0" name="' . esc_attr( SDCOM_TIMESTAMPS_OPTIONS ) . '[delete_certificates_old_woocommerce_orders_age]" id="delete_certificates_old_woocommerce_orders_age" value="' . esc_attr( $value ) . '"> %s</label><p class="description">%s</p>',
     348            wp_kses_post( __( 'Days', 'timestamps' ) ),
     349            wp_kses_post( __( 'Automatically delete old certificates after a certain age. Defaults to 365 days.', 'timestamps' ) ),
     350        );
     351    }
     352
     353    /**
     354     * Outputs the "WooCommerce Order Statuses Marked for Old Certificates" settings input checkbox field.
     355     *
     356     * The default value is _all_ WooCommerce order statuses.
     357     *
     358     * @since 1.3.0
     359     *
     360     * @return void
     361     */
     362    public function woocommerce_order_statuses_marked_old_certificates_settings_field_callback() {
     363        $option = get_option( SDCOM_TIMESTAMPS_OPTIONS );
     364
     365        // Get the WooCommerce order statuses.
     366        $order_statuses = wc_get_order_statuses();
     367
     368        // Sort the $order_statuses in alphabetical order.
     369        ksort( $order_statuses );
     370
     371        // If the option value is not present, set the default value to all WooCommerce order statuses.
     372        if ( empty( $option['woocommerce_order_statuses_marked_old_certificates'] ) ) {
     373            $option['woocommerce_order_statuses_marked_old_certificates'] = array_keys( $order_statuses );
     374        }
     375
     376        // Loop through the WooCommerce order statuses as checkbox elements.
     377        foreach ( $order_statuses as $key => $value ) {
     378            $is_checked = in_array( $key, $option['woocommerce_order_statuses_marked_old_certificates'], true );
     379            printf(
     380                '<input type="checkbox" name="%s[woocommerce_order_statuses_marked_old_certificates][]" value="%s" %s>%s<br>',
     381                esc_attr( SDCOM_TIMESTAMPS_OPTIONS ),
     382                esc_attr( $key ),
     383                checked( $is_checked, true, false ),
     384                esc_html( $value )
     385            );
     386        }
     387
     388        printf(
     389            '<p class="description">%s</p>',
     390            wp_kses_post( __( 'Select the statuses to mark for old certificates.', 'timestamps' ) ),
     391        );
     392    }
     393
     394    /**
    255395     * Render settings page.
    256396     *
     
    258398     */
    259399    public function render_settings_page() {
    260         // get the timestamps options.
    261         $timestamps_options    = get_option( SDCOM_TIMESTAMPS_OPTIONS );
    262         $timestamps_api_key    = isset( $timestamps_options['api_key'] ) ? $timestamps_options['api_key'] : '';
    263         $timestamps_username   = isset( $timestamps_options['username'] ) ? $timestamps_options['username'] : '';
    264         $timestamps_avatar_url = isset( $timestamps_options['avatar_url'] ) ? $timestamps_options['avatar_url'] : '';
     400        // Get the timestamps options.
     401        $timestamps_api_key    = get_plugin_option( 'api_key', '' );
     402        $timestamps_username   = get_plugin_option( 'username', '' );
     403        $timestamps_avatar_url = get_plugin_option( 'avatar_url', '' );
    265404        ?>
    266405        <div class="wrap">
  • timestamps/tags/1.3.0/includes/utils.php

    r3073868 r3106064  
    3737
    3838/**
    39  * Use the correct update option function depending on the context.
    40  *
    41  * @since 1.0.0
    42  * @param string $option   Name of the option to update.
    43  * @param mixed  $value    Option value.
    44  * @param mixed  $autoload Whether to load the option when WordPress starts up.
    45  * @return bool
    46  */
    47 function update_option( $option, $value, $autoload = null ) {
    48     return \update_option( $option, $value, $autoload );
    49 }
    50 
    51 /**
    52  * Use the correct get option function depending on the context.
    53  *
    54  * @since 1.0.0
    55  * @param string $option        Name of the option to get.
    56  * @param mixed  $default_value Default value.
    57  * @return mixed
    58  */
    59 function get_option( $option, $default_value = false ) {
    60     return \get_option( $option, $default_value );
    61 }
    62 
    63 /**
    64  * Use the correct delete option function depending on the context.
    65  *
    66  * @since 1.0.0
    67  * @param string $option Name of the option to delete.
    68  * @return bool
    69  */
    70 function delete_option( $option ) {
    71     return \delete_option( $option );
    72 }
    73 
    74 /**
    7539 * Checks if the user is authenticated.
    7640 *
     
    8145 */
    8246function is_authenticated() {
    83     $timestamps_options = get_option( SDCOM_TIMESTAMPS_OPTIONS );
    84     $timestamps_api_key = isset( $timestamps_options['api_key'] ) ? $timestamps_options['api_key'] : '';
     47    $timestamps_api_key = get_plugin_option( 'api_key', '' );
    8548
    8649    return ! empty( $timestamps_api_key );
     
    9558function is_block_editor_active() {
    9659
    97     $classic_editor_replace = \get_option( 'classic-editor-replace' );
     60    $classic_editor_replace = get_option( 'classic-editor-replace' );
    9861
    9962    // We assume that the Block Editor is active, whilst the Classic Editor plugin never existed.
     
    152115    return false;
    153116}
     117
     118/**
     119 * Checks if the WooCommerce plugin is active.
     120 *
     121 * @since 1.3.0
     122 * @return bool Returns true if the WooCommerce plugin is active, false otherwise.
     123 */
     124function is_woocommerce_active() {
     125    return class_exists( 'WooCommerce' );
     126}
     127
     128/**
     129 * Gets the WooCommerce volatile order data keys.
     130 *
     131 * This function returns an array of keys that represent volatile data in a WooCommerce order.
     132 *
     133 * @since 1.3.0
     134 * @return array Filtered volatile order data keys.
     135 */
     136function get_wc_volatile_order_data_keys() {
     137    $wc_volatile_order_data_keys = [ 'date_modified', 'meta_data', 'version' ];
     138
     139    return apply_filters( 'sdcom_timestamps_wc_volatile_order_data_keys', $wc_volatile_order_data_keys );
     140}
     141
     142/**
     143 * Checks if timestamps for WooCommerce orders are active.
     144 *
     145 * @since 1.3.0
     146 * @return bool True if the option is active, false otherwise.
     147 */
     148function is_timestamps_woocommerce_orders_active(): bool {
     149    $timestamps_woocommerce_orders_enabled = get_plugin_option( 'enable_timestamps_woocommerce_orders', '' );
     150
     151    return ! empty( $timestamps_woocommerce_orders_enabled );
     152}
     153
     154/**
     155 * Gets the certificate URL for a WooCommerce order.
     156 *
     157 * @param \WC_Order $order The WooCommerce order object.
     158 * @since 1.3.0
     159 * @return string The certificate URL.
     160 */
     161function get_certificate_url_wc_order( $order ): string {
     162    $sdcom_previous_certificate_id = $order->get_meta( 'sdcom_previous_certificate_id' );
     163
     164    // Bail early if there is no previous certificate id.
     165    if ( empty( $sdcom_previous_certificate_id ) ) {
     166        return '';
     167    }
     168
     169    return apply_filters( 'get_certificate_url_wc_order', esc_url( 'https://scoredetect.com/certificate/' . $sdcom_previous_certificate_id ), $order );
     170}
     171
     172/**
     173 * Gets the plugin option.
     174 *
     175 * If the option does not exist, the default value is returned.
     176 *
     177 * @param string $option_key    Name of the option to retrieve. Expected to not be SQL-escaped.
     178 * @param mixed  $default_value Optional. Default value to return if the option does not exist.
     179 * @since 1.3.0
     180 * @return mixed Value of the option. A value of any type may be returned, including
     181 *               scalar (string, boolean, float, integer), null, array, object.
     182 *               Scalar and null values will be returned as strings as long as they originate
     183 *               from a database stored option value. If there is no option in the database,
     184 *               boolean `false` is returned.
     185 */
     186function get_plugin_option( $option_key, $default_value = false ) {
     187    $timestamps_options = get_option( SDCOM_TIMESTAMPS_OPTIONS );
     188
     189    if ( empty( $timestamps_options ) ) {
     190        return false;
     191    }
     192
     193    if ( isset( $timestamps_options[ $option_key ] ) ) {
     194        return $timestamps_options[ $option_key ];
     195    }
     196
     197    return $default_value;
     198}
  • timestamps/tags/1.3.0/package-lock.json

    r3073868 r3106064  
    11{
    22  "name": "timestamps-plugin",
    3   "version": "1.1.0",
     3  "version": "1.2.1",
    44  "lockfileVersion": 3,
    55  "requires": true,
     
    77    "": {
    88      "name": "timestamps-plugin",
    9       "version": "1.1.0",
     9      "version": "1.2.1",
    1010      "dependencies": {
    1111        "@supabase/supabase-js": "^2.39.3",
  • timestamps/tags/1.3.0/package.json

    r3081650 r3106064  
    11{
    22  "name": "timestamps-plugin",
    3   "version": "1.2.1",
     3  "version": "1.3.0",
    44  "description": "Timestamp your WordPress content to empower your content authenticity and increase user trust with our blockchain timestamping solution.",
    55  "homepage": "https://www.scoredetect.com/",
  • timestamps/tags/1.3.0/readme.txt

    r3081650 r3106064  
    1 === Timestamps ===
     1=== Timestamps – Blockchain Integration for WordPress ===
    22Contributors: scoredetect, xmic
    33Tags: timestamp, blockchain, content, authenticity, copyright, timestamps, protection, verification, proof, timestamping
     
    55Tested up to: 6.5.2
    66Requires PHP: 7.4
    7 Stable tag: 1.2.1
     7Stable tag: 1.3.0
    88License: AGPL-3.0-only
    99License URI: https://spdx.org/licenses/AGPL-3.0-only.html
    1010
    11 Timestamp your WordPress content to empower your content authenticity and increase user trust with our blockchain timestamping solution.
     11No blockchain skills needed. Timestamp your WordPress content to empower your content authenticity and increase user trust.
    1212
    1313== Description ==
    14 Timestamps allow you to increase content authenticity by displaying a rich timeline of your post updates. The timeline can be independently verified by the public, as a verification factor for your content.
     14Timestamps allow you to increase content authenticity by displaying a rich timeline of your post updates. The timeline can be independently verified by the public.
    1515
    1616Here is a list of features included in the plugin:
  • timestamps/tags/1.3.0/timestamps.php

    r3081650 r3106064  
    99 *
    1010 * @link              https://www.scoredetect.com/
    11  * @since             1.2.1
     11 * @since             1.3.0
    1212 * @package           SDCOM_Timestamps
    1313 *
    1414 * @wordpress-plugin
    1515 * Plugin Name:       Timestamps
    16  * Description:       Timestamp your WordPress content to empower your content authenticity and increase user trust with our blockchain timestamping solution.
    17  * Version:           1.2.1
     16 * Description:       Timestamp your WordPress content to empower your content authenticity and increase user trust. No blockchain skills needed.
     17 * Version:           1.3.0
    1818 * Author:            ScoreDetect.com
    1919 * Author URI:        https://www.scoredetect.com/
     
    3232
    3333// Useful global constants.
    34 define( 'SDCOM_TIMESTAMPS_VERSION', '1.2.1' );
     34define( 'SDCOM_TIMESTAMPS_VERSION', '1.3.0' );
    3535define( 'SDCOM_TIMESTAMPS_OPTIONS', 'sdcom_timestamps' );
    3636define( 'SDCOM_TIMESTAMPS_URL', plugin_dir_url( __FILE__ ) );
     
    100100        new Feature\Timestamp\Timestamp()
    101101    );
     102    Features::factory()->register_feature(
     103        new Feature\WooCommerce\Orders()
     104    );
    102105}
    103106add_action( 'plugins_loaded', __NAMESPACE__ . '\register_features' );
  • timestamps/trunk/includes/classes/AdminNotices.php

    r3048002 r3106064  
    1313use SDCOM_Timestamps\Utils;
    1414use SDCOM_Timestamps\Screen;
     15
     16use function SDCOM_Timestamps\Utils\get_plugin_option;
    1517
    1618if ( ! defined( 'ABSPATH' ) ) {
     
    7072    protected function process_need_setup_notice() {
    7173
    72         $timestamps_options = get_option( SDCOM_TIMESTAMPS_OPTIONS );
    73         $timestamps_api_key = isset( $timestamps_options['api_key'] ) ? $timestamps_options['api_key'] : '';
     74        $timestamps_api_key = get_plugin_option( 'api_key', '' );
    7475
    7576        if ( ! empty( $timestamps_api_key ) ) {
     
    7778        }
    7879
    79         $dismiss = Utils\get_option( 'sdcom_timestamps_hide_need_setup_notice', false );
     80        $dismiss = get_option( 'sdcom_timestamps_hide_need_setup_notice', false );
    8081
    8182        if ( $dismiss ) {
     
    128129        $value = true;
    129130
    130         Utils\update_option( 'timestamps_hide_' . $notice . '_notice', $value );
     131        update_option( 'timestamps_hide_' . $notice . '_notice', $value );
    131132    }
    132133
  • timestamps/trunk/includes/classes/Feature/Timestamp/Timestamp.php

    r3076784 r3106064  
    1212use SDCOM_Timestamps\Utils;
    1313
     14use function SDCOM_Timestamps\Utils\get_plugin_option;
     15
    1416/**
    1517 * Timestamp feature class
     
    4850
    4951    /**
    50      * We need to delay setup up since it will fire after protected content and protected
    51      * content filters into the setup.
     52     * We need to delay setup up until init to ensure all plugins are loaded.
    5253     *
    5354     * @since 1.0.0
     
    160161        wp_set_script_translations( 'timestamp-post-editor', 'timestamps' );
    161162
    162         $timestamps_options = get_option( SDCOM_TIMESTAMPS_OPTIONS );
    163         $timestamps_api_key = isset( $timestamps_options['api_key'] ) ? $timestamps_options['api_key'] : '';
     163        $timestamps_api_key = get_plugin_option( 'api_key', '' );
    164164
    165165        wp_localize_script(
     
    259259                update_post_meta( $post_id, 'sdcom_timestamp_post', true );
    260260
    261                 $create_certificate = $this->create_certificate( $post );
     261                $create_certificate = $this->create_certificate_post( $post );
    262262
    263263                // Handle the case where the method returned false.
     
    273273                }
    274274
    275                 $update_certificate = $this->update_certificate( $post, $certificate_id );
     275                $update_certificate = $this->update_certificate_post( $post, $certificate_id );
    276276
    277277                // Handle the case where the method returned false.
     
    352352            }
    353353
    354             $create_certificate = $this->create_certificate( $post );
     354            $create_certificate = $this->create_certificate_post( $post );
    355355
    356356            // Handle the case where the method returned false.
     
    366366            }
    367367
    368             $update_certificate = $this->update_certificate( $post, $certificate_id );
     368            $update_certificate = $this->update_certificate_post( $post, $certificate_id );
    369369
    370370            // Handle the case where the method returned false.
     
    436436     * @throws \Exception If the options, post content, or API key is empty.
    437437     */
    438     private function create_certificate( $post ) {
     438    private function create_certificate_post( $post ) {
    439439        try {
    440440            $post_id                       = $post->ID;
     
    518518            }
    519519
     520            // Return the data.
    520521            return $data;
    521522
     
    534535     * @throws \Throwable If an exception occurs during the process.
    535536     */
    536     private function update_certificate( $post, $certificate_id ) {
     537    private function update_certificate_post( $post, $certificate_id ) {
    537538        try {
    538539            $post_content     = $post->post_content;
     
    575576            );
    576577
    577             $body = json_encode(
     578            $body = wp_json_encode(
    578579                array(
    579580                    'certificateId' => $certificate_id,
     
    619620            }
    620621
     622            // Return the data.
    621623            return $data;
    622624
  • timestamps/trunk/includes/classes/Screen/Settings.php

    r3048002 r3106064  
    1313use SDCOM_Timestamps\Utils;
    1414
     15use function SDCOM_Timestamps\Utils\get_plugin_option;
    1516use function SDCOM_Timestamps\Utils\is_authenticated;
     17use function SDCOM_Timestamps\Utils\is_woocommerce_active;
    1618
    1719if ( ! defined( 'ABSPATH' ) ) {
     
    8385     */
    8486    public function register_settings() {
     87
     88        $option = get_option( SDCOM_TIMESTAMPS_OPTIONS );
     89
    8590        register_setting(
    8691            SDCOM_TIMESTAMPS_OPTIONS,
     
    146151                'sdcom_timestamps_general_settings_section'
    147152            );
     153
     154            // WooCommerce Settings.
     155            if ( is_woocommerce_active() ) {
     156                add_settings_section(
     157                    'sdcom_timestamps_woocommerce_settings_section',
     158                    null,
     159                    [ $this, 'woocommerce_settings_section' ],
     160                    $this->settings_page
     161                );
     162
     163                add_settings_field(
     164                    'sdcom_timestamps_enable_timestamps_woocommerce_orders',
     165                    __( 'Enable Timestamps on WooCommerce Orders', 'timestamps' ),
     166                    [ $this, 'enable_timestamps_woocommerce_orders_settings_field_callback' ],
     167                    $this->settings_page,
     168                    'sdcom_timestamps_woocommerce_settings_section'
     169                );
     170
     171                // Check if the option "enable_timestamps_woocommerce_orders" is present and is true.
     172                if ( ! empty( $option['enable_timestamps_woocommerce_orders'] ) && $option['enable_timestamps_woocommerce_orders'] === 'true' ) {
     173                    add_settings_field(
     174                        'sdcom_timestamps_delete_certificates_old_woocommerce_orders_age',
     175                        __( 'Delete Old Certificates by WooCommerce Order Age', 'timestamps' ),
     176                        [ $this, 'delete_certificates_old_woocommerce_orders_age_settings_field_callback' ],
     177                        $this->settings_page,
     178                        'sdcom_timestamps_woocommerce_settings_section'
     179                    );
     180
     181                    add_settings_field(
     182                        'sdcom_timestamps_woocommerce_order_statuses_marked_old_certificates',
     183                        __( 'WooCommerce Order Statuses Marked for Old Certificates', 'timestamps' ),
     184                        [ $this, 'woocommerce_order_statuses_marked_old_certificates_settings_field_callback' ],
     185                        $this->settings_page,
     186                        'sdcom_timestamps_woocommerce_settings_section'
     187                    );
     188                }
     189            }
    148190        }
    149191    }
     
    185227
    186228    /**
     229     * Outputs the WooCommerce settings section.
     230     *
     231     * @since 1.3.0
     232     * @return void
     233     */
     234    public function woocommerce_settings_section() {
     235        echo wp_kses_post(
     236            sprintf(
     237                '<h2>%s</h2>',
     238                __( 'WooCommerce Settings', 'timestamps' )
     239            )
     240        );
     241    }
     242
     243    /**
    187244     * Outputs the "Display Created By" settings input checkbox field.
    188245     *
     
    195252        $option = get_option( SDCOM_TIMESTAMPS_OPTIONS );
    196253
    197         $display_created_by = ! empty( $option['display_created_by'] ) ? $option['display_created_by'] : false;
     254        $display_created_by = get_plugin_option( 'display_created_by', false );
    198255        $username           = ! empty( $option['username'] ) && $display_created_by ? $option['username'] : 'anonymous';
    199256        $date_and_time      = current_time( 'l, F j, Y \a\t g:i:s A' );
     
    224281                    wp_kses_post(
    225282                        sprintf(
     283                            /* translators: %s: username */
    226284                            __( 'by %s', 'timestamps' ),
    227285                            $username
     
    253311
    254312    /**
     313     * Outputs the "Enable Timestamps on WooCommerce Orders" settings input checkbox field.
     314     *
     315     * If the option value is present, the checkbox will be checked.
     316     * If the option value is not present, the checkbox will be unchecked.
     317     *
     318     * @since 1.3.0
     319     * @return void
     320     */
     321    public function enable_timestamps_woocommerce_orders_settings_field_callback() {
     322        $option = get_option( SDCOM_TIMESTAMPS_OPTIONS );
     323
     324        printf(
     325            '<label><input type="checkbox" name="' . esc_attr( SDCOM_TIMESTAMPS_OPTIONS ) . '[enable_timestamps_woocommerce_orders]" id="enable_timestamps_woocommerce_orders" value="true" %s> %s</label><p class="description">%s</p>',
     326            checked( isset( $option['enable_timestamps_woocommerce_orders'] ), true, false ),
     327            wp_kses_post( __( 'Active', 'timestamps' ) ),
     328            wp_kses_post( __( 'Adds Timestamps to WooCommerce Orders.', 'timestamps' ) ),
     329        );
     330    }
     331
     332    /**
     333     * Outputs the "Delete Old Certificates by WooCommerce Order Age" settings input number field.
     334     *
     335     * The default value is 365 days.
     336     *
     337     * @since 1.3.0
     338     * @return void
     339     */
     340    public function delete_certificates_old_woocommerce_orders_age_settings_field_callback() {
     341        $option = get_option( SDCOM_TIMESTAMPS_OPTIONS );
     342
     343        // Get the value from the option, or use the default value of 365 days.
     344        $value = isset( $option['delete_certificates_old_woocommerce_orders_age'] ) && ! empty( $option['delete_certificates_old_woocommerce_orders_age'] ) ? $option['delete_certificates_old_woocommerce_orders_age'] : 365;
     345
     346        printf(
     347            '<label><input type="number" min="0" name="' . esc_attr( SDCOM_TIMESTAMPS_OPTIONS ) . '[delete_certificates_old_woocommerce_orders_age]" id="delete_certificates_old_woocommerce_orders_age" value="' . esc_attr( $value ) . '"> %s</label><p class="description">%s</p>',
     348            wp_kses_post( __( 'Days', 'timestamps' ) ),
     349            wp_kses_post( __( 'Automatically delete old certificates after a certain age. Defaults to 365 days.', 'timestamps' ) ),
     350        );
     351    }
     352
     353    /**
     354     * Outputs the "WooCommerce Order Statuses Marked for Old Certificates" settings input checkbox field.
     355     *
     356     * The default value is _all_ WooCommerce order statuses.
     357     *
     358     * @since 1.3.0
     359     *
     360     * @return void
     361     */
     362    public function woocommerce_order_statuses_marked_old_certificates_settings_field_callback() {
     363        $option = get_option( SDCOM_TIMESTAMPS_OPTIONS );
     364
     365        // Get the WooCommerce order statuses.
     366        $order_statuses = wc_get_order_statuses();
     367
     368        // Sort the $order_statuses in alphabetical order.
     369        ksort( $order_statuses );
     370
     371        // If the option value is not present, set the default value to all WooCommerce order statuses.
     372        if ( empty( $option['woocommerce_order_statuses_marked_old_certificates'] ) ) {
     373            $option['woocommerce_order_statuses_marked_old_certificates'] = array_keys( $order_statuses );
     374        }
     375
     376        // Loop through the WooCommerce order statuses as checkbox elements.
     377        foreach ( $order_statuses as $key => $value ) {
     378            $is_checked = in_array( $key, $option['woocommerce_order_statuses_marked_old_certificates'], true );
     379            printf(
     380                '<input type="checkbox" name="%s[woocommerce_order_statuses_marked_old_certificates][]" value="%s" %s>%s<br>',
     381                esc_attr( SDCOM_TIMESTAMPS_OPTIONS ),
     382                esc_attr( $key ),
     383                checked( $is_checked, true, false ),
     384                esc_html( $value )
     385            );
     386        }
     387
     388        printf(
     389            '<p class="description">%s</p>',
     390            wp_kses_post( __( 'Select the statuses to mark for old certificates.', 'timestamps' ) ),
     391        );
     392    }
     393
     394    /**
    255395     * Render settings page.
    256396     *
     
    258398     */
    259399    public function render_settings_page() {
    260         // get the timestamps options.
    261         $timestamps_options    = get_option( SDCOM_TIMESTAMPS_OPTIONS );
    262         $timestamps_api_key    = isset( $timestamps_options['api_key'] ) ? $timestamps_options['api_key'] : '';
    263         $timestamps_username   = isset( $timestamps_options['username'] ) ? $timestamps_options['username'] : '';
    264         $timestamps_avatar_url = isset( $timestamps_options['avatar_url'] ) ? $timestamps_options['avatar_url'] : '';
     400        // Get the timestamps options.
     401        $timestamps_api_key    = get_plugin_option( 'api_key', '' );
     402        $timestamps_username   = get_plugin_option( 'username', '' );
     403        $timestamps_avatar_url = get_plugin_option( 'avatar_url', '' );
    265404        ?>
    266405        <div class="wrap">
  • timestamps/trunk/includes/utils.php

    r3073868 r3106064  
    3737
    3838/**
    39  * Use the correct update option function depending on the context.
    40  *
    41  * @since 1.0.0
    42  * @param string $option   Name of the option to update.
    43  * @param mixed  $value    Option value.
    44  * @param mixed  $autoload Whether to load the option when WordPress starts up.
    45  * @return bool
    46  */
    47 function update_option( $option, $value, $autoload = null ) {
    48     return \update_option( $option, $value, $autoload );
    49 }
    50 
    51 /**
    52  * Use the correct get option function depending on the context.
    53  *
    54  * @since 1.0.0
    55  * @param string $option        Name of the option to get.
    56  * @param mixed  $default_value Default value.
    57  * @return mixed
    58  */
    59 function get_option( $option, $default_value = false ) {
    60     return \get_option( $option, $default_value );
    61 }
    62 
    63 /**
    64  * Use the correct delete option function depending on the context.
    65  *
    66  * @since 1.0.0
    67  * @param string $option Name of the option to delete.
    68  * @return bool
    69  */
    70 function delete_option( $option ) {
    71     return \delete_option( $option );
    72 }
    73 
    74 /**
    7539 * Checks if the user is authenticated.
    7640 *
     
    8145 */
    8246function is_authenticated() {
    83     $timestamps_options = get_option( SDCOM_TIMESTAMPS_OPTIONS );
    84     $timestamps_api_key = isset( $timestamps_options['api_key'] ) ? $timestamps_options['api_key'] : '';
     47    $timestamps_api_key = get_plugin_option( 'api_key', '' );
    8548
    8649    return ! empty( $timestamps_api_key );
     
    9558function is_block_editor_active() {
    9659
    97     $classic_editor_replace = \get_option( 'classic-editor-replace' );
     60    $classic_editor_replace = get_option( 'classic-editor-replace' );
    9861
    9962    // We assume that the Block Editor is active, whilst the Classic Editor plugin never existed.
     
    152115    return false;
    153116}
     117
     118/**
     119 * Checks if the WooCommerce plugin is active.
     120 *
     121 * @since 1.3.0
     122 * @return bool Returns true if the WooCommerce plugin is active, false otherwise.
     123 */
     124function is_woocommerce_active() {
     125    return class_exists( 'WooCommerce' );
     126}
     127
     128/**
     129 * Gets the WooCommerce volatile order data keys.
     130 *
     131 * This function returns an array of keys that represent volatile data in a WooCommerce order.
     132 *
     133 * @since 1.3.0
     134 * @return array Filtered volatile order data keys.
     135 */
     136function get_wc_volatile_order_data_keys() {
     137    $wc_volatile_order_data_keys = [ 'date_modified', 'meta_data', 'version' ];
     138
     139    return apply_filters( 'sdcom_timestamps_wc_volatile_order_data_keys', $wc_volatile_order_data_keys );
     140}
     141
     142/**
     143 * Checks if timestamps for WooCommerce orders are active.
     144 *
     145 * @since 1.3.0
     146 * @return bool True if the option is active, false otherwise.
     147 */
     148function is_timestamps_woocommerce_orders_active(): bool {
     149    $timestamps_woocommerce_orders_enabled = get_plugin_option( 'enable_timestamps_woocommerce_orders', '' );
     150
     151    return ! empty( $timestamps_woocommerce_orders_enabled );
     152}
     153
     154/**
     155 * Gets the certificate URL for a WooCommerce order.
     156 *
     157 * @param \WC_Order $order The WooCommerce order object.
     158 * @since 1.3.0
     159 * @return string The certificate URL.
     160 */
     161function get_certificate_url_wc_order( $order ): string {
     162    $sdcom_previous_certificate_id = $order->get_meta( 'sdcom_previous_certificate_id' );
     163
     164    // Bail early if there is no previous certificate id.
     165    if ( empty( $sdcom_previous_certificate_id ) ) {
     166        return '';
     167    }
     168
     169    return apply_filters( 'get_certificate_url_wc_order', esc_url( 'https://scoredetect.com/certificate/' . $sdcom_previous_certificate_id ), $order );
     170}
     171
     172/**
     173 * Gets the plugin option.
     174 *
     175 * If the option does not exist, the default value is returned.
     176 *
     177 * @param string $option_key    Name of the option to retrieve. Expected to not be SQL-escaped.
     178 * @param mixed  $default_value Optional. Default value to return if the option does not exist.
     179 * @since 1.3.0
     180 * @return mixed Value of the option. A value of any type may be returned, including
     181 *               scalar (string, boolean, float, integer), null, array, object.
     182 *               Scalar and null values will be returned as strings as long as they originate
     183 *               from a database stored option value. If there is no option in the database,
     184 *               boolean `false` is returned.
     185 */
     186function get_plugin_option( $option_key, $default_value = false ) {
     187    $timestamps_options = get_option( SDCOM_TIMESTAMPS_OPTIONS );
     188
     189    if ( empty( $timestamps_options ) ) {
     190        return false;
     191    }
     192
     193    if ( isset( $timestamps_options[ $option_key ] ) ) {
     194        return $timestamps_options[ $option_key ];
     195    }
     196
     197    return $default_value;
     198}
  • timestamps/trunk/package-lock.json

    r3073868 r3106064  
    11{
    22  "name": "timestamps-plugin",
    3   "version": "1.1.0",
     3  "version": "1.2.1",
    44  "lockfileVersion": 3,
    55  "requires": true,
     
    77    "": {
    88      "name": "timestamps-plugin",
    9       "version": "1.1.0",
     9      "version": "1.2.1",
    1010      "dependencies": {
    1111        "@supabase/supabase-js": "^2.39.3",
  • timestamps/trunk/package.json

    r3081650 r3106064  
    11{
    22  "name": "timestamps-plugin",
    3   "version": "1.2.1",
     3  "version": "1.3.0",
    44  "description": "Timestamp your WordPress content to empower your content authenticity and increase user trust with our blockchain timestamping solution.",
    55  "homepage": "https://www.scoredetect.com/",
  • timestamps/trunk/readme.txt

    r3081650 r3106064  
    1 === Timestamps ===
     1=== Timestamps – Blockchain Integration for WordPress ===
    22Contributors: scoredetect, xmic
    33Tags: timestamp, blockchain, content, authenticity, copyright, timestamps, protection, verification, proof, timestamping
     
    55Tested up to: 6.5.2
    66Requires PHP: 7.4
    7 Stable tag: 1.2.1
     7Stable tag: 1.3.0
    88License: AGPL-3.0-only
    99License URI: https://spdx.org/licenses/AGPL-3.0-only.html
    1010
    11 Timestamp your WordPress content to empower your content authenticity and increase user trust with our blockchain timestamping solution.
     11No blockchain skills needed. Timestamp your WordPress content to empower your content authenticity and increase user trust.
    1212
    1313== Description ==
    14 Timestamps allow you to increase content authenticity by displaying a rich timeline of your post updates. The timeline can be independently verified by the public, as a verification factor for your content.
     14Timestamps allow you to increase content authenticity by displaying a rich timeline of your post updates. The timeline can be independently verified by the public.
    1515
    1616Here is a list of features included in the plugin:
  • timestamps/trunk/timestamps.php

    r3081650 r3106064  
    99 *
    1010 * @link              https://www.scoredetect.com/
    11  * @since             1.2.1
     11 * @since             1.3.0
    1212 * @package           SDCOM_Timestamps
    1313 *
    1414 * @wordpress-plugin
    1515 * Plugin Name:       Timestamps
    16  * Description:       Timestamp your WordPress content to empower your content authenticity and increase user trust with our blockchain timestamping solution.
    17  * Version:           1.2.1
     16 * Description:       Timestamp your WordPress content to empower your content authenticity and increase user trust. No blockchain skills needed.
     17 * Version:           1.3.0
    1818 * Author:            ScoreDetect.com
    1919 * Author URI:        https://www.scoredetect.com/
     
    3232
    3333// Useful global constants.
    34 define( 'SDCOM_TIMESTAMPS_VERSION', '1.2.1' );
     34define( 'SDCOM_TIMESTAMPS_VERSION', '1.3.0' );
    3535define( 'SDCOM_TIMESTAMPS_OPTIONS', 'sdcom_timestamps' );
    3636define( 'SDCOM_TIMESTAMPS_URL', plugin_dir_url( __FILE__ ) );
     
    100100        new Feature\Timestamp\Timestamp()
    101101    );
     102    Features::factory()->register_feature(
     103        new Feature\WooCommerce\Orders()
     104    );
    102105}
    103106add_action( 'plugins_loaded', __NAMESPACE__ . '\register_features' );
Note: See TracChangeset for help on using the changeset viewer.