| 1 |
<?php |
| 2 |
/** |
| 3 |
* Pro |
| 4 |
* |
| 5 |
* @package Copy the Code |
| 6 |
* @since 1.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! class_exists( 'Copy_The_Code_Pro' ) ) : |
| 10 |
|
| 11 |
/** |
| 12 |
* Copy the Code |
| 13 |
* |
| 14 |
* @since 1.0.0 |
| 15 |
*/ |
| 16 |
class Copy_The_Code_Pro { |
| 17 |
|
| 18 |
/** |
| 19 |
* Instance |
| 20 |
* |
| 21 |
* @access private |
| 22 |
* @var object Class Instance. |
| 23 |
* @since 1.0.0 |
| 24 |
*/ |
| 25 |
private static $instance; |
| 26 |
|
| 27 |
/** |
| 28 |
* Initiator |
| 29 |
* |
| 30 |
* @since 1.0.0 |
| 31 |
* @return object initialized object of class. |
| 32 |
*/ |
| 33 |
public static function get_instance() { |
| 34 |
if ( ! isset( self::$instance ) ) { |
| 35 |
self::$instance = new self; |
| 36 |
} |
| 37 |
return self::$instance; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Constructor |
| 42 |
*/ |
| 43 |
public function __construct() { |
| 44 |
add_action( 'admin_enqueue_scripts', [ $this, 'dashboard_scripts' ] ); |
| 45 |
add_action( 'copy_the_code/dashboard/save', [ $this, 'save' ] ); |
| 46 |
add_action( 'wp_footer', array( $this, 'add_style' ) ); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Add style |
| 51 |
*/ |
| 52 |
public function add_style() { |
| 53 |
$style = get_option( 'ctc_default_style' ); |
| 54 |
if ( ! $style ) { |
| 55 |
return; |
| 56 |
} |
| 57 |
$btnColor = isset( $style['btn_color'] ) ? $style['btn_color'] : ''; |
| 58 |
$btnBgColor = isset( $style['btn_bg_color'] ) ? $style['btn_bg_color'] : ''; |
| 59 |
$btnFontSize = isset( $style['btn_font_size'] ) ? $style['btn_font_size'] : ''; |
| 60 |
$btnLineHeight = isset( $style['btn_font_weight'] ) ? $style['btn_font_weight'] : ''; |
| 61 |
$btnLPadding = isset( $style['btn_l_padding'] ) ? $style['btn_l_padding'] : ''; |
| 62 |
$btnTPadding = isset( $style['btn_t_padding'] ) ? $style['btn_t_padding'] : ''; |
| 63 |
$btnRPadding = isset( $style['btn_r_padding'] ) ? $style['btn_r_padding'] : ''; |
| 64 |
$btnBPadding = isset( $style['btn_b_padding'] ) ? $style['btn_b_padding'] : ''; |
| 65 |
$btnLMargin = isset( $style['btn_l_margin'] ) ? $style['btn_l_margin'] : ''; |
| 66 |
$btnTMargin = isset( $style['btn_t_margin'] ) ? $style['btn_t_margin'] : ''; |
| 67 |
$btnRMargin = isset( $style['btn_r_margin'] ) ? $style['btn_r_margin'] : ''; |
| 68 |
$btnBMargin = isset( $style['btn_b_margin'] ) ? $style['btn_b_margin'] : ''; |
| 69 |
$btnTLRadius = isset( $style['btn_tl_radius'] ) ? $style['btn_tl_radius'] : ''; |
| 70 |
$btnTRRadius = isset( $style['btn_tr_radius'] ) ? $style['btn_tr_radius'] : ''; |
| 71 |
$btnBRRadius = isset( $style['btn_br_radius'] ) ? $style['btn_br_radius'] : ''; |
| 72 |
$btnBLRadius = isset( $style['btn_bl_radius'] ) ? $style['btn_bl_radius'] : ''; |
| 73 |
$btnHColor = isset( $style['btn_h_color'] ) ? $style['btn_h_color'] : ''; |
| 74 |
$btnHBgColor = isset( $style['btn_h_bg_color'] ) ? $style['btn_h_bg_color'] : ''; |
| 75 |
|
| 76 |
$svgIconColor = isset( $style['svg_icon_color'] ) ? $style['svg_icon_color'] : ''; |
| 77 |
$svgIconWidth = isset( $style['svg_icon_width'] ) ? $style['svg_icon_width'] : ''; |
| 78 |
$svgIconTPadding = isset( $style['svg_icon_t_padding'] ) ? $style['svg_icon_t_padding'] : ''; |
| 79 |
$svgIconRPadding = isset( $style['svg_icon_r_padding'] ) ? $style['svg_icon_r_padding'] : ''; |
| 80 |
$svgIconBPadding = isset( $style['svg_icon_b_padding'] ) ? $style['svg_icon_b_padding'] : ''; |
| 81 |
$svgIconLPadding = isset( $style['svg_icon_l_padding'] ) ? $style['svg_icon_l_padding'] : ''; |
| 82 |
$svgIconHColor = isset( $style['svg_icon_h_color'] ) ? $style['svg_icon_h_color'] : ''; |
| 83 |
|
| 84 |
$coverColor = isset( $style['cover_color'] ) ? $style['cover_color'] : ''; |
| 85 |
$coverFontSize = isset( $style['cover_font_size'] ) ? $style['cover_font_size'] : ''; |
| 86 |
|
| 87 |
?> |
| 88 |
<style> |
| 89 |
.copy-the-code-wrap.copy-the-code-style-cover .copy-the-code-button { |
| 90 |
color: <?php echo $coverColor; ?>; |
| 91 |
font-size: <?php echo esc_html( $coverFontSize ); ?>px; |
| 92 |
} |
| 93 |
|
| 94 |
.copy-the-code-wrap.copy-the-code-style-svg-icon .copy-the-code-button { |
| 95 |
padding-top: <?php echo $svgIconTPadding; ?>px; |
| 96 |
padding-right: <?php echo $svgIconRPadding; ?>px; |
| 97 |
padding-bottom: <?php echo $svgIconBPadding; ?>px; |
| 98 |
padding-left: <?php echo $svgIconLPadding; ?>px; |
| 99 |
color: <?php echo $svgIconColor; ?>; |
| 100 |
} |
| 101 |
.copy-the-code-wrap.copy-the-code-style-svg-icon .copy-the-code-button svg { |
| 102 |
fill: <?php echo $svgIconColor; ?>; |
| 103 |
width: <?php echo $svgIconWidth; ?>px; |
| 104 |
} |
| 105 |
.copy-the-code-wrap.copy-the-code-style-svg-icon .copy-the-code-button:hover { |
| 106 |
color: <?php echo $svgIconHColor; ?>; |
| 107 |
} |
| 108 |
.copy-the-code-wrap.copy-the-code-style-svg-icon .copy-the-code-button:hover svg { |
| 109 |
fill: <?php echo $svgIconHColor; ?>; |
| 110 |
} |
| 111 |
|
| 112 |
.copy-the-code-style-button .copy-the-code-button { |
| 113 |
color: <?php echo esc_html( $btnColor ); ?>; |
| 114 |
background-color: <?php echo esc_html( $btnBgColor ); ?>; |
| 115 |
font-size: <?php echo esc_html( $btnFontSize ); ?>px; |
| 116 |
line-height: <?php echo esc_html( $btnLineHeight ); ?>px; |
| 117 |
padding-left: <?php echo esc_html( $btnLPadding ); ?>px; |
| 118 |
padding-top: <?php echo esc_html( $btnTPadding ); ?>px; |
| 119 |
padding-right: <?php echo esc_html( $btnRPadding ); ?>px; |
| 120 |
padding-bottom: <?php echo esc_html( $btnBPadding ); ?>px; |
| 121 |
margin-left: <?php echo esc_html( $btnLMargin ); ?>px; |
| 122 |
margin-top: <?php echo esc_html( $btnTMargin ); ?>px; |
| 123 |
margin-right: <?php echo esc_html( $btnRMargin ); ?>px; |
| 124 |
margin-bottom: <?php echo esc_html( $btnBMargin ); ?>px; |
| 125 |
border-top-left-radius: <?php echo esc_html( $btnTLRadius ); ?>px; |
| 126 |
border-top-right-radius: <?php echo esc_html( $btnTRRadius ); ?>px; |
| 127 |
border-bottom-right-radius: <?php echo esc_html( $btnBRRadius ); ?>px; |
| 128 |
border-bottom-left-radius: <?php echo esc_html( $btnBLRadius ); ?>px; |
| 129 |
} |
| 130 |
.copy-the-code-style-button .copy-the-code-button:hover { |
| 131 |
color: <?php echo esc_html( $btnHColor ); ?>; |
| 132 |
background-color: <?php echo esc_html( $btnHBgColor ); ?>; |
| 133 |
} |
| 134 |
|
| 135 |
.copy-the-code-style-button .copy-the-code-button svg { |
| 136 |
fill: <?php echo esc_html( $btnColor ); ?>; |
| 137 |
width: <?php echo esc_html( $btnFontSize ); ?>px; |
| 138 |
} |
| 139 |
.copy-the-code-style-button .copy-the-code-button:hover svg { |
| 140 |
fill: <?php echo esc_html( $btnHColor ); ?>; |
| 141 |
} |
| 142 |
</style> |
| 143 |
<?php |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Save |
| 148 |
* |
| 149 |
* @since 3.0.0 |
| 150 |
* @return void |
| 151 |
*/ |
| 152 |
public function save() { |
| 153 |
$style = isset( $_POST['style'] ) ? $_POST['style'] : get_option( 'ctc_default_style', [] ); |
| 154 |
if ( ! $style ) { |
| 155 |
return; |
| 156 |
} |
| 157 |
|
| 158 |
update_option( 'ctc_default_style', $style ); |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* Dashboard scripts. |
| 163 |
* |
| 164 |
* @version 3.0.0 |
| 165 |
* |
| 166 |
* @param string $hook Current hook name. |
| 167 |
* @return mixed |
| 168 |
*/ |
| 169 |
function dashboard_scripts( $hook = '' ) { |
| 170 |
if ( 'settings_page_copy-the-code' !== $hook ) { |
| 171 |
return; |
| 172 |
} |
| 173 |
|
| 174 |
wp_enqueue_script( 'copy-the-code-customize', COPY_THE_CODE_URI . 'assets/admin/js/customize.js', [ 'jquery', 'wp-hooks' ], COPY_THE_CODE_VER, true ); |
| 175 |
} |
| 176 |
|
| 177 |
} |
| 178 |
|
| 179 |
/** |
| 180 |
* Kicking this off by calling 'get_instance()' method |
| 181 |
*/ |
| 182 |
Copy_The_Code_Pro::get_instance(); |
| 183 |
|
| 184 |
endif; |
| 185 |
|