'Default Value', 'required' => true, 'submit_button' => true ]
*
* Text $args = [ 'width' => '100%' 'pattern' => '^[a-zA-Z0-9_.-]*$' ]
*
* Color $args = [ 'width' => '20rem' ]
*
* Textarea $args = [ 'rows' => 6, 'cols' => 50 ]
*
* Select $args = [
* 'blank' => '-- Select One --',
* 'options' => [
* [ 'value' => 'the_value', 'label' => 'Label Name' ],
* [ 'value' => 'the_value', 'label' => 'Label Name' ]
* ]
* ]
* OR if value and label are the same
* $args = [
* 'options' => [
* 'Value/Label',
* 'Value/Label',
* ]
* ]
*
* @param string $option_name
* @param string $label
* @param string $type
* @param string $comments // Use 'get_option' for click to copy get_option()
* @return string
*/
function helpdocs_options_tr( $option_name, $label, $type, $comments = null, $args = null ) {
// Add the prefix to the option name
$option_name = HELPDOCS_GO_PF.$option_name;
// Get default
if ( get_option( $option_name ) ) {
$value = get_option( $option_name );
} elseif ( !is_null( $args ) && isset( $args[ 'default' ]) && $args[ 'default' ] != '' ) {
$value = $args[ 'default' ];
} else {
$value = '';
}
// Make exception for Footer Right
if ( $option_name == 'footer_right' && str_starts_with( $value, 'Version ' ) ) {
$value = apply_filters( 'update_footer', '' );
}
// Mark required?
if ( !is_null( $args ) && isset( $args[ 'required' ] ) && $args[ 'required' ] == true ) {
$required = ' required';
} else {
$required = '';
}
// Checkbox
if ( $type == 'checkbox' ) {
$input = '';
// Checkboxes
} elseif ( $type == 'checkboxes' ) {
if ( !is_null( $args ) ) {
$options = $args[ 'options' ];
$class = isset( $args[ 'class' ] ) ? ' class="'.esc_attr( $args[ 'class' ] ).'"' : '';
} else {
return false;
}
// Sort by label
usort( $options, function ( $item1, $item2 ) {
return strtolower( $item1[ 'label' ] ) <=> strtolower( $item2[ 'label' ] );
});
// Iter the options
$input = '';
foreach ( $options as $option ) {
if ( isset( $option[ 'value' ] ) && isset( $option[ 'label' ] ) ) {
$option_value = $option[ 'value' ];
$option_label = $option[ 'label' ];
} elseif ( !is_array( $option ) ) {
$option_value = $option;
$option_label = $option;
}
if ( !empty( $value ) && array_key_exists( $option_value, $value ) ) {
$checked = ' checked="checked"';
} else {
$checked = '';
}
$input .= '
'.$comments.'';
}
}
// Submit button
if ( !is_null( $args ) && isset( $args[ 'submit_button' ] ) && $args[ 'submit_button' ] == true ) {
$submit_button = get_submit_button( 'Search', 'button button-primary button-large '.$option_name );
} else {
$submit_button = '';
}
// Build the label HTML with optional checkbox
$label_html = '
' . esc_html( $label ) . '';
if ( ! empty( $args['sublabel_checkbox'] ) && is_string( $args['sublabel_checkbox'] ) ) {
$checkbox_id = 'helpdocs-view-sublabels-toggle-' . esc_attr( str_replace( 'helpdocs-', '', str_replace( '_', '-', $option_name ) ) );
$label_html .= '
';
}
// Build the row
$row = '
| ' . $label_html . ' |
' . $input . $submit_button . ' ' . $incl_comments . ' |
';
// Return the row
return $row;
} // End helpdocs_options_tr()
/**
* Allowed html for helpdocs_options_tr() sanitation
*
* @return array
*/
function helpdocs_wp_kses_allowed_html() {
$allowed_html = [
'div' => [
'id' => [],
'class' => [],
'style' => []
],
'p' => [
'id' => [],
'class' => []
],
'pre' => [
'class' => []
],
'code' => [
'class' => []
],
'span' => [
'id' => [],
'class' => [],
'style' => []
],
'a' => [
'href' => [],
'id' => [],
'class' => [],
'style' => [],
'target' => [],
'rel' => []
],
'img' => [
'border' => [],
'id' => [],
'class' => [],
'style' => [],
'src' => [],
'alt' => []
],
'table' => [
'class' => []
],
'tr' => [
'valign' => [],
'class' => []
],
'th' => [
'scope' => [],
'class' => []
],
'td' => [
'class' => []
],
'br' => [],
'form' => [
'method' => [],
'id' => [],
'action' => [],
],
'label' => [
'for' => [],
],
'input' => [
'type' => [],
'id' => [],
'class' => [],
'name' => [],
'value' => [],
'checked' => [],
'required' => [],
'style' => [],
'pattern' => [],
'disabled' => [],
'size' => [],
'autocomplete' => [],
'data-target' => [],
'aria-label' => []
],
'textarea' => [
'type' => [],
'id' => [],
'class' => [],
'name' => [],
'rows' => [],
'cols' => [],
'required' => [],
'style' => [],
],
'select' => [
'id' => [],
'class' => [],
'name' => [],
'required' => [],
'style' => [],
'autocomplete' => [],
],
'option' => [
'value' => [],
'selected' => [],
],
'button' => [
'class' => [],
'selected' => [],
],
'script' => [
'id' => []
],
'em' => [],
'strong' => [],
'ul' => [
'class' => [],
'data-option' => []
],
'li' => [
'class' => [],
'data-value' => []
],
'small' => [
'class' => []
],
];
return $allowed_html;
} // End helpdocs_options_tr_allowed_html()
/**
* Allow etc in content on docs page only
*
* @param array $tags
* @return array
*/
function helpdocs_allow_addt_tags( $tags ) {
$tags = array_merge( $tags, [
'script' => [
'type' => true,
'src' => true,
'async' => true,
'defer' => true,
'crossorigin' => true,
'integrity' => true,
],
'video' => [
'src' => true,
'controls' => true,
'autoplay' => true,
'loop' => true,
'muted' => true,
'poster' => true,
'width' => true,
'height' => true,
],
'source' => [
'src' => true,
'type' => true,
],
'iframe' => [
'src' => true,
'width' => true,
'height' => true,
'frameborder' => true,
'allow' => true,
'allowfullscreen' => true,
'title' => true,
'referrerpolicy' => true,
'webkitallowfullscreen' => true,
'mozallowfullscreen' => true,
],
] );
// Add support for filter
$tags = apply_filters( 'helpdocs_allowed_html', $tags );
return $tags;
} // End helpdocs_allow_addt_tags()
/**
* Validate that a date is an actual date
*
* @param [type] $date
* @return bool
*/
function helpdocs_is_date( $date ) {
return (bool)strtotime( $date );
} // End helpdocs_validate_date()
/**
* Highlighting syntax
*
* @param string $fl
* @param bool $ret
* @return void|bool
*/
function helpdocs_highlight_file2( $filename, $return = false ) {
$str = highlight_file( $filename, true );
preg_match_all("/\
.*?\<\/span\>/", $str, $mtch);
$m = array_unique( $mtch[1] );
$cls = '";
$str2 = str_replace($mtc,$rpl,$str);
if ( $return ) return $str2;
else echo wp_kses_post( $str2 );
} // End helpdocs_highlight_file2()
/**
* Add a WP Plugin Info Card
*
* @param string $slug
* @return string
*/
function helpdocs_plugin_card( $slug ) {
// Set the args
$args = [
'slug' => $slug,
'fields' => [
'last_updated' => true,
'tested' => true,
'active_installs' => true
]
];
// Fetch the plugin info from the wp repository
$response = wp_remote_post(
'http://api.wordpress.org/plugins/info/1.0/',
[
'body' => [
'action' => 'plugin_information',
'request' => serialize( (object)$args )
]
]
);
// If there is no error, continue
if ( !is_wp_error( $response ) ) {
// Unserialize
$returned_object = unserialize( wp_remote_retrieve_body( $response ) );
if ( $returned_object ) {
// Last Updated
$last_updated = $returned_object->last_updated;
$last_updated = helpdocs_time_elapsed_string( $last_updated );
// Compatibility
$compatibility = $returned_object->tested;
// Add incompatibility class
global $wp_version;
if ( $compatibility == $wp_version ) {
$is_compatible = 'Compatible with your version of WordPress';
} else {
$is_compatible = 'Untested with your version of WordPress';
}
// Get all the installed plugins
$plugins = get_plugins();
// Check if this plugin is installed
$is_installed = false;
foreach ( $plugins as $key => $plugin ) {
if ( $plugin[ 'TextDomain' ] == $slug ) {
$is_installed = $key;
}
}
// Check if it is also active
$is_active = false;
if ( $is_installed && is_plugin_active( $is_installed ) ) {
$is_active = true;
}
// Check if the plugin is already active
if ( $is_active ) {
$install_link = 'role="link" aria-disabled="true"';
$php_notice = '';
$install_text = 'Active';
// Check if the plugin is installed but not active
} elseif ( $is_installed ) {
$install_link = 'href="'.admin_url( 'plugins.php' ).'"';
$php_notice = '';
$install_text = 'Go to Activate';
// Check for php requirement
} elseif ( phpversion() < $returned_object->requires_php ) {
$install_link = 'role="link" aria-disabled="true"';
$php_notice = 'Requires PHP Version '.$returned_object->requires_php.' — You are currently on Version '.phpversion().'
';
$install_text = 'Incompatible';
// If we're good to go, add the link
} else {
// Get the admin url for the plugin install page
if ( is_multisite() ) {
$admin_url = network_admin_url( 'plugin-install.php' );
} else {
$admin_url = admin_url( 'plugin-install.php' );
}
// Vars
$install_link = 'href="'.$admin_url.'?s='.esc_attr( $returned_object->name ).'&tab=search&type=term"';
$php_notice = '';
$install_text = 'Get Now';
}
// Short Description
$pos = strpos( $returned_object->sections[ 'description' ], '.');
$desc = substr( $returned_object->sections[ 'description' ], 0, $pos + 1 );
// Rating
$rating = helpdocs_get_five_point_rating(
$returned_object->ratings[1],
$returned_object->ratings[2],
$returned_object->ratings[3],
$returned_object->ratings[4],
$returned_object->ratings[5]
);
$active_installs = $returned_object->active_installs ? number_format( $returned_object->active_installs ) . '+' : '<10';
// Link guts
$link_guts = 'href="https://wordpress.org/plugins/'.esc_attr( $slug ).'/" target="_blank" aria-label="More information about '.$returned_object->name.' '.$returned_object->version.'" data-title="'.$returned_object->name.' '.$returned_object->version.'"';
?>
star rating based on num_ratings ); ?> ratings
(num_ratings ); ?>)
Last Updated:
Active Installs
';
$h = '