Function bodies 16 total
toggleCustomDelay function · javascript · L64-L73 (10 LOC)admin/assets/js/admin.js
function toggleCustomDelay() {
var $select = $('#wcsap_schedule_delay');
var $wrap = $('#wcsap-custom-delay-wrap');
if ($select.val() === 'custom') {
$wrap.show();
} else {
$wrap.hide();
}
}toggleProviderRows function · javascript · L81-L92 (12 LOC)admin/assets/js/admin.js
function toggleProviderRows() {
var selected = $('#wcsap_ai_desc_provider').val();
$('.wcsap-provider-row').each(function () {
var provider = $(this).data('provider');
if (provider === selected) {
$(this).show();
} else {
$(this).hide();
}
});
}toggleImgProviderRows function · javascript · L100-L111 (12 LOC)admin/assets/js/admin.js
function toggleImgProviderRows() {
var selected = $('#wcsap_ai_img_provider').val();
$('.wcsap-img-provider-row').each(function () {
var provider = $(this).data('provider');
if (provider === selected) {
$(this).show();
} else {
$(this).hide();
}
});
}toggleIgToken function · javascript · L119-L126 (8 LOC)admin/assets/js/admin.js
function toggleIgToken() {
var useFb = $('#wcsap_ig_use_fb_token').is(':checked');
if (useFb) {
$('#wcsap-ig-token-row').hide();
} else {
$('#wcsap-ig-token-row').show();
}
}updateCharCount function · javascript · L134-L150 (17 LOC)admin/assets/js/admin.js
function updateCharCount() {
var $textarea = $('#wcsap-template-content');
if (!$textarea.length) return;
var count = $textarea.val().length;
$('#wcsap-char-count-value').text(count);
// Colour the IG limit if approaching.
var $igLimit = $('.wcsap-char-limit-ig');
if (count > 2200) {
$igLimit.css('color', '#d63638');
} else if (count > 1800) {
$igLimit.css('color', '#dba617');
} else {
$igLimit.css('color', '');
}
}WCSAP_Activator class · php · L12-L134 (123 LOC)includes/class-wcsap-activator.php
class WCSAP_Activator {
public static function activate(): void {
self::check_requirements();
self::create_tables();
self::set_default_options();
self::install_default_template();
update_option( 'wcsap_version', WCSAP_VERSION );
update_option( 'wcsap_activated_at', current_time( 'mysql' ) );
}
private static function check_requirements(): void {
if ( version_compare( PHP_VERSION, WCSAP_MIN_PHP, '<' ) ) {
deactivate_plugins( WCSAP_PLUGIN_BASENAME );
wp_die(
esc_html( sprintf(
__( 'WC Social Auto Publisher nécessite PHP %s+. Version actuelle : %s', 'wc-social-auto-publisher' ),
WCSAP_MIN_PHP,
PHP_VERSION
) ),
'Plugin Activation Error',
[ 'back_link' => true ]
);
}
}
private static function create_tables(): void {
global $wpdb;
WCSAP_Deactivator class · php · L12-L23 (12 LOC)includes/class-wcsap-deactivator.php
class WCSAP_Deactivator {
public static function deactivate(): void {
self::clear_scheduled_actions();
}
private static function clear_scheduled_actions(): void {
if ( function_exists( 'as_unschedule_all_actions' ) ) {
as_unschedule_all_actions( 'wcsap_publish_product' );
}
}
}Repobility · MCP-ready · https://repobility.com
WCSAP_Image_Processor class · php · L13-L234 (222 LOC)includes/class-wcsap-image-processor.php
class WCSAP_Image_Processor {
/**
* Traite une image : resize au format cible, ajout watermark, compression JPEG.
*
* @param string $source_path Chemin du fichier image source.
* @return array{success: bool, path?: string, error?: string} Chemin du fichier traite.
*/
public static function process( string $source_path ): array {
if ( ! file_exists( $source_path ) ) {
return [ 'success' => false, 'error' => __( 'Fichier image source introuvable.', 'wc-social-auto-publisher' ) ];
}
// Detecter le type MIME.
$mime = wp_check_filetype( $source_path )['type'];
if ( empty( $mime ) ) {
$mime = mime_content_type( $source_path ) ?: 'image/jpeg';
}
// Utiliser WP_Image_Editor (choisit automatiquement GD ou Imagick).
$editor = wp_get_image_editor( $source_path );
if ( is_wp_error( $editor ) ) {
return [ 'success' => false, 'error' => $editor->get_error_meWCSAP_Instagram_Publisher class · php · L13-L272 (260 LOC)includes/class-wcsap-instagram-publisher.php
class WCSAP_Instagram_Publisher {
/** @var int Timeout HTTP en secondes. */
private const HTTP_TIMEOUT = 30;
/** @var int Nombre max de tentatives de poll du container. */
private const MAX_POLL_ATTEMPTS = 20;
/** @var int Delai entre chaque poll en secondes. */
private const POLL_INTERVAL = 3;
/** @var int Delai avant retry automatique. */
private const RETRY_DELAY = 300;
/**
* Publie une image avec legende sur Instagram Business.
*
* @return array{success: bool, post_id?: string, error?: string, response?: array<string, mixed>}
*/
public static function publish( string $caption, string $image_url, int $product_id = 0 ): array {
// Mode dry run ?
if ( 'yes' === get_option( 'wcsap_dry_run', 'no' ) ) {
return self::dry_run( $caption, $image_url, $product_id );
}
if ( '' === $image_url ) {
return [ 'success' => false, 'error' => __( 'Instagram necessite obligatoiremenWCSAP_Loader class · php · L12-L100 (89 LOC)includes/class-wcsap-loader.php
class WCSAP_Loader {
/** @var array<int, array{hook: string, component: object, callback: string, priority: int, accepted_args: int}> */
private array $actions = [];
/** @var array<int, array{hook: string, component: object, callback: string, priority: int, accepted_args: int}> */
private array $filters = [];
public function __construct() {
$this->load_dependencies();
$this->define_admin_hooks();
$this->define_product_hooks();
$this->define_scheduler_hooks();
}
private function load_dependencies(): void {
// Les classes sont chargées via l'autoloader PSR-4.
}
private function define_admin_hooks(): void {
$admin = new WCSAP_Admin();
$this->add_action( 'admin_menu', $admin, 'register_menu' );
$this->add_action( 'admin_init', $admin, 'register_settings' );
$this->add_action( 'admin_enqueue_scripts', $admin, 'enqueue_assets' );
// Meta box produit.
$this->add_aWCSAP_Logger class · php · L12-L194 (183 LOC)includes/class-wcsap-logger.php
class WCSAP_Logger {
/**
* Retourne le nom complet de la table de logs.
*/
public static function table_name(): string {
global $wpdb;
return $wpdb->prefix . WCSAP_DB_PREFIX . 'logs';
}
/**
* Insère une entrée de log.
*
* @param array<string, mixed> $data Colonnes à insérer.
* @return int|false ID de la ligne insérée ou false en cas d'erreur.
*/
public static function insert( array $data ): int|false {
global $wpdb;
$defaults = [
'product_id' => 0,
'platform' => 'facebook',
'status' => 'pending',
'post_content' => '',
'image_url' => '',
'response_data' => '',
'error_message' => '',
'scheduled_at' => null,
'published_at' => null,
'created_at' => current_time( 'mysql' ),
];
$data = wp_parse_args( $data, $defaults );
$result = $wpdbWCSAP_Meta_Publisher class · php · L13-L236 (224 LOC)includes/class-wcsap-meta-publisher.php
class WCSAP_Meta_Publisher {
/** @var int Timeout HTTP en secondes. */
private const HTTP_TIMEOUT = 30;
/** @var int Delai en secondes avant un retry automatique. */
private const RETRY_DELAY = 300; // 5 minutes.
/**
* Publie un post avec image sur une page Facebook.
*
* @return array{success: bool, post_id?: string, error?: string, response?: array<string, mixed>}
*/
public static function publish( string $message, string $image_url, int $product_id = 0 ): array {
// Mode dry run ?
if ( 'yes' === get_option( 'wcsap_dry_run', 'no' ) ) {
return self::dry_run( $message, $image_url, $product_id, 'facebook' );
}
$page_id = get_option( 'wcsap_fb_page_id', '' );
$token = WCSAP_Settings::get( 'wcsap_fb_page_token' );
$version = get_option( 'wcsap_fb_api_version', 'v21.0' );
if ( empty( $page_id ) || empty( $token ) ) {
return [ 'success' => false, 'error' => __( 'WCSAP_Product_Hook class · php · L13-L112 (100 LOC)includes/class-wcsap-product-hook.php
class WCSAP_Product_Hook {
/**
* Hook appele a la creation d'un nouveau produit.
*/
public function on_new_product( int $product_id ): void {
$this->maybe_schedule( $product_id, 'create' );
}
/**
* Hook appele a la mise a jour d'un produit existant.
*/
public function on_update_product( int $product_id ): void {
// Verifier si le trigger inclut les mises a jour.
$trigger = get_option( 'wcsap_trigger_event', 'create_only' );
if ( 'create_and_update' !== $trigger ) {
return;
}
// Eviter les doublons si le produit est deja planifie.
$existing_status = get_post_meta( $product_id, '_wcsap_status', true );
if ( in_array( $existing_status, [ 'scheduled', 'pending' ], true ) ) {
return;
}
$this->maybe_schedule( $product_id, 'update' );
}
/**
* Verifie l'eligibilite du produit et planifie la publication si OK.
*/
private functWCSAP_Scheduler class · php · L12-L341 (330 LOC)includes/class-wcsap-scheduler.php
class WCSAP_Scheduler {
public const HOOK_PUBLISH = 'wcsap_publish_product';
/**
* Planifie la publication d'un produit selon le delai configure.
*/
public static function schedule( int $product_id ): int|false {
if ( ! function_exists( 'as_schedule_single_action' ) ) {
return false;
}
// Annuler toute planification existante pour ce produit.
self::cancel( $product_id );
$delay_minutes = (int) get_option( 'wcsap_schedule_delay', 0 );
$timestamp = time() + ( $delay_minutes * 60 );
$action_id = as_schedule_single_action(
$timestamp,
self::HOOK_PUBLISH,
[ 'product_id' => $product_id ],
'wcsap'
);
if ( $action_id ) {
// Mettre a jour le statut du produit.
update_post_meta( $product_id, '_wcsap_status', 'scheduled' );
update_post_meta( $product_id, '_wcsap_scheduled_at', gmdate( 'Y-m-d H:i:s', WCSAP_Settings class · php · L12-L204 (193 LOC)includes/class-wcsap-settings.php
class WCSAP_Settings {
private const ENCRYPTION_KEY_OPTION = 'wcsap_encryption_key';
/** @var list<string> Clés nécessitant un chiffrement. */
private const SENSITIVE_KEYS = [
'wcsap_fb_page_token',
'wcsap_fb_app_secret',
'wcsap_ig_token',
'wcsap_ai_gemini_key',
'wcsap_ai_openai_key',
'wcsap_ai_groq_key',
'wcsap_ai_claude_key',
'wcsap_ai_huggingface_key',
'wcsap_ai_replicate_key',
'wcsap_ai_stability_key',
'wcsap_ai_dalle_key',
];
/**
* Récupère une option du plugin.
*
* @param mixed $default Valeur par défaut.
*/
public static function get( string $key, mixed $default = false ): mixed {
$value = get_option( $key, $default );
if ( in_array( $key, self::SENSITIVE_KEYS, true ) && is_string( $value ) && '' !== $value ) {
$decrypted = self::decrypt( $value );
return ( false !== $decrypted ) ? $decrypted : $default;
Provenance: Repobility (https://repobility.com) — every score reproducible from /scan/
WCSAP_Template_Engine class · php · L12-L225 (214 LOC)includes/class-wcsap-template-engine.php
class WCSAP_Template_Engine {
/** @var array<string, string> Mapping emoji par slug de categorie. */
private const CATEGORY_EMOJIS = [
'vetements' => '👗',
'clothing' => '👗',
'mode' => '👗',
'fashion' => '👗',
'chaussures' => '👟',
'shoes' => '👟',
'electronique' => '💻',
'electronics' => '💻',
'tech' => '💻',
'beaute' => '💄',
'beauty' => '💄',
'maison' => '🏠',
'home' => '🏠',
'sport' => '⚽',
'sports' => '⚽',
'jouets' => '🧸',
'toys' => '🧸',
'alimentation' => '🍽️',
'food' => '🍽️',
'bijoux' => '💍',
'jewelry' => '💍',
'livres' => '📚',
'books' => '📚',
'auto' => '🚗',
'jardin' => '🌿',
'garden' => '🌿',
'bebe'