Skip to main content
  1. All Posts/

ManageWP Code Snippets

Snippets Open Source PHP WordPress

ManageWP Code Snippets

ManageWP code snippets collection for WordPress.

How To Use

Just copy and paste the available code snippets below and load it to your ManageWP code snippets editor.

Code Snippets

Here’s the collections of code snippets.

Info & Debugging

  • List Plugins – This will list all of the available plugin in the WordPress plugin directory. Useful to check the installed plugins in your installation.

    <?php
    

    // Directory to scan $files = scandir(“wp-content/plugins”);

    // Return the result of the scan foreach($files as $file) { echo $file.“n”; }

  • Test Database Connection – This will return a database connection status. This is useful to when you want to make sure your database credentials are working correctly or not.

    <?php
    

    // Test Database Connection $servername = “localhost”; $username = “username-here”; $password = “password-here”;

    // Create connection $conn = new mysqli($servername, $username, $password);

    // Check connection if ($conn->connect_error) { die(“Connection failed: " . $conn->connect_error); } echo “Connected successfully”;

  • View File Contents – Able to view file contents in your installation. For example, you want to check the wp-config.php contents.

    <?php
    

    // define specific file $file = “./wp-config.php”;

    // do the magic $view = file_get_contents($file, true);

    // return the results echo $view;

  • Check Free Disk Space – This will return the total free disk space on your web server.

    <?php
    

    // checking disk space $bytes = disk_free_space(”.");

    // setting up arraw for prefix $si_prefix = array( ‘B’, ‘KB’, ‘MB’, ‘GB’, ‘TB’, ‘EB’, ‘ZB’, ‘YB’ );

    // do the magic with math! $base = 1024; $class = min((int)log($bytes , $base) , count($si_prefix) - 1);

    // return the result echo “Remaining disk space is " . sprintf(’%1.2f’ , $bytes / pow($base,$class)) . ’ ’ . $si_prefix[$class];

Contributing

Contributions are welcome, create a pull request to this repo and I will review your code. Please consider to submit your pull request to the dev branch. Thank you!

Issues

If you’re facing any problems with the code snippets please let me know by creating an issue to this repository. Thank you!

To Do

  • Add more code snippets

Community

Wanna see other projects I made? Join today!

Donate or Support

If you love this collection please consider to donate or support the maintainer.

License

ManageWP Code Snippets is licensed under MIT – https://opensource.org/licenses/MIT

Author

ManageWP Code Snippets is Maintained by Waren Gonzaga

💻 Made with ❤️ by Waren Gonzaga with YHWH 🙏