PHP code example of upflex / mixup

1. Go to this page and download the library: Download upflex/mixup library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

upflex / mixup example snippets


>    
>
>    namespace BaseWp\Front;
>    
>    use UPFlex\MixUp\Core\Base;
>    
>    class Assets extends Base
>    {
>        public function __construct()
>        {
>            add_action('wp_enqueue_scripts', [self::class, 'styles']);
>            add_filter('meu_plugin_priority', [self::class, 'getPriority']);
>        }
> 
>        public static function getPriority() : int
>        {
>           return 10;
>        }
>        
>        public static function styles()
>        {
>            wp_enqueue_style('meu_plugin', 'style.css');
>        }
>    }
>    

>    
>
>    namespace BaseWp\Front;
>    
>    use UPFlex\MixUp\Core\Base;
>    use UPFlex\MixUp\Utils\Fields\Sanitize;
>    
>    class Contact extends Base
>    {
>        use Sanitize;
>    
>        public function __construct()
>        {
>            add_action('wp_ajax_meu_plugin_send_message', [self::class, 'send']);
>            add_action('wp_ajax_nopriv_meu_plugin_send_message', [self::class, 'send']);
>        }
>    
>        public function send() 
>        {
>            $fields = self::getFields('get'); # Recupera campos $_GET
>    
>            if(!empty($fields['my_email'])) {
>                return wp_send_json_success();
>            }
>    
>            return wp_send_json_error();
>        }
>        
>        # Método obrigatório    
>        protected static function setFields(): array
>        {
>            # Informa os campos e seus tipos
>            return [
>               'name',
>               'my_email' => 'email',
>            ];
>       }
>    }
>    

>    
>
>    namespace BaseWp\Admin;
>    
>    use UPFlex\MixUp\Core\Parent\PostType;
>    
>    class Events extends PostType
>    {
>        protected static string $name = 'events';
>    
>        public function __construct()
>        {
>            self::setIcon('dashicons-groups');
>            self::setPlural('Eventos');
>            self::setSingular('Evento');
>            self::setSlug('eventos');
>            self::setArgs([]); # Opcional
>    
>            add_action('init', [self::class, 'register']);
>        }
>    }
>    

>    
>
>    namespace BaseWp\Admin;
>    
>    use UPFlex\MixUp\Core\Parent\Shortcode;
>    
>    class ListEvents extends Shortcode
>    {    
>        public function __construct()
>        {
>            self::setTag('meu_plugin_list_events');
>            self::setCallback([self::class, 'render']);
>        }
>        
>        public static function render()
>        {
>        }
>    }
>    

>    
>
>    namespace BaseWp\Admin;
>    
>    use UPFlex\MixUp\Core\Parent\Taxonomy;
>    
>    class EventTypes extends Taxonomy
>    {
>        protected static string $name = 'event_types';
>    
>        public function __construct()
>        {
>            self::setPlural('Tipos');
>            self::setSingular('Tipo');
>            self::setSlug('tipos-de-evento');
>            self::setSlug('eventos');
>            self::setPostTypes([Events::getName()]); # Pode ser uma string
>    
>            add_action('init', [self::class, 'register']);
>        }
>    }
>    

>    
>
>    namespace BaseWp\Front;
>    
>    use UPFlex\MixUp\Core\Base;
>    use UPFlex\MixUp\Utils\Fields\Validate;
>    
>    class Contact extends Base
>    {
>        use Validate;
>    
>        public function __construct()
>        {
>            add_action('wp_ajax_meu_plugin_send_message', [self::class, 'send']);
>            add_action('wp_ajax_nopriv_meu_plugin_send_message', [self::class, 'send']);
>        }
>    
>        public function send()
>        {
>            $fields = self::getFieldsValidated('get'); # Recupera campos $_GET
>            $validate = $fields['success'] ?? true;
>    
>            if($validate) {
>                return wp_send_json_success();
>            }
>    
>            return wp_send_json_error();
>        }
>        
>        # Método obrigatório
>        protected static function setFields(): array
>        {
>            # Informa os campos e validações necessárias
>            return [
>               'name' => '