PHP code example of alesanchezr / wpas-wordpress-dash

1. Go to this page and download the library: Download alesanchezr/wpas-wordpress-dash library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alesanchezr / wpas-wordpress-dash example snippets


use \WPAS\Controller\WPASController;
$controller = new WPASController([
        //Here you specify the path to your consollers folder
        'namespace' => 'php\\Controllers\\'
    ]);

/**
* Autoload for PHP Composer and definition of the ABSPATH
*/

//defining the absolute path for the wordpress instalation.
if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/');

//including composer autoload

if(!strpos($_SERVER['SERVER_NAME'], '.local')){
  
}

    $typeManager = new \WPAS\Types\PostTypesManager([
        'namespace' => '\php\Types\\' \\this will be the path to your models folder
    ]);

    //You can react a new custom post type and specify his class
    $typeManager->newType(['type' => 'your_type_slug', 'class' => 'AnyPostTypeModelClass'])->register();

    namespace php\Types;

    class AnyPostTypeModelClass extends \WPAS\Types\BasePostType{
    
        //any method here
    }

//Here we are saying that we have a class Course.php with a function getCourseInfo that fetches the data needed to render any custom post tipe course
$controller->route([ 'slug' => 'Single:course', 'controller' => 'Course' ]);  

namespace php\Controllers;

class Course{
    
    public function renderCourse(){
        
        $args = [];
        $args['course'] = WP_Query(['post_type' => 'course', 'param2' => 'value2', ...);
        return $args; //Always return an Array type
    }
    
}

define('WP_DEBUG_CONTEXT', true);
sh
$ php vendor/alesanchezr/wpas-wordpress-dash/run.php <your_theme_directory_name>