Plugin Directory

Changeset 3427512


Ignore:
Timestamp:
12/26/2025 03:20:04 AM (3 months ago)
Author:
codename065
Message:

2.0.0 - 2025.12.26

✅ New visual table builder for Packages Table widget
✅ Drag-and-drop column configuration with Repeater control
✅ Multi-select data fields dropdown (20+ fields available)
✅ Column width and text alignment options per column
✅ Legacy mode toggle for backward compatibility
✅ Added BaseWidget abstract class for all widgets
✅ Added input sanitization for all widget settings
✅ Added dependency check for WPDM and Elementor
✅ Added Composer PSR-4 autoloading support
✅ Added style controls helpers (container, typography)
✅ Added new REST endpoint for category search
✅ Improved REST API security with prepared statements
✅ Improved code organization with proper namespacing

  • Fixed taxonomy typo in helper functions
  • Fixed hook timing issues for Elementor and REST API
  • Fixed categories array handling in Packages Table widget

✅ Updated all widgets to use new BaseWidget class

Location:
wpdm-elementor/trunk
Files:
2 added
19 edited

Legend:

Unmodified
Added
Removed
  • wpdm-elementor/trunk/readme.txt

    r3259585 r3427512  
    44Tags: download manager, elementor, document management, file manager, digital store, ecommerce, document management plugin,  download monitor
    55Requires at least: 5.3
    6 Tested up to: 6.7
     6Tested up to: 6.9
    77License: GPLv2 or later
    88
     
    1212== Description ==
    1313
    14 When you are using elementor and download manager together, you will not need to write download manager shortcodes manually anymore, this plugin provides configurable elementor modules for all download manager shortcode.
     14When you are using Elementor and Download Manager together, you will not need to write download manager shortcodes manually anymore. This plugin provides configurable Elementor widgets for all Download Manager features.
    1515
    1616= Addons =
    1717* Package - Embed a single file/package
    18 * Packages - Embed all packages with various filter
     18* Packages - Embed all packages with various filters
    1919* Packages by Category
    2020* Packages by Tags
    21 * All Downloads Table
     21* Packages Table - Visual table builder with drag-and-drop column configuration
    2222* Search and Search Result
    2323* User Registration Form
    2424* User Login Form
    2525* User Dashboard
     26
     27= Packages Table Builder =
     28Create beautiful download tables with our visual table builder:
     29* Drag-and-drop column ordering
     30* 20+ data fields (title, categories, download button, file size, etc.)
     31* Multiple fields per column support
     32* Custom column widths and text alignment
     33* DataTable.js integration for sorting and filtering
    2634
    2735== Installation ==
     
    3139
    3240== Changelog ==
     41
     42= 2.0.0 - 2025.12.26 =
     43✅ New visual table builder for Packages Table widget
     44✅ Drag-and-drop column configuration with Repeater control
     45✅ Multi-select data fields dropdown (20+ fields available)
     46✅ Column width and text alignment options per column
     47✅ Legacy mode toggle for backward compatibility
     48✅ Added BaseWidget abstract class for all widgets
     49✅ Added input sanitization for all widget settings
     50✅ Added dependency check for WPDM and Elementor
     51✅ Added Composer PSR-4 autoloading support
     52✅ Added style controls helpers (container, typography)
     53✅ Added new REST endpoint for category search
     54✅ Improved REST API security with prepared statements
     55✅ Improved code organization with proper namespacing
     56🐞 Fixed taxonomy typo in helper functions
     57🐞 Fixed hook timing issues for Elementor and REST API
     58🐞 Fixed categories array handling in Packages Table widget
     59✅ Updated all widgets to use new BaseWidget class
    3360
    3461= 1.3.0 - 2025.03.21 =
  • wpdm-elementor/trunk/src/Main.php

    r2932103 r3427512  
    11<?php
     2/**
     3 * Main plugin class for WPDM Elementor integration.
     4 *
     5 * @package WPDM\Elementor
     6 * @since   1.0.0
     7 */
    28
    39namespace WPDM\Elementor;
     
    1925use WPDM\Elementor\Widgets\UserProfileWidget;
    2026
     27/**
     28 * Class Main
     29 *
     30 * Handles the initialization and registration of WPDM widgets with Elementor.
     31 * Implements the Singleton pattern to ensure only one instance exists.
     32 *
     33 * @since 1.0.0
     34 */
    2135final class Main
    2236{
     37    /**
     38     * Plugin version.
     39     *
     40     * @var string
     41     */
     42    const VERSION = '2.0.0';
    2343
    2444    /**
    25      *
    26      *
     45     * Minimum Elementor version required.
     46     *
     47     * @var string
    2748     */
    28     public static function getInstance()
     49    const MINIMUM_ELEMENTOR_VERSION = '3.0.0';
     50
     51    /**
     52     * Minimum PHP version required.
     53     *
     54     * @var string
     55     */
     56    const MINIMUM_PHP_VERSION = '7.4';
     57
     58    /**
     59     * Get the singleton instance.
     60     *
     61     * Ensures only one instance of the class is loaded or can be loaded.
     62     *
     63     * @since  1.0.0
     64     * @return self The singleton instance.
     65     */
     66    public static function getInstance(): self
    2967    {
    3068        static $instance;
    3169        if (is_null($instance)) {
    32             $instance = new self;
     70            $instance = new self();
    3371        }
    3472        return $instance;
     
    3674
    3775    /**
    38      *
    39      *
     76     * Private constructor to prevent direct instantiation.
     77     *
     78     * Initializes the API and sets up WordPress hooks.
     79     *
     80     * @since 1.0.0
    4081     */
    4182    private function __construct()
    4283    {
    4384        API::getInstance();
    44         add_action("plugin_loaded", [$this, 'pluginLoaded']);
    4585
     86        // Load text domain
     87        load_plugin_textdomain(
     88            'wpdm-elementor',
     89            false,
     90            dirname(plugin_basename(__DIR__)) . '/languages/'
     91        );
     92
     93        // Register Elementor hooks - check if elementor/init already fired
     94        if (did_action('elementor/init')) {
     95            $this->addHooks();
     96        } else {
     97            add_action('elementor/init', [$this, 'addHooks']);
     98        }
    4699    }
    47100
    48     function pluginLoaded(){
    49         load_plugin_textdomain('wpdm-elementor', dirname(__DIR__) . "/languages/", basename(__DIR__).'/languages/');
    50         add_action( 'elementor/init', [ $this, 'addHooks' ] );
    51     }
    52 
    53 
    54101    /**
    55      *
    56      *
     102     * Register Elementor-specific hooks.
     103     *
     104     * Sets up category and widget registration hooks.
     105     *
     106     * @since 1.0.0
     107     * @return void
    57108     */
    58     function addHooks()
     109    public function addHooks(): void
    59110    {
    60111        add_action('elementor/elements/categories_registered', [$this, 'registerCategory'], 0);
     
    63114
    64115    /**
    65      *
    66      *
     116     * Register the WPDM widget category.
     117     *
     118     * Adds a 'Download Manager' category to the Elementor widget panel.
     119     *
     120     * @since 1.0.0
     121     * @param Elements_Manager $elements_manager Elementor elements manager instance.
     122     * @return void
    67123     */
    68     public function registerCategory(Elements_Manager $elementsManager)
     124    public function registerCategory(Elements_Manager $elements_manager): void
    69125    {
    70         $elementsManager->add_category('wpdm', ['title' => 'Download Manager']);
     126        $elements_manager->add_category(
     127            'wpdm',
     128            [
     129                'title' => __('Download Manager', WPDM_ELEMENTOR),
     130                'icon'  => 'eicon-download-button',
     131            ]
     132        );
    71133    }
    72134
    73135    /**
    74      *
    75      *
     136     * Register all WPDM widgets with Elementor.
     137     *
     138     * Includes the widget files and registers each widget class.
     139     *
     140     * @since 1.0.0
     141     * @param Widgets_Manager $widget_manager Elementor widgets manager instance.
     142     * @return void
    76143     */
    77     public function registerWidgets(Widgets_Manager $widget_manager)
     144    public function registerWidgets(Widgets_Manager $widget_manager): void
    78145    {
     146        require_once __DIR__ . '/includes.php';
    79147
    80         require_once __DIR__.'/includes.php';
     148        // Package-related widgets
     149        $widget_manager->register(new PackagesWidget());
     150        $widget_manager->register(new PackageWidget());
     151        $widget_manager->register(new CategoryWidget());
     152        $widget_manager->register(new AllPackagesWidget());
     153        $widget_manager->register(new SearchResultWidget());
     154        $widget_manager->register(new DirectLinkWidget());
    81155
    82 
    83         $widget_manager->register(new PackagesWidget());
    84 
    85         $widget_manager->register(new PackageWidget());
    86 
    87         $widget_manager->register(new CategoryWidget());
    88 
    89         //$widget_manager->register(new TagWidget());
    90 
    91         $widget_manager->register(new AllPackagesWidget());
    92 
    93         $widget_manager->register(new SearchResultWidget());
    94 
     156        // User-related widgets
    95157        $widget_manager->register(new RegFormWidget());
    96 
    97158        $widget_manager->register(new LoginFormWidget());
    98 
    99159        $widget_manager->register(new FrontendWidget());
    100 
    101160        $widget_manager->register(new UserDashboardWidget());
    102161
    103         $widget_manager->register(new DirectLinkWidget());
    104 
    105         //$widget_manager->register(new UserProfileWidget());
    106 
     162        // Disabled widgets (uncomment to enable)
     163        // $widget_manager->register(new TagWidget());
     164        // $widget_manager->register(new UserProfileWidget());
    107165    }
    108166
     167    /**
     168     * Get the plugin version.
     169     *
     170     * @since  1.3.0
     171     * @return string Plugin version.
     172     */
     173    public function getVersion(): string
     174    {
     175        return self::VERSION;
     176    }
    109177}
  • wpdm-elementor/trunk/src/api/API.php

    r2392526 r3427512  
    11<?php
     2/**
     3 * REST API endpoints for WPDM Elementor integration.
     4 *
     5 * @package WPDM\Elementor\API
     6 * @since   1.0.0
     7 */
    28
    39namespace WPDM\Elementor\API;
    410
     11use WP_REST_Request;
     12use WP_REST_Response;
    513
    6 
     14/**
     15 * Class API
     16 *
     17 * Handles REST API endpoints for the WPDM Elementor integration.
     18 * Provides package search functionality for SELECT2 dropdowns.
     19 *
     20 * @since 1.0.0
     21 */
    722class API
    823{
     24    /**
     25     * REST API namespace.
     26     *
     27     * @var string
     28     */
     29    const API_NAMESPACE = 'wpdm-elementor/v1';
    930
    10     public static function getInstance()
     31    /**
     32     * Get the singleton instance.
     33     *
     34     * @since  1.0.0
     35     * @return self The singleton instance.
     36     */
     37    public static function getInstance(): self
    1138    {
    1239        static $instance;
    1340        if (is_null($instance)) {
    14             $instance = new self;
     41            $instance = new self();
    1542        }
    1643        return $instance;
    1744    }
    1845
     46    /**
     47     * Private constructor.
     48     *
     49     * Registers the REST API initialization hook.
     50     *
     51     * @since 1.0.0
     52     */
    1953    private function __construct()
    2054    {
    21         add_action('rest_api_init', array($this, 'registerAPIEndpoints'));
     55        // Check if rest_api_init already fired
     56        if (did_action('rest_api_init')) {
     57            $this->registerAPIEndpoints();
     58        } else {
     59            add_action('rest_api_init', [$this, 'registerAPIEndpoints']);
     60        }
    2261    }
    2362
    24     public function registerAPIEndpoints()
     63    /**
     64     * Register REST API endpoints.
     65     *
     66     * @since 1.0.0
     67     * @return void
     68     */
     69    public function registerAPIEndpoints(): void
    2570    {
    26         register_rest_route('wpdm-elementor/v1', '/search-packages', [
    27             'methods' => 'GET',
    28             'callback' => [$this, 'searchPackages'],
    29             'permission_callback' => function () {
    30                 return true;
    31             }
    32         ]);
     71        register_rest_route(
     72            self::API_NAMESPACE,
     73            '/search-packages',
     74            [
     75                'methods'             => 'GET',
     76                'callback'            => [$this, 'searchPackages'],
     77                'permission_callback' => '__return_true',
     78            ]
     79        );
     80
     81        register_rest_route(
     82            self::API_NAMESPACE,
     83            '/search-categories',
     84            [
     85                'methods'             => 'GET',
     86                'callback'            => [$this, 'searchCategories'],
     87                'permission_callback' => '__return_true',
     88            ]
     89        );
    3390    }
    3491
     92    /**
     93     * Check if the current user has permission to access the endpoint.
     94     *
     95     * Returns true as this is a read-only search endpoint
     96     * used in Elementor editor context.
     97     *
     98     * @since  1.0.0
     99     * @return bool Always returns true.
     100     */
     101    public function checkPermission(): bool
     102    {
     103        return true;
     104    }
    35105
    36     public function searchPackages()
     106    /**
     107     * Search packages by title.
     108     *
     109     * Returns packages matching the search term for SELECT2 dropdown.
     110     *
     111     * @since  1.0.0
     112     * @param  WP_REST_Request $request REST request object.
     113     * @return WP_REST_Response JSON response with package results.
     114     */
     115    public function searchPackages(WP_REST_Request $request): WP_REST_Response
    37116    {
    38117        global $wpdb;
    39         $posts_table = "{$wpdb->prefix}posts";
     118
     119        $term = $request->get_param('term');
    40120        $packages = [];
    41         $term = wpdm_query_var('term', ['validate' => 'txt', 'default' => null]);
    42121
    43         if ($term) {
    44             $result_rows = $wpdb->get_results("SELECT ID, post_title FROM $posts_table where `post_type` = 'wpdmpro' AND `post_title` LIKE  '%" . $term . "%' ");
    45             foreach ($result_rows as $row) {
    46                 array_push($packages, [
    47                     'id' => $row->ID,
    48                     'text' => $row->post_title
    49                 ]);
     122        if (!empty($term)) {
     123            // Use prepared statement for security
     124            $like_term = '%' . $wpdb->esc_like($term) . '%';
     125
     126            $results = $wpdb->get_results(
     127                $wpdb->prepare(
     128                    "SELECT ID, post_title
     129                     FROM {$wpdb->posts}
     130                     WHERE post_type = 'wpdmpro'
     131                     AND post_status = 'publish'
     132                     AND post_title LIKE %s
     133                     ORDER BY post_title ASC
     134                     LIMIT 20",
     135                    $like_term
     136                )
     137            );
     138
     139            if ($results) {
     140                foreach ($results as $row) {
     141                    $packages[] = [
     142                        'id'   => (int) $row->ID,
     143                        'text' => esc_html($row->post_title),
     144                    ];
     145                }
    50146            }
    51147        }
    52         //results key is necessary for jquery select2
    53         wp_send_json(["results" => $packages]);
     148
     149        // Results key is required for jQuery SELECT2
     150        return new WP_REST_Response(['results' => $packages], 200);
     151    }
     152
     153    /**
     154     * Search categories by name.
     155     *
     156     * Returns categories matching the search term for SELECT2 dropdown.
     157     *
     158     * @since  1.3.0
     159     * @param  WP_REST_Request $request REST request object.
     160     * @return WP_REST_Response JSON response with category results.
     161     */
     162    public function searchCategories(WP_REST_Request $request): WP_REST_Response
     163    {
     164        $term = $request->get_param('term');
     165        $categories = [];
     166
     167        $args = [
     168            'taxonomy'   => 'wpdmcategory',
     169            'hide_empty' => false,
     170            'number'     => 20,
     171            'orderby'    => 'name',
     172            'order'      => 'ASC',
     173        ];
     174
     175        if (!empty($term)) {
     176            $args['search'] = $term;
     177        }
     178
     179        $terms = get_terms($args);
     180
     181        if (!is_wp_error($terms) && !empty($terms)) {
     182            foreach ($terms as $category) {
     183                $categories[] = [
     184                    'id'   => $category->slug,
     185                    'text' => esc_html($category->name),
     186                ];
     187            }
     188        }
     189
     190        return new WP_REST_Response(['results' => $categories], 200);
    54191    }
    55192}
  • wpdm-elementor/trunk/src/constants.php

    r2932103 r3427512  
    11<?php
     2/**
     3 * Plugin constants for WPDM Elementor integration.
     4 *
     5 * @package WPDM\Elementor
     6 * @since   1.0.0
     7 */
    28
    3 define('WPDM_ELEMENTOR', 'wpdm-elementor');
     9if (!defined('ABSPATH')) {
     10    exit;
     11}
     12
     13/**
     14 * Text domain for translations.
     15 *
     16 * @var string
     17 */
     18if (!defined('WPDM_ELEMENTOR')) {
     19    define('WPDM_ELEMENTOR', 'wpdm-elementor');
     20}
     21
     22/**
     23 * Plugin version.
     24 *
     25 * @var string
     26 */
     27if (!defined('WPDM_ELEMENTOR_VERSION')) {
     28    define('WPDM_ELEMENTOR_VERSION', '2.0.0');
     29}
     30
     31/**
     32 * Plugin directory path.
     33 *
     34 * @var string
     35 */
     36if (!defined('WPDM_ELEMENTOR_PATH')) {
     37    define('WPDM_ELEMENTOR_PATH', dirname(__DIR__) . '/');
     38}
     39
     40/**
     41 * Plugin directory URL.
     42 *
     43 * @var string
     44 */
     45if (!defined('WPDM_ELEMENTOR_URL')) {
     46    define('WPDM_ELEMENTOR_URL', plugin_dir_url(dirname(__FILE__)));
     47}
  • wpdm-elementor/trunk/src/helper-functions.php

    r3077561 r3427512  
    11<?php
     2/**
     3 * Helper functions for WPDM Elementor integration.
     4 *
     5 * @package WPDM\Elementor
     6 * @since   1.0.0
     7 */
    28
    3 /**
    4  *
    5  * @return [template1.php => Template 1]
    6  */
     9if (!defined('ABSPATH')) {
     10    exit;
     11}
     12
    713if (!function_exists('get_wpdm_link_templates')) {
    8     function get_wpdm_link_templates()
     14    /**
     15     * Get WPDM link templates for shortcode usage.
     16     *
     17     * Returns an array of available link templates with their display names.
     18     * Template file extensions (.php) are stripped from the names.
     19     *
     20     * @since  1.0.0
     21     * @return array Associative array of template_file => template_name pairs.
     22     */
     23    function get_wpdm_link_templates(): array
    924    {
     25        if (!function_exists('WPDM')) {
     26            return [];
     27        }
     28
    1029        $link_templates = WPDM()->packageTemplate->getTemplates('link');
    11         foreach ($link_templates as &$template) {
    12             $template = str_replace(".php", "", $template);
    13         }
     30
     31        if (!is_array($link_templates)) {
     32            return [];
     33        }
     34
     35        foreach ($link_templates as &$template) {
     36            $template = str_replace('.php', '', $template);
     37        }
     38
    1439        return $link_templates;
    1540    }
    1641}
    1742
     43if (!function_exists('get_wpdmcategory_terms')) {
     44    /**
     45     * Get WPDM category terms for Elementor controls.
     46     *
     47     * Returns an array of category terms formatted for use in
     48     * Elementor SELECT2 controls.
     49     *
     50     * @since  1.0.0
     51     * @return array Associative array of slug => name pairs.
     52     */
     53    function get_wpdmcategory_terms(): array
     54    {
     55        $terms = get_terms([
     56            'taxonomy'   => 'wpdmcategory',
     57            'hide_empty' => false,
     58        ]);
    1859
    19 /**
    20  *
    21  * @return [slug => name]
    22  */
    23 if (!function_exists('get_wpdmcategory_terms')) {
    24     function get_wpdmcategory_terms()
    25     {
    26         $wpdmcategory_terms = get_terms(['taxonomoy' => 'wpdmcategory']);
    27         foreach ($wpdmcategory_terms as $k => $t) {
    28             $wpdmcategory_terms[$t->slug] = $t->name;
    29             unset($wpdmcategory_terms[$k]);
    30         };
    31         return $wpdmcategory_terms;
     60        if (is_wp_error($terms) || empty($terms)) {
     61            return [];
     62        }
     63
     64        $options = [];
     65        foreach ($terms as $term) {
     66            $options[$term->slug] = $term->name;
     67        }
     68
     69        return $options;
    3270    }
    3371}
    3472
    35 if(!function_exists('get_elementor_link_templates')){
    36     function get_elementor_link_templates()
     73if (!function_exists('get_elementor_link_templates')) {
     74    /**
     75     * Get WPDM link templates formatted for Elementor controls.
     76     *
     77     * Returns an array of available link templates formatted for
     78     * Elementor SELECT2 controls, with file extensions removed.
     79     *
     80     * @since  1.0.0
     81     * @return array Associative array of template_key => template_key pairs.
     82     */
     83    function get_elementor_link_templates(): array
    3784    {
     85        if (!function_exists('WPDM')) {
     86            return [];
     87        }
     88
    3889        $link_templates = WPDM()->packageTemplate->getTemplates('link');
    39         array_walk($link_templates, function (&$v, $k) {
    40             $k = strrpos($k, ".") ? substr($k, 0, strrpos($k, ".")) : $k;
    41             $v = $k;
    42         });
    4390
    44         return $link_templates;
     91        if (!is_array($link_templates)) {
     92            return [];
     93        }
     94
     95        $options = [];
     96        foreach ($link_templates as $key => $value) {
     97            // Remove file extension from key
     98            $clean_key = strrpos($key, '.') !== false
     99                ? substr($key, 0, strrpos($key, '.'))
     100                : $key;
     101            $options[$clean_key] = $clean_key;
     102        }
     103
     104        return $options;
    45105    }
    46106}
     107
     108if (!function_exists('get_wpdm_tag_terms')) {
     109    /**
     110     * Get WPDM tag terms for Elementor controls.
     111     *
     112     * Returns an array of tag terms formatted for use in
     113     * Elementor SELECT2 controls.
     114     *
     115     * @since  1.3.0
     116     * @return array Associative array of slug => name pairs.
     117     */
     118    function get_wpdm_tag_terms(): array
     119    {
     120        $terms = get_terms([
     121            'taxonomy'   => 'wpdmtag',
     122            'hide_empty' => false,
     123        ]);
     124
     125        if (is_wp_error($terms) || empty($terms)) {
     126            return [];
     127        }
     128
     129        $options = [];
     130        foreach ($terms as $term) {
     131            $options[$term->slug] = $term->name;
     132        }
     133
     134        return $options;
     135    }
     136}
  • wpdm-elementor/trunk/src/includes.php

    r2392526 r3427512  
    11<?php
    22
    3 // autoload.php @generated by Composer
     3/**
     4 * File includes for WPDM Elementor plugin.
     5 *
     6 * If Composer autoload is available, use it.
     7 * Otherwise, fall back to manual includes.
     8 */
    49
    5 //require_once __DIR__ . '/composer/autoload_real.php';
     10$composer_autoload = dirname(__DIR__) . '/vendor/autoload.php';
    611
    7 //return ComposerAutoloaderInitcb57ad66fbc0e2adc70532ce7d9c8223::getLoader();
     12if (file_exists($composer_autoload)) {
     13    require_once $composer_autoload;
     14} else {
     15    // Manual includes (fallback when Composer is not used)
     16    include_once dirname(__DIR__) . '/src/constants.php';
     17    include_once dirname(__DIR__) . '/src/helper-functions.php';
    818
    9 include dirname(__DIR__).'/src/constants.php';
    10 include dirname(__DIR__).'/src/helper-functions.php';
    11 include dirname(__DIR__).'/src/widgets/AllPackagesWidget.php';
    12 include dirname(__DIR__).'/src/widgets/CategoryWidget.php';
    13 include dirname(__DIR__).'/src/widgets/DirectLinkWidget.php';
    14 include dirname(__DIR__).'/src/widgets/FrontendWidget.php';
    15 include dirname(__DIR__).'/src/widgets/LoginFormWidget.php';
    16 include dirname(__DIR__).'/src/widgets/PackagesWidget.php';
    17 include dirname(__DIR__).'/src/widgets/PackageWidget.php';
    18 include dirname(__DIR__).'/src/widgets/RegFormWidget.php';
    19 include dirname(__DIR__).'/src/widgets/SearchResultWidget.php';
    20 include dirname(__DIR__).'/src/widgets/TagWidget.php';
    21 include dirname(__DIR__).'/src/widgets/UserDashboardWidget.php';
    22 include dirname(__DIR__).'/src/widgets/UserProfileWidget.php';
     19    // Base widget class (must be loaded before other widgets)
     20    include_once dirname(__DIR__) . '/src/widgets/BaseWidget.php';
     21
     22    // Widget classes
     23    include_once dirname(__DIR__) . '/src/widgets/AllPackagesWidget.php';
     24    include_once dirname(__DIR__) . '/src/widgets/CategoryWidget.php';
     25    include_once dirname(__DIR__) . '/src/widgets/DirectLinkWidget.php';
     26    include_once dirname(__DIR__) . '/src/widgets/FrontendWidget.php';
     27    include_once dirname(__DIR__) . '/src/widgets/LoginFormWidget.php';
     28    include_once dirname(__DIR__) . '/src/widgets/PackagesWidget.php';
     29    include_once dirname(__DIR__) . '/src/widgets/PackageWidget.php';
     30    include_once dirname(__DIR__) . '/src/widgets/RegFormWidget.php';
     31    include_once dirname(__DIR__) . '/src/widgets/SearchResultWidget.php';
     32    include_once dirname(__DIR__) . '/src/widgets/TagWidget.php';
     33    include_once dirname(__DIR__) . '/src/widgets/UserDashboardWidget.php';
     34    include_once dirname(__DIR__) . '/src/widgets/UserProfileWidget.php';
     35}
    2336
    2437
  • wpdm-elementor/trunk/src/widgets/AllPackagesWidget.php

    r3259585 r3427512  
    33namespace WPDM\Elementor\Widgets;
    44
    5 use Elementor\Widget_Base;
    6 
    7 class AllPackagesWidget extends Widget_Base
     5use Elementor\Controls_Manager;
     6use Elementor\Repeater;
     7
     8/**
     9 * All Packages Widget.
     10 * Displays packages in a table/grid format with customizable columns.
     11 */
     12class AllPackagesWidget extends BaseWidget
    813{
     14    /**
     15     * Expected settings keys for this widget.
     16     */
     17    private const SETTINGS_KEYS = [
     18        'categories', 'orderby', 'order', 'items_per_page',
     19        'table_columns', 'cols', 'colheads', 'jstable', 'login'
     20    ];
     21
     22    /**
     23     * Settings sanitization rules.
     24     */
     25    private const SANITIZERS = [
     26        'orderby' => 'orderby',
     27        'order' => 'order',
     28        'items_per_page' => 'int',
     29        'cols' => 'text',
     30        'colheads' => 'text',
     31        'jstable' => 'text',
     32        'login' => 'text',
     33    ];
     34
     35    /**
     36     * Available WPDM data fields for table columns.
     37     *
     38     * @return array Field key => label pairs.
     39     */
     40    private function getDataFieldOptions(): array
     41    {
     42        return [
     43            // Basic Info
     44            'title'          => __('Title', WPDM_ELEMENTOR),
     45            'page_link'           => __('Title with Link', WPDM_ELEMENTOR),
     46            'description'    => __('Description', WPDM_ELEMENTOR),
     47            'excerpt'        => __('Excerpt', WPDM_ELEMENTOR),
     48
     49            // Taxonomy
     50            'categories'     => __('Categories', WPDM_ELEMENTOR),
     51            'tags'           => __('Tags', WPDM_ELEMENTOR),
     52
     53            // Download
     54            'download_link'  => __('Download Button', WPDM_ELEMENTOR),
     55            'download_url'   => __('Download URL', WPDM_ELEMENTOR),
     56            'download_count' => __('Download Count', WPDM_ELEMENTOR),
     57
     58            // File Info
     59            'file_size'      => __('File Size', WPDM_ELEMENTOR),
     60            'file_count'     => __('File Count', WPDM_ELEMENTOR),
     61            'file_type'      => __('File Type', WPDM_ELEMENTOR),
     62            'version'        => __('Version', WPDM_ELEMENTOR),
     63
     64            // Dates
     65            'publish_date'   => __('Publish Date', WPDM_ELEMENTOR),
     66            'update_date'    => __('Update Date', WPDM_ELEMENTOR),
     67
     68            // Media
     69            'thumb'          => __('Thumbnail', WPDM_ELEMENTOR),
     70            'preview'        => __('Preview', WPDM_ELEMENTOR),
     71            'icon'           => __('File Icon', WPDM_ELEMENTOR),
     72
     73            // Author
     74            'author'         => __('Author Name', WPDM_ELEMENTOR),
     75            //'author_pic'    => __('Author Picture', WPDM_ELEMENTOR),
     76
     77            // Stats
     78            'view_count'     => __('View Count', WPDM_ELEMENTOR),
     79
     80        ];
     81    }
    982
    1083    public function get_name()
     
    1588    public function get_title()
    1689    {
    17         return 'Packages Table';
     90        return __('Packages Table', WPDM_ELEMENTOR);
    1891    }
    1992
     
    2396    }
    2497
    25     public function get_categories()
    26     {
    27         return ['wpdm'];
     98    public function get_keywords(): array
     99    {
     100        return ['wpdm', 'download', 'table', 'packages', 'list', 'grid'];
    28101    }
    29102
    30103    protected function register_controls()
    31104    {
    32 
     105        // Content Section - Query
    33106        $this->start_controls_section(
    34             'content_section',
    35             [
    36                 'label' => esc_attr(__('Parameters', WPDM_ELEMENTOR)),
    37                 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
    38             ]
    39         );
    40 
    41         //categories
     107            'query_section',
     108            [
     109                'label' => __('Query', WPDM_ELEMENTOR),
     110                'tab'   => Controls_Manager::TAB_CONTENT,
     111            ]
     112        );
     113
    42114        $this->add_control(
    43115            'categories',
    44116            [
    45                 'label' => esc_attr(__('Categories', WPDM_ELEMENTOR)),
    46                 'type' => \Elementor\Controls_Manager::SELECT2,
     117                'label'    => __('Filter by Categories', WPDM_ELEMENTOR),
     118                'type'     => Controls_Manager::SELECT2,
    47119                'multiple' => true,
    48                 'options' => get_wpdmcategory_terms(),
    49                 'default' => []
    50             ]
    51         );
    52 
    53 
    54 
    55         //order by: Select
     120                'options'  => $this->getCategoryOptions(),
     121                'default'  => []
     122            ]
     123        );
     124
    56125        $this->add_control(
    57126            'orderby',
    58127            [
    59                 'label' => esc_attr(__('Order By', WPDM_ELEMENTOR)),
    60                 'type' => \Elementor\Controls_Manager::SELECT2,
    61                 'options' => ['date' => 'Date', 'title' => 'Title'],
     128                'label'   => __('Order By', WPDM_ELEMENTOR),
     129                'type'    => Controls_Manager::SELECT,
     130                'options' => [
     131                    'date'           => __('Date', WPDM_ELEMENTOR),
     132                    'title'          => __('Title', WPDM_ELEMENTOR),
     133                    'download_count' => __('Download Count', WPDM_ELEMENTOR),
     134                    'rand'           => __('Random', WPDM_ELEMENTOR),
     135                ],
    62136                'default' => 'date',
    63137            ]
    64138        );
    65139
    66         //order: Select
    67140        $this->add_control(
    68141            'order',
    69142            [
    70                 'label' => esc_attr(__('Order', WPDM_ELEMENTOR)),
    71                 'type' => \Elementor\Controls_Manager::CHOOSE,
     143                'label'   => __('Order', WPDM_ELEMENTOR),
     144                'type'    => Controls_Manager::CHOOSE,
    72145                'options' => [
    73                     'ASC' => ['title' => 'Ascending', 'icon' => 'fa fa-sort-alpha-down'],
    74                     'DESC' => ['title' => 'Descending', 'icon' => 'fa fa-sort-alpha-up']
     146                    'ASC'  => ['title' => __('Ascending', WPDM_ELEMENTOR), 'icon' => 'eicon-arrow-up'],
     147                    'DESC' => ['title' => __('Descending', WPDM_ELEMENTOR), 'icon' => 'eicon-arrow-down']
    75148                ],
    76149                'default' => 'DESC',
    77                 'show_label' => false
    78             ]
    79         );
    80 
    81         //items per page: text number
     150                'toggle'  => false
     151            ]
     152        );
     153
    82154        $this->add_control(
    83155            'items_per_page',
    84156            [
    85                 'label' => esc_attr(__('Items Per Page', WPDM_ELEMENTOR)),
    86                 'type' => \Elementor\Controls_Manager::TEXT,
    87                 'input_type' => 'number',
    88                 'default' => '10'
    89             ]
    90         );
    91 
    92 
    93         //cols : text
     157                'label'   => __('Items Per Page', WPDM_ELEMENTOR),
     158                'type'    => Controls_Manager::NUMBER,
     159                'min'     => 1,
     160                'max'     => 100,
     161                'default' => 10
     162            ]
     163        );
     164
     165        $this->end_controls_section();
     166
     167        // Content Section - Table Columns
     168        $this->start_controls_section(
     169            'columns_section',
     170            [
     171                'label' => __('Table Columns', WPDM_ELEMENTOR),
     172                'tab'   => Controls_Manager::TAB_CONTENT,
     173            ]
     174        );
     175
     176        $repeater = new Repeater();
     177
     178        $repeater->add_control(
     179            'column_heading',
     180            [
     181                'label'       => __('Column Heading', WPDM_ELEMENTOR),
     182                'type'        => Controls_Manager::TEXT,
     183                'default'     => __('Column', WPDM_ELEMENTOR),
     184                'label_block' => true,
     185            ]
     186        );
     187
     188        $repeater->add_control(
     189            'column_fields',
     190            [
     191                'label'       => __('Data Fields', WPDM_ELEMENTOR),
     192                'type'        => Controls_Manager::SELECT2,
     193                'multiple'    => true,
     194                'options'     => $this->getDataFieldOptions(),
     195                'default'     => ['title'],
     196                'label_block' => true,
     197                'description' => __('Select one or more fields to display in this column', WPDM_ELEMENTOR),
     198            ]
     199        );
     200
     201        $repeater->add_control(
     202            'column_width',
     203            [
     204                'label'       => __('Column Width', WPDM_ELEMENTOR),
     205                'type'        => Controls_Manager::TEXT,
     206                'default'     => '',
     207                'placeholder' => __('e.g., 100px or 20%', WPDM_ELEMENTOR),
     208                'description' => __('Leave empty for auto width', WPDM_ELEMENTOR),
     209            ]
     210        );
     211
     212        $repeater->add_control(
     213            'column_align',
     214            [
     215                'label'   => __('Text Align', WPDM_ELEMENTOR),
     216                'type'    => Controls_Manager::CHOOSE,
     217                'options' => [
     218                    'left'   => ['title' => __('Left', WPDM_ELEMENTOR), 'icon' => 'eicon-text-align-left'],
     219                    'center' => ['title' => __('Center', WPDM_ELEMENTOR), 'icon' => 'eicon-text-align-center'],
     220                    'right'  => ['title' => __('Right', WPDM_ELEMENTOR), 'icon' => 'eicon-text-align-right'],
     221                ],
     222                'default' => 'left',
     223                'toggle'  => false,
     224            ]
     225        );
     226
     227        $this->add_control(
     228            'table_columns',
     229            [
     230                'label'       => __('Columns', WPDM_ELEMENTOR),
     231                'type'        => Controls_Manager::REPEATER,
     232                'fields'      => $repeater->get_controls(),
     233                'default'     => [
     234                    [
     235                        'column_heading' => __('Title', WPDM_ELEMENTOR),
     236                        'column_fields'  => ['link'],
     237                        'column_width'   => '',
     238                        'column_align'   => 'left',
     239                    ],
     240                    [
     241                        'column_heading' => __('Categories', WPDM_ELEMENTOR),
     242                        'column_fields'  => ['categories'],
     243                        'column_width'   => '',
     244                        'column_align'   => 'left',
     245                    ],
     246                    [
     247                        'column_heading' => __('Download', WPDM_ELEMENTOR),
     248                        'column_fields'  => ['download_link'],
     249                        'column_width'   => '120px',
     250                        'column_align'   => 'center',
     251                    ],
     252                ],
     253                'title_field' => '{{{ column_heading }}}',
     254            ]
     255        );
     256
     257        $this->add_control(
     258            'legacy_mode_divider',
     259            [
     260                'type' => Controls_Manager::DIVIDER,
     261            ]
     262        );
     263
     264        $this->add_control(
     265            'use_legacy_mode',
     266            [
     267                'label'        => __('Use Legacy Mode', WPDM_ELEMENTOR),
     268                'type'         => Controls_Manager::SWITCHER,
     269                'label_on'     => __('Yes', WPDM_ELEMENTOR),
     270                'label_off'    => __('No', WPDM_ELEMENTOR),
     271                'return_value' => 'yes',
     272                'default'      => '',
     273                'description'  => __('Enable to use the old text-based column configuration', WPDM_ELEMENTOR),
     274            ]
     275        );
     276
    94277        $this->add_control(
    95278            'cols',
    96279            [
    97                 'label' => esc_attr(__('Data field name', WPDM_ELEMENTOR)),
    98                 'type' => \Elementor\Controls_Manager::TEXT,
    99                 'input_type' => 'text',
    100                 'default' => 'title|categories',
    101                 'description' => 'data field name for each column, column separator |, if you want to show multiple data fields in the same column, data field names should be separated by ,'
    102             ]
    103         );
    104 
    105         //cols tab
     280                'label'       => __('Data Field Names (Legacy)', WPDM_ELEMENTOR),
     281                'type'        => Controls_Manager::TEXT,
     282                'default'     => 'title|categories',
     283                'description' => __('Column separator: | Multiple fields per column: ,', WPDM_ELEMENTOR),
     284                'condition'   => [
     285                    'use_legacy_mode' => 'yes',
     286                ],
     287            ]
     288        );
     289
    106290        $this->add_control(
    107291            'colheads',
    108292            [
    109                 'label' => esc_attr(__('column heading', WPDM_ELEMENTOR)),
    110                 'type' => \Elementor\Controls_Manager::TEXT,
    111                 'input_type' => 'text',
    112                 'default' => 'Title|Categories',
    113                 'description' => 'colheads="Title|Categories|Update Date::200px|Download::100px'
    114             ]
    115         );
    116 
    117 
    118         //jstable: choose
     293                'label'       => __('Column Headings (Legacy)', WPDM_ELEMENTOR),
     294                'type'        => Controls_Manager::TEXT,
     295                'default'     => 'Title|Categories',
     296                'description' => __('e.g: Title|Categories|Download::100px', WPDM_ELEMENTOR),
     297                'condition'   => [
     298                    'use_legacy_mode' => 'yes',
     299                ],
     300            ]
     301        );
     302
     303        $this->end_controls_section();
     304
     305        // Content Section - Table Options
     306        $this->start_controls_section(
     307            'options_section',
     308            [
     309                'label' => __('Table Options', WPDM_ELEMENTOR),
     310                'tab'   => Controls_Manager::TAB_CONTENT,
     311            ]
     312        );
     313
    119314        $this->add_control(
    120315            'jstable',
    121316            [
    122                 'label' => esc_attr(__('Enable datatable.js', WPDM_ELEMENTOR)),
    123                 'type' => \Elementor\Controls_Manager::CHOOSE,
    124                 'options' => [
    125                     '0' => ['title' => 'Disable', 'icon' => 'fa fa-times'],
    126                     '1' => ['title' => 'Enable', 'icon' => 'fa fa-check']
    127                 ],
    128                 'default' => '0'
    129             ]
    130         );
    131 
    132 
    133         //Require login: choose
     317                'label'        => __('Enable DataTable.js', WPDM_ELEMENTOR),
     318                'type'         => Controls_Manager::SWITCHER,
     319                'label_on'     => __('Yes', WPDM_ELEMENTOR),
     320                'label_off'    => __('No', WPDM_ELEMENTOR),
     321                'return_value' => '1',
     322                'default'      => '',
     323                'description'  => __('Adds sorting, searching, and pagination features', WPDM_ELEMENTOR),
     324            ]
     325        );
     326
    134327        $this->add_control(
    135328            'login',
    136329            [
    137                 'label' => esc_attr(__('Require Login', WPDM_ELEMENTOR)),
    138                 'type' => \Elementor\Controls_Manager::CHOOSE,
    139                 'options' => [
    140                     '0' => ['title' => 'No', 'icon' => 'fa fa-times'],
    141                     '1' => ['title' => 'Yes', 'icon' => 'fa fa-check']
    142                 ],
    143                 'default' => '0'
    144             ]
    145         );
    146 
    147 
     330                'label'        => __('Require Login', WPDM_ELEMENTOR),
     331                'type'         => Controls_Manager::SWITCHER,
     332                'label_on'     => __('Yes', WPDM_ELEMENTOR),
     333                'label_off'    => __('No', WPDM_ELEMENTOR),
     334                'return_value' => '1',
     335                'default'      => '',
     336                'description'  => __('Only show table to logged-in users', WPDM_ELEMENTOR),
     337            ]
     338        );
    148339
    149340        $this->end_controls_section();
    150341    }
    151342
    152 
     343    /**
     344     * Convert repeater columns to legacy format for WPDM shortcode.
     345     *
     346     * @param array $columns Repeater columns data.
     347     * @return array ['cols' => string, 'colheads' => string]
     348     */
     349    private function convertColumnsToLegacyFormat(array $columns): array
     350    {
     351        $cols = [];
     352        $colheads = [];
     353
     354        foreach ($columns as $column) {
     355            // Get fields for this column
     356            $fields = $column['column_fields'] ?? ['title'];
     357            if (!is_array($fields)) {
     358                $fields = [$fields];
     359            }
     360            $cols[] = implode(',', $fields);
     361
     362            // Build column heading with optional width
     363            $heading = $column['column_heading'] ?? 'Column';
     364            $width = $column['column_width'] ?? '';
     365
     366            if (!empty($width)) {
     367                $heading .= '::' . $width;
     368            }
     369            $colheads[] = $heading;
     370        }
     371
     372        return [
     373            'cols'     => implode('|', $cols),
     374            'colheads' => implode('|', $colheads),
     375        ];
     376    }
    153377
    154378    protected function render()
    155379    {
    156 
    157         $settings = $this->get_settings_for_display();
    158         $cus_settings = array_slice($settings, 0, 10);
    159 
    160         $cus_settings['categories'] = implode(",", $cus_settings['categories']);
    161         if(trim($cus_settings['categories']) === '')
    162             unset($cus_settings['categories']);
    163 
    164         echo WPDM()->package->shortCodes->allPackages($cus_settings);
    165 
     380        $settings = $this->getCleanSettings(self::SETTINGS_KEYS);
     381        $settings = $this->sanitizeSettings($settings, self::SANITIZERS);
     382
     383        // Convert categories array to comma-separated string
     384        if (isset($settings['categories']) && is_array($settings['categories'])) {
     385            $settings['categories'] = implode(',', array_map('sanitize_text_field', $settings['categories']));
     386        }
     387
     388        // Remove empty categories - ensure it's a string before checking
     389        $categories = $settings['categories'] ?? '';
     390        if (!is_string($categories) || empty(trim($categories))) {
     391            unset($settings['categories']);
     392        }
     393
     394        // Check if using new repeater mode or legacy mode
     395        $use_legacy = !empty($settings['use_legacy_mode']) && $settings['use_legacy_mode'] === 'yes';
     396
     397        if (!$use_legacy && !empty($settings['table_columns'])) {
     398            // Convert repeater data to legacy format for WPDM
     399            $converted = $this->convertColumnsToLegacyFormat($settings['table_columns']);
     400            $settings['cols'] = $converted['cols'];
     401            $settings['colheads'] = $converted['colheads'];
     402        }
     403
     404        // Remove non-shortcode settings
     405        unset($settings['table_columns']);
     406        unset($settings['use_legacy_mode']);
     407
     408        // Convert switcher values
     409        $settings['jstable'] = !empty($settings['jstable']) ? '1' : '0';
     410        $settings['login'] = !empty($settings['login']) ? '1' : '0';
     411
     412        echo WPDM()->package->shortCodes->allPackages($settings);
    166413    }
    167414}
  • wpdm-elementor/trunk/src/widgets/CategoryWidget.php

    r3259585 r3427512  
    33namespace WPDM\Elementor\Widgets;
    44
    5 use Elementor\Widget_Base;
    6 
    7 class CategoryWidget extends Widget_Base
     5/**
     6 * Category Widget.
     7 * Displays packages filtered by category.
     8 */
     9class CategoryWidget extends BaseWidget
    810{
     11    /**
     12     * Expected settings keys for this widget.
     13     */
     14    private const SETTINGS_KEYS = [
     15        'catid', 'operator', 'title', 'desc', 'items_per_page',
     16        'orderby', 'order', 'template', 'author',
     17        'cols', 'colspad', 'colsphone', 'toolbar', 'paging'
     18    ];
     19
     20    /**
     21     * Settings sanitization rules.
     22     */
     23    private const SANITIZERS = [
     24        'operator' => 'text',
     25        'title' => 'text',
     26        'desc' => 'text',
     27        'items_per_page' => 'int',
     28        'orderby' => 'orderby',
     29        'order' => 'order',
     30        'template' => 'text',
     31        'author' => 'text',
     32        'cols' => 'int',
     33        'colspad' => 'int',
     34        'colsphone' => 'int',
     35        'toolbar' => 'text',
     36        'paging' => 'text',
     37    ];
    938
    1039    public function get_name()
     
    1544    public function get_title()
    1645    {
    17         return 'Packages By Category';
     46        return __('Packages By Category', WPDM_ELEMENTOR);
    1847    }
    1948
     
    2352    }
    2453
    25     public function get_categories()
    26     {
    27         return ['wpdm'];
    28     }
    29 
    3054    protected function register_controls()
    3155    {
    32 
    3356        $this->start_controls_section(
    3457            'content_section',
    3558            [
    36                 'label' => esc_attr(__('Parameters', WPDM_ELEMENTOR)),
     59                'label' => __('Parameters', WPDM_ELEMENTOR),
    3760                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
    3861            ]
    3962        );
    4063
    41 
    42         //categories: multi select
    4364        $this->add_control(
    4465            'catid',
    4566            [
    46                 'label' => esc_attr(__('Include Categories', WPDM_ELEMENTOR)),
     67                'label' => __('Include Categories', WPDM_ELEMENTOR),
    4768                'type' => \Elementor\Controls_Manager::SELECT2,
    4869                'multiple' => true,
    49                 'options' => get_wpdmcategory_terms(),
     70                'options' => $this->getCategoryOptions(),
    5071                'default' => []
    5172            ]
    5273        );
    5374
    54         //Operator: Choose
    5575        $this->add_control(
    5676            'operator',
    5777            [
    58                 'label' => esc_attr(__('Operator', WPDM_ELEMENTOR)),
    59                 'type' => \Elementor\Controls_Manager::SELECT2,
    60                 'options' => ['IN' => 'IN', 'NOT IN' => 'NOT IN', 'AND' => 'AND', 'EXISTS' => 'EXISTS', 'NOT EXISTS' => 'NOT EXISTS'],
     78                'label' => __('Operator', WPDM_ELEMENTOR),
     79                'type' => \Elementor\Controls_Manager::SELECT2,
     80                'options' => [
     81                    'IN' => 'IN',
     82                    'NOT IN' => 'NOT IN',
     83                    'AND' => 'AND',
     84                    'EXISTS' => 'EXISTS',
     85                    'NOT EXISTS' => 'NOT EXISTS'
     86                ],
    6187                'default' => 'IN',
    62                 'description' => esc_attr(__("Use this parameter only when you are using multiple categories.", WPDM_ELEMENTOR))
    63             ]
    64         );
    65 
    66         //title: Text
     88                'description' => __('Use this parameter only when using multiple categories.', WPDM_ELEMENTOR)
     89            ]
     90        );
     91
    6792        $this->add_control(
    6893            'title',
    6994            [
    70                 'label' => esc_attr(__('Title', WPDM_ELEMENTOR)),
     95                'label' => __('Title', WPDM_ELEMENTOR),
    7196                'type' => \Elementor\Controls_Manager::TEXT,
    7297                'input_type' => 'text',
    73                 'description' => esc_attr(__('You can use any text there, if you use “1” then it will show the category title', WPDM_ELEMENTOR)),
     98                'description' => __('Use "1" to show category title, or enter custom text', WPDM_ELEMENTOR),
    7499                'default' => '1'
    75100            ]
    76101        );
    77102
    78         //description: Text
    79103        $this->add_control(
    80104            'desc',
    81105            [
    82                 'label' => esc_attr(__('Description', WPDM_ELEMENTOR)),
     106                'label' => __('Description', WPDM_ELEMENTOR),
    83107                'type' => \Elementor\Controls_Manager::TEXT,
    84108                'input_type' => 'text',
    85                 'description' => esc_attr(__('You can use any text there, if you use “1” then it will show the category description', WPDM_ELEMENTOR)),
     109                'description' => __('Use "1" to show category description, or enter custom text', WPDM_ELEMENTOR),
    86110                'default' => '1'
    87 
    88             ]
    89         );
    90 
    91         //items per page: text number
     111            ]
     112        );
     113
    92114        $this->add_control(
    93115            'items_per_page',
    94116            [
    95                 'label' => esc_attr(__('Items Per Page', WPDM_ELEMENTOR)),
    96                 'type' => \Elementor\Controls_Manager::TEXT,
    97                 'input_type' => 'number',
    98                 'default' => '10'
    99             ]
    100         );
    101 
    102 
    103         //order by: Select
     117                'label' => __('Items Per Page', WPDM_ELEMENTOR),
     118                'type' => \Elementor\Controls_Manager::NUMBER,
     119                'min' => 1,
     120                'max' => 100,
     121                'default' => 10
     122            ]
     123        );
     124
    104125        $this->add_control(
    105126            'orderby',
    106127            [
    107                 'label' => esc_attr(__('Order By', WPDM_ELEMENTOR)),
    108                 'type' => \Elementor\Controls_Manager::SELECT2,
    109                 'options' => ['date' => 'Date', 'title' => 'Title'],
     128                'label' => __('Order By', WPDM_ELEMENTOR),
     129                'type' => \Elementor\Controls_Manager::SELECT2,
     130                'options' => ['date' => __('Date', WPDM_ELEMENTOR), 'title' => __('Title', WPDM_ELEMENTOR)],
    110131                'default' => 'date',
    111132            ]
    112133        );
    113134
    114         //order: Choose
    115135        $this->add_control(
    116136            'order',
    117137            [
    118                 'label' => esc_attr(__('Order', WPDM_ELEMENTOR)),
     138                'label' => __('Order', WPDM_ELEMENTOR),
    119139                'type' => \Elementor\Controls_Manager::CHOOSE,
    120140                'options' => [
    121                     'ASC' => ['title' => 'Ascending', 'icon' => 'fa fa-sort-alpha-down'],
    122                     'DESC' => ['title' => 'Descending', 'icon' => 'fa fa-sort-alpha-up']
     141                    'ASC' => ['title' => __('Ascending', WPDM_ELEMENTOR), 'icon' => 'eicon-arrow-up'],
     142                    'DESC' => ['title' => __('Descending', WPDM_ELEMENTOR), 'icon' => 'eicon-arrow-down']
    123143                ],
    124144                'default' => 'DESC',
    125                 'show_label' => false
    126             ]
    127         );
    128 
    129 
    130         //link template: select
     145                'toggle' => false
     146            ]
     147        );
    131148
    132149        $this->add_control(
    133150            'template',
    134151            [
    135                 'label' => esc_attr(__('Link Template', WPDM_ELEMENTOR)),
    136                 'type' => \Elementor\Controls_Manager::SELECT2,
    137                 'options' => get_elementor_link_templates(),
     152                'label' => __('Link Template', WPDM_ELEMENTOR),
     153                'type' => \Elementor\Controls_Manager::SELECT2,
     154                'options' => $this->getLinkTemplateOptions(),
    138155                'default' => 'link-template-default'
    139156            ]
    140157        );
    141158
    142 
    143         //authors: Text
    144159        $this->add_control(
    145160            'author',
    146161            [
    147                 'label' => esc_attr(__('Authors', WPDM_ELEMENTOR)),
     162                'label' => __('Authors', WPDM_ELEMENTOR),
    148163                'type' => \Elementor\Controls_Manager::TEXT,
    149164                'input_type' => 'text',
    150                 'placeholder' => esc_attr(__('e.g: 1, 2, 3', WPDM_ELEMENTOR)),
    151                 'description' => esc_attr(__('Author IDs seperated by comma', WPDM_ELEMENTOR))
    152             ]
    153         );
    154 
    155         //cols web
     165                'placeholder' => __('e.g: 1, 2, 3', WPDM_ELEMENTOR),
     166                'description' => __('Author IDs separated by comma', WPDM_ELEMENTOR)
     167            ]
     168        );
     169
    156170        $this->add_control(
    157171            'cols',
    158172            [
    159                 'label' => esc_attr(__('Columns In PC', WPDM_ELEMENTOR)),
    160                 'type' => \Elementor\Controls_Manager::TEXT,
    161                 'input_type' => 'number',
    162                 'default' => '3'
    163             ]
    164         );
    165 
    166         //cols tab
     173                'label' => __('Columns (Desktop)', WPDM_ELEMENTOR),
     174                'type' => \Elementor\Controls_Manager::NUMBER,
     175                'min' => 1,
     176                'max' => 6,
     177                'default' => 3
     178            ]
     179        );
     180
    167181        $this->add_control(
    168182            'colspad',
    169183            [
    170                 'label' => esc_attr(__('Columns In Tab', WPDM_ELEMENTOR)),
    171                 'type' => \Elementor\Controls_Manager::TEXT,
    172                 'input_type' => 'number',
    173                 'default' => '2'
    174             ]
    175         );
    176 
    177         //cols phone
     184                'label' => __('Columns (Tablet)', WPDM_ELEMENTOR),
     185                'type' => \Elementor\Controls_Manager::NUMBER,
     186                'min' => 1,
     187                'max' => 4,
     188                'default' => 2
     189            ]
     190        );
     191
    178192        $this->add_control(
    179193            'colsphone',
    180194            [
    181                 'label' => esc_attr(__('Columns In Phone', WPDM_ELEMENTOR)),
    182                 'type' => \Elementor\Controls_Manager::TEXT,
    183                 'input_type' => 'number',
    184                 'default' => '1'
    185             ]
    186         );
    187 
    188         //Show Toolbar: radio
     195                'label' => __('Columns (Phone)', WPDM_ELEMENTOR),
     196                'type' => \Elementor\Controls_Manager::NUMBER,
     197                'min' => 1,
     198                'max' => 2,
     199                'default' => 1
     200            ]
     201        );
     202
    189203        $this->add_control(
    190204            'toolbar',
    191205            [
    192                 'label' => esc_attr(__('Show Toolbar', WPDM_ELEMENTOR)),
     206                'label' => __('Show Toolbar', WPDM_ELEMENTOR),
    193207                'type' => \Elementor\Controls_Manager::CHOOSE,
    194208                'options' => [
    195                     '1' => ['title' => 'Show', 'icon' => 'fa fa-check'],
    196                     '0' => ['title' => 'Hide', 'icon' => 'fa fa-times']
     209                    '1' => ['title' => __('Show', WPDM_ELEMENTOR), 'icon' => 'eicon-check'],
     210                    '0' => ['title' => __('Hide', WPDM_ELEMENTOR), 'icon' => 'eicon-close']
    197211                ],
    198212                'default' => '1',
     
    200214        );
    201215
    202         //show pagination: radio
    203216        $this->add_control(
    204217            'paging',
    205218            [
    206                 'label' => esc_attr(__('Paging', WPDM_ELEMENTOR)),
     219                'label' => __('Pagination', WPDM_ELEMENTOR),
    207220                'type' => \Elementor\Controls_Manager::CHOOSE,
    208221                'options' => [
    209                     '1' => ['title' => 'Show', 'icon' => 'fa fa-check'],
    210                     '0' => ['title' => 'Hide', 'icon' => 'fa fa-times']
     222                    '1' => ['title' => __('Show', WPDM_ELEMENTOR), 'icon' => 'eicon-check'],
     223                    '0' => ['title' => __('Hide', WPDM_ELEMENTOR), 'icon' => 'eicon-close']
    211224                ],
    212225                'default' => '0',
     
    214227        );
    215228
    216 
    217229        $this->end_controls_section();
    218230    }
    219231
    220 
    221 
    222232    protected function render()
    223233    {
    224 
    225         $settings = $this->get_settings_for_display();
    226         $cus_settings = array_slice($settings, 0, 15);
    227 
    228         if(!isset($cus_settings['catid'])) return "";
    229 
    230         $cus_settings['id'] = is_array($cus_settings['catid']) ? implode(",", $cus_settings['catid']) : $cus_settings['catid'];
    231 
    232         echo WPDM()->categories->shortcode->listPackages($cus_settings);
    233 
     234        $settings = $this->getCleanSettings(self::SETTINGS_KEYS);
     235        $settings = $this->sanitizeSettings($settings, self::SANITIZERS);
     236
     237        if (empty($settings['catid'])) {
     238            return;
     239        }
     240
     241        // Convert catid array to comma-separated id
     242        $settings['id'] = is_array($settings['catid'])
     243            ? implode(',', array_map('sanitize_text_field', $settings['catid']))
     244            : sanitize_text_field($settings['catid']);
     245
     246        unset($settings['catid']);
     247
     248        echo WPDM()->categories->shortcode->listPackages($settings);
    234249    }
    235250}
  • wpdm-elementor/trunk/src/widgets/DirectLinkWidget.php

    r2844275 r3427512  
    33namespace WPDM\Elementor\Widgets;
    44
    5 use Elementor\Widget_Base;
     5/**
     6 * Direct Link Widget.
     7 * Creates a direct download link for a package.
     8 */
     9class DirectLinkWidget extends BaseWidget
     10{
     11    /**
     12     * Expected settings keys for this widget.
     13     */
     14    private const SETTINGS_KEYS = ['pid', 'target', 'label', 'class', 'eid', 'style'];
    615
    7 class DirectLinkWidget extends Widget_Base
    8 {
     16    /**
     17     * Settings sanitization rules.
     18     */
     19    private const SANITIZERS = [
     20        'pid' => 'int',
     21        'target' => 'text',
     22        'label' => 'text',
     23        'class' => 'css_class',
     24        'eid' => 'text',
     25        'style' => 'css_style',
     26    ];
    927
    10     public function get_name()
    11     {
    12         return 'wpdmdirectlink';
    13     }
     28    public function get_name()
     29    {
     30        return 'wpdmdirectlink';
     31    }
    1432
    15     public function get_title()
    16     {
    17         return 'Direct download link';
    18     }
     33    public function get_title()
     34    {
     35        return __('Direct download link', WPDM_ELEMENTOR);
     36    }
    1937
    20     public function get_icon()
    21     {
    22         return 'eicon-editor-link';
    23     }
     38    public function get_icon()
     39    {
     40        return 'eicon-editor-link';
     41    }
    2442
    25     public function get_categories()
    26     {
    27         return ['wpdm'];
    28     }
     43    protected function register_controls()
     44    {
     45        $this->start_controls_section(
     46            'content_section',
     47            [
     48                'label' => __('Parameters', WPDM_ELEMENTOR),
     49                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
     50            ]
     51        );
    2952
    30     protected function register_controls()
    31     {
     53        $this->add_control(
     54            'pid',
     55            [
     56                'label' => __('Package', WPDM_ELEMENTOR),
     57                'type' => \Elementor\Controls_Manager::SELECT2,
     58                'placeholder' => __('Package', WPDM_ELEMENTOR),
     59                'select2options' => $this->getPackageSearchConfig()
     60            ]
     61        );
    3262
    33         $this->start_controls_section(
    34             'content_section',
    35             [
    36                 'label' => esc_attr(__('Parameters', WPDM_ELEMENTOR)),
    37                 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
    38             ]
    39         );
     63        $this->add_control(
     64            'target',
     65            [
     66                'label' => __('Link Target', WPDM_ELEMENTOR),
     67                'type' => \Elementor\Controls_Manager::SELECT2,
     68                'options' => ['_blank' => '_blank', '_self' => '_self'],
     69                'default' => '_blank'
     70            ]
     71        );
    4072
    41         //Package: Text
    42         $this->add_control(
    43             'pid',
    44             [
    45                 'label' => esc_attr(__('Package', WPDM_ELEMENTOR)),
    46                 'type' => \Elementor\Controls_Manager::SELECT2,
    47                 'placeholder' => esc_attr(__('Package', WPDM_ELEMENTOR)),
    48                 'select2options' => [
    49                     'placeholder' => 'Type Package title',
    50                     'ajax' => [
    51                         'url' =>  get_rest_url(null, 'wpdm-elementor/v1/search-packages'),
    52                         'dataType' => 'json',
    53                         'delay' => 250
    54                     ],
    55                     'minimumInputLength' => 2
    56                 ]
    57             ]
    58         );
     73        $this->add_control(
     74            'label',
     75            [
     76                'label' => __('Download link label', WPDM_ELEMENTOR),
     77                'type' => \Elementor\Controls_Manager::TEXT,
     78                'input_type' => 'text',
     79                'default' => 'Download',
     80                'placeholder' => __('Download', WPDM_ELEMENTOR),
     81            ]
     82        );
    5983
    60         //link template: select
    61         $this->add_control(
    62             'target',
    63             [
    64                 'label' => esc_attr(__('Link Template', WPDM_ELEMENTOR)),
    65                 'type' => \Elementor\Controls_Manager::SELECT2,
    66                 'options' => ['_blank' => '_blank', '_self' => '_self'],
    67                 'default' => '_blank'
    68             ]
    69         );
     84        $this->add_control(
     85            'class',
     86            [
     87                'label' => __('CSS class name', WPDM_ELEMENTOR),
     88                'type' => \Elementor\Controls_Manager::TEXT,
     89                'input_type' => 'text',
     90            ]
     91        );
    7092
    71         //label Download link label
    72         $this->add_control(
    73             'label',
    74             [
    75                 'label' => esc_attr(__('Download link label', WPDM_ELEMENTOR)),
    76                 'type' => \Elementor\Controls_Manager::TEXT,
    77                 'input_type' => 'text',
    78                 'default' => 'Download',
    79                 'placeholder' => esc_attr(__('Download', WPDM_ELEMENTOR)),
    80             ]
    81         );
     93        $this->add_control(
     94            'eid',
     95            [
     96                'label' => __('HTML element ID', WPDM_ELEMENTOR),
     97                'type' => \Elementor\Controls_Manager::TEXT,
     98                'input_type' => 'text',
     99            ]
     100        );
    82101
    83         //class CSS class name, in case you want to apply some css style
    84         $this->add_control(
    85             'class',
    86             [
    87                 'label' => esc_attr(__('CSS class name', WPDM_ELEMENTOR)),
    88                 'type' => \Elementor\Controls_Manager::TEXT,
    89                 'input_type' => 'text',
    90             ]
    91         );
     102        $this->add_control(
     103            'style',
     104            [
     105                'label' => __('CSS Style', WPDM_ELEMENTOR),
     106                'type' => \Elementor\Controls_Manager::TEXTAREA,
     107                'rows' => 5,
     108                'placeholder' => __('e.g., color: #3399ff;', WPDM_ELEMENTOR),
     109            ]
     110        );
    92111
     112        $this->end_controls_section();
     113    }
    93114
    94         //eid HTML element ID
    95         $this->add_control(
    96             'eid',
    97             [
    98                 'label' => esc_attr(__('HTML element ID', WPDM_ELEMENTOR)),
    99                 'type' => \Elementor\Controls_Manager::TEXT,
    100                 'input_type' => 'text',
    101             ]
    102         );
     115    protected function render()
     116    {
     117        $settings = $this->getCleanSettings(self::SETTINGS_KEYS);
     118        $settings = $this->sanitizeSettings($settings, self::SANITIZERS);
    103119
    104         //style Apple raw css code ( ex: style="color: #3399ff;" )
    105         $this->add_control(
    106             'style',
    107             [
    108                 'label' => esc_attr(__('CSS Style', WPDM_ELEMENTOR)),
    109                 'type' => \Elementor\Controls_Manager::TEXTAREA,
    110                 'rows' => 10,
    111                 'placeholder' => esc_attr(__('Apple raw css code', WPDM_ELEMENTOR)),
    112             ]
    113         );
     120        if (empty($settings['pid'])) {
     121            return;
     122        }
    114123
     124        // Map pid to id for WPDM shortcode
     125        $settings['id'] = $settings['pid'];
     126        unset($settings['pid']);
    115127
    116 
    117         $this->end_controls_section();
    118     }
    119 
    120 
    121 
    122     protected function render()
    123     {
    124 
    125         $settings = $this->get_settings_for_display();
    126         $cus_settings = array_slice($settings, 0, 8);
    127 
    128         echo '<div class="oembed-elementor-widget">';
    129         // p($cus_settings);
    130         $cus_settings['id'] = $cus_settings['pid'];
    131         echo WPDM()->package->shortCodes->directLink($cus_settings);
    132 
    133         echo '</div>';
    134     }
     128        echo $this->wrapOutput(
     129            WPDM()->package->shortCodes->directLink($settings),
     130            'direct-link-widget'
     131        );
     132    }
    135133}
  • wpdm-elementor/trunk/src/widgets/FrontendWidget.php

    r2844275 r3427512  
    33namespace WPDM\Elementor\Widgets;
    44
    5 use Elementor\Widget_Base;
     5/**
     6 * Frontend/Author Dashboard Widget.
     7 * Displays author/contributor dashboard.
     8 */
     9class FrontendWidget extends BaseWidget
     10{
     11    /**
     12     * Expected settings keys for this widget.
     13     */
     14    private const SETTINGS_KEYS = ['logo', 'flaturl', 'hide'];
    615
    7 class FrontendWidget extends Widget_Base
    8 {
     16    /**
     17     * Settings sanitization rules.
     18     */
     19    private const SANITIZERS = [
     20        'logo' => 'url',
     21        'flaturl' => 'text',
     22    ];
    923
    1024    public function get_name()
     
    1529    public function get_title()
    1630    {
    17         return 'Author Dashboard';
     31        return __('Author Dashboard', WPDM_ELEMENTOR);
    1832    }
    1933
     
    2337    }
    2438
    25     public function get_categories()
    26     {
    27         return ['wpdm'];
    28     }
    29 
    3039    protected function register_controls()
    3140    {
    32 
    3341        $this->start_controls_section(
    3442            'content_section',
    3543            [
    36                 'label' => esc_attr(__('Parameters', WPDM_ELEMENTOR)),
     44                'label' => __('Parameters', WPDM_ELEMENTOR),
    3745                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
    3846            ]
    3947        );
    4048
    41 
    42         //logo  optional, add the logo or any image URL you want to show on top of the login form
    4349        $this->add_control(
    4450            'logo',
    4551            [
    46                 'label' => esc_attr(__('Logo URL', WPDM_ELEMENTOR)),
     52                'label' => __('Logo URL', WPDM_ELEMENTOR),
    4753                'type' => \Elementor\Controls_Manager::TEXT,
    4854                'input_type' => 'url',
    49                 'placeholder' => esc_attr(__('Logo Url', WPDM_ELEMENTOR)),
    50                 'description' => 'optional, add the logo or any image URL you want to show on top of the login form'
     55                'placeholder' => __('Logo URL', WPDM_ELEMENTOR),
     56                'description' => __('Image URL to show on top of the dashboard', WPDM_ELEMENTOR)
    5157            ]
    5258        );
    5359
    54 
    55         //flaturl   Optional parameter, default value 0, use flaturl=1 for flat url
    5660        $this->add_control(
    5761            'flaturl',
    5862            [
    59                 'label' => esc_attr(__('Flat Url', WPDM_ELEMENTOR)),
     63                'label' => __('Flat URL', WPDM_ELEMENTOR),
    6064                'type' => \Elementor\Controls_Manager::CHOOSE,
    6165                'options' => [
    62                     '0' => ['title' => 'No', 'icon' => 'fa fa-times'],
    63                     '1' => ['title' => 'Yes', 'icon' => 'fa fa-check']
     66                    '0' => ['title' => __('No', WPDM_ELEMENTOR), 'icon' => 'eicon-close'],
     67                    '1' => ['title' => __('Yes', WPDM_ELEMENTOR), 'icon' => 'eicon-check']
    6468                ],
    6569                'default' => '0'
     
    6771        );
    6872
    69         //hide
    7073        $this->add_control(
    7174            'hide',
    7275            [
    73                 'label' => esc_attr(__('hide', WPDM_ELEMENTOR)),
     76                'label' => __('Hide Elements', WPDM_ELEMENTOR),
    7477                'type' => \Elementor\Controls_Manager::SELECT2,
    7578                'multiple' => true,
    76                 'options' => ['settings' => 'Settings', 'images' => 'Images', 'cats' => 'Categories', 'tags' => 'Tags'],
     79                'options' => [
     80                    'settings' => __('Settings', WPDM_ELEMENTOR),
     81                    'images' => __('Images', WPDM_ELEMENTOR),
     82                    'cats' => __('Categories', WPDM_ELEMENTOR),
     83                    'tags' => __('Tags', WPDM_ELEMENTOR)
     84                ],
    7785                'default' => []
    7886            ]
    7987        );
    8088
    81 
    8289        $this->end_controls_section();
    8390    }
    8491
    85 
    86 
    8792    protected function render()
    8893    {
     94        $settings = $this->getCleanSettings(self::SETTINGS_KEYS);
     95        $settings = $this->sanitizeSettings($settings, self::SANITIZERS);
    8996
    90         $settings = $this->get_settings_for_display();
    91         $cus_settings = array_slice($settings, 0, 4);
    92         $cus_settings['hide'] = implode(',', $cus_settings['hide']);
     97        // Convert hide array to comma-separated string
     98        if (!empty($settings['hide']) && is_array($settings['hide'])) {
     99            $settings['hide'] = implode(',', array_map('sanitize_text_field', $settings['hide']));
     100        }
    93101
    94         echo '<div class="oembed-elementor-widget">';
    95        // p($cus_settings);
    96         echo WPDM()->authorDashboard->dashboard($cus_settings);
    97 
    98         echo '</div>';
     102        echo $this->wrapOutput(
     103            WPDM()->authorDashboard->dashboard($settings),
     104            'author-dashboard-widget'
     105        );
    99106    }
    100107}
  • wpdm-elementor/trunk/src/widgets/LoginFormWidget.php

    r2844275 r3427512  
    33namespace WPDM\Elementor\Widgets;
    44
    5 use Elementor\Widget_Base;
     5/**
     6 * Login Form Widget.
     7 * Displays a user login form.
     8 */
     9class LoginFormWidget extends BaseWidget
     10{
     11    /**
     12     * Expected settings keys for this widget.
     13     */
     14    private const SETTINGS_KEYS = ['redirect', 'logo', 'regurl', 'note_before', 'note_after'];
    615
    7 class LoginFormWidget extends Widget_Base
    8 {
     16    /**
     17     * Settings sanitization rules.
     18     */
     19    private const SANITIZERS = [
     20        'redirect' => 'url',
     21        'logo' => 'url',
     22        'regurl' => 'url',
     23        'note_before' => 'html',
     24        'note_after' => 'html',
     25    ];
    926
    1027    public function get_name()
     
    1532    public function get_title()
    1633    {
    17         return 'Login Form';
     34        return __('Login Form', WPDM_ELEMENTOR);
    1835    }
    1936
     
    2340    }
    2441
    25     public function get_categories()
    26     {
    27         return ['wpdm'];
    28     }
    29 
    3042    protected function register_controls()
    3143    {
     
    3345            'content_section',
    3446            [
    35                 'label' => esc_attr(__('Parameters', WPDM_ELEMENTOR)),
     47                'label' => __('Parameters', WPDM_ELEMENTOR),
    3648                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
    3749            ]
    3850        );
    3951
    40 
    41         //redirect: optional, use an URL where you want users to redirect after login
    4252        $this->add_control(
    4353            'redirect',
    4454            [
    45                 'label' => esc_attr(__('Redirect URL', WPDM_ELEMENTOR)),
     55                'label' => __('Redirect URL', WPDM_ELEMENTOR),
    4656                'type' => \Elementor\Controls_Manager::TEXT,
    4757                'input_type' => 'url',
    48                 'placeholder' => esc_attr(__('Redirect Url', WPDM_ELEMENTOR)),
    49                 'description' => 'optional, use an URL where you want users to redirect after login'
     58                'placeholder' => __('Redirect URL', WPDM_ELEMENTOR),
     59                'description' => __('URL to redirect after login', WPDM_ELEMENTOR)
    5060            ]
    5161        );
    5262
    53 
    54         //logo: optional, add the logo or any image URL you want to show on top of the login form
    5563        $this->add_control(
    5664            'logo',
    5765            [
    58                 'label' => esc_attr(__('Logo URL', WPDM_ELEMENTOR)),
     66                'label' => __('Logo URL', WPDM_ELEMENTOR),
    5967                'type' => \Elementor\Controls_Manager::TEXT,
    6068                'input_type' => 'url',
    61                 'placeholder' => esc_attr(__('Logo Url', WPDM_ELEMENTOR)),
    62                 'description' => 'optional, add the logo or any image URL you want to show on top of the login form'
     69                'placeholder' => __('Logo URL', WPDM_ELEMENTOR),
     70                'description' => __('Image URL to show on top of the form', WPDM_ELEMENTOR)
    6371            ]
    6472        );
    6573
    66 
    67         //regurl: optional, in case, if you have multiple login pages and multiple signup page, you may mention the signup page URL for this login form. Otherwise, it will use the standard signup page URL.
    6874        $this->add_control(
    6975            'regurl',
    7076            [
    71                 'label' => esc_attr(__("Registration URL", WPDM_ELEMENTOR)),
     77                'label' => __('Registration URL', WPDM_ELEMENTOR),
    7278                'type' => \Elementor\Controls_Manager::TEXT,
    7379                'input_type' => 'url',
    74                 'placeholder' => esc_attr(__('Logo Url', WPDM_ELEMENTOR)),
    75                 'description' => 'optional, in case, if you have multiple login pages and multiple signup page, you may mention the signup page URL for this login form. Otherwise, it will use the standard signup page URL.'
     80                'placeholder' => __('Registration URL', WPDM_ELEMENTOR),
     81                'description' => __('Custom signup page URL for this login form', WPDM_ELEMENTOR)
    7682            ]
    7783        );
    7884
    79         //note_before: optional, text/note to show above the login form
    8085        $this->add_control(
    8186            'note_before',
    8287            [
    83                 'label' => esc_attr(__("Note Before", WPDM_ELEMENTOR)),
    84                 'type' => \Elementor\Controls_Manager::TEXT,
    85                 'input_type' => 'text',
    86                 'placeholder' => esc_attr(__('Note before', WPDM_ELEMENTOR)),
    87                 'description' => 'optional, text/note to show above the login form'
     88                'label' => __('Note Before', WPDM_ELEMENTOR),
     89                'type' => \Elementor\Controls_Manager::TEXTAREA,
     90                'rows' => 3,
     91                'placeholder' => __('Text to show above the form', WPDM_ELEMENTOR),
    8892            ]
    8993        );
    9094
    91         // note_after: optional, text/note to show below the login form
    9295        $this->add_control(
    9396            'note_after',
    9497            [
    95                 'label' => esc_attr(__("Note After", WPDM_ELEMENTOR)),
    96                 'type' => \Elementor\Controls_Manager::TEXT,
    97                 'input_type' => 'text',
    98                 'placeholder' => esc_attr(__('Note After', WPDM_ELEMENTOR)),
    99                 'description' => 'optional, text/note to show below the login form'
     98                'label' => __('Note After', WPDM_ELEMENTOR),
     99                'type' => \Elementor\Controls_Manager::TEXTAREA,
     100                'rows' => 3,
     101                'placeholder' => __('Text to show below the form', WPDM_ELEMENTOR),
    100102            ]
    101103        );
    102 
    103104
    104105        $this->end_controls_section();
    105106    }
    106107
    107 
    108 
    109108    protected function render()
    110109    {
     110        $settings = $this->getCleanSettings(self::SETTINGS_KEYS);
     111        $settings = $this->sanitizeSettings($settings, self::SANITIZERS);
    111112
    112         $settings = $this->get_settings_for_display();
    113         $cus_settings = array_slice($settings, 0, 5);
    114 
    115         echo '<div class="oembed-elementor-widget">';
    116         // p($cus_settings);
    117         echo WPDM()->user->login->form($cus_settings);
    118 
    119         echo '</div>';
     113        echo $this->wrapOutput(
     114            WPDM()->user->login->form($settings),
     115            'login-form-widget'
     116        );
    120117    }
    121118}
  • wpdm-elementor/trunk/src/widgets/PackageWidget.php

    r3077561 r3427512  
    33namespace WPDM\Elementor\Widgets;
    44
    5 use Elementor\Widget_Base;
    6 
    7 class PackageWidget extends Widget_Base {
     5/**
     6 * Single Package Widget.
     7 * Embeds a single WPDM package.
     8 */
     9class PackageWidget extends BaseWidget
     10{
     11    /**
     12     * Expected settings keys for this widget.
     13     */
     14    private const SETTINGS_KEYS = ['pid', 'ltemplate'];
    815
    916    /**
    10      * Get widget name.
    11      *
    12      * Retrieve oEmbed widget name.
    13      *
    14      * @since 1.0.0
    15      * @access public
    16      *
    17      * @return string Widget name.
     17     * Settings sanitization rules.
    1818     */
    19     public function get_name() {
     19    private const SANITIZERS = [
     20        'pid' => 'int',
     21        'ltemplate' => 'text',
     22    ];
     23
     24    public function get_name()
     25    {
    2026        return 'wpdmpackage';
    2127    }
    2228
    23     /**
    24      * Get widget title.
    25      *
    26      * Retrieve oEmbed widget title.
    27      *
    28      * @since 1.0.0
    29      * @access public
    30      *
    31      * @return string Widget title.
    32      */
    33     public function get_title() {
    34         return __( 'Package', 'plugin-name' );
     29    public function get_title()
     30    {
     31        return __('Package', WPDM_ELEMENTOR);
    3532    }
    3633
    37     /**
    38      * Get widget icon.
    39      *
    40      * Retrieve oEmbed widget icon.
    41      *
    42      * @since 1.0.0
    43      * @access public
    44      *
    45      * @return string Widget icon.
    46      */
    47     public function get_icon() {
     34    public function get_icon()
     35    {
    4836        return 'eicon-download-button';
    4937    }
    5038
    51     /**
    52      * Get widget categories.
    53      *
    54      * Retrieve the list of categories the oEmbed widget belongs to.
    55      *
    56      * @since 1.0.0
    57      * @access public
    58      *
    59      * @return array Widget categories.
    60      */
    61     public function get_categories() {
    62         return [ 'wpdm' ];
    63     }
    64 
    65     /**
    66      * Register oEmbed widget controls.
    67      *
    68      * Adds different input fields to allow the user to change and customize the widget settings.
    69      *
    70      * @since 1.0.0
    71      * @access protected
    72      */
    73     protected function register_controls() {
    74 
     39    protected function register_controls()
     40    {
    7541        $this->start_controls_section(
    7642            'content_section',
    7743            [
    78                 'label' => __( 'Parameters', 'plugin-name' ),
     44                'label' => __('Parameters', WPDM_ELEMENTOR),
    7945                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
    8046            ]
    8147        );
    8248
    83        /* $this->add_control(
    84             'url',
    85             [
    86                 'label' => __( 'URL to embed', 'plugin-name' ),
    87                 'type' => \Elementor\Controls_Manager::TEXT,
    88                 'input_type' => 'url',
    89                 'placeholder' => __( 'https://your-link.com', 'plugin-name' ),
    90             ]
    91         );*/
    92 
    93         //package ID: Text
    9449        $this->add_control(
    9550            'pid',
    9651            [
    97                 'label' => esc_attr(__('Package', WPDM_ELEMENTOR)),
     52                'label' => __('Package', WPDM_ELEMENTOR),
    9853                'type' => \Elementor\Controls_Manager::SELECT2,
    99                 'placeholder' => esc_attr(__('Package', WPDM_ELEMENTOR)),
    100                 'select2options' => [
    101                     'placeholder' => 'Type Package title',
    102                     'ajax' => [
    103                         'url' =>  get_rest_url(null, 'wpdm-elementor/v1/search-packages'),
    104                         'dataType' => 'json',
    105                         'delay' => 250
    106                     ],
    107                     'minimumInputLength' => 2
    108                 ]
     54                'placeholder' => __('Package', WPDM_ELEMENTOR),
     55                'select2options' => $this->getPackageSearchConfig()
    10956            ]
    11057        );
    11158
    112 
    113         //link template: select
    11459        $this->add_control(
    11560            'ltemplate',
    11661            [
    117                 'label' => esc_attr(__('Link Template', WPDM_ELEMENTOR)),
     62                'label' => __('Link Template', WPDM_ELEMENTOR),
    11863                'type' => \Elementor\Controls_Manager::SELECT2,
    119                 'options' => get_elementor_link_templates(),
     64                'options' => $this->getLinkTemplateOptions(),
    12065                'default' => 'link-template-panel'
    12166            ]
     
    12368
    12469        $this->end_controls_section();
    125 
    12670    }
    12771
    128     /**
    129      * Render oEmbed widget output on the frontend.
    130      *
    131      * Written in PHP and used to generate the final HTML.
    132      *
    133      * @since 1.0.0
    134      * @access protected
    135      */
    136     protected function render() {
     72    protected function render()
     73    {
     74        $settings = $this->getCleanSettings(self::SETTINGS_KEYS);
     75        $settings = $this->sanitizeSettings($settings, self::SANITIZERS);
    13776
    138         $settings = $this->get_settings_for_display();
    139         echo WPDM()->package->shortCodes->singlePackage(['id' => $settings['pid'], 'template' => $settings['ltemplate']]);
     77        if (empty($settings['pid'])) {
     78            return;
     79        }
    14080
     81        echo WPDM()->package->shortCodes->singlePackage([
     82            'id' => $settings['pid'],
     83            'template' => $settings['ltemplate']
     84        ]);
    14185    }
    142 
    14386}
    14487
  • wpdm-elementor/trunk/src/widgets/PackagesWidget.php

    r3259585 r3427512  
    33namespace WPDM\Elementor\Widgets;
    44
    5 use Elementor\Widget_Base;
    6 
    7 class PackagesWidget extends Widget_Base
     5/**
     6 * Packages Widget.
     7 * Displays multiple packages with filtering options.
     8 */
     9class PackagesWidget extends BaseWidget
    810{
     11    /**
     12     * Expected settings keys for this widget.
     13     */
     14    private const SETTINGS_KEYS = [
     15        'search', 'categories', 'include_children', 'tags', 'author',
     16        'orderby', 'order', 'items_per_page', 'template',
     17        'cols', 'colspad', 'colsphone', 'toolbar', 'paging', 'login', 'async'
     18    ];
     19
     20    /**
     21     * Settings sanitization rules.
     22     */
     23    private const SANITIZERS = [
     24        'search' => 'text',
     25        'include_children' => 'text',
     26        'author' => 'text',
     27        'orderby' => 'orderby',
     28        'order' => 'order',
     29        'items_per_page' => 'int',
     30        'template' => 'text',
     31        'cols' => 'int',
     32        'colspad' => 'int',
     33        'colsphone' => 'int',
     34        'toolbar' => 'text',
     35        'paging' => 'text',
     36        'login' => 'text',
     37        'async' => 'text',
     38    ];
    939
    1040    public function get_name()
     
    1545    public function get_title()
    1646    {
    17         return 'Packages';
     47        return __('Packages', WPDM_ELEMENTOR);
    1848    }
    1949
     
    2353    }
    2454
    25     public function get_categories()
    26     {
    27         return ['wpdm'];
    28     }
    29 
    3055    protected function register_controls()
    3156    {
    32 
    3357        $this->start_controls_section(
    3458            'content_section',
    3559            [
    36                 'label' => esc_attr(__('Parameters', WPDM_ELEMENTOR)),
     60                'label' => __('Parameters', WPDM_ELEMENTOR),
    3761                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
    3862            ]
    3963        );
    4064
    41         //search keywords : TEXT filed
    4265        $this->add_control(
    4366            'search',
    4467            [
    45                 'label' => esc_attr(__('Search Keywords', WPDM_ELEMENTOR)),
     68                'label' => __('Search Keywords', WPDM_ELEMENTOR),
    4669                'type' => \Elementor\Controls_Manager::TEXT,
    4770                'input_type' => 'text',
    48                 'placeholder' => esc_attr(__('search keywords', WPDM_ELEMENTOR)),
    49             ]
    50         );
    51 
    52         //include categories: multi select
    53         $wpdmcategory_terms = get_terms(['taxonomoy' => 'wpdmcategory']);
    54         foreach($wpdmcategory_terms as $k => $t){
    55             $wpdmcategory_terms[$t->slug] = $t->name;
    56             unset($wpdmcategory_terms[$k]);
    57         };
    58 
     71                'placeholder' => __('search keywords', WPDM_ELEMENTOR),
     72            ]
     73        );
    5974
    6075        $this->add_control(
    6176            'categories',
    6277            [
    63                 'label' => esc_attr(__('Include Categories', WPDM_ELEMENTOR)),
     78                'label' => __('Include Categories', WPDM_ELEMENTOR),
    6479                'type' => \Elementor\Controls_Manager::SELECT2,
    6580                'multiple' => true,
    66                 'options' => $wpdmcategory_terms,
     81                'options' => $this->getCategoryOptions(),
    6782                'default' => []
    6883            ]
    6984        );
    7085
    71         //include children: radio
    7286        $this->add_control(
    7387            'include_children',
    7488            [
    75                 'label' => esc_attr(__('Include Children', WPDM_ELEMENTOR)),
    76                 'type' => \Elementor\Controls_Manager::CHOOSE,
    77                 'options' => [
    78                     '0' => ['title' => 'No', 'icon' => 'fa fa-times'],
    79                     '1' => ['title' => 'Yes', 'icon' => 'fa fa-check']
     89                'label' => __('Include Children', WPDM_ELEMENTOR),
     90                'type' => \Elementor\Controls_Manager::CHOOSE,
     91                'options' => [
     92                    '0' => ['title' => __('No', WPDM_ELEMENTOR), 'icon' => 'eicon-close'],
     93                    '1' => ['title' => __('Yes', WPDM_ELEMENTOR), 'icon' => 'eicon-check']
    8094                ],
    8195                'default' => '0'
     
    8397        );
    8498
    85         //category match: radios
    86 
    87         //exclude categories: multi select
    88 
    89         //tags: multi select
    90         $post_tag_terms = get_terms(['taxonomy' => 'wpdmtag']);
    91         if(is_array($post_tag_terms)) {
    92             foreach ($post_tag_terms as $k => $t) {
    93                 $post_tag_terms[$t->slug] = $t->name;
    94                 unset($post_tag_terms[$k]);
    95             };
     99        $tag_options = $this->getTagOptions();
     100        if (!empty($tag_options)) {
    96101            $this->add_control(
    97102                'tags',
    98103                [
    99                     'label' => esc_attr(__('Tags', WPDM_ELEMENTOR)),
     104                    'label' => __('Tags', WPDM_ELEMENTOR),
    100105                    'type' => \Elementor\Controls_Manager::SELECT2,
    101106                    'multiple' => true,
    102                     'options' => $post_tag_terms,
     107                    'options' => $tag_options,
    103108                    'default' => []
    104109                ]
     
    106111        }
    107112
    108         //exclude packages with text: text
    109 
    110         //authors: Text
    111113        $this->add_control(
    112114            'author',
    113115            [
    114                 'label' => esc_attr(__('Authors', WPDM_ELEMENTOR)),
     116                'label' => __('Authors', WPDM_ELEMENTOR),
    115117                'type' => \Elementor\Controls_Manager::TEXT,
    116118                'input_type' => 'text',
    117                 'placeholder' => esc_attr(__('1, 2, 3', WPDM_ELEMENTOR)),
    118                 'description' => esc_attr(__('Author IDs seperated by comma', WPDM_ELEMENTOR))
    119             ]
    120         );
    121 
    122         //exclude packages from author: text
    123 
    124 
    125 
    126         //order by: Select
     119                'placeholder' => __('1, 2, 3', WPDM_ELEMENTOR),
     120                'description' => __('Author IDs separated by comma', WPDM_ELEMENTOR)
     121            ]
     122        );
     123
    127124        $this->add_control(
    128125            'orderby',
    129126            [
    130                 'label' => esc_attr(__('Order By', WPDM_ELEMENTOR)),
     127                'label' => __('Order By', WPDM_ELEMENTOR),
    131128                'type' => \Elementor\Controls_Manager::SELECT2,
    132                 'options' => ['date' => 'Date', 'title' => 'Title'],
     129                'options' => ['date' => __('Date', WPDM_ELEMENTOR), 'title' => __('Title', WPDM_ELEMENTOR)],
    133130                'default' => 'date',
    134131            ]
    135132        );
    136133
    137         //order: Select
    138134        $this->add_control(
    139135            'order',
    140136            [
    141                 'label' => esc_attr(__('Order', WPDM_ELEMENTOR)),
    142                 'type' => \Elementor\Controls_Manager::CHOOSE,
    143                 'options' => [
    144                     'ASC' => ['title' => 'Ascending', 'icon' => 'fa fa-sort-alpha-down'],
    145                     'DESC' => ['title' => 'Descending', 'icon' => 'fa fa-sort-alpha-up']
     137                'label' => __('Order', WPDM_ELEMENTOR),
     138                'type' => \Elementor\Controls_Manager::CHOOSE,
     139                'options' => [
     140                    'ASC' => ['title' => __('Ascending', WPDM_ELEMENTOR), 'icon' => 'eicon-arrow-up'],
     141                    'DESC' => ['title' => __('Descending', WPDM_ELEMENTOR), 'icon' => 'eicon-arrow-down']
    146142                ],
    147143                'default' => 'DESC',
    148                 'show_label' => false
    149             ]
    150         );
    151 
    152         //items per page: text number
     144                'toggle' => false
     145            ]
     146        );
     147
    153148        $this->add_control(
    154149            'items_per_page',
    155150            [
    156                 'label' => esc_attr(__('Items Per Page', WPDM_ELEMENTOR)),
    157                 'type' => \Elementor\Controls_Manager::TEXT,
    158                 'input_type' => 'number',
    159                 'default' => '10'
    160             ]
    161         );
    162 
     151                'label' => __('Items Per Page', WPDM_ELEMENTOR),
     152                'type' => \Elementor\Controls_Manager::NUMBER,
     153                'min' => 1,
     154                'max' => 100,
     155                'default' => 10
     156            ]
     157        );
    163158
    164159        $this->add_control(
    165160            'template',
    166161            [
    167                 'label' => esc_attr(__('Link Template', WPDM_ELEMENTOR)),
     162                'label' => __('Link Template', WPDM_ELEMENTOR),
    168163                'type' => \Elementor\Controls_Manager::SELECT2,
    169                 'options' => get_elementor_link_templates(),
     164                'options' => $this->getLinkTemplateOptions(),
    170165                'default' => 'link-template-default'
    171166            ]
    172167        );
    173168
    174         //cols web
    175169        $this->add_control(
    176170            'cols',
    177171            [
    178                 'label' => esc_attr(__('Columns In PC', WPDM_ELEMENTOR)),
    179                 'type' => \Elementor\Controls_Manager::TEXT,
    180                 'input_type' => 'number',
    181                 'default' => '3'
    182             ]
    183         );
    184 
    185         //cols tab
     172                'label' => __('Columns (Desktop)', WPDM_ELEMENTOR),
     173                'type' => \Elementor\Controls_Manager::NUMBER,
     174                'min' => 1,
     175                'max' => 6,
     176                'default' => 3
     177            ]
     178        );
     179
    186180        $this->add_control(
    187181            'colspad',
    188182            [
    189                 'label' => esc_attr(__('Columns In Tab', WPDM_ELEMENTOR)),
    190                 'type' => \Elementor\Controls_Manager::TEXT,
    191                 'input_type' => 'number',
    192                 'default' => '2'
    193             ]
    194         );
    195 
    196         //cols phone
     183                'label' => __('Columns (Tablet)', WPDM_ELEMENTOR),
     184                'type' => \Elementor\Controls_Manager::NUMBER,
     185                'min' => 1,
     186                'max' => 4,
     187                'default' => 2
     188            ]
     189        );
     190
    197191        $this->add_control(
    198192            'colsphone',
    199193            [
    200                 'label' => esc_attr(__('Columns In Phone', WPDM_ELEMENTOR)),
    201                 'type' => \Elementor\Controls_Manager::TEXT,
    202                 'input_type' => 'number',
    203                 'default' => '1'
    204             ]
    205         );
    206 
    207         //Show Toolbar: radio
     194                'label' => __('Columns (Phone)', WPDM_ELEMENTOR),
     195                'type' => \Elementor\Controls_Manager::NUMBER,
     196                'min' => 1,
     197                'max' => 2,
     198                'default' => 1
     199            ]
     200        );
     201
    208202        $this->add_control(
    209203            'toolbar',
    210204            [
    211                 'label' => esc_attr(__('Show Toolbar', WPDM_ELEMENTOR)),
    212                 'type' => \Elementor\Controls_Manager::CHOOSE,
    213                 'options' => [
    214                     '1' => ['title' => 'Show', 'icon' => 'fa fa-check'],
    215                     '0' => ['title' => 'Hide', 'icon' => 'fa fa-times']
     205                'label' => __('Show Toolbar', WPDM_ELEMENTOR),
     206                'type' => \Elementor\Controls_Manager::CHOOSE,
     207                'options' => [
     208                    '1' => ['title' => __('Show', WPDM_ELEMENTOR), 'icon' => 'eicon-check'],
     209                    '0' => ['title' => __('Hide', WPDM_ELEMENTOR), 'icon' => 'eicon-close']
    216210                ],
    217211                'default' => '1',
     
    219213        );
    220214
    221         //show pagination: radio
    222215        $this->add_control(
    223216            'paging',
    224217            [
    225                 'label' => esc_attr(__('Paging', WPDM_ELEMENTOR)),
    226                 'type' => \Elementor\Controls_Manager::CHOOSE,
    227                 'options' => [
    228                     '1' => ['title' => 'Show', 'icon' => 'fa fa-check'],
    229                     '0' => ['title' => 'Hide', 'icon' => 'fa fa-times']
     218                'label' => __('Pagination', WPDM_ELEMENTOR),
     219                'type' => \Elementor\Controls_Manager::CHOOSE,
     220                'options' => [
     221                    '1' => ['title' => __('Show', WPDM_ELEMENTOR), 'icon' => 'eicon-check'],
     222                    '0' => ['title' => __('Hide', WPDM_ELEMENTOR), 'icon' => 'eicon-close']
    230223                ],
    231224                'default' => '0',
     
    233226        );
    234227
    235         //Require login: choose
    236228        $this->add_control(
    237229            'login',
    238230            [
    239                 'label' => esc_attr(__('Require Login', WPDM_ELEMENTOR)),
    240                 'type' => \Elementor\Controls_Manager::CHOOSE,
    241                 'options' => [
    242                     '0' => ['title' => 'No', 'icon' => 'fa fa-times'],
    243                     '1' => ['title' => 'Yes', 'icon' => 'fa fa-check']
     231                'label' => __('Require Login', WPDM_ELEMENTOR),
     232                'type' => \Elementor\Controls_Manager::CHOOSE,
     233                'options' => [
     234                    '0' => ['title' => __('No', WPDM_ELEMENTOR), 'icon' => 'eicon-close'],
     235                    '1' => ['title' => __('Yes', WPDM_ELEMENTOR), 'icon' => 'eicon-check']
    244236                ],
    245237                'default' => '0'
     
    247239        );
    248240
    249         //enable async request: radio
    250241        $this->add_control(
    251242            'async',
    252243            [
    253                 'label' => esc_attr(__('Async', WPDM_ELEMENTOR)),
    254                 'type' => \Elementor\Controls_Manager::CHOOSE,
    255                 'options' => [
    256                     '1' => ['title' => 'Enable', 'icon' => 'fa fa-check'],
    257                     '0' => ['title' => 'Disable', 'icon' => 'fa fa-times']
     244                'label' => __('Async Loading', WPDM_ELEMENTOR),
     245                'type' => \Elementor\Controls_Manager::CHOOSE,
     246                'options' => [
     247                    '1' => ['title' => __('Enable', WPDM_ELEMENTOR), 'icon' => 'eicon-check'],
     248                    '0' => ['title' => __('Disable', WPDM_ELEMENTOR), 'icon' => 'eicon-close']
    258249                ],
    259250                'default' => '1',
     
    264255    }
    265256
    266 
    267 
    268257    protected function render()
    269258    {
    270 
    271         $settings = $this->get_settings_for_display();
    272         $cus_settings = array_slice($settings, 0, 20);
    273 
    274         if(isset($cus_settings['categories']) && is_array($cus_settings['categories']))
    275             $cus_settings['categories'] = implode(",", $cus_settings['categories']);
    276         if(isset($cus_settings['tags']) && is_array($cus_settings['tags']))
    277             $cus_settings['tags'] = implode(",", $cus_settings['tags']);
    278 
    279         //echo '<div class="oembed-elementor-widget">';
    280 
    281         echo WPDM()->package->shortCodes->packages($cus_settings);
    282 
    283         //echo '</div>';
     259        $settings = $this->getCleanSettings(self::SETTINGS_KEYS);
     260        $settings = $this->sanitizeSettings($settings, self::SANITIZERS);
     261
     262        // Convert arrays to comma-separated strings
     263        $settings = $this->arraysToComma($settings, ['categories', 'tags']);
     264
     265        echo WPDM()->package->shortCodes->packages($settings);
    284266    }
    285267}
  • wpdm-elementor/trunk/src/widgets/RegFormWidget.php

    r2844275 r3427512  
    33namespace WPDM\Elementor\Widgets;
    44
    5 use Elementor\Widget_Base;
     5/**
     6 * Registration Form Widget.
     7 * Displays a user registration form.
     8 */
     9class RegFormWidget extends BaseWidget
     10{
     11    /**
     12     * Expected settings keys for this widget.
     13     */
     14    private const SETTINGS_KEYS = ['captcha', 'verifyemail', 'autologin', 'logo'];
    615
    7 class RegFormWidget extends Widget_Base
    8 {
     16    /**
     17     * Settings sanitization rules.
     18     */
     19    private const SANITIZERS = [
     20        'captcha' => 'bool',
     21        'verifyemail' => 'bool',
     22        'autologin' => 'bool',
     23        'logo' => 'url',
     24    ];
    925
    1026    public function get_name()
     
    1531    public function get_title()
    1632    {
    17         return 'Registration Form';
     33        return __('Registration Form', WPDM_ELEMENTOR);
    1834    }
    1935
     
    2339    }
    2440
    25     public function get_categories()
    26     {
    27         return ['wpdm'];
    28     }
    29 
    3041    protected function register_controls()
    3142    {
    32 
    3343        $this->start_controls_section(
    3444            'content_section',
    3545            [
    36                 'label' => esc_attr(__('Parameters', WPDM_ELEMENTOR)),
     46                'label' => __('Parameters', WPDM_ELEMENTOR),
    3747                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
    3848            ]
    3949        );
    4050
    41 
    42         // captcha: optional, default value "true", shows/hides captcha with registration form on true/false
    4351        $this->add_control(
    4452            'captcha',
    4553            [
    46                 'label' => esc_attr(__('Captcha', WPDM_ELEMENTOR)),
     54                'label' => __('Show Captcha', WPDM_ELEMENTOR),
    4755                'type' => \Elementor\Controls_Manager::CHOOSE,
    4856                'options' => [
    49                     '0' => ['title' => 'No', 'icon' => 'fa fa-times'],
    50                     '1' => ['title' => 'Yes', 'icon' => 'fa fa-check']
    51                 ],
    52                 'default' => '1'
    53             ]
    54         );
    55         //verifyemail: optional, the default value is true, if the value is false, it shows the password field with registration form and doesn't send verification email, otherwise, it doesn't show the password field and send the password to registered email.
    56         $this->add_control(
    57             'verifyemail',
    58             [
    59                 'label' => esc_attr(__('Verify Email', WPDM_ELEMENTOR)),
    60                 'type' => \Elementor\Controls_Manager::CHOOSE,
    61                 'options' => [
    62                     '0' => ['title' => 'No', 'icon' => 'fa fa-times'],
    63                     '1' => ['title' => 'Yes', 'icon' => 'fa fa-check']
     57                    '0' => ['title' => __('No', WPDM_ELEMENTOR), 'icon' => 'eicon-close'],
     58                    '1' => ['title' => __('Yes', WPDM_ELEMENTOR), 'icon' => 'eicon-check']
    6459                ],
    6560                'default' => '1'
     
    6762        );
    6863
    69         //autologin: optional, default value is "false" when "verifyemail" is true, the default value is "true" when "verifyemail" is 0, after registration, it will auto-login when the value is true otherwise redirect to the login page.
     64        $this->add_control(
     65            'verifyemail',
     66            [
     67                'label' => __('Verify Email', WPDM_ELEMENTOR),
     68                'type' => \Elementor\Controls_Manager::CHOOSE,
     69                'options' => [
     70                    '0' => ['title' => __('No', WPDM_ELEMENTOR), 'icon' => 'eicon-close'],
     71                    '1' => ['title' => __('Yes', WPDM_ELEMENTOR), 'icon' => 'eicon-check']
     72                ],
     73                'default' => '1',
     74                'description' => __('Send password via email when enabled', WPDM_ELEMENTOR)
     75            ]
     76        );
     77
    7078        $this->add_control(
    7179            'autologin',
    7280            [
    73                 'label' => esc_attr(__('Auto Login', WPDM_ELEMENTOR)),
     81                'label' => __('Auto Login', WPDM_ELEMENTOR),
    7482                'type' => \Elementor\Controls_Manager::CHOOSE,
    7583                'options' => [
    76                     '0' => ['title' => 'No', 'icon' => 'fa fa-times'],
    77                     '1' => ['title' => 'Yes', 'icon' => 'fa fa-check']
     84                    '0' => ['title' => __('No', WPDM_ELEMENTOR), 'icon' => 'eicon-close'],
     85                    '1' => ['title' => __('Yes', WPDM_ELEMENTOR), 'icon' => 'eicon-check']
    7886                ],
    79                 'default' => '0'
     87                'default' => '0',
     88                'description' => __('Automatically log in user after registration', WPDM_ELEMENTOR)
    8089            ]
    8190        );
    8291
    83 
    84         //logo: optional, add a logo or any image URL you want to show at the top of the registration form
    8592        $this->add_control(
    8693            'logo',
    8794            [
    88                 'label' => esc_attr(__('Logo URL', WPDM_ELEMENTOR)),
     95                'label' => __('Logo URL', WPDM_ELEMENTOR),
    8996                'type' => \Elementor\Controls_Manager::TEXT,
    9097                'input_type' => 'url',
    91                 'placeholder' => esc_attr(__('Logo Url', WPDM_ELEMENTOR)),
    92                 'description' => 'optional, add the logo or any image URL you want to show on top of the login form'
     98                'placeholder' => __('Logo URL', WPDM_ELEMENTOR),
     99                'description' => __('Image URL to show on top of the form', WPDM_ELEMENTOR)
    93100            ]
    94101        );
    95 
    96 
    97102
    98103        $this->end_controls_section();
    99104    }
    100105
    101 
    102 
    103106    protected function render()
    104107    {
     108        $settings = $this->getCleanSettings(self::SETTINGS_KEYS);
     109        $settings = $this->sanitizeSettings($settings, self::SANITIZERS);
    105110
    106         $settings = $this->get_settings_for_display();
    107         $cus_settings = array_slice($settings, 0, 5);
    108         $cus_settings['captcha'] = (bool) $cus_settings['captcha'];
    109         $cus_settings['verifyemail'] = (bool) $cus_settings['verifyemail'];
    110         $cus_settings['autologin'] = (bool) $cus_settings['autologin'];
    111 
    112         echo WPDM()->user->register->form($cus_settings);
    113 
     111        echo $this->wrapOutput(
     112            WPDM()->user->register->form($settings),
     113            'registration-form-widget'
     114        );
    114115    }
    115116}
  • wpdm-elementor/trunk/src/widgets/SearchResultWidget.php

    r2844275 r3427512  
    33namespace WPDM\Elementor\Widgets;
    44
    5 use Elementor\Widget_Base;
     5/**
     6 * Search Result Widget.
     7 * Displays search box and search results.
     8 */
     9class SearchResultWidget extends BaseWidget
     10{
     11    /**
     12     * Expected settings keys for this widget.
     13     */
     14    private const SETTINGS_KEYS = ['template', 'init', 'cols'];
    615
    7 class SearchResultWidget extends Widget_Base
    8 {
     16    /**
     17     * Settings sanitization rules.
     18     */
     19    private const SANITIZERS = [
     20        'template' => 'text',
     21        'init' => 'text',
     22        'cols' => 'int',
     23    ];
    924
    1025    public function get_name()
     
    1530    public function get_title()
    1631    {
    17         return 'Search Result';
     32        return __('Search Result', WPDM_ELEMENTOR);
    1833    }
    1934
     
    2338    }
    2439
    25     public function get_categories()
    26     {
    27         return ['wpdm'];
    28     }
    29 
    3040    protected function register_controls()
    3141    {
    32 
    3342        $this->start_controls_section(
    3443            'content_section',
    3544            [
    36                 'label' => esc_attr(__('Parameters', WPDM_ELEMENTOR)),
     45                'label' => __('Parameters', WPDM_ELEMENTOR),
    3746                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
    3847            ]
    3948        );
    4049
    41         //link template: select
    4250        $this->add_control(
    4351            'template',
    4452            [
    45                 'label' => esc_attr(__('Link Template', WPDM_ELEMENTOR)),
     53                'label' => __('Link Template', WPDM_ELEMENTOR),
    4654                'type' => \Elementor\Controls_Manager::SELECT2,
    4755                'options' => get_wpdm_link_templates(),
    48                 'default' => 'link-default-default'
     56                'default' => 'link-template-default'
    4957            ]
    5058        );
    5159
    52         //init: 1 if you want to show some results initially, like the latest packages, skip the parameter or 0 if you don't want to show any package until you search
    5360        $this->add_control(
    5461            'init',
    5562            [
    56                 'label' => esc_attr(__('Require Login', WPDM_ELEMENTOR)),
     63                'label' => __('Show Initial Results', WPDM_ELEMENTOR),
    5764                'type' => \Elementor\Controls_Manager::CHOOSE,
    5865                'options' => [
    59                     '0' => ['title' => 'No', 'icon' => 'fa fa-times'],
    60                     '1' => ['title' => 'Yes', 'icon' => 'fa fa-check']
     66                    '0' => ['title' => __('No', WPDM_ELEMENTOR), 'icon' => 'eicon-close'],
     67                    '1' => ['title' => __('Yes', WPDM_ELEMENTOR), 'icon' => 'eicon-check']
    6168                ],
    62                 'default' => '1'
     69                'default' => '1',
     70                'description' => __('Show latest packages before search', WPDM_ELEMENTOR)
    6371            ]
    6472        );
    65        
    66         //cols: 1 or 2 or 3 or 4 columns search result
     73
    6774        $this->add_control(
    6875            'cols',
    6976            [
    70                 'label' => esc_attr(__('Columns', WPDM_ELEMENTOR)),
    71                 'type' => \Elementor\Controls_Manager::TEXT,
    72                 'input_type' => 'number',
    73                 'default' => '3'
     77                'label' => __('Columns', WPDM_ELEMENTOR),
     78                'type' => \Elementor\Controls_Manager::NUMBER,
     79                'min' => 1,
     80                'max' => 4,
     81                'default' => 3
    7482            ]
    7583        );
     
    7886    }
    7987
    80 
    81 
    8288    protected function render()
    8389    {
     90        $settings = $this->getCleanSettings(self::SETTINGS_KEYS);
     91        $settings = $this->sanitizeSettings($settings, self::SANITIZERS);
    8492
    85         $settings = $this->get_settings_for_display();
    86         $cus_settings = array_slice($settings, 0, 4);
    87 
    88 
    89         echo WPDM()->package->shortCodes->searchResult($cus_settings);
    90 
     93        echo WPDM()->package->shortCodes->searchResult($settings);
    9194    }
    9295}
  • wpdm-elementor/trunk/src/widgets/TagWidget.php

    r3259585 r3427512  
    33namespace WPDM\Elementor\Widgets;
    44
    5 use Elementor\Widget_Base;
    6 
    7 class TagWidget extends Widget_Base
     5/**
     6 * Tag Widget.
     7 * Displays packages filtered by tags.
     8 * Note: This widget is currently disabled in Main.php
     9 */
     10class TagWidget extends BaseWidget
    811{
     12    /**
     13     * Expected settings keys for this widget.
     14     */
     15    private const SETTINGS_KEYS = [
     16        'tagid', 'title', 'desc', 'items_per_page',
     17        'orderby', 'order', 'template',
     18        'cols', 'colspad', 'colsphone', 'toolbar'
     19    ];
     20
     21    /**
     22     * Settings sanitization rules.
     23     */
     24    private const SANITIZERS = [
     25        'title' => 'text',
     26        'desc' => 'text',
     27        'items_per_page' => 'int',
     28        'orderby' => 'orderby',
     29        'order' => 'order',
     30        'template' => 'text',
     31        'cols' => 'int',
     32        'colspad' => 'int',
     33        'colsphone' => 'int',
     34        'toolbar' => 'text',
     35    ];
    936
    1037    public function get_name()
     
    1542    public function get_title()
    1643    {
    17         return 'Packages By Tags';
     44        return __('Packages By Tags', WPDM_ELEMENTOR);
    1845    }
    1946
    2047    public function get_icon()
    2148    {
    22         return 'fa fa-tags';
    23     }
    24 
    25     public function get_categories()
    26     {
    27         return ['wpdm'];
     49        return 'eicon-tags';
    2850    }
    2951
    3052    protected function register_controls()
    3153    {
    32 
    3354        $this->start_controls_section(
    3455            'content_section',
    3556            [
    36                 'label' => esc_attr(__('Parameters', WPDM_ELEMENTOR)),
     57                'label' => __('Parameters', WPDM_ELEMENTOR),
    3758                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
    3859            ]
    3960        );
    4061
    41 
    42         //categories: multi select
    4362        $this->add_control(
    4463            'tagid',
    4564            [
    46                 'label' => esc_attr(__('Tags', WPDM_ELEMENTOR)),
     65                'label' => __('Tags', WPDM_ELEMENTOR),
    4766                'type' => \Elementor\Controls_Manager::SELECT2,
    4867                'multiple' => true,
    49                 'options' => get_wpdmcategory_terms(),
     68                'options' => $this->getTagOptions(),
    5069                'default' => []
    5170            ]
    5271        );
    5372
    54         //title: Text
    5573        $this->add_control(
    5674            'title',
    5775            [
    58                 'label' => esc_attr(__('Title', WPDM_ELEMENTOR)),
     76                'label' => __('Title', WPDM_ELEMENTOR),
    5977                'type' => \Elementor\Controls_Manager::TEXT,
    6078                'input_type' => 'text',
    61                 'description' => esc_attr(__('You can use any text there, if you use “1” then it will show the Tag title', WPDM_ELEMENTOR)),
     79                'description' => __('Use "1" to show tag title, or enter custom text', WPDM_ELEMENTOR),
    6280                'default' => '1'
    6381            ]
    6482        );
    6583
    66         //description: Text
    6784        $this->add_control(
    6885            'desc',
    6986            [
    70                 'label' => esc_attr(__('Description', WPDM_ELEMENTOR)),
     87                'label' => __('Description', WPDM_ELEMENTOR),
    7188                'type' => \Elementor\Controls_Manager::TEXT,
    7289                'input_type' => 'text',
    73                 'description' => esc_attr(__('You can use any text there, if you use “1” then it will show the tag description', WPDM_ELEMENTOR)),
     90                'description' => __('Use "1" to show tag description, or enter custom text', WPDM_ELEMENTOR),
    7491                'default' => '1'
    75 
    76             ]
    77         );
    78 
    79         //items per page: text number
     92            ]
     93        );
     94
    8095        $this->add_control(
    8196            'items_per_page',
    8297            [
    83                 'label' => esc_attr(__('Items Per Page', WPDM_ELEMENTOR)),
    84                 'type' => \Elementor\Controls_Manager::TEXT,
    85                 'input_type' => 'number',
    86                 'default' => '10'
    87             ]
    88         );
    89 
    90 
    91         //order by: Select
     98                'label' => __('Items Per Page', WPDM_ELEMENTOR),
     99                'type' => \Elementor\Controls_Manager::NUMBER,
     100                'min' => 1,
     101                'max' => 100,
     102                'default' => 10
     103            ]
     104        );
     105
    92106        $this->add_control(
    93107            'orderby',
    94108            [
    95                 'label' => esc_attr(__('Order By', WPDM_ELEMENTOR)),
     109                'label' => __('Order By', WPDM_ELEMENTOR),
    96110                'type' => \Elementor\Controls_Manager::SELECT2,
    97                 'options' => ['date' => 'Date', 'title' => 'Title'],
     111                'options' => ['date' => __('Date', WPDM_ELEMENTOR), 'title' => __('Title', WPDM_ELEMENTOR)],
    98112                'default' => 'date',
    99113            ]
    100114        );
    101115
    102         //order: Choose
    103116        $this->add_control(
    104117            'order',
    105118            [
    106                 'label' => esc_attr(__('Order', WPDM_ELEMENTOR)),
     119                'label' => __('Order', WPDM_ELEMENTOR),
    107120                'type' => \Elementor\Controls_Manager::CHOOSE,
    108121                'options' => [
    109                     'ASC' => ['title' => 'Ascending', 'icon' => 'fa fa-sort-alpha-down'],
    110                     'DESC' => ['title' => 'Descending', 'icon' => 'fa fa-sort-alpha-up']
     122                    'ASC' => ['title' => __('Ascending', WPDM_ELEMENTOR), 'icon' => 'eicon-arrow-up'],
     123                    'DESC' => ['title' => __('Descending', WPDM_ELEMENTOR), 'icon' => 'eicon-arrow-down']
    111124                ],
    112125                'default' => 'DESC',
    113                 'show_label' => false
    114             ]
    115         );
    116 
    117 
    118         //link template: select
     126                'toggle' => false
     127            ]
     128        );
    119129
    120130        $this->add_control(
    121131            'template',
    122132            [
    123                 'label' => esc_attr(__('Link Template', WPDM_ELEMENTOR)),
     133                'label' => __('Link Template', WPDM_ELEMENTOR),
    124134                'type' => \Elementor\Controls_Manager::SELECT2,
    125135                'options' => get_wpdm_link_templates(),
    126                 'default' => 'link-default-default'
    127             ]
    128         );
    129 
    130 
    131         //cols web
     136                'default' => 'link-template-default'
     137            ]
     138        );
     139
    132140        $this->add_control(
    133141            'cols',
    134142            [
    135                 'label' => esc_attr(__('Columns In PC', WPDM_ELEMENTOR)),
    136                 'type' => \Elementor\Controls_Manager::TEXT,
    137                 'input_type' => 'number',
    138                 'default' => '3'
    139             ]
    140         );
    141 
    142         //cols tab
     143                'label' => __('Columns (Desktop)', WPDM_ELEMENTOR),
     144                'type' => \Elementor\Controls_Manager::NUMBER,
     145                'min' => 1,
     146                'max' => 6,
     147                'default' => 3
     148            ]
     149        );
     150
    143151        $this->add_control(
    144152            'colspad',
    145153            [
    146                 'label' => esc_attr(__('Columns In Tab', WPDM_ELEMENTOR)),
    147                 'type' => \Elementor\Controls_Manager::TEXT,
    148                 'input_type' => 'number',
    149                 'default' => '2'
    150             ]
    151         );
    152 
    153         //cols phone
     154                'label' => __('Columns (Tablet)', WPDM_ELEMENTOR),
     155                'type' => \Elementor\Controls_Manager::NUMBER,
     156                'min' => 1,
     157                'max' => 4,
     158                'default' => 2
     159            ]
     160        );
     161
    154162        $this->add_control(
    155163            'colsphone',
    156164            [
    157                 'label' => esc_attr(__('Columns In Phone', WPDM_ELEMENTOR)),
    158                 'type' => \Elementor\Controls_Manager::TEXT,
    159                 'input_type' => 'number',
    160                 'default' => '1'
    161             ]
    162         );
    163 
    164         //Show Toolbar: radio
     165                'label' => __('Columns (Phone)', WPDM_ELEMENTOR),
     166                'type' => \Elementor\Controls_Manager::NUMBER,
     167                'min' => 1,
     168                'max' => 2,
     169                'default' => 1
     170            ]
     171        );
     172
    165173        $this->add_control(
    166174            'toolbar',
    167175            [
    168                 'label' => esc_attr(__('Show Toolbar', WPDM_ELEMENTOR)),
     176                'label' => __('Show Toolbar', WPDM_ELEMENTOR),
    169177                'type' => \Elementor\Controls_Manager::CHOOSE,
    170178                'options' => [
    171                     '1' => ['title' => 'Show', 'icon' => 'fa fa-check'],
    172                     '0' => ['title' => 'Hide', 'icon' => 'fa fa-times']
     179                    '1' => ['title' => __('Show', WPDM_ELEMENTOR), 'icon' => 'eicon-check'],
     180                    '0' => ['title' => __('Hide', WPDM_ELEMENTOR), 'icon' => 'eicon-close']
    173181                ],
    174182                'default' => '1',
     
    179187    }
    180188
    181 
    182 
    183189    protected function render()
    184190    {
    185 
    186         $settings = $this->get_settings_for_display();
    187         $cus_settings = array_slice($settings, 0, 15);
    188 
    189         $cus_settings['id'] = implode(",", $cus_settings['tagid']);
    190 
    191         echo WPDM()->package->shortCodes->packagesByTag($cus_settings);
    192 
     191        $settings = $this->getCleanSettings(self::SETTINGS_KEYS);
     192        $settings = $this->sanitizeSettings($settings, self::SANITIZERS);
     193
     194        if (empty($settings['tagid'])) {
     195            return;
     196        }
     197
     198        // Convert tagid array to comma-separated id
     199        $settings['id'] = is_array($settings['tagid'])
     200            ? implode(',', array_map('sanitize_text_field', $settings['tagid']))
     201            : sanitize_text_field($settings['tagid']);
     202
     203        unset($settings['tagid']);
     204
     205        echo WPDM()->package->shortCodes->packagesByTag($settings);
    193206    }
    194207}
  • wpdm-elementor/trunk/src/widgets/UserDashboardWidget.php

    r2844275 r3427512  
    33namespace WPDM\Elementor\Widgets;
    44
    5 use Elementor\Widget_Base;
     5/**
     6 * User Dashboard Widget.
     7 * Displays user dashboard with favorites and recommendations.
     8 */
     9class UserDashboardWidget extends BaseWidget
     10{
     11    /**
     12     * Expected settings keys for this widget.
     13     */
     14    private const SETTINGS_KEYS = ['logo', 'recommended', 'fav', 'signup', 'flaturl'];
    615
    7 class UserDashboardWidget extends Widget_Base
    8 {
     16    /**
     17     * Settings sanitization rules.
     18     */
     19    private const SANITIZERS = [
     20        'logo' => 'url',
     21        'recommended' => 'text',
     22        'fav' => 'text',
     23        'signup' => 'text',
     24        'flaturl' => 'text',
     25    ];
    926
    1027    public function get_name()
     
    1532    public function get_title()
    1633    {
    17         return 'User Dashboard';
     34        return __('User Dashboard', WPDM_ELEMENTOR);
    1835    }
    1936
     
    2340    }
    2441
    25     public function get_categories()
    26     {
    27         return ['wpdm'];
    28     }
    29 
    3042    protected function register_controls()
    3143    {
    32 
    3344        $this->start_controls_section(
    3445            'content_section',
    3546            [
    36                 'label' => esc_attr(__('Parameters', WPDM_ELEMENTOR)),
     47                'label' => __('Parameters', WPDM_ELEMENTOR),
    3748                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
    3849            ]
    3950        );
    4051
    41 
    42         //logo  optional, add the logo or any image URL you want to show on top of the login form
    4352        $this->add_control(
    4453            'logo',
    4554            [
    46                 'label' => esc_attr(__('Logo URL', WPDM_ELEMENTOR)),
     55                'label' => __('Logo URL', WPDM_ELEMENTOR),
    4756                'type' => \Elementor\Controls_Manager::TEXT,
    4857                'input_type' => 'url',
    49                 'placeholder' => esc_attr(__('Logo Url', WPDM_ELEMENTOR)),
    50                 'description' => 'optional, add the logo or any image URL you want to show on top of the login form'
     58                'placeholder' => __('Logo URL', WPDM_ELEMENTOR),
     59                'description' => __('Image URL to show on top of the dashboard', WPDM_ELEMENTOR)
    5160            ]
    5261        );
    5362
    54         //recommended   value should be a category slug if you want to recommend specific category items, if you want to show recent items, use recommend="recent", skip the parameter recommended if you want to hide recommended items on the dashboard.
    5563        $this->add_control(
    5664            'recommended',
    5765            [
    58                 'label' => esc_attr(__('Recommended', WPDM_ELEMENTOR)),
     66                'label' => __('Recommended', WPDM_ELEMENTOR),
    5967                'type' => \Elementor\Controls_Manager::TEXT,
    6068                'input_type' => 'text',
    6169                'default' => 'recent',
    62                 'placeholder' => esc_attr(__('Recommended', WPDM_ELEMENTOR)),
    63                 'description' => 'value should be a category slug if you want to recommend specific category items, if you want to show recent items, use recommend="recent", skip the parameter recommended if you want to hide recommended items on the dashboard'
     70                'placeholder' => __('Category slug or "recent"', WPDM_ELEMENTOR),
     71                'description' => __('Use category slug or "recent" for latest items', WPDM_ELEMENTOR)
    6472            ]
    6573        );
    6674
    67         //fav   fav=1 if you want to show users favorite section and skip the fav parameter if you want to hide the section
    6875        $this->add_control(
    6976            'fav',
    7077            [
    71                 'label' => esc_attr(__('Show Favorite Section', WPDM_ELEMENTOR)),
     78                'label' => __('Show Favorites Section', WPDM_ELEMENTOR),
    7279                'type' => \Elementor\Controls_Manager::CHOOSE,
    7380                'options' => [
    74                     '0' => ['title' => 'No', 'icon' => 'fa fa-times'],
    75                     '1' => ['title' => 'Yes', 'icon' => 'fa fa-check']
     81                    '0' => ['title' => __('No', WPDM_ELEMENTOR), 'icon' => 'eicon-close'],
     82                    '1' => ['title' => __('Yes', WPDM_ELEMENTOR), 'icon' => 'eicon-check']
    7683                ],
    7784                'default' => '1'
     
    7986        );
    8087
    81         //signup    use signup=1 if you want to show login + signup form when a user is not logged in, signup=0 or skip the parameter if you only want to show the login form.
    8288        $this->add_control(
    8389            'signup',
    8490            [
    85                 'label' => esc_attr(__('show login + signup', WPDM_ELEMENTOR)),
     91                'label' => __('Show Login + Signup', WPDM_ELEMENTOR),
    8692                'type' => \Elementor\Controls_Manager::CHOOSE,
    8793                'options' => [
    88                     '0' => ['title' => 'No', 'icon' => 'fa fa-times'],
    89                     '1' => ['title' => 'Yes', 'icon' => 'fa fa-check']
     94                    '0' => ['title' => __('No', WPDM_ELEMENTOR), 'icon' => 'eicon-close'],
     95                    '1' => ['title' => __('Yes', WPDM_ELEMENTOR), 'icon' => 'eicon-check']
    9096                ],
    91                 'default' => '1'
     97                'default' => '1',
     98                'description' => __('Show signup form when user is not logged in', WPDM_ELEMENTOR)
    9299            ]
    93100        );
    94101
    95         //flaturl   Optional parameter, default value 0, use flaturl=1 for flat url
    96102        $this->add_control(
    97103            'flaturl',
    98104            [
    99                 'label' => esc_attr(__('Flat Url', WPDM_ELEMENTOR)),
     105                'label' => __('Flat URL', WPDM_ELEMENTOR),
    100106                'type' => \Elementor\Controls_Manager::CHOOSE,
    101107                'options' => [
    102                     '0' => ['title' => 'No', 'icon' => 'fa fa-times'],
    103                     '1' => ['title' => 'Yes', 'icon' => 'fa fa-check']
     108                    '0' => ['title' => __('No', WPDM_ELEMENTOR), 'icon' => 'eicon-close'],
     109                    '1' => ['title' => __('Yes', WPDM_ELEMENTOR), 'icon' => 'eicon-check']
    104110                ],
    105111                'default' => '0'
     
    107113        );
    108114
    109 
    110115        $this->end_controls_section();
    111116    }
    112117
    113 
    114 
    115118    protected function render()
    116119    {
     120        $settings = $this->getCleanSettings(self::SETTINGS_KEYS);
     121        $settings = $this->sanitizeSettings($settings, self::SANITIZERS);
    117122
    118         $settings = $this->get_settings_for_display();
    119         $cus_settings = array_slice($settings, 0, 3);
    120 
    121         echo '<div class="oembed-elementor-widget">';
    122        // p($cus_settings);
    123         echo WPDM()->user->dashboard->dashboard($cus_settings);
    124 
    125         echo '</div>';
     123        echo $this->wrapOutput(
     124            WPDM()->user->dashboard->dashboard($settings),
     125            'user-dashboard-widget'
     126        );
    126127    }
    127128}
  • wpdm-elementor/trunk/src/widgets/UserProfileWidget.php

    r2844275 r3427512  
    33namespace WPDM\Elementor\Widgets;
    44
    5 use Elementor\Widget_Base;
     5/**
     6 * User Profile Widget.
     7 * Displays user profile.
     8 * Note: This widget is currently disabled in Main.php
     9 */
     10class UserProfileWidget extends BaseWidget
     11{
     12    /**
     13     * Expected settings keys for this widget.
     14     */
     15    private const SETTINGS_KEYS = ['template'];
    616
    7 class UserProfileWidget extends Widget_Base
    8 {
     17    /**
     18     * Settings sanitization rules.
     19     */
     20    private const SANITIZERS = [
     21        'template' => 'text',
     22    ];
    923
    1024    public function get_name()
     
    1529    public function get_title()
    1630    {
    17         return 'User Profile';
     31        return __('User Profile', WPDM_ELEMENTOR);
    1832    }
    1933
    2034    public function get_icon()
    2135    {
    22         return 'fa fa-user-o';
    23     }
    24 
    25     public function get_categories()
    26     {
    27         return ['wpdm'];
     36        return 'eicon-user-circle-o';
    2837    }
    2938
    3039    protected function register_controls()
    3140    {
    32 
    3341        $this->start_controls_section(
    3442            'content_section',
    3543            [
    36                 'label' => esc_attr(__('Parameters', WPDM_ELEMENTOR)),
     44                'label' => __('Parameters', WPDM_ELEMENTOR),
    3745                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
    3846            ]
    3947        );
    4048
    41         //link template: select
    4249        $this->add_control(
    4350            'template',
    4451            [
    45                 'label' => esc_attr(__('Link Template', WPDM_ELEMENTOR)),
     52                'label' => __('Link Template', WPDM_ELEMENTOR),
    4653                'type' => \Elementor\Controls_Manager::SELECT2,
    4754                'options' => get_wpdm_link_templates(),
    48                 'default' => 'link-default-default'
     55                'default' => 'link-template-default'
    4956            ]
    5057        );
    51 
    5258
    5359        $this->end_controls_section();
    5460    }
    5561
    56 
    57 
    5862    protected function render()
    5963    {
     64        $settings = $this->getCleanSettings(self::SETTINGS_KEYS);
     65        $settings = $this->sanitizeSettings($settings, self::SANITIZERS);
    6066
    61         $settings = $this->get_settings_for_display();
    62         $cus_settings = array_slice($settings, 0, 5);
    63 
    64         echo '<div class="oembed-elementor-widget">';
    65         // p($cus_settings);
    66         echo WPDM()->user->profile->profile($cus_settings);
    67 
    68         echo '</div>';
     67        echo $this->wrapOutput(
     68            WPDM()->user->profile->profile($settings),
     69            'user-profile-widget'
     70        );
    6971    }
    7072}
  • wpdm-elementor/trunk/wpdm-elementor.php

    r3259585 r3427512  
    44 * Plugin URI: https://www.wpdownloadmanager.com/download/wpdm-elementor/
    55 * Description: Download Manger modules for Elementor
    6  * Version: 1.3.0
     6 * Version: 2.0.0
    77 * Author: WordPress Download Manager
    88 * Text Domain: wpdm-elementor
     
    1212 */
    1313
    14 use WPDM\Elementor\Main;
     14if (!defined('ABSPATH')) {
     15    exit;
     16}
    1517
    16 define("__WPDM_ELEMENTOR__", true);
     18/**
     19 * Check for required dependencies
     20 */
     21function wpdm_elementor_check_dependencies() {
     22    $missing = [];
    1723
    18 require_once __DIR__.'/src/api/API.php';
    19 require_once __DIR__.'/src/Main.php';
     24    if (!did_action('elementor/loaded')) {
     25        $missing[] = 'Elementor';
     26    }
    2027
    21 Main::getInstance();
     28    if (!function_exists('WPDM')) {
     29        $missing[] = 'WordPress Download Manager';
     30    }
     31
     32    return $missing;
     33}
     34
     35/**
     36 * Display admin notice for missing dependencies
     37 */
     38function wpdm_elementor_missing_dependencies_notice() {
     39    $missing = wpdm_elementor_check_dependencies();
     40    if (empty($missing)) {
     41        return;
     42    }
     43
     44    $message = sprintf(
     45        '<strong>WPDM - Elementor</strong> requires %s to be installed and activated.',
     46        implode(' and ', $missing)
     47    );
     48
     49    printf('<div class="notice notice-error"><p>%s</p></div>', $message);
     50}
     51add_action('admin_notices', 'wpdm_elementor_missing_dependencies_notice');
     52
     53/**
     54 * Initialize plugin only if dependencies are met
     55 */
     56function wpdm_elementor_init() {
     57    $missing = wpdm_elementor_check_dependencies();
     58    if (!empty($missing)) {
     59        return;
     60    }
     61
     62    define("__WPDM_ELEMENTOR__", true);
     63
     64    // Load constants first
     65    require_once __DIR__.'/src/constants.php';
     66
     67    require_once __DIR__.'/src/api/API.php';
     68    require_once __DIR__.'/src/Main.php';
     69
     70    \WPDM\Elementor\Main::getInstance();
     71}
     72add_action('plugins_loaded', 'wpdm_elementor_init');
Note: See TracChangeset for help on using the changeset viewer.