'API',
'Faq' => 'FAQ',
'Url' => 'URL',
'Html' => 'HTML',
'Css' => 'CSS',
'Php' => 'PHP',
'Json' => 'JSON',
'Xml' => 'XML',
'Sql' => 'SQL',
);
foreach ( $abbreviations as $search => $replace ) {
$result = preg_replace( '/\b' . $search . '\b/', $replace, $title );
$title = is_string( $result ) ? $result : $title;
}
return $title;
}
/**
* Get status badge HTML
*
* @since 1.0.0
*
* @param string $status Status (never, pending, success, error).
* @return string Badge HTML.
*/
function robotstxt_docmd_get_status_badge( string $status ): string {
$badges = array(
'never' => array(
'class' => 'status-never',
'label' => __( 'Never Synced', 'robotstxt-documentation-markdown' ),
),
'pending' => array(
'class' => 'status-pending',
'label' => __( 'Syncing...', 'robotstxt-documentation-markdown' ),
),
'success' => array(
'class' => 'status-success',
'label' => __( 'Success', 'robotstxt-documentation-markdown' ),
),
'error' => array(
'class' => 'status-error',
'label' => __( 'Error', 'robotstxt-documentation-markdown' ),
),
);
$badge = $badges[ $status ] ?? $badges['never'];
return sprintf(
'%s',
esc_attr( $badge['class'] ),
esc_html( $badge['label'] )
);
}
/**
* Safely get a string value from a superglobal array
*
* Provides PHPStan level 9 compliant type-narrowing for superglobal access.
*
* @since 1.0.1
*
* @param array $input The superglobal array ($_POST, $_GET, etc.).
* @param string $key The key to look for.
* @param string $fallback Default value if key not found or not a string.
* @return string
*/
function robotstxt_docmd_input_string( array $input, string $key, string $fallback = '' ): string {
if ( isset( $input[ $key ] ) && is_string( $input[ $key ] ) ) {
return $input[ $key ];
}
return $fallback;
}
/**
* Safely get an integer value from a superglobal array
*
* Provides PHPStan level 9 compliant type-narrowing for superglobal access.
*
* @since 1.0.1
*
* @param array $input The superglobal array ($_POST, $_GET, etc.).
* @param string $key The key to look for.
* @param int $fallback Default value if key not found or not numeric.
* @return int
*/
function robotstxt_docmd_input_int( array $input, string $key, int $fallback = 0 ): int {
if ( isset( $input[ $key ] ) && is_numeric( $input[ $key ] ) ) {
return (int) $input[ $key ];
}
return $fallback;
}