wp decision matrix v002

Home » Snippets » wp decision matrix v002
0

Created with:

Visibility: 

public

Creator: bjtan89@gmail.com

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project
					<?php
/**
 * Plugin Name: Weighted Decision Matrix
 * Plugin URI: https://example.com/
 * Description: A WordPress plugin that calculates a weighted decision matrix.
 * Version: 1.0.0
 * Author: Your Name
 * Author URI: https://example.com/
 * License: GPL2
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: wpturbo
 */

defined( 'ABSPATH' ) || exit;

// Enqueue plugin stylesheets and scripts
function wpturbo_enqueue_scripts() {
    wp_enqueue_style( 'wpturbo-style', plugin_dir_url( __FILE__ ) . 'css/style.css', array(), '1.0.0' );
    wp_enqueue_script( 'wpturbo-script', plugin_dir_url( __FILE__ ) . 'js/script.js', array( 'jquery' ), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'wpturbo_enqueue_scripts' );

// Shortcode to display the weighted decision matrix form
function wpturbo_decision_matrix_shortcode() {
    // Get the number of factors from the user
    $number_of_factors = get_option( 'wpturbo_number_of_factors', 3 );

    ob_start();
    ?>
    <form id="wpturbo-decision-matrix-form" method="post">
        <label for="wpturbo-number-of-factors">Number of Factors:</label>
        <select id="wpturbo-number-of-factors" name="wpturbo_number_of_factors">
            <?php for ( $i = 1; $i <= 10; $i++ ) : ?>
                <option value="<?php echo $i; ?>" <?php selected( $number_of_factors, $i ); ?>><?php echo $i; ?></option>
            <?php endfor; ?>
        </select>
        <br>

        <?php for ( $i = 1; $i <= $number_of_factors; $i++ ) : ?>
            <label for="wpturbo-factor-<?php echo $i; ?>">Factor <?php echo $i; ?> Weight:</label>
            <input type="number" id="wpturbo-factor-<?php echo $i; ?>" name="wpturbo_factor_<?php echo $i; ?>_weight" min="1" max="100" value="<?php echo get_option( 'wpturbo_factor_' . $i . '_weight', 50 ); ?>">
            <br>
        <?php endfor; ?>

        <input type="submit" name="submit" value="Calculate">
    </form>
    <?php
    return ob_get_clean();
}
add_shortcode( 'wpturbo_decision_matrix', 'wpturbo_decision_matrix_shortcode' );

// Process the weighted decision matrix form submission
function wpturbo_process_decision_matrix() {
    if ( isset( $_POST['submit'] ) ) {
        // Update the number of factors option
        if ( isset( $_POST['wpturbo_number_of_factors'] ) ) {
            $number_of_factors = absint( $_POST['wpturbo_number_of_factors'] );
            update_option( 'wpturbo_number_of_factors', $number_of_factors );
        }

        // Update the factor weights options
        for ( $i = 1; $i <= $number_of_factors; $i++ ) {
            if ( isset( $_POST['wpturbo_factor_' . $i . '_weight'] ) ) {
                $factor_weight = absint( $_POST['wpturbo_factor_' . $i . '_weight'] );
                update_option( 'wpturbo_factor_' . $i . '_weight', $factor_weight );
            }
        }

        // Process form data and calculate weighted decision matrix
        // Store the result or display it as needed
    }
}
add_action( 'init', 'wpturbo_process_decision_matrix' );

// Frontend output for the weighted decision matrix
function wpturbo_weighted_decision_matrix_output() {
    // Get the number of factors
    $number_of_factors = get_option( 'wpturbo_number_of_factors', 3 );

    ob_start();
    ?>
    <form id="wpturbo-weighted-decision-matrix-form" method="post">
        <?php for ( $i = 1; $i <= $number_of_factors; $i++ ) : ?>
            <label for="wpturbo-factor-<?php echo $i; ?>-weight">Factor <?php echo $i; ?> Weight:</label>
            <input type="range" id="wpturbo-factor-<?php echo $i; ?>-weight" name="wpturbo_factor_<?php echo $i; ?>_weight" min="1" max="100" value="<?php echo get_option( 'wpturbo_factor_' . $i . '_weight', 50 ); ?>">
            <br>
        <?php endfor; ?>

        <input type="submit" name="submit" value="Submit">
    </form>
    <?php
    return ob_get_clean();
}

// Shortcode to display the weighted decision matrix output
function wpturbo_weighted_decision_matrix_output_shortcode() {
    return wpturbo_weighted_decision_matrix_output();
}
add_shortcode( 'wpturbo_weighted_decision_matrix_output', 'wpturbo_weighted_decision_matrix_output_shortcode' );
				

Register an account to save your snippets or go Pro to get more features.