WordPress.org

Forums

YOP Poll
[resolved] Create new poll - Hide options (3 posts)

  1. wm
    Member
    Posted 1 year ago #

    I have a member site with an admin that have set the standard option. All members can create new polls when ever they like.

    But I want to hide some options on the "Add New Yop Poll" page. I see the options in "admin.php". But I can not just remove them since the page function requires the information to create a new poll.

    Example:
    - I want all members to be able to edit "Results Display:" options.
    - But I want to hide the option below "Poll Answer Result Label:" (And only use the defalt I have set in options with the admin)

    The code is:

    <tr>
    <th>
    <?php _e( 'Poll Answer Result Label', 'yop_poll' ); ?>:
    </th>
    <td><input id="yop-poll-answer-result-label" type="text"
    name="yop_poll_options[answer_result_label]"
    value="<?php echo esc_html( stripslashes( $default_options['answer_result_label'] ) ); ?>"/>
    <small><i><?php _e( 'Use %POLL-ANSWER-RESULT-PERCENTAGES% for showing answer percentages and  %POLL-ANSWER-RESULT-VOTES% for showing answer number of votes', 'yop_poll' ); ?></i></small>
    </td>
    </tr>

    The code starts with <tr> and ends with </tr>. Is there a user setting to hide this part or can I use some PhP hide code on this part? Hide but still set the default value hidden non visible on this page.

    https://wordpress.org/plugins/yop-poll/

  2. YOP
    Member
    Plugin Author

    Posted 1 year ago #

    Hi wm,

    Edit inc/admin.php and in view_add_edit_new_poll() function add

    $poll_answer_result_label = isset( $default_options['answer_result_label']) ? $default_options['answer_result_label'] : "";

    before

    if ( 'edit' == $action ){

    Also, after the if( 'edit' == $action ){ section add

    $default_options['answer_result_label'] = $poll_answer_result_label;

    so in the end you'll have

    $default_options = get_option( 'yop_poll_options', array() );
                $poll_answer_result_label = isset( $default_options['answer_result_label']) ? $default_options['answer_result_label'] : "";
       if ( 'edit' == $action ){
        $poll_id     = ( isset ( $_GET ['id'] ) ? intval( $_GET ['id'] ) : 0 );
        $poll_author = Yop_Poll_Model::get_poll_field_from_database_by_id( 'poll_author', $poll_id );
        if ( ( !$this->current_user_can( 'edit_own_polls' ) || $poll_author != $current_user->ID ) && ( !$this->current_user_can( 'edit_polls' ) ) )
         wp_die( __( 'You are not allowed to edit this item.', 'yop_poll' ) );
        $yop_poll_model       = new Yop_Poll_Model ( $poll_id );
        $answers              = Yop_Poll_Model::get_poll_answers( $poll_id );
        $other_answer         = Yop_Poll_Model::get_poll_answers( $poll_id, array( 'other' ) );
        $custom_fields        = Yop_Poll_Model::get_poll_customfields( $poll_id );
        $page_name            = __( 'Edit Poll', 'yop_poll' );
        $action_type          = 'edit';
        $poll_default_options = get_yop_poll_meta( $poll_id, 'options', true );
        foreach ( $default_options as $option_name => $option_value ) {
         if ( isset ( $poll_default_options [$option_name] ) ){
          $default_options [$option_name] = $poll_default_options [$option_name];
         }
        }
       }
                $default_options['answer_result_label'] = $poll_answer_result_label;

    In the code you pasted, set the <tr> tag as <tr style='display: none'>
    This way it will not be displayed and each time you save the poll it will have the current value set in the general options.

    Regards,

    YOP Team

  3. wm
    Member
    Posted 1 year ago #

    Thanks alot for a fast and easy to understand instructon. This code solved my issue exactly as I wanted.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic