Skip to content

Commit

Permalink
Style: Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeluno committed Apr 15, 2022
1 parent 3d3b248 commit 117a95d
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions example/taxonomy_field/APF_TaxonomyField.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*
*/

/**
*
*/
class APF_TaxonomyField extends AdminPageFramework_TaxonomyField {

/*
Expand Down Expand Up @@ -66,32 +69,30 @@ public function setUp() {
* ( optional ) modify the columns of the term listing table
*/
public function sortable_columns_APF_TaxonomyField( $aColumn ) { // sortable_column_{instantiated class name}

return array(
'custom' => 'custom',
)
+ $aColumn;

}

public function columns_APF_TaxonomyField( $aColumn ) { // column_{instantiated class name}

unset( $aColumn['description'] );
unset( $aColumn[ 'description' ] );
return array(
'cb' => $aColumn['cb'],
'cb' => $aColumn[ 'cb' ],
'thumbnail' => __( 'Thumbnail', 'admin-page-framework-loader' ),
'custom' => __( 'Custom Column', 'admin-page-framework-loader' ),
'custom' => __( 'Custom Column', 'admin-page-framework-loader' ),
)
+ $aColumn;

}

/*
* ( optional ) output the stored option to the custom column
*/
public function cell_APF_TaxonomyField( $sCellHTML, $sColumnSlug, $iTermID ) { // cell_{instantiated class name}

if ( ! $iTermID || $sColumnSlug != 'thumbnail' ) { return $sCellHTML; }
if ( ! $iTermID || $sColumnSlug != 'thumbnail' ) {
return $sCellHTML;
}

$aOptions = get_option( 'APF_TaxonomyField', array() ); // by default the class name is the option key.
return isset( $aOptions[ $iTermID ][ 'image_upload' ] ) && $aOptions[ $iTermID ][ 'image_upload' ]
Expand Down Expand Up @@ -120,25 +121,20 @@ public function do_APF_TaxonomyField() { // do_{instantiated class name}
* Customizes the sorting algorithm of a custom column.
*/
public function replyToSortCustomColumn( $aTerms, $aTaxonomies, $aArgs ) {

if ( 'edit-tags.php' == $GLOBALS['pagenow'] && isset( $_GET[ 'orderby' ] ) && 'custom' == $_GET[ 'orderby' ] ) {
if ( 'edit-tags.php' == $GLOBALS[ 'pagenow' ] && isset( $_GET[ 'orderby' ] ) && 'custom' == $_GET[ 'orderby' ] ) {
usort( $aTerms, array( $this, '_replyToSortByCustomOptionValue' ) );
}
return $aTerms;

}
public function _replyToSortByCustomOptionValue( $oTermA, $oTermB ) {

$_sClassName = get_class( $this ); // the instantiated class name is the option key by default.
$_sClassName = get_class( $this ); // the instantiated class name is the option key by default.
$_sTextFieldA = AdminPageFramework::getOption( $_sClassName, array( $oTermA->term_id, 'text_field' ) );
$_sTextFieldB = AdminPageFramework::getOption( $_sClassName, array( $oTermB->term_id, 'text_field' ) );
return isset( $_GET['order'] ) && 'asc' == $_GET['order']
return isset( $_GET[ 'order' ] ) && 'asc' == $_GET[ 'order' ]
? strnatcmp( $_sTextFieldA, $_sTextFieldB )
: strnatcmp( $_sTextFieldB, $_sTextFieldA );

}


/*
* ( optional ) Use this method to validate submitted option values.
*/
Expand Down

0 comments on commit 117a95d

Please sign in to comment.