• Hello everyone,

    I am developing a WP plugin that has an option panel that requires pagination. What this panel is doing is opening a directory and finding it’s contents then showing the first 15 results in a paginated menu. My problem is that when a user clicks on the next page link or any page number my code appends an “?ID=” to the end of the url and the user is subsequently brought to a “You do not have sufficient permissions to access this page.” rather than the page refreshing and the icons set being displayed.

    Now, I know this is a built-in WordPress security function but is there any workaround to this? How should I handle pagination without appending the URL with the ID? Any ideas are greatly appreciated.

    Here’s my code:

    <?php
    	// Start of icons
    
    	if( $_GET['id'] != '' )
    		{
    				$ID = $_GET['id'];
    		}
    		else
    		{
    				$ID = 0;
    		}
    
    	$directory = $wpicons_path."/icons/";
    
    	$icon_dir=opendir($directory);
    
    	$idCounter = 0;
    
    	 while (($filename = readdir($icon_dir))) {
                    // Place all of the pictures in an array.
                    $PICTURES[$idCounter] = $filename;
                    $idCounter++;
    
        }
        closedir($icon_dir);
    
    	$totalPictures = count($PICTURES);
    
    	  for( $i = 1; $i <= 15; $i++ )
            {
                    if( $PICTURES[$ID + $i] != '' )
                    {
    
                            echo '<img src="' .WP_PLUGIN_URL. '/wp-admin-icons/icons/' . $PICTURES[$ID + $i] . '" alt="..." />';
    
                            if( ($i % 5) == 0 )
                            {
                                    echo "<br />";
                            }
                    }
    
            }
    
    	if( ($ID - 15) >= 0 )
            {
                    echo '<a href="?id=' . ($ID - 15) . '">';
            }
            echo '<<</a> ';
            $pages = ceil($totalPictures / 15);
            for( $i = 0; $i < $pages; $i++ )
            {
                    if( ($i * 15) != $ID )
                    {
                            echo '<a href="https://localhost/testsite/wp-admin/options-general.php?page=wp-admin-icons.php/wp-admin-icons-init.php#id=' . ($i * 15) . '">';
                    }
                    echo ($i + 1). "</a> ";
            }
            if( ($ID + 15) < $totalPictures )
            {
                     echo '<a href="https://localhost/testsite/wp-admin/options-general.php?page=wp-admin-icons.php/wp-admin-icons-init.php#id=' . ($ID + 15) . '">';
            }
            echo '>></a>';
    
    ?>
  • The topic ‘My plugin's Opendir() pagination problem – Plz Help’ is closed to new replies.