Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter iso10

    (@iso10)

    Sample plugin “PRT” created to demonstrate

    https://www.filedropper.com/prt

    Thread Starter iso10

    (@iso10)

    Updated to v3.8.15 and still seeing the same issue.
    Create 4 tabs “Steps” and enter description and question text as Q1,Q2,Q3,Q4
    Publish
    Rearrange tab Steps to be Q1,Q3,Q2,Q4
    Update
    Page reloads and shows tab Steps in original order Q1,Q2,Q3,Q4

    
    <?php
    
    /**
     * Test Plugin for admin page framework
     *
     * @since             1.0.0
     * @package           prt
     * @wordpress-plugin
     * Plugin Name:       prt
     * Description:       Test Plugin for admin page framework
     * Version:           1.0.0 
     * Text Domain:       prt
     */
    
    // If this file is called directly, abort.
    if ( ! defined( 'WPINC' ) ) {
    	die;
    }
    
    define( 'PRT_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
    define( 'PRT_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
    
    // Load the Admin Page Framework if it exists
    if (file_exists(dirname(__FILE__) . '/admin-page-framework/admin-page-framework.php')) {
        include dirname( __FILE__ ) . '/admin-page-framework/admin-page-framework.php';
    }
    
    // PROFILE FIELDS - ADMIN PAGE
    class Prt extends prt_AdminPageFramework_PostType {
        
        public function setUp() {
     
            $this->setArguments(
                array( // argument - for the array structure, refer to https://codex.www.ads-software.com/Function_Reference/register_post_type#Arguments
                    'labels' => array(
                        'name'               => 'PRT',
                        'add_new_item'       => __( 'PRT Q Item', 'prt' ),
                        'plugin_action_link' => __( 'PRT Custom Q Type', 'prt' ), // (framework specific key). [3.0.6+]
                    ),
                    'supports'          => array( 'title', 'thumbnail' ), // e.g. array( 'title', 'editor', 'comments', 'thumbnail', 'excerpt' ),
                    'public'            => true,
                    //'show_ui'           => true,
                    //'show_in_menu'      => true,
                    'menu_icon'         => 'dashicons-welcome-learn-more'
                )    
            );    
            
            add_action( 'the_content', array( $this, 'content_output_handler' ) );
        }
        
        public function columns_prt_q( $aHeaderColumns ) {
            
            return array(
                    'cb'    => '<input type="checkbox" />', // Checkbox for bulk actions.
                    'title' => __( 'Title', 'prt' ), // Post title. Includes "edit", "quick edit", "trash" and "view" links. If $mode (set from $_REQUEST['mode']) is 'excerpt', a post excerpt is included between the title and links.
                    'icon'  => __( 'Icon', 'prt' ),
                    'passing_mark' => __( 'Passing Mark', 'prt' ),
                    'prerequisite' => __( 'Prerequisite', 'prt' ),
                    'id' => __( 'Quiz ID', 'prt' ),
                )     
                // + $aHeaderColumns // uncomment this to enable the default columns.
            ;
            
        }
         public function cell_prt_q_icon( $sCell, $iPostID ) { // cell_{post type}_{column key}
            $icon='<img src="" alt="N/A">';
            $postSettings=get_post_meta($iPostID,'quiz_settings',true);
            if($postSettings){
                if($postSettings['quiz_icon']){
                    $icon='<img src="'.$postSettings['quiz_icon'].'" alt="N/A">';
                }
            }
            return $sCell
                    . '<div class="perm_icon_sm">'
                        . $icon  
                    . '</div>'; 
        }
        public function cell_prt_q_passing_mark( $sCell, $iPostID ) { // cell_{post type}_{column key}
            $passMark='0%';
            $postSettings=get_post_meta($iPostID,'quiz_settings',true);
            if($postSettings){
                if($postSettings['quiz_pass']){
                    $passMark=$postSettings['quiz_pass'].'%';
                }
            }
            return $sCell
                    . '<div class="">'
                        . '<p>' . esc_attr( $passMark ) . '</p>'
                    . '</div>';   
        }
        public function cell_prt_q_prerequisite( $sCell, $iPostID ) { // cell_{post type}_{column key}
            $prerequisite='None';
            $postSettings=get_post_meta($iPostID,'quiz_settings',true);
            if($postSettings){
                if($postSettings['quiz_prerequisite']){
                    $prerequisitePost=get_post($postSettings['quiz_prerequisite']);
                    if($prerequisitePost){
                        $prerequisite=$prerequisitePost->post_title;
                    }
                }
            }
            return $sCell
                    . '<div class="">'
                        . '<p>' . esc_attr( $prerequisite ) . '</p>'
                    . '</div>'; 
        }
        public function cell_prt_q_id( $sCell, $iPostID ) { // cell_{post type}_{column key}
            return $sCell
                    . '<div class="pr_post_cell" >'
                        . '<p>id='.esc_attr($iPostID).'</p>'
                    . '</div>';
            
        }
        
        
        public function content_output_handler( $sContent ) { 
            if ( ! is_singular() ) {
                    return $sContent;
            }
            if ( ! is_main_query() ) {
                return $sContent;
            }
            global $post;
            if ( 'prt_q' !== $post->post_type ) {
                return $sContent;
            }
            echo "<div>HELLO BLUE WORLD!</div>";
            //$_sSelectedColor = get_post_meta( $GLOBALS['post']->ID, 'my_custom_color', true );
            $_sSelectedColor = 'blue';//$_sSelectedColor ? $_sSelectedColor : 'transparent';
            return "<h3>" . __( 'Selected Color', 'prt' ) . "</h3>"         
                . "<div style='width: 100%;'>123PERM456" 
                    . "<div style='margin:auto; width: 3em; height: 3em; background-color:$_sSelectedColor'></div>"
                . "</div>"
                ;
     
        }    
        
    }
    
    class PrtMetaBox extends prt_AdminPageFramework_MetaBox {
        
        /*
         * Use the setUp() method to define settings of this meta box.
         */
        public function setUp() {
            $this->addSettingSections(
                'perm_quiz',    // target page slug
                array(
                    'section_id'        => 'perm_quiz_tab_section',
                    'repeatable'        => true,
                    'sortable'          => true,
                    'section_tab_slug'  => 'perm_quiz_tab',
                    'title'             => 'Section',
                    //'description'       => 'This section is a repeatable tabbed section.',
                )
            );
            
            $this->addSettingFields(
                array(
                    'field_id'      => 'quiz_settings',
                    'type'          => 'inline_mixed',
                    'title'         => __( 'Settings', 'prt' ),
                    'content'       => array(
                        array(
                                    'field_id'   => 'quiz_pass',
                                    'type'       => 'text',
                                    'title'      => __('Passing Mark (%)', 'prt'),
                                    'attributes' => array('type'=>'number', 'min'=>'0', 'max'=>'100')
                        ),
                        array(
                                    'field_id'  => 'quiz_prerequisite',
                                    'type'      => 'select',
                                    'title'     => __('Quiz Prerequisite', 'prt'),
                                    'label'    => $this->getQuizPosts()
                        ),
                        array(
                                'field_id'   => 'quiz_icon',
                                'type'       => 'image',
                                'title'      => __('Icon', 'prt'),
                                'attributes' => array(
                                        'style' => 'max-width: 100px;max-height: 100px;float:right;margin-top:0',
                                    )
                        )
                    )
                ),
                array(
                        'field_id'   => 'quiz_desc',
                        'type'       => 'textarea',
                        'rich'       => true,
                        'title'      => __('Quiz Description', 'prt'),
                    ),
                array(
                        'field_id'   => 'quiz_status',
                        'type'       => 'hidden',
                        'default'    => 'U'
                    )
                
                
            );
            
            $this->addSettingFields(
                array('perm_quiz_tab_section'),
                array(
                                'field_id'   => 'exclude',
                                'type'       => 'checkbox',
                                'label'      => __(' Exclude from score calculation', 'prt'),
                                'default'    => false,
                                'attributes' => array(
                                        'style' => 'margin:0 10px 0px 0px;',
                                    )
                ),
                array(
                        'field_id'   => 'quiz_question',
                        'type'       => 'textarea',
                        'rich'       => true,
                        'title'      => __('Quiz Question', 'prt'),
                ),
                array(
                    'field_id'      => 'quiz_answer_group',
                    'type'          => 'inline_mixed',
                    'repeatable'    => true,
                    'title'         => __( 'Multiple Choice Answers', 'prt' ),
                    'content'       => array(
                        array(
                                'field_id'   => 'quiz_answer',
                                'type'       => 'text',
                                'title'      => __('Answer', 'prt'),
                        ),
                        array(
                                'field_id'   => 'correct_answer',
                                'type'       => 'checkbox',
                                'title'      => __('Correct', 'prt'),
                                'default'    => false,
                                'attributes' => array(
                                        'style' => 'margin:0 0 5px 20px;',
                                    )
                        )
                    )
                )
            );
            
        
        }
       
        function getQuizPosts(){
            $postslist = get_posts(array('post_type' => 'prt_q'));
            $retPostList=["-1"=>"None"];
            foreach ( $postslist as $post ){
                if( $post->ID != $_GET['post'] ){
                    $retPostList+=["$post->ID"=>$post->post_title];
                }
            }
            return $retPostList;
        }
        
    }
     
    
    new Prt('prt_q'); 
    new PrtMetaBox(
        null,   // meta box ID - can be null.
        __( 'PRT Quiz Meta Box', 'prt' ), // title
        array( 'prt_q' ),                 // post type slugs: post, page, etc.
        'normal',                                      // context
        'low'                                          // priority
    );
    
    
    • This reply was modified 7 years, 9 months ago by iso10.
Viewing 2 replies - 1 through 2 (of 2 total)