• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

GhazaliTajuddin.com

Another Kuantan Blogger

  • Home
  • Blog
    • Kuantan
    • Foods
    • Technology
    • Health
  • Stock Photography
    • Senarai Microstock Agency
    • Membuka akaun contributor Shutterstock.com
    • Tips untuk 10 keping gambar pertama Shutterstock.com
    • Mengapa Shutterstock.com reject gambar / submission
    • Model Release
    • Bagaimana withdraw earning daripada Fotolia
    • Bagaimana untuk mengisi keyword kepada imej dengan menggunakan Adobe Photoshop

wordpress

WordPress REST API Multisite

August 11, 2017 by ghazalitajuddin

I have been looking for a way to access multisite data trough WP API, but it seems very hard to find. One and only the best reference i get is from git the_glue but need some update since it not updated.

Below is my version or u can get form my git 

<?php
/*
* Plugin Name: WordPress REST API Multisite
* Plugin URI: 
* Description: 
* Version: 1.0
* Author: Ghazali Tajuddin
* Author URI: http://www.ghazalitajuddin.com
* License: MIT
* */


class WPMUrestAPI{

    function __construct() {
        add_action( 'rest_api_init', array( $this, 'call2' ));
    }
    

    public function call2() {
    // Here we are registering our route for a collection of products and creation of products.
    
        register_rest_route( 'all/sites', '/list', 
            array(
                
                // By using this constant we ensure that when the WP_REST_Server changes, our readable endpoints will work as intended.
                
                'methods'  => WP_REST_Server::READABLE,
                
                // Here we register our callback. The callback is fired when this endpoint is matched by the WP_REST_Server class.
                
                'callback' => array($this,'get_sites123'),
            )
         );
    }

   public function prefix_get_endpoint_phrase() {
        // rest_ensure_response() wraps the data we want to return into a WP_REST_Response, and ensures it will be properly returned.
        //return rest_ensure_response( 'Hello World, this is the WordPress REST API' );
        return 'Hello World, this is the WordPress REST API';
    }

    public function get_sites123() {
            
            if ( function_exists( 'get_sites' )  ) {
            $sites = get_sites( 
                [
                    'public'  => 1,
                    //'number'  => 500,
                    'orderby' => 'registered',
                    'order'   => 'DESC',
                ]
            );

            $sites_details = array();

            foreach ($sites as $site) {
                $sites_details[] = $site->blog_id;
            }

            return $sites_details;
 
    }
}

  

}


 $power = new WPMUrestAPI();

Other reference

  • https://github.com/epfl-lts2/json-rest-api-multisites
  • https://github.com/remkade/multisite-json-api
  • https://wordpress.org/support/topic/wp_get_sites-is-now-get_sites/

Filed Under: Technology Tagged With: json, multisite, REST, wordpress

Pembangunan WordPress Plugin Yang Menggunakan Shortcodes

May 16, 2016 by ghazalitajuddin

Develop pulgin yang menggunakan shortcodes ini perlu tahu beberapa perkara

  1. Widget text tak support shortcodes secara default.
    • Jika anda ingin menggunakan shortcodes pada bahagian widget. Pasti anda akan gunakan Widget Text.
    • Tetapi secara defaultnya, widget text tak support shortcodes.
    • Anda perlu aktifkan seperti berikut
      //Remove the filter if it already exists
      remove_filter('widget_text', 'do_shortcode');
      
      //Add the filter to apply the shotcode action to widget text
      add_filter('widget_text', 'do_shortcode');
  2. Guna return, bukan echo.
    • Sekiranya anda ingin memaparkan suatu keputusan melalui shortcodes anda, anda akan perasan sekiranya menggunakan echo, hasil keputusan berkenaan akan di paparkan sebelum atau diluar daripada kawasan <div> sepatutnya.
    • Untuk itu elakkan gunakan echo, kerana secara asasnya formatnya adalah menggunakan return.

      Note that the function called by the shortcode should never produce output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode. Producing the output directly will lead to unexpected results. This is similar to the way filter functions should behave, in that they should not produce expected side effects from the call, since you cannot control when and where they are called from.

    • Contohnya seperti berikut
      function callmyshortcode() {
      return 'This is correct';
      }
      add_shortcode('correctshortcode', 'callmyshortcode');
      
      /*--------------------
      function callmyshortcode() {
      echo 'This is wrong';
      }
      add_shortcode('wrongshortcode', 'callmyshortcode');
      --------------------*/

Reference: Wordperss Function Reference/add shortcode

Filed Under: General Tagged With: echo, return, shortcodes, wordpress

Yii Example How To Install Mail Extension (Swiftmailer Wrapper)

April 19, 2012 by ghazalitajuddin 4 Comments

Yii Framework
Yii Framework
  • Download this mail extension here  http://www.yiiframework.com/extension/mail.
  • Extract the files.
  • Move the vendors folder to protected/components/vendors/
  • Move YiiMail.php and YiiMailMessage.php to protected/components/
  • Add on protected/config/main.php

[php]

‘components’=>array(

…
‘mail’ => array(
‘class’ => ‘YiiMail’,
‘transportType’ => ‘php’,
‘transportType’ => ‘smtp’,
‘transportOptions’=>array(
‘host’=>’ghazalitajuddin.com’,
//’encryption’=>’tls’,
‘username’=>’***@ghazalitajuddin.com’,
‘password’=>’******’,
‘port’=>25,
),
‘logging’ => true,
‘dryRun’ => false
),

…

),

[/php]

  • Configure in controller

[php]</pre>
$message = new YiiMailMessage;
$message->setBody($model->message);
$message->subject = $model->subject;
$message->addTo($model->to);
$message->from = Yii::app()->params[‘adminEmail’];
Yii::app()->mail->send($message);
<pre>[/php]

  • Create our model

[php]
class EmailForm extends CFormModel
{
public $email;
public $to;
public $subject;
public $message;
public $from;

/**
* Declares the validation rules.
*/
public function rules()
{
return array(
// name, email, subject and body are required
array(’email, to, subject, message’, ‘required’),
// email has to be a valid email address
array(’email’, ’email’),
// verifyCode needs to be entered correctly
//array(‘verifyCode’, ‘captcha’, ‘allowEmpty’=>!CCaptcha::checkRequirements()),
);
}

/**
* Declares customized attribute labels.
* If not declared here, an attribute would have a label that is
* the same as its name with the first letter in upper case.
*/
public function attributeLabels()
{
return array(
‘verifyCode’=>’Verification Code’,
);
}
}
[/php]

  • Finally create our view

[php]
<?php
$this->pageTitle=Yii::app()->name . ‘ – Email Others’;
$this->breadcrumbs=array(
‘Email’,
);
?>

<h1>Email others</h1>

<?php if(Yii::app()->user->hasFlash(’email’)): ?>

<div class="flash-success">
<?php echo Yii::app()->user->getFlash(’email’); ?>
</div>

<?php else: ?>

<p>
If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
</p>

<div class="form">

<?php $form=$this->beginWidget(‘CActiveForm’, array(
‘id’=>’email-form’,
‘enableClientValidation’=>true,
‘clientOptions’=>array(
‘validateOnSubmit’=>true,
),
)); ?>

<p class="note">Fields with <span class="required">*</span> are required.</p>

<?php echo $form->errorSummary($model); ?>

<div class="row">
<?php echo $form->labelEx($model,’email’); ?>
<?php echo $form->textField($model,’email’); ?>
<?php echo $form->error($model,’email’); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,’to’); ?>
<?php echo $form->textField($model,’to’); ?>
<?php echo $form->error($model,’to’); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,’subject’); ?>
<?php echo $form->textField($model,’subject’,array(‘size’=>60,’maxlength’=>128)); ?>
<?php echo $form->error($model,’subject’); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,’message’); ?>
<?php echo $form->textArea($model,’message’,array(‘rows’=>6, ‘cols’=>50)); ?>
<?php echo $form->error($model,’message’); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,’from’); ?>
<?php echo $form->textArea($model,’from’); ?>
<?php echo $form->error($model,’from’); ?>
</div>

<div class="row buttons">
<?php echo CHtml::submitButton(‘Submit’); ?>
</div>

<?php $this->endWidget(); ?>

</div><!– form –>

<?php endif; ?>
[/php]

Filed Under: General, Technology Tagged With: Component, Controller, Extension, Framework, Kuantan, kuantan programmer, kuantan web developer, kuantan webmaster, Mail, Malaysian Yii, model, MVC, OOP, PHP, programmer, sendmail, SwiftMailer, View, Widget, wordpress, yii, Yii Framework

Yii CActiveDataProvider

April 5, 2012 by ghazalitajuddin Leave a Comment

Yii Framework
Yii Framework

Sample using CActiveDataProvider
Sample 1:

[php]
$dataProvider=new CActiveDataProvider(‘User’,array(
‘criteria’=>array(
‘condition’=>’activationstatus = 1’),
));
[/php]

Sample 2:

[php]
$dataProvider=new CActiveDataProvider(‘Event’, array(
‘criteria’=>array(
‘condition’=>’date >= "’.date(‘Y-m-d’, strtotime(‘-2 years’)).’"’,
),
));
[/php]

Sample 3:

[php]
$dataProvider=new CActiveDataProvider(‘Post’, array(
‘pagination’=>array(
‘pageSize’=>5,
),
‘criteria’=>$criteria,
));
[/php]

Sample 4:

[php]
$dataProvider=new CActiveDataProvider(‘User’)
[/php]

Filed Under: General, Technology Tagged With: $data, CActiveDataProvider, CGridView, CListView, Controller, Framework, Kuantan, kuantan programmer, kuantan web developer, kuantan webmaster, Malaysian Yii, model, MVC, OOP, PHP, programmer, View, Widget, wordpress, yii, Yii Framework

Yii Lookup

April 4, 2012 by ghazalitajuddin Leave a Comment

Yii Framework
Yii Framework

Some function is created to make code easy to read and manageable. The Lookup function is so powerfull to simplified data storage. Usually we store Approve, Not Approved, Qualified, Not Qualified in words for each records, but with Lookup class, we can make it short to an integer for each properties.

Table scheme “tbl_lookup”

[php]

CREATE TABLE tbl_lookup
(
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(128) NOT NULL,
code INTEGER NOT NULL,
type VARCHAR(128) NOT NULL,
position INTEGER NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

[/php]

Insert some records like this

[php]
INSERT INTO tbl_lookup (name, type, code, position) VALUES (‘Activated’, ‘ActivationStatus’, 1, 1);
INSERT INTO tbl_lookup (name, type, code, position) VALUES (‘Not Activated’, ‘ActivationStatus’, 2, 2);
INSERT INTO tbl_lookup (name, type, code, position) VALUES (‘Pending Approval’, ‘membership_status’, 1, 1);
INSERT INTO tbl_lookup (name, type, code, position) VALUES (‘Approved’, ‘membership_status’, 2, 2);
INSERT INTO tbl_lookup (name, type, code, position) VALUES (‘Not Approved’, ‘membership_status’, 3, 3);
[/php]

[Read more…] about Yii Lookup

Filed Under: General, Technology Tagged With: $data, CActiveDataProvider, CGridView, CListView, Controller, Framework, Kuantan, kuantan programmer, kuantan web developer, kuantan webmaster, lookup, lookup table, Malaysian Yii, model, MVC, OOP, PHP, programmer, View, wordpress, yii, Yii Framework

Yii CGridView

March 30, 2012 by ghazalitajuddin Leave a Comment

Yii Framework
Yii Framework
  • CGridView is one of Zii Components
  • There is other than CGridView, CDetailView, CListView. Look here.
  • CGridView use DataProvider which define in controller
  • CGridView display data in tables.
  • Supports paginating, sorting, searching.
  • Also support view, update, delete method
Define our data provider in controller like this
[php]

/**
* Lists all models.
*/
public function actionIndex()
{
$dataProvider=new CActiveDataProvider(‘User’,
array(
‘pagination’=>array(
‘pageSize’=>10,
),
‘sort’=>array(
‘defaultOrder’=> array(‘id’=>false),
)
));

$this->render(‘index’,array(
‘dataProvider’=>$dataProvider,
));
}
[/php]

[Read more…] about Yii CGridView

Filed Under: General, Technology Tagged With: CGridView, CListView, Controller, Framework, Kuantan, kuantan programmer, kuantan web developer, kuantan webmaster, model, MVC, OOP, PHP, programmer, View, Widget, wordpress, yii, Yii Framework, Zii Component

  • « Go to Previous Page
  • Page 1
  • Page 2
  • Page 3
  • Go to Next Page »

Primary Sidebar

“Solat. Sabar. Syukur. Senyum. Sedekah.”

For Collaboration, Events & Review, kindly contact me at +6016[-]9212092 or click Whatsapp button on this page.

Sponsor

Recent Posts

BadMethodCallException Method Illuminate\Database\Eloquent\Collection::roles does not exist.

User Roles And Permissions Without Package Laravel 10

Laravel Many To Many Relationship

Makan malam bersama keluarga di Awangan Palace

Sarapan pagi di Warung Gulai Kawah

Recent Comments

  • helmi on Personal Tips Berhenti Merokok
  • ghazalitajuddin on Personal Tips Berhenti Merokok
  • helmi on Personal Tips Berhenti Merokok
  • ghazalitajuddin on Nasi Lemak Kukus Restoran Zaman. Otai masih berbisa.
  • ghazalitajuddin on Air tangki radiator Proton Exora cepat kering? Cuba tukar penutup radiator!
  • Mal on Nasi Lemak Kukus Restoran Zaman. Otai masih berbisa.
  • Firdaus on Air tangki radiator Proton Exora cepat kering? Cuba tukar penutup radiator!

My Link

  • Takaful Insurance Web

JJCM

Cendol Terbaik Di Kuantan

Lunch di Nasi Kukus Alom

Diet snack untuk abang-abang kacak

Berpagian di Restoran Astana Cafe

Lain macam Nasi Kerabu Mekla ni

Tags

bebas rokok berhenti merokok breakfast Controller Framework Gezzeg Photography & Design health jalan-jalan cari makan jalan-jalan cari makan kuantan jjcm jjcm kuantan Jurufoto Kuantan Kuantan Kuantan Photographer kuantan programmer kuantan web developer kuantan webmaster laravel merokok merbahayakan kesihatan model MVC nikmat rokok OOP Pahang Pahangtourism pahang tourism Photo Manipulation PHP rajalanun retired smoking revisit pahang 2018 shutterstock stop smoking stop smoking tips stop smoking withdrawal symptom tips tips berhenti merokok View visit malaysia 2020 visit pahang visitpahang white wordpress yii Yii Framework

Recent Posts

  • BadMethodCallException Method Illuminate\Database\Eloquent\Collection::roles does not exist.
  • User Roles And Permissions Without Package Laravel 10
  • Laravel Many To Many Relationship
  • Makan malam bersama keluarga di Awangan Palace
  • Sarapan pagi di Warung Gulai Kawah

Copyright © 2025 — Ghazali Tajuddin • All rights reserved. •