get_var( $wpdb->prepare(
"SELECT DISTINCT t.term_id
FROM wp_term_taxonomy AS tt
INNER JOIN wp_terms AS t ON tt.term_id = t.term_id
WHERE t.slug = %s
AND tt.taxonomy = %s",
$slug,
$taxonomy
) );
return $results ? absint( $results ) : false;
}
/**
* Load classes.
*
* @param array $classes Key = filename / Value = Class name.
* @param string $module Module folder name.
*/
public static function load_classes( $classes, $module, $root = ORDERABLE_MODULES_PATH ) {
foreach ( $classes as $file_name => $class_name ) {
$path = $root . $module . '/class-' . $file_name . '.php';
if ( ! file_exists( $path ) ) {
continue;
}
require_once $path;
if ( ! method_exists( $class_name, 'run' ) ) {
continue;
}
$class_name::run();
}
}
/**
* Get pro button.
*
* @param string $campaign
* @param string $text
* @param bool $lock_icon
*
* @return string
*/
public static function get_pro_button( $campaign = '', $text = '', $lock_icon = true ) {
$text = empty( $text ) ? __( 'Available in Pro', 'orderable' ) : $text;
$campaign = ! empty( $campaign ) ? sprintf( '&utm_campaign=%s', $campaign ) : '';
$lock_icon = $lock_icon ? '' : '';
return sprintf( '%s %s', esc_url( 'https://orderable.com/?utm_source=Orderable&utm_medium=Plugin' . $campaign ), $lock_icon, $text );
}
/**
* Prepare post type labels.
*
* @param array $labels
*
* @return array|bool
*/
public static function prepare_post_type_labels( $labels = array() ) {
if ( empty( $labels ) ) {
return false;
}
return array(
'name' => $labels['plural'],
'singular_name' => $labels['singular'],
'menu_name' => $labels['plural'],
'name_admin_bar' => $labels['singular'],
'add_new' => __( 'Add New', 'orderable' ),
'add_new_item' => sprintf( __( 'Add New %s', 'orderable' ), $labels['singular'] ),
'new_item' => sprintf( __( 'New %s', 'orderable' ), $labels['singular'] ),
'edit_item' => sprintf( __( 'Edit %s', 'orderable' ), $labels['singular'] ),
'view_item' => sprintf( __( 'View %s', 'orderable' ), $labels['singular'] ),
'all_items' => $labels['plural'],
'search_items' => sprintf( __( 'Search %s', 'orderable' ), $labels['plural'] ),
'parent_item_colon' => sprintf( __( 'Parent %s:', 'orderable' ), $labels['plural'] ),
'not_found' => sprintf( __( 'No %s found.', 'orderable' ), strtolower( $labels['plural'] ) ),
'not_found_in_trash' => sprintf( __( 'No %s found in trash.', 'orderable' ), strtolower( $labels['plural'] ) ),
'featured_image' => sprintf( _x( '%s Featured Image', 'Overrides the “Featured Image” phrase for this post type. Added in 4.3', 'orderable' ), $labels['singular'] ),
'set_featured_image' => _x( 'Set featured image', 'Overrides the “Set featured image” phrase for this post type. Added in 4.3', 'orderable' ),
'remove_featured_image' => _x( 'Remove featured image', 'Overrides the “Remove featured image” phrase for this post type. Added in 4.3', 'orderable' ),
'use_featured_image' => _x( 'Use as featured image', 'Overrides the “Use as featured image” phrase for this post type. Added in 4.3', 'orderable' ),
'archives' => sprintf( _x( '%s archives', 'The post type archive label used in nav menus. Default “Post Archives”. Added in 4.4', 'orderable' ), $labels['plural'] ),
'insert_into_item' => sprintf( _x( 'Insert into %s', 'Overrides the “Insert into post”/”Insert into page” phrase (used when inserting media into a post). Added in 4.4', 'orderable' ), strtolower( $labels['singular'] ) ),
'uploaded_to_this_item' => sprintf( _x( 'Uploaded to this %s', 'Overrides the “Uploaded to this post”/”Uploaded to this page” phrase (used when viewing media attached to a post). Added in 4.4', 'orderable' ), strtolower( $labels['singular'] ) ),
'filter_items_list' => sprintf( _x( 'Filter %s list', 'Screen reader text for the filter links heading on the post type listing screen. Default “Filter posts list”/”Filter pages list”. Added in 4.4', 'orderable' ), strtolower( $labels['plural'] ) ),
'items_list_navigation' => sprintf( _x( '%s list navigation', 'Screen reader text for the pagination heading on the post type listing screen. Default “Posts list navigation”/”Pages list navigation”. Added in 4.4', 'orderable' ), $labels['plural'] ),
'items_list' => sprintf( _x( '%s list', 'Screen reader text for the items list heading on the post type listing screen. Default “Posts list”/”Pages list”. Added in 4.4', 'orderable' ), $labels['plural'] ),
);
}
/**
* Outputs the pro feature modal.
*/
public static function orderable_pro_modal() {
require_once ORDERABLE_TEMPLATES_PATH . 'admin/orderable-pro-modal.php';
}
/**
* Custom kses method so we can also modify CSS properties allowed.
*
* @param string $content
* @param string $context
*
* @return string
*/
public static function kses( $content, $context = '' ) {
if ( empty( $content ) ) {
return $content;
}
// Modify allowed CSS.
add_filter( 'safe_style_css', array( __CLASS__, 'safe_css' ) );
$content = wp_kses( $content, self::kses_allowed_html( $context ) );
// Disable CSS modification.
remove_filter( 'safe_style_css', array( __CLASS__, 'safe_css' ) );
return $content;
}
/**
* Sanitise output and allow form elements.
*
* @param string $context
*
* @return array
*/
public static function kses_allowed_html( $context = '' ) {
$allowed_html = wp_kses_allowed_html( 'post' );
if ( 'form' === $context ) {
$allowed_attributes = array(
'name' => array(),
'class' => array(),
'value' => array(),
'type' => array(),
'selected' => array(),
);
$allowed_html['span'] = $allowed_attributes;
$allowed_html['select'] = $allowed_attributes;
$allowed_html['option'] = $allowed_attributes;
$allowed_html['input'] = $allowed_attributes;
}
return $allowed_html;
}
/**
* Modify safe CSS values.
*
* @param array $safe_css
*
* @return array
*/
public static function safe_css( $safe_css = array() ) {
$safe_css[] = 'display';
return $safe_css;
}
/**
* Delete Orderable transients.
*/
public static function delete_orderable_transients() {
global $wpdb;
$wpdb->query("
DELETE FROM $wpdb->options
WHERE option_name LIKE ('%%\_transient\_timeout\_orderable\_%%')
OR option_name LIKE ('%%\_transient\_orderable\_%%')
");
}
/**
* Has notices?
*
* @return bool
*/
public static function has_notices() {
return ! empty( WC()->session->get( 'wc_notices', array() ) );
}
}