Plugin Directory

Changeset 3297657


Ignore:
Timestamp:
05/20/2025 09:31:42 PM (11 months ago)
Author:
vaksin
Message:

0.0.2

  • Breakdance integration
  • WPML integration
Location:
radas
Files:
170 added
7 edited

Legend:

Unmodified
Added
Removed
  • radas/trunk/admin/option-page.php

    r3156010 r3297657  
    44use Radas\Admin\Assets\Admin_Scripts_Rds;
    55use Radas\Lib\Assets\Admin_Styles_Lib;
     6use Radas\Lib\BD\Dynamic_Data\Opt_Image_Field;
     7use Radas\Lib\BD\Dynamic_Data\Opt_String_Field;
     8use Radas\Lib\BD\Dynamic_Data\Opt_URL_Field;
    69use Radas\Lib\Classes\Abstracts\Element;
    710use Radas\Lib\Classes\Abstracts\Field;
     
    2124    protected $option_values;
    2225    protected $fields;
     26    protected $option_name;
     27    protected $is_wpml_active;
     28    protected $is_breakdance_active;
    2329
    2430    public function __construct($post_id){
    2531        $this->page = json_decode(get_post_meta($post_id, 'op_json', true), true);
     32
     33        $this->option_name = $this->page['slug'];
     34        $this->is_wpml_active = Util::is_wpml_active();
     35        $this->is_breakdance_active = Util::is_breakdance_active();
     36
    2637        if($this->page){
    2738            $this->elements = Element_Factory::getInstance()($this->page['fields'][0]);
     
    7384        add_action('rest_api_init', [$this, 'register_rest']);
    7485       
    75         add_shortcode( $this->page['slug'], [$this, 'create_shortcode'] );       
     86        add_shortcode( $this->page['slug'], [$this, 'create_shortcode'] );
     87
     88        if($this->is_breakdance_active) {
     89            foreach($this->fields as $field){
     90                $this->create_bd_dynamic_data($field);
     91            }
     92        }
     93
     94        if($this->is_wpml_active) {
     95            $this->wpml_setup_string();
     96        }
    7697    }
    7798
     
    154175        $sanitized_values = $this->sanitize_values($params);
    155176     
    156         if(!get_option($this->page['slug'])){
    157             $result = add_option($this->page['slug'], $sanitized_values);
     177        if(!get_option($this->option_name )){
     178            $result = add_option($this->option_name , $sanitized_values);
    158179        } else {
    159             $result = update_option($this->page['slug'], $sanitized_values);
    160         }
    161 
    162         // if(!$result) {
    163         //     return Util::rest_response(
    164         //         code: 'failed',
    165         //         message: "Something wrong, please check your params",
    166         //         data: [
    167         //             'params' => $params
    168         //         ] ,
    169         //         status: 500
    170         //     ); 
    171         // }
     180            $result = update_option($this->option_name , $sanitized_values);
     181        }
     182
     183        if($this->is_wpml_active) {
     184            $this->register_wpml_string();
     185        }
    172186
    173187        return Util::rest_response(
    174188            code: 'success',
    175189            message: __('Your data has been successfully updated', 'radas'),
    176             data: get_option($this->page['slug'], null),
     190            data: get_option($this->option_name , null),
    177191            status: 200
    178192        );               
     
    188202        }
    189203
    190         /** get options value ana insert to fields */
     204        return $this->get_value($atts['field'], $atts);
     205
     206        /** get options value and insert to fields */
    191207        $this->get_option_values();
    192208
     
    300316    protected function get_option_values(){
    301317        if (!$this->option_values) {
    302             $option = get_option($this->page['slug'], null);
     318            $option = get_option($this->option_name , null);
    303319            if(is_array($option)){
    304320                $this->option_values = $this->sanitize_values($option);
     
    307323        return $this->option_values;
    308324    }
     325
     326    protected function create_bd_dynamic_data(Field $field){
     327        $field_data = [
     328            'type' => $field->type,
     329            'label' => $field->label,
     330            'slug' => $this->page['slug'] . '-' . $field->id,
     331            'category' => 'Radas',
     332            'sub_category' => $this->page['title'] . ' Options',
     333            'shortcode' => $this->page['slug'],
     334            'field' => $field->id,
     335        ];
     336
     337        \Breakdance\DynamicData\registerField(new Opt_String_Field($field_data));
     338
     339        if($field->type == 'media'){
     340            $field_data['slug'] = $this->page['slug'] . '-' . $field->id . '-img';
     341            \Breakdance\DynamicData\registerField(new Opt_Image_Field($field_data));
     342        }
     343
     344        if(in_array($field->type, ['email', 'tel', 'media']) ){
     345            $field_data['slug'] = $this->page['slug'] . '-' . $field->id . '-url';
     346            \Breakdance\DynamicData\registerField(new Opt_URL_Field($field_data));           
     347        }       
     348    }
     349
     350    protected function wpml_setup_string(){       
     351        add_filter( 'wpml_active_string_package_kinds', function( $kinds ) {       
     352            $kinds[ $this->page['slug'] ] = [
     353                'title'  => $this->page['title'],
     354                'slug'   => $this->page['slug'],
     355                'plural' => $this->page['title'],
     356            ];           
     357            return $kinds;
     358        });       
     359    }
     360
     361    protected function register_wpml_string(){       
     362        /*
     363        checkbox
     364        checkboxes
     365        color
     366        date
     367        editor
     368        email
     369        file
     370        hidden
     371        media
     372        number
     373        password
     374        tel
     375        radio
     376        select
     377        text
     378        textarea
     379        url
     380        */
     381
     382        /** @var Field $field */
     383        foreach($this->fields as $field){
     384            if(!in_array($field->type, $this->get_wpml_non_translated_field_type())) {
     385                $type = 'LINE';
     386                if($field->type == 'editor'){
     387                    $type = 'VISUAL';
     388                }
     389
     390                if($field->type == 'textarea'){
     391                    $type = 'AREA';
     392                }
     393
     394                do_action( 'wpml_register_string', $field->get_sanitized_value(), $field->id, $this->get_wpml_package_kind(), $field->label, $type );
     395            }
     396        }   
     397    }
     398
     399    protected function get_wpml_package_kind(){
     400        return [
     401            'kind'      => $this->page['title'],
     402            'kind_slug' => $this->page['slug'],
     403            'name'      => $this->page['slug'],
     404            'title'     => $this->page['title'],
     405        ];
     406    }
     407
     408    protected function get_wpml_non_translated_field_type(){
     409        return ['date', 'email', 'media', 'password', 'tel', 'url'];
     410    }
     411
     412    public function get_value(string $field_name, array $args = []){
     413       
     414        if( !array_key_exists( $field_name, $this->fields ) ){
     415            return null;
     416        }
     417       
     418        $defaults = [
     419            /** General
     420             * value: url (email, tel, media), id (media), text (select, radio), human (date)
     421            */
     422            'format' => '',
     423
     424            /** Media */
     425            'size'  => 'thumbnail',
     426            'width' => '',
     427            'height' => '',
     428            'format' => '', 
     429        ];
     430
     431        $args = array_merge($defaults, $args);       
     432
     433        /** get options value ana insert to fields */
     434        $this->get_option_values();
     435
     436        /** @var Field $field */
     437        $field = $this->fields[$field_name];       
     438
     439        $value = $field->get_sanitized_value();
     440
     441        if( $this->is_wpml_active && !in_array( $field->type, $this->get_wpml_non_translated_field_type() ) ) {
     442            $value = apply_filters( 'wpml_translate_string', $value , $field->id, $this->get_wpml_package_kind() );   
     443        }       
     444
     445        if( array_key_exists('format', $args) && $args['format'] == 'raw' ){
     446            return $value ;
     447        }
     448
     449        // if($field->type == 'media' && $field->attributes['data-media-type'] == 'image'){
     450        if($field->type == 'media'){ // default attachment image thumbnail
     451            if($args['format'] == 'id') {
     452                return $value ;
     453            }
     454
     455            if($args['format'] == 'url') {
     456                return wp_get_attachment_url($value );
     457            }
     458
     459            $ar_size = [];
     460            if($args['width']) {
     461                array_push($ar_size, $args['width']);
     462                if($args['height']) {
     463                    array_push($ar_size, $args['height']);                   
     464                }   
     465                return wp_get_attachment_image($value , $ar_size);
     466            }
     467
     468            if($args['size']) {
     469                return wp_get_attachment_image($value , $args['size']);
     470            }
     471        }
     472
     473        if($field->type == 'email'){
     474            if($args['format'] == 'url') {
     475                return esc_url('mailto:' . $value );
     476            }
     477        }
     478
     479        if($field->type == 'tel'){
     480            if($args['format'] == 'url') {
     481                return esc_url('tel:' . $value );
     482            }
     483        }
     484
     485        if($field->type == 'date'){           
     486            $date = date_create($value );
     487
     488            if($args['format'] == '') {
     489                return date_format($date, get_option( 'date_format' ));               
     490            }
     491
     492            if($args['format'] == 'human') {
     493                return human_time_diff(strtotime(date_format($date, 'Y-m-d h:i:s')));
     494            }
     495
     496            return date_format($date, $args['format']);               
     497        }
     498
     499        if($field->type == 'select' || $field->type == 'radio'){
     500            if($args['format'] == '') {
     501                return $value ;
     502            }
     503
     504            if($args['format'] == 'text') {
     505                return esc_html($field->options[$value ]);
     506            }           
     507        }
     508               
     509        return $value ;
     510    }
    309511}
  • radas/trunk/lib/elements/fields/color-field.php

    r3156010 r3297657  
    2323     */
    2424    public function __construct($id) {
    25         $this->type = 'checkbox';
     25        $this->type = 'color';
    2626        parent::__construct($id);
    2727    }
  • radas/trunk/lib/elements/fields/media-field.php

    r3156010 r3297657  
    6767     */
    6868    public function render_input() {
    69         add_filter('upload_mimes', function ($mime){
    70             $mime_types['svg'] = 'image/svg+xml'; //Adding svg extension
    71             // $mime_types['psd'] = 'image/vnd.adobe.photoshop'; //Adding photoshop files
    72             return $mime_types;
    73         }, 1, 1);       
     69        // add_filter('upload_mimes', function ($mime){
     70        //     $mime_types['svg'] = 'image/svg+xml'; //Adding svg extension
     71        //     // $mime_types['psd'] = 'image/vnd.adobe.photoshop'; //Adding photoshop files
     72        //     return $mime_types;
     73        // }, 1, 1);       
    7474        wp_enqueue_media();
    7575        Admin_Scripts_Lib::enqueue('rds-media-box');
  • radas/trunk/lib/elements/fields/password-field.php

    r3156010 r3297657  
    2424     */
    2525    public function __construct(string $id) {
    26         $this->type = 'text';
     26        $this->type = 'password';
    2727        parent::__construct($id);
    2828    }
  • radas/trunk/lib/helper/util.php

    r3156010 r3297657  
    172172        return new \WP_REST_Response($response, $status);
    173173    }
     174
     175    public static function is_breakdance_active() {
     176        if (!function_exists('is_plugin_active')) {
     177            require_once ABSPATH . 'wp-admin/includes/plugin.php';
     178        }
     179
     180        return is_plugin_active('breakdance/plugin.php');
     181    }
     182   
     183    public static function is_wpml_active() {
     184        if (!function_exists('is_plugin_active')) {           
     185            require_once ABSPATH . 'wp-admin/includes/plugin.php';
     186        }
     187
     188        return is_plugin_active('sitepress-multilingual-cms/sitepress.php');
     189    }
     190
     191    public static function get_lang() {
     192        return apply_filters( 'wpml_current_language', null );
     193    }   
    174194}
  • radas/trunk/radas.php

    r3156917 r3297657  
    44 * Plugin URI:        https://wpradas.com
    55 * Description:       The Lightweight WordPress Plugin for Effortless Options Page Creation
    6  * Version:           0.0.2
     6 * Version:           0.2.0
    77 * Requires at least: 6.5
    88 * Requires PHP:      8.0
  • radas/trunk/readme.txt

    r3159519 r3297657  
    22Contributors: vaksin
    33Donate link: https://paypal.me/akah
    4 Tags: options page, admin page
     4Tags: Breakdance, WPML, options page, admin page
    55Requires at least: 6.5
    6 Tested up to: 6.6.2
    7 Stable tag: 0.0.2
     6Tested up to: 6.8.1
     7Stable tag: 0.2.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1414
    1515Create form to save data in the wp_options table, This allows the data to be displayed on any page throughout the website using shortcode, making it a great option for header and footer data.
     16
     17Integrated with WPML and Breakdance seamlessly
    1618
    1719= Lightweight and Fast =
     
    6567= 0.0.2 =
    6668
     69* Breakdance integration
     70* WPML integration
     71
     72= 0.0.2 =
     73
    6774* Fix popup code
    6875* Remove header buttons in mobile
Note: See TracChangeset for help on using the changeset viewer.