get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = %s $post_type_where AND post_status = 'publish'", $page_title, $post_type ? $post_type : '' ) );
if ( $results ){
$output = array();
foreach ( $results as $post ){
$output[] = $post;
}
return $output;
}
return null;
}
/*********************************************************************************/
/*amzafs_truncateAmzString*/
/*********************************************************************************/
function amzafs_truncateAmzString($string, $length, $stopanywhere=false) {
//truncates a string to a certain char length, stopping on a word if not specified otherwise.
if (strlen($string) > $length) {
//limit hit!
$string = mb_substr($string,0,($length -3));
if ($stopanywhere) {
//stop anywhere
$string .= '...';
} else{
//stop on a word.
$string = mb_substr($string,0,strrpos($string,' ')).'...';
}
}
return $string;
}
/*********************************************************************************/
/*Add shortcode*/
/*********************************************************************************/
add_shortcode("amzcode","amzafs_amzshortcodemain");
function amzafs_amzshortcodemain( $attributes, $content = null ) {
$amazonContents="";
extract( shortcode_atts( array(
'class' => '',
'lang' => '',
'autoplay' => ''
), $attributes ) );
$idamzshortcode=$attributes[0];//Get id del shortcode
$keyword = get_term_meta( $idamzshortcode, '__term_meta_text', true ); //Get keyword del shortcode (cat) from id
$overrideLayout = get_term_meta( $idamzshortcode, '__term_meta_layout', true );
$overrideCount = get_term_meta( $idamzshortcode, '__term_meta_productcount', true );
if (($overrideCount=="")||(empty($overrideCount))) $overrideCount=99;
$slugcategoria=get_term_by('id', $idamzshortcode, 'amazon_shortcode');
$slugfinal=$slugcategoria->slug;
$obj_term = get_term($idamzshortcode, 'amazon_shortcode');
$cuentatotal=$obj_term->count;
/*Search product by keyword in Amazon API*/
//DEBUG FORZAR AMAZON
//$cuentatotal=0;
$cssRow="
";
$amz_options=get_option( 'amz_short_options' );
$select_layout=trim($amz_options["select_layout"]);
//Layout grid (1) or row (2)
$frontEndContent="";
$layoutTypeClass="";
if ($select_layout==1) {
//Grid layout
$layoutTypeClass="grid";
} elseif ($select_layout==2) {
//Table layout
if ( ! is_admin() ) {
$frontEndContent= $cssRow;
$layoutTypeClass="row";
}
}
//Layout override in shortcode settings
if ($overrideLayout==1) {
//Grid layout
$layoutTypeClass="grid";
} elseif ($overrideLayout==2) {
//Table layout
if ( ! is_admin() ) {
$frontEndContent= $cssRow;
$layoutTypeClass="row";
}
}
$svgAmazon='';
if ($cuentatotal<=0){
$amazonContents=amzafs_searchItemsAmz($keyword, $idamzshortcode);
$frontEndContent.="
$svgAmazon Please, reload the page to see the Amazon products. If you still not see them, check the plugin settings.
";
}
else {
//Show database stored products
global $post;$backup=$post;
$queryCustom = new WP_Query(array(
'post_type' => 'amz_product', // name of post type.
'posts_per_page' => $overrideCount, // name of post type.
'tax_query' => array(
array(
'taxonomy' => 'amazon_shortcode', // taxonomy name
'field' => $slugfinal, // term_id, slug or name
'terms' => $idamzshortcode, // term id, term slug or term name
)
)
));
if ( $queryCustom->have_posts() ) :
if ( ! is_admin() ) {
$frontEndContent.="
";
while ( $queryCustom->have_posts() ) : $queryCustom->the_post();
include plugin_dir_path( __FILE__ ) . 'product-template.php';
$lastProductTimestamp=get_post_time();
endwhile;
$frontEndContent.="
Copy & paste this shortcode where you want the products to appear:
';
echo '[amzcode "'.$idCategory.'"]';
echo '
Delete all the products linked to a shortcode and publish the shortcode to regenerate them. The shortcodes with 0 products will search and save them using Amazon Product Advertising API 5.0.
';
}
?>
id;
if ( is_admin() && ($screen->id == 'amz_product') ) {
function add_content_after_editor() {
global $post;
$id = $post->ID;
$imageURL = get_post_meta($id, '_wpamz_meta_imgurl', true);
if (!empty($imageURL)){
echo '
';
echo "";
echo '
';
}
}
add_action( 'edit_form_after_title', 'add_content_after_editor' );
}
}
add_action( 'admin_notices', 'amzafs_options_instructions_example2' );
/*********************************************************************************/
/*Product custom post type admin columns*/
/*********************************************************************************/
// Add the custom columns to the post type:
add_filter( 'manage_amz_product_posts_columns', 'amzafs_set_custom_edit_amz_product_columns' );
function amzafs_set_custom_edit_amz_product_columns($columns) {
//unset( $columns['author'] );
$columns['book_author'] = __( 'Image', 'your_text_domain' );
//$columns['publisher'] = __( 'Publisher', 'your_text_domain' );
return $columns;
}
// Add the data to the custom columns for the post type:
add_action( 'manage_amz_product_posts_custom_column' , 'amzafs_custom_amz_product_column', 1, 2 );
function amzafs_custom_amz_product_column( $column, $post_id ) {
switch ( $column ) {
case 'book_author' :
$imageURL = get_post_meta($post_id, '_wpamz_meta_imgurl', true);
print_r($terms);
if ( is_string( $imageURL ) )
echo "";
else
_e( 'Unable to get image(s)', 'your_text_domain' );
break;
case 'publisher' :
echo get_post_meta( $post_id , 'publisher' , true );
break;
}
}
/*********************************************************************************/
/*Reorder colums post type admin*/
/*********************************************************************************/
/*
function add_ourteam_columns ( $columns ) {
unset($columns['title']);
unset($columns['tags']);
unset($columns['date']);
return array_merge ( $columns, array (
'name' => __ ('name'),
'category' => __ ( 'Shortcode' ),
'image' => __ ( 'Image' ),
'date' => __('Date')
));
}
add_filter ( 'manage_amazon_shortcode_posts_columns', 'add_ourteam_columns' );
*/
/*********************************************************************************/
// Register & fill the column Shortcode & Keyword in categories (Shortcodes)
/*********************************************************************************/
function amzafs_department_add_dynamic_hooks() {
$taxonomy = 'amazon_shortcode';
add_filter( 'manage_' . $taxonomy . '_custom_column', 'amzafs_department_taxonomy_rows',15, 3 );
add_filter( 'manage_edit-' . $taxonomy . '_columns', 'amzafs_department_taxonomy_columns' );
}
add_action( 'admin_init', 'amzafs_department_add_dynamic_hooks' );
function amzafs_department_taxonomy_columns( $original_columns ) {
$new_columns = $original_columns;
array_splice( $new_columns, 1 );
$new_columns['frontpage'] = esc_html__( 'Shortcode', 'taxonomy-images' );
$new_columns['frontpage2'] = esc_html__( 'Keyword', 'taxonomy-images2' );
return array_merge( $new_columns, $original_columns );
}
function amzafs_department_taxonomy_rows( $row, $column_name, $term_id ) {
$t_id = $term_id;
$meta = get_option( "taxonomy_$t_id" );
if ( 'frontpage' === $column_name ) {
return '[amzcode "'.$term_id.'"]';
}
if ( 'frontpage2' === $column_name ) {
$value = amzafs___get_term_meta_text( $term_id );
return $value;
}
}
/********************************/
/*Shortcode (category) settings*/
/******************************/
// REGISTER TERM META
add_action( 'init', 'amzafs____register_term_meta_text' );
add_action( 'init', 'amzafs___register_term_meta_layout' );
add_action( 'init', 'amzafs___register_term_meta_productcount' );
function amzafs____register_term_meta_text() {
register_meta( 'term', '__term_meta_text', 'amzafs___sanitize_term_meta_text' );
}
function amzafs___register_term_meta_layout() {
register_meta( 'term', '__term_meta_layout', 'amzafs___sanitize_term_meta_layout' );
}
function amzafs___register_term_meta_productcount() {
register_meta( 'term', '__term_meta_productcount', 'amzafs___sanitize_term_meta_productcount' );
}
//SANITIZE
function amzafs___sanitize_term_meta_text ( $value ) {
return sanitize_text_field ($value);
}
function amzafs___sanitize_term_meta_layout ( $value ) {
return sanitize_text_field ($value);
}
function amzafs___sanitize_term_meta_productcount ( $value ) {
return sanitize_text_field ($value);
}
// GETTER (will be sanitized)
function amzafs___get_term_meta_text( $term_id ) {
$value = get_term_meta( $term_id, '__term_meta_text', true );
$value = amzafs___sanitize_term_meta_text( $value );
return $value;
}
function amzafs___get_term_meta_layout ($term_id ) {
$value = get_term_meta( $term_id, '__term_meta_layout', true );
$value = amzafs___sanitize_term_meta_layout( $value );
return $value;
}
function amzafs___get_term_meta_productcount ($term_id ) {
$value = get_term_meta( $term_id, '__term_meta_productcount', true );
$value = amzafs___sanitize_term_meta_productcount( $value );
return $value;
}
// ADD FIELD TO CATEGORY TERM PAGE
add_action( 'amazon_shortcode_add_form_fields', 'amzafs___add_form_field_term_meta_text' );
function amzafs___add_form_field_term_meta_text() { ?>
The keyword of the product that you want to search in Amazon.
Override default (main settings) products layout. Purchase premium version to unlock it and make me happy!
The max amount of products that you want to show. 0 or empty will show ALL stored items. Purchase premium version to unlock it and make me happy!
term_id );
if ( ! $value )
$value = ""; ?>
The keyword of the product that you want to search in Amazon.
term_id );
if ( ! $value )
$value = ""; ?>
Override default (main settings) products layout. Purchase premium version to unlock it and make me happy!
term_id );
if ( ! $value )
$value = ""; ?>
The max amount of products that you want to show. 0 or empty will show ALL stored items. Purchase premium version to unlock it and make me happy!