グッズメモ アフィリエイト・WordPressプラグイン

グッズメモ アフィリエイト・WordPressプラグインのソースコード記事の目次WordPress

goodsmemo-affiliate.php

「Plugin Name」などの「プラグイン情報ヘッダー」を記述したPHPソースコードです。WordPressは、このソースコードをプラグインと認識します。


/*
  Plugin Name: Goods Memo Affiliate
  Plugin URI:
  Description: アフィリエイトの商品を表示します。
  Version: 0.0.6
  Author:Goods Memo
  Author URI: https://www.goods-memo.net/goods-memo-affiliate/
  License: GPL v2 or later
 */

/*
 * Copyright (C) 2018 Goods Memo.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 */


define("GOODS_MEMO_DIR", __DIR__ . "/");
define("GOODS_MEMO_PREFIX", "goodsmemo");

function goodsmemo_affiliate_uninstall() {
    // データベースからオプションを削除する
    delete_option("goodsmemo_option_name");
}

register_uninstall_hook(__FILE__, "goodsmemo_affiliate_uninstall");

function addGoodsMemoAffiliateStyles() {

    $styleSheetUniqueName = GOODS_MEMO_PREFIX . "-affiliateStyles";
    $pluginCssURL = plugins_url('gma-style.css', __FILE__);
    //var_dump($pluginCssURL);

    wp_register_style($styleSheetUniqueName, $pluginCssURL);
    wp_enqueue_style($styleSheetUniqueName);
}

if (is_admin()) {

    //ダッシュボードまたは管理画面を表示中
    require_once(GOODS_MEMO_DIR . "option/AffiliateSettingPage.php");
    $settingPage = new goodsmemo\option\AffiliateSettingPage();
} else {
    //テーマを使って表示中
    require_once(GOODS_MEMO_DIR . "shortcode/Shortcode.php");

    //テスト環境にて、ショートコードの属性の値が壊れていた場合があった。
    //例:keyword="ダイエット"が、$attsにて、keyword=「class="marker_pink">ダイエット」という値になった。
    //add_shortcode(GOODS_MEMO_PREFIX . "_affiliate", "\goodsmemo\shortcode\Shortcode::makeAffiliateHTML");
    //
    //以下の書き方にしてみる。参考:http://wpdocs.osdn.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/add_shortcode
    add_shortcode(GOODS_MEMO_PREFIX . "_affiliate", array('goodsmemo\shortcode\Shortcode', 'makeAffiliateHTML'));

    //ヘッダにCSSを追加する
    add_action('wp_enqueue_scripts', 'addGoodsMemoAffiliateStyles');
}

/*
 * デバッグの例:
 * var_dump($val);
 * print_r($val);
 */

gma-style.css


/*
    Created on : 2018/10/08, 12:14:02
    Author     : Goods Memo
*/

/* 例:ワードプレスCocoonテーマのCSSにfooterクラスの設定があった場合、それも初期化する。*/
.goodsmemo-amazon-items div,
.goodsmemo-amazon-items span,
.goodsmemo-amazon-items p,
.goodsmemo-amazon-items img,
.goodsmemo-amazon-items .footer,
.goodsmemo-rakuten-items div,
.goodsmemo-rakuten-items span,
.goodsmemo-rakuten-items p,
.goodsmemo-rakuten-items img,
.goodsmemo-rakuten-items .footer
{
    margin: 0;
    padding: 0;
    border: 0;
}

.goodsmemo-amazon-items.goodsmemo-items,
.goodsmemo-rakuten-items.goodsmemo-items
{
    border-bottom: 1px #ddd solid;
}

.goodsmemo-amazon-items .goodsmemo-oneItem,
.goodsmemo-rakuten-items .goodsmemo-oneItem
{
    clear: both;

    padding-top: 20px;
    padding-bottom: 20px;

    border-top: 1px #ddd solid;
}

.goodsmemo-amazon-items .goodsmemo-oneItem .imageArea,
.goodsmemo-rakuten-items .goodsmemo-oneItem .imageArea
{
    float: left;
    width: 160px;
    margin-right: 10px;
}

.goodsmemo-rakuten-items .goodsmemo-oneItem .imageArea img
{
    /* 幅が128よりも狭い画像があった。 */
    width : auto;/* imgタグのwidth値を解除 */
    height: auto;
}

.goodsmemo-amazon-items .goodsmemo-oneItem .priceLabel,
.goodsmemo-amazon-items .goodsmemo-oneItem .pointRateLabel,
.goodsmemo-amazon-items .goodsmemo-oneItem .authorLabel,
.goodsmemo-amazon-items .goodsmemo-oneItem .manufacturerLabel,
.goodsmemo-amazon-items .goodsmemo-oneItem .bindingLabel,
.goodsmemo-amazon-items .goodsmemo-oneItem .shopLabel,
.goodsmemo-rakuten-items .goodsmemo-oneItem .priceLabel,
.goodsmemo-rakuten-items .goodsmemo-oneItem .pointRateLabel,
.goodsmemo-rakuten-items .goodsmemo-oneItem .authorLabel,
.goodsmemo-rakuten-items .goodsmemo-oneItem .manufacturerLabel,
.goodsmemo-rakuten-items .goodsmemo-oneItem .bindingLabel,
.goodsmemo-rakuten-items .goodsmemo-oneItem .shopLabel
{
    display: inline-block;/* spanの幅を固定する。*/
    text-align: right;/* インラインブロックのspanに対して、右寄せ指定。*/
    min-width: 4.3em;
    margin-right: 5px;
}

.goodsmemo-amazon-items .goodsmemo-oneItem .pointRateStartTimeLabel,
.goodsmemo-amazon-items .goodsmemo-oneItem .pointRateEndTimeLabel,
.goodsmemo-rakuten-items .goodsmemo-oneItem .pointRateStartTimeLabel,
.goodsmemo-rakuten-items .goodsmemo-oneItem .pointRateEndTimeLabel
{
    margin-right: 10px;
}

.goodsmemo-amazon-items .goodsmemo-oneItem .areaNotToWrapAround,
.goodsmemo-amazon-items .goodsmemo-oneItem .review,
.goodsmemo-rakuten-items .goodsmemo-oneItem .areaNotToWrapAround,
.goodsmemo-rakuten-items .goodsmemo-oneItem .review
{
    overflow: hidden;/* 画像の下に回り込むことを防ぐ */
}

.goodsmemo-amazon-items .goodsmemo-oneItem .priceValue,
.goodsmemo-rakuten-items .goodsmemo-oneItem .priceValue
{
    font-size: 115%;
    color: #b12704;
}

.goodsmemo-amazon-items .goodsmemo-oneItem .priceTime,
.goodsmemo-rakuten-items .goodsmemo-oneItem .priceTime
{
    margin-left: 10px;
}

.goodsmemo-amazon-items .goodsmemo-oneItem a.priceTimeLink,
.goodsmemo-rakuten-items .goodsmemo-oneItem a.priceTimeLink
{
    color: #333;
    margin-left: 10px;
}

.goodsmemo-amazon-items .goodsmemo-oneItem a:hover.priceTimeLink,
.goodsmemo-rakuten-items .goodsmemo-oneItem a:hover.priceTimeLink
{
    color: #e53900;
}

.goodsmemo-amazon-items .goodsmemo-oneItem .postageValue,
.goodsmemo-rakuten-items .goodsmemo-oneItem .postageValue
{
    margin-left: 4.3em;
}

.goodsmemo-amazon-items .goodsmemo-oneItem .pointRateValue,
.goodsmemo-rakuten-items .goodsmemo-oneItem .pointRateValue
{
    font-size: 115%;
    color: #b12704;
    margin-left: 5px;
}

.goodsmemo-amazon-items .footer,
.goodsmemo-rakuten-items .footer
{
    clear: both;
    font-size: small;

    padding-top: 20px;
    padding-bottom: 20px;

    border-top: 1px #ddd solid;
}

.goodsmemo-amazon-search-widget
{
    padding-top: 20px;
    padding-bottom: 20px;

    min-width:336px;
    min-height: 320px;/* 20px + 280px + 20px */

    border-top: 1px #ddd solid;
    border-bottom: 1px #ddd solid;
}

/*480px以下*/
@media screen and (max-width: 480px) {

    .goodsmemo-amazon-items .goodsmemo-oneItem .imageArea,
    .goodsmemo-rakuten-items .goodsmemo-oneItem .imageArea
    {
	width: 25%;
    }

}