Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • sanguine1

    (@sanguine1)

    what am i doing wrong that any code ive written, when i paste it in here it ends up all jumbled up?

    sanguine1

    (@sanguine1)

    i was able to make the lists work, but without using the settings API submit button, here is my solution if it will help in anyone in the future. These files went into “mysite/wp-content/plugins/myplugin”

    plugin.php

    <?php
    /**
     * Plugin Name: Test Plugin
     * Version: 1.0
     */
    include 'my-ajax.php';
    class TestPlugin{
      
    	private static $instance;
    
        
        static function GetInstance() {         
            if (!isset(self::$instance)) {
                self::$instance = new self();
            }
            return self::$instance;
        }
    
        public function Initialize_Plugin() {  	
        	add_action('admin_enqueue_scripts',array($this, 'admin_scripts'));
        	add_action('admin_menu', array($this,'create_menu' ));
        }
    
        function admin_scripts() {
        	if (is_admin()) {
    	    wp_register_script('admin-js', plugin_dir_url(__FILE__) . '/admin.js', array('jquery'), '', true);
    	    wp_enqueue_script('admin-js');
    	    wp_enqueue_script('jquery-ui-core');
    	    wp_enqueue_script( 'jquery-ui-sortable' );        	
                wp_register_style( 'test_jquery', '//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css', false, '1.0.0' );
         	    wp_enqueue_style( 'test_jquery' );
        	}
        }
    
    	function create_menu() {
    		add_menu_page(
            	'TEST Options',
                    'TEST Options',
                    'administrator',
                    'test_options',
                    array($this, 'plugin_options_page'),
                    null,
            	99
            	);    	
    		//call register settings function
    		add_action( 'admin_init',array($this, 'plugin_options') );
    	}
    	function plugin_options() {
    	    $style = '
    	        <style>
    		#sortable3, #sortable4 {
    		    border: 1px solid #eee;
    		    width: 142px;
        		    min-height: 40px;
        		    list-style-type: none;
        		    margin: 0;
        		    padding: 5px 0 0 0;
        		    float: left;
        		    margin-right: 10px;
                        background: #000000;
      		}
      		#sortable3 li, #sortable4 li {
      		    margin: 0 5px 5px 5px;
      		    padding: 5px;
      		    font-size: 1.2em;
      		    width: 120px;
      		}
      		</style>';
        	echo $style;
    	}
    
        function plugin_options_page() {
        	register_setting( 'settings-group', 'filter_fields_order' );
        	register_setting( 'settings-group', 'filter_fields_order2' );
        	//delete_option('filter_fields_order');
        	//delete_option('filter_fields_order2');
        	$s3_array = get_option('filter_fields_order');
        	$s4_array = get_option('filter_fields_order2');
            	
        	?> 
    	<ul id="sortable3" class="filter-fields-list">
    	<?php    		
        	if(!$s3_array){
                	$s3_array = array(
                                    array (
        				    'id' => "1",
                                        'name' => "1",
                                    ),
                    	        array (
        				    'id' => "2",
        				    'name' => "2",
                                     ),
                    	        array (
        				    'id' => "3",
                                        'name' => "3",
                                    ),
                    	        array (
        				    'id' => "4",
        				    'name' => "4",
                                    ),
                    	        array (
        				    'id' => "5",
                                        'name' => "5",
                                    ),
                    	        array (
        				    'id' => "6",
        				    'name' => "6",
                                    ),                
    			    );
                
      	    foreach ( $s3_array as $sat ) {
      	        echo '<li id="'. $sat['id'] .'" class="ui-state-default">'. $sat['name'] .'</li>';
      	    }                      
            } else {
                if($s3_array[0] == null) {
                    
                } else {
                    $s3_array = get_option('filter_fields_order');
           		foreach ($s3_array as $sat) {
                        echo '<li id="'. $sat['id'] .'" class="ui-state-default">'. $sat['name'] .'</li>';
                    }
                }
            }
    	?>
    	</ul>
        	<ul id="sortable4" class="filter-fields-list">
            <?php
        	if ($s4_array[0] == null){
            	
            } else {
                foreach ($s4_array as $sa) {
                    echo '<li id="'. $sa['id'] .'" class="ui-state-default">'. $sa['name'] .'</li>';
                }
            }
            ?>
    	</ul>
    	<?php
    	}
    } 
    $TestPlugin = TestPlugin::GetInstance();
    $TestPlugin->Initialize_Plugin();

    admin.js

    jQuery(document).ready(function($){
    	$('#sortable4, #sortable3').sortable({
            connectWith: ".filter-fields-list",
        	update: function (event, ui) {
                $('#loading-animation').show();
         	 	var list = this.id;
                var order = $(this).sortable('toArray').toString();
                args = {
                    url: ajaxurl,
                    type: 'POST',
                    async: true,
                    cache: false,
                    dataType: 'json',
                    data:{
                        action: 'item_sort', 
                        order:  order, 
                        list: list
                    },
                    success: function(response) {
                        //alert(list+order);
                        return; 
                    },
                    error: function(xhr,textStatus,e) {  
                        alert(e);
                        return; 
                    }
                };
                $.ajax(args);
        	}
    	}).disableSelection();
    });

    my-ajax.php

    <?php
    function my_save_item_order() {	
        $order = explode(',', $_POST['order']);
    	$list = $_POST['list'];
        if($list == "sortable3") {
        	update_option('filter_fields_order', $order);
        }    
        if($list == "sortable4") {
        	update_option('filter_fields_order2', $order);
        } 
        wp_die();
    }
    add_action('wp_ajax_item_sort', 'my_save_item_order');

    Its probably not the best way to do any of it(not that i would know if it was or wasnt) but i hope it helps someone.

    • This reply was modified 1 month ago by sanguine1.
    • This reply was modified 1 month ago by sanguine1.
    add_action( 'the_content', 'list_tags_bygroup' );
    
    function list_tags_bygroup ( $content ) {
    	if ( is_page('sample-page')) {
    		$arrays = tag_groups_cloud( array( 'orderby' => 'count', 'order' => 'DESC' ) , true  );
    		$html = '<ul>';
        	for ($i = 0; $i < sizeof($arrays); $i++) {
        		$html .= "<li>{$arrays->name}</li>";
            }   
            $html .= '</ul>';
    		echo $html;
        }
    }

    that was as far as i got, i think i almost made it myself. Thanks again

    well it works i thank you, the output was exactly what i wanted. thank you so very much. i literally spent hours lol.

Viewing 4 replies - 1 through 4 (of 4 total)